Skip to content

Migrate to null-safety #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Created with package:mono_repo v3.4.6
# Created with package:mono_repo v3.4.7
name: Dart CI
on:
push:
Expand Down Expand Up @@ -27,13 +27,13 @@ jobs:
restore-keys: |
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: stable
- id: checkout
uses: actions/checkout@v2
- name: mono_repo self validate
run: pub global activate mono_repo 3.4.6
run: pub global activate mono_repo 3.4.7
- name: mono_repo self validate
run: pub global run mono_repo generate --validate
job_002:
Expand All @@ -50,7 +50,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: "2.12.0"
- id: checkout
Expand All @@ -155,6 +155,39 @@ jobs:
working-directory: source_gen
run: dartanalyzer .
job_005:
name: "unit_test; Dart 2.12.0; PKG: example_usage; `pub run test --run-skipped`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v2
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:example_usage;commands:test_0"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:example_usage
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/[email protected]
with:
sdk: "2.12.0"
- id: checkout
uses: actions/checkout@v2
- id: example_usage_pub_upgrade
name: "example_usage; pub upgrade --no-precompile"
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: example_usage
run: pub upgrade --no-precompile
- name: "example_usage; pub run test --run-skipped"
if: "always() && steps.example_usage_pub_upgrade.conclusion == 'success'"
working-directory: example_usage
run: pub run test --run-skipped
needs:
- job_001
- job_002
- job_003
- job_004
job_006:
name: "unit_test; Dart dev; PKG: example_usage; `pub run test --run-skipped`"
runs-on: ubuntu-latest
steps:
Expand All @@ -168,7 +201,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand All @@ -187,7 +220,7 @@ jobs:
- job_002
- job_003
- job_004
job_006:
job_007:
name: "unit_test; Dart 2.12.0; PKG: source_gen; `pub run test`"
runs-on: ubuntu-latest
steps:
Expand All @@ -201,7 +234,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: "2.12.0"
- id: checkout
Expand All @@ -220,7 +253,7 @@ jobs:
- job_002
- job_003
- job_004
job_007:
job_008:
name: "unit_test; Dart dev; PKG: source_gen; `pub run test`"
runs-on: ubuntu-latest
steps:
Expand All @@ -234,7 +267,7 @@ jobs:
os:ubuntu-latest;pub-cache-hosted;dart:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- uses: dart-lang/setup-dart@v0.3
- uses: dart-lang/setup-dart@v1.0
with:
sdk: dev
- id: checkout
Expand Down
2 changes: 1 addition & 1 deletion _test_annotations/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: _test_annotations
environment:
sdk: '>=2.10.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: source_gen_example

environment:
sdk: ">=2.10.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
analyzer: '>=0.42.0-nullsafety <2.0.0'
analyzer: ^1.0.0
build: ^2.0.0
source_gen: any

Expand Down
1 change: 1 addition & 0 deletions example_usage/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://github.com/google/mono_repo.dart for details
dart:
- 2.12.0
- dev

stages:
Expand Down
4 changes: 2 additions & 2 deletions example_usage/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: source_gen_example_usage

environment:
sdk: '>=2.10.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dev_dependencies:
build_runner: ^1.10.3
build_verify: ^1.1.0
build_verify: ^2.0.0
source_gen_example:
path: ../example
test: ^1.5.1
Expand Down
5 changes: 5 additions & 0 deletions source_gen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.0

- Migrate to null safety.
- Require Dart `2.12.0`.

## 0.9.10+4

* Upgrade to `package:build` version `2.0.0`.
Expand Down
20 changes: 8 additions & 12 deletions source_gen/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import 'src/utils.dart';
const _outputExtensions = '.g.dart';
const _partFiles = '.g.part';

