Skip to content

Commit cfa6b9b

Browse files
committed
Migrate to null-safety
Closes #493
1 parent e546b16 commit cfa6b9b

33 files changed

+331
-285
lines changed

.github/workflows/dart.yml

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Created with package:mono_repo v3.4.6
1+
# Created with package:mono_repo v3.4.7
22
name: Dart CI
33
on:
44
push:
@@ -27,13 +27,13 @@ jobs:
2727
restore-keys: |
2828
os:ubuntu-latest;pub-cache-hosted
2929
os:ubuntu-latest
30-
- uses: dart-lang/setup-dart@v0.3
30+
- uses: dart-lang/setup-dart@v1.0
3131
with:
3232
sdk: stable
3333
- id: checkout
3434
uses: actions/checkout@v2
3535
- name: mono_repo self validate
36-
run: pub global activate mono_repo 3.4.6
36+
run: pub global activate mono_repo 3.4.7
3737
- name: mono_repo self validate
3838
run: pub global run mono_repo generate --validate
3939
job_002:
@@ -50,7 +50,7 @@ jobs:
5050
os:ubuntu-latest;pub-cache-hosted;dart:dev
5151
os:ubuntu-latest;pub-cache-hosted
5252
os:ubuntu-latest
53-
- uses: dart-lang/setup-dart@v0.3
53+
- uses: dart-lang/setup-dart@v1.0
5454
with:
5555
sdk: dev
5656
- id: checkout
@@ -108,7 +108,7 @@ jobs:
108108
os:ubuntu-latest;pub-cache-hosted;dart:dev
109109
os:ubuntu-latest;pub-cache-hosted
110110
os:ubuntu-latest
111-
- uses: dart-lang/setup-dart@v0.3
111+
- uses: dart-lang/setup-dart@v1.0
112112
with:
113113
sdk: dev
114114
- id: checkout
@@ -140,7 +140,7 @@ jobs:
140140
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
141141
os:ubuntu-latest;pub-cache-hosted
142142
os:ubuntu-latest
143-
- uses: dart-lang/setup-dart@v0.3
143+
- uses: dart-lang/setup-dart@v1.0
144144
with:
145145
sdk: "2.12.0"
146146
- id: checkout
@@ -155,6 +155,39 @@ jobs:
155155
working-directory: source_gen
156156
run: dartanalyzer .
157157
job_005:
158+
name: "unit_test; Dart 2.12.0; PKG: example_usage; `pub run test --run-skipped`"
159+
runs-on: ubuntu-latest
160+
steps:
161+
- name: Cache Pub hosted dependencies
162+
uses: actions/cache@v2
163+
with:
164+
path: "~/.pub-cache/hosted"
165+
key: "os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:example_usage;commands:test_0"
166+
restore-keys: |
167+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0;packages:example_usage
168+
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
169+
os:ubuntu-latest;pub-cache-hosted
170+
os:ubuntu-latest
171+
- uses: dart-lang/[email protected]
172+
with:
173+
sdk: "2.12.0"
174+
- id: checkout
175+
uses: actions/checkout@v2
176+
- id: example_usage_pub_upgrade
177+
name: "example_usage; pub upgrade --no-precompile"
178+
if: "always() && steps.checkout.conclusion == 'success'"
179+
working-directory: example_usage
180+
run: pub upgrade --no-precompile
181+
- name: "example_usage; pub run test --run-skipped"
182+
if: "always() && steps.example_usage_pub_upgrade.conclusion == 'success'"
183+
working-directory: example_usage
184+
run: pub run test --run-skipped
185+
needs:
186+
- job_001
187+
- job_002
188+
- job_003
189+
- job_004
190+
job_006:
158191
name: "unit_test; Dart dev; PKG: example_usage; `pub run test --run-skipped`"
159192
runs-on: ubuntu-latest
160193
steps:
@@ -168,7 +201,7 @@ jobs:
168201
os:ubuntu-latest;pub-cache-hosted;dart:dev
169202
os:ubuntu-latest;pub-cache-hosted
170203
os:ubuntu-latest
171-
- uses: dart-lang/setup-dart@v0.3
204+
- uses: dart-lang/setup-dart@v1.0
172205
with:
173206
sdk: dev
174207
- id: checkout
@@ -187,7 +220,7 @@ jobs:
187220
- job_002
188221
- job_003
189222
- job_004
190-
job_006:
223+
job_007:
191224
name: "unit_test; Dart 2.12.0; PKG: source_gen; `pub run test`"
192225
runs-on: ubuntu-latest
193226
steps:
@@ -201,7 +234,7 @@ jobs:
201234
os:ubuntu-latest;pub-cache-hosted;dart:2.12.0
202235
os:ubuntu-latest;pub-cache-hosted
203236
os:ubuntu-latest
204-
- uses: dart-lang/setup-dart@v0.3
237+
- uses: dart-lang/setup-dart@v1.0
205238
with:
206239
sdk: "2.12.0"
207240
- id: checkout
@@ -220,7 +253,7 @@ jobs:
220253
- job_002
221254
- job_003
222255
- job_004
223-
job_007:
256+
job_008:
224257
name: "unit_test; Dart dev; PKG: source_gen; `pub run test`"
225258
runs-on: ubuntu-latest
226259
steps:
@@ -234,7 +267,7 @@ jobs:
234267
os:ubuntu-latest;pub-cache-hosted;dart:dev
235268
os:ubuntu-latest;pub-cache-hosted
236269
os:ubuntu-latest
237-
- uses: dart-lang/setup-dart@v0.3
270+
- uses: dart-lang/setup-dart@v1.0
238271
with:
239272
sdk: dev
240273
- id: checkout

