Files
MeshChatX/scripts/unify-backend-plain-files.sh
T

83 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Make the two per-arch cx_Freeze backend trees compatible with
# @electron/universal's merge requirements:
#
# 1. Every file must exist in BOTH trees (no unique-to-one-arch files).
# 2. Every non-Mach-O file must be byte-identical across trees.
#
# Python bytecode (.pyc inside library.zip) is architecture-independent;
# only timestamps and zip metadata cause SHA differences.
#
# Native Mach-O binaries (.so/.dylib on darwin) must never be copied from one
# architecture slice to the other: @electron/universal runs lipo on matching
# paths and requires x86_64 in the x64 tree and arm64 in the arm64 tree.
# Copying arm64 .so into darwin-x64 breaks universal packaging (lipo: same
# architectures). Non-binary files may still be synced when missing.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
ARM64_DIR="$ROOT/build/exe/darwin-arm64"
X64_DIR="$ROOT/build/exe/darwin-x64"
if [[ ! -d "$ARM64_DIR" || ! -d "$X64_DIR" ]]; then
echo "unify-backend: one or both backend dirs missing, skipping"
exit 0
fi
unified=0
synced=0
copy_missing() {
local src_dir="$1" dst_dir="$2" label="$3"
while IFS= read -r -d '' rel; do
rel="${rel#./}"
if [[ ! -f "$dst_dir/$rel" ]]; then
local src_file="$src_dir/$rel"
local ft
ft=$(file --brief --no-pad "$src_file" 2>/dev/null || true)
if [[ "$ft" == Mach-O* ]]; then
echo "unify-backend: refusing to copy Mach-O across architecture trees: $rel" >&2
echo " ($label); source reports: $ft" >&2
echo " Fix the cx_Freeze build for ${dst_dir##*/} (darwin-x64 needs x86_64 Python: PYTHON_CMD / PYTHON_CMD_X64)." >&2
exit 1
fi
mkdir -p "$dst_dir/$(dirname "$rel")"
cp "$src_file" "$dst_dir/$rel"
echo " synced ($label): $rel"
synced=$((synced + 1))
fi
done < <(cd "$src_dir" && find . -type f -print0)
}
copy_missing "$ARM64_DIR" "$X64_DIR" "arm64 -> x64"
copy_missing "$X64_DIR" "$ARM64_DIR" "x64 -> arm64"
while IFS= read -r -d '' rel; do
rel="${rel#./}"
arm64_file="$ARM64_DIR/$rel"
x64_file="$X64_DIR/$rel"
[[ -f "$x64_file" ]] || continue
if cmp -s "$arm64_file" "$x64_file"; then
continue
fi
filetype=$(file --brief --no-pad "$arm64_file" 2>/dev/null || true)
if [[ "$filetype" == Mach-O* ]]; then
continue
fi
cp "$arm64_file" "$x64_file"
echo " unified: $rel"
unified=$((unified + 1))
done < <(cd "$ARM64_DIR" && find . -type f -print0)
total=$((unified + synced))
if [[ $total -gt 0 ]]; then
echo "unify-backend: synced $synced missing file(s), unified $unified differing file(s)"
else
echo "unify-backend: all files already identical and present in both trees"
fi