| 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 leg_apiimpl; | 5 library leg_apiimpl; |
| 6 | 6 |
| 7 import 'dart:uri'; | 7 import 'dart:uri'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import '../compiler.dart' as api; | 10 import '../compiler.dart' as api; |
| 11 import 'dart2jslib.dart' as leg; | 11 import 'dart2jslib.dart' as leg; |
| 12 import 'tree/tree.dart' as tree; | 12 import 'tree/tree.dart' as tree; |
| 13 import 'elements/elements.dart' as elements; | 13 import 'elements/elements.dart' as elements; |
| 14 import 'ssa/tracer.dart' as ssa; | 14 import 'ssa/tracer.dart' as ssa; |
| 15 import '../../libraries.dart'; | 15 import '../../libraries.dart'; |
| 16 import 'source_file.dart'; | 16 import 'source_file.dart'; |
| 17 | 17 |
| 18 class Compiler extends leg.Compiler { | 18 class Compiler extends leg.Compiler { |
| 19 api.ReadStringFromUri provider; | 19 api.ReadStringFromUri provider; |
| 20 api.DiagnosticHandler handler; | 20 api.DiagnosticHandler handler; |
| 21 final Uri libraryRoot; | 21 final Uri libraryRoot; |
| 22 final Uri packageRoot; | 22 final Uri packageRoot; |
| 23 List<String> options; | 23 List<String> options; |
| 24 bool mockableLibraryUsed = false; | 24 bool mockableLibraryUsed = false; |
| 25 final Set<String> allowedLibraryCategories; |
| 25 | 26 |
| 26 Compiler(this.provider, this.handler, this.libraryRoot, this.packageRoot, | 27 Compiler(this.provider, this.handler, this.libraryRoot, this.packageRoot, |
| 27 List<String> options) | 28 List<String> options) |
| 28 : this.options = options, | 29 : this.options = options, |
| 30 this.allowedLibraryCategories = getAllowedLibraryCategories(options), |
| 29 super( | 31 super( |
| 30 tracer: new ssa.HTracer(), | 32 tracer: new ssa.HTracer(), |
| 31 enableTypeAssertions: hasOption(options, '--enable-checked-mode'), | 33 enableTypeAssertions: hasOption(options, '--enable-checked-mode'), |
| 32 enableUserAssertions: hasOption(options, '--enable-checked-mode'), | 34 enableUserAssertions: hasOption(options, '--enable-checked-mode'), |
| 33 enableMinification: hasOption(options, '--minify'), | 35 enableMinification: hasOption(options, '--minify'), |
| 34 enableNativeLiveTypeAnalysis: | 36 enableNativeLiveTypeAnalysis: |
| 35 !hasOption(options, '--disable-native-live-type-analysis'), | 37 !hasOption(options, '--disable-native-live-type-analysis'), |
| 36 emitJavaScript: !hasOption(options, '--output-type=dart'), | 38 emitJavaScript: !hasOption(options, '--output-type=dart'), |
| 37 disallowUnsafeEval: hasOption(options, '--disallow-unsafe-eval'), | 39 disallowUnsafeEval: hasOption(options, '--disallow-unsafe-eval'), |
| 38 analyzeAll: hasOption(options, '--analyze-all'), | 40 analyzeAll: hasOption(options, '--analyze-all'), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 throw new ArgumentError("packageRoot must end with a /"); | 55 throw new ArgumentError("packageRoot must end with a /"); |
| 54 } | 56 } |
| 55 } | 57 } |
| 56 | 58 |
| 57 static List<String> getStrips(List<String> options) { | 59 static List<String> getStrips(List<String> options) { |
| 58 for (String option in options) { | 60 for (String option in options) { |
| 59 if (option.startsWith('--force-strip=')) { | 61 if (option.startsWith('--force-strip=')) { |
| 60 return option.substring('--force-strip='.length).split(','); | 62 return option.substring('--force-strip='.length).split(','); |
| 61 } | 63 } |
| 62 } | 64 } |
| 63 return []; | 65 return const <String>[]; |
| 66 } |
| 67 |
| 68 static Set<String> getAllowedLibraryCategories(List<String> options) { |
| 69 for (String option in options) { |
| 70 if (option.startsWith('--categories=')) { |
| 71 var result = option.substring('--categories='.length).split(','); |
| 72 result.add('Shared'); |
| 73 result.add('Internal'); |
| 74 return new Set<String>.from(result); |
| 75 } |
| 76 } |
| 77 return new Set<String>.from(['Client', 'Shared', 'Internal']); |
| 64 } | 78 } |
| 65 | 79 |
| 66 static bool hasOption(List<String> options, String option) { | 80 static bool hasOption(List<String> options, String option) { |
| 67 return options.indexOf(option) >= 0; | 81 return options.indexOf(option) >= 0; |
| 68 } | 82 } |
| 69 | 83 |
| 70 // TODO(johnniwinther): Merge better with [translateDartUri] when | 84 // TODO(johnniwinther): Merge better with [translateDartUri] when |
| 71 // [scanBuiltinLibrary] is removed. | 85 // [scanBuiltinLibrary] is removed. |
| 72 String lookupLibraryPath(String dartLibraryName) { | 86 String lookupLibraryPath(String dartLibraryName) { |
| 73 LibraryInfo info = LIBRARIES[dartLibraryName]; | 87 LibraryInfo info = LIBRARIES[dartLibraryName]; |
| 74 if (info == null) return null; | 88 if (info == null) return null; |
| 75 if (!info.isDart2jsLibrary) return null; | 89 if (!info.isDart2jsLibrary) return null; |
| 90 if (!allowedLibraryCategories.contains(info.category)) return null; |
| 76 String path = info.dart2jsPath; | 91 String path = info.dart2jsPath; |
| 77 if (path == null) { | 92 if (path == null) { |
| 78 path = info.path; | 93 path = info.path; |
| 79 } | 94 } |
| 80 return "lib/$path"; | 95 return "lib/$path"; |
| 81 } | 96 } |
| 82 | 97 |
| 83 String lookupPatchPath(String dartLibraryName) { | 98 String lookupPatchPath(String dartLibraryName) { |
| 84 LibraryInfo info = LIBRARIES[dartLibraryName]; | 99 LibraryInfo info = LIBRARIES[dartLibraryName]; |
| 85 if (info == null) return null; | 100 if (info == null) return null; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 218 |
| 204 Uri resolvePatchUri(String dartLibraryPath) { | 219 Uri resolvePatchUri(String dartLibraryPath) { |
| 205 String patchPath = lookupPatchPath(dartLibraryPath); | 220 String patchPath = lookupPatchPath(dartLibraryPath); |
| 206 if (patchPath == null) return null; | 221 if (patchPath == null) return null; |
| 207 return libraryRoot.resolve(patchPath); | 222 return libraryRoot.resolve(patchPath); |
| 208 } | 223 } |
| 209 | 224 |
| 210 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); | 225 translatePackageUri(Uri uri, tree.Node node) => packageRoot.resolve(uri.path); |
| 211 | 226 |
| 212 bool run(Uri uri) { | 227 bool run(Uri uri) { |
| 228 log('Allowed library categories: $allowedLibraryCategories'); |
| 213 bool success = super.run(uri); | 229 bool success = super.run(uri); |
| 214 int cumulated = 0; | 230 int cumulated = 0; |
| 215 for (final task in tasks) { | 231 for (final task in tasks) { |
| 216 cumulated += task.timing; | 232 cumulated += task.timing; |
| 217 log('${task.name} took ${task.timing}msec'); | 233 log('${task.name} took ${task.timing}msec'); |
| 218 } | 234 } |
| 219 int total = totalCompileTime.elapsedMilliseconds; | 235 int total = totalCompileTime.elapsedMilliseconds; |
| 220 log('Total compile-time ${total}msec;' | 236 log('Total compile-time ${total}msec;' |
| 221 ' unaccounted ${total - cumulated}msec'); | 237 ' unaccounted ${total - cumulated}msec'); |
| 222 return success; | 238 return success; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 236 handler(translateUri(span.uri, null), span.begin, span.end, | 252 handler(translateUri(span.uri, null), span.begin, span.end, |
| 237 message, kind); | 253 message, kind); |
| 238 } | 254 } |
| 239 } | 255 } |
| 240 | 256 |
| 241 bool get isMockCompilation { | 257 bool get isMockCompilation { |
| 242 return mockableLibraryUsed | 258 return mockableLibraryUsed |
| 243 && (options.indexOf('--allow-mock-compilation') != -1); | 259 && (options.indexOf('--allow-mock-compilation') != -1); |
| 244 } | 260 } |
| 245 } | 261 } |
| OLD | NEW |