From 82326c93de98e1974e6b431b45f356ba52fb4318 Mon Sep 17 00:00:00 2001 From: Elliot Kennedy Date: Thu, 28 Sep 2023 22:26:58 +0100 Subject: [PATCH] Do not mask workspace dependencies with a source attribute - they are transitive and not sourced from the workspace --- src/skeleton/version_masking.rs | 2 +- tests/skeletons.rs | 202 ++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+), 1 deletion(-) diff --git a/src/skeleton/version_masking.rs b/src/skeleton/version_masking.rs index 5ead018..dfd79ae 100644 --- a/src/skeleton/version_masking.rs +++ b/src/skeleton/version_masking.rs @@ -36,7 +36,7 @@ fn mask_local_versions_in_lockfile( package .get("name") .map(|name| local_package_names.contains(name)) - .unwrap_or_default() + .unwrap_or_default() && package.get("source").is_none() }) // Mask the version .for_each(|package| { diff --git a/tests/skeletons.rs b/tests/skeletons.rs index b9a4d66..f2e12cf 100644 --- a/tests/skeletons.rs +++ b/tests/skeletons.rs @@ -736,6 +736,208 @@ version = "1.8.1" ); } +#[test] +pub fn transitive_workspace_dependency_not_masked() { + // Arrange + let project = CargoWorkspace::new() + .manifest( + ".", + r#" +[workspace] +members = [ + "src/project_a", + "src/project_b", +] +"#, + ) + .bin_package( + "src/project_a", + r#" +[package] +name = "project_a" +version = "2.2.2" +edition = "2018" + +[[bin]] +name = "test-dummy" +path = "src/main.rs" + +[dependencies] +either = { version = "=1.8.1" } +"#, + ) + .lib_package( + "src/project_b", + r#" +[package] +name = "project_b" +version = "5.5.5" +edition = "2018" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +"#, + ) + .file( + "Cargo.lock", + r#" +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +dependencies = [ + "project_b 5.5.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "project_a" +version = "2.2.2" +dependencies = [ + "either", +] + +[[package]] +name = "project_b" +version = "5.5.5" + +[[package]] +name = "project_b" +version = "5.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +"#, + ) + .build(); + + // Act + let skeleton = Skeleton::derive(project.path(), None).unwrap(); + let cook_directory = TempDir::new().unwrap(); + skeleton + .build_minimum_project(cook_directory.path(), false) + .unwrap(); + + // Assert + let lock_file = skeleton.lock_file.expect("there should be a lock_file"); + assert!(!lock_file.contains( + r#" +[[package]] +name = "project_a" +version = "2.2.2" +"# + )); + assert!(lock_file.contains( + r#" +[[package]] +name = "project_a" +version = "0.0.1" +"# + )); + assert!(lock_file.contains( + r#" +[[package]] +name = "project_b" +version = "5.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +"# + )); + assert!(lock_file.contains( + r#" +[[package]] +name = "project_b" +version = "0.0.1" +"# + )); + assert!(lock_file.contains( + r#" +[[package]] +name = "either" +version = "1.8.1" +"# + )); + + let first = skeleton.manifests[0].clone(); + check( + &first.contents, + expect_test::expect![[r#" + [workspace] + members = ["src/project_a", "src/project_b"] + "#]], + ); + let second = skeleton.manifests[1].clone(); + check( + &second.contents, + expect_test::expect![[r#" + bench = [] + test = [] + example = [] + + [[bin]] + path = "src/main.rs" + name = "test-dummy" + test = true + doctest = true + bench = true + doc = true + plugin = false + proc-macro = false + harness = true + required-features = [] + + [package] + name = "project_a" + edition = "2018" + version = "0.0.1" + autobins = true + autoexamples = true + autotests = true + autobenches = true + + [dependencies.either] + version = "=1.8.1" + "#]], + ); + let third = skeleton.manifests[2].clone(); + check( + &third.contents, + expect_test::expect![[r#" + bin = [] + bench = [] + test = [] + example = [] + + [package] + name = "project_b" + edition = "2018" + version = "0.0.1" + autobins = true + autoexamples = true + autotests = true + autobenches = true + + [dependencies] + + [lib] + test = true + doctest = true + bench = true + doc = true + plugin = false + proc-macro = false + harness = true + required-features = [] + crate-type = ["cdylib"] + "#]], + ); +} + #[test] pub fn ignore_vendored_directory() { // Arrange