From faff623ea11fc7412ee8646e571bd4d4f54801b9 Mon Sep 17 00:00:00 2001 From: messense Date: Fri, 10 Dec 2021 19:53:56 +0800 Subject: [PATCH] Fix undefined auditwheel policy panic --- .codespellrc | 1 + Changelog.md | 1 + src/auditwheel/audit.rs | 8 ++++++-- tests/manylinux_incompliant.sh | 14 ++++++++++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.codespellrc b/.codespellrc index 8511d3f6f..4fb6b0844 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,2 +1,3 @@ [codespell] ignore-words-list = crate +skip = ./.git,./target,./test-crates/venvs,./guide/book diff --git a/Changelog.md b/Changelog.md index f0577c0c7..cb4f17748 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fix docs for `new` and `init` commands in `maturin --help` in [#734](https://github.com/PyO3/maturin/pull/734) * Add support for x86_64 Haiku in [#735](https://github.com/PyO3/maturin/pull/735) +* Fix undefined auditwheel policy panic in [#740](https://github.com/PyO3/maturin/pull/740) ## [0.12.4] - 2021-12-06 diff --git a/src/auditwheel/audit.rs b/src/auditwheel/audit.rs index f24f3bd99..c936e76b1 100644 --- a/src/auditwheel/audit.rs +++ b/src/auditwheel/audit.rs @@ -34,9 +34,12 @@ pub enum AuditWheelError { "Your library is not {0} compliant because it links the following forbidden libraries: {1:?}", )] PlatformTagValidationError(Policy, Vec), - /// The elf file isn't manylinux/musllinux compaible. Contains unsupported architecture + /// The elf file isn't manylinux/musllinux compatible. Contains unsupported architecture #[error("Your library is not {0} compliant because it has unsupported architecture: {1}")] UnsupportedArchitecture(Policy, String), + /// This platform tag isn't defined by auditwheel yet + #[error("{0} compatibility policy is not defined by auditwheel yet, pass `--skip-auditwheel` to proceed anyway")] + UndefinedPolicy(String), } #[derive(Clone, Debug)] @@ -281,7 +284,8 @@ pub fn auditwheel_rs( } if let Some(platform_tag) = platform_tag { - let mut policy = Policy::from_name(&platform_tag.to_string()).unwrap(); + let tag = platform_tag.to_string(); + let mut policy = Policy::from_name(&tag).ok_or(AuditWheelError::UndefinedPolicy(tag))?; policy.fixup_musl_libc_so_name(target.target_arch()); if let Some(highest_policy) = highest_policy { diff --git a/tests/manylinux_incompliant.sh b/tests/manylinux_incompliant.sh index de296fec5..c48dcfbf7 100755 --- a/tests/manylinux_incompliant.sh +++ b/tests/manylinux_incompliant.sh @@ -1,7 +1,7 @@ #!/bin/bash # Fail because we're running in manylinux2014, which can't build for manylinux 2010 -for PYBIN in /opt/python/cp3[6]*/bin; do +for PYBIN in /opt/python/cp3[9]*/bin; do if cargo run -- build --no-sdist -m test-crates/pyo3-mixed/Cargo.toml -i "${PYBIN}/python" --manylinux 2010 -o dist; then echo "maturin build unexpectedly succeeded" exit 1 @@ -12,7 +12,7 @@ done # Fail because we're linking zlib with black-listed symbols(gzflags), which is not allowed in manylinux yum install -y zlib-devel -for PYBIN in /opt/python/cp3[6]*/bin; do +for PYBIN in /opt/python/cp3[9]*/bin; do if cargo run -- build --no-sdist -m test-crates/lib_with_disallowed_lib/Cargo.toml -i "${PYBIN}/python" --manylinux 2014 -o dist; then echo "maturin build unexpectedly succeeded" exit 1 @@ -20,3 +20,13 @@ for PYBIN in /opt/python/cp3[6]*/bin; do echo "maturin build failed as expected" fi done + +# Fail because manylinux_2_99 policy is not defined by auditwheel +for PYBIN in /opt/python/cp3[9]*/bin; do + if cargo run -- build --no-sdist -m test-crates/pyo3-mixed/Cargo.toml -i "${PYBIN}/python" --compatibility manylinux_2_99 -o dist; then + echo "maturin build unexpectedly succeeded" + exit 1 + else + echo "maturin build failed as expected" + fi +done