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 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import 'package:package_config/package_config_types.dart';
import 'base/config.dart';
......@@ -13,35 +10,40 @@ import 'base/file_system.dart';
import 'base/logger.dart';
import 'base/os.dart';
import 'base/utils.dart';
import 'build_system/targets/icon_tree_shaker.dart';
import 'convert.dart';
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.
class BuildInfo {
const BuildInfo(
this.mode,
this.flavor, {
this.trackWidgetCreation = false,
this.extraFrontEndOptions,
this.extraGenSnapshotOptions,
List<String>? extraFrontEndOptions,
List<String>? extraGenSnapshotOptions,
this.fileSystemRoots,
this.fileSystemScheme,
this.buildNumber,
this.buildName,
this.splitDebugInfoPath,
this.dartObfuscation = false,
this.dartDefines = const <String>[],
List<String>? dartDefines,
this.bundleSkSLPath,
this.dartExperiments = const <String>[],
@required this.treeShakeIcons,
List<String>? dartExperiments,
required this.treeShakeIcons,
this.performanceMeasurementFile,
this.packagesPath = '.packages', // TODO(jonahwilliams): make this required and remove the default.
this.nullSafetyMode = NullSafetyMode.sound,
this.codeSizeDirectory,
this.androidGradleDaemon = true,
this.packageConfig = PackageConfig.empty,
});
}) : extraFrontEndOptions = extraFrontEndOptions ?? const <String>[],
extraGenSnapshotOptions = extraGenSnapshotOptions ?? const <String>[],
dartDefines = dartDefines ?? const <String>[],
dartExperiments = dartExperiments ?? const <String>[];
final BuildMode mode;
......@@ -59,7 +61,7 @@ class BuildInfo {
/// If not null, the Gradle build task will be `assembleFlavorMode` (e.g.
/// `assemblePaidRelease`), and the Xcode build configuration will be
/// Mode-Flavor (e.g. Release-Paid).
final String flavor;
final String? flavor;
/// The path to the .packages file to use for compilation.
///
......@@ -67,8 +69,8 @@ class BuildInfo {
/// file. If not provided, defaults to `.packages`.
final String packagesPath;
final List<String> fileSystemRoots;
final String fileSystemScheme;
final List<String>? fileSystemRoots;
final String? fileSystemScheme;
/// Whether the build should track widget creation locations.
final bool trackWidgetCreation;
......@@ -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.
/// On Android it is used as versionCode.
/// 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.
/// 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 Xcode builds it is used as CFBundleShortVersionString.
final String buildName;
final String? buildName;
/// An optional directory path to save debugging information from dwarf stack
/// traces. If null, stack trace information is not stripped from the
/// executable.
final String splitDebugInfoPath;
final String? splitDebugInfoPath;
/// Whether to apply dart source code obfuscation.
final bool dartObfuscation;
......@@ -103,7 +105,7 @@ class BuildInfo {
/// An optional path to a JSON containing object SkSL shaders.
///
/// 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.
///
......@@ -119,11 +121,11 @@ class BuildInfo {
///
/// This is not considered a build input and will not force assemble to
/// rerun tasks.
final String performanceMeasurementFile;
final String? performanceMeasurementFile;
/// If provided, an output directory where one or more v8-style heap snapshots
/// will be written for code size profiling.
final String codeSizeDirectory;
final String? codeSizeDirectory;
/// Whether to enable the Gradle daemon when performing an Android build.
///
......@@ -181,7 +183,7 @@ class BuildInfo {
/// 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
String get lowerCasedFlavor => flavor?.toLowerCase();
String? get lowerCasedFlavor => flavor?.toLowerCase();
/// Convert to a structured string encoded structure appropriate for usage as
/// environment variables or to embed in other scripts.
......@@ -189,28 +191,28 @@ class BuildInfo {
/// Fields that are `null` are excluded from this configuration.
Map<String, String> toEnvironmentConfig() {
return <String, String>{
if (dartDefines?.isNotEmpty ?? false)
if (dartDefines.isNotEmpty)
'DART_DEFINES': encodeDartDefines(dartDefines),
if (dartObfuscation != null)
'DART_OBFUSCATION': dartObfuscation.toString(),
if (extraFrontEndOptions?.isNotEmpty ?? false)
'EXTRA_FRONT_END_OPTIONS': extraFrontEndOptions?.join(','),
if (extraGenSnapshotOptions?.isNotEmpty ?? false)
'EXTRA_GEN_SNAPSHOT_OPTIONS': extraGenSnapshotOptions?.join(','),
if (extraFrontEndOptions.isNotEmpty)
'EXTRA_FRONT_END_OPTIONS': extraFrontEndOptions.join(','),
if (extraGenSnapshotOptions.isNotEmpty)
'EXTRA_GEN_SNAPSHOT_OPTIONS': extraGenSnapshotOptions.join(','),
if (splitDebugInfoPath != null)
'SPLIT_DEBUG_INFO': splitDebugInfoPath,
'SPLIT_DEBUG_INFO': splitDebugInfoPath!,
if (trackWidgetCreation != null)
'TRACK_WIDGET_CREATION': trackWidgetCreation.toString(),
if (treeShakeIcons != null)
'TREE_SHAKE_ICONS': treeShakeIcons.toString(),
if (performanceMeasurementFile != null)
'PERFORMANCE_MEASUREMENT_FILE': performanceMeasurementFile,
'PERFORMANCE_MEASUREMENT_FILE': performanceMeasurementFile!,
if (bundleSkSLPath != null)
'BUNDLE_SKSL_PATH': bundleSkSLPath,
'BUNDLE_SKSL_PATH': bundleSkSLPath!,
if (packagesPath != null)
'PACKAGE_CONFIG': packagesPath,
if (codeSizeDirectory != null)
'CODE_SIZE_DIRECTORY': codeSizeDirectory,
'CODE_SIZE_DIRECTORY': codeSizeDirectory!,
};
}
......@@ -219,14 +221,14 @@ class BuildInfo {
List<String> toGradleConfig() {
// PACKAGE_CONFIG not currently supported.
return <String>[
if (dartDefines?.isNotEmpty ?? false)
if (dartDefines.isNotEmpty)
'-Pdart-defines=${encodeDartDefines(dartDefines)}',
if (dartObfuscation != null)
'-Pdart-obfuscation=$dartObfuscation',
if (extraFrontEndOptions?.isNotEmpty ?? false)
'-Pextra-front-end-options=${extraFrontEndOptions?.join(',')}',
if (extraGenSnapshotOptions?.isNotEmpty ?? false)
'-Pextra-gen-snapshot-options=${extraGenSnapshotOptions?.join(',')}',
if (extraFrontEndOptions.isNotEmpty)
'-Pextra-front-end-options=${extraFrontEndOptions.join(',')}',
if (extraGenSnapshotOptions.isNotEmpty)
'-Pextra-gen-snapshot-options=${extraGenSnapshotOptions.join(',')}',
if (splitDebugInfoPath != null)
'-Psplit-debug-info=$splitDebugInfoPath',
if (trackWidgetCreation != null)
......@@ -353,7 +355,7 @@ enum EnvironmentType {
simulator,
}
String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber, Logger logger) {
String? validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String buildNumber, Logger logger) {
if (buildNumber == null) {
return null;
}
......@@ -400,7 +402,7 @@ String validatedBuildNumberForPlatform(TargetPlatform targetPlatform, String bui
return buildNumber;
}
String validatedBuildNameForPlatform(TargetPlatform targetPlatform, String buildName, Logger logger) {
String? validatedBuildNameForPlatform(TargetPlatform targetPlatform, String buildName, Logger logger) {
if (buildName == null) {
return null;
}
......@@ -517,8 +519,6 @@ String getNameForDarwinArch(DarwinArch arch) {
case DarwinArch.x86_64:
return 'x86_64';
}
assert(false);
return null;
}
DarwinArch getIOSArchForName(String arch) {
......@@ -536,7 +536,7 @@ DarwinArch getIOSArchForName(String arch) {
throw Exception('Unsupported iOS arch name "$arch"');
}
String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch}) {
String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch? darwinArch}) {
switch (platform) {
case TargetPlatform.android_arm:
return 'android-arm';
......@@ -572,11 +572,9 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch}
case TargetPlatform.android:
return 'android';
}
assert(false);
return null;
}
TargetPlatform getTargetPlatformForName(String platform) {
TargetPlatform? getTargetPlatformForName(String platform) {
switch (platform) {
case 'android':
return TargetPlatform.android;
......@@ -634,8 +632,6 @@ String getNameForAndroidArch(AndroidArch arch) {
case AndroidArch.x86:
return 'x86';
}
assert(false);
return null;
}
String getPlatformNameForAndroidArch(AndroidArch arch) {
......@@ -649,8 +645,6 @@ String getPlatformNameForAndroidArch(AndroidArch arch) {
case AndroidArch.x86:
return 'android-x86';
}
assert(false);
return null;
}
String fuchsiaArchForTargetPlatform(TargetPlatform targetPlatform) {
......@@ -660,8 +654,7 @@ String fuchsiaArchForTargetPlatform(TargetPlatform targetPlatform) {
case TargetPlatform.fuchsia_x64:
return 'x64';
default:
assert(false);
return null;
throw UnsupportedError('Unexpected Fuchsia platform $targetPlatform');
}
}
......@@ -683,7 +676,7 @@ HostPlatform getCurrentHostPlatform() {
}
/// 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
// up command line argument processing.
if (context == null) {
......@@ -695,7 +688,7 @@ String getBuildDirectory([Config config, FileSystem fileSystem]) {
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)) {
throw Exception(
'build-dir config setting in ${globals.config.configPath} must be relative');
......@@ -735,7 +728,7 @@ String getWebBuildDirectory() {
}
/// Returns the Linux build output directory.
String getLinuxBuildDirectory([TargetPlatform targetPlatform]) {
String getLinuxBuildDirectory([TargetPlatform? targetPlatform]) {
final String arch = (targetPlatform == null) ?
_getCurrentHostPlatformArchName() :
getNameForTargetPlatformArch(targetPlatform);
......@@ -777,10 +770,10 @@ String encodeDartDefines(List<String> defines) {
}
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 environmentDefines[key]
return environmentDefines[key]!
.split(',')
.cast<String>()
.toList();
......@@ -788,10 +781,10 @@ List<String> decodeCommaSeparated(Map<String, String> environmentDefines, String
/// Dart defines are encoded inside [environmentDefines] as a comma-separated list.
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 environmentDefines[key]
return environmentDefines[key]!
.split(',')
.map<Object>(_defineDecoder.convert)
.cast<String>()
......@@ -820,10 +813,8 @@ String getNameForTargetPlatformArch(TargetPlatform platform) {
case TargetPlatform.linux_arm64:
return 'arm64';
default:
break;
throw UnsupportedError('Unexpected target platform $platform');
}
assert(false);
return null;
}
String getNameForHostPlatformArch(HostPlatform platform) {
......@@ -839,6 +830,4 @@ String getNameForHostPlatformArch(HostPlatform platform) {
case HostPlatform.windows_x64:
return 'x64';
}
assert(false);
return null;
}
......@@ -22,9 +22,6 @@ import 'common.dart';
/// only the glyphs used by the application.
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) {
if (object is List<dynamic>) {
return object.cast<Map<String, dynamic>>();
......
......@@ -19,7 +19,6 @@ import '../base/utils.dart';
import '../build_info.dart';
import '../build_system/build_system.dart';
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 '../cache.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