@@ -1893,22 +1893,15 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
18931893 buildSystem: globals.buildSystem,
18941894 buildTargets: globals.buildTargets,
18951895 );
1896-
1897- // null implicitly means all plugins are allowed
1898- List <String >? allowedPlugins;
1899- if (stringArg (FlutterGlobalOptions .kDeviceIdOption, global: true ) == 'preview' ) {
1900- // The preview device does not currently support any plugins.
1901- allowedPlugins = PreviewDevice .supportedPubPlugins;
1902- }
1903- await project.regeneratePlatformSpecificTooling (
1904- allowedPlugins: allowedPlugins,
1905- releaseMode: featureFlags.isExplicitPackageDependenciesEnabled && getBuildMode ().isRelease,
1906- );
19071896 if (reportNullSafety) {
19081897 await _sendNullSafetyAnalyticsEvents (project);
19091898 }
19101899 }
19111900
1901+ if (regeneratePlatformSpecificToolingDurifyVerify) {
1902+ await regeneratePlatformSpecificToolingIfApplicable (project);
1903+ }
1904+
19121905 setupApplicationPackages ();
19131906
19141907 if (commandPath != null ) {
@@ -1918,6 +1911,66 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
19181911 return runCommand ();
19191912 }
19201913
1914+ /// Whether to run [regeneratePlatformSpecificTooling] in [verifyThenRunCommand] .
1915+ ///
1916+ /// By default `true` , but sub-commands that do _meta_ builds (make multiple different
1917+ /// builds sequentially in one-go) may choose to override this and provide `false` , instead
1918+ /// calling [regeneratePlatformSpecificTooling] manually when applicable.
1919+ @visibleForOverriding
1920+ bool get regeneratePlatformSpecificToolingDurifyVerify => true ;
1921+
1922+ /// Runs [FlutterProject.regeneratePlatformSpecificTooling] for [project] with appropriate configuration.
1923+ ///
1924+ /// By default, this uses [getBuildMode] to determine and provide whether a release build is being made,
1925+ /// but sub-commands (such as commands that do _meta_ builds, or builds that make multiple different builds
1926+ /// sequentially in one-go) may choose to overide this and make the call at a different point in time.
1927+ ///
1928+ /// This method should only be called when [shouldRunPub] is `true` :
1929+ /// ```dart
1930+ /// if (shouldRunPub) {
1931+ /// await regeneratePlatformSpecificTooling(project);
1932+ /// }
1933+ /// ```
1934+ ///
1935+ /// See also:
1936+ ///
1937+ /// - <https://github.com/flutter/flutter/issues/162649>.
1938+ @protected
1939+ @nonVirtual
1940+ Future <void > regeneratePlatformSpecificToolingIfApplicable (
1941+ FlutterProject project, {
1942+ bool ? releaseMode,
1943+ }) async {
1944+ if (! shouldRunPub) {
1945+ return ;
1946+ }
1947+
1948+ // TODO(matanlurey): Determine if PreviewDevice should be kept.
1949+ // https://github.com/flutter/flutter/issues/162693
1950+ final List <String >? allowedPlugins;
1951+ if (stringArg (FlutterGlobalOptions .kDeviceIdOption, global: true ) == 'preview' ) {
1952+ // The preview device does not currently support any plugins.
1953+ allowedPlugins = PreviewDevice .supportedPubPlugins;
1954+ } else {
1955+ // null means all plugins are allowed
1956+ allowedPlugins = null ;
1957+ }
1958+
1959+ await project.regeneratePlatformSpecificTooling (
1960+ allowedPlugins: allowedPlugins,
1961+ // TODO(matanlurey): Move this up, i.e. releaseMode ??= getBuildMode().release.
1962+ //
1963+ // As it stands, this is a breaking change until https://github.com/flutter/flutter/issues/162704 is
1964+ // implemented, as the build_ios_framework command (and similar) will start querying
1965+ // for getBuildMode(), causing an error (meta-build commands like build ios-framework do not have
1966+ // a single build mode). Once ios-framework and macos-framework are migrated, then this can be
1967+ // cleaned up.
1968+ releaseMode:
1969+ featureFlags.isExplicitPackageDependenciesEnabled &&
1970+ (releaseMode ?? getBuildMode ().isRelease),
1971+ );
1972+ }
1973+
19211974 Future <void > _sendNullSafetyAnalyticsEvents (FlutterProject project) async {
19221975 final BuildInfo buildInfo = await getBuildInfo ();
19231976 NullSafetyAnalysisEvent (
0 commit comments