From 95e1da2d1e79894b201d836d8a59bacecce3f5fd Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Aug 2024 11:48:47 -0500 Subject: [PATCH 1/5] test(vendor): Clarify what vendor config is used --- tests/testsuite/vendor.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index 4d151473490..d3462713cc0 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -35,7 +35,7 @@ fn vendor_simple() { let lock = p.read_file("vendor/log/Cargo.toml"); assert!(lock.contains("version = \"0.3.5\"")); - add_vendor_config(&p); + add_crates_io_vendor_config(&p); p.cargo("check").run(); } @@ -150,7 +150,7 @@ directory = "deps/.vendor" assert!(lock.contains("version = \"0.3.5\"")); } -fn add_vendor_config(p: &Project) { +fn add_crates_io_vendor_config(p: &Project) { p.change_file( ".cargo/config.toml", r#" @@ -247,7 +247,7 @@ fn two_versions() { let lock = p.read_file("vendor/bitflags-0.7.0/Cargo.toml"); assert!(lock.contains("version = \"0.7.0\"")); - add_vendor_config(&p); + add_crates_io_vendor_config(&p); p.cargo("check").run(); } @@ -292,7 +292,7 @@ fn two_explicit_versions() { let lock = p.read_file("vendor/bitflags-0.7.0/Cargo.toml"); assert!(lock.contains("version = \"0.7.0\"")); - add_vendor_config(&p); + add_crates_io_vendor_config(&p); p.cargo("check").run(); } @@ -385,7 +385,7 @@ fn two_lockfiles() { let lock = p.read_file("vendor/bitflags-0.7.0/Cargo.toml"); assert!(lock.contains("version = \"0.7.0\"")); - add_vendor_config(&p); + add_crates_io_vendor_config(&p); p.cargo("check").cwd("foo").run(); p.cargo("check").cwd("bar").run(); } @@ -642,7 +642,7 @@ fn vendoring_git_crates() { p.cargo("vendor --respect-source-config").run(); p.read_file("vendor/serde_derive/src/wut.rs"); - add_vendor_config(&p); + add_crates_io_vendor_config(&p); p.cargo("check").run(); } From 03633458a9e6865f94faa8b5dd046ab83a1268a0 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Aug 2024 11:25:14 -0500 Subject: [PATCH 2/5] test(vendor): Fork the package tests --- tests/testsuite/vendor.rs | 1049 ++++++++++++++++++++++++++++++++++++- 1 file changed, 1048 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index d3462713cc0..db639cfa965 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -4,10 +4,11 @@ //! "fake" crates.io is used. Otherwise `vendor` would download the crates.io //! index from the network. -use std::fs; +use std::fs::{self, File}; use cargo_test_support::compare::assert_e2e; use cargo_test_support::git; +use cargo_test_support::publish::validate_crate_contents; use cargo_test_support::registry::{self, Package, RegistryBuilder}; use cargo_test_support::str; use cargo_test_support::{basic_lib_manifest, basic_manifest, paths, project, Project}; @@ -207,6 +208,1052 @@ fn package_exclude() { assert!(!csum.contains(".dotdir/include")); } +#[cargo_test] +fn discovery_inferred_build_rs_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs", "build.rs"] + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 4 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "build.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = "build.rs" +include = [ + "src/lib.rs", + "build.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_build_rs_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs"] + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[WARNING] ignoring `package.build` as `build.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 3 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/lib.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_build_rs_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs", "build.rs"] + build = "build.rs" + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 4 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "build.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = "build.rs" +include = [ + "src/lib.rs", + "build.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_build_rs_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs"] + build = "build.rs" + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[WARNING] ignoring `package.build` as `build.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 3 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/lib.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_lib_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/main.rs", "src/lib.rs"] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 5 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "src/main.rs", + "src/lib.rs", + ], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = [ + "src/main.rs", + "src/lib.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" + +[[bin]] +name = "foo" +path = "src/main.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_lib_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/main.rs"] + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[WARNING] ignoring library `foo` as `src/lib.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 4 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/main.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[[bin]] +name = "foo" +path = "src/main.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_lib_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/main.rs", "src/lib.rs"] + + [lib] + path = "src/lib.rs" + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 5 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "src/main.rs", + "src/lib.rs", + ], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = [ + "src/main.rs", + "src/lib.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" + +[[bin]] +name = "foo" +path = "src/main.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_lib_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/main.rs"] + + [lib] + path = "src/lib.rs" + "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[WARNING] ignoring library `foo` as `src/lib.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 4 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/main.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[[bin]] +name = "foo" +path = "src/main.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_other_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs", "src/bin/foo/main.rs", "examples/example_foo.rs", "tests/test_foo.rs", "benches/bench_foo.rs"] + "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 8 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "src/lib.rs", + "src/bin/foo/main.rs", + "examples/example_foo.rs", + "tests/test_foo.rs", + "benches/bench_foo.rs", + ], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = [ + "src/lib.rs", + "src/bin/foo/main.rs", + "examples/example_foo.rs", + "tests/test_foo.rs", + "benches/bench_foo.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" + +[[bin]] +name = "foo" +path = "src/bin/foo/main.rs" + +[[example]] +name = "example_foo" +path = "examples/example_foo.rs" + +[[test]] +name = "test_foo" +path = "tests/test_foo.rs" + +[[bench]] +name = "bench_foo" +path = "benches/bench_foo.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_inferred_other_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs"] + "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr(r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[WARNING] ignoring binary `foo` as `src/bin/foo/main.rs` is not included in the published package +[WARNING] ignoring example `example_foo` as `examples/example_foo.rs` is not included in the published package +[WARNING] ignoring test `test_foo` as `tests/test_foo.rs` is not included in the published package +[WARNING] ignoring benchmark `bench_foo` as `benches/bench_foo.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 4 files, [..]B ([..]B compressed) +"#) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/lib.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_other_included() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs", "src/bin/foo/main.rs", "examples/example_foo.rs", "tests/test_foo.rs", "benches/bench_foo.rs"] + + [[bin]] + name = "foo" + + [[example]] + name = "example_foo" + + [[test]] + name = "test_foo" + + [[bench]] + name = "bench_foo" + "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr( + r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 8 files, [..]B ([..]B compressed) +"#, + ) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &[ + "Cargo.lock", + "Cargo.toml", + "Cargo.toml.orig", + "src/lib.rs", + "src/bin/foo/main.rs", + "examples/example_foo.rs", + "tests/test_foo.rs", + "benches/bench_foo.rs", + ], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = [ + "src/lib.rs", + "src/bin/foo/main.rs", + "examples/example_foo.rs", + "tests/test_foo.rs", + "benches/bench_foo.rs", +] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" + +[[bin]] +name = "foo" +path = "src/bin/foo/main.rs" + +[[example]] +name = "example_foo" +path = "examples/example_foo.rs" + +[[test]] +name = "test_foo" +path = "tests/test_foo.rs" + +[[bench]] +name = "bench_foo" +path = "benches/bench_foo.rs" +"#, + )], + ); +} + +#[cargo_test] +fn discovery_explicit_other_excluded() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + license = "MIT" + description = "foo" + documentation = "docs.rs/foo" + authors = [] + include = ["src/lib.rs"] + + [[main]] + name = "foo" + + [[example]] + name = "example_foo" + + [[test]] + name = "test_foo" + + [[bench]] + name = "bench_foo" + "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + .build(); + + p.cargo("package") + .with_stdout("") + .with_stderr(r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[WARNING] ignoring binary `foo` as `src/bin/foo/main.rs` is not included in the published package +[WARNING] ignoring example `example_foo` as `examples/example_foo.rs` is not included in the published package +[WARNING] ignoring test `test_foo` as `tests/test_foo.rs` is not included in the published package +[WARNING] ignoring benchmark `bench_foo` as `benches/bench_foo.rs` is not included in the published package +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[PACKAGED] 4 files, [..]B ([..]B compressed) +"#) + .run(); + + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], + &[( + "Cargo.toml", + r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2015" +name = "foo" +version = "0.0.1" +authors = [] +build = false +include = ["src/lib.rs"] +autobins = false +autoexamples = false +autotests = false +autobenches = false +description = "foo" +documentation = "docs.rs/foo" +readme = false +license = "MIT" + +[lib] +name = "foo" +path = "src/lib.rs" +"#, + )], + ); +} + #[cargo_test] fn two_versions() { let p = project() From f53849eb710d14df84067d40f1796b8bf78e0b81 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Aug 2024 11:36:23 -0500 Subject: [PATCH 3/5] test(vendor): Drop explicitlu specified build-target cases Since we already cover this for `cargo package` and we turn all implicit targets into explicit targets (making implicit tests cover explicit cases), this becomes redundant. --- tests/testsuite/vendor.rs | 543 +------------------------------------- 1 file changed, 2 insertions(+), 541 deletions(-) diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index db639cfa965..eabdab747fd 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -363,327 +363,7 @@ path = "src/lib.rs" } #[cargo_test] -fn discovery_explicit_build_rs_included() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - license = "MIT" - description = "foo" - documentation = "docs.rs/foo" - authors = [] - include = ["src/lib.rs", "build.rs"] - build = "build.rs" - "#, - ) - .file("src/lib.rs", "") - .file("build.rs", "fn main() {}") - .build(); - - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 4 files, [..]B ([..]B compressed) -"#, - ) - .run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "build.rs"], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. -# -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. - -[package] -edition = "2015" -name = "foo" -version = "0.0.1" -authors = [] -build = "build.rs" -include = [ - "src/lib.rs", - "build.rs", -] -autobins = false -autoexamples = false -autotests = false -autobenches = false -description = "foo" -documentation = "docs.rs/foo" -readme = false -license = "MIT" - -[lib] -name = "foo" -path = "src/lib.rs" -"#, - )], - ); -} - -#[cargo_test] -fn discovery_explicit_build_rs_excluded() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - license = "MIT" - description = "foo" - documentation = "docs.rs/foo" - authors = [] - include = ["src/lib.rs"] - build = "build.rs" - "#, - ) - .file("src/lib.rs", "") - .file("build.rs", "fn main() {}") - .build(); - - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[WARNING] ignoring `package.build` as `build.rs` is not included in the published package -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 3 files, [..]B ([..]B compressed) -"#, - ) - .run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. -# -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. - -[package] -edition = "2015" -name = "foo" -version = "0.0.1" -authors = [] -build = false -include = ["src/lib.rs"] -autobins = false -autoexamples = false -autotests = false -autobenches = false -description = "foo" -documentation = "docs.rs/foo" -readme = false -license = "MIT" - -[lib] -name = "foo" -path = "src/lib.rs" -"#, - )], - ); -} - -#[cargo_test] -fn discovery_inferred_lib_included() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - license = "MIT" - description = "foo" - documentation = "docs.rs/foo" - authors = [] - include = ["src/main.rs", "src/lib.rs"] - "#, - ) - .file("src/main.rs", "fn main() {}") - .file("src/lib.rs", "") - .build(); - - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 5 files, [..]B ([..]B compressed) -"#, - ) - .run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &[ - "Cargo.lock", - "Cargo.toml", - "Cargo.toml.orig", - "src/main.rs", - "src/lib.rs", - ], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. -# -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. - -[package] -edition = "2015" -name = "foo" -version = "0.0.1" -authors = [] -build = false -include = [ - "src/main.rs", - "src/lib.rs", -] -autobins = false -autoexamples = false -autotests = false -autobenches = false -description = "foo" -documentation = "docs.rs/foo" -readme = false -license = "MIT" - -[lib] -name = "foo" -path = "src/lib.rs" - -[[bin]] -name = "foo" -path = "src/main.rs" -"#, - )], - ); -} - -#[cargo_test] -fn discovery_inferred_lib_excluded() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - license = "MIT" - description = "foo" - documentation = "docs.rs/foo" - authors = [] - include = ["src/main.rs"] - "#, - ) - .file("src/main.rs", "fn main() {}") - .file("src/lib.rs", "") - .build(); - - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[WARNING] ignoring library `foo` as `src/lib.rs` is not included in the published package -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 4 files, [..]B ([..]B compressed) -"#, - ) - .run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. -# -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. - -[package] -edition = "2015" -name = "foo" -version = "0.0.1" -authors = [] -build = false -include = ["src/main.rs"] -autobins = false -autoexamples = false -autotests = false -autobenches = false -description = "foo" -documentation = "docs.rs/foo" -readme = false -license = "MIT" - -[[bin]] -name = "foo" -path = "src/main.rs" -"#, - )], - ); -} - -#[cargo_test] -fn discovery_explicit_lib_included() { +fn discovery_inferred_lib_included() { let p = project() .file( "Cargo.toml", @@ -697,9 +377,6 @@ fn discovery_explicit_lib_included() { documentation = "docs.rs/foo" authors = [] include = ["src/main.rs", "src/lib.rs"] - - [lib] - path = "src/lib.rs" "#, ) .file("src/main.rs", "fn main() {}") @@ -774,7 +451,7 @@ path = "src/main.rs" } #[cargo_test] -fn discovery_explicit_lib_excluded() { +fn discovery_inferred_lib_excluded() { let p = project() .file( "Cargo.toml", @@ -788,9 +465,6 @@ fn discovery_explicit_lib_excluded() { documentation = "docs.rs/foo" authors = [] include = ["src/main.rs"] - - [lib] - path = "src/lib.rs" "#, ) .file("src/main.rs", "fn main() {}") @@ -1041,219 +715,6 @@ path = "src/lib.rs" ); } -#[cargo_test] -fn discovery_explicit_other_included() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - license = "MIT" - description = "foo" - documentation = "docs.rs/foo" - authors = [] - include = ["src/lib.rs", "src/bin/foo/main.rs", "examples/example_foo.rs", "tests/test_foo.rs", "benches/bench_foo.rs"] - - [[bin]] - name = "foo" - - [[example]] - name = "example_foo" - - [[test]] - name = "test_foo" - - [[bench]] - name = "bench_foo" - "#, - ) - .file("src/lib.rs", "") - .file("src/bin/foo/main.rs", "fn main() {}") - .file("examples/example_foo.rs", "fn main() {}") - .file("tests/test_foo.rs", "fn main() {}") - .file("benches/bench_foo.rs", "fn main() {}") - .build(); - - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 8 files, [..]B ([..]B compressed) -"#, - ) - .run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &[ - "Cargo.lock", - "Cargo.toml", - "Cargo.toml.orig", - "src/lib.rs", - "src/bin/foo/main.rs", - "examples/example_foo.rs", - "tests/test_foo.rs", - "benches/bench_foo.rs", - ], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. -# -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. - -[package] -edition = "2015" -name = "foo" -version = "0.0.1" -authors = [] -build = false -include = [ - "src/lib.rs", - "src/bin/foo/main.rs", - "examples/example_foo.rs", - "tests/test_foo.rs", - "benches/bench_foo.rs", -] -autobins = false -autoexamples = false -autotests = false -autobenches = false -description = "foo" -documentation = "docs.rs/foo" -readme = false -license = "MIT" - -[lib] -name = "foo" -path = "src/lib.rs" - -[[bin]] -name = "foo" -path = "src/bin/foo/main.rs" - -[[example]] -name = "example_foo" -path = "examples/example_foo.rs" - -[[test]] -name = "test_foo" -path = "tests/test_foo.rs" - -[[bench]] -name = "bench_foo" -path = "benches/bench_foo.rs" -"#, - )], - ); -} - -#[cargo_test] -fn discovery_explicit_other_excluded() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.0.1" - edition = "2015" - license = "MIT" - description = "foo" - documentation = "docs.rs/foo" - authors = [] - include = ["src/lib.rs"] - - [[main]] - name = "foo" - - [[example]] - name = "example_foo" - - [[test]] - name = "test_foo" - - [[bench]] - name = "bench_foo" - "#, - ) - .file("src/lib.rs", "") - .file("src/bin/foo/main.rs", "fn main() {}") - .file("examples/example_foo.rs", "fn main() {}") - .file("tests/test_foo.rs", "fn main() {}") - .file("benches/bench_foo.rs", "fn main() {}") - .build(); - - p.cargo("package") - .with_stdout("") - .with_stderr(r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[WARNING] ignoring binary `foo` as `src/bin/foo/main.rs` is not included in the published package -[WARNING] ignoring example `example_foo` as `examples/example_foo.rs` is not included in the published package -[WARNING] ignoring test `test_foo` as `tests/test_foo.rs` is not included in the published package -[WARNING] ignoring benchmark `bench_foo` as `benches/bench_foo.rs` is not included in the published package -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 4 files, [..]B ([..]B compressed) -"#) - .run(); - - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO -# -# When uploading crates to the registry Cargo will automatically -# "normalize" Cargo.toml files for maximal compatibility -# with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies. -# -# If you are reading this file be aware that the original Cargo.toml -# will likely look very different (and much more reasonable). -# See Cargo.toml.orig for the original contents. - -[package] -edition = "2015" -name = "foo" -version = "0.0.1" -authors = [] -build = false -include = ["src/lib.rs"] -autobins = false -autoexamples = false -autotests = false -autobenches = false -description = "foo" -documentation = "docs.rs/foo" -readme = false -license = "MIT" - -[lib] -name = "foo" -path = "src/lib.rs" -"#, - )], - ); -} - #[cargo_test] fn two_versions() { let p = project() From 999195c65b796c9e2f05260f41dbf6bdc032bd64 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Aug 2024 11:47:40 -0500 Subject: [PATCH 4/5] test(vendor): Port 'package' tests to 'vendor' --- tests/testsuite/vendor.rs | 511 +++++++++++++++++++++++--------------- 1 file changed, 312 insertions(+), 199 deletions(-) diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index eabdab747fd..f7665e6d396 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -4,11 +4,10 @@ //! "fake" crates.io is used. Otherwise `vendor` would download the crates.io //! index from the network. -use std::fs::{self, File}; +use std::fs; use cargo_test_support::compare::assert_e2e; use cargo_test_support::git; -use cargo_test_support::publish::validate_crate_contents; use cargo_test_support::registry::{self, Package, RegistryBuilder}; use cargo_test_support::str; use cargo_test_support::{basic_lib_manifest, basic_manifest, paths, project, Project}; @@ -164,6 +163,23 @@ fn add_crates_io_vendor_config(p: &Project) { ); } +fn add_git_vendor_config(p: &Project, git_project: &Project) { + p.change_file( + ".cargo/config.toml", + &format!( + r#" + [source."git+{url}"] + git = "{url}" + replace-with = 'vendor' + + [source.vendor] + directory = 'vendor' + "#, + url = git_project.url() + ), + ); +} + #[cargo_test] fn package_exclude() { let p = project() @@ -210,12 +226,13 @@ fn package_exclude() { #[cargo_test] fn discovery_inferred_build_rs_included() { - let p = project() - .file( - "Cargo.toml", - r#" + let git_project = git::new("dep", |project| { + project + .file( + "Cargo.toml", + r#" [package] - name = "foo" + name = "dep" version = "0.0.1" edition = "2015" license = "MIT" @@ -224,31 +241,38 @@ fn discovery_inferred_build_rs_included() { authors = [] include = ["src/lib.rs", "build.rs"] "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + }); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + + [dependencies.dep] + git = '{}' + "#, + git_project.url() + ), ) - .file("src/lib.rs", "") - .file("build.rs", "fn main() {}") + .file("src/main.rs", "fn main() {}") .build(); - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 4 files, [..]B ([..]B compressed) -"#, - ) - .run(); + p.cargo("vendor --respect-source-config").run(); + add_git_vendor_config(&p, &git_project); - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs", "build.rs"], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + let lock = p.read_file("vendor/dep/Cargo.toml"); + assert_e2e().eq( + lock, + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -259,9 +283,14 @@ fn discovery_inferred_build_rs_included() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. +bin = [] +example = [] +test = [] +bench = [] + [package] edition = "2015" -name = "foo" +name = "dep" version = "0.0.1" authors = [] build = "build.rs" @@ -279,21 +308,24 @@ readme = false license = "MIT" [lib] -name = "foo" +name = "dep" path = "src/lib.rs" -"#, - )], + +"##]], ); + + p.cargo("check").run(); } #[cargo_test] fn discovery_inferred_build_rs_excluded() { - let p = project() - .file( - "Cargo.toml", - r#" + let git_project = git::new("dep", |project| { + project + .file( + "Cargo.toml", + r#" [package] - name = "foo" + name = "dep" version = "0.0.1" edition = "2015" license = "MIT" @@ -302,32 +334,38 @@ fn discovery_inferred_build_rs_excluded() { authors = [] include = ["src/lib.rs"] "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + }); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + + [dependencies.dep] + git = '{}' + "#, + git_project.url() + ), ) - .file("src/lib.rs", "") - .file("build.rs", "fn main() {}") + .file("src/main.rs", "fn main() {}") .build(); - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[WARNING] ignoring `package.build` as `build.rs` is not included in the published package -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 3 files, [..]B ([..]B compressed) -"#, - ) - .run(); + p.cargo("vendor --respect-source-config").run(); + add_git_vendor_config(&p, &git_project); - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + let lock = p.read_file("vendor/dep/Cargo.toml"); + assert_e2e().eq( + lock, + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -338,12 +376,17 @@ fn discovery_inferred_build_rs_excluded() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. +bin = [] +example = [] +test = [] +bench = [] + [package] edition = "2015" -name = "foo" +name = "dep" version = "0.0.1" authors = [] -build = false +build = "build.rs" include = ["src/lib.rs"] autobins = false autoexamples = false @@ -355,21 +398,33 @@ readme = false license = "MIT" [lib] -name = "foo" +name = "dep" path = "src/lib.rs" -"#, - )], + +"##]], ); + + p.cargo("check") + .with_status(101) + .with_stderr( + r#"[COMPILING] dep v0.0.1 ([..]/dep#[..]) +[ERROR] couldn't read [ROOT]/foo/vendor/dep/build.rs: [..] + +[ERROR] could not compile `dep` (build script) due to 1 previous error +"#, + ) + .run(); } #[cargo_test] fn discovery_inferred_lib_included() { - let p = project() - .file( - "Cargo.toml", - r#" + let git_project = git::new("dep", |project| { + project + .file( + "Cargo.toml", + r#" [package] - name = "foo" + name = "dep" version = "0.0.1" edition = "2015" license = "MIT" @@ -378,37 +433,38 @@ fn discovery_inferred_lib_included() { authors = [] include = ["src/main.rs", "src/lib.rs"] "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + }); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + + [dependencies.dep] + git = '{}' + "#, + git_project.url() + ), ) .file("src/main.rs", "fn main() {}") - .file("src/lib.rs", "") .build(); - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 5 files, [..]B ([..]B compressed) -"#, - ) - .run(); + p.cargo("vendor --respect-source-config").run(); + add_git_vendor_config(&p, &git_project); - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &[ - "Cargo.lock", - "Cargo.toml", - "Cargo.toml.orig", - "src/main.rs", - "src/lib.rs", - ], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + let lock = p.read_file("vendor/dep/Cargo.toml"); + assert_e2e().eq( + lock, + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -419,9 +475,13 @@ fn discovery_inferred_lib_included() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. +example = [] +test = [] +bench = [] + [package] edition = "2015" -name = "foo" +name = "dep" version = "0.0.1" authors = [] build = false @@ -439,25 +499,28 @@ readme = false license = "MIT" [lib] -name = "foo" +name = "dep" path = "src/lib.rs" [[bin]] -name = "foo" +name = "dep" path = "src/main.rs" -"#, - )], + +"##]], ); + + p.cargo("check").run(); } #[cargo_test] fn discovery_inferred_lib_excluded() { - let p = project() - .file( - "Cargo.toml", - r#" + let git_project = git::new("dep", |project| { + project + .file( + "Cargo.toml", + r#" [package] - name = "foo" + name = "dep" version = "0.0.1" edition = "2015" license = "MIT" @@ -466,32 +529,38 @@ fn discovery_inferred_lib_excluded() { authors = [] include = ["src/main.rs"] "#, + ) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "") + }); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + + [dependencies.dep] + git = '{}' + "#, + git_project.url() + ), ) .file("src/main.rs", "fn main() {}") - .file("src/lib.rs", "") .build(); - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[WARNING] ignoring library `foo` as `src/lib.rs` is not included in the published package -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 4 files, [..]B ([..]B compressed) -"#, - ) - .run(); + p.cargo("vendor --respect-source-config").run(); + add_git_vendor_config(&p, &git_project); - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + let lock = p.read_file("vendor/dep/Cargo.toml"); + assert_e2e().eq( + lock, + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -502,9 +571,13 @@ fn discovery_inferred_lib_excluded() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. +example = [] +test = [] +bench = [] + [package] edition = "2015" -name = "foo" +name = "dep" version = "0.0.1" authors = [] build = false @@ -518,22 +591,38 @@ documentation = "docs.rs/foo" readme = false license = "MIT" +[lib] +name = "dep" +path = "src/lib.rs" + [[bin]] -name = "foo" +name = "dep" path = "src/main.rs" -"#, - )], + +"##]], ); + + p.cargo("check") + .with_status(101) + .with_stderr( + r#"[CHECKING] dep v0.0.1 ([..]/dep#[..]) +[ERROR] couldn't read [ROOT]/foo/vendor/dep/src/lib.rs: [..] + +[ERROR] could not compile `dep` (lib) due to 1 previous error +"#, + ) + .run(); } #[cargo_test] fn discovery_inferred_other_included() { - let p = project() + let git_project = git::new("dep", |project| { + project .file( "Cargo.toml", r#" [package] - name = "foo" + name = "dep" version = "0.0.1" edition = "2015" license = "MIT" @@ -548,37 +637,35 @@ fn discovery_inferred_other_included() { .file("examples/example_foo.rs", "fn main() {}") .file("tests/test_foo.rs", "fn main() {}") .file("benches/bench_foo.rs", "fn main() {}") - .build(); + }); - p.cargo("package") - .with_stdout("") - .with_stderr( - r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 8 files, [..]B ([..]B compressed) -"#, + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + + [dependencies.dep] + git = '{}' + "#, + git_project.url() + ), ) - .run(); + .file("src/main.rs", "fn main() {}") + .build(); - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &[ - "Cargo.lock", - "Cargo.toml", - "Cargo.toml.orig", - "src/lib.rs", - "src/bin/foo/main.rs", - "examples/example_foo.rs", - "tests/test_foo.rs", - "benches/bench_foo.rs", - ], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + p.cargo("vendor --respect-source-config").run(); + add_git_vendor_config(&p, &git_project); + + let lock = p.read_file("vendor/dep/Cargo.toml"); + assert_e2e().eq( + lock, + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -591,7 +678,7 @@ fn discovery_inferred_other_included() { [package] edition = "2015" -name = "foo" +name = "dep" version = "0.0.1" authors = [] build = false @@ -612,7 +699,7 @@ readme = false license = "MIT" [lib] -name = "foo" +name = "dep" path = "src/lib.rs" [[bin]] @@ -630,19 +717,22 @@ path = "tests/test_foo.rs" [[bench]] name = "bench_foo" path = "benches/bench_foo.rs" -"#, - )], + +"##]], ); + + p.cargo("check").run(); } #[cargo_test] fn discovery_inferred_other_excluded() { - let p = project() - .file( - "Cargo.toml", - r#" + let git_project = git::new("dep", |project| { + project + .file( + "Cargo.toml", + r#" [package] - name = "foo" + name = "dep" version = "0.0.1" edition = "2015" license = "MIT" @@ -651,36 +741,41 @@ fn discovery_inferred_other_excluded() { authors = [] include = ["src/lib.rs"] "#, + ) + .file("src/lib.rs", "") + .file("src/bin/foo/main.rs", "fn main() {}") + .file("examples/example_foo.rs", "fn main() {}") + .file("tests/test_foo.rs", "fn main() {}") + .file("benches/bench_foo.rs", "fn main() {}") + }); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + + [dependencies.dep] + git = '{}' + "#, + git_project.url() + ), ) - .file("src/lib.rs", "") - .file("src/bin/foo/main.rs", "fn main() {}") - .file("examples/example_foo.rs", "fn main() {}") - .file("tests/test_foo.rs", "fn main() {}") - .file("benches/bench_foo.rs", "fn main() {}") + .file("src/main.rs", "fn main() {}") .build(); - p.cargo("package") - .with_stdout("") - .with_stderr(r#"[PACKAGING] foo v0.0.1 ([ROOT]/foo) -[WARNING] ignoring binary `foo` as `src/bin/foo/main.rs` is not included in the published package -[WARNING] ignoring example `example_foo` as `examples/example_foo.rs` is not included in the published package -[WARNING] ignoring test `test_foo` as `tests/test_foo.rs` is not included in the published package -[WARNING] ignoring benchmark `bench_foo` as `benches/bench_foo.rs` is not included in the published package -[VERIFYING] foo v0.0.1 ([ROOT]/foo) -[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s -[PACKAGED] 4 files, [..]B ([..]B compressed) -"#) - .run(); + p.cargo("vendor --respect-source-config").run(); + add_git_vendor_config(&p, &git_project); - let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap(); - validate_crate_contents( - f, - "foo-0.0.1.crate", - &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"], - &[( - "Cargo.toml", - r#"# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO + let lock = p.read_file("vendor/dep/Cargo.toml"); + assert_e2e().eq( + lock, + str![[r##" +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility @@ -693,7 +788,7 @@ fn discovery_inferred_other_excluded() { [package] edition = "2015" -name = "foo" +name = "dep" version = "0.0.1" authors = [] build = false @@ -708,11 +803,29 @@ readme = false license = "MIT" [lib] -name = "foo" +name = "dep" path = "src/lib.rs" -"#, - )], + +[[bin]] +name = "foo" +path = "src/bin/foo/main.rs" + +[[example]] +name = "example_foo" +path = "examples/example_foo.rs" + +[[test]] +name = "test_foo" +path = "tests/test_foo.rs" + +[[bench]] +name = "bench_foo" +path = "benches/bench_foo.rs" + +"##]], ); + + p.cargo("check").run(); } #[cargo_test] From e3a711f5cd4e785dff224afde1eed473f2080737 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 7 Aug 2024 12:27:37 -0500 Subject: [PATCH 5/5] fix(vendor): Strip excluded build targets This is a **very** hacky solution, duplicating the minimum of what `prepare_for_publish` does to fix this one issue and in the least intrusive way to the vendor code. The intention is to keep this low risk for backporting to beta and stable. We need to revisit this, refactoring the `cargo package` code so that we can call into that for each vendored dependency. Fixes #14348 --- src/cargo/ops/vendor.rs | 115 ++++++++++++++++++++++++++++++++++++- src/cargo/util/toml/mod.rs | 8 +-- tests/testsuite/vendor.rs | 68 ++-------------------- 3 files changed, 121 insertions(+), 70 deletions(-) diff --git a/src/cargo/ops/vendor.rs b/src/cargo/ops/vendor.rs index 5c83198f2c7..d2169f591a0 100644 --- a/src/cargo/ops/vendor.rs +++ b/src/cargo/ops/vendor.rs @@ -220,7 +220,7 @@ fn sync( let pathsource = PathSource::new(src, id.source_id(), gctx); let paths = pathsource.list_files(pkg)?; let mut map = BTreeMap::new(); - cp_sources(pkg, src, &paths, &dst, &mut map, &mut tmp_buf) + cp_sources(pkg, src, &paths, &dst, &mut map, &mut tmp_buf, gctx) .with_context(|| format!("failed to copy over vendored sources for: {}", id))?; // Finally, emit the metadata about this package @@ -316,6 +316,7 @@ fn cp_sources( dst: &Path, cksums: &mut BTreeMap, tmp_buf: &mut [u8], + gctx: &GlobalContext, ) -> CargoResult<()> { for p in paths { let relative = p.strip_prefix(&src).unwrap(); @@ -359,7 +360,12 @@ fn cp_sources( let cksum = if dst.file_name() == Some(OsStr::new("Cargo.toml")) && pkg.package_id().source_id().is_git() { - let contents = pkg.manifest().to_resolved_contents()?; + let packaged_files = paths + .iter() + .map(|p| p.strip_prefix(src).unwrap().to_owned()) + .collect::>(); + let vendored_pkg = prepare_for_vendor(pkg, &packaged_files, gctx)?; + let contents = vendored_pkg.manifest().to_resolved_contents()?; copy_and_checksum( &dst, &mut dst_opts, @@ -391,6 +397,111 @@ fn cp_sources( Ok(()) } +/// HACK: Perform the bare minimum of `prepare_for_publish` needed for #14348. +/// +/// There are parts of `prepare_for_publish` that could be directly useful (e.g. stripping +/// `[workspace]`) while other parts that require other filesystem operations (moving the README +/// file) and ideally we'd reuse `cargo package` code to take care of all of this for us. +fn prepare_for_vendor( + me: &Package, + packaged_files: &[PathBuf], + gctx: &GlobalContext, +) -> CargoResult { + let contents = me.manifest().contents(); + let document = me.manifest().document(); + let original_toml = + prepare_toml_for_vendor(me.manifest().resolved_toml().clone(), packaged_files, gctx)?; + let normalized_toml = original_toml.clone(); + let features = me.manifest().unstable_features().clone(); + let workspace_config = me.manifest().workspace_config().clone(); + let source_id = me.package_id().source_id(); + let mut warnings = Default::default(); + let mut errors = Default::default(); + let manifest = crate::util::toml::to_real_manifest( + contents.to_owned(), + document.clone(), + original_toml, + normalized_toml, + features, + workspace_config, + source_id, + me.manifest_path(), + gctx, + &mut warnings, + &mut errors, + )?; + let new_pkg = Package::new(manifest, me.manifest_path()); + Ok(new_pkg) +} + +fn prepare_toml_for_vendor( + mut me: cargo_util_schemas::manifest::TomlManifest, + packaged_files: &[PathBuf], + gctx: &GlobalContext, +) -> CargoResult { + let package = me + .package + .as_mut() + .expect("venedored manifests must have packages"); + if let Some(cargo_util_schemas::manifest::StringOrBool::String(path)) = &package.build { + let path = paths::normalize_path(Path::new(path)); + let included = packaged_files.contains(&path); + let build = if included { + let path = path + .into_os_string() + .into_string() + .map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?; + let path = crate::util::toml::normalize_path_string_sep(path); + cargo_util_schemas::manifest::StringOrBool::String(path) + } else { + gctx.shell().warn(format!( + "ignoring `package.build` as `{}` is not included in the published package", + path.display() + ))?; + cargo_util_schemas::manifest::StringOrBool::Bool(false) + }; + package.build = Some(build); + } + + let lib = if let Some(target) = &me.lib { + crate::util::toml::prepare_target_for_publish(target, packaged_files, "library", gctx)? + } else { + None + }; + let bin = crate::util::toml::prepare_targets_for_publish( + me.bin.as_ref(), + packaged_files, + "binary", + gctx, + )?; + let example = crate::util::toml::prepare_targets_for_publish( + me.example.as_ref(), + packaged_files, + "example", + gctx, + )?; + let test = crate::util::toml::prepare_targets_for_publish( + me.test.as_ref(), + packaged_files, + "test", + gctx, + )?; + let bench = crate::util::toml::prepare_targets_for_publish( + me.bench.as_ref(), + packaged_files, + "benchmark", + gctx, + )?; + + me.lib = lib; + me.bin = bin; + me.example = example; + me.test = test; + me.bench = bench; + + Ok(me) +} + fn copy_and_checksum( dst_path: &Path, dst_opts: &mut OpenOptions, diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 088dd0196ad..62278660a1b 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1068,7 +1068,7 @@ fn deprecated_ws_default_features( } #[tracing::instrument(skip_all)] -fn to_real_manifest( +pub fn to_real_manifest( contents: String, document: toml_edit::ImDocument, original_toml: manifest::TomlManifest, @@ -2760,7 +2760,7 @@ fn prepare_toml_for_publish( } } -fn prepare_targets_for_publish( +pub fn prepare_targets_for_publish( targets: Option<&Vec>, included: &[PathBuf], context: &str, @@ -2785,7 +2785,7 @@ fn prepare_targets_for_publish( } } -fn prepare_target_for_publish( +pub fn prepare_target_for_publish( target: &manifest::TomlTarget, included: &[PathBuf], context: &str, @@ -2818,7 +2818,7 @@ fn normalize_path_sep(path: PathBuf, context: &str) -> CargoResult { Ok(path.into()) } -fn normalize_path_string_sep(path: String) -> String { +pub fn normalize_path_string_sep(path: String) -> String { if std::path::MAIN_SEPARATOR != '/' { path.replace(std::path::MAIN_SEPARATOR, "/") } else { diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index f7665e6d396..a5f60a32e5d 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -283,11 +283,6 @@ fn discovery_inferred_build_rs_included() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. -bin = [] -example = [] -test = [] -bench = [] - [package] edition = "2015" name = "dep" @@ -376,17 +371,12 @@ fn discovery_inferred_build_rs_excluded() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. -bin = [] -example = [] -test = [] -bench = [] - [package] edition = "2015" name = "dep" version = "0.0.1" authors = [] -build = "build.rs" +build = false include = ["src/lib.rs"] autobins = false autoexamples = false @@ -404,16 +394,7 @@ path = "src/lib.rs" "##]], ); - p.cargo("check") - .with_status(101) - .with_stderr( - r#"[COMPILING] dep v0.0.1 ([..]/dep#[..]) -[ERROR] couldn't read [ROOT]/foo/vendor/dep/build.rs: [..] - -[ERROR] could not compile `dep` (build script) due to 1 previous error -"#, - ) - .run(); + p.cargo("check").run(); } #[cargo_test] @@ -475,10 +456,6 @@ fn discovery_inferred_lib_included() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. -example = [] -test = [] -bench = [] - [package] edition = "2015" name = "dep" @@ -571,10 +548,6 @@ fn discovery_inferred_lib_excluded() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. -example = [] -test = [] -bench = [] - [package] edition = "2015" name = "dep" @@ -591,10 +564,6 @@ documentation = "docs.rs/foo" readme = false license = "MIT" -[lib] -name = "dep" -path = "src/lib.rs" - [[bin]] name = "dep" path = "src/main.rs" @@ -602,16 +571,7 @@ path = "src/main.rs" "##]], ); - p.cargo("check") - .with_status(101) - .with_stderr( - r#"[CHECKING] dep v0.0.1 ([..]/dep#[..]) -[ERROR] couldn't read [ROOT]/foo/vendor/dep/src/lib.rs: [..] - -[ERROR] could not compile `dep` (lib) due to 1 previous error -"#, - ) - .run(); + p.cargo("check").run(); } #[cargo_test] @@ -806,22 +766,6 @@ license = "MIT" name = "dep" path = "src/lib.rs" -[[bin]] -name = "foo" -path = "src/bin/foo/main.rs" - -[[example]] -name = "example_foo" -path = "examples/example_foo.rs" - -[[test]] -name = "test_foo" -path = "tests/test_foo.rs" - -[[bench]] -name = "bench_foo" -path = "benches/bench_foo.rs" - "##]], ); @@ -1559,10 +1503,6 @@ fn git_deterministic() { # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. -bin = [] -test = [] -bench = [] - [package] edition = "2021" name = "git_dep" @@ -1580,7 +1520,7 @@ license = "MIT" [lib] name = "git_dep" -path = [..] +path = "src/lib.rs" [[example]] name = "a"