Skip to content

Commit 370cb2c

Browse files
authored
Remove all use of package:build (#3448)
1 parent 70c2897 commit 370cb2c

16 files changed

+642
-578
lines changed

lib/src/generator/html_resources.g.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// WARNING: This file is auto-generated. Do not edit.
2-
1+
// TODO(srawlins): Generate this code with a simple script. See
2+
// https://github.com/dart-lang/dartdoc/blob/6df872abbdfbbc4fdcfc795c1836e0613c7f6c8b/tool/builder.dart
3+
// for the previous 'package:build' implementation.
34
const List<String> resourceNames = [
45
'docs.dart.js',
56
'docs.dart.js.map',

lib/src/mustachio/annotations.dart

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ class Renderer {
5454
String standardTemplateBasename, {
5555
this.visibleTypes = const {},
5656
}) : standardHtmlTemplate =
57-
'package:dartdoc/templates/html/$standardTemplateBasename.html',
58-
standardMdTemplate =
59-
'package:dartdoc/templates/md/$standardTemplateBasename.md';
57+
'lib/templates/html/$standardTemplateBasename.html',
58+
standardMdTemplate = 'lib/templates/md/$standardTemplateBasename.md';
6059

6160
@visibleForTesting
6261
const Renderer.forTest(
6362
this.name,
6463
this.context,
6564
String standardTemplateBasename, {
6665
this.visibleTypes = const {},
67-
}) : standardHtmlTemplate = 'templates/$standardTemplateBasename.html',
68-
standardMdTemplate = 'templates/$standardTemplateBasename.md';
66+
}) : standardHtmlTemplate =
67+
'test/mustachio/templates/$standardTemplateBasename.html',
68+
standardMdTemplate =
69+
'test/mustachio/templates/$standardTemplateBasename.md';
6970
}
7071

7172
/// A container for a type, [T], which is the type of a context object,
@@ -94,29 +95,28 @@ class RendererSpec {
9495

9596
final String standardMdTemplate;
9697

97-
final Map<TemplateFormat, Uri?> standardTemplateUris;
98+
final Map<TemplateFormat, String?> standardTemplatePaths;
9899

99100
RendererSpec(
100101
this.name,
101102
this.contextType,
102103
this.visibleTypes,
103104
this.standardHtmlTemplate,
104105
this.standardMdTemplate,
105-
) : standardTemplateUris = {
106-
TemplateFormat.html: _parseUriFromAnnotation(standardHtmlTemplate),
107-
TemplateFormat.md: _parseUriFromAnnotation(standardMdTemplate),
106+
) : standardTemplatePaths = {
107+
TemplateFormat.html: standardHtmlTemplate,
108+
TemplateFormat.md: standardMdTemplate,
108109
};
109110

110-
/// Parses a URI from a String which comes from a const annotation object.
111-
///
112-
/// The String value may be the literal value, 'null'.
113-
static Uri? _parseUriFromAnnotation(String unparsed) =>
114-
unparsed == 'null' ? null : Uri.parse(unparsed);
115-
116111
InterfaceElement get contextElement => contextType.element;
117112
}
118113

119114
enum TemplateFormat {
120115
html,
121-
md,
116+
md;
117+
118+
String aotLibraryPath(String base) => switch (this) {
119+
TemplateFormat.html => '$base.aot_renderers_for_html.dart',
120+
TemplateFormat.md => '$base.aot_renderers_for_md.dart',
121+
};
122122
}

