Skip to content

Commit

Permalink
Fix crate_universe/private/srcs.bzl to work with repo mappings
Browse files Browse the repository at this point in the history
Currently the list in the said file only works if the rules_rust repo is named exactly "rules_rust". This commit fixes it so that the list contains Label objects which would work regardless of what the repo is called.

Also fixes the generation script to allow leading '@'s in the label stringification result (see bazelbuild/bazel#16196).
  • Loading branch information
Wyverald committed Sep 6, 2022
1 parent d1fc9ac commit 65b9cec
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 47 deletions.
9 changes: 7 additions & 2 deletions crate_universe/private/bootstrap_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ CARGO_BAZEL_SRCS = [
]
"""

def _format_src_label(label):
if label.workspace_name != "":
fail("`srcs` must be from the rules_rust repository")
return "Label('{}'),".format(str(label).lstrip('@'))

def _srcs_module_impl(ctx):
srcs = ["@rules_rust{}".format(src.owner) for src in ctx.files.srcs]
srcs = [_format_src_label(src.owner) for src in ctx.files.srcs]
if not srcs:
fail("`srcs` cannot be empty")
output = ctx.actions.declare_file(ctx.label.name)

ctx.actions.write(
output = output,
content = _SRCS_TEMPLATE.format(
srcs = "\n ".join(["\"{}\",".format(src) for src in srcs]),
srcs = "\n ".join(srcs),
),
)

Expand Down
90 changes: 45 additions & 45 deletions crate_universe/private/srcs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@
# Each source file is tracked as a target so the `cargo_bootstrap_repository`
# rule will know to automatically rebuild if any of the sources changed.
CARGO_BAZEL_SRCS = [
"@rules_rust//crate_universe:src/cli.rs",
"@rules_rust//crate_universe:src/cli/generate.rs",
"@rules_rust//crate_universe:src/cli/query.rs",
"@rules_rust//crate_universe:src/cli/splice.rs",
"@rules_rust//crate_universe:src/cli/vendor.rs",
"@rules_rust//crate_universe:src/config.rs",
"@rules_rust//crate_universe:src/context.rs",
"@rules_rust//crate_universe:src/context/crate_context.rs",
"@rules_rust//crate_universe:src/context/platforms.rs",
"@rules_rust//crate_universe:src/lib.rs",
"@rules_rust//crate_universe:src/lockfile.rs",
"@rules_rust//crate_universe:src/main.rs",
"@rules_rust//crate_universe:src/metadata.rs",
"@rules_rust//crate_universe:src/metadata/dependency.rs",
"@rules_rust//crate_universe:src/metadata/metadata_annotation.rs",
"@rules_rust//crate_universe:src/rendering.rs",
"@rules_rust//crate_universe:src/rendering/template_engine.rs",
"@rules_rust//crate_universe:src/rendering/templates/crate_build_file.j2",
"@rules_rust//crate_universe:src/rendering/templates/module_build_file.j2",
"@rules_rust//crate_universe:src/rendering/templates/module_bzl.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/crate/aliases.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/crate/binary.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/crate/build_script.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/crate/common_attrs.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/crate/deps.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/crate/library.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/crate/proc_macro.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/header.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/module/aliases_map.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/module/deps_map.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/module/repo_git.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/module/repo_http.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/starlark/glob.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/starlark/selectable_dict.j2",
"@rules_rust//crate_universe:src/rendering/templates/partials/starlark/selectable_list.j2",
"@rules_rust//crate_universe:src/rendering/templates/vendor_module.j2",
"@rules_rust//crate_universe:src/splicing.rs",
"@rules_rust//crate_universe:src/splicing/cargo_config.rs",
"@rules_rust//crate_universe:src/splicing/splicer.rs",
"@rules_rust//crate_universe:src/test.rs",
"@rules_rust//crate_universe:src/utils.rs",
"@rules_rust//crate_universe:src/utils/starlark.rs",
"@rules_rust//crate_universe:src/utils/starlark/glob.rs",
"@rules_rust//crate_universe:src/utils/starlark/label.rs",
"@rules_rust//crate_universe:src/utils/starlark/select.rs",
Label('//crate_universe:src/cli.rs'),
Label('//crate_universe:src/cli/generate.rs'),
Label('//crate_universe:src/cli/query.rs'),
Label('//crate_universe:src/cli/splice.rs'),
Label('//crate_universe:src/cli/vendor.rs'),
Label('//crate_universe:src/config.rs'),
Label('//crate_universe:src/context.rs'),
Label('//crate_universe:src/context/crate_context.rs'),
Label('//crate_universe:src/context/platforms.rs'),
Label('//crate_universe:src/lib.rs'),
Label('//crate_universe:src/lockfile.rs'),
Label('//crate_universe:src/main.rs'),
Label('//crate_universe:src/metadata.rs'),
Label('//crate_universe:src/metadata/dependency.rs'),
Label('//crate_universe:src/metadata/metadata_annotation.rs'),
Label('//crate_universe:src/rendering.rs'),
Label('//crate_universe:src/rendering/template_engine.rs'),
Label('//crate_universe:src/rendering/templates/crate_build_file.j2'),
Label('//crate_universe:src/rendering/templates/module_build_file.j2'),
Label('//crate_universe:src/rendering/templates/module_bzl.j2'),
Label('//crate_universe:src/rendering/templates/partials/crate/aliases.j2'),
Label('//crate_universe:src/rendering/templates/partials/crate/binary.j2'),
Label('//crate_universe:src/rendering/templates/partials/crate/build_script.j2'),
Label('//crate_universe:src/rendering/templates/partials/crate/common_attrs.j2'),
Label('//crate_universe:src/rendering/templates/partials/crate/deps.j2'),
Label('//crate_universe:src/rendering/templates/partials/crate/library.j2'),
Label('//crate_universe:src/rendering/templates/partials/crate/proc_macro.j2'),
Label('//crate_universe:src/rendering/templates/partials/header.j2'),
Label('//crate_universe:src/rendering/templates/partials/module/aliases_map.j2'),
Label('//crate_universe:src/rendering/templates/partials/module/deps_map.j2'),
Label('//crate_universe:src/rendering/templates/partials/module/repo_git.j2'),
Label('//crate_universe:src/rendering/templates/partials/module/repo_http.j2'),
Label('//crate_universe:src/rendering/templates/partials/starlark/glob.j2'),
Label('//crate_universe:src/rendering/templates/partials/starlark/selectable_dict.j2'),
Label('//crate_universe:src/rendering/templates/partials/starlark/selectable_list.j2'),
Label('//crate_universe:src/rendering/templates/vendor_module.j2'),
Label('//crate_universe:src/splicing.rs'),
Label('//crate_universe:src/splicing/cargo_config.rs'),
Label('//crate_universe:src/splicing/splicer.rs'),
Label('//crate_universe:src/test.rs'),
Label('//crate_universe:src/utils.rs'),
Label('//crate_universe:src/utils/starlark.rs'),
Label('//crate_universe:src/utils/starlark/glob.rs'),
Label('//crate_universe:src/utils/starlark/label.rs'),
Label('//crate_universe:src/utils/starlark/select.rs'),
]

0 comments on commit 65b9cec

Please sign in to comment.