From c428c0ef41c19fa5b181847bed932ffc50d31538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Mon, 6 Apr 2020 23:37:06 +0200 Subject: [PATCH 01/30] Use associated constants directly on primitive types instead of modules --- crates/cargo-test-support/src/lib.rs | 1 - crates/resolver-tests/tests/resolve.rs | 2 +- src/cargo/core/resolver/conflict_cache.rs | 2 +- tests/testsuite/standard_lib.rs | 2 +- tests/testsuite/test.rs | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index ef69f852e..ac53db0df 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -118,7 +118,6 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Output}; use std::str; use std::time::{self, Duration}; -use std::usize; use cargo::util::{is_ci, CargoResult, ProcessBuilder, ProcessError, Rustc}; use serde_json::{self, Value}; diff --git a/crates/resolver-tests/tests/resolve.rs b/crates/resolver-tests/tests/resolve.rs index 2d2ac0fe3..4ba0f9ba4 100644 --- a/crates/resolver-tests/tests/resolve.rs +++ b/crates/resolver-tests/tests/resolve.rs @@ -25,7 +25,7 @@ proptest! { 0 } else { // but that local builds will give a small clear test case. - std::u32::MAX + u32::MAX }, result_cache: prop::test_runner::basic_result_cache, .. ProptestConfig::default() diff --git a/src/cargo/core/resolver/conflict_cache.rs b/src/cargo/core/resolver/conflict_cache.rs index 863a517f7..c59e41178 100644 --- a/src/cargo/core/resolver/conflict_cache.rs +++ b/src/cargo/core/resolver/conflict_cache.rs @@ -175,7 +175,7 @@ impl ConflictCache { dep: &Dependency, must_contain: Option, ) -> Option<&ConflictMap> { - let out = self.find(dep, &|id| cx.is_active(id), must_contain, std::usize::MAX); + let out = self.find(dep, &|id| cx.is_active(id), must_contain, usize::MAX); if cfg!(debug_assertions) { if let Some(c) = &out { assert!(cx.is_conflicting(None, c).is_some()); diff --git a/tests/testsuite/standard_lib.rs b/tests/testsuite/standard_lib.rs index bfaad60a5..26ffbe24f 100644 --- a/tests/testsuite/standard_lib.rs +++ b/tests/testsuite/standard_lib.rs @@ -297,7 +297,7 @@ fn lib_nostd() { r#" #![no_std] pub fn foo() { - assert_eq!(core::u8::MIN, 0); + assert_eq!(u8::MIN, 0); } "#, ) diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 7fe5665e0..76f40cea8 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -129,7 +129,7 @@ fn cargo_test_overflow_checks() { use std::panic; pub fn main() { let r = panic::catch_unwind(|| { - [1, i32::max_value()].iter().sum::(); + [1, i32::MAX].iter().sum::(); }); assert!(r.is_err()); }"#, From 89c92bfa0431a7129407264039a8f544182c26ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Mon, 20 Apr 2020 12:46:00 +0200 Subject: [PATCH 02/30] Add windows-gnu CI --- azure-pipelines.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 392ecb9ed..fdd3141b5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -41,6 +41,9 @@ jobs: x86_64-msvc: TOOLCHAIN: stable-x86_64-pc-windows-msvc OTHER_TARGET: i686-pc-windows-msvc + x86_64-gnu: + TOOLCHAIN: nightly-x86_64-pc-windows-gnu + OTHER_TARGET: i686-pc-windows-gnu - job: rustfmt pool: From 9f742466f178bc7d1a2952053fd5f62a663e8494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Mon, 20 Apr 2020 18:57:56 +0200 Subject: [PATCH 03/30] Update tests for windows-gnu --- crates/cargo-test-support/src/cross_compile.rs | 2 ++ tests/testsuite/build.rs | 13 +++++++++++-- tests/testsuite/build_script.rs | 3 ++- tests/testsuite/out_dir.rs | 17 +++++++++++++++-- tests/testsuite/plugins.rs | 3 ++- tests/testsuite/standard_lib.rs | 6 ++++++ 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/crates/cargo-test-support/src/cross_compile.rs b/crates/cargo-test-support/src/cross_compile.rs index 771a52284..7d3ec3353 100644 --- a/crates/cargo-test-support/src/cross_compile.rs +++ b/crates/cargo-test-support/src/cross_compile.rs @@ -190,6 +190,8 @@ pub fn alternate() -> &'static str { "i686-unknown-linux-gnu" } else if cfg!(all(target_os = "windows", target_env = "msvc")) { "i686-pc-windows-msvc" + } else if cfg!(all(target_os = "windows", target_env = "gnu")) { + "i686-pc-windows-gnu" } else { panic!("This test should be gated on cross_compile::disabled."); } diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 6adb4d745..b116635b3 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -3769,7 +3769,11 @@ fn cdylib_not_lifted() { p.cargo("build").run(); let files = if cfg!(windows) { - vec!["foo.dll.lib", "foo.dll.exp", "foo.dll"] + if cfg!(target_env = "msvc") { + vec!["foo.dll.lib", "foo.dll.exp", "foo.dll"] + } else { + vec!["libfoo.dll.a", "foo.dll"] + } } else if cfg!(target_os = "macos") { vec!["libfoo.dylib"] } else { @@ -3803,7 +3807,12 @@ fn cdylib_final_outputs() { p.cargo("build").run(); let files = if cfg!(windows) { - vec!["foo_bar.dll.lib", "foo_bar.dll"] + if cfg!(target_env = "msvc") { + vec!["foo_bar.dll.lib", "foo_bar.dll"] + } else { + // FIXME https://github.com/rust-lang/cargo/pull/6875 + vec!["foo_bar.dll"] + } } else if cfg!(target_os = "macos") { vec!["libfoo_bar.dylib"] } else { diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 701852c1e..eb79675f7 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -1663,7 +1663,8 @@ fn build_script_with_dynamic_native_dependency() { let src = root.join(&file); let dst = out_dir.join(&file); fs::copy(src, dst).unwrap(); - if cfg!(windows) { + // FIXME https://github.com/rust-lang/cargo/pull/6875 + if cfg!(target_env = "msvc") { fs::copy(root.join("builder.dll.lib"), out_dir.join("builder.dll.lib")).unwrap(); } diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index f3301a0a0..d68bf27bd 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -20,6 +20,7 @@ fn binary_with_debug() { &["foo"], &["foo", "foo.dSYM"], &["foo.exe", "foo.pdb"], + &["foo.exe"], ); } @@ -55,6 +56,7 @@ fn static_library_with_debug() { &["libfoo.a"], &["libfoo.a"], &["foo.lib"], + &["libfoo.a"], ); } @@ -90,6 +92,8 @@ fn dynamic_library_with_debug() { &["libfoo.so"], &["libfoo.dylib"], &["foo.dll", "foo.dll.lib"], + // FIXME https://github.com/rust-lang/cargo/pull/6875 + &["foo.dll"], ); } @@ -124,6 +128,7 @@ fn rlib_with_debug() { &["libfoo.rlib"], &["libfoo.rlib"], &["libfoo.rlib"], + &["libfoo.rlib"], ); } @@ -167,6 +172,7 @@ fn include_only_the_binary_from_the_current_package() { &["foo"], &["foo", "foo.dSYM"], &["foo.exe", "foo.pdb"], + &["foo.exe"], ); } @@ -242,6 +248,7 @@ fn avoid_build_scripts() { &["a", "b"], &["a", "a.dSYM", "b", "b.dSYM"], &["a.exe", "a.pdb", "b.exe", "b.pdb"], + &["a.exe", "b.exe"], ); } @@ -266,6 +273,7 @@ fn cargo_build_out_dir() { &["foo"], &["foo", "foo.dSYM"], &["foo.exe", "foo.pdb"], + &["foo.exe"], ); } @@ -273,10 +281,15 @@ fn check_dir_contents( out_dir: &Path, expected_linux: &[&str], expected_mac: &[&str], - expected_win: &[&str], + expected_win_msvc: &[&str], + expected_win_gnu: &[&str], ) { let expected = if cfg!(target_os = "windows") { - expected_win + if cfg!(target_env = "msvc") { + expected_win_msvc + } else { + expected_win_gnu + } } else if cfg!(target_os = "macos") { expected_mac } else { diff --git a/tests/testsuite/plugins.rs b/tests/testsuite/plugins.rs index 7bd5b7772..f714399f8 100644 --- a/tests/testsuite/plugins.rs +++ b/tests/testsuite/plugins.rs @@ -180,7 +180,8 @@ fn plugin_with_dynamic_native_dependency() { let src = root.join(&file); let dst = out_dir.join(&file); fs::copy(src, dst).unwrap(); - if cfg!(windows) { + // FIXME https://github.com/rust-lang/cargo/pull/6875 + if cfg!(target_env = "msvc") { fs::copy(root.join("builder.dll.lib"), out_dir.join("builder.dll.lib")).unwrap(); } diff --git a/tests/testsuite/standard_lib.rs b/tests/testsuite/standard_lib.rs index bfaad60a5..74205d9cf 100644 --- a/tests/testsuite/standard_lib.rs +++ b/tests/testsuite/standard_lib.rs @@ -21,6 +21,12 @@ fn setup() -> Option { return None; } + if cfg!(all(target_os = "windows", target_env = "gnu")) { + // FIXME: contains object files that we don't handle yet: + // https://github.com/rust-lang/wg-cargo-std-aware/issues/46 + return None; + } + // Our mock sysroot requires a few packages from crates.io, so make sure // they're "published" to crates.io. Also edit their code a bit to make sure // that they have access to our custom crates with custom apis. From 6910cdf458a4212b75d54d20a0dff14ffc78f9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Mon, 20 Apr 2020 20:29:03 +0200 Subject: [PATCH 04/30] Fix rustc-dev component installation on CI --- ci/azure-install-rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/azure-install-rust.yml b/ci/azure-install-rust.yml index f37b4a6ab..f11171506 100644 --- a/ci/azure-install-rust.yml +++ b/ci/azure-install-rust.yml @@ -4,7 +4,7 @@ steps: rustup set profile minimal rustup component remove --toolchain=$TOOLCHAIN rust-docs || echo "already removed" rustup update --no-self-update $TOOLCHAIN - if [ "$TOOLCHAIN" = "nightly" ]; then + if [[ "$TOOLCHAIN" == "nightly"* ]]; then rustup component add --toolchain=$TOOLCHAIN rustc-dev fi rustup default $TOOLCHAIN From 2dd0b0d082ca55d1e8645ed569c094cf5c1e5d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Tue, 21 Apr 2020 17:24:36 +0200 Subject: [PATCH 05/30] Make sure to lift dylibs --- src/cargo/core/compiler/context/compilation_files.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 770da6758..fac6564a1 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -332,7 +332,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> { // we don't want to link it up. if out_dir.ends_with("deps") { // Don't lift up library dependencies. - if unit.target.is_bin() || self.roots.contains(unit) { + if unit.target.is_bin() || self.roots.contains(unit) || unit.target.is_dylib() { Some(( out_dir.parent().unwrap().to_owned(), if unit.mode.is_any_test() { From 68c22a16bcfdfa9a7e5d1936fb24a37beba9a381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 17 Apr 2019 15:49:07 +0200 Subject: [PATCH 06/30] Add implib to the stamp files This was already done when targetting msvc, but it needs to be done for all targets to allow rustc to link with shared libraries when using llvm -l is only supported by gcc, while llvm needs an import library to link indirectly with a dll --- src/cargo/core/compiler/build_context/target_info.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 39346b34c..7bf15d9be 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -258,6 +258,17 @@ impl TargetInfo { should_replace_hyphens: false, }) } + else if target_triple.ends_with("windows-gnu") + && crate_type.ends_with("dylib") + && suffix == ".dll" + { + ret.push(FileType { + suffix: ".dll.a".to_string(), + prefix: "lib".to_string(), + flavor: FileFlavor::Normal, + should_replace_hyphens: false, + }) + } // See rust-lang/cargo#4535. if target_triple.starts_with("wasm32-") && crate_type == "bin" && suffix == ".js" { From b19d6ac2a7f9abfe267c38c5cf7652c63e01d908 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 21 Apr 2020 10:52:46 -0700 Subject: [PATCH 07/30] Update tests and comments for testing windows-gnu. --- src/cargo/core/compiler/build_context/target_info.rs | 8 ++++---- tests/testsuite/build.rs | 3 +-- tests/testsuite/build_script.rs | 1 - tests/testsuite/out_dir.rs | 3 +-- tests/testsuite/plugins.rs | 3 +-- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 7bf15d9be..5b7dac40b 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -257,11 +257,11 @@ impl TargetInfo { flavor: FileFlavor::Normal, should_replace_hyphens: false, }) - } - else if target_triple.ends_with("windows-gnu") - && crate_type.ends_with("dylib") - && suffix == ".dll" + } else if target_triple.ends_with("windows-gnu") + && crate_type.ends_with("dylib") + && suffix == ".dll" { + // LD can link DLL directly, but LLD requires the import library. ret.push(FileType { suffix: ".dll.a".to_string(), prefix: "lib".to_string(), diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index b116635b3..dc987c6e6 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -3810,8 +3810,7 @@ fn cdylib_final_outputs() { if cfg!(target_env = "msvc") { vec!["foo_bar.dll.lib", "foo_bar.dll"] } else { - // FIXME https://github.com/rust-lang/cargo/pull/6875 - vec!["foo_bar.dll"] + vec!["foo_bar.dll", "libfoo_bar.dll.a"] } } else if cfg!(target_os = "macos") { vec!["libfoo_bar.dylib"] diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index eb79675f7..caaf45a96 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -1663,7 +1663,6 @@ fn build_script_with_dynamic_native_dependency() { let src = root.join(&file); let dst = out_dir.join(&file); fs::copy(src, dst).unwrap(); - // FIXME https://github.com/rust-lang/cargo/pull/6875 if cfg!(target_env = "msvc") { fs::copy(root.join("builder.dll.lib"), out_dir.join("builder.dll.lib")).unwrap(); diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index d68bf27bd..15b26f619 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -92,8 +92,7 @@ fn dynamic_library_with_debug() { &["libfoo.so"], &["libfoo.dylib"], &["foo.dll", "foo.dll.lib"], - // FIXME https://github.com/rust-lang/cargo/pull/6875 - &["foo.dll"], + &["foo.dll", "libfoo.dll.a"], ); } diff --git a/tests/testsuite/plugins.rs b/tests/testsuite/plugins.rs index f714399f8..0035e2031 100644 --- a/tests/testsuite/plugins.rs +++ b/tests/testsuite/plugins.rs @@ -180,8 +180,7 @@ fn plugin_with_dynamic_native_dependency() { let src = root.join(&file); let dst = out_dir.join(&file); fs::copy(src, dst).unwrap(); - // FIXME https://github.com/rust-lang/cargo/pull/6875 - if cfg!(target_env = "msvc") { + if cfg!(target_env = "msvc") { fs::copy(root.join("builder.dll.lib"), out_dir.join("builder.dll.lib")).unwrap(); } From 9ed56cad001477bf84a1ef13db59d04c54287405 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 11 Apr 2020 10:30:19 -0700 Subject: [PATCH 08/30] Add some more context to errors walking path sources. --- src/cargo/core/compiler/fingerprint.rs | 20 ++++++++++++++++++-- src/cargo/sources/path.rs | 16 +++++++++++++++- tests/testsuite/build_script.rs | 13 +++++++++++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/compiler/fingerprint.rs b/src/cargo/core/compiler/fingerprint.rs index e38eac1eb..337274e9d 100644 --- a/src/cargo/core/compiler/fingerprint.rs +++ b/src/cargo/core/compiler/fingerprint.rs @@ -1209,7 +1209,12 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult, unit: &Unit) -> CargoRes // the whole crate. let (gen_local, overridden) = build_script_local_fingerprints(cx, unit); let deps = &cx.build_explicit_deps[unit]; - let local = (gen_local)(deps, Some(&|| pkg_fingerprint(cx.bcx, &unit.pkg)))?.unwrap(); + let local = (gen_local)( + deps, + Some(&|| { + pkg_fingerprint(cx.bcx, &unit.pkg).chain_err(|| { + format!( + "failed to determine package fingerprint for build script for {}", + unit.pkg + ) + }) + }), + )? + .unwrap(); let output = deps.build_script_output.clone(); // Include any dependencies of our execution, which is typically just the diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index a0380160c..1f313d4af 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -96,6 +96,15 @@ impl<'cfg> PathSource<'cfg> { /// are relevant for building this package, but it also contains logic to /// use other methods like .gitignore to filter the list of files. pub fn list_files(&self, pkg: &Package) -> CargoResult> { + self._list_files(pkg).chain_err(|| { + format!( + "failed to determine list of files in {}", + pkg.root().display() + ) + }) + } + + fn _list_files(&self, pkg: &Package) -> CargoResult> { let root = pkg.root(); let no_include_option = pkg.manifest().include().is_empty(); @@ -415,7 +424,12 @@ impl<'cfg> PathSource<'cfg> { let mut max = FileTime::zero(); let mut max_path = PathBuf::new(); - for file in self.list_files(pkg)? { + for file in self.list_files(pkg).chain_err(|| { + format!( + "failed to determine the most recently modified file in {}", + pkg.root().display() + ) + })? { // An `fs::stat` error here is either because path is a // broken symlink, a permissions error, or a race // condition where this path was `rm`-ed -- either way, diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index caaf45a96..13bbe7e2d 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -3985,12 +3985,21 @@ fn build_script_scan_eacces() { .build(); let path = p.root().join("secrets"); fs::set_permissions(&path, fs::Permissions::from_mode(0)).unwrap(); - // "Caused by" is a string from libc such as the following: + // The last "Caused by" is a string from libc such as the following: // Permission denied (os error 13) p.cargo("build") .with_stderr( "\ -[ERROR] cannot read \"[..]/foo/secrets\" +[ERROR] failed to determine package fingerprint for build script for foo v0.0.1 ([..]/foo) + +Caused by: + failed to determine the most recently modified file in [..]/foo + +Caused by: + failed to determine list of files in [..]/foo + +Caused by: + cannot read \"[..]/foo/secrets\" Caused by: [..] From 51e0c71c5f0c03bfdbf2550e9e35fe9eb9f40522 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 11 Apr 2020 10:36:58 -0700 Subject: [PATCH 09/30] Allow `package.exclude` patterns to match directories. --- src/cargo/sources/path.rs | 61 +++++++++++++++++++-------------- tests/testsuite/build_script.rs | 25 ++++++++++++++ 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 1f313d4af..1d1fd5fe0 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -120,17 +120,21 @@ impl<'cfg> PathSource<'cfg> { } let ignore_include = include_builder.build()?; - let ignore_should_package = |relative_path: &Path| -> CargoResult { + let ignore_should_package = |relative_path: &Path, is_dir: bool| -> CargoResult { // "Include" and "exclude" options are mutually exclusive. if no_include_option { - match ignore_exclude - .matched_path_or_any_parents(relative_path, /* is_dir */ false) - { + match ignore_exclude.matched_path_or_any_parents(relative_path, is_dir) { Match::None => Ok(true), Match::Ignore(_) => Ok(false), Match::Whitelist(_) => Ok(true), } } else { + if is_dir { + // Generally, include directives don't list every + // directory (nor should they!). Just skip all directory + // checks, and only check files. + return Ok(true); + } match ignore_include .matched_path_or_any_parents(relative_path, /* is_dir */ false) { @@ -141,7 +145,7 @@ impl<'cfg> PathSource<'cfg> { } }; - let mut filter = |path: &Path| -> CargoResult { + let mut filter = |path: &Path, is_dir: bool| -> CargoResult { let relative_path = path.strip_prefix(root)?; let rel = relative_path.as_os_str(); @@ -151,7 +155,7 @@ impl<'cfg> PathSource<'cfg> { return Ok(true); } - ignore_should_package(relative_path) + ignore_should_package(relative_path, is_dir) }; // Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135). @@ -171,7 +175,7 @@ impl<'cfg> PathSource<'cfg> { &self, pkg: &Package, root: &Path, - filter: &mut dyn FnMut(&Path) -> CargoResult, + filter: &mut dyn FnMut(&Path, bool) -> CargoResult, ) -> Option>> { // If this package is in a Git repository, then we really do want to // query the Git repository as it takes into account items such as @@ -214,7 +218,7 @@ impl<'cfg> PathSource<'cfg> { &self, pkg: &Package, repo: &git2::Repository, - filter: &mut dyn FnMut(&Path) -> CargoResult, + filter: &mut dyn FnMut(&Path, bool) -> CargoResult, ) -> CargoResult> { warn!("list_files_git {}", pkg.package_id()); let index = repo.index()?; @@ -298,7 +302,10 @@ impl<'cfg> PathSource<'cfg> { continue; } - if is_dir.unwrap_or_else(|| file_path.is_dir()) { + // `is_dir` is None for symlinks. The `unwrap` checks if the + // symlink points to a directory. + let is_dir = is_dir.unwrap_or_else(|| file_path.is_dir()); + if is_dir { warn!(" found submodule {}", file_path.display()); let rel = file_path.strip_prefix(root)?; let rel = rel.to_str().ok_or_else(|| { @@ -316,7 +323,8 @@ impl<'cfg> PathSource<'cfg> { PathSource::walk(&file_path, &mut ret, false, filter)?; } } - } else if (*filter)(&file_path)? { + } else if (*filter)(&file_path, is_dir)? { + assert!(!is_dir); // We found a file! warn!(" found {}", file_path.display()); ret.push(file_path); @@ -347,29 +355,28 @@ impl<'cfg> PathSource<'cfg> { fn list_files_walk_except_dot_files_and_dirs( &self, pkg: &Package, - filter: &mut dyn FnMut(&Path) -> CargoResult, + filter: &mut dyn FnMut(&Path, bool) -> CargoResult, ) -> CargoResult> { let root = pkg.root(); let mut exclude_dot_files_dir_builder = GitignoreBuilder::new(root); exclude_dot_files_dir_builder.add_line(None, ".*")?; let ignore_dot_files_and_dirs = exclude_dot_files_dir_builder.build()?; - let mut filter_ignore_dot_files_and_dirs = |path: &Path| -> CargoResult { - let relative_path = path.strip_prefix(root)?; - match ignore_dot_files_and_dirs - .matched_path_or_any_parents(relative_path, /* is_dir */ false) - { - Match::Ignore(_) => Ok(false), - _ => filter(path), - } - }; + let mut filter_ignore_dot_files_and_dirs = + |path: &Path, is_dir: bool| -> CargoResult { + let relative_path = path.strip_prefix(root)?; + match ignore_dot_files_and_dirs.matched_path_or_any_parents(relative_path, is_dir) { + Match::Ignore(_) => Ok(false), + _ => filter(path, is_dir), + } + }; self.list_files_walk(pkg, &mut filter_ignore_dot_files_and_dirs) } fn list_files_walk( &self, pkg: &Package, - filter: &mut dyn FnMut(&Path) -> CargoResult, + filter: &mut dyn FnMut(&Path, bool) -> CargoResult, ) -> CargoResult> { let mut ret = Vec::new(); PathSource::walk(pkg.root(), &mut ret, true, filter)?; @@ -380,12 +387,14 @@ impl<'cfg> PathSource<'cfg> { path: &Path, ret: &mut Vec, is_root: bool, - filter: &mut dyn FnMut(&Path) -> CargoResult, + filter: &mut dyn FnMut(&Path, bool) -> CargoResult, ) -> CargoResult<()> { - if !path.is_dir() { - if (*filter)(path)? { - ret.push(path.to_path_buf()); - } + let is_dir = path.is_dir(); + if !is_root && !(*filter)(path, is_dir)? { + return Ok(()); + } + if !is_dir { + ret.push(path.to_path_buf()); return Ok(()); } // Don't recurse into any sub-packages that we have. diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 13bbe7e2d..a54b5eed4 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -3977,7 +3977,9 @@ fn links_interrupted_can_restart() { fn build_script_scan_eacces() { // build.rs causes a scan of the whole project, which can be a problem if // a directory is not accessible. + use cargo_test_support::git; use std::os::unix::fs::PermissionsExt; + let p = project() .file("src/lib.rs", "") .file("build.rs", "fn main() {}") @@ -4007,5 +4009,28 @@ Caused by: ) .with_status(101) .run(); + + // Try `package.exclude` to skip a directory. + p.change_file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + exclude = ["secrets"] + "#, + ); + p.cargo("build").run(); + + // Try with git. This succeeds because the git status walker ignores + // directories it can't access. + p.change_file("Cargo.toml", &basic_manifest("foo", "0.0.1")); + p.build_dir().rm_rf(); + let repo = git::init(&p.root()); + git::add(&repo); + git::commit(&repo); + p.cargo("build").run(); + + // Restore permissions so that the directory can be deleted. fs::set_permissions(&path, fs::Permissions::from_mode(0o755)).unwrap(); } From 1232ad3cde0d3ccee2dbd0b356b173260238eede Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 11 Apr 2020 10:38:21 -0700 Subject: [PATCH 10/30] Don't require Cargo.toml to be in root of a git repo for path source walking. --- src/cargo/sources/path.rs | 69 ++++++++++++++++------------- tests/testsuite/package.rs | 55 ++++++++++++++++++++++- tests/testsuite/publish_lockfile.rs | 1 + 3 files changed, 94 insertions(+), 31 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 1d1fd5fe0..961dc7371 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -177,40 +177,49 @@ impl<'cfg> PathSource<'cfg> { root: &Path, filter: &mut dyn FnMut(&Path, bool) -> CargoResult, ) -> Option>> { - // If this package is in a Git repository, then we really do want to - // query the Git repository as it takes into account items such as - // `.gitignore`. We're not quite sure where the Git repository is, - // however, so we do a bit of a probe. - // - // We walk this package's path upwards and look for a sibling - // `Cargo.toml` and `.git` directory. If we find one then we assume that - // we're part of that repository. - let mut cur = root; - loop { - if cur.join("Cargo.toml").is_file() { - // If we find a Git repository next to this `Cargo.toml`, we still - // check to see if we are indeed part of the index. If not, then - // this is likely an unrelated Git repo, so keep going. - if let Ok(repo) = git2::Repository::open(cur) { - let index = match repo.index() { - Ok(index) => index, - Err(err) => return Some(Err(err.into())), - }; - let path = root.strip_prefix(cur).unwrap().join("Cargo.toml"); - if index.get_path(&path, 0).is_some() { - return Some(self.list_files_git(pkg, &repo, filter)); - } - } + let repo = match git2::Repository::discover(root) { + Ok(repo) => repo, + Err(_) => return None, + }; + let index = match repo.index() { + Ok(index) => index, + Err(err) => { + let e = anyhow::Error::new(err).context(format!( + "failed to open git index at {}", + repo.path().display() + )); + return Some(Err(e)); } - // Don't cross submodule boundaries. - if cur.join(".git").is_dir() { - break; + }; + let repo_root = match repo.workdir() { + Some(dir) => dir, + None => { + return Some(Err(anyhow::format_err!( + "did not expect repo at {} to be bare", + repo.path().display() + ))) } - match cur.parent() { - Some(parent) => cur = parent, - None => break, + }; + let repo_relative_path = match root.strip_prefix(repo_root) { + Ok(path) => path, + Err(err) => { + let e = anyhow::Error::new(err).context(format!( + "expected git repo {} to be parent of package {}", + repo.path().display(), + root.display() + )); + return Some(Err(e)); } + }; + // Git requires forward-slashes. + let repo_safe_path = repo_relative_path + .join("Cargo.toml") + .to_string_lossy() + .replace('\\', "/"); + if index.get_path(Path::new(&repo_safe_path), 0).is_some() { + return Some(self.list_files_git(pkg, &repo, filter)); } + // Package Cargo.toml is not in git, don't use git to guide our selection. None } diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index c25d79c24..ddfeea58d 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -6,7 +6,7 @@ use cargo_test_support::{ basic_manifest, cargo_process, git, path2url, paths, project, publish::validate_crate_contents, registry, symlink_supported, t, }; -use std::fs::{read_to_string, File}; +use std::fs::{self, read_to_string, File}; use std::path::Path; #[cargo_test] @@ -1691,3 +1691,56 @@ fn package_restricted_windows() { ) .run(); } + +#[cargo_test] +fn finds_git_in_parent() { + // Test where `Cargo.toml` is not in the root of the git repo. + let repo_path = paths::root().join("repo"); + fs::create_dir(&repo_path).unwrap(); + let p = project() + .at("repo/foo") + .file("Cargo.toml", &basic_manifest("foo", "0.1.0")) + .file("src/lib.rs", "") + .build(); + let repo = git::init(&repo_path); + git::add(&repo); + git::commit(&repo); + p.change_file("ignoreme", ""); + p.change_file("ignoreme2", ""); + p.cargo("package --list --allow-dirty") + .with_stdout( + "\ +Cargo.toml +Cargo.toml.orig +ignoreme +ignoreme2 +src/lib.rs +", + ) + .run(); + + p.change_file(".gitignore", "ignoreme"); + p.cargo("package --list --allow-dirty") + .with_stdout( + "\ +.gitignore +Cargo.toml +Cargo.toml.orig +ignoreme2 +src/lib.rs +", + ) + .run(); + + fs::write(repo_path.join(".gitignore"), "ignoreme2").unwrap(); + p.cargo("package --list --allow-dirty") + .with_stdout( + "\ +.gitignore +Cargo.toml +Cargo.toml.orig +src/lib.rs +", + ) + .run(); +} diff --git a/tests/testsuite/publish_lockfile.rs b/tests/testsuite/publish_lockfile.rs index 7e0964f0d..741d220b9 100644 --- a/tests/testsuite/publish_lockfile.rs +++ b/tests/testsuite/publish_lockfile.rs @@ -469,6 +469,7 @@ fn ignore_lockfile_inner() { "\ [PACKAGING] bar v0.0.1 ([..]) [ARCHIVING] .cargo_vcs_info.json +[ARCHIVING] .gitignore [ARCHIVING] Cargo.lock [ARCHIVING] Cargo.toml [ARCHIVING] Cargo.toml.orig From 3a5af295d82a700ba40e9dea12f0e913a5f90cac Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 13 Apr 2020 10:49:32 -0700 Subject: [PATCH 11/30] Swap Result/Option for discover_git_and_list_files. --- src/cargo/sources/path.rs | 63 +++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 961dc7371..fe95e5987 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -160,8 +160,8 @@ impl<'cfg> PathSource<'cfg> { // Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135). if no_include_option { - if let Some(result) = self.discover_git_and_list_files(pkg, root, &mut filter) { - return result; + if let Some(result) = self.discover_git_and_list_files(pkg, root, &mut filter)? { + return Ok(result); } // no include option and not git repo discovered (see rust-lang/cargo#7183). return self.list_files_walk_except_dot_files_and_dirs(pkg, &mut filter); @@ -176,51 +176,44 @@ impl<'cfg> PathSource<'cfg> { pkg: &Package, root: &Path, filter: &mut dyn FnMut(&Path, bool) -> CargoResult, - ) -> Option>> { + ) -> CargoResult>> { let repo = match git2::Repository::discover(root) { Ok(repo) => repo, - Err(_) => return None, - }; - let index = match repo.index() { - Ok(index) => index, - Err(err) => { - let e = anyhow::Error::new(err).context(format!( - "failed to open git index at {}", - repo.path().display() - )); - return Some(Err(e)); - } - }; - let repo_root = match repo.workdir() { - Some(dir) => dir, - None => { - return Some(Err(anyhow::format_err!( - "did not expect repo at {} to be bare", - repo.path().display() - ))) - } - }; - let repo_relative_path = match root.strip_prefix(repo_root) { - Ok(path) => path, - Err(err) => { - let e = anyhow::Error::new(err).context(format!( - "expected git repo {} to be parent of package {}", - repo.path().display(), - root.display() - )); - return Some(Err(e)); + Err(e) => { + log::debug!( + "could not discover git repo at or above {}: {}", + root.display(), + e + ); + return Ok(None); } }; + let index = repo + .index() + .chain_err(|| format!("failed to open git index at {}", repo.path().display()))?; + let repo_root = repo.workdir().ok_or_else(|| { + anyhow::format_err!( + "did not expect repo at {} to be bare", + repo.path().display() + ) + })?; + let repo_relative_path = root.strip_prefix(repo_root).chain_err(|| { + format!( + "expected git repo {} to be parent of package {}", + repo.path().display(), + root.display() + ) + })?; // Git requires forward-slashes. let repo_safe_path = repo_relative_path .join("Cargo.toml") .to_string_lossy() .replace('\\', "/"); if index.get_path(Path::new(&repo_safe_path), 0).is_some() { - return Some(self.list_files_git(pkg, &repo, filter)); + return Ok(Some(self.list_files_git(pkg, &repo, filter)?)); } // Package Cargo.toml is not in git, don't use git to guide our selection. - None + Ok(None) } fn list_files_git( From 0efc187816de3187524455023b328f1f7863989f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 24 Apr 2020 08:45:16 -0700 Subject: [PATCH 12/30] Bump to 0.46.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index acec91102..fd663368d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo" -version = "0.45.0" +version = "0.46.0" edition = "2018" authors = ["Yehuda Katz ", "Carl Lerche ", From 1bea5f60eb115e8057ea5c4f45d1be6a6c7e4e18 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 24 Apr 2020 09:42:47 -0700 Subject: [PATCH 13/30] Update changelog for 1.44. --- CHANGELOG.md | 111 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ecd981e..490b555df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,60 @@ # Changelog -## Cargo 1.44 (2020-06-04) -[bda50510...HEAD](https://github.com/rust-lang/cargo/compare/bda50510...HEAD) +## Cargo 1.45 (2020-07-16) +[ebda5065e...HEAD](https://github.com/rust-lang/cargo/compare/ebda5065e...HEAD) ### Added + +### Changed +- Changed official documentation to recommend `.cargo/config.toml` filenames + (with the `.toml` extension). `.toml` extension support was added in 1.39. + [#8121](https://github.com/rust-lang/cargo/pull/8121) +- The `registry.index` config value is no longer allowed (it has been + deprecated for 4 years). + [#7973](https://github.com/rust-lang/cargo/pull/7973) +- An error is generated if both `--index` and `--registry` are passed + (previously `--index` was silently ignored). + [#7973](https://github.com/rust-lang/cargo/pull/7973) +- The `registry.token` config value is no longer used with the `--index` flag. + This is intended to avoid potentially leaking the crates.io token to another + registry. + [#7973](https://github.com/rust-lang/cargo/pull/7973) +- Added a warning if `registry.token` is used with source replacement. It is + intended this will be an error in future versions. + [#7973](https://github.com/rust-lang/cargo/pull/7973) +- Windows GNU targets now copy `.dll.a` import library files for DLL crate + types to the output directory. + [#8141](https://github.com/rust-lang/cargo/pull/8141) + +### Fixed +- Fixed copying Windows `.pdb` files to the output directory when the filename + contained dashes. + [#8123](https://github.com/rust-lang/cargo/pull/8123) + +### Nightly only +- Fixed passing the full path for `--target` to `rustdoc` when using JSON spec + targets. + [#8094](https://github.com/rust-lang/cargo/pull/8094) +- `-Cembed-bitcode=no` renamed to `-Cbitcode-in-rlib=no` + [#8134](https://github.com/rust-lang/cargo/pull/8134) +- Added new `resolver` field to `Cargo.toml` to opt-in to the new feature + resolver. + [#8129](https://github.com/rust-lang/cargo/pull/8129) + +## Cargo 1.44 (2020-06-04) +[bda50510...ebda5065e](https://github.com/rust-lang/cargo/compare/bda50510...ebda5065e) + +### Added +- 🔥 Added the `cargo tree` command. + [docs](https://doc.rust-lang.org/nightly/cargo/commands/cargo-tree.html) + [#8062](https://github.com/rust-lang/cargo/pull/8062) - Added warnings if a package has Windows-restricted filenames (like `nul`, `con`, `aux`, `prn`, etc.). [#7959](https://github.com/rust-lang/cargo/pull/7959) +- Added a `"build-finished"` JSON message when compilation is complete so that + tools can detect when they can stop listening for JSON messages with + commands like `cargo run` or `cargo test`. + [#8069](https://github.com/rust-lang/cargo/pull/8069) ### Changed - Valid package names are now restricted to Unicode XID identifiers. This is @@ -19,22 +67,79 @@ [#7959](https://github.com/rust-lang/cargo/pull/7959) - Tests are no longer hard-linked into the output directory (`target/debug/`). This ensures tools will have access to debug symbols and execute tests in - the same was as Cargo. Tools should use JSON messages to discover the path + the same way as Cargo. Tools should use JSON messages to discover the path to the executable. [#7965](https://github.com/rust-lang/cargo/pull/7965) - Updating git submodules now displays an "Updating" message for each submodule. [#7989](https://github.com/rust-lang/cargo/pull/7989) +- File modification times are now preserved when extracting a `.crate` file. + This reverses the change made in 1.40 where the mtime was not preserved. + [#7935](https://github.com/rust-lang/cargo/pull/7935) +- Build script warnings are now displayed separately when the build script + fails. + [#8017](https://github.com/rust-lang/cargo/pull/8017) +- Removed the `git-checkout` subcommand. + [#8040](https://github.com/rust-lang/cargo/pull/8040) +- The progress bar is now enabled for all unix platforms. Previously it was + only Linux, macOS, and FreeBSD. + [#8054](https://github.com/rust-lang/cargo/pull/8054) +- Artifacts generated by pre-release versions of `rustc` now share the same + filenames. This means that changing nightly versions will not leave stale + files in the build directory. + [#8073](https://github.com/rust-lang/cargo/pull/8073) +- Invalid package names are rejected when using renamed dependencies. + [#8090](https://github.com/rust-lang/cargo/pull/8090) +- Added a certain class of HTTP2 errors as "spurious" that will get retried. + [#8102](https://github.com/rust-lang/cargo/pull/8102) ### Fixed - Cargo no longer buffers excessive amounts of compiler output in memory. [#7838](https://github.com/rust-lang/cargo/pull/7838) - Symbolic links in git repositories now work on Windows. [#7996](https://github.com/rust-lang/cargo/pull/7996) +- Fixed an issue where `profile.dev` was not loaded from a config file with + `cargo test` when the `dev` profile was not defined in `Cargo.toml`. + [#8012](https://github.com/rust-lang/cargo/pull/8012) +- When a binary is built as an implicit dependency of an integration test, + it now checks `dep_name/feature_name` syntax in `required-features` correctly. + [#8020](https://github.com/rust-lang/cargo/pull/8020) +- Fixed an issue where Cargo would not detect that an executable (such as an + integration test) needs to be rebuilt when the previous build was + interrupted with Ctrl-C. + [#8087](https://github.com/rust-lang/cargo/pull/8087) +- Protect against some (unknown) situations where Cargo could panic when the + system monotonic clock doesn't appear to be monotonic. + [#8114](https://github.com/rust-lang/cargo/pull/8114) ### Nightly only - Fixed panic with new feature resolver and required-features. [#7962](https://github.com/rust-lang/cargo/pull/7962) +- Added `RUSTC_WORKSPACE_WRAPPER` environment variable, which provides a way + to wrap `rustc` for workspace members only, and affects the filename hash so + that artifacts produced by the wrapper are cached separately. This usage can + be seen on nightly clippy with `cargo clippy -Zunstable-options`. + [#7533](https://github.com/rust-lang/cargo/pull/7533) +- Added `--unit-graph` CLI option to display Cargo's internal dependency graph + as JSON. + [#7977](https://github.com/rust-lang/cargo/pull/7977) +- Changed `-Zbuild_dep` to `-Zhost_dep`, and added proc-macros to the feature + decoupling logic. + [#8003](https://github.com/rust-lang/cargo/pull/8003) + [#8028](https://github.com/rust-lang/cargo/pull/8028) +- Fixed so that `--crate-version` is not automatically passed when the flag + is found in `RUSTDOCFLAGS`. + [#8014](https://github.com/rust-lang/cargo/pull/8014) +- Fixed panic with `-Zfeatures=dev_dep` and `check --profile=test`. + [#8027](https://github.com/rust-lang/cargo/pull/8027) +- Fixed panic with `-Zfeatures=itarget` with certain host dependencies. + [#8048](https://github.com/rust-lang/cargo/pull/8048) +- Added support for `-Cembed-bitcode=no`, which provides a performance boost + and disk-space usage reduction for non-LTO builds. + [#8066](https://github.com/rust-lang/cargo/pull/8066) +- `-Zpackage-features` has been extended with several changes intended to make + it easier to select features on the command-line in a workspace. + [#8074](https://github.com/rust-lang/cargo/pull/8074) ## Cargo 1.43 (2020-04-23) [9d32b7b0...rust-1.43.0](https://github.com/rust-lang/cargo/compare/9d32b7b0...rust-1.43.0) From 25715e4f2aa40f8f0827baef3123bee5cb4cb374 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 23 Apr 2020 09:31:33 -0700 Subject: [PATCH 14/30] Bump git2. --- Cargo.toml | 4 ++-- src/cargo/sources/path.rs | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index acec91102..ac4f46849 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ pretty_env_logger = { version = "0.4", optional = true } anyhow = "1.0" filetime = "0.2.9" flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] } -git2 = "0.13.1" +git2 = "0.13.5" git2-curl = "0.14.0" glob = "0.3.0" hex = "0.4" @@ -44,7 +44,7 @@ jobserver = "0.1.21" lazycell = "1.2.0" libc = "0.2" log = "0.4.6" -libgit2-sys = "0.12.1" +libgit2-sys = "0.12.5" memchr = "2.1.3" num_cpus = "1.0" opener = "0.4" diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index fe95e5987..31be1eb78 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -204,12 +204,8 @@ impl<'cfg> PathSource<'cfg> { root.display() ) })?; - // Git requires forward-slashes. - let repo_safe_path = repo_relative_path - .join("Cargo.toml") - .to_string_lossy() - .replace('\\', "/"); - if index.get_path(Path::new(&repo_safe_path), 0).is_some() { + let manifest_path = repo_relative_path.join("Cargo.toml"); + if index.get_path(&manifest_path, 0).is_some() { return Ok(Some(self.list_files_git(pkg, &repo, filter)?)); } // Package Cargo.toml is not in git, don't use git to guide our selection. From 5c762bc3fda46926467e8cbaed82eca68b0fb0e7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 24 Apr 2020 12:54:24 -0700 Subject: [PATCH 15/30] Re-enable rustc-info-cache test again Support for `-Cbitcode-in-rlib` is now on nightly! --- tests/testsuite/rustc_info_cache.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/rustc_info_cache.rs b/tests/testsuite/rustc_info_cache.rs index 3ef091e4f..db016e0ae 100644 --- a/tests/testsuite/rustc_info_cache.rs +++ b/tests/testsuite/rustc_info_cache.rs @@ -6,9 +6,9 @@ use std::env; #[cargo_test] fn rustc_info_cache() { - // TODO: need to gate this on nightly as soon as -Cbitcode-in-rlib lands in - // nightly - if true { + // Needs `-Cbitcode-in-rlib` to ride to stable before this can be enabled + // everywhere. + if !cargo_test_support::is_nightly() { return; } From 2f04635e83ec22ab0481d1bd602c44d4396c1a03 Mon Sep 17 00:00:00 2001 From: Tom Fay Date: Sat, 25 Apr 2020 18:19:19 +0100 Subject: [PATCH 16/30] Mention that cargo_metadata can parse json messages --- src/doc/src/reference/external-tools.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/doc/src/reference/external-tools.md b/src/doc/src/reference/external-tools.md index 410db2440..26f99fd0b 100644 --- a/src/doc/src/reference/external-tools.md +++ b/src/doc/src/reference/external-tools.md @@ -48,7 +48,11 @@ alter the way the JSON messages are computed and rendered. See the description of the `--message-format` option in the [build command documentation] for more details. +If you are using Rust, the [cargo_metadata] crate can be used to parse these +messages. + [build command documentation]: ../commands/cargo-build.md +[cargo_metadata]: https://crates.io/crates/cargo_metadata #### Compiler messages From 3b3ca09562ca82762bc1db475318436b577ee37f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 26 Apr 2020 05:55:56 -0700 Subject: [PATCH 17/30] Add changelog about dylib uplift. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 490b555df..4c31ec596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,10 @@ - Windows GNU targets now copy `.dll.a` import library files for DLL crate types to the output directory. [#8141](https://github.com/rust-lang/cargo/pull/8141) +- Dylibs for all dependencies are now unconditionally copied to the output + directory. Some obscure scenarios can cause an old dylib to be referenced + between builds, and this ensures that all the latest copies are used. + [#8139](https://github.com/rust-lang/cargo/pull/8139) ### Fixed - Fixed copying Windows `.pdb` files to the output directory when the filename From 2c6711155232b2d6271bb7147610077c3a8cee65 Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Sun, 19 Apr 2020 12:54:23 -0400 Subject: [PATCH 18/30] Added warning when using restricted names in Windows. --- src/cargo/ops/cargo_package.rs | 23 +++---------- src/cargo/sources/registry/mod.rs | 19 +++++++---- src/cargo/util/restricted_names.rs | 11 +++++++ tests/testsuite/package.rs | 52 ++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 24 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 772c6f87f..5dcdd2ff4 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -823,25 +823,12 @@ fn check_filename(file: &Path, shell: &mut Shell) -> CargoResult<()> { file.display() ) } - let mut check_windows = |name| -> CargoResult<()> { - if restricted_names::is_windows_reserved(name) { - shell.warn(format!( - "file {} is a reserved Windows filename, \ + if restricted_names::is_windows_reserved_path(file) { + shell.warn(format!( + "file {} is a reserved Windows filename, \ it will not work on Windows platforms", - file.display() - ))?; - } - Ok(()) - }; - for component in file.iter() { - if let Some(component) = component.to_str() { - check_windows(component)?; - } - } - if file.extension().is_some() { - if let Some(stem) = file.file_stem().and_then(|s| s.to_str()) { - check_windows(stem)?; - } + file.display() + ))?; } Ok(()) } diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 9a181b907..4c340026c 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -178,7 +178,7 @@ use crate::sources::PathSource; use crate::util::errors::CargoResultExt; use crate::util::hex; use crate::util::into_url::IntoUrl; -use crate::util::{CargoResult, Config, Filesystem}; +use crate::util::{restricted_names, CargoResult, Config, Filesystem}; const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok"; pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index"; @@ -495,11 +495,18 @@ impl<'cfg> RegistrySource<'cfg> { prefix ) } - - // Once that's verified, unpack the entry as usual. - entry - .unpack_in(parent) - .chain_err(|| format!("failed to unpack entry at `{}`", entry_path.display()))?; + // Unpacking failed + let mut result = entry.unpack_in(parent).map_err(anyhow::Error::from); + if cfg!(windows) && restricted_names::is_windows_reserved_path(&entry_path) { + result = result.chain_err(|| { + format!( + "`{}` appears to contain a reserved Windows path, \ + it cannot be extracted on Windows", + entry_path.display() + ) + }); + } + result.chain_err(|| format!("failed to unpack entry at `{}`", entry_path.display()))?; } // Write to the lock file to indicate that unpacking was successful. diff --git a/src/cargo/util/restricted_names.rs b/src/cargo/util/restricted_names.rs index ad9df7dc1..3e1cb036d 100644 --- a/src/cargo/util/restricted_names.rs +++ b/src/cargo/util/restricted_names.rs @@ -2,6 +2,7 @@ use crate::util::CargoResult; use anyhow::bail; +use std::path::Path; /// Returns `true` if the name contains non-ASCII characters. pub fn is_non_ascii_name(name: &str) -> bool { @@ -81,3 +82,13 @@ pub fn validate_package_name(name: &str, what: &str, help: &str) -> CargoResult< } Ok(()) } + +// Check the entire path for names reserved in Windows. +pub fn is_windows_reserved_path(path: &Path) -> bool { + path.iter() + .filter_map(|component| component.to_str()) + .any(|component| { + let stem = component.split('.').next().unwrap(); + is_windows_reserved(stem) + }) +} diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index ddfeea58d..c04b7786d 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1744,3 +1744,55 @@ src/lib.rs ) .run(); } + +#[cargo_test] +#[cfg(windows)] +fn reserved_windows_name() { + Package::new("bar", "1.0.0") + .file("src/lib.rs", "pub mod aux;") + .file("src/aux.rs", "") + .publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + + [dependencies] + bar = "1.0.0" + "#, + ) + .file("src/main.rs", "extern crate bar;\nfn main() { }") + .build(); + p.cargo("package") + .with_status(101) + .with_stderr_contains( + "\ +error: failed to verify package tarball + +Caused by: + failed to download replaced source registry `[..]` + +Caused by: + failed to unpack package `[..] `[..]`)` + +Caused by: + failed to unpack entry at `[..]aux.rs` + +Caused by: + `[..]aux.rs` appears to contain a reserved Windows path, it cannot be extracted on Windows + +Caused by: + failed to unpack `[..]aux.rs` + +Caused by: + failed to unpack `[..]aux.rs` into `[..]aux.rs`", + ) + .run(); +} From aca8baed0728c92e7729da10528e0cd0aa8ab686 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 26 Apr 2020 11:20:21 -0700 Subject: [PATCH 19/30] Fix flaky linking_interrupted test. --- tests/testsuite/freshness.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 827fe2f75..4cc901717 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -2316,6 +2316,8 @@ LLVM version: 9.0 fn linking_interrupted() { // Interrupt during the linking phase shouldn't leave test executable as "fresh". + // This is used to detect when linking starts, then to pause the linker so + // that the test can kill cargo. let listener = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = listener.local_addr().unwrap(); @@ -2367,6 +2369,8 @@ fn linking_interrupted() { "CARGO_TARGET_{}_LINKER", rustc_host().to_uppercase().replace('-', "_") ); + // NOTE: This assumes that the path to the linker is not in the + // fingerprint. But maybe it should be? let mut cmd = p .cargo("test --test t1 --no-run") .env(&linker_env, linker.bin("linker")) @@ -2381,8 +2385,21 @@ fn linking_interrupted() { // Interrupt the child. child.kill().unwrap(); - // Note: rustc and the linker are still running, let them exit here. - conn.write(b"X").unwrap(); + child.wait().unwrap(); + // Note: rustc and the linker may still be running because we didn't kill + // the entire process group. Normally, when a user hits Ctrl-C, everything + // is killed. However, setting up process groups in a cross-platform test + // is a pain, and there's no easy way to know when everything has been + // killed. This write will tell them to exit, pretending that they died + // before finishing. Ignore the error, because (sometimes?) on Windows + // everything is already killed. + let _ = conn.write(b"X"); + // Sleep a bit to allow rustc to clean up and exit. I have seen some race + // conditions on macOS where clang dies with `no such + // file...t1-HASH.rcgu.o`. I think what is happening is that the old rustc + // process is still running, and deletes the `*.o` files while the command + // below is trying to write them. Not sure if that is macOS-specific. + std::thread::sleep(std::time::Duration::new(2, 0)); // Build again, shouldn't be fresh. p.cargo("test --test t1") From 686ccfa462aa40eef8421ea84bca52141a1e8814 Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Wed, 22 Apr 2020 22:56:40 -0400 Subject: [PATCH 20/30] Fixed some unnecessary borrows and clones. As suggested by the clippy. --- src/cargo/core/compiler/context/compilation_files.rs | 2 +- src/cargo/core/manifest.rs | 8 ++++---- src/cargo/ops/cargo_compile.rs | 6 +++--- src/cargo/ops/registry.rs | 2 +- src/cargo/ops/resolve.rs | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index fac6564a1..9fc2f4117 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -133,7 +133,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> { .map(|unit| (unit, LazyCell::new())) .collect(); CompilationFiles { - ws: &cx.bcx.ws, + ws: cx.bcx.ws, host, target, export_dir: cx.bcx.build_config.export_dir.clone(), diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 6ed4f1dea..c5c15a4a8 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -353,7 +353,7 @@ compact_debug! { kinds.clone(), self.src_path.path().unwrap().to_path_buf(), self.edition, - ).inner.clone(), + ).inner, format!("lib_target({:?}, {:?}, {:?}, {:?})", self.name, kinds, self.src_path, self.edition), ) @@ -366,21 +366,21 @@ compact_debug! { &self.name, path.to_path_buf(), self.edition, - ).inner.clone(), + ).inner, format!("custom_build_target({:?}, {:?}, {:?})", self.name, path, self.edition), ) } TargetSourcePath::Metabuild => { ( - Target::metabuild_target(&self.name).inner.clone(), + Target::metabuild_target(&self.name).inner, format!("metabuild_target({:?})", self.name), ) } } } _ => ( - Target::new(self.src_path.clone(), self.edition).inner.clone(), + Target::new(self.src_path.clone(), self.edition).inner, format!("with_path({:?}, {:?})", self.src_path, self.edition), ), } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 17d2a5ee1..31aaf3610 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -419,7 +419,7 @@ pub fn create_bcx<'a, 'cfg>( &resolved_features, &pkg_set, &profiles, - &interner, + interner, )?; let std_roots = if let Some(crates) = &config.cli_unstable().build_std { @@ -442,7 +442,7 @@ pub fn create_bcx<'a, 'cfg>( std_features, build_config.requested_kind, &pkg_set, - &interner, + interner, &profiles, )? } else { @@ -491,7 +491,7 @@ pub fn create_bcx<'a, 'cfg>( build_config.mode, &target_data, &profiles, - &interner, + interner, )?; let bcx = BuildContext::new( diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 69e778f15..9de9c4147 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -811,7 +811,7 @@ fn get_source_id( reg: Option<&String>, ) -> CargoResult { match (reg, index) { - (Some(r), _) => SourceId::alt_registry(config, &r), + (Some(r), _) => SourceId::alt_registry(config, r), (_, Some(i)) => SourceId::for_registry(&i.into_url()?), _ => { let map = SourceConfigMap::new(config)?; diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index dd32b9367..220946ea2 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -127,7 +127,7 @@ pub fn resolve_ws_with_opts<'cfg>( let pkg_set = get_resolved_packages(&resolved_with_overrides, registry)?; let member_ids = ws - .members_with_features(&specs, &opts.features)? + .members_with_features(specs, &opts.features)? .into_iter() .map(|(p, _fts)| p.package_id()) .collect::>(); @@ -136,7 +136,7 @@ pub fn resolve_ws_with_opts<'cfg>( &member_ids, has_dev_units, requested_target, - &target_data, + target_data, )?; let resolved_features = FeatureResolver::resolve( From ca085e97232e0b13ca3515b2a01b46851654aefd Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 27 Apr 2020 12:02:18 -0700 Subject: [PATCH 21/30] Remove Windows nested job object detection. According to https://docs.microsoft.com/en-us/windows/win32/procthread/nested-jobs nested jobs have been supported since Windows 8. This code isn't particularly safe with multiple test threads running at once because it modifies the job object of the test itself. --- tests/testsuite/death.rs | 44 ---------------------------------------- 1 file changed, 44 deletions(-) diff --git a/tests/testsuite/death.rs b/tests/testsuite/death.rs index 39ad914a6..eb8d57219 100644 --- a/tests/testsuite/death.rs +++ b/tests/testsuite/death.rs @@ -8,52 +8,8 @@ use std::thread; use cargo_test_support::{project, slow_cpu_multiplier}; -#[cfg(unix)] -fn enabled() -> bool { - true -} - -// On Windows support for these tests is only enabled through the usage of job -// objects. Support for nested job objects, however, was added in recent-ish -// versions of Windows, so this test may not always be able to succeed. -// -// As a result, we try to add ourselves to a job object here -// can succeed or not. -#[cfg(windows)] -fn enabled() -> bool { - use winapi::um::{handleapi, jobapi, jobapi2, processthreadsapi}; - - unsafe { - // If we're not currently in a job, then we can definitely run these - // tests. - let me = processthreadsapi::GetCurrentProcess(); - let mut ret = 0; - let r = jobapi::IsProcessInJob(me, 0 as *mut _, &mut ret); - assert_ne!(r, 0); - if ret == ::winapi::shared::minwindef::FALSE { - return true; - } - - // If we are in a job, then we can run these tests if we can be added to - // a nested job (as we're going to create a nested job no matter what as - // part of these tests. - // - // If we can't be added to a nested job, then these tests will - // definitely fail, and there's not much we can do about that. - let job = jobapi2::CreateJobObjectW(0 as *mut _, 0 as *const _); - assert!(!job.is_null()); - let r = jobapi2::AssignProcessToJobObject(job, me); - handleapi::CloseHandle(job); - r != 0 - } -} - #[cargo_test] fn ctrl_c_kills_everyone() { - if !enabled() { - return; - } - let listener = TcpListener::bind("127.0.0.1:0").unwrap(); let addr = listener.local_addr().unwrap(); From 01648b942bf82c5ec708e2f2d6d0a9a4385b2ae9 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 27 Apr 2020 12:23:09 -0700 Subject: [PATCH 22/30] Add a wrapper to wait for rustc to exit. --- tests/testsuite/death.rs | 4 +- tests/testsuite/freshness.rs | 76 ++++++++++++++++++++++++------------ 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/tests/testsuite/death.rs b/tests/testsuite/death.rs index eb8d57219..381088fbb 100644 --- a/tests/testsuite/death.rs +++ b/tests/testsuite/death.rs @@ -88,7 +88,7 @@ fn ctrl_c_kills_everyone() { } #[cfg(unix)] -fn ctrl_c(child: &mut Child) { +pub fn ctrl_c(child: &mut Child) { let r = unsafe { libc::kill(-(child.id() as i32), libc::SIGINT) }; if r < 0 { panic!("failed to kill: {}", io::Error::last_os_error()); @@ -96,6 +96,6 @@ fn ctrl_c(child: &mut Child) { } #[cfg(windows)] -fn ctrl_c(child: &mut Child) { +pub fn ctrl_c(child: &mut Child) { child.kill().unwrap(); } diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 4cc901717..62059734c 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -10,6 +10,7 @@ use std::process::Stdio; use std::thread; use std::time::SystemTime; +use super::death; use cargo_test_support::paths::{self, CargoPathExt}; use cargo_test_support::registry::Package; use cargo_test_support::{basic_manifest, is_coarse_mtime, project, rustc_host, sleep_ms}; @@ -2318,8 +2319,12 @@ fn linking_interrupted() { // This is used to detect when linking starts, then to pause the linker so // that the test can kill cargo. - let listener = TcpListener::bind("127.0.0.1:0").unwrap(); - let addr = listener.local_addr().unwrap(); + let link_listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let link_addr = link_listener.local_addr().unwrap(); + + // This is used to detect when rustc exits. + let rustc_listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let rustc_addr = rustc_listener.local_addr().unwrap(); // Create a linker that we can interrupt. let linker = project() @@ -2328,8 +2333,6 @@ fn linking_interrupted() { .file( "src/main.rs", &r#" - use std::io::Read; - fn main() { // Figure out the output filename. let output = match std::env::args().find(|a| a.starts_with("/OUT:")) { @@ -2348,58 +2351,79 @@ fn linking_interrupted() { std::fs::write(&output, "").unwrap(); // Tell the test that we are ready to be interrupted. let mut socket = std::net::TcpStream::connect("__ADDR__").unwrap(); - // Wait for the test to tell us to exit. - let _ = socket.read(&mut [0; 1]); + // Wait for the test to kill us. + std::thread::sleep(std::time::Duration::new(60, 0)); } "# - .replace("__ADDR__", &addr.to_string()), + .replace("__ADDR__", &link_addr.to_string()), ) .build(); linker.cargo("build").run(); + // Create a wrapper around rustc that will tell us when rustc is finished. + let rustc = project() + .at("rustc-waiter") + .file("Cargo.toml", &basic_manifest("rustc-waiter", "1.0.0")) + .file( + "src/main.rs", + &r#" + fn main() { + let mut conn = None; + // Check for a normal build (not -vV or --print). + if std::env::args().any(|arg| arg == "t1") { + // Tell the test that rustc has started. + conn = Some(std::net::TcpStream::connect("__ADDR__").unwrap()); + } + let status = std::process::Command::new("rustc") + .args(std::env::args().skip(1)) + .status() + .expect("rustc to run"); + std::process::exit(status.code().unwrap_or(1)); + } + "# + .replace("__ADDR__", &rustc_addr.to_string()), + ) + .build(); + rustc.cargo("build").run(); + // Build it once so that the fingerprint gets saved to disk. let p = project() .file("src/lib.rs", "") .file("tests/t1.rs", "") .build(); p.cargo("test --test t1 --no-run").run(); + // Make a change, start a build, then interrupt it. p.change_file("src/lib.rs", "// modified"); let linker_env = format!( "CARGO_TARGET_{}_LINKER", rustc_host().to_uppercase().replace('-', "_") ); - // NOTE: This assumes that the path to the linker is not in the - // fingerprint. But maybe it should be? + // NOTE: This assumes that the paths to the linker or rustc are not in the + // fingerprint. But maybe they should be? let mut cmd = p .cargo("test --test t1 --no-run") .env(&linker_env, linker.bin("linker")) + .env("RUSTC", rustc.bin("rustc-waiter")) .build_command(); let mut child = cmd .stdout(Stdio::null()) .stderr(Stdio::null()) + .env("__CARGO_TEST_SETSID_PLEASE_DONT_USE_ELSEWHERE", "1") .spawn() .unwrap(); + // Wait for rustc to start. + let mut rustc_conn = rustc_listener.accept().unwrap().0; // Wait for linking to start. - let mut conn = listener.accept().unwrap().0; + drop(link_listener.accept().unwrap()); // Interrupt the child. - child.kill().unwrap(); - child.wait().unwrap(); - // Note: rustc and the linker may still be running because we didn't kill - // the entire process group. Normally, when a user hits Ctrl-C, everything - // is killed. However, setting up process groups in a cross-platform test - // is a pain, and there's no easy way to know when everything has been - // killed. This write will tell them to exit, pretending that they died - // before finishing. Ignore the error, because (sometimes?) on Windows - // everything is already killed. - let _ = conn.write(b"X"); - // Sleep a bit to allow rustc to clean up and exit. I have seen some race - // conditions on macOS where clang dies with `no such - // file...t1-HASH.rcgu.o`. I think what is happening is that the old rustc - // process is still running, and deletes the `*.o` files while the command - // below is trying to write them. Not sure if that is macOS-specific. - std::thread::sleep(std::time::Duration::new(2, 0)); + death::ctrl_c(&mut child); + assert!(!child.wait().unwrap().success()); + // Wait for rustc to exit. If we don't wait, then the command below could + // start while rustc is still being torn down. + let mut buf = [0]; + drop(rustc_conn.read_exact(&mut buf)); // Build again, shouldn't be fresh. p.cargo("test --test t1") From 5907db65995084acc5d84ce81630336ad96afcda Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 27 Apr 2020 14:16:41 -0700 Subject: [PATCH 23/30] Fix warning for `resolve` mismatch in workspace. --- src/cargo/core/workspace.rs | 4 +++- tests/testsuite/features2.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 38428229b..5931a9a5c 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -792,7 +792,9 @@ impl<'cfg> Workspace<'cfg> { if !manifest.patch().is_empty() { emit_warning("patch")?; } - if manifest.resolve_behavior() != self.resolve_behavior { + if manifest.resolve_behavior().is_some() + && manifest.resolve_behavior() != self.resolve_behavior + { // Only warn if they don't match. emit_warning("resolver")?; } diff --git a/tests/testsuite/features2.rs b/tests/testsuite/features2.rs index e6f729263..d42fa7a6f 100644 --- a/tests/testsuite/features2.rs +++ b/tests/testsuite/features2.rs @@ -1592,6 +1592,17 @@ fn resolver_enables_new_features() { p.cargo("run --bin a") .masquerade_as_nightly_cargo() .env("EXPECTED_FEATS", "1") + .with_stderr( + "\ +[UPDATING] [..] +[DOWNLOADING] crates ... +[DOWNLOADED] common [..] +[COMPILING] common v1.0.0 +[COMPILING] a v0.1.0 [..] +[FINISHED] [..] +[RUNNING] `target/debug/a[EXE]` +", + ) .run(); // only normal+dev From cf57ce157422dea48e0d5c4fb35aabfd293acde4 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 27 Apr 2020 14:31:24 -0700 Subject: [PATCH 24/30] Clear `RUSTDOCFLAGS` for all tests --- crates/cargo-test-support/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 118438590..a4cf29171 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -1723,6 +1723,7 @@ fn _process(t: &OsStr) -> cargo::util::ProcessBuilder { .env_remove("RUSTDOC") .env_remove("RUSTC_WRAPPER") .env_remove("RUSTFLAGS") + .env_remove("RUSTDOCFLAGS") .env_remove("XDG_CONFIG_HOME") // see #2345 .env("GIT_CONFIG_NOSYSTEM", "1") // keep trying to sandbox ourselves .env_remove("EMAIL") From 156c65123f9c1564b7e66802d68d9c2cb3ea62e8 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 28 Apr 2020 10:49:03 -0700 Subject: [PATCH 25/30] Allow `cargo package --list` even for things that don't package. --- src/cargo/ops/cargo_package.rs | 32 +++++++++++------ tests/testsuite/package.rs | 55 +++++++++++++++++++++++++++-- tests/testsuite/publish_lockfile.rs | 4 +-- tests/testsuite/registry.rs | 15 +++++--- 4 files changed, 86 insertions(+), 20 deletions(-) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 5dcdd2ff4..b9aa42fc4 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -50,8 +50,17 @@ struct ArchiveFile { enum FileContents { /// Absolute path to the file on disk to add to the archive. OnDisk(PathBuf), - /// Contents of a file generated in memory. - Generated(String), + /// Generates a file. + Generated(GeneratedFile), +} + +enum GeneratedFile { + /// Generates `Cargo.toml` by rewriting the original. + Manifest, + /// Generates `Cargo.lock` in some cases (like if there is a binary). + Lockfile, + /// Adds a `.cargo-vcs_info.json` file if in a (clean) git repo. + VcsInfo(String), } pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult> { @@ -71,8 +80,6 @@ pub fn package(ws: &Workspace<'_>, opts: &PackageOpts<'_>) -> CargoResult