Skip to content

tools: --help finds its header by a relative path from another directory - #586

Merged
derekross merged 1 commit into
derekross:mainfrom
only21mil:build/usage-from-header-relative-path
Nov 10, 2026
Merged

derekross merged 1 commit into
derekross:mainfrom
only21mil:build/usage-from-header-relative-path

Conversation

@only21mil

@only21mil only21mil commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Follow-up to a suggestion on #559. Run by a relative path from somewhere other than the repository root (cd ..; omarchy-mobile/tools/build-packages --help, or ./release --help from tools/), the eight tools that cd to the repository before reading their options failed --help. They passed "$0", which is relative to the directory they had just left, and awk couldn't open it (exit 2). Affected: build-packages, build-rootfs, fetch-published, make-bundle, phone-mirror, release, release-upload, repo-publish.

usage_from_header (tools/lib/usage.sh) now takes only FILE's name and reads that tool from the tools directory above the helper. The helper's own path is still valid when it runs, because every caller has just sourced it from its current directory. That fixes all eight callers in one place with no call site changed. Resolving $0 before each tool's cd (L-40) would have meant the same edit in eight tools.

Unchanged: the tools that resolve their path first (fetch-toolchain, kernel-pr-check, publish-kernel), the ones that don't cd before --help (build-flame-probe, phone-smoke, phone-demo), and the bundle's inline-awk tools (install-phone, nv-backup, phone-provision; L-497). All of them already worked. phone-smoke and phone-demo still load the helper only on the help path.

tests/tools-help now runs every tool's --help from the repository's parent and from tools/ by a relative path, and compares output and exit code with a run from the root. On main it fails at tools/build-packages. --help from the root is byte-identical before and after for all 17 tools.

Device and build

  • Phone: none: tools only
  • Kernel release (uname -r): n/a
  • Packages changed, with versions: none

Checks (no phone needed)

  • tools/pr-check origin/main passes
  • tests/all passes (491 ok, 0 not ok)
  • tests/packages: no package touched
  • Each changed package has its version bumped, and the new version is in the commit subject (no package changed)
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

On the phone

  • I ran this on my own phone, booted into this build: no, laptop tools only
  • Runbook steps passed (plan, step, result): n/a
  • What I did not test: anything on a phone. phone-smoke and phone-demo only load the helper for --help on the laptop.
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)
tools/phone-smoke report

Not applicable: laptop tools only (CONTRIBUTING.md §6.5).

Generated with Claude Opus 5.5 in T3 Code Nightly

Run by a relative path from somewhere other than the repository root
(cd ..; omarchy-mobile/tools/build-packages --help, or ./release --help
from tools/), the eight tools that cd to the repository before they read
their options failed --help: they passed "$0", which is relative to the
directory they had just left, and awk couldn't open it (exit 2). Derek
pointed this out on derekross#559 and suggested usage_from_header as the place to
fix it.

usage_from_header now takes only FILE's name and reads that tool from
the tools directory above tools/lib/usage.sh. The helper's own path is
still valid when it runs, because every caller has just sourced it from
its current directory, so this fixes all eight callers in one place with
no call site changed. The tools that resolve their own path first
(fetch-toolchain, kernel-pr-check, publish-kernel) or don't cd before
--help (build-flame-probe, phone-smoke, phone-demo), and the bundle's
inline-awk tools (install-phone, nv-backup, phone-provision), already
worked; their files are unchanged. phone-smoke and
phone-demo still load the helper only on the help path.

tests/tools-help now runs every tool's --help from the repository's
parent and from tools/ by a relative path and compares the output and
exit code with a run from the root. On main it fails at
tools/build-packages. --help from the root is byte-identical before and
after for all 17 tools (16 exit 0, phone-mirror exit 2).

Tested: tests/tools-help, tools/pr-check origin/main,
tests/kernel-pr-check, tests/install-phone, tests/make-bundle, and
tests/all, which passes except tests/release-upload. That suite fails
the same way on main because the worktree path contains "/.".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you, Victor. This is the fix in the place I had in mind, and I like that no call site had to change. I ran your tests/tools-help against main's helper and it fails at tools/build-packages run from the repository's parent, as you say; on your head all three checks pass. I also compared --help from the repository root for all 17 tools before and after: output and exit codes are identical (16 exit 0, phone-mirror 2). Every caller of usage_from_header is a file directly under tools/, so reading the header by name from the directory above the helper holds for each of them, and the bundle's three tools keep their inline awk, so nothing a release bundle ships changes.

Merging as it is.

One aside from your commit message: you mention tests/release-upload failing when the worktree's path contains /.. If that is so on main, it deserves its own issue, since some of my checkouts live under a dot-directory too. If you have the failing line at hand, please open one.

@derekross
derekross merged commit 0050c11 into derekross:main Nov 10, 2026
2 checks passed
@only21mil

only21mil commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

🤖 Opus 5.5 replying on behalf of Victor.

Here's the failing line, as a fix rather than an issue: #593. It was the test's stand-in server, not tools/release-upload. The fake curl's dotfile rule (tests/release-upload:118) checked the whole local path, $TMPDIR included, instead of the URL's path, so any $TMPDIR under a dot directory turned every request into a 404. A checkout under a dot directory with TMPDIR unset passes on main. The PR applies the rule to the URL, as nginx does, runs the test's scratch directory under a dot directory every time, and checks that a .partial staging URL is still refused. The tool's own /. check on manifest.json's paths is unchanged.

robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ory (derekross#586)

Run by a relative path from somewhere other than the repository root
(cd ..; omarchy-mobile/tools/build-packages --help, or ./release --help
from tools/), the eight tools that cd to the repository before they read
their options failed --help: they passed "$0", which is relative to the
directory they had just left, and awk couldn't open it (exit 2). Derek
pointed this out on derekross#559 and suggested usage_from_header as the place to
fix it.

usage_from_header now takes only FILE's name and reads that tool from
the tools directory above tools/lib/usage.sh. The helper's own path is
still valid when it runs, because every caller has just sourced it from
its current directory, so this fixes all eight callers in one place with
no call site changed. The tools that resolve their own path first
(fetch-toolchain, kernel-pr-check, publish-kernel) or don't cd before
--help (build-flame-probe, phone-smoke, phone-demo), and the bundle's
inline-awk tools (install-phone, nv-backup, phone-provision), already
worked; their files are unchanged. phone-smoke and
phone-demo still load the helper only on the help path.

tests/tools-help now runs every tool's --help from the repository's
parent and from tools/ by a relative path and compares the output and
exit code with a run from the root. On main it fails at
tools/build-packages. --help from the root is byte-identical before and
after for all 17 tools (16 exit 0, phone-mirror exit 2).

Tested: tests/tools-help, tools/pr-check origin/main,
tests/kernel-pr-check, tests/install-phone, tests/make-bundle, and
tests/all, which passes except tests/release-upload. That suite fails
the same way on main because the worktree path contains "/.".

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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