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

Copy excluding .gitignore files causes failure without --in-place #492

Open
ASuciuX opened this issue Feb 6, 2025 · 9 comments
Open

Copy excluding .gitignore files causes failure without --in-place #492

ASuciuX opened this issue Feb 6, 2025 · 9 comments
Labels
bug Something isn't working copy_tree Copying trees to build dirs

Comments

@ASuciuX
Copy link
Contributor

ASuciuX commented Feb 6, 2025

Hello @sourcefrog, hope you’re doing well!

I’ve seen some great updates since I last implemented cargo-mutants in different workflows.

I ran into an issue where cargo-mutants fails when working with a copied version of the project. The error appears to be a binding issue—multiple dependencies rely on the same library but with different versions, causing cargo build to be unable to resolve them correctly. However, using the --in-place flag works fine.

I haven’t fully investigated the root cause or a potential underlying solution, but I found that using --in-place is preferable for CI regardless. The main concern is that, locally, running cargo-mutants requires a cloned version of the repository, which isn’t ideal. Given this, I wanted to open this issue and share my findings, especially since I noticed specified in the documentation to also share cases like this.

Here’s the failing CI action log when running cargo-mutants without --in-place:
https://github.com/hirosystems/ordhook/actions/runs/13164203008/job/36740241226#step:9:986

And here’s a related discussion on the dependency issue:
hirosystems/ordhook#395

@sourcefrog
Copy link
Owner

sourcefrog commented Feb 6, 2025

Hi @ASuciuX

This sounds like #117 but I guess you are already using >25.0.0 that includes that fix?

If you can narrow this down to a specific failure that will help.

Some things to try:

  1. If you manually copy the tree with cp -r does it work?
  2. If you manually copy the tree and then delete target does it work?

@ASuciuX
Copy link
Contributor Author

ASuciuX commented Feb 6, 2025

Yes, I am using 25.0.0.

  1. The copy containing the target still fails without --in-place. and works with --in-place`.
  2. Same

I've copied the codebase to a random user location. Should I copy it to a temp root location?

@sourcefrog
Copy link
Owner

I haven’t fully investigated the root cause or a potential underlying solution, but I found that using --in-place is preferable for CI regardless.

Separately from this bug: yes, that is better for CI. There's no point spending time copying to a temp directory if the source is itself a disposable temp directory.

@sourcefrog
Copy link
Owner

  • The copy containing the target still fails without --in-place and works with --in-place.

Interesting. If it's not the copying then I guess the problem is with the manifest and cargo config fixups done in https://github.com/sourcefrog/cargo-mutants/blob/main/src/manifest.rs after the copy.

pub fn copy_from(source: &Utf8Path, options: &Options, console: &Console) -> Result<BuildDir> {
let name_base = format!("cargo-mutants-{}-", source.file_name().unwrap_or("unnamed"));
let source_abs = source
.canonicalize_utf8()
.context("canonicalize source path")?;
let temp_dir = copy_tree(source, &name_base, options, console)?;
let path: Utf8PathBuf = temp_dir
.path()
.to_owned()
.try_into()
.context("tempdir path to UTF-8")?;
fix_manifest(&path.join("Cargo.toml"), &source_abs)?;
fix_cargo_config(&path, &source_abs)?;
let temp_dir = if options.leak_dirs {
let _ = temp_dir.into_path();
info!(?path, "Build directory will be leaked for inspection");
None
} else {
Some(temp_dir)
};
let build_dir = BuildDir { path, temp_dir };
Ok(build_dir)
}

A good next step would be to find the specific failing cargo command and its output.

@sourcefrog sourcefrog added bug Something isn't working copy_tree Copying trees to build dirs labels Feb 6, 2025
@sourcefrog
Copy link
Owner

sourcefrog commented Feb 7, 2025

OK the failure is pretty apparent in https://github.com/hirosystems/ordhook/actions/runs/13164203008/job/36740241226#step:9:986,

--> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/p256k1-7.2.2/src/_rename.rs:10:5
error[E0432]: unresolved imports crate::bindings::s2bca0a5cbf756dd4ff1f0bda4585a7d3c64e1480_secp256k1_context_preallocated_clone, crate::bindings::s2bca0a5cbf756dd4ff1f0bda4585a7d3c64e1480_secp256k1_context_preallocated_clone_size, crate::bindings::s2bca0a5cbf756dd4ff1f0bda4585a7d3c64e1480_secp256k1_context_preallocated_create, crate::bindings::s2bca0a5cbf756dd4ff1f0bda4585a7d3c64e1480_secp256k1_context_preallocated_destroy, crate::bindings::s2bca0a5cbf756dd4ff1f0bda4585a7d3c64e1480_secp256k1_context_preallocated_size

These names come from https://github.com/Trust-Machines/p256k1/blob/master/p256k1/src/bindings.rs

I notice that in this tree, src/bindings.rs is both checked in, and also in .gitignore. By default cargo-mutants skips gitignored files, so that might be what's breaking it.

I would try with --gitignore=false and that will probably fix it? At least, let me know?

https://github.com/Trust-Machines/p256k1 itself seems to run OK under mutants, although finding some gaps.

@sourcefrog
Copy link
Owner

#454 says we perhaps shouldn't skip gitignored files by default, because it saves a bit of time copying but might cause confusing errors when the tree depends on gitignored files. Maybe this is more evidence for it.

@ASuciuX
Copy link
Contributor Author

ASuciuX commented Feb 7, 2025

Nice, thank you! It works with --gitignore=false. Indeed it was because of that bindings.

How does it skip the gitignored files? Doesn’t it copy them to the temporary runs after building the project?

@sourcefrog
Copy link
Owner

With --gitignore=true (currently the default) it just does not copy them into the temp dirs:

let mut walk_builder = WalkBuilder::new(from_path);
let copy_vcs = options.copy_vcs; // for lifetime
walk_builder
.git_ignore(options.gitignore)
.git_exclude(options.gitignore)
.git_global(options.gitignore)
.hidden(false) // copy hidden files
.ignore(false) // don't use .ignore
.require_git(true) // stop at git root; only read gitignore files inside git trees
.filter_entry(move |entry| {
let name = entry.file_name().to_string_lossy();
name != "mutants.out"
&& name != "mutants.out.old"
&& (copy_vcs || !VCS_DIRS.contains(&name.as_ref()))
});

@sourcefrog sourcefrog changed the title Cargo-Mutants Fails on Copied Projects, Works with --in-place Copy excluding .gitignore files causes failure without --in-place Feb 7, 2025
@ASuciuX
Copy link
Contributor Author

ASuciuX commented Feb 7, 2025

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working copy_tree Copying trees to build dirs
Projects
None yet
Development

No branches or pull requests

2 participants