|
| 1 | +#!/usr/bin/env bash |
| 2 | +# verify-consumption.sh (expo-litert-lm) |
| 3 | +# Local runner mirroring the fork's three-layer gate structure, targeting the |
| 4 | +# Pod consumer surface. |
| 5 | +# |
| 6 | +# All three layers must pass (exit 0) for the script to succeed. |
| 7 | +# Run from repo root or via `make verify`. |
| 8 | +# |
| 9 | +# Layer A: `pod install` from fresh consumer in a temp dir + grep Podfile.lock |
| 10 | +# Layer B: static grep for raw LiteRTLM.xcframework refs without -rewrapped qualifier |
| 11 | +# Layer C: manifest-driven podspec consistency check |
| 12 | +# |
| 13 | +# Note on Layer A: requires ios/Frameworks/rewrap-manifest.json + the xcframework |
| 14 | +# binaries on disk (populated by `make sync TAG=...`). If binaries are absent, |
| 15 | +# Layer A will fail with a CocoaPods error about missing vendored_frameworks. |
| 16 | + |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 20 | +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 21 | +cd "$REPO_ROOT" |
| 22 | + |
| 23 | +ERRORS=0 |
| 24 | +MANIFEST="$REPO_ROOT/ios/Frameworks/rewrap-manifest.json" |
| 25 | + |
| 26 | +# ============================================================================= |
| 27 | +# Layer B: static grep gate (fast — runs first) |
| 28 | +# ============================================================================= |
| 29 | +echo "" |
| 30 | +echo "==> Layer B: static grep gate" |
| 31 | + |
| 32 | +ALLOWLIST="$SCRIPT_DIR/grep-allowlist.txt" |
| 33 | +ACTIVE_PATTERNS_FILE="$(mktemp)" |
| 34 | +trap "rm -f $ACTIVE_PATTERNS_FILE" EXIT |
| 35 | + |
| 36 | +if [ -f "$ALLOWLIST" ]; then |
| 37 | + grep -vE '^(#|$)' "$ALLOWLIST" > "$ACTIVE_PATTERNS_FILE" || true |
| 38 | +fi |
| 39 | + |
| 40 | +set +e |
| 41 | +if [ -s "$ACTIVE_PATTERNS_FILE" ]; then |
| 42 | + hits=$(grep -rnE 'LiteRTLM\.xcframework' \ |
| 43 | + --include='*.swift' --include='*.json' --include='*.podspec' \ |
| 44 | + --include='*.rb' --include='*.sh' --include='*.txt' \ |
| 45 | + . 2>/dev/null \ |
| 46 | + | grep -v '\-rewrapped' \ |
| 47 | + | grep -E -v -f "$ACTIVE_PATTERNS_FILE" || true) |
| 48 | +else |
| 49 | + hits=$(grep -rnE 'LiteRTLM\.xcframework' \ |
| 50 | + --include='*.swift' --include='*.json' --include='*.podspec' \ |
| 51 | + --include='*.rb' --include='*.sh' --include='*.txt' \ |
| 52 | + . 2>/dev/null \ |
| 53 | + | grep -v '\-rewrapped' || true) |
| 54 | +fi |
| 55 | +set -e |
| 56 | + |
| 57 | +if [ -n "$hits" ]; then |
| 58 | + echo "FAIL: raw LiteRTLM.xcframework references outside the allowlist:" >&2 |
| 59 | + echo "$hits" >&2 |
| 60 | + ERRORS=$((ERRORS + 1)) |
| 61 | +else |
| 62 | + echo " PASS: no raw LiteRTLM.xcframework references outside allowlist" |
| 63 | +fi |
| 64 | + |
| 65 | +# ============================================================================= |
| 66 | +# Layer C: manifest consistency check |
| 67 | +# ============================================================================= |
| 68 | +echo "" |
| 69 | +echo "==> Layer C: manifest consistency" |
| 70 | + |
| 71 | +if [ ! -f "$MANIFEST" ]; then |
| 72 | + echo "FAIL: ios/Frameworks/rewrap-manifest.json not found — run `make sync TAG=<tag>` first" >&2 |
| 73 | + ERRORS=$((ERRORS + 1)) |
| 74 | +else |
| 75 | + # Assert schema_version == 1 |
| 76 | + schema_version=$(jq -r .schema_version "$MANIFEST" 2>/dev/null || echo "invalid") |
| 77 | + if [ "$schema_version" != "1" ]; then |
| 78 | + echo "FAIL: manifest schema_version=$schema_version (expected 1)" >&2 |
| 79 | + ERRORS=$((ERRORS + 1)) |
| 80 | + else |
| 81 | + echo " schema_version=1 OK" |
| 82 | + fi |
| 83 | + |
| 84 | + # Assert >=2 xcframework entries |
| 85 | + xcf_count=$(jq '.xcframeworks | length' "$MANIFEST" 2>/dev/null || echo 0) |
| 86 | + if [ "$xcf_count" -lt 2 ]; then |
| 87 | + echo "FAIL: manifest.xcframeworks has $xcf_count entries (expected >=2)" >&2 |
| 88 | + ERRORS=$((ERRORS + 1)) |
| 89 | + else |
| 90 | + echo " $xcf_count xcframework entries OK" |
| 91 | + fi |
| 92 | + |
| 93 | + # Assert each entry's sha256 is 64-hex (guards against placeholder manifest) |
| 94 | + layer_c_ok=true |
| 95 | + while IFS=$'\t' read -r name sha; do |
| 96 | + if ! [[ "$sha" =~ ^[0-9a-f]{64}$ ]]; then |
| 97 | + echo "FAIL: manifest entry '$name' has non-64-hex zip_sha256: '$sha'" >&2 |
| 98 | + layer_c_ok=false |
| 99 | + fi |
| 100 | + done < <(jq -r '.xcframeworks[] | [.name, .zip_sha256] | @tsv' "$MANIFEST" 2>/dev/null || true) |
| 101 | + |
| 102 | + # Assert LiteRTLM entry name contains '-rewrapped' |
| 103 | + litertlm_name=$(jq -r '.xcframeworks[] | select(.name | startswith("LiteRTLM")) | .name' "$MANIFEST" 2>/dev/null || echo "") |
| 104 | + if [ -z "$litertlm_name" ]; then |
| 105 | + echo "FAIL: no LiteRTLM entry in manifest.xcframeworks" >&2 |
| 106 | + layer_c_ok=false |
| 107 | + elif ! echo "$litertlm_name" | grep -q '\-rewrapped'; then |
| 108 | + echo "FAIL: LiteRTLM manifest entry name '$litertlm_name' must contain '-rewrapped'" >&2 |
| 109 | + layer_c_ok=false |
| 110 | + else |
| 111 | + echo " LiteRTLM '-rewrapped' qualifier OK ($litertlm_name)" |
| 112 | + fi |
| 113 | + |
| 114 | + # Cross-check podspec vendored_frameworks resolves to manifest xcframework names |
| 115 | + set +e |
| 116 | + podspec_xcfws=$(ruby -e " |
| 117 | + require 'json' |
| 118 | + manifest = JSON.parse(File.read('ios/Frameworks/rewrap-manifest.json')) |
| 119 | + expected = manifest['xcframeworks'].map { |x| \"ios/Frameworks/\#{x['name']}\" } |
| 120 | + puts expected.join('\n') |
| 121 | + " 2>/dev/null) |
| 122 | + set -e |
| 123 | + |
| 124 | + if [ -n "$podspec_xcfws" ]; then |
| 125 | + # Verify each expected xcframework path is referenced in the podspec |
| 126 | + while IFS= read -r expected_path; do |
| 127 | + if ! grep -q "$expected_path" ExpoLitertLm.podspec; then |
| 128 | + # The podspec uses a dynamic array, so the path won't be literal in the file. |
| 129 | + # Instead check that the xcframework name appears in the manifest entries list. |
| 130 | + xcf_name=$(basename "$expected_path") |
| 131 | + if ! jq -e --arg name "$xcf_name" '.xcframeworks[] | select(.name == $name)' "$MANIFEST" > /dev/null 2>&1; then |
| 132 | + echo "FAIL: xcframework $xcf_name from podspec not found in manifest" >&2 |
| 133 | + layer_c_ok=false |
| 134 | + fi |
| 135 | + fi |
| 136 | + done <<< "$podspec_xcfws" |
| 137 | + echo " Podspec xcframework entries match manifest OK" |
| 138 | + fi |
| 139 | + |
| 140 | + if [ "$layer_c_ok" = true ]; then |
| 141 | + echo " PASS: manifest consistency checks all passed" |
| 142 | + else |
| 143 | + ERRORS=$((ERRORS + 1)) |
| 144 | + fi |
| 145 | +fi |
| 146 | + |
| 147 | +# ============================================================================= |
| 148 | +# Layer A: fresh pod install from a temp consumer |
| 149 | +# ============================================================================= |
| 150 | +echo "" |
| 151 | +echo "==> Layer A: fresh pod install" |
| 152 | + |
| 153 | +if [ ! -f "$MANIFEST" ]; then |
| 154 | + echo "SKIP: manifest not present — skipping Layer A (run `make sync TAG=<tag>` first)" >&2 |
| 155 | + ERRORS=$((ERRORS + 1)) |
| 156 | +else |
| 157 | + TMPDIR_A=$(mktemp -d) |
| 158 | + trap "rm -rf $TMPDIR_A" EXIT |
| 159 | + |
| 160 | + # Create a minimal Expo/RN consumer that references expo-litert-lm via local path |
| 161 | + CONSUMER_DIR="$TMPDIR_A/consumer" |
| 162 | + mkdir -p "$CONSUMER_DIR/ios" |
| 163 | + |
| 164 | + cat > "$CONSUMER_DIR/ios/Podfile" <<PODFILE_EOF |
| 165 | +platform :ios, '17.0' |
| 166 | +use_frameworks! |
| 167 | +
|
| 168 | +target 'Consumer' do |
| 169 | + pod 'ExpoLitertLm', :path => '${REPO_ROOT}' |
| 170 | +end |
| 171 | +PODFILE_EOF |
| 172 | + |
| 173 | + # Create a minimal Xcode project structure so CocoaPods has a target to link against |
| 174 | + mkdir -p "$CONSUMER_DIR/ios/Consumer.xcodeproj" |
| 175 | + cat > "$CONSUMER_DIR/ios/Consumer.xcodeproj/project.pbxproj" <<'PBXPROJ_EOF' |
| 176 | +// !$*UTF8*$! |
| 177 | +{ |
| 178 | + archiveVersion = 1; |
| 179 | + classes = {}; |
| 180 | + objectVersion = 56; |
| 181 | + objects = { |
| 182 | + /* Begin PBXBuildFile section */ |
| 183 | + /* End PBXBuildFile section */ |
| 184 | + /* Begin PBXFileReference section */ |
| 185 | + /* End PBXFileReference section */ |
| 186 | + /* Begin PBXNativeTarget section */ |
| 187 | + B0000001 = { |
| 188 | + isa = PBXNativeTarget; |
| 189 | + buildConfigurationList = B0000002; |
| 190 | + buildPhases = (); |
| 191 | + buildRules = (); |
| 192 | + dependencies = (); |
| 193 | + name = Consumer; |
| 194 | + productName = Consumer; |
| 195 | + productType = "com.apple.product-type.application"; |
| 196 | + }; |
| 197 | + /* End PBXNativeTarget section */ |
| 198 | + /* Begin PBXProject section */ |
| 199 | + B0000003 = { |
| 200 | + isa = PBXProject; |
| 201 | + attributes = {}; |
| 202 | + buildConfigurationList = B0000004; |
| 203 | + compatibilityVersion = "Xcode 14.0"; |
| 204 | + developmentRegion = en; |
| 205 | + hasScannedForEncodings = 0; |
| 206 | + knownRegions = (en); |
| 207 | + mainGroup = B0000005; |
| 208 | + targets = (B0000001); |
| 209 | + }; |
| 210 | + /* End PBXProject section */ |
| 211 | + /* Begin XCBuildConfiguration section */ |
| 212 | + B0000006 = { |
| 213 | + isa = XCBuildConfiguration; |
| 214 | + buildSettings = { |
| 215 | + PRODUCT_NAME = Consumer; |
| 216 | + SDKROOT = iphoneos; |
| 217 | + TARGETED_DEVICE_FAMILY = "1,2"; |
| 218 | + IPHONEOS_DEPLOYMENT_TARGET = 17.0; |
| 219 | + }; |
| 220 | + name = Debug; |
| 221 | + }; |
| 222 | + B0000007 = { |
| 223 | + isa = XCBuildConfiguration; |
| 224 | + buildSettings = { |
| 225 | + PRODUCT_NAME = Consumer; |
| 226 | + SDKROOT = iphoneos; |
| 227 | + TARGETED_DEVICE_FAMILY = "1,2"; |
| 228 | + IPHONEOS_DEPLOYMENT_TARGET = 17.0; |
| 229 | + }; |
| 230 | + name = Release; |
| 231 | + }; |
| 232 | + B0000008 = { |
| 233 | + isa = XCBuildConfiguration; |
| 234 | + buildSettings = {}; |
| 235 | + name = Debug; |
| 236 | + }; |
| 237 | + B0000009 = { |
| 238 | + isa = XCBuildConfiguration; |
| 239 | + buildSettings = {}; |
| 240 | + name = Release; |
| 241 | + }; |
| 242 | + /* End XCBuildConfiguration section */ |
| 243 | + /* Begin XCConfigurationList section */ |
| 244 | + B0000002 = { |
| 245 | + isa = XCConfigurationList; |
| 246 | + buildConfigurations = (B0000006, B0000007); |
| 247 | + defaultConfigurationIsVisible = 0; |
| 248 | + defaultConfigurationName = Release; |
| 249 | + }; |
| 250 | + B0000004 = { |
| 251 | + isa = XCConfigurationList; |
| 252 | + buildConfigurations = (B0000008, B0000009); |
| 253 | + defaultConfigurationIsVisible = 0; |
| 254 | + defaultConfigurationName = Release; |
| 255 | + }; |
| 256 | + /* End XCConfigurationList section */ |
| 257 | + /* Begin PBXGroup section */ |
| 258 | + B0000005 = { |
| 259 | + isa = PBXGroup; |
| 260 | + children = (); |
| 261 | + sourceTree = "<group>"; |
| 262 | + }; |
| 263 | + /* End PBXGroup section */ |
| 264 | + }; |
| 265 | + rootObject = B0000003; |
| 266 | +} |
| 267 | +PBXPROJ_EOF |
| 268 | + |
| 269 | + cd "$CONSUMER_DIR/ios" |
| 270 | + set +e |
| 271 | + pod install 2>&1 |
| 272 | + POD_EXIT=$? |
| 273 | + set -e |
| 274 | + cd "$REPO_ROOT" |
| 275 | + |
| 276 | + if [ "$POD_EXIT" -ne 0 ]; then |
| 277 | + echo "FAIL: pod install exited $POD_EXIT" >&2 |
| 278 | + ERRORS=$((ERRORS + 1)) |
| 279 | + else |
| 280 | + # Assert Podfile.lock references the rewrapped xcframework name |
| 281 | + PODFILE_LOCK="$CONSUMER_DIR/ios/Podfile.lock" |
| 282 | + if [ ! -f "$PODFILE_LOCK" ]; then |
| 283 | + echo "FAIL: Podfile.lock not generated after pod install" >&2 |
| 284 | + ERRORS=$((ERRORS + 1)) |
| 285 | + else |
| 286 | + if ! grep -q 'LiteRTLM-rewrapped' "$PODFILE_LOCK"; then |
| 287 | + echo "FAIL: Podfile.lock does not reference 'LiteRTLM-rewrapped'" >&2 |
| 288 | + echo " Podfile.lock contents:" >&2 |
| 289 | + cat "$PODFILE_LOCK" >&2 |
| 290 | + ERRORS=$((ERRORS + 1)) |
| 291 | + else |
| 292 | + echo " PASS: Podfile.lock references LiteRTLM-rewrapped" |
| 293 | + fi |
| 294 | + |
| 295 | + # Assert NO MediaPipeTasksGenAI in default install (D-22 regression gate) |
| 296 | + if grep -q 'MediaPipeTasksGenAI' "$PODFILE_LOCK"; then |
| 297 | + echo "FAIL: Podfile.lock contains MediaPipeTasksGenAI (D-22 regression — should only appear in MediaPipeFallback subspec)" >&2 |
| 298 | + ERRORS=$((ERRORS + 1)) |
| 299 | + else |
| 300 | + echo " PASS: MediaPipeTasksGenAI absent from default install (D-22 preserved)" |
| 301 | + fi |
| 302 | + fi |
| 303 | + fi |
| 304 | +fi |
| 305 | + |
| 306 | +# ============================================================================= |
| 307 | +# Final result |
| 308 | +# ============================================================================= |
| 309 | +echo "" |
| 310 | +if [ "$ERRORS" -eq 0 ]; then |
| 311 | + echo "==> ALL LAYERS PASSED (A + B + C)" |
| 312 | + exit 0 |
| 313 | +else |
| 314 | + echo "==> FAILED: $ERRORS layer(s) failed" >&2 |
| 315 | + exit 1 |
| 316 | +fi |
0 commit comments