From 191760b5cb6d9a8e6e4d553afe5e176d52edf978 Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:49:03 +0800 Subject: [PATCH] Ship the Linux Preset Caches Before Packing the AppImage (#17485) --- .github/workflows/build_orca.yml | 24 ++----- build_linux.sh | 18 +++-- docs/HLSD/preset-cache.md | 3 +- scripts/build_preset_cache.sh | 71 ++++++++++--------- .../platform/unix/build_linux_image.sh.in | 14 +++- 5 files changed, 69 insertions(+), 61 deletions(-) diff --git a/.github/workflows/build_orca.yml b/.github/workflows/build_orca.yml index 08ec367fdb..861a661966 100644 --- a/.github/workflows/build_orca.yml +++ b/.github/workflows/build_orca.yml @@ -770,7 +770,8 @@ jobs: run: | # Build + tar the unit tests (-t) on both Linux legs so each arch # (x86_64 + aarch64) gets tested by its own unit_tests_linux_* job. - ./build_linux.sh -istrlL + # -P ships the system preset caches into the package before the AppImage is packed from it. + ./build_linux.sh -istrlLP ./scripts/check_appimage_libs.sh ./build/package ./build/package/bin/orca-slicer appimage=./build/OrcaSlicer_Linux_AppImage${{ env.ubuntu-ver-str }}${{ env.arch_suffix }}_${{ env.ver }}.AppImage mv -n ./build/OrcaSlicer_Linux_V${{ env.ver_pure }}.AppImage "$appimage" @@ -790,23 +791,6 @@ jobs: retention-days: 5 if-no-files-found: error - - name: Build system preset cache (Linux) - if: runner.os == 'Linux' - shell: bash - run: | - # Both were packed from resources/ before the caches existed, so the - # AppImage is unpacked first and the caches shipped into it and into - # the package tree; the source tree keeps its JSONs for later steps. - appimage=$(find build -maxdepth 1 -name "OrcaSlicer_Linux_AppImage*.AppImage" | head -1) - chmod +x "$appimage" - "$appimage" --appimage-extract - ./scripts/build_preset_cache.sh -b build build/package/resources/profiles squashfs-root/resources/profiles - # The runtime extracts every directory as 0700, and appimagetool (continuous - # build 333 onwards) refuses to pack a tree other users cannot read. - chmod -R a+rX squashfs-root - appimagetool=$(find build -name "appimagetool.AppImage" | head -1) - ARCH=$(uname -m) "$appimagetool" --appimage-extract-and-run squashfs-root "$appimage" - rm -rf squashfs-root # Ship the freshly-built validator so slice_check_linux (build_all.yml) # can slice-sweep the shipped profiles with this PR's engine. Taken from # the aarch64 leg so the sweep also exercises the arm build; x86_64 on @@ -855,8 +839,8 @@ jobs: path: './build/src/Release/OrcaSlicer_profile_validator' # generate_system_cache is what scripts/build_preset_cache.sh bakes the - # .opc caches with; it was already built by the "Build system - # preset cache (Linux)" step above. The .opc format is 64-bit + # .opc caches with; build_linux.sh -P already built it to ship the + # caches in the package. The .opc format is 64-bit # little-endian native, i.e. identical across every platform Orca ships, # so only the Linux binary is published. - name: Upload generate_system_cache Ubuntu diff --git a/build_linux.sh b/build_linux.sh index b4c03e52ec..484fbf7ccb 100755 --- a/build_linux.sh +++ b/build_linux.sh @@ -8,7 +8,7 @@ SCRIPT_PATH=$(dirname "$(readlink -f "${0}")") pushd "${SCRIPT_PATH}" > /dev/null function usage() { - echo "Usage: ./${SCRIPT_NAME} [-1][-b][-c][-d][-D][-e][-F][-g][-h][-i][-j N][-J N][-p][-r][-s][-t][-u][-l][-L] [-- CMAKE_ARGS...]" + echo "Usage: ./${SCRIPT_NAME} [-1][-b][-c][-d][-D][-e][-F][-g][-h][-i][-j N][-J N][-p][-P][-r][-s][-t][-u][-l][-L] [-- CMAKE_ARGS...]" echo " -1: limit builds to one core (where possible)" echo " -j N: limit builds to N cores (where possible)" echo " -J N: build up to N dependencies at a time, each still using -j jobs (default: 1)" @@ -23,6 +23,7 @@ function usage() { echo " -h: prints this help text" echo " -i: build the Orca Slicer AppImage (optional)" echo " -p: disable precompiled headers (on by default): more ccache hits after header changes, slower misses" + echo " -P: ship the system preset caches in the package and AppImage, deleting the preset JSONs they replace (CI packaging)" echo " -r: skip RAM and disk checks (low RAM compiling)" echo " -s: build the Orca Slicer (optional)" echo " -t: build tests (optional), requires -s flag" @@ -47,7 +48,7 @@ unset name BUILD_DIR=build BUILD_CONFIG=Release FORWARDED_ARGS=() -while getopts ":1j:J:bcCdDeFghiprstulL" opt ; do +while getopts ":1j:J:bcCdDeFghipPrstulL" opt ; do case ${opt} in 1 ) export CMAKE_BUILD_PARALLEL_LEVEL=1 @@ -104,6 +105,10 @@ while getopts ":1j:J:bcCdDeFghiprstulL" opt ; do SLIC3R_PRECOMPILED_HEADERS="OFF" FORWARDED_ARGS+=("-p") ;; + P ) + SHIP_PRESET_CACHES="1" + FORWARDED_ARGS+=("-P") + ;; r ) SKIP_RAM_CHECK="1" FORWARDED_ARGS+=("-r") @@ -648,11 +653,14 @@ if [[ -n "${BUILD_IMAGE}" || -n "${BUILD_ORCA}" ]] ; then pushd $BUILD_DIR > /dev/null build_linux_image="./src/build_linux_image.sh" if [[ -e ${build_linux_image} ]] ; then - extra_script_args="" + extra_script_args=() if [[ -n "${BUILD_IMAGE}" ]] ; then - extra_script_args="-i" + extra_script_args+=("-i") fi - print_and_run ${build_linux_image} ${extra_script_args} -R "${BUILD_CONFIG}" + if [[ -n "${SHIP_PRESET_CACHES}" ]] ; then + extra_script_args+=("-c") + fi + print_and_run ${build_linux_image} "${extra_script_args[@]}" -R "${BUILD_CONFIG}" echo "done" fi diff --git a/docs/HLSD/preset-cache.md b/docs/HLSD/preset-cache.md index 41a52bd633..7005583dd8 100644 --- a/docs/HLSD/preset-cache.md +++ b/docs/HLSD/preset-cache.md @@ -358,7 +358,8 @@ step, not something a build should do to a working tree by surprise: the Windows refuses that target unless given `--prune-source`, and CI passes it. Generation runs after the build, in the same job, so the caches ship with a build that -can read them. +can read them. On Linux it runs while the package tree is staged (`build_linux.sh -P`), so +the AppImage is packed from a tree that already holds them. The flatpak differs only in where the script is called from. Nothing outside flatpak-builder ever builds it, so there is no packaged tree for the workflow to point diff --git a/scripts/build_preset_cache.sh b/scripts/build_preset_cache.sh index 71d2c2db6c..b5728ddc31 100755 --- a/scripts/build_preset_cache.sh +++ b/scripts/build_preset_cache.sh @@ -89,17 +89,43 @@ find_tool() { printf '%s' "$best" } -# The preset files a vendor profile lists, relative to its vendor directory, one -# per line. Nothing when the profile is missing. -listed_presets() { - [ -f "$1" ] || return 0 - python3 - "$1" <<'EOF' -import json, sys -with open(sys.argv[1], encoding="utf-8") as f: - profile = json.load(f) -for key in ("machine_model_list", "process_list", "filament_list", "machine_list"): - for entry in profile.get(key, []): - print(entry["sub_path"]) +# Prune one profiles directory for every vendor that has a cache in the first: +# drop the vendor profile, the preset files it lists, and the directories that +# leaves empty. One process for all vendors; starting one per vendor dominated +# the run. +prune_cached_presets() { + python3 - "$1" "$2" <<'EOF' +import json, os, sys +caches_dir, target = sys.argv[1:3] +shipped = pruned = 0 +for name in sorted(os.listdir(caches_dir)): + if not name.endswith(".opc"): + continue + vendor = name[:-len(".opc")] + shipped += 1 + # Read the list from the target's own profile, before it goes: the source + # profile may already be gone when an earlier target pruned it. + profile_path = os.path.join(target, vendor + ".json") + listed = [] + if os.path.isfile(profile_path): + with open(profile_path, encoding="utf-8") as f: + profile = json.load(f) + for key in ("machine_model_list", "process_list", "filament_list", "machine_list"): + listed += [entry["sub_path"] for entry in profile.get(key, [])] + os.remove(profile_path) + pruned += 1 + vendor_dir = os.path.join(target, vendor) + if not os.path.isdir(vendor_dir): + continue + for sub_path in listed: + path = vendor_dir + "/" + sub_path # not os.path.join: an absolute sub_path stays inside + if sub_path and os.path.isfile(path): + os.remove(path) + pruned += 1 + for root, _, _ in os.walk(vendor_dir, topdown=False): + if not os.listdir(root): + os.rmdir(root) +print(f"{target}: {shipped} caches, dropped {pruned} preset JSONs") EOF } @@ -158,26 +184,5 @@ for target in "$@"; do cp "$profiles_dir"/*.opc "$resolved"/ fi - pruned=0 - shipped=0 - for cache in "$profiles_dir"/*.opc; do - vendor=$(basename "$cache" .opc) - shipped=$(( shipped + 1 )) - # Read the list from the target's own profile, before it goes: the - # source profile may already be gone when an earlier target pruned it. - listed=$(listed_presets "$resolved/$vendor.json") - if [ -f "$resolved/$vendor.json" ]; then - rm -f "$resolved/$vendor.json" - pruned=$(( pruned + 1 )) - fi - [ -d "$resolved/$vendor" ] || continue - while IFS= read -r sub_path; do - if [ -n "$sub_path" ] && [ -f "$resolved/$vendor/$sub_path" ]; then - rm -f "$resolved/$vendor/$sub_path" - pruned=$(( pruned + 1 )) - fi - done <<< "$listed" - find "$resolved/$vendor" -type d -empty -delete - done - echo "$resolved: $shipped caches, dropped $pruned preset JSONs" + prune_cached_presets "$profiles_dir" "$resolved" done diff --git a/src/dev-utils/platform/unix/build_linux_image.sh.in b/src/dev-utils/platform/unix/build_linux_image.sh.in index a7f99ba775..f47952ad81 100755 --- a/src/dev-utils/platform/unix/build_linux_image.sh.in +++ b/src/dev-utils/platform/unix/build_linux_image.sh.in @@ -22,13 +22,17 @@ fi # shellcheck source=/dev/null source "${POLICY_FILE}" -while getopts ":ihR:" opt; do +while getopts ":ichR:" opt; do case ${opt} in i ) export BUILD_IMAGE="1" ;; - h ) echo "Usage: ./build_linux_image.sh [-i][-R config]" + c ) + SHIP_PRESET_CACHES="1" + ;; + h ) echo "Usage: ./build_linux_image.sh [-i][-c][-R config]" echo " -i: Generate Appimage (optional)" + echo " -c: Ship the system preset caches, deleting the preset JSONs they replace" echo " -R: Specify from which config to obtain the binary: Release, RelWithDebInfo, or Debug" exit 1 ;; @@ -185,6 +189,12 @@ echo -n "[9/9] Generating Linux app..." fi cp -Rf ../resources "$APPDIR/resources" + # Before the AppImage is packed from this tree, so it ships the caches without a repack. + if [ -n "$SHIP_PRESET_CACHES" ]; then + # Caches copied in with resources may be stale; the script ships a fresh set. + rm -f "$APPDIR/resources/profiles"/*.opc + "${REPO_ROOT}/scripts/build_preset_cache.sh" -b . -c "$CONFIG" "$APPDIR/resources/profiles" + fi ORIGINAL_BINARY_LOCATION="" if [ -f "src/${CONFIG}/@SLIC3R_APP_CMD@" ]; then