Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: lib/src/dependency_graph.dart

Issue 1014173002: Copy resources refered to in the HTML to the output folder (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Tracks the shape of the import/export graph and dependencies between files. 5 /// Tracks the shape of the import/export graph and dependencies between files.
6 library dev_compiler.src.dependency_graph; 6 library dev_compiler.src.dependency_graph;
7 7
8 import 'dart:collection' show HashSet; 8 import 'dart:collection' show HashSet;
9 9
10 import 'package:analyzer/analyzer.dart' show parseDirectives; 10 import 'package:analyzer/analyzer.dart' show parseDirectives;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 /// Node associated with a resolved [uri]. 66 /// Node associated with a resolved [uri].
67 SourceNode nodeFromUri(Uri uri) { 67 SourceNode nodeFromUri(Uri uri) {
68 var uriString = Uri.encodeFull('$uri'); 68 var uriString = Uri.encodeFull('$uri');
69 return nodes.putIfAbsent(uri, () { 69 return nodes.putIfAbsent(uri, () {
70 var source = _context.sourceFactory.forUri(uriString); 70 var source = _context.sourceFactory.forUri(uriString);
71 var extension = path.extension(uriString); 71 var extension = path.extension(uriString);
72 if (extension == '.html') { 72 if (extension == '.html') {
73 return new HtmlSourceNode(uri, source, this); 73 return new HtmlSourceNode(uri, source, this);
74 } else if (extension == '.dart' || uriString.startsWith('dart:')) { 74 } else if (extension == '.dart' || uriString.startsWith('dart:')) {
75 return new DartSourceNode(uri, source); 75 return new DartSourceNode(uri, source);
76 } else if (extension == '.js' || extension == '.css') { 76 } else {
77 return new ResourceSourceNode(uri, source); 77 return new ResourceSourceNode(uri, source);
78 } else {
79 assert(false); // unreachable
80 } 78 }
81 }); 79 });
82 } 80 }
83 } 81 }
84 82
85 /// A node in the import graph representing a source file. 83 /// A node in the import graph representing a source file.
86 abstract class SourceNode { 84 abstract class SourceNode {
87 /// Resolved URI for this node. 85 /// Resolved URI for this node.
88 final Uri uri; 86 final Uri uri;
89 87
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 136 }
139 137
140 /// A node representing an entry HTML source file. 138 /// A node representing an entry HTML source file.
141 class HtmlSourceNode extends SourceNode { 139 class HtmlSourceNode extends SourceNode {
142 /// Resources included by default on any application. 140 /// Resources included by default on any application.
143 final runtimeDeps; 141 final runtimeDeps;
144 142
145 /// Libraries referred to via script tags. 143 /// Libraries referred to via script tags.
146 Set<DartSourceNode> scripts = new Set<DartSourceNode>(); 144 Set<DartSourceNode> scripts = new Set<DartSourceNode>();
147 145
146 /// Link-rel stylesheets and images.
147 Set<ResourceSourceNode> resources = new Set<ResourceSourceNode>();
148
148 @override 149 @override
149 Iterable<SourceNode> get allDeps => [scripts, runtimeDeps].expand((e) => e); 150 Iterable<SourceNode> get allDeps =>
151 [scripts, resources, runtimeDeps].expand((e) => e);
150 152
151 @override 153 @override
152 Iterable<SourceNode> get depsWithoutParts => allDeps; 154 Iterable<SourceNode> get depsWithoutParts => allDeps;
153 155
154 /// Parsed document, updated whenever [update] is invoked. 156 /// Parsed document, updated whenever [update] is invoked.
155 Document document; 157 Document document;
156 158
157 HtmlSourceNode(Uri uri, Source source, SourceGraph graph) 159 HtmlSourceNode(Uri uri, Source source, SourceGraph graph)
158 : runtimeDeps = graph.runtimeDeps, 160 : runtimeDeps = graph.runtimeDeps,
159 super(uri, source); 161 super(uri, source);
(...skipping 17 matching lines...) Expand all
177 if (node == null || !node.source.exists()) { 179 if (node == null || !node.source.exists()) {
178 _reportError(graph, 'Script file $src not found', script); 180 _reportError(graph, 'Script file $src not found', script);
179 } 181 }
180 if (node != null) newScripts.add(node); 182 if (node != null) newScripts.add(node);
181 } 183 }
182 184
183 if (!_same(newScripts, scripts)) { 185 if (!_same(newScripts, scripts)) {
184 structureChanged = true; 186 structureChanged = true;
185 scripts = newScripts; 187 scripts = newScripts;
186 } 188 }
189
190 var newResources = new Set<ResourceSourceNode>();
191 for (var tag in document.querySelectorAll('link[rel="stylesheet"]')) {
192 newResources
193 .add(graph.nodeFromUri(uri.resolve(tag.attributes['href'])));
194 }
195 for (var tag in document.querySelectorAll('img')) {
196 newResources.add(graph.nodeFromUri(uri.resolve(tag.attributes['src'])));
197 }
198 if (!_same(newResources, resources)) {
199 structureChanged = true;
200 resources = newResources;
201 }
187 } 202 }
188 } 203 }
189 204
190 void _reportError(SourceGraph graph, String message, Node node) { 205 void _reportError(SourceGraph graph, String message, Node node) {
191 graph._reporter.enterHtml(source.uri); 206 graph._reporter.enterHtml(source.uri);
192 graph._reporter.log(new DependencyGraphError(message, node.sourceSpan)); 207 graph._reporter.log(new DependencyGraphError(message, node.sourceSpan));
193 graph._reporter.leaveHtml(); 208 graph._reporter.leaveHtml();
194 } 209 }
195 } 210 }
196 211
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 'harmony_feature_check.js', 466 'harmony_feature_check.js',
452 'dart_runtime.js', 467 'dart_runtime.js',
453 'dart_core.js' 468 'dart_core.js'
454 ]; 469 ];
455 470
456 /// Runtime files added to applications when running in server mode. 471 /// Runtime files added to applications when running in server mode.
457 final runtimeFilesForServerMode = new List<String>.from(defaultRuntimeFiles) 472 final runtimeFilesForServerMode = new List<String>.from(defaultRuntimeFiles)
458 ..addAll(const ['messages_widget.js', 'messages.css']); 473 ..addAll(const ['messages_widget.js', 'messages.css']);
459 474
460 final _log = new Logger('dev_compiler.dependency_graph'); 475 final _log = new Logger('dev_compiler.dependency_graph');
OLDNEW
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698