Skip to content

Remove a game's build folder after a successful build, with a setting to keep it - #232

Closed
v0lumehi wants to merge 7 commits into
mainfrom
v0lumehi/cleanup-after-build
Closed

v0lumehi wants to merge 7 commits into
mainfrom
v0lumehi/cleanup-after-build

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

A player builds a game once and plays it. The app on the Mac, or the game inside the shared app on the iPhone or iPad, holds everything the game needs. Breath of the Wild's 01007EF00011E000.app is 17 GB, and its build folder 01007EF00011E000_build holds another ~31 GB that only a rebuild uses (extract/ 14 GB, shader/ 12 GB, aoc/ 1.3 GB, tmp/ 1.1 GB, ipa/ 1 GB, pso/ 650 MB). Developers who rebuild often want to keep it: a new host takes minutes with the folder, and without it the game is extracted again and every shader translated again (~25 minutes for BotW's Mac shaders, hours for big iOS builds).

  • Setting: "Keep build files" in Settings (own "Build files" card, UserDefaults key keepBuildFiles), off by default. The note under it names the cost both ways: off frees tens of GB and a rebuild takes much longer, on makes rebuilds fast but each game keeps tens of GB.
  • Cleanup runs once the whole build has succeeded (script, archive step and the install on a device if there is one), never during a build and never for a failed or stopped one, or a failed install. It reuses the Free space logic (BuildFolder.remove) for every part: extracted game files, shader output, Xcode project and app build, other caches. Old shader versions are inside the shader output, and the script prunes them itself since Remove stale shader library folders after a build and offer them in Free space #231, so nothing here duplicates that.
  • Always, with either setting: tmp/.
  • The iPhone or iPad target needs the mirror. The installer copies the game's DmGame<title ID>.framework into the shell folder (ShellInstall.mirrorFramework, <shell folder>/frameworks/), and that copy is the primary one since The shell's framework mirror is the primary copy, and the installer makes it #406. The cleanup removes the build folder only when this mirror is complete, meaning the framework folder holds its binary DmGame<title ID> and game.manifest.json. If the mirror is missing or incomplete, the build folder stays as it is and the log says so in one line. The check is BuildCleanup.mirrorComplete, and BuildCleanup.run makes it. It does not apply when Keep build files is on, because then no part is removed.
  • The Mac app target needs no mirror. The .app holds everything.
  • Before a rebuild without build files, the Build page says in one line that this build extracts and translates again and takes longer. It shows only for a game that was built before and whose extract/ and shader/ are gone.
  • The log names what was removed and the space freed. The library cards show nothing new.
  • Logic is in BuildCleanup.swift. ContentView gets a few lines (the setting, arming the cleanup when the script succeeds, the status line, the Settings row). FreeSpace.removeTree and BuildModel.say lost private.

Kept, and why the install flows stay intact

  • Never touched: the game app, the IPA, games/<title ID>/ (romfs.img, aoc/), the NSPs, the library entry. Also never a part: logs/, profile/, run/, nsp/ and the staged inputs.

  • Install on the iPhone copies games/<title ID>/romfs.img and aoc/ from the output folder, not from the build folder (they are copied there by the archive step before the install), so removing extract/ and aoc/ in the build folder is safe.

  • Reinstall and Renew work on the shared app, which signs from its own project outside the build folder (ShellInstall, BuildModel.resignOnDevice). Nothing in the build folder is needed for them, so the cleanup keeps no Xcode folder back. The framework the game built stays in shell-framework/, which no part names.

  • No gameDataImage hook. Nothing reads the Mac-side game data image after a build, so extract/<v>/RomFS.img stays a build intermediate that this PR may delete. The hook (Plan.gameDataImage) and its test are removed.

  • The protected paths come from one list now: BuildFolder.protectedPaths(app:ipa:iosApp:archive:output:titleID:inputs:) (FreeSpace.swift) serves the Free space sheet and armCleanup, so the installed app and the archive folder with its romfs.img are protected in both.

  • tmp.key and tmp.partial are not in alwaysRemoved: nothing in the build scripts writes them.

  • The Build page hint msg.workdirHint (under Save to) describes the new behaviour in zh, en, sv, de and fr: the build folder is removed after a successful build unless Keep build files is on, and reuse by pointing back at the same folder only holds with it on.

