Skip to content

refactor: split build_command.rb into cli/build modules (WP-00 R1) - #75

Merged
AdamMusa merged 12 commits into
mainfrom
refactor/split-build-command
Nov 18, 2026
Merged

AdamMusa merged 12 commits into
mainfrom
refactor/split-build-command

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

WP-00 R1. build_command.rb (3,690 lines) is split into modules under cli/build/, with no behavior change. This branch now contains current main (#67 and the final #73, 234 goldens), merged in 58a564a. main had not changed any CLI code since the old base, so the merge had no conflicts.

What

  • build_command.rb keeps the requires, command_build and command_install. The rest moves under cli/build/: loaders and helpers, the native_config/ writers and contributors/. BuildCommand includes these modules after FlutterSdk, so Ruflet::CLI, its includers and the Rails tasks see the same methods, visibility and constants.
  • prepare_flutter_client runs the Build::Contributors list in the old order: template_refresh → apple_host → app_identity → protected_services → signing → runtime_mode → extensions → assets. A later feature adds its step with register(name, handler, before:/after:).
  • Build::ConfigSchema registers 599 ruflet.yaml keys and 22 services.yaml keys. Nothing reads it yet; it is there for CLI-22.
  • CLIENT_EXTENSION_MAP is still a literal. Making it data-driven is SVC-02.

Behavior changes

None. .gitignore re-includes packages/ruflet/lib/ruflet/cli/build/, which **/build/ would otherwise hide.

Changes in this round (after the Nov 8 approval)

  • origin/main merged in.
  • Every config_schema/*.rb file requires what it needs, so it can be loaded in any order. A test loads each file in its own process.
  • The ios.team_id description now says what the build does: build macos also writes the team into the iOS Xcode project.
  • New tests pin two contributor behaviors that no golden checks: a nil from template_refresh lets the build continue, and extensions sets @ruflet_self_contained_build.

Proof (head 1b39384f)

  • H1 goldens. ruby test/compat/compat.rb --jobs 8 prints checked 234 goldens and exits 0 on Ruby 4.0.5 and 3.4.5. compat_goldens_test.rb runs 242 tests with 0 failures.

  • Suites. Each test file runs in its own process with the in-tree RUBYLIB, on Ruby 4.0.5 and on 3.4.5 (minitest 5, as in CI). All are green:

    Package Files Runs
    ruflet 18 439
    ruflet_core 189 1071 (1 skip: needs RUFLET_ENGINE_ROOT)
    ruflet_server 13 49
    ruflet_rails 17 293
    ruflet_record 5 24

    Compared with main at c2d547b (Ruby 4.0.5), every file both trees share has the same runs and assertions. The extra 26 runs come from the 4 new build_*_test.rb files.

  • Re-planted bugs. Each bug was planted alone in a copy of this head, then the full compat check and the 4 build tests were run:

    Planted bug Caught by
    swap the extensions and assets contributors 81 goldens, build_contributors_test
    skip removing the managed macOS entitlements 81 goldens, build_native_config_test
    skip removing the managed Android permissions 3 goldens, build_native_config_test
    change the default usage string in apple_plist.rb 34 goldens
    swap signing and protected_services build_contributors_test (no golden)
    drop @ruflet_self_contained_build new pin in build_contributors_test (no golden)
    make template_refresh's nil stop the build new pin in build_contributors_test (no golden)
    source-checkout ruby_runtime path one ../ short build_command_surface_test
    a config_schema file without its require build_config_schema_test

    Rows 1 to 7 come from the Nov 8 review; rows 8 and 9 are new.

  • Carried over from the Nov 8 review at 13eaf59, still valid because git diff 13eaf591 HEAD -- packages/ruflet/lib touches only config_schema/: the Prism AST check (189 of 193 members identical, the 4 differences intended), constant resolution, and the doc harness (183 of 183).

  • CI: every check passed on 1b39384: Verify Ruflet Explorer, including Run framework tests on Ruby 3.4.5 (run 44215502829); the Android, iOS Simulator, macOS, Windows, Linux and web prebuilds; and the Explorer desktop builds (runs 44215503234 and 44215495399). No job was re-run.

Other open PRs

Record every method BuildCommand defines (visibility and parameters),
every constant it exposes (value digest) and where the source-checkout
ruby_runtime resolves, so moving the implementation into cli/build/
cannot drop or reshape anything the tests, the Rails tasks or the other
commands reach through it.
Move the 3.7k-line BuildCommand into one module per concern under
cli/build/ (config_loader, client_dir, flutter_tooling, exports,
pipeline, embedded_project, embedded_runtime, native_config/*,
contributors/*). BuildCommand includes them all, so Ruflet::CLI, the
Rails tasks and every includer resolve the same methods and constants.

Every method and constant is moved verbatim, with its comments; 192 of
193 have an identical Prism AST. The exception is
source_checkout_ruby_runtime_path, whose __dir__-relative path gains one
"../" because its file is one directory deeper; it resolves to the same
ruby_runtime checkout.

.gitignore re-includes lib/ruflet/cli/build/, which **/build/ would
otherwise hide.
prepare_flutter_client is to run the steps that write the client's
configuration from a registered list: the built-ins in their current
order, each taking one shared build context, the first refusal stopping
the build before any tool runs, and a feature's own step placed with
before:/after:.
prepare_flutter_client now runs the steps that write the client's
configuration from Build::Contributors, an ordered list each contributor
file adds itself to: template_refresh, apple_host, app_identity,
protected_services, signing, runtime_mode, extensions, assets. Each takes
one Build::Context and returns true to continue, exactly where the inline
code continued, and the first refusal stops the build before any tool
runs, as the early returns did. The Flutter steps after them are
unchanged and read the metadata and asset flags from the context.

A later feature adds its own step with Contributors.register, placed with
before:/after:, instead of editing prepare_flutter_client.
The services contributor is to hand the Android permissions and macOS
entitlements it wants to native_config writers that own those files:
the managed set is replaced, everything else in the file is kept, and a
second run changes nothing.
native_config/android_manifest gains write_android_manifest_permissions
and the new native_config/entitlements owns write_macos_entitlements.
The services contributor now only decides which permissions and
entitlements it manages and wants, and hands them to those writers.
The writers are the former loop bodies, unchanged, so the manifest and
both entitlement files come out byte-identical (H1 goldens).
The registry is to list every ruflet.yaml and services.yaml key Ruflet
reads, for `ruflet check` (CLI-22) to validate against later. A probe
records every key the build's readers ask a config for; each of those,
every key `ruflet new` and the Rails installer write, and every key the
H1 fixtures use must be registered.
Build::ConfigSchema lists every ruflet.yaml and services.yaml key Ruflet
reads: its dotted path, type (map, list, string, boolean, integer, path,
url), the feature that reads it and a short description. Each feature
declares its keys in config_schema/<feature>.rb (sections, app_identity,
backend, signing, runtime, services, extensions, assets: 599 ruflet.yaml
and 22 services.yaml keys); platform keys are registered in all three
spellings platform_build_config merges.

Nothing reads the registry yet, so no build changes. It is the list
`ruflet check` (CLI-22) will validate projects against, and new
ruflet.yaml keys register themselves in it (X4).
…e schema files

Two contributor behaviors no golden sees: a missing template root lets the
build continue, and the extensions step records @ruflet_self_contained_build.
Each config_schema file must load on its own; today only sections.rb-first
load order works.
…eam_id's macOS use

Every config_schema/<feature>.rb now requires sections (and sections the
registry), so a WP-01 schema file can be required anywhere. The ios.team_id
description says what the build does today: a macOS build writes it into the
iOS Xcode project too. The registry is not read by any build yet.
--disable-gems broke the check wherever RUBYOPT activates a gem (a local
Ruby 3.4.5 pinning minitest 5 does). The file needs no gems either way.
@AdamMusa
AdamMusa merged commit 4f64623 into main Nov 18, 2026
12 checks passed
AdamMusa added a commit that referenced this pull request Nov 20, 2026
#75 split build_command.rb into cli/build/ modules and turned
prepare_flutter_client's steps into registered contributors. The seam is
carried into that layout:

- build_command.rb requires client_bootstrap and includes ClientBootstrap
  next to FlutterSdk, as before.
- The write_client_bootstrap call, which ran right after the extension
  selection was applied and verified, is now the startup_hooks contributor
  (cli/build/contributors/startup_hooks.rb), registered after :extensions,
  so it still runs at that point, before assets and before Flutter.
- build_contributors_test pins startup_hooks in that place in BUILT_IN and
  checks that the contributor passes the build on and always continues.
AdamMusa added a commit that referenced this pull request Nov 21, 2026
Port the build fixes onto the cli/build/* split (#75) and keep #77/#78's
command registry: usage errors stay main's (exit 64), and the dispatcher,
help heredoc and new-command checks this branch had are dropped in favour
of main's. appbundle now gets aab's identity check, package rename and
stale-output clearing without being renamed to aab.
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