Skip to content

Commit

Permalink
Don't check .gitignore files outside of projet directory
Browse files Browse the repository at this point in the history
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.

buildroot/buildroot@a14c862

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 <[email protected]>
  • Loading branch information
jameshilliard committed Jul 26, 2024
1 parent 46cce03 commit 29f30ea
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/build_options.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::needless_borrows_for_generic_args)]
use crate::auditwheel::PlatformTag;
use crate::build_context::BridgeModel;
use crate::compile::{CompileTarget, LIB_CRATE_TYPES};
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
//! - upload: Uses ureq to add the upload command.
//!
//! - rustls: Makes ureq use the rustls stack so that we can build maturin in a CentOS 6
//! docker container and which maturin itself manylinux compliant.
//! docker container and which maturin itself manylinux compliant.
//!
//! - native-tls: Makes ureq use the platform native tls stack
//!
//! - password-storage (off by default): Uses the keyring package to store the password. keyring
//! pulls in a lot of shared libraries and outdated dependencies, so this is off by default, except
//! for the build on the github releases page.
//! (https://github.com/hwchen/secret-service-rs/issues/9)
//! pulls in a lot of shared libraries and outdated dependencies, so this is off by default, except
//! for the build on the github releases page.
//! (https://github.com/hwchen/secret-service-rs/issues/9)
#![deny(missing_docs)]

Expand Down
12 changes: 11 additions & 1 deletion src/module_writer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! The wheel format is (mostly) specified in PEP 427
#![allow(clippy::needless_borrows_for_generic_args)]
use crate::project_layout::ProjectLayout;
use crate::target::Os;
use crate::{
Expand Down Expand Up @@ -1286,8 +1287,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(&project_layout.project_root)
.hidden(false)
.parents(false)
.git_global(false)
.git_exclude(false)
.build()
{
let absolute = absolute?.into_path();
if !absolute.starts_with(package.as_path()) {
continue;
}
let relative = absolute.strip_prefix(python_dir).unwrap();
if absolute.is_dir() {
writer.add_directory(relative)?;
Expand Down
4 changes: 4 additions & 0 deletions src/project_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const PYPROJECT_TOML: &str = "pyproject.toml";
/// Whether this project is pure rust or rust mixed with python and whether it has wheel data
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ProjectLayout {
/// Contains the absolute path to the project root directory
pub project_root: PathBuf,
/// Contains the absolute path to the python source directory
pub python_dir: PathBuf,
/// Contains the canonicalized (i.e. absolute) path to the python part of the project
Expand Down Expand Up @@ -397,6 +399,7 @@ impl ProjectLayout {
eprintln!("🍹 Building a mixed python/rust project");

Ok(ProjectLayout {
project_root: project_root.to_path_buf(),
python_dir: python_root,
python_packages,
python_module: Some(python_module),
Expand All @@ -415,6 +418,7 @@ impl ProjectLayout {
}

Ok(ProjectLayout {
project_root: project_root.to_path_buf(),
python_dir: python_root,
python_packages,
python_module: None,
Expand Down
1 change: 1 addition & 0 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::needless_borrows_for_generic_args)]
use crate::module_writer::{add_data, ModuleWriter};
use crate::pyproject_toml::SdistGenerator;
use crate::{pyproject_toml::Format, BuildContext, PyProjectToml, SDistWriter};
Expand Down
1 change: 1 addition & 0 deletions test-crates/pyo3-mixed-implicit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.py[cdo]
1 change: 1 addition & 0 deletions test-crates/pyo3-mixed-include-exclude/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.py[cdo]
1 change: 1 addition & 0 deletions test-crates/pyo3-mixed-py-subdir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.py[cdo]
1 change: 1 addition & 0 deletions test-crates/pyo3-mixed-src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.py[cdo]
1 change: 1 addition & 0 deletions test-crates/pyo3-mixed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.py[cdo]
2 changes: 2 additions & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ fn pyo3_mixed_include_exclude_sdist() {
SdistGenerator::Cargo,
expect![[r#"
{
"pyo3_mixed_include_exclude-2.1.3/.gitignore",
"pyo3_mixed_include_exclude-2.1.3/Cargo.lock",
"pyo3_mixed_include_exclude-2.1.3/Cargo.toml",
"pyo3_mixed_include_exclude-2.1.3/PKG-INFO",
Expand Down Expand Up @@ -759,6 +760,7 @@ fn pyo3_mixed_include_exclude_git_sdist_generator() {
SdistGenerator::Git,
expect![[r#"
{
"pyo3_mixed_include_exclude-2.1.3/.gitignore",
"pyo3_mixed_include_exclude-2.1.3/Cargo.lock",
"pyo3_mixed_include_exclude-2.1.3/Cargo.toml",
"pyo3_mixed_include_exclude-2.1.3/PKG-INFO",
Expand Down

0 comments on commit 29f30ea

Please sign in to comment.