Unverified Commit 19eab105 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate build_system, exceptions, and source to null safety (#83147)

parent efdbe403
...@@ -48,7 +48,7 @@ import 'src/commands/update_packages.dart'; ...@@ -48,7 +48,7 @@ import 'src/commands/update_packages.dart';
import 'src/commands/upgrade.dart'; import 'src/commands/upgrade.dart';
import 'src/devtools_launcher.dart'; import 'src/devtools_launcher.dart';
import 'src/features.dart'; import 'src/features.dart';
import 'src/globals.dart' as globals; import 'src/globals_null_migrated.dart' as globals;
// Files in `isolated` are intentionally excluded from google3 tooling. // Files in `isolated` are intentionally excluded from google3 tooling.
import 'src/isolated/mustache_template.dart'; import 'src/isolated/mustache_template.dart';
import 'src/isolated/resident_web_runner.dart'; import 'src/isolated/resident_web_runner.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -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 '../base/file_system.dart'; import '../base/file_system.dart';
import 'build_system.dart'; import 'build_system.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -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 '../artifacts.dart'; import '../artifacts.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../build_info.dart'; import '../build_info.dart';
...@@ -76,7 +74,7 @@ class SourceVisitor implements ResolvedFiles { ...@@ -76,7 +74,7 @@ class SourceVisitor implements ResolvedFiles {
.replaceAllMapped(_separatorExpr, (Match match) => '${match.group(1)}\n') .replaceAllMapped(_separatorExpr, (Match match) => '${match.group(1)}\n')
.split('\n') .split('\n')
// Expand escape sequences, so that '\ ', for example,ß becomes ' ' // Expand escape sequences, so that '\ ', for example,ß becomes ' '
.map<String>((String path) => path.replaceAllMapped(_escapeExpr, (Match match) => match.group(1)).trim()) .map<String>((String path) => path.replaceAllMapped(_escapeExpr, (Match match) => match.group(1)!).trim())
.where((String path) => path.isNotEmpty) .where((String path) => path.isNotEmpty)
.toSet() .toSet()
.map(environment.fileSystem.file); .map(environment.fileSystem.file);
...@@ -93,7 +91,7 @@ class SourceVisitor implements ResolvedFiles { ...@@ -93,7 +91,7 @@ class SourceVisitor implements ResolvedFiles {
final List<String> segments = <String>[]; final List<String> segments = <String>[];
final List<String> rawParts = pattern.split('/'); final List<String> rawParts = pattern.split('/');
final bool hasWildcard = rawParts.last.contains('*'); final bool hasWildcard = rawParts.last.contains('*');
String wildcardFile; String? wildcardFile;
if (hasWildcard) { if (hasWildcard) {
wildcardFile = rawParts.removeLast(); wildcardFile = rawParts.removeLast();
} }
...@@ -141,7 +139,7 @@ class SourceVisitor implements ResolvedFiles { ...@@ -141,7 +139,7 @@ class SourceVisitor implements ResolvedFiles {
// example, `foo_*_.dart`. We want to match `foo_b_.dart` but not // example, `foo_*_.dart`. We want to match `foo_b_.dart` but not
// `foo_.dart`. To do so, we first subtract the first section from the // `foo_.dart`. To do so, we first subtract the first section from the
// string if the first segment matches. // string if the first segment matches.
final List<String> wildcardSegments = wildcardFile.split('*'); final List<String> wildcardSegments = wildcardFile?.split('*') ?? <String>[];
if (wildcardSegments.length > 2) { if (wildcardSegments.length > 2) {
throw InvalidPatternException(pattern); throw InvalidPatternException(pattern);
} }
...@@ -171,7 +169,7 @@ class SourceVisitor implements ResolvedFiles { ...@@ -171,7 +169,7 @@ class SourceVisitor implements ResolvedFiles {
/// To increase the performance of builds that use a known revision of Flutter, /// To increase the performance of builds that use a known revision of Flutter,
/// these are updated to point towards the engine.version file instead of /// these are updated to point towards the engine.version file instead of
/// the artifact itself. /// the artifact itself.
void visitArtifact(Artifact artifact, TargetPlatform platform, BuildMode mode) { void visitArtifact(Artifact artifact, TargetPlatform? platform, BuildMode? mode) {
// This is not a local engine. // This is not a local engine.
if (environment.engineVersion != null) { if (environment.engineVersion != null) {
sources.add(environment.flutterRootDir sources.add(environment.flutterRootDir
...@@ -232,7 +230,7 @@ abstract class Source { ...@@ -232,7 +230,7 @@ abstract class Source {
/// The source is provided by an [Artifact]. /// The source is provided by an [Artifact].
/// ///
/// If [artifact] points to a directory then all child files are included. /// If [artifact] points to a directory then all child files are included.
const factory Source.artifact(Artifact artifact, {TargetPlatform platform, BuildMode mode}) = _ArtifactSource; const factory Source.artifact(Artifact artifact, {TargetPlatform? platform, BuildMode? mode}) = _ArtifactSource;
/// The source is provided by an [HostArtifact]. /// The source is provided by an [HostArtifact].
/// ///
...@@ -269,8 +267,8 @@ class _ArtifactSource implements Source { ...@@ -269,8 +267,8 @@ class _ArtifactSource implements Source {
const _ArtifactSource(this.artifact, { this.platform, this.mode }); const _ArtifactSource(this.artifact, { this.platform, this.mode });
final Artifact artifact; final Artifact artifact;
final TargetPlatform platform; final TargetPlatform? platform;
final BuildMode mode; final BuildMode? mode;
@override @override
void accept(SourceVisitor visitor) => visitor.visitArtifact(artifact, platform, mode); void accept(SourceVisitor visitor) => visitor.visitArtifact(artifact, platform, mode);
......
...@@ -21,7 +21,7 @@ import 'build_system/targets/common.dart'; ...@@ -21,7 +21,7 @@ import 'build_system/targets/common.dart';
import 'cache.dart'; import 'cache.dart';
import 'convert.dart'; import 'convert.dart';
import 'devfs.dart'; import 'devfs.dart';
import 'globals.dart' as globals; import 'globals_null_migrated.dart' as globals;
import 'project.dart'; import 'project.dart';
String get defaultMainPath => globals.fs.path.join('lib', 'main.dart'); String get defaultMainPath => globals.fs.path.join('lib', 'main.dart');
......
...@@ -10,7 +10,7 @@ import '../build_info.dart'; ...@@ -10,7 +10,7 @@ import '../build_info.dart';
import '../commands/build_linux.dart'; import '../commands/build_linux.dart';
import '../commands/build_macos.dart'; import '../commands/build_macos.dart';
import '../commands/build_windows.dart'; import '../commands/build_windows.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import 'build_aar.dart'; import 'build_aar.dart';
import 'build_apk.dart'; import 'build_apk.dart';
......
...@@ -18,7 +18,7 @@ import '../build_system/build_system.dart'; ...@@ -18,7 +18,7 @@ import '../build_system/build_system.dart';
import '../build_system/targets/ios.dart'; import '../build_system/targets/ios.dart';
import '../cache.dart'; import '../cache.dart';
import '../flutter_plugins.dart'; import '../flutter_plugins.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../macos/cocoapod_utils.dart'; import '../macos/cocoapod_utils.dart';
import '../project.dart'; import '../project.dart';
import '../runner/flutter_command.dart' show DevelopmentArtifact, FlutterCommandResult; import '../runner/flutter_command.dart' show DevelopmentArtifact, FlutterCommandResult;
......
...@@ -14,7 +14,7 @@ import '../cache.dart'; ...@@ -14,7 +14,7 @@ import '../cache.dart';
import '../dart/generate_synthetic_packages.dart'; import '../dart/generate_synthetic_packages.dart';
import '../dart/pub.dart'; import '../dart/pub.dart';
import '../flutter_plugins.dart'; import '../flutter_plugins.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../plugins.dart'; import '../plugins.dart';
import '../project.dart'; import '../project.dart';
import '../reporting/reporting.dart'; import '../reporting/reporting.dart';
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
import 'android/gradle_utils.dart'; import 'android/gradle_utils.dart';
import 'base/context.dart'; import 'base/context.dart';
import 'build_system/build_system.dart';
import 'device.dart'; import 'device.dart';
import 'doctor.dart'; import 'doctor.dart';
import 'fuchsia/fuchsia_sdk.dart'; import 'fuchsia/fuchsia_sdk.dart';
...@@ -21,7 +20,6 @@ import 'runner/local_engine.dart'; ...@@ -21,7 +20,6 @@ import 'runner/local_engine.dart';
export 'globals_null_migrated.dart'; export 'globals_null_migrated.dart';
BuildSystem get buildSystem => context.get<BuildSystem>();
CrashReporter get crashReporter => context.get<CrashReporter>(); CrashReporter get crashReporter => context.get<CrashReporter>();
Doctor get doctor => context.get<Doctor>(); Doctor get doctor => context.get<Doctor>();
DeviceManager get deviceManager => context.get<DeviceManager>(); DeviceManager get deviceManager => context.get<DeviceManager>();
......
...@@ -23,6 +23,7 @@ import 'base/template.dart'; ...@@ -23,6 +23,7 @@ import 'base/template.dart';
import 'base/terminal.dart'; import 'base/terminal.dart';
import 'base/time.dart'; import 'base/time.dart';
import 'base/user_messages.dart'; import 'base/user_messages.dart';
import 'build_system/build_system.dart';
import 'cache.dart'; import 'cache.dart';
import 'ios/ios_workflow.dart'; import 'ios/ios_workflow.dart';
import 'ios/plist_parser.dart'; import 'ios/plist_parser.dart';
...@@ -33,6 +34,7 @@ import 'reporting/reporting.dart'; ...@@ -33,6 +34,7 @@ import 'reporting/reporting.dart';
import 'version.dart'; import 'version.dart';
Artifacts? get artifacts => context.get<Artifacts>(); Artifacts? get artifacts => context.get<Artifacts>();
BuildSystem? get buildSystem => context.get<BuildSystem>();
Cache get cache => context.get<Cache>()!; Cache get cache => context.get<Cache>()!;
Config get config => context.get<Config>()!; Config get config => context.get<Config>()!;
HttpClientFactory? get httpClientFactory => context.get<HttpClientFactory>(); HttpClientFactory? get httpClientFactory => context.get<HttpClientFactory>();
......
...@@ -35,7 +35,7 @@ import 'convert.dart'; ...@@ -35,7 +35,7 @@ import 'convert.dart';
import 'devfs.dart'; import 'devfs.dart';
import 'device.dart'; import 'device.dart';
import 'features.dart'; import 'features.dart';
import 'globals.dart' as globals; import 'globals_null_migrated.dart' as globals;
import 'project.dart'; import 'project.dart';
import 'resident_devtools_handler.dart'; import 'resident_devtools_handler.dart';
import 'run_cold.dart'; import 'run_cold.dart';
......
...@@ -13,7 +13,7 @@ import '../build_system/build_system.dart'; ...@@ -13,7 +13,7 @@ import '../build_system/build_system.dart';
import '../build_system/targets/web.dart'; import '../build_system/targets/web.dart';
import '../cache.dart'; import '../cache.dart';
import '../flutter_plugins.dart'; import '../flutter_plugins.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../platform_plugins.dart'; import '../platform_plugins.dart';
import '../plugins.dart'; import '../plugins.dart';
import '../project.dart'; import '../project.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -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 'dart:async'; import 'dart:async';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
...@@ -21,15 +19,15 @@ import '../../src/common.dart'; ...@@ -21,15 +19,15 @@ import '../../src/common.dart';
import '../../src/fake_process_manager.dart'; import '../../src/fake_process_manager.dart';
void main() { void main() {
FileSystem fileSystem; late FileSystem fileSystem;
Environment environment; late Environment environment;
Target fooTarget; late Target fooTarget;
Target barTarget; late Target barTarget;
Target fizzTarget; late Target fizzTarget;
Target sharedTarget; late Target sharedTarget;
int fooInvocations; late int fooInvocations;
int barInvocations; late int barInvocations;
int shared; late int shared;
setUp(() { setUp(() {
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
...@@ -136,7 +134,7 @@ void main() { ...@@ -136,7 +134,7 @@ void main() {
expect(stampFile, exists); expect(stampFile, exists);
final Map<String, dynamic> stampContents = castStringKeyedMap( final Map<String, Object?>? stampContents = castStringKeyedMap(
json.decode(stampFile.readAsStringSync())); json.decode(stampFile.readAsStringSync()));
expect(stampContents, containsPair('inputs', <Object>['/foo.dart'])); expect(stampContents, containsPair('inputs', <Object>['/foo.dart']));
...@@ -312,7 +310,7 @@ void main() { ...@@ -312,7 +310,7 @@ void main() {
testWithoutContext('Can describe itself with JSON output', () { testWithoutContext('Can describe itself with JSON output', () {
environment.buildDir.createSync(recursive: true); environment.buildDir.createSync(recursive: true);
expect(fooTarget.toJson(environment), <String, dynamic>{ expect(fooTarget.toJson(environment), <String, Object?>{
'inputs': <Object>[ 'inputs': <Object>[
'/foo.dart', '/foo.dart',
], ],
...@@ -685,7 +683,7 @@ void main() { ...@@ -685,7 +683,7 @@ void main() {
} }
BuildSystem setUpBuildSystem(FileSystem fileSystem, [FakePlatform platform]) { BuildSystem setUpBuildSystem(FileSystem fileSystem, [FakePlatform? platform]) {
return FlutterBuildSystem( return FlutterBuildSystem(
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
...@@ -694,16 +692,17 @@ BuildSystem setUpBuildSystem(FileSystem fileSystem, [FakePlatform platform]) { ...@@ -694,16 +692,17 @@ BuildSystem setUpBuildSystem(FileSystem fileSystem, [FakePlatform platform]) {
} }
class TestTarget extends Target { class TestTarget extends Target {
TestTarget([this._build, this._canSkip]); TestTarget([Future<void> Function(Environment environment)? build, this._canSkip])
: _build = build ?? ((Environment environment) async {});
final Future<void> Function(Environment environment) _build; final Future<void> Function(Environment environment) _build;
final bool Function(Environment environment) _canSkip; final bool Function(Environment environment)? _canSkip;
@override @override
bool canSkip(Environment environment) { bool canSkip(Environment environment) {
if (_canSkip != null) { if (_canSkip != null) {
return _canSkip(environment); return _canSkip!(environment);
} }
return super.canSkip(environment); return super.canSkip(environment);
} }
......
...@@ -2,8 +2,6 @@ ...@@ -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:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/exceptions.dart'; import 'package:flutter_tools/src/build_system/exceptions.dart';
...@@ -65,12 +63,8 @@ void main() { ...@@ -65,12 +63,8 @@ void main() {
} }
class TestTarget extends Target { class TestTarget extends Target {
TestTarget([this._build]);
final Future<void> Function(Environment environment) _build;
@override @override
Future<void> build(Environment environment) => _build(environment); Future<void> build(Environment environment) async {}
@override @override
List<Target> dependencies = <Target>[]; List<Target> dependencies = <Target>[];
......
...@@ -18,7 +18,7 @@ import 'package:flutter_tools/src/commands/build_linux.dart'; ...@@ -18,7 +18,7 @@ import 'package:flutter_tools/src/commands/build_linux.dart';
import 'package:flutter_tools/src/commands/build_macos.dart'; import 'package:flutter_tools/src/commands/build_macos.dart';
import 'package:flutter_tools/src/commands/build_web.dart'; import 'package:flutter_tools/src/commands/build_web.dart';
import 'package:flutter_tools/src/commands/build_windows.dart'; import 'package:flutter_tools/src/commands/build_windows.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/runner/flutter_command.dart'; import 'package:flutter_tools/src/runner/flutter_command.dart';
import '../../src/common.dart'; import '../../src/common.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -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 'dart:async'; import 'dart:async';
import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
...@@ -28,21 +26,21 @@ class TestBuildSystem implements BuildSystem { ...@@ -28,21 +26,21 @@ class TestBuildSystem implements BuildSystem {
_onRun = null; _onRun = null;
final List<BuildResult> _results; final List<BuildResult> _results;
final BuildResult _singleResult; final BuildResult? _singleResult;
final dynamic _exception; final Object? _exception;
final void Function(Target target, Environment environment) _onRun; final void Function(Target target, Environment environment)? _onRun;
int _nextResult = 0; int _nextResult = 0;
@override @override
Future<BuildResult> build(Target target, Environment environment, {BuildSystemConfig buildSystemConfig = const BuildSystemConfig()}) async { Future<BuildResult> build(Target target, Environment environment, {BuildSystemConfig buildSystemConfig = const BuildSystemConfig()}) async {
if (_onRun != null) { if (_onRun != null) {
_onRun(target, environment); _onRun?.call(target, environment);
} }
if (_exception != null) { if (_exception != null) {
throw _exception; throw _exception!;
} }
if (_singleResult != null) { if (_singleResult != null) {
return _singleResult; return _singleResult!;
} }
if (_nextResult >= _results.length) { if (_nextResult >= _results.length) {
throw StateError('Unexpected build request of ${target.name}'); throw StateError('Unexpected build request of ${target.name}');
...@@ -51,15 +49,15 @@ class TestBuildSystem implements BuildSystem { ...@@ -51,15 +49,15 @@ class TestBuildSystem implements BuildSystem {
} }
@override @override
Future<BuildResult> buildIncremental(Target target, Environment environment, BuildResult previousBuild) async { Future<BuildResult> buildIncremental(Target target, Environment environment, BuildResult? previousBuild) async {
if (_onRun != null) { if (_onRun != null) {
_onRun(target, environment); _onRun?.call(target, environment);
} }
if (_exception != null) { if (_exception != null) {
throw _exception; throw _exception!;
} }
if (_singleResult != null) { if (_singleResult != null) {
return _singleResult; return _singleResult!;
} }
if (_nextResult >= _results.length) { if (_nextResult >= _results.length) {
throw StateError('Unexpected buildIncremental request of ${target.name}'); throw StateError('Unexpected buildIncremental request of ${target.name}');
......
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