|
| 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 should be 0 (fallback succeeded, no failures recorded) |
| 67 | +echo "Exit code: $EXIT_CODE" |
| 68 | +if [ "$EXIT_CODE" -ne 0 ]; then |
| 69 | + echo "FAIL: Expected exit code 0 (fallback success), got $EXIT_CODE" 1>&2 |
| 70 | + pass=false |
| 71 | +fi |
| 72 | + |
| 73 | +# Check 2: Log should show test mode was enabled |
| 74 | +if ! grep -q "test mode enabled" "$OUTDIR/bootstrap.log"; then |
| 75 | + echo "FAIL: Log should contain 'test mode enabled' message" 1>&2 |
| 76 | + pass=false |
| 77 | +fi |
| 78 | + |
| 79 | +# Check 3: Look for evidence of the patch failure |
| 80 | +if grep -q "applying patch\|patch" "$OUTDIR/bootstrap.log"; then |
| 81 | + echo "Patch application was attempted" |
| 82 | +fi |
| 83 | + |
| 84 | +# Check 4: Prebuilt fallback MUST be triggered and succeed |
| 85 | +if ! grep -q "pre-built fallback" "$OUTDIR/bootstrap.log"; then |
| 86 | + echo "FAIL: Expected prebuilt fallback to be triggered" 1>&2 |
| 87 | + pass=false |
| 88 | +elif ! grep -q "successfully used pre-built wheel" "$OUTDIR/bootstrap.log"; then |
| 89 | + echo "FAIL: Prebuilt fallback was triggered but did not succeed" 1>&2 |
| 90 | + pass=false |
| 91 | +else |
| 92 | + echo "SUCCESS: Prebuilt fallback triggered and succeeded" |
| 93 | +fi |
| 94 | + |
| 95 | +# Check 5: No failures should be recorded (fallback succeeded) |
| 96 | +FAILURES_FILE=$(find "$OUTDIR/work-dir" -name "test-mode-failures-*.json" 2>/dev/null | head -1) |
| 97 | +if [ -n "$FAILURES_FILE" ] && [ -f "$FAILURES_FILE" ]; then |
| 98 | + FAILURE_COUNT=$(jq '.failures | length' "$FAILURES_FILE") |
| 99 | + if [ "$FAILURE_COUNT" -gt 0 ]; then |
| 100 | + echo "FAIL: Expected no failures (fallback should succeed), got $FAILURE_COUNT" 1>&2 |
| 101 | + jq '.failures[] | {package, failure_type, exception_type}' "$FAILURES_FILE" 1>&2 |
| 102 | + pass=false |
| 103 | + fi |
| 104 | +fi |
| 105 | + |
| 106 | +# Check 6: Verify test mode completed |
| 107 | +if grep -q "test mode:" "$OUTDIR/bootstrap.log"; then |
| 108 | + echo "Test mode processing completed" |
| 109 | +else |
| 110 | + echo "NOTE: Test mode summary not found in log" 1>&2 |
| 111 | +fi |
| 112 | + |
| 113 | +$pass |
0 commit comments