From 4f76eb8e1b45ac95ddae2bbef3fca510dd597da6 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Tue, 23 Jul 2024 11:01:06 -0600 Subject: [PATCH] Don't check .gitignore files outside of projet directory When building inside a .gitignore'd output directory as part of another build system maturin may accidentially pick up the parent .gitignore. Lets just disable searching for parent .gitignore files since this functionality is broken anyways as the logic does not match git's .gitignore logic anyways. For example in buildroot we have an output directory that has its contents gitignored in which maturin will build packages, changing some minor implementation details in how we ignore this directory triggered this bug. https://github.com/buildroot/buildroot/commit/a14c862c08865e053d5fce90a0d0323b8f9e4bc0 As the output dir files are supposed to be ignored both before and after this change this indicates that ignore::WalkBuilder parent matching is fundamentally broken and can not be used reliably in the first place as it does not match git's ignore logic. Also disable git exclude and git global excludes which may cause problems. Signed-off-by: James Hilliard --- src/module_writer.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/module_writer.rs b/src/module_writer.rs index 309d0890..dc3a9828 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -1286,8 +1286,17 @@ pub fn write_python_part( } for package in python_packages { - for absolute in WalkBuilder::new(package).hidden(false).build() { + for absolute in WalkBuilder::new(python_dir) + .hidden(false) + .parents(false) + .git_global(false) + .git_exclude(false) + .build() + { let absolute = absolute?.into_path(); + if !absolute.canonicalize()?.starts_with(package.canonicalize()?) { + continue; + } let relative = absolute.strip_prefix(python_dir).unwrap(); if absolute.is_dir() { writer.add_directory(relative)?;