|
| 1 | +#!/bin/bash |
| 2 | +# -*- indent-tabs-mode: nil; tab-width: 2; sh-indentation: 2; -*- |
| 3 | + |
| 4 | +# Test --test-mode: build failure with prebuilt fallback |
| 5 | +# |
| 6 | +# Verifies that when a source build fails but a prebuilt wheel is available, |
| 7 | +# test-mode uses the prebuilt wheel as fallback and continues without failure. |
| 8 | +# Uses a broken patch to trigger the build failure, then falls back to PyPI wheel. |
| 9 | +# |
| 10 | +# See: https://github.com/python-wheel-build/fromager/issues/895 |
| 11 | + |
| 12 | +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 13 | +source "$SCRIPTDIR/common.sh" |
| 14 | + |
| 15 | +# Use setuptools - it's on PyPI with prebuilt wheels |
| 16 | +DIST="setuptools" |
| 17 | +VERSION="75.8.0" |
| 18 | + |
| 19 | +# Step 1: Configure settings to mark setuptools as NOT prebuilt |
| 20 | +# This forces fromager to try building from source |
| 21 | +SETTINGS_DIR="$OUTDIR/test-settings" |
| 22 | +mkdir -p "$SETTINGS_DIR" |
| 23 | +cat > "$SETTINGS_DIR/${DIST}.yaml" << EOF |
| 24 | +variants: |
| 25 | + cpu: |
| 26 | + pre_built: false |
| 27 | +EOF |
| 28 | + |
| 29 | +# Step 2: Create a broken patches dir that will cause build to fail |
| 30 | +# We create a patch targeting setup.py with wrong content - patch will fail |
| 31 | +# without prompting for input (unlike targeting a non-existent file) |
| 32 | +PATCHES_DIR="$OUTDIR/test-patches" |
| 33 | +mkdir -p "$PATCHES_DIR/${DIST}" |
| 34 | +cat > "$PATCHES_DIR/${DIST}/break-build.patch" << 'PATCHEOF' |
| 35 | +--- a/setup.py |
| 36 | ++++ b/setup.py |
| 37 | +@@ -1,3 +1,3 @@ |
| 38 | +-this content does not match |
| 39 | +-the actual setup.py file |
| 40 | +-so patch will fail |
| 41 | ++replaced content |
| 42 | ++that will never |
| 43 | ++be applied |
| 44 | +PATCHEOF |
| 45 | + |
| 46 | +# Step 3: Run bootstrap in test mode |
| 47 | +# - Package will resolve from PyPI |
| 48 | +# - Source preparation will fail (bad patch) |
| 49 | +# - Prebuilt fallback should succeed (wheel on PyPI) |
| 50 | +echo "Running test-mode bootstrap with broken patch..." |
| 51 | +set +e |
| 52 | +fromager \ |
| 53 | + --log-file="$OUTDIR/bootstrap.log" \ |
| 54 | + --error-log-file="$OUTDIR/fromager-errors.log" \ |
| 55 | + --sdists-repo="$OUTDIR/sdists-repo" \ |
| 56 | + --wheels-repo="$OUTDIR/wheels-repo" \ |
| 57 | + --work-dir="$OUTDIR/work-dir" \ |
| 58 | + --settings-dir="$SETTINGS_DIR" \ |
| 59 | + --patches-dir="$PATCHES_DIR" \ |
| 60 | + bootstrap --test-mode "${DIST}==${VERSION}" |
| 61 | +EXIT_CODE=$? |
| 62 | +set -e |
| 63 | + |
| 64 | +pass=true |
| 65 | + |
| 66 | +# Check 1: Exit code - could be 0 (fallback succeeded) or 1 (failures recorded) |
| 67 | +# The key is that the test mode continued processing |
| 68 | +echo "Exit code: $EXIT_CODE" |
| 69 | + |
| 70 | +# Check 2: Log should show test mode was enabled |
| 71 | +if ! grep -q "test mode enabled" "$OUTDIR/bootstrap.log"; then |
| 72 | + echo "FAIL: Log should contain 'test mode enabled' message" 1>&2 |
| 73 | + pass=false |
| 74 | +fi |
| 75 | + |
| 76 | +# Check 3: Look for evidence of the patch failure and fallback attempt |
| 77 | +if grep -q "applying patch\|patch" "$OUTDIR/bootstrap.log"; then |
| 78 | + echo "Patch application was attempted" |
| 79 | +fi |
| 80 | + |
| 81 | +# Check 4: Check if prebuilt fallback was triggered |
| 82 | +if grep -q "pre-built fallback" "$OUTDIR/bootstrap.log"; then |
| 83 | + echo "Prebuilt fallback was triggered" |
| 84 | + if grep -q "successfully used pre-built wheel" "$OUTDIR/bootstrap.log"; then |
| 85 | + echo "SUCCESS: Prebuilt fallback succeeded" |
| 86 | + fi |
| 87 | +fi |
| 88 | + |
| 89 | +# Check 5: If there are failures recorded, verify the structure |
| 90 | +FAILURES_FILE=$(find "$OUTDIR/work-dir" -name "test-mode-failures-*.json" 2>/dev/null | head -1) |
| 91 | +if [ -n "$FAILURES_FILE" ] && [ -f "$FAILURES_FILE" ]; then |
| 92 | + echo "Found failures file: $FAILURES_FILE" |
| 93 | + FAILURE_COUNT=$(jq '.failures | length' "$FAILURES_FILE") |
| 94 | + echo "Number of failures recorded: $FAILURE_COUNT" |
| 95 | + # Show failures for debugging |
| 96 | + jq '.failures[] | {package, failure_type, exception_type}' "$FAILURES_FILE" |
| 97 | +fi |
| 98 | + |
| 99 | +# Check 6: Verify test mode completed (wrote summary or failures) |
| 100 | +if grep -q "test mode:" "$OUTDIR/bootstrap.log"; then |
| 101 | + echo "Test mode processing completed" |
| 102 | +else |
| 103 | + echo "NOTE: Test mode summary not found in log" 1>&2 |
| 104 | +fi |
| 105 | + |
| 106 | +$pass |
0 commit comments