Checked

  • Tests: cd frontend && swift build -c release && swift test passes (697 tests, 17 skipped, 0 failures). New BuildCleanupTests (temporary folders only): the setting's default, every part removed with the setting off, the outputs and logs kept, only scratch files removed with the setting on, nothing removed for a failed or stopped build or while the build goes on, the log line, the rebuild note's condition, the strings in zh, en, sv, de and fr without semicolons, the iPhone or iPad folder removed when the mirror is complete (testIPhoneBuildFolderIsRemovedWhenTheMirrorIsComplete), kept when the mirror is missing or has no binary (testIPhoneBuildFolderStaysWhenTheMirrorIsMissing, testIPhoneBuildFolderStaysWhenTheMirrorHasNoBinary), no mirror needed for the Mac app or with the setting on, and the whole flow for an iPhone build (testTheIPhoneBuildFolderGoesOnlyAfterTheMirrorExists). python3 -m unittest discover -s frontend-qt/tests passes. python3 tools/engine.py check ok.
  • Visual QA: NX_LAUNCHER_CAPTURE_DIR=/tmp/build-cleanup swift test --filter BuildCleanupTests. Captures on the author's machine: /tmp/build-cleanup/settings-keep-off.png, settings-keep-on.png, build-rebuild-note-crop.png, build-no-note-crop.png (full pages build-rebuild-note.png, build-no-note.png). The CLI cannot upload them.
  • Not run on a device or with a real game: no real build, no device install, no Renew on hardware. The shared app's install reads the game's framework and archive after the script (installShell, packArchive), and the cleanup runs after that. The user's game folders were not touched.

Notes

  • The Qt front end has no build folder handling (no Free space, no cleanup), so nothing was added there. Only its generated string table was regenerated (gen_localization.py).
  • The new strings (cleanup.keptNoMirror too) have text in zh, en, sv, de and fr. GermanLocalizationTests and FrenchLocalizationTests list cleanup.item (a format of two values, the same in English) with the keys that match on purpose. The French msg.workdirHint was still the old text and is updated.
  • No build part names shell-framework/, so the cleanup does not delete the framework in the build folder itself. The mirror condition makes sure that a later install never depends on a folder that was cleaned.

Scope

  • No vendored file (dm/, scripts/, docs/, ref/, AGENTS.md) is edited directly
  • Not an engine or game profile fix
  • No keys, game files or data extracted from a game

Product change: waiting 48h before merge.

@v0lumehi v0lumehi added launcher The NX2Apple launcher app enhancement New feature or request labels Oct 30, 2026
@v0lumehi
v0lumehi force-pushed the v0lumehi/cleanup-after-build branch from 56b850a to 1a6226a Compare October 30, 2026 13:42
@github-actions github-actions Bot added the windows Windows (the Qt front end) label Oct 30, 2026
@v0lumehi

Copy link
Copy Markdown
Collaborator Author

@LNPANDY rebased onto current main, CI green. It changes what a build leaves on disk for players: after a successful build the game's build folder is removed (with a setting to keep it), which saves space but means the next build of that game starts from scratch. It can merge after the 48 hours, from 2026-10-31 23:38 UTC, unless you have objections.

@LNPANDY

LNPANDY commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Reviewed the diff against current main (df71372). The cleanup itself holds up: it reuses BuildFolder.remove, arms only after a successful script run, and every failure/stop path I traced leaves done false, so nothing is deleted on a failed build or an install that failed. No user save, Mac app or games/<id> is in reach.

Three things before this merges:

  1. The Build page text still describes the old behaviour. The description says the "Save to" hint now describes Keep build files, but no hunk touches msg.workdirHint (Localization.swift:805), and it still sits under Save to (ContentView.swift:3127) promising that pointing the output folder back at the same place reuses the build. With cleanup on by default that line is wrong on every build.
  2. The gameDataImage hook is written but never set (BuildCleanup.swift:34, 57-62). If Install on the iPhone: game data once per game and version, then the slim app #213 lands, extract/<v>/RomFS.img becomes the only Mac-side copy of the game data, and this PR deletes it by default. Either fill it here or state in this PR that it must merge after Install on the iPhone: game data once per game and version, then the slim app #213 with that wiring.
  3. A later build without a device or team removes xcode/ and xcode-derived-data/ (BuildCleanup.swift:59), so a copy installed earlier loses Renew/Reinstall. That may be intended; if so, say it in the setting text.

Minor: the protected-path list at BuildCleanup.swift:131 duplicates BuildFolder.protectedPaths (FreeSpace.swift:80-88) and has already drifted (no archivePath, no iosAppPath); worth sharing one list. tmp.key/tmp.partial in alwaysRemoved match nothing the script writes.

No need to re-argue the default: silent multi-GB deletion after a successful build is a product decision and it is declared. Once 1 and 2 are settled I will merge.

@LNPANDY

LNPANDY commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Follow-up to the review above: #213 is closed (its useful half moved to #261, and it needed no --romfs separate build at all). So point 2 no longer applies — the gameDataImage hook in BuildCleanup.swift:34,57-62 can be dropped rather than wired, and extract/<v>/RomFS.img stays a build intermediate that this PR may delete.

That leaves points 1 and 3: the msg.workdirHint text still describing the old reuse behaviour, and the xcode/ + xcode-derived-data/ removal on a later build without a device or team, which costs Renew/Reinstall.

@v0lumehi
v0lumehi force-pushed the v0lumehi/cleanup-after-build branch from 1a6226a to 504ed69 Compare October 30, 2026 16:03
@v0lumehi

Copy link
Copy Markdown
Collaborator Author

