Migrate build system build.dart to null safety (#83381)
This commit is contained in:
parent
48a2bc8c64
commit
00263c4f8a
@ -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:process/process.dart';
|
import 'package:process/process.dart';
|
||||||
|
|
||||||
import '../artifacts.dart';
|
import '../artifacts.dart';
|
||||||
@ -20,7 +17,7 @@ class SnapshotType {
|
|||||||
SnapshotType(this.platform, this.mode)
|
SnapshotType(this.platform, this.mode)
|
||||||
: assert(mode != null);
|
: assert(mode != null);
|
||||||
|
|
||||||
final TargetPlatform platform;
|
final TargetPlatform? platform;
|
||||||
final BuildMode mode;
|
final BuildMode mode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -30,9 +27,9 @@ class SnapshotType {
|
|||||||
/// Interface to the gen_snapshot command-line tool.
|
/// Interface to the gen_snapshot command-line tool.
|
||||||
class GenSnapshot {
|
class GenSnapshot {
|
||||||
GenSnapshot({
|
GenSnapshot({
|
||||||
@required Artifacts artifacts,
|
required Artifacts artifacts,
|
||||||
@required ProcessManager processManager,
|
required ProcessManager processManager,
|
||||||
@required Logger logger,
|
required Logger logger,
|
||||||
}) : _artifacts = artifacts,
|
}) : _artifacts = artifacts,
|
||||||
_processUtils = ProcessUtils(logger: logger, processManager: processManager);
|
_processUtils = ProcessUtils(logger: logger, processManager: processManager);
|
||||||
|
|
||||||
@ -56,10 +53,11 @@ class GenSnapshot {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Future<int> run({
|
Future<int> run({
|
||||||
@required SnapshotType snapshotType,
|
required SnapshotType snapshotType,
|
||||||
DarwinArch darwinArch,
|
DarwinArch? darwinArch,
|
||||||
Iterable<String> additionalArgs = const <String>[],
|
Iterable<String> additionalArgs = const <String>[],
|
||||||
}) {
|
}) {
|
||||||
|
assert(snapshotType.platform != TargetPlatform.ios || darwinArch != null);
|
||||||
final List<String> args = <String>[
|
final List<String> args = <String>[
|
||||||
...additionalArgs,
|
...additionalArgs,
|
||||||
];
|
];
|
||||||
@ -69,7 +67,7 @@ class GenSnapshot {
|
|||||||
// iOS has a separate gen_snapshot for armv7 and arm64 in the same,
|
// iOS has a separate gen_snapshot for armv7 and arm64 in the same,
|
||||||
// directory. So we need to select the right one.
|
// directory. So we need to select the right one.
|
||||||
if (snapshotType.platform == TargetPlatform.ios) {
|
if (snapshotType.platform == TargetPlatform.ios) {
|
||||||
snapshotterPath += '_' + getNameForDarwinArch(darwinArch);
|
snapshotterPath += '_' + getNameForDarwinArch(darwinArch!);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _processUtils.stream(
|
return _processUtils.stream(
|
||||||
@ -82,11 +80,11 @@ class GenSnapshot {
|
|||||||
class AOTSnapshotter {
|
class AOTSnapshotter {
|
||||||
AOTSnapshotter({
|
AOTSnapshotter({
|
||||||
this.reportTimings = false,
|
this.reportTimings = false,
|
||||||
@required Logger logger,
|
required Logger logger,
|
||||||
@required FileSystem fileSystem,
|
required FileSystem fileSystem,
|
||||||
@required Xcode xcode,
|
required Xcode xcode,
|
||||||
@required ProcessManager processManager,
|
required ProcessManager processManager,
|
||||||
@required Artifacts artifacts,
|
required Artifacts artifacts,
|
||||||
}) : _logger = logger,
|
}) : _logger = logger,
|
||||||
_fileSystem = fileSystem,
|
_fileSystem = fileSystem,
|
||||||
_xcode = xcode,
|
_xcode = xcode,
|
||||||
@ -108,16 +106,16 @@ class AOTSnapshotter {
|
|||||||
|
|
||||||
/// Builds an architecture-specific ahead-of-time compiled snapshot of the specified script.
|
/// Builds an architecture-specific ahead-of-time compiled snapshot of the specified script.
|
||||||
Future<int> build({
|
Future<int> build({
|
||||||
@required TargetPlatform platform,
|
required TargetPlatform platform,
|
||||||
@required BuildMode buildMode,
|
required BuildMode buildMode,
|
||||||
@required String mainPath,
|
required String mainPath,
|
||||||
@required String outputPath,
|
required String outputPath,
|
||||||
DarwinArch darwinArch,
|
DarwinArch? darwinArch,
|
||||||
String sdkRoot,
|
String? sdkRoot,
|
||||||
List<String> extraGenSnapshotOptions = const <String>[],
|
List<String> extraGenSnapshotOptions = const <String>[],
|
||||||
@required bool bitcode,
|
required bool bitcode,
|
||||||
@required String splitDebugInfo,
|
String? splitDebugInfo,
|
||||||
@required bool dartObfuscation,
|
required bool dartObfuscation,
|
||||||
bool quiet = false,
|
bool quiet = false,
|
||||||
}) async {
|
}) async {
|
||||||
assert(platform != TargetPlatform.ios || darwinArch != null);
|
assert(platform != TargetPlatform.ios || darwinArch != null);
|
||||||
@ -197,7 +195,7 @@ class AOTSnapshotter {
|
|||||||
// Faster async/await
|
// Faster async/await
|
||||||
if (shouldSplitDebugInfo) ...<String>[
|
if (shouldSplitDebugInfo) ...<String>[
|
||||||
'--dwarf-stack-traces',
|
'--dwarf-stack-traces',
|
||||||
'--save-debugging-info=${_fileSystem.path.join(splitDebugInfo, debugFilename)}'
|
'--save-debugging-info=${_fileSystem.path.join(splitDebugInfo!, debugFilename)}'
|
||||||
],
|
],
|
||||||
if (dartObfuscation)
|
if (dartObfuscation)
|
||||||
'--obfuscate',
|
'--obfuscate',
|
||||||
@ -220,7 +218,7 @@ class AOTSnapshotter {
|
|||||||
// end-developer can link into their app.
|
// end-developer can link into their app.
|
||||||
if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin) {
|
if (platform == TargetPlatform.ios || platform == TargetPlatform.darwin) {
|
||||||
final RunResult result = await _buildFramework(
|
final RunResult result = await _buildFramework(
|
||||||
appleArch: darwinArch,
|
appleArch: darwinArch!,
|
||||||
isIOS: platform == TargetPlatform.ios,
|
isIOS: platform == TargetPlatform.ios,
|
||||||
sdkRoot: sdkRoot,
|
sdkRoot: sdkRoot,
|
||||||
assemblyPath: assembly,
|
assemblyPath: assembly,
|
||||||
@ -238,13 +236,13 @@ class AOTSnapshotter {
|
|||||||
/// Builds an iOS or macOS framework at [outputPath]/App.framework from the assembly
|
/// Builds an iOS or macOS framework at [outputPath]/App.framework from the assembly
|
||||||
/// source at [assemblyPath].
|
/// source at [assemblyPath].
|
||||||
Future<RunResult> _buildFramework({
|
Future<RunResult> _buildFramework({
|
||||||
@required DarwinArch appleArch,
|
required DarwinArch appleArch,
|
||||||
@required bool isIOS,
|
required bool isIOS,
|
||||||
@required String sdkRoot,
|
String? sdkRoot,
|
||||||
@required String assemblyPath,
|
required String assemblyPath,
|
||||||
@required String outputPath,
|
required String outputPath,
|
||||||
@required bool bitcode,
|
required bool bitcode,
|
||||||
@required bool quiet
|
required bool quiet
|
||||||
}) async {
|
}) async {
|
||||||
final String targetArch = getNameForDarwinArch(appleArch);
|
final String targetArch = getNameForDarwinArch(appleArch);
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
@ -262,7 +260,7 @@ class AOTSnapshotter {
|
|||||||
|
|
||||||
const String embedBitcodeArg = '-fembed-bitcode';
|
const String embedBitcodeArg = '-fembed-bitcode';
|
||||||
final String assemblyO = _fileSystem.path.join(outputPath, 'snapshot_assembly.o');
|
final String assemblyO = _fileSystem.path.join(outputPath, 'snapshot_assembly.o');
|
||||||
List<String> isysrootArgs;
|
List<String>? isysrootArgs;
|
||||||
if (sdkRoot != null) {
|
if (sdkRoot != null) {
|
||||||
isysrootArgs = <String>['-isysroot', sdkRoot];
|
isysrootArgs = <String>['-isysroot', sdkRoot];
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import 'common.dart';
|
|||||||
import 'io.dart';
|
import 'io.dart';
|
||||||
import 'logger.dart';
|
import 'logger.dart';
|
||||||
|
|
||||||
typedef StringConverter = String Function(String string);
|
typedef StringConverter = String? Function(String string);
|
||||||
|
|
||||||
/// A function that will be run before the VM exits.
|
/// A function that will be run before the VM exits.
|
||||||
typedef ShutdownHook = FutureOr<dynamic> Function();
|
typedef ShutdownHook = FutureOr<dynamic> Function();
|
||||||
@ -452,12 +452,13 @@ class _DefaultProcessUtils implements ProcessUtils {
|
|||||||
.transform<String>(const LineSplitter())
|
.transform<String>(const LineSplitter())
|
||||||
.where((String line) => filter == null || filter.hasMatch(line))
|
.where((String line) => filter == null || filter.hasMatch(line))
|
||||||
.listen((String line) {
|
.listen((String line) {
|
||||||
|
String? mappedLine = line;
|
||||||
if (mapFunction != null) {
|
if (mapFunction != null) {
|
||||||
line = mapFunction(line);
|
mappedLine = mapFunction(line);
|
||||||
}
|
}
|
||||||
if (line != null) {
|
if (mappedLine != null) {
|
||||||
final String message = '$prefix$line';
|
final String message = '$prefix$mappedLine';
|
||||||
if (stdoutErrorMatcher?.hasMatch(line) == true) {
|
if (stdoutErrorMatcher?.hasMatch(mappedLine) == true) {
|
||||||
_logger.printError(message, wrap: false);
|
_logger.printError(message, wrap: false);
|
||||||
} else if (trace) {
|
} else if (trace) {
|
||||||
_logger.printTrace(message);
|
_logger.printTrace(message);
|
||||||
@ -471,11 +472,12 @@ class _DefaultProcessUtils implements ProcessUtils {
|
|||||||
.transform<String>(const LineSplitter())
|
.transform<String>(const LineSplitter())
|
||||||
.where((String line) => filter == null || filter.hasMatch(line))
|
.where((String line) => filter == null || filter.hasMatch(line))
|
||||||
.listen((String line) {
|
.listen((String line) {
|
||||||
|
String? mappedLine = line;
|
||||||
if (mapFunction != null) {
|
if (mapFunction != null) {
|
||||||
line = mapFunction(line);
|
mappedLine = mapFunction(line);
|
||||||
}
|
}
|
||||||
if (line != null) {
|
if (mappedLine != null) {
|
||||||
_logger.printError('$prefix$line', wrap: false);
|
_logger.printError('$prefix$mappedLine', wrap: false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import '../../base/build.dart';
|
|||||||
import '../../base/deferred_component.dart';
|
import '../../base/deferred_component.dart';
|
||||||
import '../../base/file_system.dart';
|
import '../../base/file_system.dart';
|
||||||
import '../../build_info.dart';
|
import '../../build_info.dart';
|
||||||
import '../../globals.dart' as globals show platform, printError, xcode;
|
import '../../globals_null_migrated.dart' as globals show platform, printError, xcode;
|
||||||
import '../../project.dart';
|
import '../../project.dart';
|
||||||
import '../build_system.dart';
|
import '../build_system.dart';
|
||||||
import '../depfile.dart';
|
import '../depfile.dart';
|
||||||
|
@ -12,7 +12,7 @@ import '../../base/file_system.dart';
|
|||||||
import '../../build_info.dart';
|
import '../../build_info.dart';
|
||||||
import '../../compile.dart';
|
import '../../compile.dart';
|
||||||
import '../../dart/package_map.dart';
|
import '../../dart/package_map.dart';
|
||||||
import '../../globals.dart' as globals show xcode;
|
import '../../globals_null_migrated.dart' as globals show xcode;
|
||||||
import '../build_system.dart';
|
import '../build_system.dart';
|
||||||
import '../depfile.dart';
|
import '../depfile.dart';
|
||||||
import '../exceptions.dart';
|
import '../exceptions.dart';
|
||||||
|
@ -12,7 +12,7 @@ import '../../base/common.dart';
|
|||||||
import '../../base/file_system.dart';
|
import '../../base/file_system.dart';
|
||||||
import '../../base/io.dart';
|
import '../../base/io.dart';
|
||||||
import '../../build_info.dart';
|
import '../../build_info.dart';
|
||||||
import '../../globals.dart' as globals show xcode;
|
import '../../globals_null_migrated.dart' as globals show xcode;
|
||||||
import '../../macos/xcode.dart';
|
import '../../macos/xcode.dart';
|
||||||
import '../../project.dart';
|
import '../../project.dart';
|
||||||
import '../build_system.dart';
|
import '../build_system.dart';
|
||||||
|
@ -10,7 +10,7 @@ import '../../base/file_system.dart';
|
|||||||
import '../../base/io.dart';
|
import '../../base/io.dart';
|
||||||
import '../../base/process.dart';
|
import '../../base/process.dart';
|
||||||
import '../../build_info.dart';
|
import '../../build_info.dart';
|
||||||
import '../../globals.dart' as globals show xcode;
|
import '../../globals_null_migrated.dart' as globals show xcode;
|
||||||
import '../build_system.dart';
|
import '../build_system.dart';
|
||||||
import '../depfile.dart';
|
import '../depfile.dart';
|
||||||
import '../exceptions.dart';
|
import '../exceptions.dart';
|
||||||
|
@ -2,8 +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:file/memory.dart';
|
import 'package:file/memory.dart';
|
||||||
import 'package:flutter_tools/src/artifacts.dart';
|
import 'package:flutter_tools/src/artifacts.dart';
|
||||||
import 'package:flutter_tools/src/base/build.dart';
|
import 'package:flutter_tools/src/base/build.dart';
|
||||||
@ -72,22 +70,16 @@ const List<String> kBitcodeClang = <String>[
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('SnapshotType', () {
|
group('SnapshotType', () {
|
||||||
test('throws, if build mode is null', () {
|
|
||||||
expect(
|
|
||||||
() => SnapshotType(TargetPlatform.android_x64, null),
|
|
||||||
throwsA(anything),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
test('does not throw, if target platform is null', () {
|
test('does not throw, if target platform is null', () {
|
||||||
expect(() => SnapshotType(null, BuildMode.release), returnsNormally);
|
expect(() => SnapshotType(null, BuildMode.release), returnsNormally);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('GenSnapshot', () {
|
group('GenSnapshot', () {
|
||||||
GenSnapshot genSnapshot;
|
late GenSnapshot genSnapshot;
|
||||||
Artifacts artifacts;
|
late Artifacts artifacts;
|
||||||
FakeProcessManager processManager;
|
late FakeProcessManager processManager;
|
||||||
BufferLogger logger;
|
late BufferLogger logger;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
artifacts = Artifacts.test();
|
artifacts = Artifacts.test();
|
||||||
@ -179,10 +171,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('AOTSnapshotter', () {
|
group('AOTSnapshotter', () {
|
||||||
MemoryFileSystem fileSystem;
|
late MemoryFileSystem fileSystem;
|
||||||
AOTSnapshotter snapshotter;
|
late AOTSnapshotter snapshotter;
|
||||||
Artifacts artifacts;
|
late Artifacts artifacts;
|
||||||
FakeProcessManager processManager;
|
late FakeProcessManager processManager;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
fileSystem = MemoryFileSystem.test();
|
fileSystem = MemoryFileSystem.test();
|
||||||
|
@ -83,6 +83,24 @@ void main() {
|
|||||||
expect(logger.statusText, equals('${testString[0]}\n'));
|
expect(logger.statusText, equals('${testString[0]}\n'));
|
||||||
expect(logger.errorText, equals('${testString[0]}\n'));
|
expect(logger.errorText, equals('${testString[0]}\n'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWithoutContext('Command output is filtered by mapFunction', () async {
|
||||||
|
processManager.addCommand(const FakeCommand(
|
||||||
|
command: <String>['command'],
|
||||||
|
stdout: 'match\nno match',
|
||||||
|
stderr: 'match\nno match',
|
||||||
|
));
|
||||||
|
|
||||||
|
await processUtils.stream(<String>['command'], mapFunction: (String line) {
|
||||||
|
if (line == 'match') {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(logger.statusText, equals('match\n'));
|
||||||
|
expect(logger.errorText, equals('match\n'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('run', () {
|
group('run', () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user