diff --git a/CHANGELOG.md b/CHANGELOG.md index 678acf7..8970090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- allow workspaces by having validate_manifest now use `metadata --no-deps` instead of deprecated `read-manifest` + therefor no longer failing on workspaces and TomlTweaker no longer removing the workspace table from `Cargo.toml` + + ## [0.10.0] - 2020-08-08 ### Added diff --git a/src/prepare.rs b/src/prepare.rs index 08bd6e3..de41a48 100644 --- a/src/prepare.rs +++ b/src/prepare.rs @@ -59,7 +59,7 @@ impl<'a> Prepare<'a> { } let res = Command::new(self.workspace, self.toolchain.cargo()) - .args(&["read-manifest", "--manifest-path", "Cargo.toml"]) + .args(&["metadata", "--manifest-path", "Cargo.toml", "--no-deps"]) .cd(self.source_dir) .log_output(false) .run(); @@ -196,7 +196,7 @@ impl<'a> TomlTweaker<'a> { self.remove_missing_items("example"); self.remove_missing_items("test"); - self.remove_workspaces(); + self.remove_parent_workspaces(); self.remove_unwanted_cargo_features(); self.remove_dependencies(); self.apply_patches(); @@ -237,13 +237,9 @@ impl<'a> TomlTweaker<'a> { } } - fn remove_workspaces(&mut self) { + fn remove_parent_workspaces(&mut self) { let krate = self.krate.to_string(); - if self.table.remove("workspace").is_some() { - info!("removed workspace from {}", krate); - } - // Eliminate parent workspaces if let Some(&mut Value::Table(ref mut package)) = self.table.get_mut("package") { if package.remove("workspace").is_some() { @@ -467,6 +463,9 @@ mod tests { [target."cfg(unix)".dependencies] quux = { version = "1.0" } + + [workspace] + members = [] }; let krate = Crate::local("/dev/null".as_ref()); diff --git a/tests/buildtest/crates/cargo-workspace/Cargo.lock b/tests/buildtest/crates/cargo-workspace/Cargo.lock new file mode 100644 index 0000000..8bda135 --- /dev/null +++ b/tests/buildtest/crates/cargo-workspace/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "world" +version = "0.1.0" diff --git a/tests/buildtest/crates/cargo-workspace/Cargo.toml b/tests/buildtest/crates/cargo-workspace/Cargo.toml new file mode 100644 index 0000000..fd9cf16 --- /dev/null +++ b/tests/buildtest/crates/cargo-workspace/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["world"] \ No newline at end of file diff --git a/tests/buildtest/crates/cargo-workspace/world/Cargo.toml b/tests/buildtest/crates/cargo-workspace/world/Cargo.toml new file mode 100644 index 0000000..5e9837b --- /dev/null +++ b/tests/buildtest/crates/cargo-workspace/world/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "world" +version = "0.1.0" +authors = ["Skgland "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tests/buildtest/crates/cargo-workspace/world/src/main.rs b/tests/buildtest/crates/cargo-workspace/world/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/tests/buildtest/crates/cargo-workspace/world/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/tests/buildtest/mod.rs b/tests/buildtest/mod.rs index 2c52235..a76fa8a 100644 --- a/tests/buildtest/mod.rs +++ b/tests/buildtest/mod.rs @@ -97,6 +97,21 @@ fn test_cargo_config() { }); } +#[test] +fn test_cargo_workspace() { + runner::run("cargo-workspace", |run| { + run.build(SandboxBuilder::new().enable_networking(false), |build| { + let storage = rustwide::logging::LogStorage::new(LevelFilter::Info); + rustwide::logging::capture(&storage, || -> Result<_, Error> { + build.cargo().args(&["run"]).run()?; + Ok(()) + })?; + Ok(()) + })?; + Ok(()) + }); +} + test_prepare_error!( test_missing_cargotoml, "missing-cargotoml",