Skip to content

Commit 0fbd992

Browse files
committed
Builds / serves multiple HTML files.
With this, I can build multiple Angular samples simultaneously: [dist/dart/playground/build/web] dart ~/git/dev_compiler/bin/dartdevc.dart -o /tmp/ddc-out --force-compile src/*/index.html Fixes #430 [email protected] Review URL: https://codereview.chromium.org/1645343002 .
1 parent cf6bca8 commit 0fbd992

File tree

15 files changed

+107
-2322
lines changed

15 files changed

+107
-2322
lines changed

pkg/dev_compiler/lib/src/codegen/html_codegen.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ String generateEntryHtml(HtmlSourceNode root, AbstractCompiler compiler) {
6868
}
6969
});
7070

71+
var rootDir = path.dirname(root.uri.path);
72+
String rootRelative(String fullPath) {
73+
return path.relative(path.join(compiler.inputBaseDir, fullPath),
74+
from: rootDir);
75+
}
76+
7177
var fragment = new DocumentFragment();
7278
for (var resource in resources) {
73-
var resourcePath =
74-
resourceOutputPath(resource.uri, root.uri, options.runtimeDir);
79+
var resourcePath = rootRelative(
80+
resourceOutputPath(resource.uri, root.uri, options.runtimeDir));
7581
var ext = path.extension(resourcePath);
7682
if (resource.cachingHash != null) {
7783
resourcePath = _addHash(resourcePath, resource.cachingHash);
@@ -92,7 +98,7 @@ String generateEntryHtml(HtmlSourceNode root, AbstractCompiler compiler) {
9298
var info = lib.info;
9399
if (info == null) continue;
94100
var uri = info.library.source.uri;
95-
var jsPath = compiler.getModulePath(uri);
101+
var jsPath = rootRelative(compiler.getModulePath(uri));
96102
if (uri == scriptUri) mainLibraryName = compiler.getModuleName(uri);
97103
if (lib.cachingHash != null) {
98104
jsPath = _addHash(jsPath, lib.cachingHash);

pkg/dev_compiler/lib/src/compiler.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ class BatchCompiler extends AbstractCompiler {
304304
}
305305
}
306306

307-
new File(getOutputPath(source.uri)).openSync(mode: FileMode.WRITE)
308-
..writeStringSync(document.outerHtml)
309-
..writeStringSync('\n')
310-
..closeSync();
307+
var outputFile = getOutputPath(source.uri);
308+
new File(outputFile)
309+
..createSync(recursive: true)
310+
..writeAsStringSync(document.outerHtml + '\n');
311311
}
312312

313313
html.DocumentFragment _linkLibraries(

pkg/dev_compiler/lib/src/options.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ CompilerOptions parseOptions(List<String> argv, {bool forceOutDir: false}) {
233233
customUrlMappings[splitMapping[0]] = splitMapping[1];
234234
}
235235

236-
if (serverMode && args.rest.length != 1) showUsage = true;
237-
238236
return new CompilerOptions(
239237
codegenOptions: new CodegenOptions(
240238
emitSourceMaps: args['source-maps'],

pkg/dev_compiler/lib/src/server/dependency_graph.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,22 @@ abstract class SourceNode {
156156
}
157157
}
158158

159+
/// A unique node representing all entry points in the graph. This is just for
160+
/// graph algorthm convenience.
161+
class EntryNode extends SourceNode {
162+
final Iterable<SourceNode> entryPoints;
163+
164+
@override
165+
Iterable<SourceNode> get allDeps => entryPoints;
166+
167+
@override
168+
Iterable<SourceNode> get depsWithoutParts => entryPoints;
169+
170+
EntryNode(SourceGraph graph, Uri uri, Iterable<SourceNode> nodes)
171+
: entryPoints = nodes,
172+
super(graph, uri, null);
173+
}
174+
159175
/// A node representing an entry HTML source file.
160176
class HtmlSourceNode extends SourceNode {
161177
/// Resources included by default on any application.
@@ -466,7 +482,7 @@ rebuild(SourceNode start, bool build(SourceNode node)) {
466482
bool shouldBuildNode(SourceNode n) {
467483
if (n.needsRebuild) return true;
468484
if (n is HtmlSourceNode) return htmlNeedsRebuild;
469-
if (n is ResourceSourceNode) return false;
485+
if (n is ResourceSourceNode || n is EntryNode) return false;
470486
return (n as DartSourceNode)
471487
.imports
472488
.any((i) => apiChangeDetected.contains(i));

pkg/dev_compiler/lib/src/server/server.dart

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import 'dependency_graph.dart';
3636

3737
/// Encapsulates the logic when the compiler is run as a development server.
3838
class ServerCompiler extends AbstractCompiler {
39-
final SourceNode _entryNode;
39+
SourceNode _entryNode;
4040
List<LibraryInfo> _libraries = <LibraryInfo>[];
4141
final _generators = <CodeGenerator>[];
4242
bool _hashing;
@@ -45,31 +45,37 @@ class ServerCompiler extends AbstractCompiler {
4545
factory ServerCompiler(AnalysisContext context, CompilerOptions options,
4646
{AnalysisErrorListener reporter}) {
4747
var srcOpts = options.sourceOptions;
48-
var inputFile = options.inputs[0];
49-
var inputUri =
48+
var inputFiles = options.inputs;
49+
var inputUris = inputFiles.map((String inputFile) =>
5050
inputFile.startsWith('dart:') || inputFile.startsWith('package:')
5151
? Uri.parse(inputFile)
5252
: new Uri.file(path.absolute(srcOpts.useImplicitHtml
5353
? SourceResolverOptions.implicitHtmlFile
54-
: inputFile));
54+
: inputFile)));
5555
var graph = new SourceGraph(context, reporter, options);
56-
var entryNode = graph.nodeFromUri(inputUri);
56+
var entryNodes = inputUris.map((inputUri) => graph.nodeFromUri(inputUri));
5757

58-
return new ServerCompiler._(context, options, reporter, entryNode);
58+
return new ServerCompiler._(context, options, reporter, graph, entryNodes);
5959
}
6060

61-
ServerCompiler._(AnalysisContext context, CompilerOptions options,
62-
AnalysisErrorListener reporter, this._entryNode)
61+
ServerCompiler._(
62+
AnalysisContext context,
63+
CompilerOptions options,
64+
AnalysisErrorListener reporter,
65+
SourceGraph graph,
66+
List<SourceNode> entryNodes)
6367
: super(context, options, reporter) {
68+
_entryNode = entryNodes.length == 1
69+
? entryNodes.first
70+
: new EntryNode(graph, new Uri.file(inputBaseDir), entryNodes);
71+
6472
if (outputDir != null) {
6573
_generators.add(new JSGenerator(this));
6674
}
6775
// TODO(sigmund): refactor to support hashing of the dart output?
6876
_hashing = options.enableHashing && _generators.length == 1;
6977
}
7078

71-
Uri get entryPointUri => _entryNode.uri;
72-
7379
CheckerResults run() {
7480
var clock = new Stopwatch()..start();
7581

@@ -112,9 +118,12 @@ class ServerCompiler extends AbstractCompiler {
112118
return;
113119
}
114120

115-
var filename = path.basename(node.uri.path);
116-
String outputFile = path.join(outputDir, filename);
117-
new File(outputFile).writeAsStringSync(output);
121+
var filepath =
122+
resourceOutputPath(node.uri, _entryNode.uri, options.runtimeDir);
123+
String outputFile = path.join(outputDir, filepath);
124+
new File(outputFile)
125+
..createSync(recursive: true)
126+
..writeAsStringSync(output);
118127
}
119128

120129
void _buildResourceFile(ResourceSourceNode node) {

pkg/dev_compiler/lib/src/utils.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,12 @@ String resourceOutputPath(Uri resourceUri, Uri entryUri, String runtimeDir) {
314314

315315
if (resourceUri.scheme != 'file') return null;
316316

317-
var entryDir = path.dirname(entryUri.path);
317+
var entryPath = entryUri.path;
318+
// The entry uri is either a directory or a dart/html file. If the latter,
319+
// trim the file.
320+
var entryDir = entryPath.endsWith('.dart') || entryPath.endsWith('.html')
321+
? path.dirname(entryPath)
322+
: entryPath;
318323
var filepath = path.normalize(path.join(entryDir, resourceUri.path));
319324
if (path.isWithin(runtimeDir, filepath)) {
320325
filepath = path.relative(filepath, from: runtimeDir);
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
11
// Messages from compiling equality.dart
2-
severe: [AnalyzerMessage] The redirected constructor '() → DefaultEquality' has incompatible parameters with '() → Equality<E>' (package:collection/equality.dart, line 18, col 30)
3-
severe: [STATIC_TYPE_ERROR] Type check failed: const DefaultEquality() (DefaultEquality) is not of type Equality<E> because const DefaultEquality() cannot be typed as Equality<E> (package:collection/equality.dart, line 75, col 31)
4-
severe: [STATIC_TYPE_ERROR] Type check failed: const DefaultEquality() (DefaultEquality) is not of type Equality<E> because const DefaultEquality() cannot be typed as Equality<E> (package:collection/equality.dart, line 120, col 53)
5-
severe: [STATIC_TYPE_ERROR] Type check failed: const DefaultEquality() (DefaultEquality) is not of type Equality<E> because const DefaultEquality() cannot be typed as Equality<E> (package:collection/equality.dart, line 205, col 38)
6-
severe: [STATIC_TYPE_ERROR] Type check failed: const DefaultEquality() (DefaultEquality) is not of type Equality<E> because const DefaultEquality() cannot be typed as Equality<E> (package:collection/equality.dart, line 223, col 38)
7-
severe: [STATIC_TYPE_ERROR] Type check failed: const DefaultEquality() (DefaultEquality) is not of type Equality<K> because const DefaultEquality() cannot be typed as Equality<K> (package:collection/equality.dart, line 263, col 42)
8-
severe: [STATIC_TYPE_ERROR] Type check failed: const DefaultEquality() (DefaultEquality) is not of type Equality<V> because const DefaultEquality() cannot be typed as Equality<V> (package:collection/equality.dart, line 264, col 44)
9-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to E (package:collection/equality.dart, line 87, col 36)
10-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to E (package:collection/equality.dart, line 87, col 49)

pkg/dev_compiler/test/codegen/expect/collection/src/canonicalized_map.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ dart_library.library('collection/src/canonicalized_map', null, /* Imports */[
3232
return pair == null ? null : pair.last;
3333
}
3434
set(key, value) {
35-
dart.as(key, K);
36-
dart.as(value, V);
37-
this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new (utils.Pair$(K, V))(key, value));
35+
(() => {
36+
dart.as(key, K);
37+
dart.as(value, V);
38+
if (!dart.notNull(this[_isValidKey](key))) return;
39+
this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new (utils.Pair$(K, V))(key, value));
40+
})();
3841
return value;
3942
}
4043
addAll(other) {
@@ -62,7 +65,7 @@ dart_library.library('collection/src/canonicalized_map', null, /* Imports */[
6265
return this[_base].isNotEmpty;
6366
}
6467
get keys() {
65-
return dart.as(this[_base].values[dartx.map](dart.fn(pair => pair.first, K, [utils.Pair$(K, V)])), core.Iterable$(K));
68+
return this[_base].values[dartx.map](dart.fn(pair => pair.first, K, [utils.Pair$(K, V)]));
6669
}
6770
get length() {
6871
return this[_base].length;
@@ -78,7 +81,7 @@ dart_library.library('collection/src/canonicalized_map', null, /* Imports */[
7881
return pair == null ? null : pair.last;
7982
}
8083
get values() {
81-
return dart.as(this[_base].values[dartx.map](dart.fn(pair => pair.last, V, [utils.Pair$(K, V)])), core.Iterable$(V));
84+
return this[_base].values[dartx.map](dart.fn(pair => pair.last, V, [utils.Pair$(K, V)]));
8285
}
8386
toString() {
8487
return collection.Maps.mapToString(this);
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
// Messages from compiling canonicalized_map.dart
2-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to C (package:collection/src/canonicalized_map.dart, line 67, col 11)
3-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<dynamic> to Iterable<K> (package:collection/src/canonicalized_map.dart, line 94, col 27)
4-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to C (package:collection/src/canonicalized_map.dart, line 99, col 30)
5-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<dynamic> to Iterable<V> (package:collection/src/canonicalized_map.dart, line 109, col 29)
2+
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to C (package:collection/src/canonicalized_map.dart, line 61, col 11)
3+
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to C (package:collection/src/canonicalized_map.dart, line 93, col 30)
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Messages from compiling queue_list.dart
2-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<E> to List<dynamic> (package:collection/src/queue_list.dart, line 44, col 25)
3-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 45, col 40)
4-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<E> to List<dynamic> (package:collection/src/queue_list.dart, line 61, col 19)
2+
severe: [INVALID_METHOD_OVERRIDE] Mixin introduces an invalid override. The type of ListMixin.expand (((E) → Iterable<dynamic>) → Iterable<dynamic>) is not a subtype of Iterable<E>.expand (<T>((E) → Iterable<T>) → Iterable<T>). (package:collection/src/queue_list.dart, line 12, col 40)
3+
severe: [INVALID_METHOD_OVERRIDE] Mixin introduces an invalid override. The type of ListMixin.map (((E) → dynamic) → Iterable<dynamic>) is not a subtype of Iterable<E>.map (<T>((E) → T) → Iterable<T>). (package:collection/src/queue_list.dart, line 12, col 40)
4+
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<E> to List<dynamic> (package:collection/src/queue_list.dart, line 38, col 25)
5+
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 39, col 40)
6+
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<E> to List<dynamic> (package:collection/src/queue_list.dart, line 55, col 19)
7+
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 61, col 52)
58
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 67, col 52)
6-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 73, col 52)
7-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 77, col 52)
8-
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 78, col 40)
9+
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 71, col 52)
10+
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 72, col 40)

0 commit comments

Comments
 (0)