textures: extract main(argv), atomic output writes, and error guards in bc7_blocks with CLI suite #2380
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2388"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T14:51:20Z.
Change
Harden
tools/bc7_blocks.pyfor programmatic and CLI execution while keeping itsBC7Cbinary layout and--fieldsJSON output unchanged:__main__block intomain(argv=None) -> intforwardingargvtoparser.parse_args(argv).--columnsand--rows(> 0) upfront before creating directories or generating blocks.--fieldscolliding withcasevia_same_path()(Path.resolve()equality andPath.samefile()for hardlinks/aliases) and reject existing directories for either output path.tempfile.TemporaryDirectoryinstances via_atomic_write_outputs()before committing withos.replace()before making one atomic replacement per file. A later replacement can fail after the first succeeds. The error tells the caller to retry both destinations, and temporary files are cleaned up.(OSError, ValueError, struct.error)cleanly viaparser.exit(1, ...)without raw Python tracebacks.tests/bc7_blocks_cli_check.pyand registerbc7_blocks_cli_checkinCMakeLists.txt.Verification
Verified on commit
6c10634c(rebased onupstream/mainee7a6631):out/pe-env/Scripts/python.exe -B tests/bc7_blocks_cli_check.py -v->Ran 7 tests in 0.511s - OK(exit 0)out/pe-env/Scripts/python.exe -B tests/bc7_blocks_check.py -v->Ran 10 tests in 0.196s - OK (skipped=2)(8 passed; 2 optional skips:test_bcpack_mode6_strict_referenceoptional reference decoder,test_independent_decoderoptionaltexture2ddecoder; exit 0)out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py->form coverage checks passed(exit 0)out/pe-env/Scripts/python.exe -B tests/docs_links_check.py->Self-test passed. Checked 19 Markdown files and 463 links.(exit 0)out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py->Self-test passed. Checked 1709 tracked source, script and build/CI files: no bidirectional controls.(exit 0)Spot mutation checks against
tools/bc7_blocks.py(8/8 killed bytests/bc7_blocks_cli_check.py, restored cleanly):argvforwarding, bypass upfront positive dimension check, bypass existing-directory check, bypassresolve()collision check, bypasssamefile()collision check, bypass_atomic_write_outputs()staging +os.replace(), and individually dropstruct.errorandOSErrorhandlers (all returned exit 1).Evidence and follow-up
tools/bc7_blocks.fixture()(MIT, repo-authored; no game files, dumps, or binaries).--columns/--rows, path collisions via..alias and hardlink, existing directories ascaseor--fields,struct.error/ValueErrorhandling, andos.replace()/ staging failures leaving zero partial files or temp directories.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T14:55:37Z.
Review: CHANGES_REQUESTED
I reproduced two failure states on Windows at
6c10634c. With existing outputs and the secondos.replacedenied, the CLI exits 1 with a new BC7C file and the old JSON. The current injected failure only reaches the first replacement. The two destinations cannot be published together with sequential renames. Please make the per-file replacement and retry behavior explicit and add a second-replacement control with existing files. Also reject an ancestor/descendant pair before staging. Withcase.bc7c --fields case.bc7c/fields.jsonand no prior outputs, the current code exits 1 after creatingcase.bc7cas a directory. All seven existing CLI tests passed here.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T14:58:40Z.
Review: APPROVED
The follow-up rejects nested output destinations before staging and clearly reports when the first atomic replacement succeeded and the second failed. Retrying with both paths regenerates the pair. Windows: 9/9 CLI and 8/8 decoder checks passed. Two optional decoder comparisons skipped. The independent second-replacement test preserves the old JSON until a successful retry.