Skip to content

fix: resolve path-valued Flutter build flags against the project (CLI-05) - #79

Merged
AdamMusa merged 13 commits into
mainfrom
fix/cli-relative-paths
Nov 21, 2026
Merged

AdamMusa merged 13 commits into
mainfrom
fix/cli-relative-paths

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

WP-00 CLI-05. Based on main, which is merged in with merge commits: 08207d86 brings in 27e2ffa8 (#78), f8291c17 brings in ea3f7eb0 (#98), a1bd686a brings in f034e99b (#109), 2f133ebe brings in 06c6e28f (#84) and e3bf262b brings in 33705440 (#89). This PR's own commits are 6c79d407, 1f3e2f9d, 0c3e47f0, 64ca3df2, d3edbd79, 780c31a8, 7c135090 and 43515045.

What

ruflet build runs flutter build with chdir: set to the client dir (build_command.rb:201). Flutter resolves a relative path against its working directory. A path the developer meant relative to the project is therefore read from, or written to, build/client.

This PR makes a relative value of a path-valued flag absolute against the project root, but only when the path Flutter would use today is broken. Every other value reaches Flutter exactly as written.

  • Inputs (--dart-define-from-file, --export-options-plist) are rewritten only when the value is not a file relative to the client dir (Flutter would stop with "not found") and is a file relative to the project.
  • Outputs (--split-debug-info, --code-size-directory, --performance-measurement-file, and for build web also --output, --output-dir and -o) are rewritten only when all of these hold:
    • the client dir is the managed build/client, which a template refresh deletes (client_dir.rb:47, new_command.rb:77);
    • today's path lies inside build/client;
    • today's path is not inside what the build exports from there (build/client/build/<web|ios|macos|windows|linux|app/outputs>);
    • the project path lies inside the project;
    • the project path is not the project root or ./build, which hold build/client;
    • the project path is not inside build/client;
    • the project path is not inside the ./build/<platform> directory that the export deletes and replaces (exports.rb:24).
  • Case: when the file system holding build/client ignores case (the APFS and NTFS default), these comparisons ignore case too. The check is File.identical?(build/client, build/CLIENT). On such a file system, -o Build/Web is the exported build/client/build/web and -o BUILD is ./build, so both stay as written.

An ipa is resolved like ios. The resolver does this mapping itself, so it does not depend on its caller.

Left as written:

  • absolute paths;
  • paths that already leave build/client, such as ../../symbols;
  • outputs in a client dir the developer owns (RUFLET_CLIENT_DIR, ./ruflet_client);
  • empty or missing values, values that look like a flag, and a ~ that no shell expanded;
  • an argument or value that is not valid in its encoding (--dart-define=GREETING=caf\xE9 in a UTF-8 locale), or whose encoding clashes with the project path's. main forwards these untouched. On a1bd686a, the first raised ArgumentError and the second raised Encoding::CompatibilityError;
  • -o/--output for targets other than web, because Flutter gives them no such option;
  • every other argument, and everything after a bare --.

The resolver handles every spelling Flutter's parser accepts: --f v, --f=v, -o v and -ov.

Why

CLI-05 (P1). An earlier head (1f3e2f9d) rewrote every relative path, and that broke spellings that work today. a1bd686a still compared paths case-sensitively. On APFS it rewrote -o Build/Web and --split-debug-info=Build/App/Outputs/symbols, which main exports. This head keeps all of them working, and H1 goldens and unit tests pin them.

Behavior changes

The table lists exactly the 9 H1 goldens that differ from main. Each of these invocations is broken on main: either Flutter exits 1, or the output is stranded in build/client and deleted at the next template refresh.

Invocation main This PR
build apk --self --dart-define-from-file=config/defines.json (also --dart-define-from-file config/defines.json) Flutter "Did not find the file", exit 1 <project>/config/defines.json is read, exit 0
build ipa --self --export-options-plist ExportOptions.plist "property list does not exist", exit 1 <project>/ExportOptions.plist is read, exit 0
build apk --self --split-debug-info=symbols [--obfuscate] (also --split-debug-info symbols) build/client/symbols ./symbols
build apk --self --analyze-size --target-platform android-arm64 --code-size-directory=sizes --performance-measurement-file perf.json build/client/sizes, build/client/perf.json ./sizes, ./perf.json
build web -o dist (also --output dist, --output-dir=dist) build/client/dist, not exported ./dist
  • The [ruflet build] Running Flutter … line shows the rewritten values as absolute paths.
  • On a case-sensitive file system (Linux, or a case-sensitive APFS volume), -o Build/Web names a directory that is neither exported nor ./build. There it falls under the last row: main strands it in build/client/Build/Web, and this PR writes ./Build/Web.
  • Flutter refuses --analyze-size for an apk built for its three default ABIs (android/build_validation.dart:14), both on main and with this PR. That is why the size-analysis row names one --target-platform. The H1 flutter stub models that check.
  • None of these flags appears in the docs (git grep on ruflet_site origin/main 4d02964).

Unchanged (H1 goldens generated with main's lib)

  • build apk --self --dart-define-from-file=../../config/defines.json
  • build ipa --self --export-options-plist ../../ExportOptions.plist
  • build apk --self --split-debug-info=../../symbols
  • build apk --self --split-debug-info=../client/symbols: this is build/client/symbols today. Rewritten, it would land outside the project.
  • build web -o ../web_dist
  • build web -o . and build web -o build: inside build/client today. Rewritten, they would land on the project root and on ./build.
  • build web -o build/web (exported)
  • build apk --self --split-debug-info=build/app/outputs/symbols (exported with the APK)
  • build apk --self --split-debug-info=build/android/symbols: rewritten, the export would delete it.
  • build ipa --self --split-debug-info=build/ios/symbols (exported with build/ios)
  • RUFLET_CLIENT_DIR=<client> build apk --self --split-debug-info=symbols: written into that client, as today.
  • New, in another case on APFS:
    • build web -o Build/Web: exported to ./build/web.
    • build web -o BUILD: ./build.
    • build web -o Build/Client/web_out: inside build/client.
    • build apk --self --split-debug-info=Build/App/Outputs/symbols: exported to ./build/android/symbols.
    • build apk --self --split-debug-info=Build/Android/symbols: the export would replace it.

Tests (head 43515045; merged head e3bf262b at the end)

All runs used Homebrew Ruby 4.0.5 with GEM_HOME unset, unless noted otherwise.

  • H1: ruby test/compat/compat.rb --jobs 4 checked 343 goldens with 0 failing. It also passes on rbenv Ruby 3.4.5.
  • Against main: running this head's test/compat with main's lib (06c6e28f) gives "343 goldens, 9 failing". The 9 are exactly the goldens in the table. All 17 "Unchanged" goldens pass.
  • Against the previous head: with a1bd686a's flutter_tooling.rb, all 5 new case goldens fail ("8 goldens, 5 failing").
  • test/build_path_flags_test.rb (28 tests) runs in a temporary project and covers every rule above. The case rules are tested both ways (case ignored and case significant), and also as this machine's file system behaves.
  • Planted bugs: I planted 40, among them the old rewrite-everything rule, each guard removed in turn, each case-folded comparison made case-sensitive, and each encoding guard dropped. The tests catch 37. The 3 survivors behave identically to the real code:
    • dropping the absolute-path guard;
    • dropping the empty-value guard;
    • File.exist? in place of File.identical? in the case check, on a host that ignores case.
  • Every packages/ruflet test file passes when run in its own process: 26 files, 826 runs, 0 failures, 0 errors. That includes compat_goldens_test.rb (351 runs). No other package changes.
  • CI on 43515045: every job passed (publish is skipped). "Verify Ruflet Explorer" runs on Ruby 3.4.5; its "Run framework tests" step ran build_path_flags_test (28 runs) and compat_goldens_test (351 runs, with 1 railties skip that main has too).
  • Merged head e3bf262b (origin/main 33705440 merged in; that merge changes only packages/ruflet_server and .github/workflows/build-ruflet-client.yml, and git diff origin/main e3bf262b equals this PR's diff before the merge): H1 checked 343 goldens with 0 failing; every packages/ruflet test file in its own process: 26 files, 826 runs, 0 failures; all 17 packages/ruflet_server test files pass.

Not in this PR

  • A ruflet.yaml key for these paths (BD-05/BD-10).
  • Docs (ruflet_site cli_reference.md/build_and_release.md: what a relative path in a forwarded flag means). These go in a follow-up docs PR.
  • Size: packages/ruflet/lib grows from 378,869 to 386,478 bytes against 06c6e28f. There is no native, Flutter or template change.

Adds test/build_path_flags_test.rb, red on this commit: every path flag
CLI-05 lists, as `--flag=value` and `--flag value` (and -o/-oVALUE), is
resolved against the project root; absolute paths, values Ruflet cannot
resolve and every other argument reach Flutter unchanged.

The H1 flutter build stub now treats path options as Flutter does,
relative to its working directory: --dart-define-from-file and
--export-options-plist must exist, --split-debug-info,
--code-size-directory (with --analyze-size), --performance-measurement-file
and a web --output/-o directory are written there. Regenerated on this
code, the goldens show today's behavior: inputs in the project are not
found, and symbols and web output land inside build/client, so `ruflet
build web -o dist` exports nothing.

Six H1 invocations are added for the spellings not covered yet.
…-05)

`ruflet build` runs Flutter in build/client, and Flutter resolves a
relative path against its working directory. So
`--dart-define-from-file=config/defines.json` and `--export-options-plist
ExportOptions.plist` were not found, `--split-debug-info=symbols` wrote
build/client/symbols, and `ruflet build web -o dist` wrote
build/client/dist and exported nothing.

The value of --dart-define-from-file, --split-debug-info,
--export-options-plist, --code-size-directory,
--performance-measurement-file and --output/--output-dir/-o is now made
absolute against the project root before Flutter runs, in every spelling
Flutter accepts (`--flag value`, `--flag=value`, `-o value`, `-ovalue`).
Absolute paths, missing or empty values, values that look like a flag,
an unexpanded `~`, and every other argument reach Flutter unchanged.

H1: only the 9 goldens that pass one of these flags change (argv, and
where the Flutter stub finds or writes the files).
The review of the first fix found relative paths that work today and that
it broke: paths written against build/client (`../../config/defines.json`,
`../../ExportOptions.plist`, `../../symbols`, `-o ../web_dist`).

Eight H1 invocations, generated with main's lib (today's behavior), pin
those plus three more that must not move: `build web -o build/web` (the
build exports it), `--split-debug-info=build/app/outputs/symbols`
(exported with the APK) and `--split-debug-info=build/android/symbols`
(today stranded in build/client; moved to ./build/android the export would
delete it), and `--split-debug-info=symbols` into a RUFLET_CLIENT_DIR the
developer owns.

build_path_flags_test.rb now runs in a temporary project and covers each
rule: inputs only when missing from the client dir and present in the
project, outputs only from the managed build/client, the export guards,
-o/--output only for web, and nothing after a bare `--`.

The H1 flutter stub also stops at a bare `--` and, like Flutter, requires
the export options plist to be a file.
…e is broken (CLI-05)

The first fix rewrote every relative path against the project, which broke
paths that work today (review of 1f3e2f9). A relative value now reaches
Flutter as written unless the path Flutter would use, relative to the
client dir, is broken:

- inputs (--dart-define-from-file, --export-options-plist) are rewritten
  only when the value is not a file in the client dir, where Flutter would
  stop with "not found", and is one in the project;
- outputs (--split-debug-info, --code-size-directory,
  --performance-measurement-file, and for web --output/--output-dir/-o)
  are rewritten only when they would land inside the managed build/client,
  which a template refresh deletes, outside what the build exports from
  there (build/client/build/<platform>), and when the project path is
  neither inside build/client nor inside the ./build/<platform> directory
  the export replaces. A client dir the developer owns (RUFLET_CLIENT_DIR,
  ./ruflet_client) keeps its outputs.

-o/--output are handled only for web, the one Ruflet target Flutter gives
them, and nothing after a bare `--` is touched. So `../../symbols`,
`-o ../web_dist`, `-o build/web` and the other spellings that work today
are unchanged, and the eight goldens of the previous commit pass.
… root as written, and resolve ipa like ios (CLI-05)

An output whose project path is outside the project, is the project root,
or is a directory holding build/client (./build) is left as written.
The resolver maps ipa to ios itself instead of relying on its caller.
Unit tests pin these, a directory standing in for an input, and outputs
beside the export directories.
…lings (CLI-05)

Flutter refuses --analyze-size for an apk built for its three default ABIs
(android/build_validation.dart), so the corpus entry now passes
--target-platform android-arm64 and the flutter stub models the check.
New goldens, generated with main's lib: build ipa --split-debug-info=build/ios/symbols,
build apk --split-debug-info=../client/symbols, build web -o . and -o build.
AdamMusa added a commit that referenced this pull request Nov 20, 2026
…t Ruby cannot read

On a file system that ignores case (APFS and NTFS by default), the
resolver compared paths by string, so it rewrote outputs that work today:
`build web -o Build/Web` and `--split-debug-info=Build/App/Outputs/...`
are exported from build/client, and `-o BUILD` is ./build. The
comparisons now fold case where the file system holding the client dir
does. H1 goldens generated with main's lib pin five such spellings.

An argument or value that is not valid in its encoding, or whose encoding
clashes with the project path, now reaches Flutter as written instead of
raising ArgumentError in the resolver, as on main.
@AdamMusa
AdamMusa merged commit f805819 into main Nov 21, 2026
12 checks passed
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.

1 participant