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

Side by Side Diff: pkg/kernel/lib/application_root.dart

Issue 2539783002: Revert "Store library paths relative to a given application root folder." (Closed)
Patch Set: Created 4 years 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 | « pkg/kernel/lib/analyzer/loader.dart ('k') | pkg/kernel/lib/ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4 library kernel.application_root;
5
6 import 'package:path/path.dart' as pathlib;
7
8 /// Resolves URIs with the `app` scheme.
9 ///
10 /// These are used internally in kernel to represent file paths relative to
11 /// some application root. This is done to avoid storing irrelevant paths, such
12 /// as the path to the home directory of the user who compiled a given file.
13 class ApplicationRoot {
14 static const String scheme = 'app';
15
16 final String path;
17
18 ApplicationRoot(this.path) {
19 assert(pathlib.isAbsolute(path));
20 }
21
22 /// Resolves a given file path or URI to a relative URI.
23 Uri resolve(String pathString) {
24 var uri = Uri.parse(pathString);
25 if (uri.hasScheme) return relativeUri(uri);
26 return new Uri(
27 scheme: ApplicationRoot.scheme,
28 path: pathlib.relative(uri.path, from: this.path));
29 }
30
31 /// Converts `app` URIs to absolute `file` URIs.
32 Uri absoluteUri(Uri uri) {
33 if (uri.scheme == ApplicationRoot.scheme) {
34 return new Uri(scheme: 'file', path: pathlib.join(this.path, uri.path));
35 } else {
36 return uri;
37 }
38 }
39
40 /// Converts `file` URIs to `app` URIs.
41 Uri relativeUri(Uri uri) {
42 if (uri.scheme == 'file') {
43 return new Uri(
44 scheme: ApplicationRoot.scheme,
45 path: pathlib.relative(uri.path, from: this.path));
46 } else {
47 return uri;
48 }
49 }
50 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/analyzer/loader.dart ('k') | pkg/kernel/lib/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698