Skip to content

Commit d3a227d

Browse files
authored
Cleanup splicing utils (#2564)
1 parent 3785334 commit d3a227d

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

crate_universe/private/splicing_utils.bzl

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def kebab_case_keys(data):
3434
}
3535

3636
def compile_splicing_manifest(splicing_config, manifests, cargo_config_path, packages):
37-
"""Produce a manifest containing required components for splciing a new Cargo workspace
37+
"""Produce a manifest containing required components for splicing a new Cargo workspace
3838
3939
[cargo_config]: https://doc.rust-lang.org/cargo/reference/config.html
4040
[cargo_toml]: https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -56,14 +56,14 @@ def compile_splicing_manifest(splicing_config, manifests, cargo_config_path, pac
5656
for (pkg, data) in packages.items()
5757
}
5858

59-
# Auto-generated splicier manifest values
59+
# Auto-generated splicer manifest values
6060
splicing_manifest_content = {
6161
"cargo_config": cargo_config_path,
6262
"direct_packages": direct_packages_info,
6363
"manifests": manifests,
6464
}
6565

66-
return dict(splicing_config.items() + splicing_manifest_content.items())
66+
return splicing_config | splicing_manifest_content
6767

6868
def _no_at_label(label):
6969
"""Strips leading '@'s for stringified labels in the main repository for backwards-comaptibility reasons."""
@@ -75,7 +75,7 @@ def _no_at_label(label):
7575
return s
7676

7777
def create_splicing_manifest(repository_ctx):
78-
"""Produce a manifest containing required components for splciing a new Cargo workspace
78+
"""Produce a manifest containing required components for splicing a new Cargo workspace
7979
8080
Args:
8181
repository_ctx (repository_ctx): The rule's context object.
@@ -94,9 +94,7 @@ def create_splicing_manifest(repository_ctx):
9494
# Load user configurable splicing settings
9595
config = json.decode(repository_ctx.attr.splicing_config or splicing_config())
9696

97-
repo_dir = repository_ctx.path(".")
98-
99-
splicing_manifest = repository_ctx.path("{}/splicing_manifest.json".format(repo_dir))
97+
splicing_manifest = repository_ctx.path("splicing_manifest.json")
10098

10199
data = compile_splicing_manifest(
102100
splicing_config = config,
@@ -132,7 +130,6 @@ def splice_workspace_manifest(repository_ctx, generator, cargo_lockfile, splicin
132130
path: The path to a Cargo metadata json file found in the spliced workspace root.
133131
"""
134132
repository_ctx.report_progress("Splicing Cargo workspace.")
135-
repo_dir = repository_ctx.path(".")
136133

137134
splicing_output_dir = repository_ctx.path("splicing-output")
138135

@@ -159,7 +156,7 @@ def splice_workspace_manifest(repository_ctx, generator, cargo_lockfile, splicin
159156
if CARGO_BAZEL_DEBUG in repository_ctx.os.environ:
160157
arguments.extend([
161158
"--workspace-dir",
162-
repository_ctx.path("{}/splicing-workspace".format(repo_dir)),
159+
repository_ctx.path("splicing-workspace"),
163160
])
164161

165162
env = {
@@ -170,10 +167,10 @@ def splice_workspace_manifest(repository_ctx, generator, cargo_lockfile, splicin
170167

171168
# Ensure the short hand repin variable is set to the full name.
172169
if REPIN in repository_ctx.os.environ and CARGO_BAZEL_REPIN not in repository_ctx.os.environ:
173-
env.update({CARGO_BAZEL_REPIN: repository_ctx.os.environ[REPIN]})
170+
env["CARGO_BAZEL_REPIN"] = repository_ctx.os.environ[REPIN]
174171

175172
# Add any Cargo environment variables to the `cargo-bazel` execution
176-
env.update(cargo_environ(repository_ctx))
173+
env |= cargo_environ(repository_ctx)
177174

178175
execute(
179176
repository_ctx = repository_ctx,
@@ -182,11 +179,11 @@ def splice_workspace_manifest(repository_ctx, generator, cargo_lockfile, splicin
182179
)
183180

184181
# This file must have been produced by the execution above.
185-
spliced_lockfile = repository_ctx.path("{}/Cargo.lock".format(splicing_output_dir))
182+
spliced_lockfile = repository_ctx.path(splicing_output_dir.get_child("Cargo.lock"))
186183
if not spliced_lockfile.exists:
187-
fail("Lockfile file does not exist: {}".format(spliced_lockfile))
188-
spliced_metadata = repository_ctx.path("{}/metadata.json".format(splicing_output_dir))
184+
fail("Lockfile file does not exist: " + str(spliced_lockfile))
185+
spliced_metadata = repository_ctx.path(splicing_output_dir.get_child("metadata.json"))
189186
if not spliced_metadata.exists:
190-
fail("Metadata file does not exist: {}".format(spliced_metadata))
187+
fail("Metadata file does not exist: " + str(spliced_metadata))
191188

192189
return spliced_metadata

0 commit comments

Comments
 (0)