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

Unified Diff: lib/src/utils.dart

Issue 1223113005: simplify computing of runtime file locations (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 | « lib/src/codegen/html_codegen.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/utils.dart
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index bb411735035abb46c1649908b984ceaa278a1741..e72e2ad25cd82a352ce749ebd6c46b338ceff948 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -30,7 +30,6 @@ import 'package:analyzer/src/generated/source.dart' show LineInfo, Source;
import 'package:analyzer/analyzer.dart' show parseDirectives;
import 'package:crypto/crypto.dart' show CryptoUtils, MD5;
import 'package:source_span/source_span.dart';
-import 'package:yaml/yaml.dart';
import 'codegen/js_names.dart' show invalidVariableName;
@@ -311,36 +310,19 @@ String computeHashFromFile(String filepath) {
return CryptoUtils.bytesToHex((new MD5()..add(bytes)).close());
}
-String resourceOutputPath(Uri resourceUri, Uri entryUri) {
+String resourceOutputPath(Uri resourceUri, Uri entryUri, String runtimeDir) {
if (resourceUri.scheme == 'package') return resourceUri.path;
if (resourceUri.scheme != 'file') return null;
- var filepath = resourceUri.path;
- var relativePath = path.relative(filepath, from: path.dirname(entryUri.path));
-
- // File:/// urls can be for resources in the same project or resources from
- // the dev_compiler package. For now we only support relative paths going
- // further inside the folder where the entrypoint is located, otherwise we
- // assume this is a runtime resource from the dev_compiler.
- if (!relativePath.startsWith('..')) return relativePath;
-
- // Since this is a URI path we can assume forward slash and use lastIndexOf.
- var runtimePath = '/lib/runtime/';
- var pos = filepath.lastIndexOf(runtimePath);
- if (pos == -1) return null;
-
- var filename = filepath.substring(pos + runtimePath.length);
- var dir = filepath.substring(0, pos);
-
- // TODO(jmesserly): can we implement this without repeatedly reading pubspec?
- // It seems like we should know our package's root directory without needing
- // to search like this.
- var pubspec =
- loadYaml(new File(path.join(dir, 'pubspec.yaml')).readAsStringSync());
-
- // Ensure this is loaded from the dev_compiler package.
- if (pubspec['name'] != 'dev_compiler') return null;
- return path.join('dev_compiler', 'runtime', filename);
+
+ var entryDir = path.dirname(entryUri.path);
+ var filepath = path.normalize(path.join(entryDir, resourceUri.path));
+ if (path.isWithin(runtimeDir, filepath)) {
+ filepath = path.relative(filepath, from: runtimeDir);
+ return path.join('dev_compiler', 'runtime', filepath);
+ }
+
+ return path.relative(resourceUri.path, from: entryDir);
}
/// Given an annotated [node] and a [test] function, returns the first matching
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698