OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #library('frog_leg'); | 5 #library('frog_leg'); |
6 | 6 |
7 #import('dart:io'); | 7 #import('dart:io'); |
8 #import('dart:uri'); | 8 #import('dart:uri'); |
9 | 9 |
10 #import('lang.dart', prefix: 'frog'); | 10 #import('lang.dart', prefix: 'frog'); |
11 #import('../lib/compiler/compiler.dart', prefix: 'compiler'); | 11 #import('../lib/compiler/compiler.dart', prefix: 'compiler'); |
12 #import('../lib/compiler/implementation/filenames.dart'); | 12 #import('../lib/compiler/implementation/filenames.dart'); |
13 | 13 #import('../lib/compiler/implementation/util/uri_extras.dart'); |
14 String relativize(Uri base, Uri uri) { | |
15 if (base.scheme == 'file' && | |
16 base.scheme == uri.scheme && | |
17 base.userInfo == uri.userInfo && | |
18 base.domain == uri.domain && | |
19 base.port == uri.port && | |
20 uri.query == "" && uri.fragment == "") { | |
21 if (uri.path.startsWith(base.path)) { | |
22 return uri.path.substring(base.path.length); | |
23 } | |
24 List<String> uriParts = uri.path.split('/'); | |
25 List<String> baseParts = base.path.split('/'); | |
26 int common = 0; | |
27 int length = Math.min(uriParts.length, baseParts.length); | |
28 while (common < length && uriParts[common] == baseParts[common]) { | |
29 common++; | |
30 } | |
31 StringBuffer sb = new StringBuffer(); | |
32 for (int i = common + 1; i < baseParts.length; i++) { | |
33 sb.add('../'); | |
34 } | |
35 for (int i = common; i < uriParts.length - 1; i++) { | |
36 sb.add('${uriParts[i]}/'); | |
37 } | |
38 sb.add('${uriParts.last()}'); | |
39 return sb.toString(); | |
40 } | |
41 return uri.toString(); | |
42 } | |
43 | 14 |
44 bool compile(frog.World world) { | 15 bool compile(frog.World world) { |
45 final throwOnError = frog.options.throwOnErrors; | 16 final throwOnError = frog.options.throwOnErrors; |
46 final showWarnings = frog.options.showWarnings; | 17 final showWarnings = frog.options.showWarnings; |
47 final allowMockCompilation = frog.options.allowMockCompilation; | 18 final allowMockCompilation = frog.options.allowMockCompilation; |
48 Uri cwd = new Uri(scheme: 'file', path: getCurrentDirectory()); | 19 Uri cwd = getCurrentDirectory(); |
49 Uri uri = cwd.resolve(nativeToUriPath(frog.options.dartScript)); | 20 Uri uri = cwd.resolve(nativeToUriPath(frog.options.dartScript)); |
50 String frogLibDir = nativeToUriPath(frog.options.libDir); | 21 String frogLibDir = nativeToUriPath(frog.options.libDir); |
51 if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/"; | 22 if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/"; |
52 Uri frogLib = new Uri(scheme: 'file', path: frogLibDir); | 23 Uri frogLib = new Uri(scheme: 'file', path: frogLibDir); |
53 Uri libraryRoot = frogLib.resolve('../../'); | 24 Uri libraryRoot = frogLib.resolve('../../'); |
54 Map<String, frog.SourceFile> sourceFiles = <frog.SourceFile>{}; | 25 Map<String, frog.SourceFile> sourceFiles = <frog.SourceFile>{}; |
55 | 26 |
56 Future<String> provider(Uri uri) { | 27 Future<String> provider(Uri uri) { |
57 if (uri.scheme != 'file') { | 28 if (uri.scheme != 'file') { |
58 throw new IllegalArgumentException(uri); | 29 throw new IllegalArgumentException(uri); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 world.legCode = code; | 63 world.legCode = code; |
93 world.jsBytesWritten = code.length; | 64 world.jsBytesWritten = code.length; |
94 return true; | 65 return true; |
95 } | 66 } |
96 | 67 |
97 class AbortLeg { | 68 class AbortLeg { |
98 final message; | 69 final message; |
99 AbortLeg(this.message); | 70 AbortLeg(this.message); |
100 toString() => 'Aborted due to --throw-on-error: $message'; | 71 toString() => 'Aborted due to --throw-on-error: $message'; |
101 } | 72 } |
102 | |
103 String getCurrentDirectory() { | |
104 String dir = new File(".").fullPathSync(); | |
105 if (dir.endsWith("/")) return dir; | |
106 return "$dir/"; | |
107 } | |
OLD | NEW |