Unverified Commit 66af44c9 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate build_info to null safety (#79469)

parent d657b4ae
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart'; import 'package:package_config/package_config_types.dart';
import 'base/config.dart'; import 'base/config.dart';
...@@ -13,35 +10,40 @@ import 'base/file_system.dart'; ...@@ -13,35 +10,40 @@ import 'base/file_system.dart';
import 'base/logger.dart'; import 'base/logger.dart';
import 'base/os.dart'; import 'base/os.dart';
import 'base/utils.dart'; import 'base/utils.dart';
import 'build_system/targets/icon_tree_shaker.dart';
import 'convert.dart'; import 'convert.dart';
import 'globals_null_migrated.dart' as globals; import 'globals_null_migrated.dart' as globals;
/// Whether icon font subsetting is enabled by default.
const bool kIconTreeShakerEnabledDefault = true;
/// Information about a build to be performed or used. /// Information about a build to be performed or used.
class BuildInfo { class BuildInfo {
const BuildInfo( const BuildInfo(
this.mode, this.mode,
this.flavor, { this.flavor, {
this.trackWidgetCreation = false, this.trackWidgetCreation = false,
this.extraFrontEndOptions, List<String>? extraFrontEndOptions,
this.extraGenSnapshotOptions, List<String>? extraGenSnapshotOptions,
this.fileSystemRoots, this.fileSystemRoots,
this.fileSystemScheme, this.fileSystemScheme,
this.buildNumber, this.buildNumber,
this.buildName, this.buildName,
this.splitDebugInfoPath, this.splitDebugInfoPath,
this.dartObfuscation = false, this.dartObfuscation = false,
this.dartDefines = const <String>[], List<String>? dartDefines,
this.bundleSkSLPath, this.bundleSkSLPath,
this.dartExperiments = const <String>[], List<String>? dartExperiments,
@required this.treeShakeIcons, required this.treeShakeIcons,
this.performanceMeasurementFile, this.performanceMeasurementFile,
this.packagesPath = '.packages', // TODO(jonahwilliams): make this required and remove the default. this.packagesPath = '.packages', // TODO(jonahwilliams): make this required and remove the default.
this.nullSafetyMode = NullSafetyMode.sound, this.nullSafetyMode = NullSafetyMode.sound,
this.codeSizeDirectory, this.codeSizeDirectory,
this.androidGradleDaemon = true, this.androidGradleDaemon = true,
this.packageConfig = PackageConfig.empty, this.packageConfig = PackageConfig.empty,
}); }) : extraFrontEndOptions = extraFrontEndOptions ?? const <String>[],
extraGenSnapshotOptions = extraGenSnapshotOptions ?? const <String>[],
dartDefines = dartDefines ?? const <String>[],
dartExperiments = dartExperiments ?? const <String>[];
final BuildMode mode; final BuildMode mode;
...@@ -59,7 +61,7 @@ class BuildInfo { ...@@ -59,7 +61,7 @@ class BuildInfo {
/// If not null, the Gradle build task will be `assembleFlavorMode` (e.g. /// If not null, the Gradle build task will be `assembleFlavorMode` (e.g.
/// `assemblePaidRelease`), and the Xcode build configuration will be /// `assemblePaidRelease`), and the Xcode build configuration will be
/// Mode-Flavor (e.g. Release-Paid). /// Mode-Flavor (e.g. Release-Paid).
final String flavor; final String? flavor;
/// The path to the .packages file to use for compilation. /// The path to the .packages file to use for compilation.
/// ///
...@@ -67,8 +69,8 @@ class BuildInfo { ...@@ -67,8 +69,8 @@ class BuildInfo {
/// file. If not provided, defaults to `.packages`. /// file. If not provided, defaults to `.packages`.
final String packagesPath; final String packagesPath;
final List<String> fileSystemRoots; final List<String>? fileSystemRoots;
final String fileSystemScheme; final String? fileSystemScheme;
/// Whether the build should track widget creation locations. /// Whether the build should track widget creation locations.
final bool trackWidgetCreation; final bool trackWidgetCreation;
...@@ -84,18 +86,18 @@ class BuildInfo { ...@@ -84,18 +86,18 @@ class BuildInfo {
/// It is used to determine whether one build is more recent than another, with higher numbers indicating more recent build. /// It is used to determine whether one build is more recent than another, with higher numbers indicating more recent build.
/// On Android it is used as versionCode. /// On Android it is used as versionCode.
/// On Xcode builds it is used as CFBundleVersion. /// On Xcode builds it is used as CFBundleVersion.
final String buildNumber; final String? buildNumber;
/// A "x.y.z" string used as the version number shown to users. /// A "x.y.z" string used as the version number shown to users.
/// For each new version of your app, you will provide a version number to differentiate it from previous versions. /// For each new version of your app, you will provide a version number to differentiate it from previous versions.
/// On Android it is used as versionName. /// On Android it is used as versionName.
/// On Xcode builds it is used as CFBundleShortVersionString. /// On Xcode builds it is used as CFBundleShortVersionString.
final String buildName; final String? buildName;
/// An optional directory path to save debugging information from dwarf stack /// An optional directory path to save debugging information from dwarf stack
/// traces. If null, stack trace information is not stripped from the /// traces. If null, stack trace information is not stripped from the
/// executable. /// executable.
final String splitDebugInfoPath; final String? splitDebugInfoPath;
/// Whether to apply dart source code obfuscation. /// Whether to apply dart source code obfuscation.
final bool dartObfuscation; final bool dartObfuscation;
...@@ -103,7 +105,7 @@ class BuildInfo { ...@@ -103,7 +105,7 @@ class BuildInfo {
/// An optional path to a JSON containing object SkSL shaders. /// An optional path to a JSON containing object SkSL shaders.
/// ///
/// Currently this is only supported for Android builds. /// Currently this is only supported for Android builds.
final String bundleSkSLPath; final String? bundleSkSLPath;
/// Additional constant values to be made available in the Dart program. /// Additional constant values to be made available in the Dart program.
/// ///
...@@ -119,11 +121,11 @@ class BuildInfo { ...@@ -119,11 +121,11 @@ class BuildInfo {
/// ///
/// This is not considered a build input and will not force assemble to /// This is not considered a build input and will not force assemble to
/// rerun tasks. /// rerun tasks.
final String performanceMeasurementFile; final String? performanceMeasurementFile;
/// If provided, an output directory where one or more v8-style heap snapshots /// If provided, an output directory where one or more v8-style heap snapshots
/// will be written for code size profiling. /// will be written for code size profiling.
final String codeSizeDirectory; final String? codeSizeDirectory;
/// Whether to enable the Gradle daemon when performing an Android build. /// Whether to enable the Gradle daemon when performing an Android build.
/// ///
...@@ -181,7 +183,7 @@ class BuildInfo { ...@@ -181,7 +183,7 @@ class BuildInfo {
/// the flavor name in the output files is lower-cased (see flutter.gradle), /// the flavor name in the output files is lower-cased (see flutter.gradle),
/// so the lower cased flavor name is used to compute the output file name /// so the lower cased flavor name is used to compute the output file name
String get lowerCasedFlavor => flavor?.toLowerCase(); String? get lowerCasedFlavor => flavor?.toLowerCase();
/// Convert to a structured string encoded structure appropriate for usage as /// Convert to a structured string encoded structure appropriate for usage as
/// environment variables or to embed in other scripts. /// environment variables or to embed in other scripts.
...@@ -189,28 +191,28 @@ class BuildInfo { ...@@ -189,28 +191,28 @@ class BuildInfo {
/// Fields that are `null` are excluded from this configuration. /// Fields that are `null` are excluded from this configuration.
Map<String, String> toEnvironmentConfig() { Map<String, String> toEnvironmentConfig() {
return <String, String>{ return <String, String>{
if (dartDefines?.isNotEmpty ?? false) if (dartDefines.isNotEmpty)
'DART_DEFINES': encodeDartDefines(dartDefines), 'DART_DEFINES': encodeDartDefines(dartDefines),
if (dartObfuscation != null) if (dartObfuscation != null)
'DART_OBFUSCATION': dartObfuscation.toString(), 'DART_OBFUSCATION': dartObfuscation.toString(),
if (extraFrontEndOptions?.isNotEmpty ?? false) if (extraFrontEndOptions.isNotEmpty)
'EXTRA_FRONT_END_OPTIONS': extraFrontEndOptions?.join(','), 'EXTRA_FRONT_END_OPTIONS': extraFrontEndOptions.join(','),
if (extraGenSnapshotOptions?.isNotEmpty ?? false) if (extraGenSnapshotOptions.isNotEmpty)
'EXTRA_GEN_SNAPSHOT_OPTIONS': extraGenSnapshotOptions?.join(','), 'EXTRA_GEN_SNAPSHOT_OPTIONS': extraGenSnapshotOptions.join(','),
if (splitDebugInfoPath != null) if (splitDebugInfoPath != null)
'SPLIT_DEBUG_INFO': splitDebugInfoPath, 'SPLIT_DEBUG_INFO': splitDebugInfoPath!,
if (trackWidgetCreation != null) if (trackWidgetCreation != null)
'TRACK_WIDGET_CREATION': trackWidgetCreation.toString(), 'TRACK_WIDGET_CREATION': trackWidgetCreation.toString(),
if (treeShakeIcons != null) if (treeShakeIcons != null)
'TREE_SHAKE_ICONS': treeShakeIcons.toString(), 'TREE_SHAKE_ICONS': treeShakeIcons.toString(),
if (performanceMeasurementFile != null) if (performanceMeasurementFile != null)
'PERFORMANCE_MEASUREMENT_FILE': performanceMeasurementFile, 'PERFORMANCE_MEASUREMENT_FILE': performanceMeasurementFile!,
if (bundleSkSLPath != null) if (bundleSkSLPath != null)
'BUNDLE_SKSL_PATH': bundleSkSLPath, 'BUNDLE_SKSL_PATH': bundleSkSLPath!,
if (packagesPath != null) if (packagesPath != null)
'PACKAGE_CONFIG': packagesPath, 'PACKAGE_CONFIG': packagesPath,
if (codeSizeDirectory != null) if (codeSizeDirectory != null)
'CODE_SIZE_DIRECTORY': codeSizeDirectory, 'CODE_SIZE_DIRECTORY': codeSizeDirectory!,
}; };
} }
...@@ -219,14 +221,14 @@ class BuildInfo { ...@@ -219,14 +221,14 @@ class BuildInfo {
List<String> toGradleConfig() { List<String> toGradleConfig() {
// PACKAGE_CONFIG not currently supported. // PACKAGE_CONFIG not currently supported.
return <String>[ return <String>[
if (dartDefines?.isNotEmpty ?? false) if (dartDefines.isNotEmpty)
'-Pdart-defines=${encodeDartDefines(dartDefines)}', '-Pdart-defines=${encodeDartDefines(dartDefines)}',
if (dartObfuscation != null) if (dartObfuscation != null)
'-Pdart-obfuscation=$dartObfuscation', '-Pdart-obfuscation=$dartObfuscation',
if (extraFrontEndOptions?.isNotEmpty ?? false) if (extraFrontEndOptions.isNotEmpty)
'-Pextra-front-end-options=${extraFrontEndOptions?.join(',')}', '-Pextra-front-end-options=${extraFrontEndOptions.join(',')}',
if (extraGenSnapshotOptions?.isNotEmpty ?? false) if (extraGenSnapshotOptions.isNotEmpty)
'-Pextra-gen-snapshot-options=${extraGenSnapshotOptions?.join(',')}', '-Pextra-gen-snapshot-options=${extraGenSnapshotOptions.join(',')}',
if (splitDebugInfoPath != null) if (splitDebugInfoPath != null)
'-Psplit-debug-info=$splitDebugInfoPath', '-Psplit-debug-info=$splitDebugInfoPath',
if (trackWidgetCreation != null) if (trackWidgetCreation != null)
...@@ -353,7 +355,7 @@ enum EnvironmentType { ...@@ -353,7 +355,7 @@ enum EnvironmentType {
simulator, simulator,
} }
String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber, Logger logger) { String? validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber, Logger logger) {
if (buildNumber == null) { if (buildNumber == null) {
return null; return null;
} }
...@@ -400,7 +402,7 @@ String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String bui ...@@ -400,7 +402,7 @@ String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String bui
return buildNumber; return buildNumber;
} }
String validatedBuildNameForPlatform(TargetPlatform targetPlatform, String buildName, Logger logger) { String? validatedBuildNameForPlatform(TargetPlatform targetPlatform, String buildName, Logger logger) {
if (buildName == null) { if (buildName == null) {
return null; return null;
} }
...@@ -517,8 +519,6 @@ String getNameForDarwinArch(DarwinArch arch) { ...@@ -517,8 +519,6 @@ String getNameForDarwinArch(DarwinArch arch) {
case DarwinArch.x86_64: case DarwinArch.x86_64:
return 'x86_64'; return 'x86_64';
} }
assert(false);
return null;
} }
DarwinArch getIOSArchForName(String arch) { DarwinArch getIOSArchForName(String arch) {
...@@ -536,7 +536,7 @@ DarwinArch getIOSArchForName(String arch) { ...@@ -536,7 +536,7 @@ DarwinArch getIOSArchForName(String arch) {
throw Exception('Unsupported iOS arch name "$arch"'); throw Exception('Unsupported iOS arch name "$arch"');
} }
String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch}) { String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch? darwinArch}) {
switch (platform) { switch (platform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
return 'android-arm'; return 'android-arm';
...@@ -572,11 +572,9 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch} ...@@ -572,11 +572,9 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch}
case TargetPlatform.android: case TargetPlatform.android:
return 'android'; return 'android';
} }
assert(false);
return null;
} }
TargetPlatform getTargetPlatformForName(String platform) { TargetPlatform? getTargetPlatformForName(String platform) {
switch (platform) { switch (platform) {
case 'android': case 'android':
return TargetPlatform.android; return TargetPlatform.android;
...@@ -634,8 +632,6 @@ String getNameForAndroidArch(AndroidArch arch) { ...@@ -634,8 +632,6 @@ String getNameForAndroidArch(AndroidArch arch) {
case AndroidArch.x86: case AndroidArch.x86:
return 'x86'; return 'x86';
} }
assert(false);
return null;
} }
String getPlatformNameForAndroidArch(AndroidArch arch) { String getPlatformNameForAndroidArch(AndroidArch arch) {
...@@ -649,8 +645,6 @@ String getPlatformNameForAndroidArch(AndroidArch arch) { ...@@ -649,8 +645,6 @@ String getPlatformNameForAndroidArch(AndroidArch arch) {
case AndroidArch.x86: case AndroidArch.x86:
return 'android-x86'; return 'android-x86';
} }
assert(false);
return null;
} }
String fuchsiaArchForTargetPlatform(TargetPlatform targetPlatform) { String fuchsiaArchForTargetPlatform(TargetPlatform targetPlatform) {
...@@ -660,8 +654,7 @@ String fuchsiaArchForTargetPlatform(TargetPlatform targetPlatform) { ...@@ -660,8 +654,7 @@ String fuchsiaArchForTargetPlatform(TargetPlatform targetPlatform) {
case TargetPlatform.fuchsia_x64: case TargetPlatform.fuchsia_x64:
return 'x64'; return 'x64';
default: default:
assert(false); throw UnsupportedError('Unexpected Fuchsia platform $targetPlatform');
return null;
} }
} }
...@@ -683,7 +676,7 @@ HostPlatform getCurrentHostPlatform() { ...@@ -683,7 +676,7 @@ HostPlatform getCurrentHostPlatform() {
} }
/// Returns the top-level build output directory. /// Returns the top-level build output directory.
String getBuildDirectory([Config config, FileSystem fileSystem]) { String getBuildDirectory([Config? config, FileSystem? fileSystem]) {
// TODO(johnmccutchan): Stop calling this function as part of setting // TODO(johnmccutchan): Stop calling this function as part of setting
// up command line argument processing. // up command line argument processing.
if (context == null) { if (context == null) {
...@@ -695,7 +688,7 @@ String getBuildDirectory([Config config, FileSystem fileSystem]) { ...@@ -695,7 +688,7 @@ String getBuildDirectory([Config config, FileSystem fileSystem]) {
return 'build'; return 'build';
} }
final String buildDir = localConfig.getValue('build-dir') as String ?? 'build'; final String buildDir = localConfig.getValue('build-dir') as String? ?? 'build';
if (localFilesystem.path.isAbsolute(buildDir)) { if (localFilesystem.path.isAbsolute(buildDir)) {
throw Exception( throw Exception(
'build-dir config setting in ${globals.config.configPath} must be relative'); 'build-dir config setting in ${globals.config.configPath} must be relative');
...@@ -735,7 +728,7 @@ String getWebBuildDirectory() { ...@@ -735,7 +728,7 @@ String getWebBuildDirectory() {
} }
/// Returns the Linux build output directory. /// Returns the Linux build output directory.
String getLinuxBuildDirectory([TargetPlatform targetPlatform]) { String getLinuxBuildDirectory([TargetPlatform? targetPlatform]) {
final String arch = (targetPlatform == null) ? final String arch = (targetPlatform == null) ?
_getCurrentHostPlatformArchName() : _getCurrentHostPlatformArchName() :
getNameForTargetPlatformArch(targetPlatform); getNameForTargetPlatformArch(targetPlatform);
...@@ -777,10 +770,10 @@ String encodeDartDefines(List<String> defines) { ...@@ -777,10 +770,10 @@ String encodeDartDefines(List<String> defines) {
} }
List<String> decodeCommaSeparated(Map<String, String> environmentDefines, String key) { List<String> decodeCommaSeparated(Map<String, String> environmentDefines, String key) {
if (!environmentDefines.containsKey(key) || environmentDefines[key].isEmpty) { if (!environmentDefines.containsKey(key) || environmentDefines[key]!.isEmpty) {
return <String>[]; return <String>[];
} }
return environmentDefines[key] return environmentDefines[key]!
.split(',') .split(',')
.cast<String>() .cast<String>()
.toList(); .toList();
...@@ -788,10 +781,10 @@ List<String> decodeCommaSeparated(Map<String, String> environmentDefines, String ...@@ -788,10 +781,10 @@ List<String> decodeCommaSeparated(Map<String, String> environmentDefines, String
/// Dart defines are encoded inside [environmentDefines] as a comma-separated list. /// Dart defines are encoded inside [environmentDefines] as a comma-separated list.
List<String> decodeDartDefines(Map<String, String> environmentDefines, String key) { List<String> decodeDartDefines(Map<String, String> environmentDefines, String key) {
if (!environmentDefines.containsKey(key) || environmentDefines[key].isEmpty) { if (!environmentDefines.containsKey(key) || environmentDefines[key]!.isEmpty) {
return <String>[]; return <String>[];
} }
return environmentDefines[key] return environmentDefines[key]!
.split(',') .split(',')
.map<Object>(_defineDecoder.convert) .map<Object>(_defineDecoder.convert)
.cast<String>() .cast<String>()
...@@ -820,10 +813,8 @@ String getNameForTargetPlatformArch(TargetPlatform platform) { ...@@ -820,10 +813,8 @@ String getNameForTargetPlatformArch(TargetPlatform platform) {
case TargetPlatform.linux_arm64: case TargetPlatform.linux_arm64:
return 'arm64'; return 'arm64';
default: default:
break; throw UnsupportedError('Unexpected target platform $platform');
} }
assert(false);
return null;
} }
String getNameForHostPlatformArch(HostPlatform platform) { String getNameForHostPlatformArch(HostPlatform platform) {
...@@ -839,6 +830,4 @@ String getNameForHostPlatformArch(HostPlatform platform) { ...@@ -839,6 +830,4 @@ String getNameForHostPlatformArch(HostPlatform platform) {
case HostPlatform.windows_x64: case HostPlatform.windows_x64:
return 'x64'; return 'x64';
} }
assert(false);
return null;
} }
...@@ -22,9 +22,6 @@ import 'common.dart'; ...@@ -22,9 +22,6 @@ import 'common.dart';
/// only the glyphs used by the application. /// only the glyphs used by the application.
const String kIconTreeShakerFlag = 'TreeShakeIcons'; const String kIconTreeShakerFlag = 'TreeShakeIcons';
/// Whether icon font subsetting is enabled by default.
const bool kIconTreeShakerEnabledDefault = true;
List<Map<String, dynamic>> _getList(dynamic object, String errorMessage) { List<Map<String, dynamic>> _getList(dynamic object, String errorMessage) {
if (object is List<dynamic>) { if (object is List<dynamic>) {
return object.cast<Map<String, dynamic>>(); return object.cast<Map<String, dynamic>>();
......
...@@ -19,7 +19,6 @@ import '../base/utils.dart'; ...@@ -19,7 +19,6 @@ import '../base/utils.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../build_system/build_system.dart'; import '../build_system/build_system.dart';
import '../build_system/targets/common.dart' show kExtraFrontEndOptions, kExtraGenSnapshotOptions; // for "useLegacyNames" only import '../build_system/targets/common.dart' show kExtraFrontEndOptions, kExtraGenSnapshotOptions; // for "useLegacyNames" only
import '../build_system/targets/icon_tree_shaker.dart' show kIconTreeShakerEnabledDefault;
import '../bundle.dart' as bundle; import '../bundle.dart' as bundle;
import '../cache.dart'; import '../cache.dart';
import '../dart/generate_synthetic_packages.dart'; import '../dart/generate_synthetic_packages.dart';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment