Skip to content

Commit 8c0011f

Browse files
authored
Ensure crate_universe modules don't override intermediates for debugging (#3244)
This way all files are available for introspection after generation.
1 parent d34e149 commit 8c0011f

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

crate_universe/extensions.bzl

+5-4
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ def _generate_hub_and_spokes(
630630
cargo_lockfile = cargo_lockfile,
631631
splicing_manifest = splicing_manifest,
632632
config_path = config_file,
633-
output_dir = module_ctx.path("{}/{}".format(tag_path, "splicing-output")),
633+
output_dir = tag_path.get_child("splicing-output"),
634+
debug_workspace_dir = tag_path.get_child("splicing-workspace"),
634635
)
635636

636637
# If a cargo lockfile was not provided, use the splicing lockfile.
@@ -639,7 +640,7 @@ def _generate_hub_and_spokes(
639640

640641
# Create a fallback lockfile to be parsed downstream.
641642
if lockfile == None:
642-
lockfile = module_ctx.path("cargo-bazel-lock.json")
643+
lockfile = tag_path.get_child("cargo-bazel-lock.json")
643644
module_ctx.file(lockfile, "")
644645

645646
kwargs.update({
@@ -649,8 +650,8 @@ def _generate_hub_and_spokes(
649650
# The workspace root when one is explicitly provided.
650651
nonhermetic_root_bazel_workspace_dir = module_ctx.path(Label("@@//:MODULE.bazel")).dirname
651652

652-
paths_to_track_file = module_ctx.path("paths_to_track.json")
653-
warnings_output_file = module_ctx.path("warnings_output.json")
653+
paths_to_track_file = tag_path.get_child("paths_to_track.json")
654+
warnings_output_file = tag_path.get_child("warnings_output.json")
654655

655656
# Run the generator
656657
module_ctx.report_progress("Generating crate BUILD files for `{}`".format(cfg.name))

crate_universe/private/splicing_utils.bzl

+6-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def splice_workspace_manifest(
121121
cargo_lockfile,
122122
splicing_manifest,
123123
config_path,
124-
output_dir):
124+
output_dir,
125+
debug_workspace_dir = None):
125126
"""Splice together a Cargo workspace from various other manifests and package definitions
126127
127128
Args:
@@ -131,6 +132,7 @@ def splice_workspace_manifest(
131132
splicing_manifest (path): The path to a splicing manifest.
132133
config_path (path): The path to the config file (containing `cargo_bazel::config::Config`.)
133134
output_dir (path): THe location in which to write splicing outputs.
135+
debug_workspace_dir (path): The location in which to save splicing outputs for future review.
134136
135137
Returns:
136138
path: The path to a Cargo metadata json file found in the spliced workspace root.
@@ -156,9 +158,11 @@ def splice_workspace_manifest(
156158
# Optionally set the splicing workspace directory to somewhere within the repository directory
157159
# to improve the debugging experience.
158160
if CARGO_BAZEL_DEBUG in repository_ctx.os.environ:
161+
if debug_workspace_dir == None:
162+
debug_workspace_dir = repository_ctx.path("splicing-workspace")
159163
arguments.extend([
160164
"--workspace-dir",
161-
repository_ctx.path("splicing-workspace"),
165+
debug_workspace_dir,
162166
])
163167

164168
env = {}

crate_universe/src/splicing/splicer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::path::Path;
77
use anyhow::{bail, Context, Result};
88
use camino::{Utf8Path, Utf8PathBuf};
99
use cargo_toml::Manifest;
10+
use tracing::debug;
1011

1112
use crate::config::CrateId;
1213
use crate::metadata::discover_workspaces;
@@ -349,6 +350,7 @@ impl<'a> SplicerKind<'a> {
349350
fs::create_dir_all(&dot_cargo_dir)?;
350351
}
351352

353+
debug!("Using Cargo config: {}", cargo_config_path);
352354
fs::copy(cargo_config_path, dot_cargo_dir.join("config.toml"))?;
353355
}
354356

0 commit comments

Comments
 (0)