Use --target-os for appropriate precompiled targets. (#127567)
This PR adds uses of the `--target-os` command line argument when building kernel sources for precompiled applications for supported target operating systems. The Dart CFE then: * treats `Platform.operatingSystem` as if it were defined as the constant string provided as an argument to the flag, * treats `Platform.pathSeparator` as the appropriate separator for that operating system, * attempts to constant evaluate the initializer for any field annotated with the `vm:platform-const` pragma, and * attempts to constant evaluate all calls to a method annotated with the `vm:platform-const` pragma. The `vm:platform-const` pragma can appear in either library or user code. If the attempt to constant evaluate the field initializer or method call fails, then an error is thrown at kernel compilation time. Addresses #14233. The tests in `packages/flutter_tools/test/general.shard/build_system/targets/common_test.dart` have been adjusted properly to account for the new passed command line arguments.
This commit is contained in:
@@ -206,6 +206,21 @@ class KernelSnapshot extends Target {
|
||||
forceLinkPlatform = false;
|
||||
}
|
||||
|
||||
final String? targetOS = switch (targetPlatform) {
|
||||
TargetPlatform.fuchsia_arm64 || TargetPlatform.fuchsia_x64 => 'fuchsia',
|
||||
TargetPlatform.android ||
|
||||
TargetPlatform.android_arm ||
|
||||
TargetPlatform.android_arm64 ||
|
||||
TargetPlatform.android_x64 ||
|
||||
TargetPlatform.android_x86 =>
|
||||
'android',
|
||||
TargetPlatform.darwin => 'macos',
|
||||
TargetPlatform.ios => 'ios',
|
||||
TargetPlatform.linux_arm64 || TargetPlatform.linux_x64 => 'linux',
|
||||
TargetPlatform.windows_x64 => 'windows',
|
||||
TargetPlatform.tester || TargetPlatform.web_javascript => null,
|
||||
};
|
||||
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
packagesFile,
|
||||
logger: environment.logger,
|
||||
@@ -234,6 +249,7 @@ class KernelSnapshot extends Target {
|
||||
dartDefines: decodeDartDefines(environment.defines, kDartDefines),
|
||||
packageConfig: packageConfig,
|
||||
buildDir: environment.buildDir,
|
||||
targetOS: targetOS,
|
||||
checkDartPluginRegistry: environment.generateDartPluginRegistry,
|
||||
);
|
||||
if (output == null || output.errorCount != 0) {
|
||||
|
||||
@@ -233,6 +233,7 @@ class KernelCompiler {
|
||||
String? initializeFromDill,
|
||||
String? platformDill,
|
||||
Directory? buildDir,
|
||||
String? targetOS,
|
||||
bool checkDartPluginRegistry = false,
|
||||
required String? packagesPath,
|
||||
required BuildMode buildMode,
|
||||
@@ -293,6 +294,11 @@ class KernelCompiler {
|
||||
if (aot) ...<String>[
|
||||
'--aot',
|
||||
'--tfa',
|
||||
// The --target-os flag only makes sense for whole program compilation.
|
||||
if (targetOS != null) ...<String>[
|
||||
'--target-os',
|
||||
targetOS,
|
||||
],
|
||||
],
|
||||
if (packagesPath != null) ...<String>[
|
||||
'--packages',
|
||||
|
||||
@@ -94,6 +94,8 @@ void main() {
|
||||
'--track-widget-creation',
|
||||
'--aot',
|
||||
'--tfa',
|
||||
'--target-os',
|
||||
'android',
|
||||
'--packages',
|
||||
'/.dart_tool/package_config.json',
|
||||
'--output-dill',
|
||||
@@ -132,6 +134,8 @@ void main() {
|
||||
'--track-widget-creation',
|
||||
'--aot',
|
||||
'--tfa',
|
||||
'--target-os',
|
||||
'android',
|
||||
'--packages',
|
||||
'/.dart_tool/package_config.json',
|
||||
'--output-dill',
|
||||
@@ -171,6 +175,8 @@ void main() {
|
||||
'--track-widget-creation',
|
||||
'--aot',
|
||||
'--tfa',
|
||||
'--target-os',
|
||||
'android',
|
||||
'--packages',
|
||||
'/.dart_tool/package_config.json',
|
||||
'--output-dill',
|
||||
@@ -211,6 +217,8 @@ void main() {
|
||||
'--track-widget-creation',
|
||||
'--aot',
|
||||
'--tfa',
|
||||
'--target-os',
|
||||
'android',
|
||||
'--packages',
|
||||
'/.dart_tool/package_config.json',
|
||||
'--output-dill',
|
||||
|
||||
Reference in New Issue
Block a user