From 6ca27ffc857c7ac658fda14a83dfb4905d742315 Mon Sep 17 00:00:00 2001 From: khyperia Date: Wed, 28 Oct 2020 18:10:34 +0100 Subject: [PATCH 1/3] Make host_root return host.root(), not host.dest() Also create host_dest function to let other callsites retain their old functionality --- src/cargo/core/compiler/context/compilation_files.rs | 9 +++++++-- src/cargo/core/compiler/custom_build.rs | 2 +- src/cargo/core/compiler/mod.rs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 917b2a8caf5..37b11da8471 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -207,11 +207,16 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> { } } - /// Returns the root of the build output tree for the host - pub fn host_root(&self) -> &Path { + /// Returns the final artifact path for the host (`/…/target/debug`) + pub fn host_dest(&self) -> &Path { self.host.dest() } + /// Returns the root of the build output tree for the host (`/…/target`) + pub fn host_root(&self) -> &Path { + self.host.root() + } + /// Returns the host `deps` directory path. pub fn host_deps(&self) -> &Path { self.host.deps() diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 59596faa5ea..7e02008c8a1 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -272,7 +272,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { let output_file = script_run_dir.join("output"); let err_file = script_run_dir.join("stderr"); let root_output_file = script_run_dir.join("root-output"); - let host_target_root = cx.files().host_root().to_path_buf(); + let host_target_root = cx.files().host_dest().to_path_buf(); let all = ( id, pkg_name.clone(), diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index a408c089e03..53849e300e1 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -217,7 +217,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc) -> Car exec.init(cx, unit); let exec = exec.clone(); - let root_output = cx.files().host_root().to_path_buf(); + let root_output = cx.files().host_dest().to_path_buf(); let target_dir = cx.bcx.ws.target_dir().into_path_unlocked(); let pkg_root = unit.pkg.root().to_path_buf(); let cwd = rustc From 29b0817b876baeaa64a4310e19729e3c43055aec Mon Sep 17 00:00:00 2001 From: khyperia Date: Wed, 28 Oct 2020 20:22:41 +0100 Subject: [PATCH 2/3] Add test for dep within target having right path --- tests/testsuite/dep_info.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/testsuite/dep_info.rs b/tests/testsuite/dep_info.rs index 52d050def11..75b068c6bcc 100644 --- a/tests/testsuite/dep_info.rs +++ b/tests/testsuite/dep_info.rs @@ -176,6 +176,40 @@ fn build_dep_info_dylib() { assert!(p.example_lib("ex", "dylib").with_extension("d").is_file()); } +#[cargo_test] +fn dep_path_inside_target_has_correct_path() { + let p = project() + .file("Cargo.toml", &basic_bin_manifest("a")) + .file("target/debug/blah", "") + .file( + "src/main.rs", + r#" + fn main() { + let x = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/target/debug/blah")); + } + "#, + ) + .build(); + + p.cargo("build").run(); + + let depinfo_path = &p.bin("a").with_extension("d"); + + assert!(depinfo_path.is_file(), "{:?}", depinfo_path); + + let depinfo = p.read_file(depinfo_path.to_str().unwrap()); + + let bin_path = p.bin("a"); + if !depinfo.lines().any(|line| { + line.starts_with(&format!("{}:", bin_path.display())) && line.contains("target/debug/blah") + }) { + panic!( + "Could not find {:?}: target/debug/blah in {:?}", + bin_path, depinfo_path + ); + } +} + #[cargo_test] fn no_rewrite_if_no_change() { let p = project().file("src/lib.rs", "").build(); From 628f701dd969573da08cef8b236f2f7d9927d3c3 Mon Sep 17 00:00:00 2001 From: khyperia Date: Wed, 28 Oct 2020 20:45:50 +0100 Subject: [PATCH 3/3] Fix test path on windows --- tests/testsuite/dep_info.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/dep_info.rs b/tests/testsuite/dep_info.rs index 75b068c6bcc..ffc3bccc0db 100644 --- a/tests/testsuite/dep_info.rs +++ b/tests/testsuite/dep_info.rs @@ -200,12 +200,14 @@ fn dep_path_inside_target_has_correct_path() { let depinfo = p.read_file(depinfo_path.to_str().unwrap()); let bin_path = p.bin("a"); + let target_debug_blah = Path::new("target").join("debug").join("blah"); if !depinfo.lines().any(|line| { - line.starts_with(&format!("{}:", bin_path.display())) && line.contains("target/debug/blah") + line.starts_with(&format!("{}:", bin_path.display())) + && line.contains(target_debug_blah.to_str().unwrap()) }) { panic!( - "Could not find {:?}: target/debug/blah in {:?}", - bin_path, depinfo_path + "Could not find {:?}: {:?} in {:?}", + bin_path, target_debug_blah, depinfo_path ); } }