Skip to content

Commit

Permalink
Separate test build folders
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Dec 31, 2021
1 parent 133b3f9 commit 28d273a
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ dist/
build
dist
tags
test-crates/wheels/
test-crates/targets/
test-crates/venvs/
6 changes: 4 additions & 2 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::{anyhow, bail, Context, Result};
use std::path::Path;
use std::process::Command;
use std::str;
use tempfile::TempDir;

/// Installs a crate by compiling it and copying the shared library to site-packages.
/// Also adds the dist-info directory to make sure pip and other tools detect the library
Expand All @@ -23,15 +24,16 @@ pub fn develop(
extras: Vec<String>,
) -> Result<()> {
let target = Target::from_target_triple(None)?;

let python = target.get_venv_python(&venv_dir);
// Store wheel in a unique location so we don't get name clashes with parallel runs
let wheel_dir = TempDir::new().context("Failed to create temporary directory")?;

let build_options = BuildOptions {
platform_tag: Some(PlatformTag::Linux),
interpreter: Some(vec![python.clone()]),
bindings,
manifest_path: manifest_file.to_path_buf(),
out: None,
out: Some(wheel_dir.path().to_path_buf()),
skip_auditwheel: false,
target: None,
cargo_extra_args,
Expand Down
4 changes: 2 additions & 2 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ impl Target {
}
}

/// Returns the default Manylinux tag for this architecture
pub fn get_default_manylinux_tag(&self) -> PlatformTag {
/// Returns the oldest possible Manylinux tag for this architecture
pub fn get_minimum_manylinux_tag(&self) -> PlatformTag {
match self.arch {
Arch::Aarch64 | Arch::Armv7L | Arch::Powerpc64 | Arch::Powerpc64Le | Arch::S390X => {
PlatformTag::manylinux2014()
Expand Down
18 changes: 13 additions & 5 deletions tests/common/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ use std::str;

/// Creates a virtualenv and activates it, checks that the package isn't installed, uses
/// "maturin develop" to install it and checks it is working
pub fn test_develop(package: impl AsRef<Path>, bindings: Option<String>) -> Result<()> {
pub fn test_develop(
package: impl AsRef<Path>,
bindings: Option<String>,
unique_name: &str,
) -> Result<()> {
maybe_mock_cargo();

let (venv_dir, python) = create_virtualenv(&package, "develop")?;

// Ensure the test doesn't wrongly pass
check_installed(&package.as_ref(), &python).unwrap_err();
check_installed(package.as_ref(), &python).unwrap_err();

let output = Command::new(&python)
.args(&["-m", "pip", "install", "-U", "pip", "cffi"])
.args(&["-m", "pip", "install", "cffi"])
.output()?;
if !output.status.success() {
panic!(
Expand All @@ -31,14 +35,18 @@ pub fn test_develop(package: impl AsRef<Path>, bindings: Option<String>) -> Resu
develop(
bindings,
&manifest_file,
vec!["--quiet".to_string()],
vec![
"--quiet".to_string(),
"--target-dir".to_string(),
format!("test-crates/targets/{}", unique_name),
],
vec![],
&venv_dir,
false,
cfg!(feature = "faster-tests"),
vec![],
)?;

check_installed(&package.as_ref(), &python)?;
check_installed(package.as_ref(), &python)?;
Ok(())
}
17 changes: 14 additions & 3 deletions tests/common/editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ use std::str;
use structopt::StructOpt;

/// test PEP 660 editable installs
pub fn test_editable(package: impl AsRef<Path>, bindings: Option<String>) -> Result<()> {
pub fn test_editable(
package: impl AsRef<Path>,
bindings: Option<String>,
unique_name: &str,
) -> Result<()> {
maybe_mock_cargo();

let package_string = package.as_ref().join("Cargo.toml").display().to_string();

let (venv_dir, python) = create_virtualenv(&package, "editable")?;
let interpreter = python.to_str().expect("invalid interpreter path");
let cargo_extra_args = format!(
"--cargo-extra-args=--quiet --target-dir test-crates/targets/{}",
unique_name
);
let wheel_dir = format!("test-crates/wheels/{}", unique_name);

// The first argument is ignored by clap
let mut cli = vec![
"build",
Expand All @@ -25,7 +35,9 @@ pub fn test_editable(package: impl AsRef<Path>, bindings: Option<String>) -> Res
&package_string,
"--compatibility",
"linux",
"--cargo-extra-args='--quiet'",
&cargo_extra_args,
"--out",
&wheel_dir,
];

if let Some(ref bindings) = bindings {
Expand All @@ -34,7 +46,6 @@ pub fn test_editable(package: impl AsRef<Path>, bindings: Option<String>) -> Res
}

let options: BuildOptions = BuildOptions::from_iter_safe(cli)?;

let build_context = options.into_build_context(false, cfg!(feature = "faster-tests"), true)?;
let wheels = build_context.build_wheels()?;

Expand Down
18 changes: 12 additions & 6 deletions tests/common/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub fn abi3_without_version() -> Result<()> {
"build",
"--manifest-path",
"test-crates/pyo3-abi3-without-version/Cargo.toml",
"--cargo-extra-args='--quiet'",
"--cargo-extra-args=--quiet --target-dir test-targets/wheels/abi3_without_version",
];

let options = BuildOptions::from_iter_safe(cli)?;
let options: BuildOptions = BuildOptions::from_iter_safe(cli)?;
let result = options.into_build_context(false, cfg!(feature = "faster-tests"), false);
if let Err(err) = result {
assert_eq!(err.to_string(),
Expand All @@ -34,11 +34,13 @@ pub fn pyo3_no_extension_module() -> Result<()> {
"build",
"--manifest-path",
"test-crates/pyo3-no-extension-module/Cargo.toml",
"--cargo-extra-args='--quiet'",
"--cargo-extra-args=--quiet --target-dir test-crates/targets/pyo3_no_extension_module",
"-i=python",
"--out",
"test-crates/targets/pyo3_no_extension_module",
];

let options = BuildOptions::from_iter_safe(cli)?;
let options: BuildOptions = BuildOptions::from_iter_safe(cli)?;
let result = options
.into_build_context(false, cfg!(feature = "faster-tests"), false)?
.build_wheels();
Expand Down Expand Up @@ -67,8 +69,9 @@ pub fn locked_doesnt_build_without_cargo_lock() -> Result<()> {
"build",
"--manifest-path",
"test-crates/lib_with_path_dep/Cargo.toml",
"--cargo-extra-args='--locked'",
"-i=python",
"--cargo-extra-args=--locked",
"-itargetspython",
"--cargo-extra-args=--target-dir test-crates/targets/locked_doesnt_build_without_cargo_lock",
];
let options: BuildOptions = BuildOptions::from_iter_safe(cli)?;
let result = options.into_build_context(false, cfg!(feature = "faster-tests"), false);
Expand Down Expand Up @@ -104,6 +107,9 @@ pub fn invalid_manylinux_does_not_panic() -> Result<()> {
"-i=python",
"--compatibility",
"manylinux_2_99",
"--cargo-extra-args=--target-dir test-crates/targets/invalid_manylinux_does_not_panic",
"--out",
"test-crates/targets/invalid_manylinux_does_not_panic",
];
let options: BuildOptions = BuildOptions::from_iter_safe(cli)?;
let result = options
Expand Down
18 changes: 15 additions & 3 deletions tests/common/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ use structopt::StructOpt;

/// For each installed python version, this builds a wheel, creates a virtualenv if it
/// doesn't exist, installs the package and runs check_installed.py
pub fn test_integration(package: impl AsRef<Path>, bindings: Option<String>) -> Result<()> {
pub fn test_integration(
package: impl AsRef<Path>,
bindings: Option<String>,
unique_name: &str,
zig: bool,
) -> Result<()> {
maybe_mock_cargo();

let target = Target::from_target_triple(None)?;

let package_string = package.as_ref().join("Cargo.toml").display().to_string();

// The first argument is ignored by clap
let shed = format!("test-crates/wheels/{}", unique_name);
let cargo_extra_args = format!(
"--cargo-extra-args=--quiet --target-dir test-crates/targets/{}",
unique_name
);
let mut cli = vec![
"build",
"--manifest-path",
&package_string,
"--cargo-extra-args='--quiet'",
&cargo_extra_args,
"--out",
&shed,
"--compatibility",
"linux",
];
Expand Down Expand Up @@ -174,7 +186,7 @@ pub fn test_integration_conda(package: impl AsRef<Path>, bindings: Option<String
"build",
"--manifest-path",
&package_string,
"--cargo-extra-args='--quiet'",
"--cargo-extra-args=--quiet",
];

if let Some(ref bindings) = bindings {
Expand Down
34 changes: 23 additions & 11 deletions tests/common/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use flate2::read::GzDecoder;
use maturin::BuildOptions;
use std::collections::HashSet;
use std::iter::FromIterator;
use std::path::Path;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use tar::Archive;

Expand All @@ -13,7 +13,7 @@ use tar::Archive;
/// The bool in the Ok() response says whether the test was actually run
#[cfg(target_os = "linux")]
pub fn test_musl() -> Result<bool> {
use anyhow::{bail, format_err};
use anyhow::bail;
use fs_err::File;
use goblin::elf::Elf;
use std::fs;
Expand Down Expand Up @@ -57,14 +57,14 @@ pub fn test_musl() -> Result<bool> {
"x86_64-unknown-linux-musl",
"--compatibility",
"linux",
"--cargo-extra-args=--quiet --target-dir test-crates/targets/test_musl",
"--out",
"test-crates/wheels/test_musl",
])?;

let build_context = options.into_build_context(false, cfg!(feature = "faster-tests"), false)?;
let built_lib = build_context
.manifest_path
.parent()
.ok_or(format_err!("Missing parent directory"))?
.join("target/x86_64-unknown-linux-musl/debug/hello-world");
let built_lib =
PathBuf::from("test-crates/targets/test_musl/x86_64-unknown-linux-musl/debug/hello-world");
if built_lib.is_file() {
fs::remove_file(&built_lib)?;
}
Expand Down Expand Up @@ -94,6 +94,9 @@ pub fn test_workspace_cargo_lock() -> Result<()> {
"test-crates/workspace/py/Cargo.toml",
"--compatibility",
"linux",
"--cargo-extra-args=--quiet --target-dir test-crates/targets/test_workspace_cargo_lock",
"--out",
"test-crates/wheels/test_workspace_cargo_lock",
])?;

let build_context = options.into_build_context(false, false, false)?;
Expand All @@ -106,13 +109,22 @@ pub fn test_workspace_cargo_lock() -> Result<()> {
pub fn test_source_distribution(
package: impl AsRef<Path>,
expected_files: Vec<&str>,
unique_name: &str,
) -> Result<()> {
let manifest_dir = package.as_ref();
let manifest_path = manifest_dir.join("Cargo.toml");
let sdist_directory = tempfile::tempdir()?;
let manifest_path = package.as_ref().join("Cargo.toml");
let sdist_directory = Path::new("test-crates")
.join("wheels")
.join(unique_name)
.to_path_buf();

let build_options = BuildOptions {
manifest_path,
out: Some(sdist_directory.into_path()),
out: Some(sdist_directory),
cargo_extra_args: vec![
"--quiet".to_string(),
"--target-dir".to_string(),
"test-crates/targets/test_workspace_cargo_lock".to_string(),
],
..Default::default()
};

Expand Down
Loading

0 comments on commit 28d273a

Please sign in to comment.