Sitelet https://github.com/flutter/flutter/pull/191592
Skip to content

[flutter_tools] Honor configured build-dir across flutter project and build targets - #191592

Merged
auto-submit[bot] merged 6 commits into
masterfrom
investigation/issue-102924
Aug 28, 2026
Merged

auto-submit[bot] merged 6 commits into
masterfrom
investigation/issue-102924

Conversation

@bkonyi

@bkonyi bkonyi commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

When flutter config --build-dir=<out> was set, FlutterProject.buildDirectory, Environment.rootBuildDir, and multiple build commands and targets still hardcoded the 'build' string literal, causing the default build/ directory to be created and populated alongside the custom build folder.

This change:

  • Replaces hardcoded 'build' with getBuildDirectory() in FlutterProject.buildDirectory, Environment, deferred components validators/targets, and framework build commands.
  • Makes getBuildDirectory() gracefully handle environments without injected context.
  • Adds regression tests in project_test.dart, build_system_test.dart, and build_info_test.dart.

Fixes #102924

… build targets

When `flutter config --build-dir=<out>` was set, `FlutterProject.buildDirectory`, `Environment.rootBuildDir`, and multiple build commands and targets still hardcoded the `'build'` string literal, causing the default `build/` directory to be created and populated alongside the custom build folder.

This change:
- Replaces hardcoded `'build'` with `getBuildDirectory()` in `FlutterProject.buildDirectory`, `Environment`, deferred components validators/targets, and framework build commands.
- Makes `getBuildDirectory()` gracefully handle environments without injected context.
- Adds regression tests in `project_test.dart`, `build_system_test.dart`, and `build_info_test.dart`.

Fixes #102924
@bkonyi
bkonyi requested review from a team as code owners August 24, 2026 18:02
@bkonyi
bkonyi requested review from gmackall and removed request for a team August 24, 2026 18:02
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 24, 2026
@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team labels Aug 24, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Flutter tools to dynamically retrieve the build directory using getBuildDirectory() instead of hardcoding the 'build' string, allowing for a custom build directory configuration. The getBuildDirectory function is updated to retrieve Config and FileSystem from the zone context when not explicitly provided. The review feedback suggests passing FileSystem and Config arguments explicitly to getBuildDirectory() across several files to avoid unnecessary context lookups and adhere to the preference for explicit parameters over globals.

Comment thread packages/flutter_tools/lib/src/project.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/build_ios_framework.dart
Comment thread packages/flutter_tools/lib/src/commands/build_macos_framework.dart
Comment thread packages/flutter_tools/lib/src/commands/test.dart Outdated
Comment thread packages/flutter_tools/lib/src/android/deferred_components_validator.dart Outdated
Comment thread packages/flutter_tools/lib/src/build_system/build_system.dart Outdated
bkonyi added 3 commits August 24, 2026 20:53
… parameters

Pass explicit `FileSystem` and `Config` references to `getBuildDirectory()` where available to minimize fallback context lookups.
…ld targets

Resolve FlutterProject from environment.projectDir rather than FlutterProject.current() in AndroidAotDeferredComponentsBundle and DeferredComponentsGenSnapshotValidator.
…lution in Android build targets and commands