_test_annotations/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name: _test_annotations
22
environment:
3-
sdk: '>=2.10.0 <3.0.0'
3+
sdk: '>=2.12.0 <3.0.0'

example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: source_gen_example
22

33
environment:
4-
sdk: ">=2.10.0 <3.0.0"
4+
sdk: ">=2.12.0 <3.0.0"
55

66
dependencies:
7-
analyzer: '>=0.42.0-nullsafety <2.0.0'
7+
analyzer: ^1.0.0
88
build: ^2.0.0
99
source_gen: any
1010

example_usage/mono_pkg.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# See https://github.com/google/mono_repo.dart for details
22
dart:
3+
- 2.12.0
34
- dev
45

56
stages:

example_usage/pubspec.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
name: source_gen_example_usage
22

33
environment:
4-
sdk: '>=2.10.0 <3.0.0'
4+
sdk: '>=2.12.0 <3.0.0'
55

66
dev_dependencies:
77
build_runner: ^1.10.3
8-
build_verify: ^1.1.0
8+
build_verify: ^2.0.0
99
source_gen_example:
1010
path: ../example
1111
test: ^1.5.1
1212

1313
dependency_overrides:
14+
# waiting on build_runner to update
15+
dart_style: ^2.0.0
16+
1417
source_gen:
1518
path: ../source_gen

source_gen/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.0.0
2+
3+
- Migrate to null safety.
4+
- Require Dart `2.12.0`.
5+
16
## 0.9.10+4
27

38
* Upgrade to `package:build` version `2.0.0`.

source_gen/lib/builder.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import 'src/utils.dart';
2222
const _outputExtensions = '.g.dart';
2323
const _partFiles = '.g.part';
2424

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

2828
final includePartName = optionsMap.remove('include_part_name') as bool;
2929
final ignoreForFile = Set<String>.from(
30-
optionsMap.remove('ignore_for_file') as List ?? <String>[],
30+
optionsMap.remove('ignore_for_file') as List? ?? <String>[],
3131
);
3232

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

3838
if (optionsMap.isNotEmpty) {
39-
if (log == null) {
40-
throw StateError('Upgrade `build_runner` to at least 0.8.2.');
41-
} else {
42-
log.warning('These options were ignored: `$optionsMap`.');
43-
}
39+
log.warning('These options were ignored: `$optionsMap`.');
4440
}
4541
return builder;
4642
}
@@ -68,8 +64,8 @@ class CombiningBuilder implements Builder {
6864
/// debugging build issues.
6965
const CombiningBuilder({
7066
bool includePartName = false,
71-
Set<String> ignoreForFile,
72-
}) : _includePartName = includePartName ?? false,
67+
Set<String>? ignoreForFile,
68+
}) : _includePartName = includePartName,
7369
_ignoreForFile = ignoreForFile ?? const <String>{};
7470

