forked from firka/flutter
Reland "Expose build mode in environment of asset transformer processes" (#144958)
Relands https://github.com/flutter/flutter/pull/144752, which had to be reverted because the branch was stale. The original branch branched off `master` before https://github.com/flutter/flutter/pull/144734 landed. That PR introduced a new `AssetTransformer` call site.
This PR branch is identical to the original but with a new commit that addresses the new call site, [update new call sites](6bb5296a61).
This commit is contained in:
@@ -15,6 +15,7 @@ import '../../devfs.dart';
|
||||
import '../../flutter_manifest.dart';
|
||||
import '../build_system.dart';
|
||||
import '../depfile.dart';
|
||||
import '../exceptions.dart';
|
||||
import '../tools/asset_transformer.dart';
|
||||
import '../tools/scene_importer.dart';
|
||||
import '../tools/shader_compiler.dart';
|
||||
@@ -35,7 +36,7 @@ Future<Depfile> copyAssets(
|
||||
Directory outputDirectory, {
|
||||
Map<String, DevFSContent> additionalContent = const <String, DevFSContent>{},
|
||||
required TargetPlatform targetPlatform,
|
||||
BuildMode? buildMode,
|
||||
required BuildMode buildMode,
|
||||
List<File> additionalInputs = const <File>[],
|
||||
String? flavor,
|
||||
}) async {
|
||||
@@ -101,6 +102,7 @@ Future<Depfile> copyAssets(
|
||||
processManager: environment.processManager,
|
||||
fileSystem: environment.fileSystem,
|
||||
dartBinaryPath: environment.artifacts.getArtifactPath(Artifact.engineDartBinary),
|
||||
buildMode: buildMode,
|
||||
);
|
||||
|
||||
final Map<String, AssetBundleEntry> assetEntries = <String, AssetBundleEntry>{
|
||||
@@ -186,7 +188,7 @@ Future<Depfile> copyAssets(
|
||||
// Copy deferred components assets only for release or profile builds.
|
||||
// The assets are included in assetBundle.entries as a normal asset when
|
||||
// building as debug.
|
||||
if (environment.defines[kDeferredComponents] == 'true' && buildMode != null) {
|
||||
if (environment.defines[kDeferredComponents] == 'true') {
|
||||
await Future.wait<void>(assetBundle.deferredComponentsEntries.entries.map<Future<void>>(
|
||||
(MapEntry<String, Map<String, AssetBundleEntry>> componentEntries) async {
|
||||
final Directory componentOutputDir =
|
||||
@@ -343,6 +345,11 @@ class CopyAssets extends Target {
|
||||
|
||||
@override
|
||||
Future<void> build(Environment environment) async {
|
||||
final String? buildModeEnvironment = environment.defines[kBuildMode];
|
||||
if (buildModeEnvironment == null) {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
|
||||
final Directory output = environment
|
||||
.buildDir
|
||||
.childDirectory('flutter_assets');
|
||||
@@ -351,6 +358,7 @@ class CopyAssets extends Target {
|
||||
environment,
|
||||
output,
|
||||
targetPlatform: TargetPlatform.android,
|
||||
buildMode: buildMode,
|
||||
flavor: environment.defines[kFlavor],
|
||||
);
|
||||
environment.depFileService.writeToFile(
|
||||
|
||||
@@ -503,6 +503,7 @@ abstract class IosAssetBundle extends Target {
|
||||
environment,
|
||||
assetDirectory,
|
||||
targetPlatform: TargetPlatform.ios,
|
||||
buildMode: buildMode,
|
||||
additionalInputs: <File>[
|
||||
flutterProject.ios.infoPlist,
|
||||
flutterProject.ios.appFrameworkInfoPlist,
|
||||
|
||||
@@ -137,6 +137,7 @@ abstract class BundleLinuxAssets extends Target {
|
||||
environment,
|
||||
outputDirectory,
|
||||
targetPlatform: targetPlatform,
|
||||
buildMode: buildMode,
|
||||
additionalContent: <String, DevFSContent>{
|
||||
'version.json': DevFSStringContent(versionInfo),
|
||||
},
|
||||
|
||||
@@ -438,6 +438,7 @@ abstract class MacOSBundleFlutterAssets extends Target {
|
||||
environment,
|
||||
assetDirectory,
|
||||
targetPlatform: TargetPlatform.darwin,
|
||||
buildMode: buildMode,
|
||||
flavor: environment.defines[kFlavor],
|
||||
);
|
||||
environment.depFileService.writeToFile(
|
||||
|
||||
@@ -444,13 +444,21 @@ _flutter.buildConfig = ${jsonEncode(buildConfig)};
|
||||
}
|
||||
}
|
||||
|
||||
final String? buildModeEnvironment = environment.defines[kBuildMode];
|
||||
if (buildModeEnvironment == null) {
|
||||
throw MissingDefineException(kBuildMode, name);
|
||||
}
|
||||
final BuildMode buildMode = BuildMode.fromCliName(buildModeEnvironment);
|
||||
|
||||
createVersionFile(environment, environment.defines);
|
||||
final Directory outputDirectory = environment.outputDir.childDirectory('assets');
|
||||
outputDirectory.createSync(recursive: true);
|
||||
|
||||
final Depfile depfile = await copyAssets(
|
||||
environment,
|
||||
environment.outputDir.childDirectory('assets'),
|
||||
targetPlatform: TargetPlatform.web_javascript,
|
||||
buildMode: buildMode,
|
||||
);
|
||||
final DepfileService depfileService = environment.depFileService;
|
||||
depfileService.writeToFile(
|
||||
|
||||
@@ -142,6 +142,7 @@ abstract class BundleWindowsAssets extends Target {
|
||||
environment,
|
||||
outputDirectory,
|
||||
targetPlatform: targetPlatform,
|
||||
buildMode: buildMode,
|
||||
);
|
||||
environment.depFileService.writeToFile(
|
||||
depfile,
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../../base/error_handling_io.dart';
|
||||
import '../../base/file_system.dart';
|
||||
import '../../base/io.dart';
|
||||
import '../../base/logger.dart';
|
||||
import '../../build_info.dart';
|
||||
import '../../devfs.dart';
|
||||
import '../../flutter_manifest.dart';
|
||||
import '../build_system.dart';
|
||||
@@ -22,13 +23,18 @@ final class AssetTransformer {
|
||||
required ProcessManager processManager,
|
||||
required FileSystem fileSystem,
|
||||
required String dartBinaryPath,
|
||||
required BuildMode buildMode,
|
||||
}) : _processManager = processManager,
|
||||
_fileSystem = fileSystem,
|
||||
_dartBinaryPath = dartBinaryPath;
|
||||
_dartBinaryPath = dartBinaryPath,
|
||||
_buildMode = buildMode;
|
||||
|
||||
static const String buildModeEnvVar = 'FLUTTER_BUILD_MODE';
|
||||
|
||||
final ProcessManager _processManager;
|
||||
final FileSystem _fileSystem;
|
||||
final String _dartBinaryPath;
|
||||
final BuildMode _buildMode;
|
||||
|
||||
/// The [Source] inputs that targets using this should depend on.
|
||||
///
|
||||
@@ -115,6 +121,9 @@ final class AssetTransformer {
|
||||
final ProcessResult result = await _processManager.run(
|
||||
command,
|
||||
workingDirectory: workingDirectory,
|
||||
environment: <String, String>{
|
||||
AssetTransformer.buildModeEnvVar: _buildMode.cliName,
|
||||
}
|
||||
);
|
||||
final String stdout = result.stdout as String;
|
||||
final String stderr = result.stderr as String;
|
||||
|
||||
@@ -147,6 +147,7 @@ Future<void> writeBundle(
|
||||
required Artifacts artifacts,
|
||||
required Logger logger,
|
||||
required Directory projectDir,
|
||||
required BuildMode buildMode,
|
||||
}) async {
|
||||
if (bundleDir.existsSync()) {
|
||||
try {
|
||||
@@ -178,6 +179,7 @@ Future<void> writeBundle(
|
||||
processManager: processManager,
|
||||
fileSystem: fileSystem,
|
||||
dartBinaryPath: artifacts.getArtifactPath(Artifact.engineDartBinary),
|
||||
buildMode: buildMode,
|
||||
);
|
||||
|
||||
// Limit number of open files to avoid running out of file descriptors.
|
||||
|
||||
@@ -411,7 +411,11 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
||||
|
||||
String? testAssetDirectory;
|
||||
if (buildTestAssets) {
|
||||
await _buildTestAsset(flavor: buildInfo.flavor, impellerStatus: debuggingOptions.enableImpeller);
|
||||
await _buildTestAsset(
|
||||
flavor: buildInfo.flavor,
|
||||
impellerStatus: debuggingOptions.enableImpeller,
|
||||
buildMode: debuggingOptions.buildInfo.mode,
|
||||
);
|
||||
testAssetDirectory = globals.fs.path.
|
||||
join(flutterProject.directory.path, 'build', 'unit_test_assets');
|
||||
}
|
||||
@@ -674,6 +678,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
||||
Future<void> _buildTestAsset({
|
||||
required String? flavor,
|
||||
required ImpellerStatus impellerStatus,
|
||||
required BuildMode buildMode,
|
||||
}) async {
|
||||
final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle();
|
||||
final int build = await assetBundle.build(
|
||||
@@ -694,6 +699,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
|
||||
artifacts: globals.artifacts!,
|
||||
logger: globals.logger,
|
||||
projectDir: globals.fs.currentDirectory,
|
||||
buildMode: buildMode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,6 +442,7 @@ class DevFS {
|
||||
required FileSystem fileSystem,
|
||||
required ProcessManager processManager,
|
||||
required Artifacts artifacts,
|
||||
required BuildMode buildMode,
|
||||
HttpClient? httpClient,
|
||||
Duration? uploadRetryThrottle,
|
||||
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
|
||||
@@ -465,6 +466,7 @@ class DevFS {
|
||||
processManager: processManager,
|
||||
fileSystem: fileSystem,
|
||||
dartBinaryPath: artifacts.getArtifactPath(Artifact.engineDartBinary),
|
||||
buildMode: buildMode,
|
||||
),
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
|
||||
@@ -1003,6 +1003,7 @@ class WebDevFS implements DevFS {
|
||||
artifacts: globals.artifacts!,
|
||||
logger: globals.logger,
|
||||
projectDir: rootDirectory,
|
||||
buildMode: buildInfo.mode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,6 +391,7 @@ class FlutterDevice {
|
||||
logger: globals.logger,
|
||||
processManager: globals.processManager,
|
||||
artifacts: globals.artifacts!,
|
||||
buildMode: buildInfo.mode,
|
||||
);
|
||||
return devFS!.create();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user