Unverified Commit db930ba3 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate build_macos and web_test_compiler to null safety (#84469)

parent ef2879a4
...@@ -2,10 +2,6 @@ ...@@ -2,10 +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 '../base/analyze_size.dart'; import '../base/analyze_size.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
...@@ -27,11 +23,11 @@ final RegExp _anyOutput = RegExp('.*'); ...@@ -27,11 +23,11 @@ final RegExp _anyOutput = RegExp('.*');
/// Builds the macOS project through xcodebuild. /// Builds the macOS project through xcodebuild.
// TODO(jonahwilliams): refactor to share code with the existing iOS code. // TODO(jonahwilliams): refactor to share code with the existing iOS code.
Future<void> buildMacOS({ Future<void> buildMacOS({
FlutterProject flutterProject, required FlutterProject flutterProject,
BuildInfo buildInfo, required BuildInfo buildInfo,
String targetOverride, String? targetOverride,
@required bool verboseLogging, required bool verboseLogging,
SizeAnalyzer sizeAnalyzer, SizeAnalyzer? sizeAnalyzer,
}) async { }) async {
if (!flutterProject.macos.xcodeWorkspace.existsSync()) { if (!flutterProject.macos.xcodeWorkspace.existsSync()) {
throwToolExit('No macOS desktop project configured. ' throwToolExit('No macOS desktop project configured. '
...@@ -77,16 +73,16 @@ Future<void> buildMacOS({ ...@@ -77,16 +73,16 @@ Future<void> buildMacOS({
// If the standard project exists, specify it to getInfo to handle the case where there are // If the standard project exists, specify it to getInfo to handle the case where there are
// other Xcode projects in the macos/ directory. Otherwise pass no name, which will work // other Xcode projects in the macos/ directory. Otherwise pass no name, which will work
// regardless of the project name so long as there is exactly one project. // regardless of the project name so long as there is exactly one project.
final String xcodeProjectName = xcodeProject.existsSync() ? xcodeProject.basename : null; final String? xcodeProjectName = xcodeProject.existsSync() ? xcodeProject.basename : null;
final XcodeProjectInfo projectInfo = await globals.xcodeProjectInterpreter.getInfo( final XcodeProjectInfo projectInfo = await globals.xcodeProjectInterpreter!.getInfo(
xcodeProject.parent.path, xcodeProject.parent.path,
projectFilename: xcodeProjectName, projectFilename: xcodeProjectName,
); );
final String scheme = projectInfo.schemeFor(buildInfo); final String? scheme = projectInfo.schemeFor(buildInfo);
if (scheme == null) { if (scheme == null) {
projectInfo.reportFlavorNotFoundAndExit(); projectInfo.reportFlavorNotFoundAndExit();
} }
final String configuration = projectInfo.buildConfigurationFor(buildInfo, scheme); final String? configuration = projectInfo.buildConfigurationFor(buildInfo, scheme);
if (configuration == null) { if (configuration == null) {
throwToolExit('Unable to find expected configuration in Xcode project.'); throwToolExit('Unable to find expected configuration in Xcode project.');
} }
...@@ -141,7 +137,7 @@ Future<void> buildMacOS({ ...@@ -141,7 +137,7 @@ Future<void> buildMacOS({
.firstWhere((Directory directory) { .firstWhere((Directory directory) {
return globals.fs.path.extension(directory.path) == '.app'; return globals.fs.path.extension(directory.path) == '.app';
}); });
final Map<String, Object> output = await sizeAnalyzer.analyzeAotSnapshot( final Map<String, Object?> output = await sizeAnalyzer.analyzeAotSnapshot(
aotSnapshot: aotSnapshot, aotSnapshot: aotSnapshot,
precompilerTrace: precompilerTrace, precompilerTrace: precompilerTrace,
outputDirectory: appDirectory, outputDirectory: appDirectory,
......
...@@ -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.dart'; import 'package:package_config/package_config.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -26,12 +23,12 @@ import 'test_config.dart'; ...@@ -26,12 +23,12 @@ import 'test_config.dart';
/// A web compiler for the test runner. /// A web compiler for the test runner.
class WebTestCompiler { class WebTestCompiler {
WebTestCompiler({ WebTestCompiler({
@required FileSystem fileSystem, required FileSystem fileSystem,
@required Logger logger, required Logger logger,
@required Artifacts artifacts, required Artifacts artifacts,
@required Platform platform, required Platform platform,
@required ProcessManager processManager, required ProcessManager processManager,
@required Config config, required Config config,
}) : _logger = logger, }) : _logger = logger,
_fileSystem = fileSystem, _fileSystem = fileSystem,
_artifacts = artifacts, _artifacts = artifacts,
...@@ -47,24 +44,23 @@ class WebTestCompiler { ...@@ -47,24 +44,23 @@ class WebTestCompiler {
final Config _config; final Config _config;
Future<WebMemoryFS> initialize({ Future<WebMemoryFS> initialize({
@required Directory projectDirectory, required Directory projectDirectory,
@required String testOutputDir, required String testOutputDir,
@required List<String> testFiles, required List<String> testFiles,
@required BuildInfo buildInfo, required BuildInfo buildInfo,
}) async { }) async {
LanguageVersion languageVersion = LanguageVersion(2, 8); LanguageVersion languageVersion = LanguageVersion(2, 8);
HostArtifact platformDillArtifact; HostArtifact platformDillArtifact = HostArtifact.webPlatformSoundKernelDill;
// TODO(jonahwilliams): to support autodetect this would need to partition the source code into a // TODO(jonahwilliams): to support autodetect this would need to partition the source code into a
// a sound and unsound set and perform separate compilations. // a sound and unsound set and perform separate compilations.
final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions ?? <String>[]); final List<String> extraFrontEndOptions = List<String>.of(buildInfo.extraFrontEndOptions);
if (buildInfo.nullSafetyMode == NullSafetyMode.unsound || buildInfo.nullSafetyMode == NullSafetyMode.autodetect) { if (buildInfo.nullSafetyMode == NullSafetyMode.unsound || buildInfo.nullSafetyMode == NullSafetyMode.autodetect) {
platformDillArtifact = HostArtifact.webPlatformKernelDill; platformDillArtifact = HostArtifact.webPlatformKernelDill;
if (!extraFrontEndOptions.contains('--no-sound-null-safety')) { if (!extraFrontEndOptions.contains('--no-sound-null-safety')) {
extraFrontEndOptions.add('--no-sound-null-safety'); extraFrontEndOptions.add('--no-sound-null-safety');
} }
} else if (buildInfo.nullSafetyMode == NullSafetyMode.sound) { } else if (buildInfo.nullSafetyMode == NullSafetyMode.sound) {
platformDillArtifact = HostArtifact.webPlatformSoundKernelDill; languageVersion = currentLanguageVersion(_fileSystem, Cache.flutterRoot!);
languageVersion = currentLanguageVersion(_fileSystem, Cache.flutterRoot);
if (!extraFrontEndOptions.contains('--sound-null-safety')) { if (!extraFrontEndOptions.contains('--sound-null-safety')) {
extraFrontEndOptions.add('--sound-null-safety'); extraFrontEndOptions.add('--sound-null-safety');
} }
...@@ -133,7 +129,7 @@ class WebTestCompiler { ...@@ -133,7 +129,7 @@ class WebTestCompiler {
fileSystem: _fileSystem, fileSystem: _fileSystem,
); );
final CompilerOutput output = await residentCompiler.recompile( final CompilerOutput? output = await residentCompiler.recompile(
Uri.parse('org-dartlang-app:///main.dart'), Uri.parse('org-dartlang-app:///main.dart'),
<Uri>[], <Uri>[],
outputPath: outputDirectory.childFile('out').path, outputPath: outputDirectory.childFile('out').path,
...@@ -141,7 +137,7 @@ class WebTestCompiler { ...@@ -141,7 +137,7 @@ class WebTestCompiler {
fs: _fileSystem, fs: _fileSystem,
projectRootPath: projectDirectory.absolute.path, projectRootPath: projectDirectory.absolute.path,
); );
if (output.errorCount > 0) { if (output == null || output.errorCount > 0) {
throwToolExit('Failed to compile'); throwToolExit('Failed to compile');
} }
// Cache the output kernel file to speed up subsequent compiles. // Cache the output kernel file to speed up subsequent compiles.
......
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