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

Unified Diff: lib/src/compiler.dart

Issue 1243693002: fix for bin/devc relative path (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/src/options.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler.dart
diff --git a/lib/src/compiler.dart b/lib/src/compiler.dart
index e7af8f7f37b394537c560af6d83790f81a1c0622..b8e789537a2d1a52565461a66b450b2658fe32ec 100644
--- a/lib/src/compiler.dart
+++ b/lib/src/compiler.dart
@@ -58,6 +58,7 @@ class BatchCompiler extends AbstractCompiler {
BatchCompiler(AnalysisContext context, CompilerOptions options,
{AnalysisErrorListener reporter})
: super(context, options, reporter) {
+ _inputBaseDir = options.inputBaseDir;
if (outputDir != null) {
_jsGen = new JSGenerator(this);
}
@@ -84,9 +85,13 @@ class BatchCompiler extends AbstractCompiler {
}
void compileFromUri(Uri uri) {
+ if (!uri.isAbsolute) {
+ throw new ArgumentError.value('$uri', 'uri', 'must be absolute');
+ }
var source = context.sourceFactory.forUri(Uri.encodeFull('$uri'));
- if (source == null) throw new ArgumentError.value(
- uri.toString(), 'uri', 'could not find source for');
+ if (source == null) {
+ throw new ArgumentError.value('$uri', 'uri', 'could not find source for');
+ }
compileSource(source);
}
@@ -114,6 +119,15 @@ class BatchCompiler extends AbstractCompiler {
bool failureInLib = false;
for (var element in unitElements) {
var unit = context.resolveCompilationUnit(element.source, library);
+
+ // TODO(jmesserly): this hack is to avoid compiling the same compilation
+ // unit to JS twice. We mutate the AST, so it's not safe to run more than
+ // once on the same unit.
+ if (element.library == library) {
+ if (unit.getProperty(_propertyName) == true) return;
+ unit.setProperty(_propertyName, true);
+ }
+
units.add(unit);
failureInLib = logErrors(element.source) || failureInLib;
checker.visitCompilationUnit(unit);
@@ -129,12 +143,6 @@ class BatchCompiler extends AbstractCompiler {
var unit = units.first;
var parts = units.skip(1).toList();
- // TODO(jmesserly): this hack is to avoid compiling the same compilation
- // unit to JS twice. We mutate the AST, so it's not safe to run more than
- // once on the same unit.
- if (unit.getProperty(_propertyName) == true) return;
- unit.setProperty(_propertyName, true);
-
_jsGen.generateLibrary(new LibraryUnit(unit, parts));
}
}
@@ -149,6 +157,7 @@ class BatchCompiler extends AbstractCompiler {
var loadedLibs = new LinkedHashSet<Uri>();
+ var htmlOutDir = path.dirname(getOutputPath(source.uri));
for (var script in scripts) {
Source scriptSource = null;
var srcAttr = script.attributes['src'];
@@ -171,7 +180,7 @@ class BatchCompiler extends AbstractCompiler {
if (scriptSource != null) {
var lib = context.computeLibraryElement(scriptSource);
compileLibrary(lib);
- script.replaceWith(_linkLibraries(lib, loadedLibs));
+ script.replaceWith(_linkLibraries(lib, loadedLibs, from: htmlOutDir));
}
}
@@ -179,7 +188,7 @@ class BatchCompiler extends AbstractCompiler {
// as a special case.
for (var file in defaultRuntimeFiles) {
var input = path.join(options.runtimeDir, file);
- var output = path.join(outputDir, runtimeFileOutput(file));
+ var output = path.join(htmlOutDir, runtimeFileOutput(file));
new Directory(path.dirname(output)).createSync(recursive: true);
new File(input).copySync(output);
}
@@ -191,18 +200,21 @@ class BatchCompiler extends AbstractCompiler {
}
html.DocumentFragment _linkLibraries(
- LibraryElement mainLib, LinkedHashSet<Uri> loaded) {
+ LibraryElement mainLib, LinkedHashSet<Uri> loaded, {String from}) {
+ assert(from != null);
var alreadyLoaded = loaded.length;
_collectLibraries(mainLib, loaded);
var newLibs = loaded.skip(alreadyLoaded);
var df = new html.DocumentFragment();
- for (var path in defaultRuntimeFiles) {
- df.append(html_codegen.libraryInclude(runtimeFileOutput(path)));
+ for (var file in defaultRuntimeFiles) {
+ df.append(html_codegen.libraryInclude(runtimeFileOutput(file)));
vsm 2015/07/20 16:11:16 I think you need to make a relative path wrt *from
Jennifer Messerly 2015/07/20 16:32:31 It's already a relative path. The (poorly named) r
}
for (var uri in newLibs) {
if (uri.scheme == 'dart') continue;
- df.append(html_codegen.libraryInclude(getModulePath(uri)));
+ var jsPath = getModulePath(uri);
+ jsPath = path.relative(path.join(outputDir, jsPath), from: from);
+ df.append(html_codegen.libraryInclude(jsPath));
}
df.append(html_codegen.invokeMain(getModuleName(mainLib.source.uri)));
return df;
@@ -249,7 +261,7 @@ abstract class AbstractCompiler {
Uri stringToUri(String uriString) {
var uri = uriString.startsWith('dart:') || uriString.startsWith('package:')
? Uri.parse(uriString)
- : new Uri.file(uriString);
+ : new Uri.file(path.absolute(uriString));
return uri;
}
@@ -313,15 +325,15 @@ abstract class AbstractCompiler {
String getModuleName(Uri uri) {
var filepath = path.withoutExtension(uri.path);
if (uri.scheme == 'dart') {
- filepath = 'dart/$filepath';
+ return 'dart/$filepath';
} else if (uri.scheme == 'file') {
- filepath = path.relative(filepath, from: inputBaseDir);
+ return path.relative(filepath, from: inputBaseDir);
} else {
assert(uri.scheme == 'package');
// filepath is good here, we want the output to start with a directory
// matching the package name.
+ return filepath;
}
- return filepath;
}
/// Log any errors encountered when resolving [source] and return whether any
« no previous file with comments | « no previous file | lib/src/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698