Skip to content

Commit 80d5b60

Browse files
committed
Auto merge of #13777 - Byron:fix-13773, r=weihanglo
fix 13773 - 'cargo build' fails when list_files() with gix is triggered Fixes #13773. ### Tasks * [x] reproduce issue with new test-case * [x] update [fixed `gix-dir`](#13777) in Cargo.lock to turn test green
2 parents b503c83 + 3fd120b commit 80d5b60

File tree

3 files changed

+70
-11
lines changed

3 files changed

+70
-11
lines changed

Cargo.lock

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cargo-test-support/src/git.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use some of the helper functions in this file to interact with the repository.
3838
3939
*/
4040

41-
use crate::{path2url, project, Project, ProjectBuilder};
41+
use crate::{path2url, project, Project, ProjectBuilder, SymlinkBuilder};
4242
use std::fs;
4343
use std::path::{Path, PathBuf};
4444
use std::sync::Once;
@@ -76,6 +76,13 @@ impl RepoBuilder {
7676
me
7777
}
7878

79+
/// Create a symlink to a directory
80+
pub fn nocommit_symlink_dir<T: AsRef<Path>>(self, dst: T, src: T) -> Self {
81+
let workdir = self.repo.workdir().unwrap();
82+
SymlinkBuilder::new_dir(workdir.join(dst), workdir.join(src)).mk();
83+
self
84+
}
85+
7986
/// Add a file that will be left in the working directory, but not added
8087
/// to the repository.
8188
pub fn nocommit_file(self, path: &str, contents: &str) -> RepoBuilder {

tests/testsuite/build.rs

+54-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use cargo::{
66
ops::CompileOptions,
77
GlobalContext,
88
};
9-
use cargo_test_support::compare;
109
use cargo_test_support::paths::{root, CargoPathExt};
1110
use cargo_test_support::registry::Package;
12-
use cargo_test_support::tools;
1311
use cargo_test_support::{
1412
basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, git, is_nightly, main_file,
1513
paths, process, project, rustc_host, sleep_ms, symlink_supported, t, Execs, ProjectBuilder,
1614
};
15+
use cargo_test_support::{cargo_process, compare};
16+
use cargo_test_support::{git_process, tools};
1717
use cargo_util::paths::dylib_path_envvar;
1818
use std::env;
1919
use std::fs;
@@ -33,6 +33,58 @@ fn cargo_compile_simple() {
3333
p.process(&p.bin("foo")).with_stdout("i am foo\n").run();
3434
}
3535

36+
#[cargo_test]
37+
fn build_with_symlink_to_path_dependency_with_build_script_in_git() {
38+
if !symlink_supported() {
39+
return;
40+
}
41+
42+
let root = paths::root();
43+
git::repo(&root)
44+
.nocommit_file(
45+
"Cargo.toml",
46+
r#"
47+
[package]
48+
name = "foo"
49+
version = "0.1.0"
50+
edition = "2021"
51+
52+
[dependencies]
53+
# the path leads through a symlink, 'symlink-to-original' is a worktree root,
54+
# and symlink-to-dir/ is a symlink to a sub-directory to be stepped through.
55+
lib = { version = "0.1.0", path = "symlink-to-original/symlink-to-dir/lib" }
56+
"#,
57+
)
58+
.nocommit_file("src/main.rs", "fn main() { }")
59+
.nocommit_file("original/dir/lib/build.rs", "fn main() {}")
60+
.nocommit_file(
61+
"original/dir/lib/Cargo.toml",
62+
r#"
63+
[package]
64+
name = "lib"
65+
version = "0.1.0"
66+
edition = "2021"
67+
"#,
68+
)
69+
.nocommit_file("original/dir/lib/src/lib.rs", "")
70+
.nocommit_symlink_dir("original", "symlink-to-original")
71+
.nocommit_symlink_dir("original/dir", "original/symlink-to-dir")
72+
.build();
73+
74+
// It is necessary to have a sub-repository and to add files so there is an index.
75+
git_process("init")
76+
.cwd(root.join("original"))
77+
.build_command()
78+
.status()
79+
.unwrap();
80+
git_process("add .")
81+
.cwd(root.join("original"))
82+
.build_command()
83+
.status()
84+
.unwrap();
85+
cargo_process("build").run()
86+
}
87+
3688
#[cargo_test]
3789
fn cargo_fail_with_no_stderr() {
3890
let p = project()

0 commit comments

Comments
 (0)