I'm new to bazel and trying to automatize updates in the MapIt database and code.
I named the root folder for my bazel project bazel_mapit where there is the WORKSPACE file and the BUILD file for this external dependency as follows.
WORSPACE:
new_git_repository(
name = "mapit_repo",
remote = "https://github.com/mysociety/mapit",
tag = "v2.0",
build_file = "mapit_repo.BUILD",
init_submodules = 1,
)
mapit_reop.BUILD:
package(default_visibility = ["//visibility:public"])
filegroup(
name = "mapit_files",
srcs = glob(
[
"**/*",
],
exclude = [
"**/LICENSE",
"**/*.zip",
],
),
)
Now I want to generate the configuration file conf/general.yml inside the MapIt sources. The problem now is, when I add the following code to the mapit_repo.BUILD file, I getting errors that bazel can't find
'@bazel_mapit//:general_yml.bzl'
mapit_repo.BUILD (extension):
load("@bazel_mapit//:general_yml.bzl", "general_yml")
general_yml(
name = 'generate_general_yml',
bzl_mapit_db_user = 'foo',
)
filegroup (
name = 'mapit_general_yml',
srcs = ['conf/general.yml'],
data = ['conf/general.yml-example'],
)
How can I generate a config file in an external dependency?
Update:
This is the content of the working mapit_repo.BUILD file:
package(default_visibility = ["//visibility:public"])
filegroup(
name = "mapit_files",
srcs = glob(
[
"**/*",
],
exclude = [
"**/LICENSE",
"**/*.zip",
],
),
)
load("@//conf:general_yml.bzl", "general_yml")
general_yml(
name = 'generate_general_yml',
bzl_mapit_db_user = 'foo',
)
filegroup (
name = 'mapit_general_yml',
srcs = ['conf/general.yml'],
data = ['@//conf:general.yml.tmpl'],
)
I think all that needs to change is the load()
mapit_repo.BUILD. That build file is going to be evaluated from within the external workspace, so to reference the bzl file in the main workspace, you can use @//:general_yml.bzl
. (That is, the empty workspace name refers to the main workspace)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.