Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309#!/bin/bashset -euo pipefail
cd "$(dirname "$0")/.."source Scripts/product.envsource Scripts/version.shsource Scripts/packaging-paths.shif [[ $# -gt 2 || ( ${1:-debug} != debug && ${1:-debug} != release ) ]]; then echo "Usage: $0 [debug|release] [--inspectable|--reality (debug only) | --preview (release only)]" >&2 exit 2fiif [[ $# -eq 2 ]]; then case "$1:$2" in debug:--inspectable|debug:--reality|release:--preview) ;; *) echo "Unsupported bundle option: $1 $2" >&2; exit 2 ;; esacficonfiguration=${1:-debug}preview=0if [[ ${2:-} == --preview ]]; then preview=1; fiinspectable=0if [[ ${2:-} == --inspectable ]]; then inspectable=1; fireality=0if [[ ${2:-} == --reality ]]; then reality=1 [[ -x build/reality-helper/ParcelRealityDriver ]] || { printf 'Build the reality helper first.\n' >&2; exit 1; }fibundle_id=${PARCEL_BUNDLE_ID:-$PRODUCT_BUNDLE_ID}version=${PARCEL_VERSION-0.1.0}build_number=${PARCEL_BUILD_NUMBER-1}identity=${PARCEL_SIGN_IDENTITY:-}if [[ -z $identity ]]; then keychain="$HOME/Library/Keychains/login.keychain-db" if ! identities=$(security find-identity -p codesigning "$keychain"); then echo 'Could not inspect signing identities in the login keychain.' >&2 exit 1 fi matches=() while IFS= read -r line; do if [[ $line =~ ([[:xdigit:]]{40})[[:space:]]+\"([^\"]+)\" && ${BASH_REMATCH[2]} == "$PRODUCT_NAME Development" ]]; then matches+=("${BASH_REMATCH[1]}") fi done <<< "$identities" if (( ${#matches[@]} > 1 )); then echo "More than one $PRODUCT_NAME Development identity found; set PARCEL_SIGN_IDENTITY to its fingerprint." >&2 exit 1 elif (( ${#matches[@]} == 1 )); then identity=${matches[0]} else identity=- fifiif [[ ! $bundle_id =~ ^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$ ]]; then echo "Invalid bundle identifier: $bundle_id" >&2 exit 1fivalidate_release_version "$version" "$build_number"if [[ -n $PRODUCT_SUPPORT_EMAIL && ! $PRODUCT_SUPPORT_EMAIL =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+$ ]]; then printf 'Invalid PRODUCT_SUPPORT_EMAIL in Scripts/product.env.\n' >&2 exit 1fiif (( reality )) && [[ $identity == '-' ]]; then printf 'Reality bundles require the existing Parcel Development signing identity.\n' >&2 exit 1fiif [[ $configuration == release && $identity == '-' && ${PARCEL_ALLOW_ADHOC:-0} != 1 ]]; then echo 'Ad-hoc release bundles require PARCEL_ALLOW_ADHOC=1 and are not for distribution.' >&2 exit 1fipackaging_build_directory# SwiftBuild retains resource-copy state; manifest/compiler variants must not share it.scratch="$PWD/.build/bundle/normal"if (( reality )); then scratch="$PWD/.build/bundle/reality"; fifor path in .build .build/bundle "$scratch"; do [[ ! -L $path ]] || { printf 'Refusing a symlinked bundle cache: %s\n' "$path" >&2; exit 1; }doneScripts/check-app-icons.sh --resources Sources/ParcelUI/Resources/AppIconsPARCEL_DEV_BINARY=$(Scripts/parcel-dev.sh --path)export PARCEL_DEV_BINARYmkdir -p buildwork=$(mktemp -d "$PWD/build/.bundle.XXXXXX")trap 'rm -rf "$work"' EXIT
# SwiftBuild's resource accessors can find bundles inside a signed app.export PARCEL_BUNDLE_BUILD=1# Keep checkout paths out of shipped binaries.checkout=$(realpath .)build_args=(--scratch-path "$scratch" --build-system swiftbuild -c "$configuration" -Xswiftc -file-prefix-map -Xswiftc "$checkout=." -Xswiftc -debug-prefix-map -Xswiftc "$checkout=." -Xswiftc -file-compilation-dir -Xswiftc . -Xcc "-ffile-prefix-map=$checkout=." -Xcc "-fdebug-prefix-map=$checkout=.")if (( reality )); then build_args+=(-Xswiftc -DPARCEL_REALITY); fi# Multiple --arch options silently select the legacy build backend, which cannot build our resource plugin.# SwiftBuild's release default is universal; verify both slices below.for product in "$PRODUCT_APP_TARGET" "$PRODUCT_CLI"; do if ! Scripts/swift-build.sh "${build_args[@]}" --product "$product" > "$work/build.log" 2>&1; then /bin/cat "$work/build.log" >&2 exit 1 fidonebin_dir=$(swift build "${build_args[@]}" --show-bin-path)if [[ $configuration == release ]]; then lipo "$bin_dir/$PRODUCT_APP_TARGET" -verify_arch arm64 x86_64 lipo "$bin_dir/$PRODUCT_CLI" -verify_arch arm64 x86_64fi
app="$work/$PRODUCT_NAME.app"resources="$app/Contents/Resources"mkdir -p "$app/Contents/MacOS" "$resources/bin"cp Packaging/Sparkle-LICENSE "$resources/Sparkle-LICENSE"cp "$bin_dir/$PRODUCT_APP_TARGET" "$app/Contents/MacOS/$PRODUCT_NAME"cp "$bin_dir/$PRODUCT_CLI" "$resources/bin/$PRODUCT_CLI"if (( reality )); then mkdir "$app/Contents/Helpers" cp build/reality-helper/ParcelRealityDriver "$app/Contents/Helpers/ParcelRealityDriver"ficp Resources/Info.plist "$app/Contents/Info.plist"/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $bundle_id" "$app/Contents/Info.plist"/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" "$app/Contents/Info.plist"/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $build_number" "$app/Contents/Info.plist"/usr/libexec/PlistBuddy -c "Set :ParcelSupportEmail \"$PRODUCT_SUPPORT_EMAIL\"" "$app/Contents/Info.plist"update_configuration=$configurationif (( preview )); then update_configuration=debug; fiScripts/parcel-dev.sh update-metadata configure "$app/Contents/Info.plist" "$update_configuration"framework_source=${PARCEL_SPARKLE_FRAMEWORK:-$scratch/artifacts/sparkle/Sparkle/Sparkle.xcframework/macos-arm64_x86_64/Sparkle.framework}[[ -d $framework_source ]] || { echo "Sparkle framework not found: $framework_source" >&2; exit 1; }mkdir -p "$app/Contents/Frameworks"ditto "$framework_source" "$app/Contents/Frameworks/Sparkle.framework"framework="$app/Contents/Frameworks/Sparkle.framework"lipo "$framework/Versions/B/Sparkle" -verify_arch arm64 x86_64if ! otool -l "$app/Contents/MacOS/$PRODUCT_NAME" | grep -F '@executable_path/../Frameworks' > /dev/null; then install_name_tool -add_rpath '@executable_path/../Frameworks' "$app/Contents/MacOS/$PRODUCT_NAME"firsync -a --exclude='/Info.plist' --exclude='*.xcassets' --exclude='*.xcstrings' Resources/ "$resources/"while IFS= read -r -d '' bundle; do bundle_name=$(basename "$bundle") if [[ -e $resources/$bundle_name || -L $resources/$bundle_name || -e $resources/bin/$bundle_name || -L $resources/bin/$bundle_name ]]; then echo "Resource bundle already exists: $bundle_name" >&2 exit 1 fi ditto "$bundle" "$resources/$bundle_name" # The standalone CLI looks for target bundles beside its executable. ln -s "../$bundle_name" "$resources/bin/$bundle_name"done < <(find "$bin_dir" -maxdepth 1 -type d -name '*.bundle' -print0)
catalogs=()while IFS= read -r -d '' catalog; do catalogs+=("$catalog")done < <(find Resources -type d -name '*.xcassets' -print0)if (( ${#catalogs[@]} )); then icons=() while IFS= read -r -d '' icon; do icons+=("$icon") done < <(find "${catalogs[@]}" -type d -name '*.appiconset' -print0) asset_args=(--compile "$resources" --platform macosx --minimum-deployment-target 15.0 --output-partial-info-plist "$work/assets.plist" --warnings --errors) if (( ${#icons[@]} > 1 )); then echo 'More than one app icon set found; select a single app icon.' >&2 exit 1 elif (( ${#icons[@]} == 1 )); then Scripts/check-app-icons.sh --catalog "${icons[0]}" icon_name=$(basename "${icons[0]}" .appiconset) asset_args+=(--app-icon "$icon_name") fi if ! xcrun actool "${asset_args[@]}" "${catalogs[@]}" > "$work/actool.log" 2>&1; then /bin/cat "$work/actool.log" >&2 exit 1 fi /usr/libexec/PlistBuddy -c "Merge \"$work/assets.plist\"" "$app/Contents/Info.plist"ficompile_catalog() { local catalog=$1 destination=$2 compiled relative target prepared mkdir "$work/strings" prepared="$work/$(basename "$catalog")" Scripts/parcel-dev.sh prepare-catalog "$catalog" "$prepared" if ! xcrun xcstringstool compile "$prepared" --output-directory "$work/strings" > "$work/strings.log" 2>&1; then /bin/cat "$work/strings.log" >&2 return 1 fi while IFS= read -r -d '' compiled; do relative=${compiled#"$work/strings/"} target="$destination/$relative" if [[ -e $target ]]; then echo "Resource already exists: $relative" >&2 return 1 else mkdir -p "$(dirname "$target")" cp "$compiled" "$target" fi done < <(find "$work/strings" -type f -print0) rm -rf "$work/strings"}while IFS= read -r -d '' catalog; do compile_catalog "$catalog" "$resources"done < <(find Resources -type f -name '*.xcstrings' -print0)while IFS= read -r -d '' catalog; do rm "$catalog"done < <(find "$resources" -type f -name '*.xcstrings' -print0)
# Pseudo catalogs are generated only into staged debug resources, never into SwiftPM's cache.if [[ $configuration == debug ]]; then # Main may have no catalog of its own; let module bundles choose their developer locale. /usr/libexec/PlistBuddy -c 'Add :CFBundleAllowMixedLocalizations bool true' "$app/Contents/Info.plist" shopt -s nullglob root_catalogs=(Resources/*.xcstrings) if (( ${#root_catalogs[@]} )); then Scripts/check-localization-pseudo.sh Resources "$resources" fi for directory in Sources/*/Resources; do module_catalogs=("$directory"/*.xcstrings) (( ${#module_catalogs[@]} )) || continue module=${directory#Sources/} module=${module%/Resources} module_bundles=("$resources"/*_"$module".bundle) (( ${#module_bundles[@]} )) || continue if (( ${#module_bundles[@]} != 1 )); then printf 'Ambiguous resource bundle for %s\n' "$module" >&2 exit 1 fi destination=${module_bundles[0]} if [[ -d $destination/Contents/Resources ]]; then destination+=/Contents/Resources; fi Scripts/check-localization-pseudo.sh "$directory" "$destination" doneelse # Refuse leaked developer resources rather than shipping them from a stale or supplied bundle. if [[ -n $(find "$resources" -type d -iname 'en-XA.lproj' -print -quit) ]]; then printf 'Release bundle contains pseudo-localization resources.\n' >&2 exit 1 fifi
# The main bundle advertises shipping languages only; pseudo is not a picker option.localizations=$(find "$resources" -type d -name '*.lproj' -exec basename {} .lproj \; | LC_ALL=C sort -u)/usr/libexec/PlistBuddy -c 'Add :CFBundleLocalizations array' "$app/Contents/Info.plist"while IFS= read -r localization; do [[ $localization == Base || $localization == en-XA ]] && continue [[ $localization =~ ^[A-Za-z0-9_-]+$ ]] || { echo "Invalid localization: $localization" >&2; exit 1; } /usr/libexec/PlistBuddy -c "Add :CFBundleLocalizations: string $localization" "$app/Contents/Info.plist"done <<< "$localizations"# The CLI needs this identity/localization metadata; signing rejects a link outside Resources.cp "$app/Contents/Info.plist" "$resources/bin/Info.plist"
for binary in "$app/Contents/MacOS/$PRODUCT_NAME" "$resources/bin/$PRODUCT_CLI"; do Scripts/parcel-dev.sh strip-binary-paths "$binary" "$PWD"doneif [[ $configuration == release ]]; then Scripts/parcel-dev.sh check-binaries "$app" "$PRODUCT_NAME" "$PWD"else Scripts/parcel-dev.sh check-binaries --sdk-only "$app" "$PRODUCT_NAME" "$PWD"fi
sign() { local args=(--force --sign "$identity" --options runtime) if [[ $configuration == release && $preview == 0 && $identity != '-' ]]; then args+=(--timestamp) else args+=(--timestamp=none) fi if ! codesign "${args[@]}" "$@" > "$work/sign.log" 2>&1; then /bin/cat "$work/sign.log" >&2 return 1 fi}sign "$framework/Versions/B/XPCServices/Installer.xpc"sign --preserve-metadata=entitlements "$framework/Versions/B/XPCServices/Downloader.xpc"sign "$framework/Versions/B/Autoupdate"sign "$framework/Versions/B/Updater.app"sign "$framework"sign "$resources/bin/$PRODUCT_CLI"# Without a team ID the hardened runtime refuses to load our own embedded Sparkle, so local builds opt out of library validation.if ! codesign -dv "$framework" > "$work/framework-signature.log" 2>&1; then /bin/cat "$work/framework-signature.log" >&2 exit 1fiif ! grep -q '^TeamIdentifier=' "$work/framework-signature.log"; then echo 'The framework signature has no team identifier metadata.' >&2 exit 1fiif grep -q '^TeamIdentifier=not set$' "$work/framework-signature.log"; then if [[ $configuration == release && $preview == 0 && ${PARCEL_ALLOW_ADHOC:-0} != 1 ]]; then echo 'Release bundles need a team-signed identity; use --preview for an unnotarized beta or PARCEL_ALLOW_ADHOC=1 for rehearsals.' >&2 exit 1 fi /usr/libexec/PlistBuddy -c 'Add :com.apple.security.cs.disable-library-validation bool true' "$work/local.entitlements" > /dev/nullfiif [[ $inspectable == 1 ]]; then /usr/libexec/PlistBuddy -c 'Add :com.apple.security.get-task-allow bool true' "$work/local.entitlements" > /dev/nullfiif [[ -f $work/local.entitlements ]]; then sign --entitlements "$work/local.entitlements" "$app"else sign "$app"ficodesign --verify --strict --deep "$app"if (( ! reality )); then Scripts/check-reality-isolation.sh "$app"; fiif (( reality )) && [[ -e build/$PRODUCT_NAME.app ]]; then Scripts/designated-requirement.sh "build/$PRODUCT_NAME.app" "$app"fiif [[ $identity == '-' ]]; then echo 'Ad-hoc builds lose their Accessibility grant on every rebuild; use Scripts/make-dev-cert.sh or PARCEL_SIGN_IDENTITY to keep it.' >&2fiScripts/bundle-preflight.sh "$app"if [[ -e build/$PRODUCT_NAME.app || -L build/$PRODUCT_NAME.app ]]; then # Only filesystem safety matters for the replaced bundle; older versions lack alternate artwork. Scripts/parcel-dev.sh bundle-preflight "build/$PRODUCT_NAME.app"fiScripts/parcel-dev.sh install-bundle "$app" "build/$PRODUCT_NAME.app"