7571
@override
@@ -89,7 +85,7 @@ class CombiningBuilder implements Builder {
8985
partIdRegExpLiteral, // A valid part ID
9086
RegExp.escape(_partFiles), // the ending part extension
9187
'\$', // end of string
92-
].join(''));
88+
].join());
9389

9490
final assetIds = await buildStep
9591
.findAssets(Glob(pattern))

source_gen/lib/src/builder.dart

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class _Builder extends Builder {
4141
/// Wrap [_generators] to form a [Builder]-compatible API.
4242
_Builder(
4343
this._generators, {
44-
String Function(String code) formatOutput,
44+
String Function(String code)? formatOutput,
4545
String generatedExtension = '.g.dart',
4646
List<String> additionalOutputExtensions = const [],
47-
String header,
47+
String? header,
4848
this.allowSyntaxErrors = false,
4949
}) : _generatedExtension = generatedExtension,
5050
buildExtensions = {
@@ -55,9 +55,6 @@ class _Builder extends Builder {
5555
},
5656
formatOutput = formatOutput ?? _formatter.format,
5757
_header = (header ?? defaultFileHeader).trim() {
58-
if (_generatedExtension == null) {
59-
throw ArgumentError.notNull('generatedExtension');
60-
}
6158
if (_generatedExtension.isEmpty || !_generatedExtension.startsWith('.')) {
6259
throw ArgumentError.value(_generatedExtension, 'generatedExtension',
6360
'Extension must be in the format of .*');
@@ -109,14 +106,6 @@ class _Builder extends Builder {
109106
if (!_isLibraryBuilder) {
110107
final asset = buildStep.inputId;
111108
final name = nameOfPartial(library, asset);
112-
if (name == null) {
113-
final suggest = suggestLibraryName(asset);
114-
throw InvalidGenerationSourceError(
115-
'Could not find library identifier so a "part of" cannot be built.',
116-
todo: ''
117-
'Consider adding the following to your source file:\n\n'
118-
'library $suggest;');
119-
}
120109
contentBuffer.writeln();
121110

122111
String part;
@@ -212,7 +201,7 @@ class SharedPartBuilder extends _Builder {
212201
SharedPartBuilder(
213202
List<Generator> generators,
214203
String partId, {
215-
String Function(String code) formatOutput,
204+
String Function(String code)? formatOutput,
216205
List<String> additionalOutputExtensions = const [],
217206
bool allowSyntaxErrors = false,
218207
}) : super(
@@ -267,9 +256,9 @@ class PartBuilder extends _Builder {
267256
PartBuilder(
268257
List<Generator> generators,
269258
String generatedExtension, {
270-
String Function(String code) formatOutput,
259+
String Function(String code)? formatOutput,
271260
List<String> additionalOutputExtensions = const [],
272-
String header,
261+
String? header,
273262
bool allowSyntaxErrors = false,
274263
}) : super(
275264
generators,
@@ -307,10 +296,10 @@ class LibraryBuilder extends _Builder {
307296
/// libraries.
308297
LibraryBuilder(
309298
Generator generator, {
310-
String Function(String code) formatOutput,
299+
String Function(String code)? formatOutput,
311300
String generatedExtension = '.g.dart',
312301
List<String> additionalOutputExtensions = const [],
313-
String header,
302+
String? header,
314303
bool allowSyntaxErrors = false,
315304
}) : super(
316305
[generator],
@@ -359,7 +348,8 @@ Future<bool> _hasAnyTopLevelAnnotations(
359348
if (directive.metadata.isNotEmpty) return true;
360349
if (directive is PartDirective) {
361350
partIds.add(
362-
AssetId.resolve(Uri.parse(directive.uri.stringValue), from: input));
351+
AssetId.resolve(Uri.parse(directive.uri.stringValue!), from: input),
352+
);
363353
}
364354
}
365355
for (var declaration in parsed.declarations) {

0 commit comments

Comments
 (0)