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

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

Issue 2532053005: Store library paths relative to a given application root folder. (Closed)
Patch Set: Revert changes to testcase baseline 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(path == null || pathlib.isAbsolute(path));
20 }
21
22 ApplicationRoot.none() : path = null;
23
24 /// Converts `app` URIs to absolute `file` URIs.
25 Uri absoluteUri(Uri uri) {
26 if (path == null) return uri;
27 if (uri.scheme == ApplicationRoot.scheme) {
28 return new Uri(scheme: 'file', path: pathlib.join(this.path, uri.path));
29 } else {
30 return uri;
31 }
32 }
33
34 /// Converts `file` URIs to `app` URIs.
35 Uri relativeUri(Uri uri) {
36 if (path == null) return uri;
37 if (uri.scheme == 'file' && pathlib.isWithin(this.path, uri.path)) {
38 return new Uri(
39 scheme: ApplicationRoot.scheme,
40 path: pathlib.relative(uri.path, from: this.path));
41 } else {
42 return uri;
43 }
44 }
45 }
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