Skip to content

Commit e210443

Browse files
authored
[flutter_tools] Deprecate --build and --no-build flags on flutter run (flutter#191358)
## Description This PR formally deprecates the \`--build\` and \`--no-build\` flags on \`flutter run\` in favor of \`--use-application-binary\`, aligning \`flutter run\` with \`flutter drive\` (which previously deprecated \`--build\`). ### Context & Changes * In 2019 ([flutter#37735](flutter#37735)), \`flutter run\` stopped handling the \`build\` flag when \`--use-application-binary\` was added, but the flag definition was unintentionally left on \`argParser\`, causing it to remain in \`--help\` as a silent no-op. * Rather than restoring implicit build-skipping behavior (which introduces ambiguity regarding which derived artifact to run across build flavors, split APKs, and schemes), we deprecate \`--[no-]build\` and direct users to \`--use-application-binary\`. * Hides \`--build\` from standard \`flutter run -h\` output (\`hide: !verboseHelp\`). * Emits a deprecation warning when \`--build\` or \`--no-build\` is passed. * Adds hermetic unit tests in \`run_test.dart\` for the deprecation warnings. ## Related Issues Fixes flutter#68529 ## Tests - Added hermetic unit tests in \`packages/flutter_tools/test/commands.shard/hermetic/run_test.dart\` verifying warning triggers and default execution. - Verified \`packages/flutter_tools/test/general.shard/args_test.dart\` passes.
1 parent 3512ebe commit e210443

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

‎packages/flutter_tools/lib/src/commands/run.dart‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,14 @@ class RunCommand extends RunCommandBase {
489489
'a test using "flutter run" for debugging purposes. This flag is '
490490
'only available when running in debug mode.',
491491
)
492-
..addFlag('build', defaultsTo: true, help: 'If necessary, build the app before running.')
492+
..addFlag(
493+
'build',
494+
defaultsTo: true,
495+
hide: !verboseHelp,
496+
help:
497+
'(deprecated) If necessary, build the app before running. To use an existing app, pass the "--${FlutterOptions.kUseApplicationBinary}" '
498+
'flag with an existing application artifact.',
499+
)
493500
..addOption('project-root', hide: !verboseHelp, help: 'Specify the project root directory.')
494501
..addFlag(
495502
'hot',
@@ -751,6 +758,20 @@ class RunCommand extends RunCommandBase {
751758
'behave differently in a future release.',
752759
);
753760
}
761+
762+
if (argResults!.wasParsed('build')) {
763+
if (boolArg('build')) {
764+
globals.printWarning(
765+
'The "--build" flag is deprecated and will be removed in a future release. '
766+
'Building is the default behavior, so this flag can be safely removed.',
767+
);
768+
} else {
769+
globals.printWarning(
770+
'The "--no-build" flag is deprecated and will be removed in a future release. '
771+
'To use a prebuilt application, pass "--${FlutterOptions.kUseApplicationBinary}".',
772+
);
773+
}
774+
}
754775
}
755776

756777
@visibleForTesting

‎packages/flutter_tools/test/commands.shard/hermetic/run_test.dart‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,78 @@ server:
19131913
// https://github.com/flutter/flutter/issues/142060
19141914
skip: true,
19151915
);
1916+
1917+
testUsingContext(
1918+
'warning triggered when --build flag is passed',
1919+
() async {
1920+
final CommandRunner<void> runner = createTestCommandRunner(
1921+
TestRunCommandThatOnlyValidates(),
1922+
);
1923+
await runner.run(<String>['run', '--build']);
1924+
1925+
expect(
1926+
testLogger.warningText,
1927+
contains(
1928+
'The "--build" flag is deprecated and will be removed in a future release. '
1929+
'Building is the default behavior, so this flag can be safely removed.',
1930+
),
1931+
);
1932+
},
1933+
overrides: <Type, Generator>{
1934+
FileSystem: () => fileSystem,
1935+
ProcessManager: () => FakeProcessManager.any(),
1936+
Logger: () => logger,
1937+
DeviceManager: () => testDeviceManager,
1938+
},
1939+
initializeFlutterRoot: false,
1940+
);
1941+
1942+
testUsingContext(
1943+
'warning triggered when --no-build flag is passed',
1944+
() async {
1945+
final CommandRunner<void> runner = createTestCommandRunner(
1946+
TestRunCommandThatOnlyValidates(),
1947+
);
1948+
await runner.run(<String>['run', '--no-build']);
1949+
1950+
expect(
1951+
testLogger.warningText,
1952+
contains(
1953+
'The "--no-build" flag is deprecated and will be removed in a future release. '
1954+
'To use a prebuilt application, pass "--${FlutterOptions.kUseApplicationBinary}".',
1955+
),
1956+
);
1957+
},
1958+
overrides: <Type, Generator>{
1959+
FileSystem: () => fileSystem,
1960+
ProcessManager: () => FakeProcessManager.any(),
1961+
Logger: () => logger,
1962+
DeviceManager: () => testDeviceManager,
1963+
},
1964+
initializeFlutterRoot: false,
1965+
);
1966+
1967+
testUsingContext(
1968+
'no warning triggered when --build or --no-build flag is not passed',
1969+
() async {
1970+
final CommandRunner<void> runner = createTestCommandRunner(
1971+
TestRunCommandThatOnlyValidates(),
1972+
);
1973+
await runner.run(<String>['run']);
1974+
1975+
expect(
1976+
testLogger.warningText,
1977+
isNot(contains('is deprecated')),
1978+
);
1979+
},
1980+
overrides: <Type, Generator>{
1981+
FileSystem: () => fileSystem,
1982+
ProcessManager: () => FakeProcessManager.any(),
1983+
Logger: () => logger,
1984+
DeviceManager: () => testDeviceManager,
1985+
},
1986+
initializeFlutterRoot: false,
1987+
);
19161988
});
19171989
}
19181990

0 commit comments

Comments
 (0)