Skip to content
6 changes: 5 additions & 1 deletion packages/flutter_tools/bin/fuchsia_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ Future<void> run(List<String> args) async {
BuildMode.debug,
'',
treeShakeIcons: false,
packagesPath: globals.fs.path.normalize(globals.fs.path.absolute(argResults[_kOptionPackages] as String)),
packageConfigPath: globals.fs.path.normalize(
globals.fs.path.absolute(
argResults[_kOptionPackages] as String,
),
),
),
),
watcher: collector,
Expand Down
53 changes: 46 additions & 7 deletions packages/flutter_tools/lib/src/build_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:meta/meta.dart';

import 'package:package_config/package_config_types.dart';

import 'artifacts.dart';
Expand Down Expand Up @@ -37,7 +39,7 @@ class BuildInfo {
List<String>? dartExperiments,
required this.treeShakeIcons,
this.performanceMeasurementFile,
this.packagesPath = '.dart_tool/package_config.json', // TODO(zanderso): make this required and remove the default.
required this.packageConfigPath,
this.nullSafetyMode = NullSafetyMode.sound,
this.codeSizeDirectory,
this.androidGradleDaemon = true,
Expand Down Expand Up @@ -75,7 +77,7 @@ class BuildInfo {
///
/// This is used by package:package_config to locate the actual package_config.json
/// file. If not provided, defaults to `.dart_tool/package_config.json`.
final String packagesPath;
final String packageConfigPath;

final List<String> fileSystemRoots;
final String? fileSystemScheme;
Expand Down Expand Up @@ -184,10 +186,47 @@ class BuildInfo {
/// If set, web builds will use the locally built CanvasKit instead of using the CDN
final bool useLocalCanvasKit;

static const BuildInfo debug = BuildInfo(BuildMode.debug, null, trackWidgetCreation: true, treeShakeIcons: false);
static const BuildInfo profile = BuildInfo(BuildMode.profile, null, treeShakeIcons: kIconTreeShakerEnabledDefault);
static const BuildInfo jitRelease = BuildInfo(BuildMode.jitRelease, null, treeShakeIcons: kIconTreeShakerEnabledDefault);
static const BuildInfo release = BuildInfo(BuildMode.release, null, treeShakeIcons: kIconTreeShakerEnabledDefault);
/// Can be used when the actual information is not needed.
static const BuildInfo dummy = BuildInfo(
BuildMode.debug,
null,
trackWidgetCreation: true,
treeShakeIcons: false,
packageConfigPath: '.dart_tool/package_config.json',
);

@visibleForTesting
static const BuildInfo debug = BuildInfo(
BuildMode.debug,
null,
trackWidgetCreation: true,
treeShakeIcons: false,
packageConfigPath: '.dart_tool/package_config.json',
);

@visibleForTesting
static const BuildInfo profile = BuildInfo(
BuildMode.profile,
null,
treeShakeIcons: kIconTreeShakerEnabledDefault,
packageConfigPath: '.dart_tool/package_config.json',
);

@visibleForTesting
static const BuildInfo jitRelease = BuildInfo(
BuildMode.jitRelease,
null,
treeShakeIcons: kIconTreeShakerEnabledDefault,
packageConfigPath: '.dart_tool/package_config.json',
);

@visibleForTesting
static const BuildInfo release = BuildInfo(
BuildMode.release,
null,
treeShakeIcons: kIconTreeShakerEnabledDefault,
packageConfigPath: '.dart_tool/package_config.json',
);

/// Returns whether a debug build is requested.
///
Expand Down Expand Up @@ -293,7 +332,7 @@ class BuildInfo {
'PERFORMANCE_MEASUREMENT_FILE': performanceMeasurementFile!,
if (bundleSkSLPath != null)
'BUNDLE_SKSL_PATH': bundleSkSLPath!,
'PACKAGE_CONFIG': packagesPath,
'PACKAGE_CONFIG': packageConfigPath,
if (codeSizeDirectory != null)
'CODE_SIZE_DIRECTORY': codeSizeDirectory!,
if (flavor != null)
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter_tools/lib/src/commands/build_aar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class BuildAarCommand extends BuildSubCommand {
DevelopmentArtifact.androidGenSnapshot,
};

@override
late final FlutterProject project = _getProject();

@override
Expand Down Expand Up @@ -182,7 +183,7 @@ class BuildAarCommand extends BuildSubCommand {
FlutterProject _getProject() {
final List<String> remainingArguments = argResults!.rest;
if (remainingArguments.isEmpty) {
return FlutterProject.current();
return super.project;
}
final File mainFile = _fileSystem.file(remainingArguments.first);
final String path;
Expand Down
7 changes: 3 additions & 4 deletions packages/flutter_tools/lib/src/commands/build_appbundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class BuildAppBundleCommand extends BuildSubCommand {
if (globals.androidSdk == null) {
exitWithNoSdkMessage();
}

final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(await getBuildInfo(),
targetArchs: stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName),
);
Expand All @@ -146,7 +145,7 @@ class BuildAppBundleCommand extends BuildSubCommand {
final List<DeferredComponent>? deferredComponents = FlutterProject.current().manifest.deferredComponents;
if (deferredComponents != null && boolArg('deferred-components') && boolArg('validate-deferred-components') && !boolArg('debug')) {
final DeferredComponentsPrebuildValidator validator = DeferredComponentsPrebuildValidator(
FlutterProject.current().directory,
project.directory,
globals.logger,
globals.platform,
title: 'Deferred components prebuild validation',
Expand All @@ -160,7 +159,7 @@ class BuildAppBundleCommand extends BuildSubCommand {
// Delete intermediates libs dir for components to resolve mismatching
// abis supported by base and dynamic feature modules.
for (final DeferredComponent component in deferredComponents) {
final Directory deferredLibsIntermediate = FlutterProject.current().directory
final Directory deferredLibsIntermediate = project.directory
.childDirectory('build')
.childDirectory(component.name)
.childDirectory('intermediates')
Expand All @@ -177,7 +176,7 @@ class BuildAppBundleCommand extends BuildSubCommand {
displayNullSafetyMode(androidBuildInfo.buildInfo);
globals.terminal.usesTerminalUi = true;
await androidBuilder?.buildAab(
project: FlutterProject.current(),
project: project,
target: targetFile,
androidBuildInfo: androidBuildInfo,
validateDeferredComponents: boolArg('validate-deferred-components'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import '../cache.dart';
import '../flutter_plugins.dart';
import '../globals.dart' as globals;
import '../macos/cocoapod_utils.dart';
import '../project.dart';
import '../runner/flutter_command.dart' show DevelopmentArtifact, FlutterCommandResult;
import '../version.dart';
import 'build.dart';
Expand Down Expand Up @@ -108,9 +107,6 @@ abstract class BuildFrameworkCommand extends BuildSubCommand {
@override
bool get reportNullSafety => false;

@protected
late final FlutterProject project = FlutterProject.current();

Future<List<BuildInfo>> getBuildInfos() async {
return <BuildInfo>[
if (boolArg('debug')) await getBuildInfo(forcedBuildMode: BuildMode.debug),
Expand Down
4 changes: 1 addition & 3 deletions packages/flutter_tools/lib/src/commands/build_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import '../cache.dart';
import '../features.dart';
import '../globals.dart' as globals;
import '../linux/build_linux.dart';
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart';

Expand Down Expand Up @@ -60,7 +59,6 @@ class BuildLinuxCommand extends BuildSubCommand {
@override
Future<FlutterCommandResult> runCommand() async {
final BuildInfo buildInfo = await getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current();
final TargetPlatform targetPlatform =
getTargetPlatformForName(stringArg('target-platform')!);
final bool needCrossBuild =
Expand All @@ -87,7 +85,7 @@ class BuildLinuxCommand extends BuildSubCommand {
displayNullSafetyMode(buildInfo);
final Logger logger = globals.logger;
await buildLinux(
flutterProject.linux,
project.linux,
buildInfo,
target: targetFile,
sizeAnalyzer: SizeAnalyzer(
Expand Down
4 changes: 1 addition & 3 deletions packages/flutter_tools/lib/src/commands/build_macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../cache.dart';
import '../features.dart';
import '../globals.dart' as globals;
import '../macos/build_macos.dart';
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart';

Expand Down Expand Up @@ -51,7 +50,6 @@ class BuildMacosCommand extends BuildSubCommand {
@override
Future<FlutterCommandResult> runCommand() async {
final BuildInfo buildInfo = await getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current();
if (!featureFlags.isMacOSEnabled) {
throwToolExit('"build macos" is not currently supported. To enable, run "flutter config --enable-macos-desktop".');
}
Expand All @@ -60,7 +58,7 @@ class BuildMacosCommand extends BuildSubCommand {
}
displayNullSafetyMode(buildInfo);
await buildMacOS(
flutterProject: flutterProject,
flutterProject: project,
buildInfo: buildInfo,
targetOverride: targetFile,
verboseLogging: globals.logger.isVerbose,
Expand Down
21 changes: 14 additions & 7 deletions packages/flutter_tools/lib/src/commands/build_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../base/io.dart';
import '../base/process.dart';
import '../build_info.dart';
import '../cache.dart';
import '../dart/package_map.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
Expand Down Expand Up @@ -45,13 +46,6 @@ class BuildPreviewCommand extends BuildSubCommand {
final ProcessUtils processUtils;
final Artifacts artifacts;

static const BuildInfo buildInfo = BuildInfo(
BuildMode.debug,
null, // no flavor
// users may add icons later
treeShakeIcons: false,
);

@override
void requiresPubspecYaml() {}

Expand All @@ -65,6 +59,19 @@ class BuildPreviewCommand extends BuildSubCommand {
final Directory targetDir = fs.systemTempDirectory.createTempSync('flutter-build-preview');
try {
final FlutterProject flutterProject = await _createProject(targetDir);

final BuildInfo buildInfo = BuildInfo(
BuildMode.debug,
null, // no flavor
// users may add icons later
packageConfigPath: flutterProject.packageConfigFile.path,
packageConfig: await loadPackageConfigWithLogging(
flutterProject.packageConfigFile,
logger: logger,
),
treeShakeIcons: false,
);

// TODO(loic-sharma): Support windows-arm64 preview device, https://github.com/flutter/flutter/issues/139949.
await buildWindows(
flutterProject.windows,
Expand Down
6 changes: 2 additions & 4 deletions packages/flutter_tools/lib/src/commands/build_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import '../base/utils.dart';
import '../build_info.dart';
import '../features.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../runner/flutter_command.dart'
show DevelopmentArtifact, FlutterCommandResult, FlutterOptions;
import '../web/compile.dart';
Expand Down Expand Up @@ -184,7 +183,6 @@ class BuildWebCommand extends BuildSubCommand {
)];
}

final FlutterProject flutterProject = FlutterProject.current();
final String target = stringArg('target')!;
final BuildInfo buildInfo = await getBuildInfo();
if (buildInfo.isDebug) {
Expand All @@ -197,7 +195,7 @@ class BuildWebCommand extends BuildSubCommand {
'--base-href should start and end with /',
);
}
if (!flutterProject.web.existsSync()) {
if (!project.web.existsSync()) {
throwToolExit('Missing index.html.');
}
if (!_fileSystem.currentDirectory
Expand Down Expand Up @@ -227,7 +225,7 @@ class BuildWebCommand extends BuildSubCommand {
analytics: globals.analytics,
);
await webBuilder.buildWeb(
flutterProject,
project,
target,
buildInfo,
ServiceWorkerStrategy.fromCliName(stringArg('pwa-strategy')),
Expand Down
4 changes: 1 addition & 3 deletions packages/flutter_tools/lib/src/commands/build_windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import '../build_info.dart';
import '../cache.dart';
import '../features.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../runner/flutter_command.dart' show FlutterCommandResult;
import '../windows/build_windows.dart';
import '../windows/visual_studio.dart';
Expand Down Expand Up @@ -49,7 +48,6 @@ class BuildWindowsCommand extends BuildSubCommand {

@override
Future<FlutterCommandResult> runCommand() async {
final FlutterProject flutterProject = FlutterProject.current();
final BuildInfo buildInfo = await getBuildInfo();
if (!featureFlags.isWindowsEnabled) {
throwToolExit('"build windows" is not currently supported. To enable, run "flutter config --enable-windows-desktop".');
Expand All @@ -64,7 +62,7 @@ class BuildWindowsCommand extends BuildSubCommand {

displayNullSafetyMode(buildInfo);
await buildWindows(
flutterProject.windows,
project.windows,
buildInfo,
targetPlatform,
target: targetFile,
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/commands/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ class DeviceDomain extends Domain {
debuggingOptions: DebuggingOptions.fromJson(
castStringKeyedMap(args['debuggingOptions'])!,
// We are using prebuilts, build info does not matter here.
BuildInfo.debug,
BuildInfo.dummy,
),
mainPath: _getStringArg(args, 'mainPath'),
route: _getStringArg(args, 'route'),
Expand Down
7 changes: 3 additions & 4 deletions packages/flutter_tools/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class RunCommand extends RunCommandBase {
runTargetName: deviceType,
runTargetOsVersion: deviceOsVersion,
runModeName: modeName,
runProjectModule: FlutterProject.current().isModule,
runProjectModule: project.isModule,
runProjectHostLanguage: hostLanguage.join(','),
runAndroidEmbeddingVersion: androidEmbeddingVersion,
runEnableImpeller: enableImpeller.asBool,
Expand Down Expand Up @@ -753,9 +753,9 @@ class RunCommand extends RunCommandBase {

@override
Future<FlutterCommandResult> runCommand() async {
final BuildInfo buildInfo = await getBuildInfo();
// Enable hot mode by default if `--no-hot` was not passed and we are in
// debug mode.
final BuildInfo buildInfo = await getBuildInfo();
final bool hotMode = shouldUseHotMode(buildInfo);
final String? applicationBinaryPath = stringArg(FlutterOptions.kUseApplicationBinary);

Expand Down Expand Up @@ -817,7 +817,6 @@ class RunCommand extends RunCommandBase {
stringsArg(FlutterOptions.kEnableExperiment).isNotEmpty) {
expFlags = stringsArg(FlutterOptions.kEnableExperiment);
}
final FlutterProject flutterProject = FlutterProject.current();
final List<FlutterDevice> flutterDevices = <FlutterDevice>[
for (final Device device in devices!)
await FlutterDevice.create(
Expand All @@ -833,7 +832,7 @@ class RunCommand extends RunCommandBase {
final ResidentRunner runner = await createRunner(
applicationBinaryPath: applicationBinaryPath,
flutterDevices: flutterDevices,
flutterProject: flutterProject,
flutterProject: project,
hotMode: hotMode,
);

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
collector = CoverageCollector(
verbose: !machine,
libraryNames: packagesToInclude,
packagesPath: buildInfo.packagesPath,
resolver: await CoverageCollector.getResolver(buildInfo.packagesPath),
packagesPath: buildInfo.packageConfigPath,
resolver: await CoverageCollector.getResolver(buildInfo.packageConfigPath),
testTimeRecorder: testTimeRecorder,
branchCoverage: boolArg('branch-coverage'),
);
Expand Down
Loading