From cb3fb86f49ec7f6bb18adbcdfefd4f2da75c71c6 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 19 Feb 2021 16:37:11 +0100 Subject: [PATCH] Migrate user-facing apis to null-safety (#2996) Migrate packages typically imported by build authors to null-safety (part 1 /3). Closes #2920 In this PR, I migrate - the `build` package - the `build_test` package (or rather, the parts of that package that don't import `build_resolvers`) - the `scratch_space` package After the `graphs` package is migrated, I'll open another PR to migrate the `build_resolvers` package. When that one is done too, we can start to opt the tests of `build` and `build_test` into null-safety and publish, thus enabling build authors to write and test their builders with strong null-safety. Migrating the rest of the build system is not a goal for the near future, so we won't run builds with strong null-safety. --- build/CHANGELOG.md | 5 +++ build/lib/src/analyzer/resolver.dart | 4 +-- build/lib/src/asset/id.dart | 5 ++- build/lib/src/asset/reader.dart | 4 +-- build/lib/src/builder/build_step_impl.dart | 23 ++++++++----- build/lib/src/builder/builder.dart | 4 +-- build/lib/src/builder/exceptions.dart | 2 +- .../src/builder/file_deleting_builder.dart | 2 +- build/lib/src/builder/logging.dart | 4 +-- .../lib/src/builder/multiplexing_builder.dart | 3 +- .../src/builder/post_process_build_step.dart | 2 +- build/lib/src/experiments.dart | 2 +- build/lib/src/generate/expected_outputs.dart | 2 +- build/lib/src/generate/run_builder.dart | 17 +++++----- .../generate/run_post_process_builder.dart | 5 ++- build/lib/src/resource/resource.dart | 10 +++--- build/pubspec.yaml | 27 +++++++++------ build/test/builder/build_step_impl_test.dart | 1 + .../builder/multiplexing_builder_test.dart | 1 + build/test/generate/run_builder_test.dart | 1 + .../run_post_process_builder_test.dart | 1 + build/test/resource/resource_test.dart | 2 +- build_config/pubspec.yaml | 3 ++ build_daemon/pubspec.yaml | 16 ++++++++- build_resolvers/pubspec.yaml | 7 +++- build_runner/pubspec.yaml | 9 +++-- build_runner_core/lib/src/asset/cache.dart | 4 +-- .../lib/src/asset/file_based.dart | 2 +- build_runner_core/pubspec.yaml | 16 +++++++-- build_test/CHANGELOG.md | 4 +++ build_test/lib/build_test.dart | 2 ++ build_test/lib/builder.dart | 2 ++ build_test/lib/src/assets.dart | 2 +- build_test/lib/src/builder.dart | 12 +++---- build_test/lib/src/debug_test_builder.dart | 2 +- build_test/lib/src/in_memory_reader.dart | 16 ++++----- build_test/lib/src/matchers.dart | 6 ++-- build_test/lib/src/multi_asset_reader.dart | 2 +- build_test/lib/src/package_reader.dart | 28 +++++++++------ build_test/lib/src/resolve_source.dart | 1 + build_test/lib/src/stub_reader.dart | 3 +- .../lib/src/test_bootstrap_builder.dart | 2 ++ build_test/lib/src/test_builder.dart | 1 + build_test/lib/src/written_asset_reader.dart | 11 +++--- build_test/pubspec.yaml | 34 +++++++++++-------- build_test/test/check_outputs_test.dart | 1 + build_test/test/debug_test_builder_test.dart | 1 + build_test/test/in_memory_reader_test.dart | 1 + build_test/test/multi_asset_reader_test.dart | 1 + build_test/test/package_reader_test.dart | 1 + build_test/test/record_logs_test.dart | 1 + build_test/test/resolve_source_test.dart | 1 + .../test/test_bootstrap_builder_test.dart | 1 + build_test/test/test_builder_test.dart | 10 +++--- .../test/written_asset_reader_test.dart | 2 ++ build_web_compilers/pubspec.yaml | 2 +- scratch_space/CHANGELOG.md | 4 +++ scratch_space/lib/src/scratch_space.dart | 2 +- scratch_space/lib/src/util.dart | 2 +- scratch_space/pubspec.yaml | 19 +++++++---- scratch_space/test/scratch_space_test.dart | 4 ++- 61 files changed, 232 insertions(+), 133 deletions(-) diff --git a/build/CHANGELOG.md b/build/CHANGELOG.md index 36828864f..eacdc923d 100644 --- a/build/CHANGELOG.md +++ b/build/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.0-dev + +- Migrate to null-safety +- __Breaking__: Remove the deprecated `rootPackage` argument to `runBuilder` + ## 1.6.3 - Use latest analyzer version `1.x`. diff --git a/build/lib/src/analyzer/resolver.dart b/build/lib/src/analyzer/resolver.dart index b671921de..acdb7e4c3 100644 --- a/build/lib/src/analyzer/resolver.dart +++ b/build/lib/src/analyzer/resolver.dart @@ -64,7 +64,7 @@ abstract class Resolver { /// **NOTE**: In general, its recommended to use [libraryFor] with an absolute /// asset id instead of a named identifier that has the possibility of not /// being unique. - Future findLibraryByName(String libraryName); + Future findLibraryByName(String libraryName); /// Returns the [AssetId] of the Dart library or part declaring [element]. /// @@ -168,7 +168,7 @@ class SyntaxErrorInAssetException implements Exception { final error = errorAndResult.key; // Use a short name: We present the full context by including the asset id // and this is easier to skim through - final sourceName = error.source?.shortName ?? ''; + final sourceName = error.source.shortName; final lineInfo = errorAndResult.value.lineInfo; final position = lineInfo.getLocation(error.offset); diff --git a/build/lib/src/asset/id.dart b/build/lib/src/asset/id.dart index 9d79ac7af..f0cb75818 100644 --- a/build/lib/src/asset/id.dart +++ b/build/lib/src/asset/id.dart @@ -55,7 +55,7 @@ class AssetId implements Comparable { /// /// `asset:` uris have the format '$package/$path', including the top level /// directory. - factory AssetId.resolve(String uri, {AssetId from}) { + factory AssetId.resolve(String uri, {AssetId? from}) { final parsedUri = Uri.parse(uri); if (parsedUri.hasScheme) { if (parsedUri.scheme == 'package') { @@ -108,8 +108,7 @@ class AssetId implements Comparable { /// A `package:` URI suitable for use directly with other systems if this /// asset is under it's package's `lib/` directory, else an `asset:` URI /// suitable for use within build tools. - Uri get uri => _uri ??= _constructUri(this); - Uri _uri; + late final Uri uri = _constructUri(this); /// Deserializes an [AssetId] from [data], which must be the result of /// calling [serialize] on an existing [AssetId]. diff --git a/build/lib/src/asset/reader.dart b/build/lib/src/asset/reader.dart index 518255f62..557d4fc7b 100644 --- a/build/lib/src/asset/reader.dart +++ b/build/lib/src/asset/reader.dart @@ -28,7 +28,7 @@ abstract class AssetReader { /// * Throws a `PackageNotFoundException` if `id.package` is not found. /// * Throws a `AssetNotFoundException` if `id.path` is not found. /// * Throws an `InvalidInputException` if [id] is an invalid input. - Future readAsString(AssetId id, {Encoding encoding}); + Future readAsString(AssetId id, {Encoding encoding = utf8}); /// Indicates whether asset at [id] is readable. Future canRead(AssetId id); @@ -68,5 +68,5 @@ abstract class MultiPackageAssetReader extends AssetReader { /// Some implementations may require the [package] argument, while others /// may have a sane default. @override - Stream findAssets(Glob glob, {String package}); + Stream findAssets(Glob glob, {String? package}); } diff --git a/build/lib/src/builder/build_step_impl.dart b/build/lib/src/builder/build_step_impl.dart index 186750731..899c7f5dd 100644 --- a/build/lib/src/builder/build_step_impl.dart +++ b/build/lib/src/builder/build_step_impl.dart @@ -25,7 +25,7 @@ import 'exceptions.dart'; /// This represents a single input and its expected and real outputs. It also /// handles tracking of dependencies. class BuildStepImpl implements BuildStep { - final Resolvers _resolvers; + final Resolvers? _resolvers; final StageTracker _stageTracker; /// The primary input id for this build step. @@ -55,12 +55,12 @@ class BuildStepImpl implements BuildStep { bool _isComplete = false; - final void Function(Iterable) _reportUnusedAssets; + final void Function(Iterable)? _reportUnusedAssets; BuildStepImpl(this.inputId, Iterable expectedOutputs, this._reader, this._writer, this._resolvers, this._resourceManager, - {StageTracker stageTracker, - void Function(Iterable) reportUnusedAssets}) + {StageTracker? stageTracker, + void Function(Iterable)? reportUnusedAssets}) : _expectedOutputs = expectedOutputs.toSet(), _stageTracker = stageTracker ?? NoOpStageTracker.instance, _reportUnusedAssets = reportUnusedAssets; @@ -68,10 +68,15 @@ class BuildStepImpl implements BuildStep { @override Resolver get resolver { if (_isComplete) throw BuildStepCompletedException(); - return _DelayedResolver(_resolver ??= _resolvers.get(this)); + final resolvers = _resolvers; + if (resolvers == null) { + throw UnsupportedError('Resolvers are not available in this build.'); + } + + return _DelayedResolver(_resolver ??= resolvers.get(this)); } - Future _resolver; + Future? _resolver; @override Future canRead(AssetId id) { @@ -142,7 +147,7 @@ class BuildStepImpl implements BuildStep { Future _futureOrWrite( FutureOr content, Future Function(T content) write) => - (content is Future) ? content.then(write) : write(content as T); + (content is Future) ? content.then(write) : write(content); /// Waits for work to finish and cleans up resources. /// @@ -165,7 +170,7 @@ class BuildStepImpl implements BuildStep { @override void reportUnusedAssets(Iterable assets) { - if (_reportUnusedAssets != null) _reportUnusedAssets(assets); + _reportUnusedAssets?.call(assets); } } @@ -202,7 +207,7 @@ class _DelayedResolver implements Resolver { .libraryFor(assetId, allowSyntaxErrors: allowSyntaxErrors); @override - Future findLibraryByName(String libraryName) async => + Future findLibraryByName(String libraryName) async => (await _delegate).findLibraryByName(libraryName); @override diff --git a/build/lib/src/builder/builder.dart b/build/lib/src/builder/builder.dart index 1c97f4053..b12a5716a 100644 --- a/build/lib/src/builder/builder.dart +++ b/build/lib/src/builder/builder.dart @@ -40,7 +40,7 @@ class BuilderOptions { /// Whether or not this builder is running on the root package. final bool isRoot; - const BuilderOptions(this.config, {bool isRoot}) : isRoot = isRoot ?? false; + const BuilderOptions(this.config, {this.isRoot = false}); /// Returns a new set of options with keys from [other] overriding options in /// this instance. @@ -50,7 +50,7 @@ class BuilderOptions { /// returned directly. /// /// The `isRoot` value will also be overridden to value from [other]. - BuilderOptions overrideWith(BuilderOptions other) { + BuilderOptions overrideWith(BuilderOptions? other) { if (other == null) return this; return BuilderOptions({}..addAll(config)..addAll(other.config), isRoot: other.isRoot); diff --git a/build/lib/src/builder/exceptions.dart b/build/lib/src/builder/exceptions.dart index 8458b051b..678fa44d7 100644 --- a/build/lib/src/builder/exceptions.dart +++ b/build/lib/src/builder/exceptions.dart @@ -5,7 +5,7 @@ import '../asset/id.dart'; class UnexpectedOutputException implements Exception { final AssetId assetId; - final Iterable expected; + final Iterable? expected; UnexpectedOutputException(this.assetId, {this.expected}); diff --git a/build/lib/src/builder/file_deleting_builder.dart b/build/lib/src/builder/file_deleting_builder.dart index 462103979..7bd6db32b 100644 --- a/build/lib/src/builder/file_deleting_builder.dart +++ b/build/lib/src/builder/file_deleting_builder.dart @@ -24,7 +24,7 @@ class FileDeletingBuilder implements PostProcessBuilder { FileDeletingBuilder.withExcludes( this.inputExtensions, Iterable exclude, {this.isEnabled = true}) - : exclude = exclude?.map((s) => Glob(s))?.toList() ?? const []; + : exclude = exclude.map((s) => Glob(s)).toList(); @override FutureOr build(PostProcessBuildStep buildStep) { diff --git a/build/lib/src/builder/logging.dart b/build/lib/src/builder/logging.dart index 8edb13f78..a303b2f6e 100644 --- a/build/lib/src/builder/logging.dart +++ b/build/lib/src/builder/logging.dart @@ -13,7 +13,7 @@ final _default = Logger('build.fallback'); /// The log instance for the currently running BuildStep. /// /// Will be `null` when not running within a build. -Logger get log => Zone.current[logKey] as Logger ?? _default; +Logger get log => Zone.current[logKey] as Logger? ?? _default; /// Runs [fn] in an error handling [Zone]. /// @@ -29,7 +29,7 @@ Future scopeLogAsync(Future Function() fn, Logger log) { done.completeError(e, st); }, zoneSpecification: ZoneSpecification(print: (self, parent, zone, message) { log.warning(message); - }), zoneValues: {logKey: log}).then((result) { + }), zoneValues: {logKey: log})?.then((result) { if (done.isCompleted) return; done.complete(result); }); diff --git a/build/lib/src/builder/multiplexing_builder.dart b/build/lib/src/builder/multiplexing_builder.dart index ea7f9e943..bf9c44d93 100644 --- a/build/lib/src/builder/multiplexing_builder.dart +++ b/build/lib/src/builder/multiplexing_builder.dart @@ -42,8 +42,7 @@ Map> _mergeMaps(Iterable>> maps) { var result = >{}; for (var map in maps) { for (var key in map.keys) { - result.putIfAbsent(key, () => []); - result[key].addAll(map[key]); + result.putIfAbsent(key, () => []).addAll(map[key]!); } } return result; diff --git a/build/lib/src/builder/post_process_build_step.dart b/build/lib/src/builder/post_process_build_step.dart index 5c804aac0..9ca980ab8 100644 --- a/build/lib/src/builder/post_process_build_step.dart +++ b/build/lib/src/builder/post_process_build_step.dart @@ -76,4 +76,4 @@ class PostProcessBuildStep { Future _futureOrWrite( FutureOr content, Future Function(T content) write) => - (content is Future) ? content.then(write) : write(content as T); + (content is Future) ? content.then(write) : write(content); diff --git a/build/lib/src/experiments.dart b/build/lib/src/experiments.dart index 9ef88f02c..018eb417c 100644 --- a/build/lib/src/experiments.dart +++ b/build/lib/src/experiments.dart @@ -10,7 +10,7 @@ const Symbol _enabledExperimentsKey = #dartLanguageEnabledExperiments; /// /// This can be overridden for a new [Zone] by using [withEnabledExperiments]. List get enabledExperiments => - Zone.current[_enabledExperimentsKey] as List ?? const []; + Zone.current[_enabledExperimentsKey] as List? ?? const []; /// Runs [fn] in a [Zone], setting [enabledExperiments] for all code running /// in that [Zone]. diff --git a/build/lib/src/generate/expected_outputs.dart b/build/lib/src/generate/expected_outputs.dart index 9d3425a40..84a9f8f88 100644 --- a/build/lib/src/generate/expected_outputs.dart +++ b/build/lib/src/generate/expected_outputs.dart @@ -10,7 +10,7 @@ Iterable expectedOutputs(Builder builder, AssetId input) { var matchingExtensions = builder.buildExtensions.keys.where((e) => input.path.endsWith(e)); return matchingExtensions - .expand((e) => _replaceExtensions(input, e, builder.buildExtensions[e])); + .expand((e) => _replaceExtensions(input, e, builder.buildExtensions[e]!)); } Iterable _replaceExtensions( diff --git a/build/lib/src/generate/run_builder.dart b/build/lib/src/generate/run_builder.dart index efe1d9037..880da1999 100644 --- a/build/lib/src/generate/run_builder.dart +++ b/build/lib/src/generate/run_builder.dart @@ -29,22 +29,21 @@ import 'expected_outputs.dart'; /// `BuildStep.reportUnusedAssets` in [builder] will be forwarded to this /// function with the associated primary input. Future runBuilder(Builder builder, Iterable inputs, - AssetReader reader, AssetWriter writer, Resolvers resolvers, - {Logger logger, - ResourceManager resourceManager, - @Deprecated('The rootPackage argument is unused') String rootPackage, + AssetReader reader, AssetWriter writer, Resolvers? resolvers, + {Logger? logger, + ResourceManager? resourceManager, StageTracker stageTracker = NoOpStageTracker.instance, - void Function(AssetId input, Iterable assets) + void Function(AssetId input, Iterable assets)? reportUnusedAssetsForInput}) async { var shouldDisposeResourceManager = resourceManager == null; - resourceManager ??= ResourceManager(); + final resources = resourceManager ?? ResourceManager(); logger ??= Logger('runBuilder'); //TODO(nbosch) check overlapping outputs? Future buildForInput(AssetId input) async { var outputs = expectedOutputs(builder, input); if (outputs.isEmpty) return; var buildStep = BuildStepImpl( - input, outputs, reader, writer, resolvers, resourceManager, + input, outputs, reader, writer, resolvers, resources, stageTracker: stageTracker, reportUnusedAssets: reportUnusedAssetsForInput == null ? null @@ -59,7 +58,7 @@ Future runBuilder(Builder builder, Iterable inputs, await scopeLogAsync(() => Future.wait(inputs.map(buildForInput)), logger); if (shouldDisposeResourceManager) { - await resourceManager.disposeAll(); - await resourceManager.beforeExit(); + await resources.disposeAll(); + await resources.beforeExit(); } } diff --git a/build/lib/src/generate/run_post_process_builder.dart b/build/lib/src/generate/run_post_process_builder.dart index 15fca7023..121bae0ec 100644 --- a/build/lib/src/generate/run_post_process_builder.dart +++ b/build/lib/src/generate/run_post_process_builder.dart @@ -3,7 +3,6 @@ // BSD-style license that can be found in the LICENSE file. import 'package:logging/logging.dart'; -import 'package:meta/meta.dart'; import '../asset/id.dart'; import '../asset/reader.dart'; @@ -20,8 +19,8 @@ import '../builder/post_process_builder.dart'; /// deleted on disk since the `writer` has no mechanism for delete. Future runPostProcessBuilder(PostProcessBuilder builder, AssetId inputId, AssetReader reader, AssetWriter writer, Logger logger, - {@required void Function(AssetId) addAsset, - @required void Function(AssetId) deleteAsset}) async { + {required void Function(AssetId) addAsset, + required void Function(AssetId) deleteAsset}) async { await scopeLogAsync(() async { var buildStep = postProcessBuildStep(inputId, reader, writer, addAsset, deleteAsset); diff --git a/build/lib/src/resource/resource.dart b/build/lib/src/resource/resource.dart index 6a559105c..fe9049e52 100644 --- a/build/lib/src/resource/resource.dart +++ b/build/lib/src/resource/resource.dart @@ -22,18 +22,18 @@ class Resource { /// Optional method which is given an existing instance that is ready to be /// disposed. - final DisposeInstance _userDispose; + final DisposeInstance? _userDispose; /// Optional method which is called before the process is going to exit. /// /// This allows resources to do any final cleanup, and is not given an /// instance. - final BeforeExit _userBeforeExit; + final BeforeExit? _userBeforeExit; /// A Future instance of this resource if one has ever been requested. final _instanceByManager = >{}; - Resource(this._create, {DisposeInstance dispose, BeforeExit beforeExit}) + Resource(this._create, {DisposeInstance? dispose, BeforeExit? beforeExit}) : _userDispose = dispose, _userBeforeExit = beforeExit; @@ -47,7 +47,7 @@ class Resource { var oldInstance = _fetch(manager); _instanceByManager.remove(manager); if (_userDispose != null) { - return oldInstance.then(_userDispose); + return oldInstance.then(_userDispose!); } else { return Future.value(null); } @@ -88,7 +88,7 @@ class ResourceManager { /// Invokes the `beforeExit` callbacks of all [Resource]s that had one. Future beforeExit() async { await Future.wait(_resourcesWithBeforeExit.map((r) async { - if (r._userBeforeExit != null) return r._userBeforeExit(); + return r._userBeforeExit?.call(); })); _resourcesWithBeforeExit.clear(); } diff --git a/build/pubspec.yaml b/build/pubspec.yaml index 7bf04cec2..d0d68a020 100644 --- a/build/pubspec.yaml +++ b/build/pubspec.yaml @@ -1,23 +1,30 @@ name: build -version: 1.6.3 +version: 2.0.0-dev description: A build system for Dart. homepage: https://github.com/dart-lang/build/tree/master/build environment: - sdk: ">=2.11.99 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" dependencies: analyzer: ^1.0.0 - async: ">=1.13.3 <3.0.0" - convert: ">=2.0.0 <4.0.0" - crypto: ">=0.9.2 <4.0.0" + async: ^2.0.0 + convert: ^3.0.0 + crypto: ^3.0.0 glob: ^2.0.0 - logging: ">=0.11.2 <2.0.0" - meta: ^1.1.0 - path: ^1.1.0 + logging: ^1.0.0 + meta: ^1.3.0 + path: ^1.8.0 dev_dependencies: build_resolvers: ^1.0.0 - build_test: ^1.0.0 + build_test: ^1.4.0 pedantic: ^1.0.0 - test: ^1.2.0 + test: ^1.16.0 + +dependency_overrides: + build_resolvers: + path: ../build_resolvers + build_test: + path: ../build_test + ## Remove each of the above as they are published diff --git a/build/test/builder/build_step_impl_test.dart b/build/test/builder/build_step_impl_test.dart index aaf1942c7..578e926bf 100644 --- a/build/test/builder/build_step_impl_test.dart +++ b/build/test/builder/build_step_impl_test.dart @@ -1,6 +1,7 @@ // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +//@dart=2.9 @TestOn('vm') import 'dart:async'; import 'dart:convert'; diff --git a/build/test/builder/multiplexing_builder_test.dart b/build/test/builder/multiplexing_builder_test.dart index 339f15540..3bdbe0f1e 100644 --- a/build/test/builder/multiplexing_builder_test.dart +++ b/build/test/builder/multiplexing_builder_test.dart @@ -1,6 +1,7 @@ // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// @dart=2.9 import 'package:build/build.dart'; import 'package:build_test/build_test.dart'; diff --git a/build/test/generate/run_builder_test.dart b/build/test/generate/run_builder_test.dart index 6547bb500..9783e0a60 100644 --- a/build/test/generate/run_builder_test.dart +++ b/build/test/generate/run_builder_test.dart @@ -1,6 +1,7 @@ // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// @dart=2.9 @TestOn('vm') import 'dart:async'; diff --git a/build/test/generate/run_post_process_builder_test.dart b/build/test/generate/run_post_process_builder_test.dart index d517f13cb..f6f91652a 100644 --- a/build/test/generate/run_post_process_builder_test.dart +++ b/build/test/generate/run_post_process_builder_test.dart @@ -1,6 +1,7 @@ // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// @dart=2.9 import 'package:build/build.dart'; import 'package:build_test/build_test.dart'; diff --git a/build/test/resource/resource_test.dart b/build/test/resource/resource_test.dart index fad0442f9..2897574c1 100644 --- a/build/test/resource/resource_test.dart +++ b/build/test/resource/resource_test.dart @@ -9,7 +9,7 @@ import 'package:test/test.dart'; import 'package:build/build.dart'; void main() { - ResourceManager resourceManager; + late ResourceManager resourceManager; setUp(() { resourceManager = ResourceManager(); }); diff --git a/build_config/pubspec.yaml b/build_config/pubspec.yaml index 87884de6d..4ec701b89 100644 --- a/build_config/pubspec.yaml +++ b/build_config/pubspec.yaml @@ -27,3 +27,6 @@ dependency_overrides: path: ../build_runner build_runner_core: path: ../build_runner_core + # Temporarily required until build version 2.0.0 is released + build: + path: ../build \ No newline at end of file diff --git a/build_daemon/pubspec.yaml b/build_daemon/pubspec.yaml index e4a636279..da41ccb1d 100644 --- a/build_daemon/pubspec.yaml +++ b/build_daemon/pubspec.yaml @@ -27,4 +27,18 @@ dev_dependencies: mockito: ^4.0.0 test: ^1.3.3 test_descriptor: ^1.1.1 - uuid: ^2.0.0 + uuid: ^3.0.0-0 + +dependency_overrides: + ## Remove each of the following as they are published + build: + path: ../build + build_config: + path: ../build_config + build_resolvers: + path: ../build_resolvers + build_runner: + path: ../build_runner + build_runner_core: + path: ../build_runner_core + ## Remove each of the above as they are published diff --git a/build_resolvers/pubspec.yaml b/build_resolvers/pubspec.yaml index 2b8242684..b71f3d7d4 100644 --- a/build_resolvers/pubspec.yaml +++ b/build_resolvers/pubspec.yaml @@ -8,7 +8,7 @@ environment: dependencies: analyzer: ^1.0.0 - build: ">=1.6.0 <1.7.0" + build: "^2.0.0" crypto: ">=2.0.0 <4.0.0" graphs: ^0.2.0 logging: ">=0.11.2 <2.0.0" @@ -21,3 +21,8 @@ dependencies: dev_dependencies: test: ^1.0.0 build_test: ^1.0.0 + +dependency_overrides: + # Temporarily required until build version 2.0.0 is released + build: + path: ../build diff --git a/build_runner/pubspec.yaml b/build_runner/pubspec.yaml index e6b055eeb..c1b54e852 100644 --- a/build_runner/pubspec.yaml +++ b/build_runner/pubspec.yaml @@ -9,8 +9,8 @@ environment: dependencies: args: ">=1.4.0 <3.0.0" async: ">=1.13.3 <3.0.0" - build: ">=1.5.0 <1.7.0" - build_config: '>=0.4.1 <0.4.7' + build: ">=2.0.0 <2.1.0" + build_config: '>=0.4.1 <0.4.6' build_daemon: ^2.1.0 build_resolvers: ^1.4.0 build_runner_core: ">=5.2.0 <7.0.0" @@ -51,3 +51,8 @@ dev_dependencies: test_process: ^1.0.0 _test_common: path: ../_test_common + +dependency_overrides: + # Temporarily required until build version 2.0.0 is released + build: + path: ../build diff --git a/build_runner_core/lib/src/asset/cache.dart b/build_runner_core/lib/src/asset/cache.dart index 12fabebec..f315eced3 100644 --- a/build_runner_core/lib/src/asset/cache.dart +++ b/build_runner_core/lib/src/asset/cache.dart @@ -79,9 +79,7 @@ class CachingAssetReader implements AssetReader { } @override - Future readAsString(AssetId id, {Encoding encoding}) { - encoding ??= utf8; - + Future readAsString(AssetId id, {Encoding encoding = utf8}) { if (encoding != utf8) { // Fallback case, we never cache the String value for the non-default, // encoding but we do allow it to cache the bytes. diff --git a/build_runner_core/lib/src/asset/file_based.dart b/build_runner_core/lib/src/asset/file_based.dart index 8fdf141db..3d30feb6f 100644 --- a/build_runner_core/lib/src/asset/file_based.dart +++ b/build_runner_core/lib/src/asset/file_based.dart @@ -35,7 +35,7 @@ class FileBasedAssetReader extends AssetReader .then((file) => _descriptorPool.withResource(file.readAsBytes)); @override - Future readAsString(AssetId id, {Encoding encoding}) => + Future readAsString(AssetId id, {Encoding encoding = utf8}) => _fileForOrThrow(id, packageGraph).then((file) => _descriptorPool .withResource(() => file.readAsString(encoding: encoding ?? utf8))); diff --git a/build_runner_core/pubspec.yaml b/build_runner_core/pubspec.yaml index ea23d2eaf..362a0ca81 100644 --- a/build_runner_core/pubspec.yaml +++ b/build_runner_core/pubspec.yaml @@ -8,8 +8,8 @@ environment: dependencies: async: ">=1.13.3 <3.0.0" - build: ">=1.5.1 <1.7.0" - build_config: ">=0.4.3 <0.4.7" + build: "^2.0.0" + build_config: ">=0.4.3 <0.4.6" build_resolvers: ^1.4.0 collection: ^1.14.0 convert: ">=2.0.1 <4.0.0" @@ -33,3 +33,15 @@ dev_dependencies: test_process: ^1.0.0 _test_common: path: ../_test_common + +dependency_overrides: + ## Remove each of the below as they are published + build: + path: ../build + build_config: + path: ../build_config + build_resolvers: + path: ../build_resolvers + build_test: + path: ../build_test + ## Remove each of the above as they are published diff --git a/build_test/CHANGELOG.md b/build_test/CHANGELOG.md index 366a3aaf7..697686095 100644 --- a/build_test/CHANGELOG.md +++ b/build_test/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.4.0-dev + +- Migrate to null safety + ## 1.3.7 - Update to analyzer `1.x`. diff --git a/build_test/lib/build_test.dart b/build_test/lib/build_test.dart index e2155148b..c121de6ed 100644 --- a/build_test/lib/build_test.dart +++ b/build_test/lib/build_test.dart @@ -1,6 +1,8 @@ // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// +// @dart=2.9 export 'package:build/src/builder/logging.dart' show scopeLogAsync; diff --git a/build_test/lib/builder.dart b/build_test/lib/builder.dart index 44d76978a..415d35c3d 100644 --- a/build_test/lib/builder.dart +++ b/build_test/lib/builder.dart @@ -1,6 +1,8 @@ // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// +//@dart=2.9 import 'src/debug_test_builder.dart'; import 'src/test_bootstrap_builder.dart'; diff --git a/build_test/lib/src/assets.dart b/build_test/lib/src/assets.dart index 53597a843..d71cd1302 100644 --- a/build_test/lib/src/assets.dart +++ b/build_test/lib/src/assets.dart @@ -9,7 +9,7 @@ import 'package:build/build.dart'; import 'in_memory_writer.dart'; int _nextId = 0; -AssetId makeAssetId([String assetIdString]) { +AssetId makeAssetId([String? assetIdString]) { if (assetIdString == null) { assetIdString = 'a|web/asset_$_nextId.txt'; _nextId++; diff --git a/build_test/lib/src/builder.dart b/build_test/lib/src/builder.dart index f36f6e384..83fd9693c 100644 --- a/build_test/lib/src/builder.dart +++ b/build_test/lib/src/builder.dart @@ -31,7 +31,7 @@ void _copyToAll(BuildStep buildStep, Map> buildExtensions, } for (final inputExtension in buildExtensions.keys) { if (!buildStep.inputId.path.endsWith(inputExtension)) continue; - for (final outputExtension in buildExtensions[inputExtension]) { + for (final outputExtension in buildExtensions[inputExtension]!) { final newPath = _replaceSuffix( buildStep.inputId.path, inputExtension, outputExtension); final id = AssetId(buildStep.inputId.package, newPath); @@ -76,7 +76,7 @@ class TestBuilder implements Builder { final Map> buildExtensions; final BuildBehavior _build; - final BuildBehavior _extraWork; + final BuildBehavior? _extraWork; /// A stream of all the [BuildStep.inputId]s that are seen. /// @@ -91,9 +91,9 @@ class TestBuilder implements Builder { Stream get buildsCompleted => _buildsCompletedController.stream; TestBuilder({ - Map> buildExtensions, - BuildBehavior build, - BuildBehavior extraWork, + Map>? buildExtensions, + BuildBehavior? build, + BuildBehavior? extraWork, }) : buildExtensions = buildExtensions ?? appendExtension('.copy'), _build = build ?? _defaultBehavior, _extraWork = extraWork; @@ -103,7 +103,7 @@ class TestBuilder implements Builder { if (!await buildStep.canRead(buildStep.inputId)) return; _buildInputsController.add(buildStep.inputId); await _build(buildStep, buildExtensions); - if (_extraWork != null) await _extraWork(buildStep, buildExtensions); + await _extraWork?.call(buildStep, buildExtensions); _buildsCompletedController.add(buildStep.inputId); } } diff --git a/build_test/lib/src/debug_test_builder.dart b/build_test/lib/src/debug_test_builder.dart index 443f82d7a..02613057e 100644 --- a/build_test/lib/src/debug_test_builder.dart +++ b/build_test/lib/src/debug_test_builder.dart @@ -54,7 +54,7 @@ class DebugTestBuilder implements Builder { final document = parse(customHtml); // Replace with