Skip to content

Commit

Permalink
Added debug logging for spliced manifests to crate_universe (#2629)
Browse files Browse the repository at this point in the history
This adds the following new logging when `CARGO_BAZEL_DEBUG=1` is
enabled in the environment when the repository rule runs.
```
cd test/no_std && CARGO_BAZEL_REPIN=1 CARGO_BAZEL_DEBUG=1 bazel sync --only=no_std_crate_index
```
````
...
...
Splice 2024-04-27T16:31:48.249675Z DEBUG write_registry_urls_and_feature_map: cargo_bazel::splicing::splicer: Writing Cargo manifest '/private/var/tmp/_bazel_user/427c86c43c8db37f50959419e7306f4e/external/no_std_crate_index/splicing-workspace/Cargo.toml':
```toml
[dependencies.libc_alloc]
version = "1.0.3"

[lib]
name = "direct_cargo_bazel_deps"
path = ".direct_cargo_bazel_deps.rs"
required-features = []

[package]
edition = "2018"
name = "direct-cargo-bazel-deps"
version = "0.0.1"

[workspace]
members = []
resolver = "2"

[workspace.metadata.cargo-bazel.features."direct-cargo-bazel-deps
0.0.1"]
common = []

[workspace.metadata.cargo-bazel.features."direct-cargo-bazel-deps
0.0.1".selects]

[workspace.metadata.cargo-bazel.features."libc_alloc 1.0.4"]
common = []

[workspace.metadata.cargo-bazel.features."libc_alloc 1.0.4".selects]

[workspace.metadata.cargo-bazel.package_prefixes]

[workspace.metadata.cargo-bazel.sources."libc_alloc 1.0.4"]
sha256 =
"6a090348b66d90d8507e30f0d2bd88e5a5c454bd1733fc6d617cbc3471bf69ea"
url = "https://static.crates.io/crates/libc_alloc/1.0.4/download"
```
...
...
````
  • Loading branch information
UebelAndre committed Apr 29, 2024
1 parent 2776987 commit c43af7b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crate_universe/src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ impl Digest {
.with_context(|| format!("Failed to run {} to get its version", binary.display()))?;

if !output.status.success() {
eprintln!("{}", String::from_utf8_lossy(&output.stdout));
eprintln!("{}", String::from_utf8_lossy(&output.stderr));
bail!("Failed to query cargo version")
}

Expand Down
3 changes: 3 additions & 0 deletions crate_universe/src/splicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ impl WorkspaceMetadata {
})
}

/// Update an existing Cargo manifest with metadata about registry urls and target
/// features that are needed in generator steps beyond splicing.
#[tracing::instrument(skip_all)]
pub(crate) fn write_registry_urls_and_feature_map(
cargo: &Cargo,
lockfile: &cargo_lock::Lockfile,
Expand Down
13 changes: 11 additions & 2 deletions crate_universe/src/splicing/splicer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl<'a> SplicerKind<'a> {
}

/// Performs splicing based on the current variant.
#[tracing::instrument(skip_all)]
pub(crate) fn splice(&self, workspace_dir: &Path) -> Result<SplicedManifest> {
match self {
SplicerKind::Workspace {
Expand All @@ -205,6 +206,7 @@ impl<'a> SplicerKind<'a> {
}

/// Implementation for splicing Cargo workspaces
#[tracing::instrument(skip_all)]
fn splice_workspace(
workspace_dir: &Path,
path: &&PathBuf,
Expand Down Expand Up @@ -241,6 +243,7 @@ impl<'a> SplicerKind<'a> {
}

/// Implementation for splicing individual Cargo packages
#[tracing::instrument(skip_all)]
fn splice_package(
workspace_dir: &Path,
path: &&PathBuf,
Expand Down Expand Up @@ -283,6 +286,7 @@ impl<'a> SplicerKind<'a> {
}

/// Implementation for splicing together multiple Cargo packages/workspaces
#[tracing::instrument(skip_all)]
fn splice_multi_package(
workspace_dir: &Path,
manifests: &&BTreeMap<PathBuf, Manifest>,
Expand Down Expand Up @@ -656,8 +660,13 @@ pub(crate) fn write_root_manifest(path: &Path, manifest: cargo_toml::Manifest) -

// TODO(https://gitlab.com/crates.rs/cargo_toml/-/issues/3)
let value = toml::Value::try_from(manifest)?;
fs::write(path, toml::to_string(&value)?)
.context(format!("Failed to write manifest to {}", path.display()))
let content = toml::to_string(&value)?;
tracing::debug!(
"Writing Cargo manifest '{}':\n```toml\n{}```",
path.display(),
content
);
fs::write(path, content).context(format!("Failed to write manifest to {}", path.display()))
}

/// Create a symlink file on unix systems
Expand Down

0 comments on commit c43af7b

Please sign in to comment.