Skip to content

Fixes for CombiningBuilder #348

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
Jun 18, 2018
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
16 changes: 13 additions & 3 deletions source_gen/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,22 @@ class _Builder extends Builder {
'Consider adding the following to your source file:\n\n'
'library $suggest;');
}
final part = computePartUrl(buildStep.inputId, outputId);
contentBuffer.writeln();

String part;
if (_outputPartOf) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. These variable names are confusing and not indicative in what we are using them for.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right...but is this PR okay otherwise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping you'd fix it in this one.

contentBuffer.writeln('part of $name;');
part = computePartUrl(buildStep.inputId, outputId);
} else {
assert(_generatedExtension.endsWith('.g.part'),
'in the SharedPartBuilder flow');
var finalPartId = buildStep.inputId.changeExtension('.g.dart');
part = computePartUrl(buildStep.inputId, finalPartId);
}
if (!library.parts.map((c) => c.uri).contains(part)) {
// TODO: Upgrade to error in a future breaking change?
log.warning('Missing "part \'$part\';".');
}
contentBuffer.writeln();
if (_outputPartOf) contentBuffer.writeln('part of $name;');
}

for (var item in generatedOutputs) {
Expand Down Expand Up @@ -175,6 +184,7 @@ class SharedPartBuilder extends _Builder {
formatOutput: formatOutput,
generatedExtension: '.$partId.g.part',
additionalOutputExtensions: additionalOutputExtensions,
header: '',
outputPartOf: false) {
if (!_partIdRegExp.hasMatch(partId)) {
throw new ArgumentError.value(
Expand Down
47 changes: 30 additions & 17 deletions source_gen/test/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,22 @@ void main() {
});
});

group('ShardPartBilder', () {
group('SharedPartBuilder', () {
test('warns about missing part', () async {
var srcs = _createPackageStub(testLibContent: _testLibContentNoPart);
var builder =
new SharedPartBuilder([const CommentGenerator()], 'comment');
var logs = <String>[];
await testBuilder(
builder,
srcs,
onLog: (log) {
logs.add(log.message);
},
);
expect(logs, ['Missing "part \'test_lib.g.dart\';".']);
});

test('outputs <partId>.g.part files', () async {
await testBuilder(
new SharedPartBuilder(
Expand Down Expand Up @@ -230,23 +245,7 @@ void main() {
decodedMatches(isNot(contains('part of'))),
});
});
});

test('CombiningBuilder includes a generated code header', () async {
await testBuilder(
new CombiningBuilder(),
{
'$_pkgName|lib/a.dart': 'library a; part "a.g.dart";',
'$_pkgName|lib/a.foo.g.part': 'some generated content'
},
generateFor: new Set.from(['$_pkgName|lib/a.dart']),
outputs: {
'$_pkgName|lib/a.g.dart': decodedMatches(
startsWith('// GENERATED CODE - DO NOT MODIFY BY HAND')),
});
});

group('ShardPartBilder', () {
group('constructor', () {
for (var entry in {
'starts with `.`': '.foo',
Expand All @@ -269,6 +268,20 @@ void main() {
});

group('CombiningBuilder', () {
test('CombiningBuilder includes a generated code header', () async {
await testBuilder(
new CombiningBuilder(),
{
'$_pkgName|lib/a.dart': 'library a; part "a.g.dart";',
'$_pkgName|lib/a.foo.g.part': 'some generated content'
},
generateFor: new Set.from(['$_pkgName|lib/a.dart']),
outputs: {
'$_pkgName|lib/a.g.dart': decodedMatches(
startsWith('// GENERATED CODE - DO NOT MODIFY BY HAND')),
});
});

test('outputs `.g.dart` files', () async {
await testBuilder(
new CombiningBuilder(),
Expand Down