mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Migrate build_macos and web_test_compiler to null safety (#84469)
This commit is contained in:
parent
ef2879a46f
commit
db930ba32f
@ -2,10 +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 '../base/analyze_size.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
@ -27,11 +23,11 @@ final RegExp _anyOutput = RegExp('.*');
|
||||
/// Builds the macOS project through xcodebuild.
|
||||
// TODO(jonahwilliams): refactor to share code with the existing iOS code.
|
||||
Future<void> buildMacOS({
|
||||
FlutterProject flutterProject,
|
||||
BuildInfo buildInfo,
|
||||
String targetOverride,
|
||||
@required bool verboseLogging,
|
||||
SizeAnalyzer sizeAnalyzer,
|
||||
required FlutterProject flutterProject,
|
||||
required BuildInfo buildInfo,
|
||||
String? targetOverride,
|
||||
required bool verboseLogging,
|
||||
SizeAnalyzer? sizeAnalyzer,
|
||||
}) async {
|
||||
if (!flutterProject.macos.xcodeWorkspace.existsSync()) {
|
||||
throwToolExit('No macOS desktop project configured. '
|
||||
@ -77,16 +73,16 @@ Future<void> buildMacOS({
|
||||
// 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
|
||||
// regardless of the project name so long as there is exactly one project.
|
||||
final String xcodeProjectName = xcodeProject.existsSync() ? xcodeProject.basename : null;
|
||||
final XcodeProjectInfo projectInfo = await globals.xcodeProjectInterpreter.getInfo(
|
||||
final String? xcodeProjectName = xcodeProject.existsSync() ? xcodeProject.basename : null;
|
||||
final XcodeProjectInfo projectInfo = await globals.xcodeProjectInterpreter!.getInfo(
|
||||
xcodeProject.parent.path,
|
||||
projectFilename: xcodeProjectName,
|
||||
);
|
||||
final String scheme = projectInfo.schemeFor(buildInfo);
|
||||
final String? scheme = projectInfo.schemeFor(buildInfo);
|
||||
if (scheme == null) {
|
||||
projectInfo.reportFlavorNotFoundAndExit();
|
||||
}
|
||||
final String configuration = projectInfo.buildConfigurationFor(buildInfo, scheme);
|
||||
final String? configuration = projectInfo.buildConfigurationFor(buildInfo, scheme);
|
||||
if (configuration == null) {
|
||||
throwToolExit('Unable to find expected configuration in Xcode project.');
|
||||
}
|
||||
@ -141,7 +137,7 @@ Future<void> buildMacOS({
|
||||
.firstWhere((Directory directory) {
|
||||
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,
|
||||
precompilerTrace: precompilerTrace,
|
||||
outputDirectory: appDirectory,
|
||||
|
||||
@ -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.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
@ -26,12 +23,12 @@ import 'test_config.dart';
|
||||
/// A web compiler for the test runner.
|
||||
class WebTestCompiler {
|
||||
WebTestCompiler({
|
||||
@required FileSystem fileSystem,
|
||||
@required Logger logger,
|
||||
@required Artifacts artifacts,
|
||||
@required Platform platform,
|
||||
@required ProcessManager processManager,
|
||||
@required Config config,
|
||||
required FileSystem fileSystem,
|
||||
required Logger logger,
|
||||
required Artifacts artifacts,
|
||||
required Platform platform,
|
||||
required ProcessManager processManager,
|
||||
required Config config,
|
||||
}) : _logger = logger,
|
||||
_fileSystem = fileSystem,
|
||||
_artifacts = artifacts,
|
||||
@ -47,24 +44,23 @@ class WebTestCompiler {
|
||||
final Config _config;
|
||||
|
||||
Future<WebMemoryFS> initialize({
|
||||
@required Directory projectDirectory,
|
||||
@required String testOutputDir,
|
||||
@required List<String> testFiles,
|
||||
@required BuildInfo buildInfo,
|
||||
required Directory projectDirectory,
|
||||
required String testOutputDir,
|
||||
required List<String> testFiles,
|
||||
required BuildInfo buildInfo,
|
||||
}) async {
|
||||
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
|
||||
// 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) {
|
||||
platformDillArtifact = HostArtifact.webPlatformKernelDill;
|
||||
if (!extraFrontEndOptions.contains('--no-sound-null-safety')) {
|
||||
extraFrontEndOptions.add('--no-sound-null-safety');
|
||||
}
|
||||
} 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')) {
|
||||
extraFrontEndOptions.add('--sound-null-safety');
|
||||
}
|
||||
@ -133,7 +129,7 @@ class WebTestCompiler {
|
||||
fileSystem: _fileSystem,
|
||||
);
|
||||
|
||||
final CompilerOutput output = await residentCompiler.recompile(
|
||||
final CompilerOutput? output = await residentCompiler.recompile(
|
||||
Uri.parse('org-dartlang-app:///main.dart'),
|
||||
<Uri>[],
|
||||
outputPath: outputDirectory.childFile('out').path,
|
||||
@ -141,7 +137,7 @@ class WebTestCompiler {
|
||||
fs: _fileSystem,
|
||||
projectRootPath: projectDirectory.absolute.path,
|
||||
);
|
||||
if (output.errorCount > 0) {
|
||||
if (output == null || output.errorCount > 0) {
|
||||
throwToolExit('Failed to compile');
|
||||
}
|
||||
// Cache the output kernel file to speed up subsequent compiles.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user