Use FlutterProject.fromDirectory(environment.projectDir).buildDirectory instead of environment.rootBuildDir in AndroidAotDeferredComponentsBundle and copyAssets. Also use project instead of FlutterProject.current() in BuildApkCommand, BuildAppBundleCommand, and DeferredComponentsPrebuildValidator.
@bkonyi
bkonyi requested review from chingjun and dcharkes August 24, 2026 23:21
.childDirectory('build')
.childDirectory(DeferredComponentsValidator.kDeferredComponentsTempDirectory);
ErrorHandlingFileSystem.deleteIfExists(dir, recursive: true);
ErrorHandlingFileSystem.deleteIfExists(outputDir, recursive: true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now deletes everything instead of just the validator output? Is that intentional? If it is intentional, it should probably be not a function in this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this deletes the temporary outputs. This is what outputDir is set to in the base DeferredComponentsValidator:

outputDir = projectDir
          .childDirectory(getBuildDirectory(null, projectDir.fileSystem))
          .childDirectory(kDeferredComponentsTempDirectory),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, gotcha!

if (localConfig == null) {
try {
localConfig = context.get<Config>();
} on UnsupportedError {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this seems kind of weird. Is this code to deal with tests not having support for something in the context?

If it's null you default back to 'build'. I thought that is what this PR is trying to fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. That was an anti-pattern to accommodate testWithoutContext tests. I have removed the try/catch on UnsupportedError in getBuildDirectory(). Callers in context-free tests now pass explicit mock/test configs, while production callers continue to resolve Config and FileSystem via context.

bkonyi added 2 commits August 27, 2026 17:08
…ccess in getBuildDirectory

Remove try/catch on UnsupportedError around global context lookups in `getBuildDirectory()`. Callers requiring custom or hermetic configurations in `testWithoutContext` pass explicit arguments rather than relying on swallowed context errors.

Propagate `outputDir` to `DeferredComponentsValidator` from commands and build targets, and support hermetic build directory testing in `FlutterProject.fromDirectoryTest`.
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 27, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 27, 2026
Merged via the queue into master with commit 48a031b Aug 28, 2026
27 of 28 checks passed
@auto-submit
auto-submit Bot deleted the investigation/issue-102924 branch August 28, 2026 00:22
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Aug 28, 2026
flutter/flutter@e8dca90...8d8c1aa

2026-08-28 engine-flutter-autoroll@skia.org Roll Packages from bd3cbc1 to cd4cdd0 (15 revisions) (flutter/flutter#191965)
2026-08-28 matthiasngeo@gmail.com Bump customer testing version to pick up forui tests (flutter/flutter#191931)
2026-08-28 victorsanniay@gmail.com Use leading scroll offset instead of infinite offset to reveal pinned slivers (flutter/flutter#191329)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 21f71051e749 to fe0b9a5261f9 (1 revision) (flutter/flutter#191960)
2026-08-28 robert.ancell@canonical.com Share the common Linux window controller code in mixins (flutter/flutter#191930)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from 2cf2f69fd9f0 to ae63a6eca3f1 (1 revision) (flutter/flutter#191953)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 11e3a7cb0fd0 to 21f71051e749 (3 revisions) (flutter/flutter#191942)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from e030e77d5413 to 2cf2f69fd9f0 (2 revisions) (flutter/flutter#191934)
2026-08-28 32538273+ValentinVignal@users.noreply.github.com Remove no-shuffle in flutter tools overall experience test (flutter/flutter#191861)
2026-08-28 bkonyi@google.com [flutter_tools] Gracefully handle Windows Application Control and security policy execution blocks (flutter/flutter#191912)
2026-08-28 bkonyi@google.com [tool] Migrate ConfigCommand to modular dependency injection (flutter/flutter#190743)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 37459da0a755 to 11e3a7cb0fd0 (9 revisions) (flutter/flutter#191929)
2026-08-28 robert.ancell@canonical.com Connect to moved-to-rect after the window is realized (flutter/flutter#191773)
2026-08-28 chris@bracken.jp macOS: Compare accessibility strings as NSStrings in tests (flutter/flutter#191853)
2026-08-28 chris@bracken.jp macOS: Record test accessibility notifications in a dictionary (flutter/flutter#191854)
2026-08-28 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from 6SXRz6wsA2Zm_rAqP... to u_fSMsPU22VvUsvSo... (flutter/flutter#191927)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from cb4c39d067f3 to e030e77d5413 (3 revisions) (flutter/flutter#191923)
2026-08-27 okorohelijah@google.com Migrate ios driver tests batch 2 to simulators (flutter/flutter#190930)
2026-08-27 bkonyi@google.com [flutter_test] Ensure LiveTestWidgetsFlutterBinding executes frame and pointer callbacks in the test zone (flutter/flutter#191595)
2026-08-27 36861262+QuncCccccc@users.noreply.github.com Deprecate legacy gen_defaults tool (flutter/flutter#191911)
2026-08-27 robert.ancell@canonical.com Fix black window in the subsurface view renderer (flutter/flutter#191850)
2026-08-27 engine-flutter-autoroll@skia.org Roll Skia from 82e972ea84b1 to 37459da0a755 (10 revisions) (flutter/flutter#191906)
2026-08-27 chris@bracken.jp iOS: Key the platform view factory registries by NSString (flutter/flutter#191855)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#191895)
2026-08-27 bkonyi@google.com [flutter_tools] Honor configured build-dir across flutter project and build targets (flutter/flutter#191592)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Revert: Handle linear and radial gradients in UberSDF (flutter/flutter#191913)
2026-08-27 34871572+gmackall@users.noreply.github.com Explicitly disable HCPP in hybrid_android_views integration test (flutter/flutter#191894)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…r#12679)

flutter/flutter@e8dca90...8d8c1aa

2026-08-28 engine-flutter-autoroll@skia.org Roll Packages from bd3cbc1 to cd4cdd0 (15 revisions) (flutter/flutter#191965)
2026-08-28 matthiasngeo@gmail.com Bump customer testing version to pick up forui tests (flutter/flutter#191931)
2026-08-28 victorsanniay@gmail.com Use leading scroll offset instead of infinite offset to reveal pinned slivers (flutter/flutter#191329)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 21f71051e749 to fe0b9a5261f9 (1 revision) (flutter/flutter#191960)
2026-08-28 robert.ancell@canonical.com Share the common Linux window controller code in mixins (flutter/flutter#191930)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from 2cf2f69fd9f0 to ae63a6eca3f1 (1 revision) (flutter/flutter#191953)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 11e3a7cb0fd0 to 21f71051e749 (3 revisions) (flutter/flutter#191942)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from e030e77d5413 to 2cf2f69fd9f0 (2 revisions) (flutter/flutter#191934)
2026-08-28 32538273+ValentinVignal@users.noreply.github.com Remove no-shuffle in flutter tools overall experience test (flutter/flutter#191861)
2026-08-28 bkonyi@google.com [flutter_tools] Gracefully handle Windows Application Control and security policy execution blocks (flutter/flutter#191912)
2026-08-28 bkonyi@google.com [tool] Migrate ConfigCommand to modular dependency injection (flutter/flutter#190743)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 37459da0a755 to 11e3a7cb0fd0 (9 revisions) (flutter/flutter#191929)
2026-08-28 robert.ancell@canonical.com Connect to moved-to-rect after the window is realized (flutter/flutter#191773)
2026-08-28 chris@bracken.jp macOS: Compare accessibility strings as NSStrings in tests (flutter/flutter#191853)
2026-08-28 chris@bracken.jp macOS: Record test accessibility notifications in a dictionary (flutter/flutter#191854)
2026-08-28 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from 6SXRz6wsA2Zm_rAqP... to u_fSMsPU22VvUsvSo... (flutter/flutter#191927)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from cb4c39d067f3 to e030e77d5413 (3 revisions) (flutter/flutter#191923)
2026-08-27 okorohelijah@google.com Migrate ios driver tests batch 2 to simulators (flutter/flutter#190930)
2026-08-27 bkonyi@google.com [flutter_test] Ensure LiveTestWidgetsFlutterBinding executes frame and pointer callbacks in the test zone (flutter/flutter#191595)
2026-08-27 36861262+QuncCccccc@users.noreply.github.com Deprecate legacy gen_defaults tool (flutter/flutter#191911)
2026-08-27 robert.ancell@canonical.com Fix black window in the subsurface view renderer (flutter/flutter#191850)
2026-08-27 engine-flutter-autoroll@skia.org Roll Skia from 82e972ea84b1 to 37459da0a755 (10 revisions) (flutter/flutter#191906)
2026-08-27 chris@bracken.jp iOS: Key the platform view factory registries by NSString (flutter/flutter#191855)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#191895)
2026-08-27 bkonyi@google.com [flutter_tools] Honor configured build-dir across flutter project and build targets (flutter/flutter#191592)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Revert: Handle linear and radial gradients in UberSDF (flutter/flutter#191913)
2026-08-27 34871572+gmackall@users.noreply.github.com Explicitly disable HCPP in hybrid_android_views integration test (flutter/flutter#191894)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…r#12679)

flutter/flutter@e8dca90...8d8c1aa

2026-08-28 engine-flutter-autoroll@skia.org Roll Packages from bd3cbc1 to cd4cdd0 (15 revisions) (flutter/flutter#191965)
2026-08-28 matthiasngeo@gmail.com Bump customer testing version to pick up forui tests (flutter/flutter#191931)
2026-08-28 victorsanniay@gmail.com Use leading scroll offset instead of infinite offset to reveal pinned slivers (flutter/flutter#191329)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 21f71051e749 to fe0b9a5261f9 (1 revision) (flutter/flutter#191960)
2026-08-28 robert.ancell@canonical.com Share the common Linux window controller code in mixins (flutter/flutter#191930)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from 2cf2f69fd9f0 to ae63a6eca3f1 (1 revision) (flutter/flutter#191953)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 11e3a7cb0fd0 to 21f71051e749 (3 revisions) (flutter/flutter#191942)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from e030e77d5413 to 2cf2f69fd9f0 (2 revisions) (flutter/flutter#191934)
2026-08-28 32538273+ValentinVignal@users.noreply.github.com Remove no-shuffle in flutter tools overall experience test (flutter/flutter#191861)
2026-08-28 bkonyi@google.com [flutter_tools] Gracefully handle Windows Application Control and security policy execution blocks (flutter/flutter#191912)
2026-08-28 bkonyi@google.com [tool] Migrate ConfigCommand to modular dependency injection (flutter/flutter#190743)
2026-08-28 engine-flutter-autoroll@skia.org Roll Skia from 37459da0a755 to 11e3a7cb0fd0 (9 revisions) (flutter/flutter#191929)
2026-08-28 robert.ancell@canonical.com Connect to moved-to-rect after the window is realized (flutter/flutter#191773)
2026-08-28 chris@bracken.jp macOS: Compare accessibility strings as NSStrings in tests (flutter/flutter#191853)
2026-08-28 chris@bracken.jp macOS: Record test accessibility notifications in a dictionary (flutter/flutter#191854)
2026-08-28 engine-flutter-autoroll@skia.org Roll Fuchsia Test Scripts from 6SXRz6wsA2Zm_rAqP... to u_fSMsPU22VvUsvSo... (flutter/flutter#191927)
2026-08-28 engine-flutter-autoroll@skia.org Roll Dart SDK from cb4c39d067f3 to e030e77d5413 (3 revisions) (flutter/flutter#191923)
2026-08-27 okorohelijah@google.com Migrate ios driver tests batch 2 to simulators (flutter/flutter#190930)
2026-08-27 bkonyi@google.com [flutter_test] Ensure LiveTestWidgetsFlutterBinding executes frame and pointer callbacks in the test zone (flutter/flutter#191595)
2026-08-27 36861262+QuncCccccc@users.noreply.github.com Deprecate legacy gen_defaults tool (flutter/flutter#191911)
2026-08-27 robert.ancell@canonical.com Fix black window in the subsurface view renderer (flutter/flutter#191850)
2026-08-27 engine-flutter-autoroll@skia.org Roll Skia from 82e972ea84b1 to 37459da0a755 (10 revisions) (flutter/flutter#191906)
2026-08-27 chris@bracken.jp iOS: Key the platform view factory registries by NSString (flutter/flutter#191855)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Sync CHANGELOG.md from stable (flutter/flutter#191895)
2026-08-27 bkonyi@google.com [flutter_tools] Honor configured build-dir across flutter project and build targets (flutter/flutter#191592)
2026-08-27 154381524+flutteractionsbot@users.noreply.github.com Revert: Handle linear and radial gradients in UberSDF (flutter/flutter#191913)
2026-08-27 34871572+gmackall@users.noreply.github.com Explicitly disable HCPP in hybrid_android_views integration test (flutter/flutter#191894)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When setting flutter config --build-dir=<out>, the default build folder is still created.

2 participants