Builder combiningBuilder([BuilderOptions options]) {
final optionsMap = Map<String, dynamic>.from(options?.config ?? {});
Builder combiningBuilder([BuilderOptions options = BuilderOptions.empty]) {
final optionsMap = Map<String, dynamic>.from(options.config);

final includePartName = optionsMap.remove('include_part_name') as bool;
final includePartName = optionsMap.remove('include_part_name') as bool?;
final ignoreForFile = Set<String>.from(
optionsMap.remove('ignore_for_file') as List ?? <String>[],
optionsMap.remove('ignore_for_file') as List? ?? <String>[],
);

final builder = CombiningBuilder(
Expand All @@ -36,11 +36,7 @@ Builder combiningBuilder([BuilderOptions options]) {
);

if (optionsMap.isNotEmpty) {
if (log == null) {
throw StateError('Upgrade `build_runner` to at least 0.8.2.');
} else {
log.warning('These options were ignored: `$optionsMap`.');
}
log.warning('These options were ignored: `$optionsMap`.');
}
return builder;
}
Expand All @@ -67,8 +63,8 @@ class CombiningBuilder implements Builder {
/// is output as a comment before its content. This can be useful when
/// debugging build issues.
const CombiningBuilder({
bool includePartName = false,
Set<String> ignoreForFile,
bool? includePartName,
Set<String>? ignoreForFile,
}) : _includePartName = includePartName ?? false,
_ignoreForFile = ignoreForFile ?? const <String>{};

Expand All @@ -89,7 +85,7 @@ class CombiningBuilder implements Builder {
partIdRegExpLiteral, // A valid part ID
RegExp.escape(_partFiles), // the ending part extension
'\$', // end of string
].join(''));
].join());

final assetIds = await buildStep
.findAssets(Glob(pattern))
Expand Down
28 changes: 9 additions & 19 deletions source_gen/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class _Builder extends Builder {
/// Wrap [_generators] to form a [Builder]-compatible API.
_Builder(
this._generators, {
String Function(String code) formatOutput,
String Function(String code)? formatOutput,
String generatedExtension = '.g.dart',
List<String> additionalOutputExtensions = const [],
String header,
String? header,
this.allowSyntaxErrors = false,
}) : _generatedExtension = generatedExtension,
buildExtensions = {
Expand All @@ -55,9 +55,6 @@ class _Builder extends Builder {
},
formatOutput = formatOutput ?? _formatter.format,
_header = (header ?? defaultFileHeader).trim() {
if (_generatedExtension == null) {
throw ArgumentError.notNull('generatedExtension');
}
if (_generatedExtension.isEmpty || !_generatedExtension.startsWith('.')) {
throw ArgumentError.value(_generatedExtension, 'generatedExtension',
'Extension must be in the format of .*');
Expand Down Expand Up @@ -109,14 +106,6 @@ class _Builder extends Builder {
if (!_isLibraryBuilder) {
final asset = buildStep.inputId;
final name = nameOfPartial(library, asset);
if (name == null) {
final suggest = suggestLibraryName(asset);
throw InvalidGenerationSourceError(
'Could not find library identifier so a "part of" cannot be built.',
todo: ''
'Consider adding the following to your source file:\n\n'
'library $suggest;');
}
contentBuffer.writeln();

String part;
Expand Down Expand Up @@ -212,7 +201,7 @@ class SharedPartBuilder extends _Builder {
SharedPartBuilder(
List<Generator> generators,
String partId, {
String Function(String code) formatOutput,
String Function(String code)? formatOutput,
List<String> additionalOutputExtensions = const [],
bool allowSyntaxErrors = false,
}) : super(
Expand Down Expand Up @@ -267,9 +256,9 @@ class PartBuilder extends _Builder {
PartBuilder(
List<Generator> generators,
String generatedExtension, {
String Function(String code) formatOutput,
String Function(String code)? formatOutput,
List<String> additionalOutputExtensions = const [],
String header,
String? header,
bool allowSyntaxErrors = false,
}) : super(
generators,
Expand Down Expand Up @@ -307,10 +296,10 @@ class LibraryBuilder extends _Builder {
/// libraries.
LibraryBuilder(
Generator generator, {
String Function(String code) formatOutput,
String Function(String code)? formatOutput,
String generatedExtension = '.g.dart',
List<String> additionalOutputExtensions = const [],
String header,
String? header,
bool allowSyntaxErrors = false,
}) : super(
[generator],
Expand Down Expand Up @@ -359,7 +348,8 @@ Future<bool> _hasAnyTopLevelAnnotations(
if (directive.metadata.isNotEmpty) return true;
if (directive is PartDirective) {
partIds.add(
AssetId.resolve(Uri.parse(directive.uri.stringValue), from: input));
AssetId.resolve(Uri.parse(directive.uri.stringValue!), from: input),
);
}
}
for (var declaration in parsed.declarations) {
Expand Down
Loading