Skip to content

Fix: Handle package.workspace key in child Cargo.toml #3442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ use_repo(
"cui__cargo_toml-0.22.1",
"cui__cfg-expr-0.18.0",
"cui__clap-4.5.37",
"cui__clean-path-0.2.1",
"cui__crates-index-3.7.0",
"cui__glob-0.3.2",
"cui__hex-0.4.3",
Expand Down
12 changes: 12 additions & 0 deletions crate_universe/3rdparty/crates/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions crate_universe/3rdparty/crates/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crate_universe/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crate_universe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ tracing-subscriber = "0.3.19"
url = "2.5.4"
walkdir = "2.5.0"
glob = "0.3.2"
clean-path = "0.2.1"

[dev-dependencies]
maplit = "1.0.2"
9 changes: 7 additions & 2 deletions crate_universe/src/metadata/workspace_discoverer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{BTreeMap, BTreeSet};

use crate::utils::PathCleanUtf8;
use anyhow::{anyhow, bail, Context, Result};
use camino::{Utf8Path, Utf8PathBuf};
use cargo_toml::Manifest;
Expand Down Expand Up @@ -135,8 +136,12 @@ fn discover_workspaces_with_cache(
explicit_workspace_path.display()
)
})?;
actual_workspace_path =
child_path.parent().unwrap().join(explicit_workspace_path);
actual_workspace_path = child_path
.parent()
.unwrap()
.join(explicit_workspace_path)
.clean()
.join("Cargo.toml");
}
}
if !discovered_workspaces
Expand Down
20 changes: 20 additions & 0 deletions crate_universe/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(crate) mod target_triple;

pub(crate) const CRATES_IO_INDEX_URL: &str = "https://github.com/rust-lang/crates.io-index";

use camino::Utf8PathBuf;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -63,6 +64,17 @@ pub(crate) fn normalize_cargo_file_paths(
.collect()
}

pub(crate) trait PathCleanUtf8 {
/// Normalize utf8 path from camino
fn clean(&self) -> Utf8PathBuf;
}

impl PathCleanUtf8 for Utf8PathBuf {
fn clean(&self) -> Utf8PathBuf {
Utf8PathBuf::from_path_buf(clean_path::clean(self.as_std_path())).unwrap()
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -111,4 +123,12 @@ mod test {
assert!(!output.to_str().unwrap().contains('+'));
}
}

#[test]
fn test_normalize_utf8_path() {
assert_eq!(
Utf8PathBuf::from("my/long/../path").clean(),
Utf8PathBuf::from("my/path")
);
}
}
4 changes: 2 additions & 2 deletions examples/crate_universe/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ use_repo(
"crates_vendor_pkgs__tracing-subscriber-0.3.19",
"cvm",
"cvm__serde_yaml-0.9.34-deprecated",
"cvm__tempfile-3.19.1",
"cvm__tokio-1.44.2",
"cvm__tempfile-3.20.0",
"cvm__tokio-1.45.0",
"cvm__tokio-test-0.4.4",
)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "num_printer"
version = "0.1.0"
edition = "2018"
workspace = ".."

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
Expand Down
1 change: 1 addition & 0 deletions examples/crate_universe/cargo_workspace/printer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "printer"
version = "0.1.0"
edition = "2018"
workspace = ".."

[dependencies]
rng = { path = "../rng" }
Expand Down
1 change: 1 addition & 0 deletions examples/crate_universe/cargo_workspace/rng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "rng"
version = "0.1.0"
edition = "2018"
workspace = ".."

[dependencies]
rand = "0.7.3"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading