Skip to content

Commit

Permalink
Builds / serves multiple HTML files.
Browse files Browse the repository at this point in the history
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 .
  • Loading branch information
vsmenon committed Jan 29, 2016
1 parent cf6bca8 commit 0fbd992
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 2,322 deletions.
12 changes: 9 additions & 3 deletions pkg/dev_compiler/lib/src/codegen/html_codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ String generateEntryHtml(HtmlSourceNode root, AbstractCompiler compiler) {
}
});

var rootDir = path.dirname(root.uri.path);
String rootRelative(String fullPath) {
return path.relative(path.join(compiler.inputBaseDir, fullPath),
from: rootDir);
}

var fragment = new DocumentFragment();
for (var resource in resources) {
var resourcePath =
resourceOutputPath(resource.uri, root.uri, options.runtimeDir);
var resourcePath = rootRelative(
resourceOutputPath(resource.uri, root.uri, options.runtimeDir));
var ext = path.extension(resourcePath);
if (resource.cachingHash != null) {
resourcePath = _addHash(resourcePath, resource.cachingHash);
Expand All @@ -92,7 +98,7 @@ String generateEntryHtml(HtmlSourceNode root, AbstractCompiler compiler) {
var info = lib.info;
if (info == null) continue;
var uri = info.library.source.uri;
var jsPath = compiler.getModulePath(uri);
var jsPath = rootRelative(compiler.getModulePath(uri));
if (uri == scriptUri) mainLibraryName = compiler.getModuleName(uri);
if (lib.cachingHash != null) {
jsPath = _addHash(jsPath, lib.cachingHash);
Expand Down
8 changes: 4 additions & 4 deletions pkg/dev_compiler/lib/src/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ class BatchCompiler extends AbstractCompiler {
}
}

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

html.DocumentFragment _linkLibraries(
Expand Down
2 changes: 0 additions & 2 deletions pkg/dev_compiler/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ CompilerOptions parseOptions(List<String> argv, {bool forceOutDir: false}) {
customUrlMappings[splitMapping[0]] = splitMapping[1];
}

if (serverMode && args.rest.length != 1) showUsage = true;

return new CompilerOptions(
codegenOptions: new CodegenOptions(
emitSourceMaps: args['source-maps'],
Expand Down
18 changes: 17 additions & 1 deletion pkg/dev_compiler/lib/src/server/dependency_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ abstract class SourceNode {
}
}

/// A unique node representing all entry points in the graph. This is just for
/// graph algorthm convenience.
class EntryNode extends SourceNode {
final Iterable<SourceNode> entryPoints;

@override
Iterable<SourceNode> get allDeps => entryPoints;

@override
Iterable<SourceNode> get depsWithoutParts => entryPoints;

EntryNode(SourceGraph graph, Uri uri, Iterable<SourceNode> nodes)
: entryPoints = nodes,
super(graph, uri, null);
}

/// A node representing an entry HTML source file.
class HtmlSourceNode extends SourceNode {
/// Resources included by default on any application.
Expand Down Expand Up @@ -466,7 +482,7 @@ rebuild(SourceNode start, bool build(SourceNode node)) {
bool shouldBuildNode(SourceNode n) {
if (n.needsRebuild) return true;
if (n is HtmlSourceNode) return htmlNeedsRebuild;
if (n is ResourceSourceNode) return false;
if (n is ResourceSourceNode || n is EntryNode) return false;
return (n as DartSourceNode)
.imports
.any((i) => apiChangeDetected.contains(i));
Expand Down
35 changes: 22 additions & 13 deletions pkg/dev_compiler/lib/src/server/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import 'dependency_graph.dart';

/// Encapsulates the logic when the compiler is run as a development server.
class ServerCompiler extends AbstractCompiler {
final SourceNode _entryNode;
SourceNode _entryNode;
List<LibraryInfo> _libraries = <LibraryInfo>[];
final _generators = <CodeGenerator>[];
bool _hashing;
Expand All @@ -45,31 +45,37 @@ class ServerCompiler extends AbstractCompiler {
factory ServerCompiler(AnalysisContext context, CompilerOptions options,
{AnalysisErrorListener reporter}) {
var srcOpts = options.sourceOptions;
var inputFile = options.inputs[0];
var inputUri =
var inputFiles = options.inputs;
var inputUris = inputFiles.map((String inputFile) =>
inputFile.startsWith('dart:') || inputFile.startsWith('package:')
? Uri.parse(inputFile)
: new Uri.file(path.absolute(srcOpts.useImplicitHtml
? SourceResolverOptions.implicitHtmlFile
: inputFile));
: inputFile)));
var graph = new SourceGraph(context, reporter, options);
var entryNode = graph.nodeFromUri(inputUri);
var entryNodes = inputUris.map((inputUri) => graph.nodeFromUri(inputUri));

return new ServerCompiler._(context, options, reporter, entryNode);
return new ServerCompiler._(context, options, reporter, graph, entryNodes);
}

ServerCompiler._(AnalysisContext context, CompilerOptions options,
AnalysisErrorListener reporter, this._entryNode)
ServerCompiler._(
AnalysisContext context,
CompilerOptions options,
AnalysisErrorListener reporter,
SourceGraph graph,
List<SourceNode> entryNodes)
: super(context, options, reporter) {
_entryNode = entryNodes.length == 1
? entryNodes.first
: new EntryNode(graph, new Uri.file(inputBaseDir), entryNodes);

if (outputDir != null) {
_generators.add(new JSGenerator(this));
}
// TODO(sigmund): refactor to support hashing of the dart output?
_hashing = options.enableHashing && _generators.length == 1;
}

Uri get entryPointUri => _entryNode.uri;

CheckerResults run() {
var clock = new Stopwatch()..start();

Expand Down Expand Up @@ -112,9 +118,12 @@ class ServerCompiler extends AbstractCompiler {
return;
}

var filename = path.basename(node.uri.path);
String outputFile = path.join(outputDir, filename);
new File(outputFile).writeAsStringSync(output);
var filepath =
resourceOutputPath(node.uri, _entryNode.uri, options.runtimeDir);
String outputFile = path.join(outputDir, filepath);
new File(outputFile)
..createSync(recursive: true)
..writeAsStringSync(output);
}

void _buildResourceFile(ResourceSourceNode node) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/dev_compiler/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,12 @@ String resourceOutputPath(Uri resourceUri, Uri entryUri, String runtimeDir) {

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

var entryDir = path.dirname(entryUri.path);
var entryPath = entryUri.path;
// The entry uri is either a directory or a dart/html file. If the latter,
// trim the file.
var entryDir = entryPath.endsWith('.dart') || entryPath.endsWith('.html')
? path.dirname(entryPath)
: entryPath;
var filepath = path.normalize(path.join(entryDir, resourceUri.path));
if (path.isWithin(runtimeDir, filepath)) {
filepath = path.relative(filepath, from: runtimeDir);
Expand Down
9 changes: 0 additions & 9 deletions pkg/dev_compiler/test/codegen/expect/collection/equality.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
// Messages from compiling equality.dart
severe: [AnalyzerMessage] The redirected constructor '() → DefaultEquality' has incompatible parameters with '() → Equality<E>' (package:collection/equality.dart, line 18, col 30)
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)
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)
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)
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)
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)
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)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to E (package:collection/equality.dart, line 87, col 36)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to E (package:collection/equality.dart, line 87, col 49)
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ dart_library.library('collection/src/canonicalized_map', null, /* Imports */[
return pair == null ? null : pair.last;
}
set(key, value) {
dart.as(key, K);
dart.as(value, V);
this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new (utils.Pair$(K, V))(key, value));
(() => {
dart.as(key, K);
dart.as(value, V);
if (!dart.notNull(this[_isValidKey](key))) return;
this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new (utils.Pair$(K, V))(key, value));
})();
return value;
}
addAll(other) {
Expand Down Expand Up @@ -62,7 +65,7 @@ dart_library.library('collection/src/canonicalized_map', null, /* Imports */[
return this[_base].isNotEmpty;
}
get keys() {
return dart.as(this[_base].values[dartx.map](dart.fn(pair => pair.first, K, [utils.Pair$(K, V)])), core.Iterable$(K));
return this[_base].values[dartx.map](dart.fn(pair => pair.first, K, [utils.Pair$(K, V)]));
}
get length() {
return this[_base].length;
Expand All @@ -78,7 +81,7 @@ dart_library.library('collection/src/canonicalized_map', null, /* Imports */[
return pair == null ? null : pair.last;
}
get values() {
return dart.as(this[_base].values[dartx.map](dart.fn(pair => pair.last, V, [utils.Pair$(K, V)])), core.Iterable$(V));
return this[_base].values[dartx.map](dart.fn(pair => pair.last, V, [utils.Pair$(K, V)]));
}
toString() {
return collection.Maps.mapToString(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Messages from compiling canonicalized_map.dart
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to C (package:collection/src/canonicalized_map.dart, line 67, col 11)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<dynamic> to Iterable<K> (package:collection/src/canonicalized_map.dart, line 94, col 27)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to C (package:collection/src/canonicalized_map.dart, line 99, col 30)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<dynamic> to Iterable<V> (package:collection/src/canonicalized_map.dart, line 109, col 29)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to C (package:collection/src/canonicalized_map.dart, line 61, col 11)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from dynamic to C (package:collection/src/canonicalized_map.dart, line 93, col 30)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Messages from compiling queue_list.dart
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<E> to List<dynamic> (package:collection/src/queue_list.dart, line 44, col 25)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 45, col 40)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<E> to List<dynamic> (package:collection/src/queue_list.dart, line 61, col 19)
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)
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)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<E> to List<dynamic> (package:collection/src/queue_list.dart, line 38, col 25)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 39, col 40)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from Iterable<E> to List<dynamic> (package:collection/src/queue_list.dart, line 55, col 19)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 61, col 52)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 67, col 52)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 73, col 52)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 77, col 52)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 78, col 40)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 71, col 52)
warning: [DOWN_CAST_COMPOSITE] Unsound implicit cast from List<dynamic> to Iterable<E> (package:collection/src/queue_list.dart, line 72, col 40)
Loading

0 comments on commit 0fbd992

Please sign in to comment.