Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 13773 - 'cargo build' fails when list_files() with gix is triggered #13777

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion crates/cargo-test-support/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +76,13 @@ impl RepoBuilder {
me
}

/// Create a symlink to a directory
pub fn nocommit_symlink_dir<T: AsRef<Path>>(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 {
Expand Down
56 changes: 54 additions & 2 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down