Skip to content

build_ipa_from_nsp: set work before the default IPA path reads it - #15

Closed
JMRBDev wants to merge 3 commits into
LNPANDY:mainfrom
JMRBDev:fix-out-ipa-work-order
Closed

JMRBDev wants to merge 3 commits into
LNPANDY:mainfrom
JMRBDev:fix-out-ipa-work-order

Conversation

@JMRBDev

@JMRBDev JMRBDev commented Oct 26, 2026

Copy link
Copy Markdown

What happens: every build without -o / OUT_IPA stops right after the profile is resolved:

File "scripts/build_ipa_from_nsp.py", line 1796, in main
    out_ipa = ... else work.parent / g.get('ipa')
UnboundLocalError: cannot access local variable 'work' where it is not associated with a value

Why: the default output path is work.parent / <ipa>, but work was assigned three lines later (line 1799). The two statements just need to swap. No -o is passed by the front end (NS Port Builder), so every app build hits this — Mario Tennis Aces (0100BDE00862A000, no profile) hit it immediately after the survey, and any registered game would hit it too.

Fix: move the work = ... line above the out_ipa = ... line. One line moved, no behaviour change for builds that pass -o.

Checked: python3 -m py_compile scripts/build_ipa_from_nsp.py; the Maria Tennis Aces run continues past the profile stage with the same command line.

The default output path is `work.parent / <ipa>`, but `work` was assigned three
lines later, so every build without `-o`/OUT_IPA stopped right after the profile
was resolved (a provisional-profile game: right after the survey):

    UnboundLocalError: cannot access local variable 'work'

Mario Tennis Aces (0100BDE00862A000, no profile) hit it at line 1796. Moving the
assignment above the path computation fixes every game, including the ones the
front end builds, since the app passes no `-o`.
The daily sync takes scripts/build_ipa_from_nsp.py fresh from upstream and
re-applies the fork patches, so the ordering fix in the file alone would be
reverted (or fail the `work-dir out_ipa` anchor) on the next run. The two
patches now carry it: `work-dir work` drops the assignment from its upstream
position and `work-dir out_ipa` writes it above the path that reads it.

Checked by applying patch_nsp() to upstream's file: the work/out_ipa lines come
out in the order the fork ships, with no hunk in that region.
@JMRBDev

JMRBDev commented Oct 26, 2026

Copy link
Copy Markdown
Author

Amended: the ordering fix is now also in scripts/sync_upstream.py, so the daily sync cannot revert it (the work.parent line is a fork patch; editing only the generated file would be undone, or fail the work-dir out_ipa anchor). Verified by applying patch_nsp() to upstream's file: work comes out above out_ipa, no hunk in that region.

… the old one

seedds/nxnative LNPANDY#278 moves out_ipa under `if want_ios:` and indents it by four
spaces, which would leave the work-dir out_ipa patch without its anchor on the
next sync (the issue LNPANDY#13 pattern). The patch now detects the shape: with the
`out_ipa = None` + `if want_ios:` pair it inserts `work` above that pair and
rewrites the 8-space line; otherwise it rewrites the single 4-space line as
before. The 8-space anchor is used only in that shape, because the 4-space
string also occurs inside it.

Checked by applying patch_nsp() to upstream/main and to the LNPANDY#278 branch: both
outputs compile, and `work` comes before `out_ipa` in both.
@JMRBDev

JMRBDev commented Oct 26, 2026

Copy link
Copy Markdown
Author

Second amendment: the patch now handles the shape upstream #278 gives the out_ipa block (moved under if want_ios:, indented by four spaces). Verified by applying patch_nsp() to both upstream/main and the #278 branch — both outputs compile and keep work above out_ipa.

LNPANDY added a commit that referenced this pull request Oct 26, 2026
…#15)

My --work-dir patch moved `work = ...` up but left the default-IPA line reading
`work.parent` above it, so any build without -o died with
'cannot access local variable work'. The NS Port Builder never passes -o, so every
app build was broken; the Mac command line only escaped because it sets OUT_IPA.

The two statements are now in the right order with a comment saying why, and the
sync patcher replaces them as ONE block: patching them separately is what allowed
the wrong order in the first place (each anchor applied on its own).

Verified: work is assigned at line 1796, out_ipa reads it at 1799, and the patcher's
output still equals the tree code line for code line.
@LNPANDY

LNPANDY commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Fixed in baf9647 — and thank you for catching it, this was my bug and it broke every app build.

I moved work = ... up when adding --work-dir, but the default-IPA line that reads work.parent stayed above it. The command line escaped it because it sets OUT_IPA; NS Port Builder never passes -o, so every build from the app died.

Your diagnosis and the fix (swap the two statements) were both exactly right. I also merged the two sync-patcher entries that produced this into one block replacement: patching work and out_ipa separately is what let them land in the wrong order in the first place.

Verified: work is assigned at line 1796, out_ipa reads it at 1799, and the patcher's output still equals the tree code line for code line.

@JMRBDev

JMRBDev commented Oct 26, 2026

Copy link
Copy Markdown
Author

Closing this one: baf9647 fixed the tree and collapsed the two patch entries into a single block replacement, which is the better shape. The only piece left is what #278 will do to that block's anchor (it moves out_ipa under if want_ios: and adds the out_app block), and that is carried in #17, verified against both shapes. Thanks for the quick turnaround.

@JMRBDev JMRBDev closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants