Skip to content
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

Allow workspaces #42

Merged
merged 4 commits into from
Sep 7, 2020
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -467,6 +463,9 @@ mod tests {

[target."cfg(unix)".dependencies]
quux = { version = "1.0" }

[workspace]
members = []
};

let krate = Crate::local("/dev/null".as_ref());
Expand Down
5 changes: 5 additions & 0 deletions tests/buildtest/crates/cargo-workspace/Cargo.lock

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

2 changes: 2 additions & 0 deletions tests/buildtest/crates/cargo-workspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[workspace]
members = ["world"]
9 changes: 9 additions & 0 deletions tests/buildtest/crates/cargo-workspace/world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "world"
version = "0.1.0"
authors = ["Skgland <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
3 changes: 3 additions & 0 deletions tests/buildtest/crates/cargo-workspace/world/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
15 changes: 15 additions & 0 deletions tests/buildtest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down