lib/src/mustachio/parser.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class MustachioParser {
2424
/// The index of the character currently being parsed.
2525
int _index = 0;
2626

27-
MustachioParser(this.template, Uri url)
27+
MustachioParser(this.template, String path)
2828
: _templateLength = template.length,
29-
_sourceFile = SourceFile.fromString(template, url: url);
29+
_sourceFile = SourceFile.fromString(template, url: path);
3030

3131
/// Parses [template] into a sequence of [MustachioNode]s.
3232
///

lib/src/mustachio/renderer_base.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Template {
9494
// 2) In the case of a reference from a top-level template, user code has
9595
// called [Template.parse], and the user is responsible for handling the
9696
// exception.
97-
var ast = MustachioParser(file.readAsStringSync(), file.toUri()).parse();
97+
var ast = MustachioParser(file.readAsStringSync(), file.path).parse();
9898
var nodeQueue = Queue.of(ast);
9999
var partials = <String, File>{};
100100

pubspec.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ dependencies:
2626

2727
dev_dependencies:
2828
async: ^2.11.0
29-
build: ^2.4.0
30-
build_runner: ^2.4.2
31-
build_test: ^2.1.7
32-
build_version: ^2.1.1
3329
code_builder: ^4.4.0
3430
dart_style: ^2.3.1
3531
grinder: ^0.9.4

test/mustachio/aot_compiler_builder_test.dart

Lines changed: 66 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,18 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
@Timeout.factor(4)
6-
import 'dart:convert';
7-
import 'package:analyzer/dart/element/element.dart';
8-
import 'package:build/build.dart';
9-
import 'package:build_test/build_test.dart';
5+
@TestOn('vm && !windows')
6+
library;
7+
8+
import 'dart:io';
109
import 'package:test/test.dart';
10+
import 'package:test_descriptor/test_descriptor.dart' as d;
1111

1212
import 'builder_test_base.dart';
1313

1414
void main() {
15-
late InMemoryAssetWriter writer;
16-
17-
Future<LibraryElement> resolveGeneratedLibrary() async {
18-
var rendererAsset = AssetId('foo', 'lib/foo.aot_renderers_for_html.dart');
19-
var writtenStrings = writer.assets
20-
.map((id, content) => MapEntry(id.toString(), utf8.decode(content)));
21-
return await resolveSources(writtenStrings,
22-
(Resolver resolver) => resolver.libraryFor(rendererAsset));
23-
}
24-
25-
setUp(() {
26-
writer = InMemoryAssetWriter();
27-
});
28-
2915
test('builds renderers from multiple annotations', () async {
3016
await testMustachioBuilder(
31-
writer,
3217
'''
3318
class Foo {
3419
String s1 = 'hello';
@@ -40,14 +25,17 @@ class Baz {}
4025
@Renderer(#renderFoo, Context<Foo>(), 'foo')
4126
@Renderer(#renderBar, Context<Bar>(), 'bar')
4227
library foo;
43-
import 'package:mustachio/annotations.dart';
28+
import 'annotations.dart';
4429
''',
45-
additionalAssets: {
46-
'foo|lib/templates/html/foo.html': '{{ >foo_header }}',
47-
'foo|lib/templates/html/_foo_header.html': 'EMPTY',
48-
},
30+
additionalAssets: () => [
31+
d.dir('lib/templates/html', [
32+
d.file('foo.html', '{{ >foo_header }}'),
33+
d.file('_foo_header.html', 'EMPTY'),
34+
]),
35+
],
4936
);
50-
var renderersLibrary = await resolveGeneratedLibrary();
37+
var renderersLibrary =
38+
await resolveGeneratedLibrary(aotRenderersForHtmlPath);
5139

5240
expect(renderersLibrary.getTopLevelFunction('renderFoo'), isNotNull);
5341
expect(renderersLibrary.getTopLevelFunction('renderBar'), isNotNull);
@@ -57,24 +45,33 @@ import 'package:mustachio/annotations.dart';
5745
}, timeout: Timeout.factor(2));
5846

5947
test('builds a public API render function', () async {
60-
await testMustachioBuilder(writer, '''
48+
await testMustachioBuilder(
49+
'''
6150
class Foo<T> {
6251
String s1 = 'hello';
6352
}
64-
''', libraryFrontMatter: '''
53+
''',
54+
libraryFrontMatter: '''
6555
@Renderer(#renderFoo, Context<Foo>(), 'foo')
6656
library foo;
67-
import 'package:mustachio/annotations.dart';
68-
''');
69-
var rendererAsset = AssetId('foo', 'lib/foo.aot_renderers_for_html.dart');
70-
var generatedContent = utf8.decode(writer.assets[rendererAsset]!);
57+
import 'annotations.dart';
58+
''',
59+
additionalAssets: () => [
60+
d.dir('lib/templates/html', [
61+
d.file('foo.html', 's1 is {{ s1 }}'),
62+
]),
63+
d.dir('md', [
64+
d.file('foo.md', 's1 is {{ s1 }}'),
65+
]),
66+
],
67+
);
68+
var generatedContent = await File(aotRenderersForHtmlPath).readAsString();
7169
expect(
7270
generatedContent, contains('String renderFoo<T>(_i1.Foo<T> context0)'));
7371
});
7472

7573
test('builds a private render function for a partial', () async {
7674
await testMustachioBuilder(
77-
writer,
7875
'''
7976
class Foo<T> {
8077
String s1 = 'hello';
@@ -83,30 +80,36 @@ class Foo<T> {
8380
libraryFrontMatter: '''
8481
@Renderer(#renderFoo, Context<Foo>(), 'foo')
8582
library foo;
86-
import 'package:mustachio/annotations.dart';
83+
import 'annotations.dart';
8784
''',
88-
additionalAssets: {
89-
'foo|lib/templates/html/foo.html': '{{ >foo_header }}',
90-
'foo|lib/templates/html/_foo_header.html': 's1 is {{ s1 }}',
91-
},
85+
additionalAssets: () => [
86+
d.dir('lib', [
87+
d.dir('templates', [
88+
d.dir('html', [
89+
d.file('foo.html', '{{ >foo_header }}'),
90+
d.file('_foo_header.html', 's1 is {{ s1 }}'),
91+
]),
92+
]),
93+
]),
94+
],
9295
);
93-
var rendererAsset = AssetId('foo', 'lib/foo.aot_renderers_for_html.dart');
94-
var generatedContent = utf8.decode(writer.assets[rendererAsset]!);
96+
var generatedContent = await File(aotRenderersForHtmlPath).readAsString();
9597
expect(
9698
generatedContent,
9799
contains(
98100
'String _renderFoo_partial_foo_header_0<T>(_i1.Foo<T> context0)'));
99101
});
100102

101103
test('builds a renderer for a generic, bounded type', () async {
102-
await testMustachioBuilder(writer, '''
104+
await testMustachioBuilder('''
103105
class Foo<T extends num> {
104106
String s1 = 'hello';
105107
}
106108
class Bar {}
107109
class Baz {}
108110
''');
109-
var renderersLibrary = await resolveGeneratedLibrary();
111+
var renderersLibrary =
112+
await resolveGeneratedLibrary(aotRenderersForHtmlPath);
110113

111114
var fooRenderFunction = renderersLibrary.getTopLevelFunction('renderFoo')!;
112115
expect(fooRenderFunction.typeParameters, hasLength(1));
@@ -116,7 +119,6 @@ class Baz {}
116119

117120
test('deduplicates partials which share context type LUB', () async {
118121
await testMustachioBuilder(
119-
writer,
120122
'''
121123
abstract class Base {
122124
String get s1;
@@ -136,16 +138,17 @@ class Bar implements Base {
136138
@Renderer(#renderFoo, Context<Foo>(), 'foo')
137139
@Renderer(#renderBar, Context<Bar>(), 'bar')
138140
library foo;
139-
import 'package:mustachio/annotations.dart';
141+
import 'annotations.dart';
140142
''',
141-
additionalAssets: {
142-
'foo|lib/templates/html/foo.html': '{{ >base }}',
143-
'foo|lib/templates/html/bar.html': '{{ >base }}',
144-
'foo|lib/templates/html/_base.html': 's1 is {{ s1 }}',
145-
},
143+
additionalAssets: () => [
144+
d.dir('lib/templates/html', [
145+
d.file('foo.html', '{{ >base }}'),
146+
d.file('bar.html', '{{ >base }}'),
147+
d.file('_base.html', 's1 is {{ s1 }}'),
148+
]),
149+
],
146150
);
147-
var rendererAsset = AssetId('foo', 'lib/foo.aot_renderers_for_html.dart');
148-
var generatedContent = utf8.decode(writer.assets[rendererAsset]!);
151+
var generatedContent = await File(aotRenderersForHtmlPath).readAsString();
149152
expect(
150153
generatedContent,
151154
contains('String _renderFoo_partial_base_0(_i1.Foo context0) =>\n'
@@ -165,7 +168,6 @@ import 'package:mustachio/annotations.dart';
165168
test('does not deduplicate partials when attempting to do so throws',
166169
() async {
167170
await testMustachioBuilder(
168-
writer,
169171
'''
170172
abstract class Base {}
171173
@@ -183,16 +185,17 @@ class Bar implements Base {
183185
@Renderer(#renderFoo, Context<Foo>(), 'foo')
184186
@Renderer(#renderBar, Context<Bar>(), 'bar')
185187
library foo;
186-
import 'package:mustachio/annotations.dart';
188+
import 'annotations.dart';
187189
''',
188-
additionalAssets: {
189-
'foo|lib/templates/html/foo.html': '{{ >base }}',
190-
'foo|lib/templates/html/bar.html': '{{ >base }}',
191-
'foo|lib/templates/html/_base.html': 's1 is {{ s1 }}',
192-
},
190+
additionalAssets: () => [
191+
d.dir('lib/templates/html', [
192+
d.file('foo.html', '{{ >base }}'),
193+
d.file('bar.html', '{{ >base }}'),
194+
d.file('_base.html', 's1 is {{ s1 }}'),
195+
]),
196+
],
193197
);
194-
var rendererAsset = AssetId('foo', 'lib/foo.aot_renderers_for_html.dart');
195-
var generatedContent = utf8.decode(writer.assets[rendererAsset]!);
198+
var generatedContent = await File(aotRenderersForHtmlPath).readAsString();
196199
expect(
197200
generatedContent,
198201
contains('String _renderFoo_partial_base_0(_i1.Foo context0) {'),
@@ -203,3 +206,6 @@ import 'package:mustachio/annotations.dart';
203206
);
204207
});
205208
}
209+
210+
String get aotRenderersForHtmlPath =>
211+
'${d.sandbox}/foo_package/lib/foo.aot_renderers_for_html.dart';

0 commit comments

Comments
 (0)