@LNPANDY thanks, all three points and the minor ones are in 504ed69 (rebased onto current main, Qt table regenerated).

  1. Build page text. msg.workdirHint (Localization.swift) is rewritten in zh, en and sv: the build folder is removed after a successful build unless Keep build files is on in Settings, and pointing the output folder back at the same place only reuses the build with it on.
  2. gameDataImage. The description now says that Install on the iPhone: game data once per game and version, then the slim app #213 must not merge without wiring the hook. Install on the iPhone: game data once per game and version, then the slim app #213 is rebased onto this branch and sets it in armCleanup, resets it in startBuild, and carries the test that the image survives the cleanup.
  3. xcode/ and xcode-derived-data/. Intended, and settings.keepBuildNote now says that a later build without a device or team removes them, so a copy installed earlier loses Renew and Reinstall (zh, en, sv).

Minor: BuildFolder.protectedPaths(app:ipa:iosApp:archive:output:titleID:inputs:) in FreeSpace.swift is the one list now, used by the Free space sheet and by armCleanup (BuildCleanup.swift), so iosAppPath and the archive folder with its romfs.img are covered there too. tmp.key and tmp.partial are dropped from alwaysRemoved, since nothing in build_ipa_from_nsp.py writes them.

New tests in BuildCleanupTests: the hint and note strings per language, the shared protected list, and that only tmp is always removed without an IPA. swift build -c release, swift test (487, 0 failures), the Qt tests and scripts/patches.py check pass locally. Waiting for CI.

@v0lumehi

Copy link
Copy Markdown
Collaborator Author

@LNPANDY understood, #213 is closed, so point 2 is handled by dropping the hook: Plan.gameDataImage, its use in BuildCleanup.kept and its test are removed in 34937a1, and the description no longer says that #213 must wire it. extract/<v>/RomFS.img is a build intermediate that this PR may delete again. Points 1 and 3 and the minor items are in 504ed69 as described above. swift test passes locally (486 tests, 0 failures), waiting for CI.

@v0lumehi
v0lumehi force-pushed the v0lumehi/cleanup-after-build branch 4 times, most recently from 5f63c93 to b755b57 Compare October 31, 2026 17:10
…s keeps it

A player builds a game once and plays it: the app or IPA and the game data
hold everything the game needs, and the build folder (about 31 GB next to a
17 GB app for Breath of the Wild) only serves the next build. After a build
that succeeded as a whole, including the archive step and an install on a
device, the launcher now removes the parts the Free space sheet offers.
Settings has Keep build files (off by default) for whoever rebuilds often.

Scratch files go either way. A game installed through Xcode keeps its project
and derived data for Reinstall and Renew, and Renew now signs with
DM_COPY_GAME_RESOURCES=NO so it no longer reads the removed game files and
shaders. A failed or stopped build removes nothing. The build page says once
that a rebuild without build files starts from nothing, and the log names
what was removed and the space freed.
The shared app signs from its own project outside the build folder, so the
cleanup no longer keeps xcode/ for Renew, the re-sign parameters and the IPA
packing leftovers are gone, and the Keep build files note no longer says a
copy installed earlier loses Renew and Reinstall.

cleanup.item is the same text in English and German (a format with two
values), so GermanLocalizationTests lists it with the other keys that match.
@v0lumehi
v0lumehi force-pushed the v0lumehi/cleanup-after-build branch from b755b57 to 5fd0957 Compare October 31, 2026 17:38
@v0lumehi
v0lumehi requested a review from LNPANDY October 31, 2026 18:44
Clean up an iPhone or iPad build folder only when the game's framework mirror in the shell folder is complete.
@thehobbit85

Copy link
Copy Markdown
Contributor

@v0lumehi I checked this against main at 3162e571. The earlier review points have replies, but GitHub cannot merge the branch after the launcher refactor. The old ContentView.swift, Swift localization file and generated Qt string table have been removed on main. The cleanup tests also conflict with the test target rename and the current German localization test.

Could you port the cleanup into the current build flow, carry the strings into frontend/l10n/, and update the tests on this PR? Please attach the before/after captures listed in the description and record the real build, device install and Renew result. That will let the owner finish the review on a green revision.

@v0lumehi v0lumehi modified the milestones: v1.3.0, v1.4.0 Nov 7, 2026
@v0lumehi

v0lumehi commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you for the implementation, tests and time you put into this.

We have decided against automatic removal of build files. Deleting the cache after a successful build can turn the next small rebuild into a lengthy extraction and shader compilation. We will keep explicit cleanup with an explanation of the space saved and the rebuild cost.

This is a product-scope decision, not a judgment on the effort behind the contribution. We are closing it rather than keeping it in a waiting state.

@v0lumehi v0lumehi closed this Nov 9, 2026
@v0lumehi
v0lumehi deleted the v0lumehi/cleanup-after-build branch November 20, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request launcher The NX2Apple launcher app windows Windows (the Qt front end)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants