From 07d2bd751708bd438975f80b3db6aa648baad2a3 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 18 Apr 2024 18:44:59 +0200 Subject: [PATCH 1/2] reproduce failure when packaging a path-dependency inside a symlinked git repository (#13773) --- crates/cargo-test-support/src/git.rs | 9 ++++- tests/testsuite/build.rs | 56 +++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/crates/cargo-test-support/src/git.rs b/crates/cargo-test-support/src/git.rs index 236011ca1c1..2b838e8c991 100644 --- a/crates/cargo-test-support/src/git.rs +++ b/crates/cargo-test-support/src/git.rs @@ -38,7 +38,7 @@ use some of the helper functions in this file to interact with the repository. */ -use crate::{path2url, project, Project, ProjectBuilder}; +use crate::{path2url, project, Project, ProjectBuilder, SymlinkBuilder}; use std::fs; use std::path::{Path, PathBuf}; use std::sync::Once; @@ -76,6 +76,13 @@ impl RepoBuilder { me } + /// Create a symlink to a directory + pub fn nocommit_symlink_dir>(self, dst: T, src: T) -> Self { + let workdir = self.repo.workdir().unwrap(); + SymlinkBuilder::new_dir(workdir.join(dst), workdir.join(src)).mk(); + self + } + /// Add a file that will be left in the working directory, but not added /// to the repository. pub fn nocommit_file(self, path: &str, contents: &str) -> RepoBuilder { diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 507d6cb19dd..daa605fdfd4 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -6,14 +6,14 @@ use cargo::{ ops::CompileOptions, GlobalContext, }; -use cargo_test_support::compare; use cargo_test_support::paths::{root, CargoPathExt}; use cargo_test_support::registry::Package; -use cargo_test_support::tools; use cargo_test_support::{ basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, git, is_nightly, main_file, paths, process, project, rustc_host, sleep_ms, symlink_supported, t, Execs, ProjectBuilder, }; +use cargo_test_support::{cargo_process, compare}; +use cargo_test_support::{git_process, tools}; use cargo_util::paths::dylib_path_envvar; use std::env; use std::fs; @@ -33,6 +33,58 @@ fn cargo_compile_simple() { p.process(&p.bin("foo")).with_stdout("i am foo\n").run(); } +#[cargo_test] +fn build_with_symlink_to_path_dependency_with_build_script_in_git() { + if !symlink_supported() { + return; + } + + let root = paths::root(); + git::repo(&root) + .nocommit_file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2021" + + [dependencies] + # the path leads through a symlink, 'symlink-to-original' is a worktree root, + # and symlink-to-dir/ is a symlink to a sub-directory to be stepped through. + lib = { version = "0.1.0", path = "symlink-to-original/symlink-to-dir/lib" } + "#, + ) + .nocommit_file("src/main.rs", "fn main() { }") + .nocommit_file("original/dir/lib/build.rs", "fn main() {}") + .nocommit_file( + "original/dir/lib/Cargo.toml", + r#" + [package] + name = "lib" + version = "0.1.0" + edition = "2021" + "#, + ) + .nocommit_file("original/dir/lib/src/lib.rs", "") + .nocommit_symlink_dir("original", "symlink-to-original") + .nocommit_symlink_dir("original/dir", "original/symlink-to-dir") + .build(); + + // It is necessary to have a sub-repository and to add files so there is an index. + git_process("init") + .cwd(root.join("original")) + .build_command() + .status() + .unwrap(); + git_process("add .") + .cwd(root.join("original")) + .build_command() + .status() + .unwrap(); + cargo_process("build").run() +} + #[cargo_test] fn cargo_fail_with_no_stderr() { let p = project() From 3fd120b7b300b037d670e658fa44d5bc7f2f4712 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 18 Apr 2024 22:24:28 +0200 Subject: [PATCH 2/2] use the latest patch release of `gix-dir` to fix #13777 --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 497222682f4..a116e634d37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1296,9 +1296,9 @@ dependencies = [ [[package]] name = "gix-dir" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6943a1f213ad7a060a0548ece229be53f3c2151534b126446ce3533eaf5f14c" +checksum = "3d6fcd56ffa1133f35525af890226ad0d3b2e607b4490360c94b1869e278eba3" dependencies = [ "bstr", "gix-discover", @@ -1431,9 +1431,9 @@ dependencies = [ [[package]] name = "gix-index" -version = "0.32.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3383122cf18655ef4c097c0b935bba5eb56983947959aaf3b0ceb1949d4dd371" +checksum = "881ab3b1fa57f497601a5add8289e72a7ae09471fc0b9bbe483b628ae8e418a1" dependencies = [ "bitflags 2.5.0", "bstr", @@ -1592,9 +1592,9 @@ dependencies = [ [[package]] name = "gix-pathspec" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d479789f3abd10f68a709454ce04cd68b54092ee882c8622ae3aa1bb9bf8496c" +checksum = "ea9f934a111e0efdf93ae06e3648427e60e783099fbebd6a53a7a2ffb10a1e65" dependencies = [ "bitflags 2.5.0", "bstr", @@ -1833,9 +1833,9 @@ dependencies = [ [[package]] name = "gix-worktree" -version = "0.33.0" +version = "0.33.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "359a87dfef695b5f91abb9a424c947edca82768f34acfc269659f66174a510b4" +checksum = "f06ca5dd164678914fc9280ba9d1ffeb66499ccc16ab1278c513828beee88401" dependencies = [ "bstr", "gix-attributes",