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

Unified Diff: pkg/dev_compiler/lib/src/compiler/compiler.dart

Issue 2833633002: Various DDC fixes for windows (Closed)
Patch Set: Fix formatting Created 3 years, 8 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
Index: pkg/dev_compiler/lib/src/compiler/compiler.dart
diff --git a/pkg/dev_compiler/lib/src/compiler/compiler.dart b/pkg/dev_compiler/lib/src/compiler/compiler.dart
index c07c31c11f532b0d8e462482e4750a5d2ad6a7b2..e958e44939657332fd555cc28e7b3686b7992ab6 100644
--- a/pkg/dev_compiler/lib/src/compiler/compiler.dart
+++ b/pkg/dev_compiler/lib/src/compiler/compiler.dart
@@ -156,13 +156,11 @@ class ModuleCompiler {
var compilingSdk = false;
for (var sourcePath in unit.sources) {
- var sourceUri = Uri.parse(sourcePath);
- if (sourceUri.scheme == '') {
- sourceUri = path.toUri(path.absolute(sourcePath));
- } else if (sourceUri.scheme == 'dart') {
+ var sourceUri = _sourceToUri(sourcePath);
+ if (sourceUri.scheme == "dart") {
compilingSdk = true;
}
- Source source = context.sourceFactory.forUri2(sourceUri);
+ var source = context.sourceFactory.forUri2(sourceUri);
var fileUsage = 'You need to pass at least one existing .dart file as an'
' argument.';
@@ -427,7 +425,9 @@ class BuildUnit {
// build units.
final Func1<Source, String> libraryToModule;
- BuildUnit(this.name, this.libraryRoot, this.sources, this.libraryToModule);
+ BuildUnit(
+ String modulePath, this.libraryRoot, this.sources, this.libraryToModule)
+ : name = '${path.toUri(modulePath)}';
}
/// The output of Dart->JS compilation.
@@ -502,10 +502,9 @@ class JSModuleFile {
builtMap =
placeSourceMap(sourceMap.build(jsUrl), mapUrl, options.bazelMapping);
if (options.sourceMapComment) {
- var relativeMapUrl = path
- .toUri(
- path.relative(path.fromUri(mapUrl), from: path.dirname(jsUrl)))
- .toString();
+ var jsDir = path.dirname(path.fromUri(jsUrl));
+ var relative = path.relative(path.fromUri(mapUrl), from: jsDir);
+ var relativeMapUrl = path.toUri(relative).toString();
assert(path.dirname(jsUrl) == path.dirname(mapUrl));
printer.emit('\n//# sourceMappingURL=');
printer.emit(relativeMapUrl);
@@ -529,7 +528,9 @@ class JSModuleFile {
void writeCodeSync(ModuleFormat format, String jsPath,
{bool singleOutFile: false}) {
String mapPath = jsPath + '.map';
- var code = getCode(format, jsPath, mapPath, singleOutFile: singleOutFile);
+ var code = getCode(
+ format, path.toUri(jsPath).toString(), path.toUri(mapPath).toString(),
+ singleOutFile: singleOutFile);
var c = code.code;
if (singleOutFile) {
// In singleOutFile mode we wrap each module in an eval statement to
@@ -577,26 +578,56 @@ class JSModuleCode {
}
/// Adjusts the source paths in [sourceMap] to be relative to [sourceMapPath],
-/// and returns the new map.
+/// and returns the new map. Relative paths are in terms of URIs ('/'), not
+/// local OS paths (e.g., windows '\').
// TODO(jmesserly): find a new home for this.
Map placeSourceMap(
Map sourceMap, String sourceMapPath, Map<String, String> bazelMappings) {
- var dir = path.dirname(sourceMapPath);
var map = new Map.from(sourceMap);
+ // Convert to a local file path if it's not.
+ sourceMapPath = path.fromUri(_sourceToUri(sourceMapPath));
+ var sourceMapDir = path.dirname(path.absolute(sourceMapPath));
var list = new List.from(map['sources']);
map['sources'] = list;
- String transformUri(String uri) {
- if (uri.startsWith('dart:')) return uri;
- var match = bazelMappings[path.absolute(uri)];
+
+ String makeRelative(String sourcePath) {
+ var uri = _sourceToUri(sourcePath);
+ if (uri.scheme == 'dart' || uri.scheme == 'package') return sourcePath;
+
+ // Convert to a local file path if it's not.
+ sourcePath = path.absolute(path.fromUri(uri));
+
+ // Allow bazel mappings to override.
+ var match = bazelMappings[sourcePath];
if (match != null) return match;
- // Fall back to a relative path.
- return path.toUri(path.relative(path.fromUri(uri), from: dir)).toString();
+ // Fall back to a relative path against the source map itself.
+ sourcePath = path.relative(sourcePath, from: sourceMapDir);
+
+ // Convert from relative local path to relative URI.
+ return path.toUri(sourcePath).path;
}
for (int i = 0; i < list.length; i++) {
- list[i] = transformUri(list[i]);
+ list[i] = makeRelative(list[i]);
}
- map['file'] = transformUri(map['file']);
+ map['file'] = makeRelative(map['file']);
return map;
}
+
+// Convert a source string to a Uri. The [source] may be a Dart URI, a file
+// URI, or a local win/mac/linux path.
+Uri _sourceToUri(String source) {
+ var uri = Uri.parse(source);
+ var scheme = uri.scheme;
+ switch (scheme) {
+ case "dart":
+ case "package":
+ case "file":
+ // A valid URI.
+ return uri;
+ default:
+ // Assume a file path.
+ return new Uri.file(path.absolute(source));
+ }
+}
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/code_generator.dart ('k') | pkg/dev_compiler/lib/src/compiler/source_map_printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698