OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Set of flags and options passed to the compiler | 5 /// Set of flags and options passed to the compiler |
6 library dev_compiler.src.options; | 6 library dev_compiler.src.options; |
7 | 7 |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
11 import 'package:cli_util/cli_util.dart' show getSdkDir; | 11 import 'package:cli_util/cli_util.dart' show getSdkDir; |
12 import 'package:logging/logging.dart' show Level; | 12 import 'package:logging/logging.dart' show Level; |
13 import 'package:path/path.dart' as path; | 13 import 'package:path/path.dart' as path; |
14 import 'package:yaml/yaml.dart'; | 14 import 'package:yaml/yaml.dart'; |
15 | 15 |
16 import '../strong_mode.dart' show StrongModeOptions; | |
17 | |
18 const bool _CLOSURE_DEFAULT = false; | 16 const bool _CLOSURE_DEFAULT = false; |
19 | 17 |
20 /// Options used to set up Source URI resolution in the analysis context. | 18 /// Options used to set up Source URI resolution in the analysis context. |
21 class SourceResolverOptions { | 19 class SourceResolverOptions { |
22 /// Whether to resolve 'package:' uris using the multi-package resolver. | 20 /// Whether to resolve 'package:' uris using the multi-package resolver. |
23 final bool useMultiPackage; | 21 final bool useMultiPackage; |
24 | 22 |
25 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" | 23 /// Custom URI mappings, such as "dart:foo" -> "path/to/foo.dart" |
26 final Map<String, String> customUrlMappings; | 24 final Map<String, String> customUrlMappings; |
27 | 25 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 /// V8-based binary to be used to run the .js output (d8, iojs, node). | 85 /// V8-based binary to be used to run the .js output (d8, iojs, node). |
88 /// Can be just the executable name if it's in the path, or a path to the | 86 /// Can be just the executable name if it's in the path, or a path to the |
89 /// executable. | 87 /// executable. |
90 final String v8Binary; | 88 final String v8Binary; |
91 | 89 |
92 const RunnerOptions({this.v8Binary: 'iojs'}); | 90 const RunnerOptions({this.v8Binary: 'iojs'}); |
93 } | 91 } |
94 | 92 |
95 /// General options used by the dev compiler and server. | 93 /// General options used by the dev compiler and server. |
96 class CompilerOptions { | 94 class CompilerOptions { |
97 final StrongModeOptions strongOptions; | |
98 final SourceResolverOptions sourceOptions; | 95 final SourceResolverOptions sourceOptions; |
99 final CodegenOptions codegenOptions; | 96 final CodegenOptions codegenOptions; |
100 final RunnerOptions runnerOptions; | 97 final RunnerOptions runnerOptions; |
101 | 98 |
102 /// Whether to check the sdk libraries. | 99 /// Whether to check the sdk libraries. |
103 final bool checkSdk; | 100 final bool checkSdk; |
104 | 101 |
105 /// Whether to dump summary information on the console. | 102 /// Whether to dump summary information on the console. |
106 final bool dumpInfo; | 103 final bool dumpInfo; |
107 | 104 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 final String runtimeDir; | 139 final String runtimeDir; |
143 | 140 |
144 /// The files to compile. | 141 /// The files to compile. |
145 final List<String> inputs; | 142 final List<String> inputs; |
146 | 143 |
147 /// The base directory for [inputs]. Module imports will be generated relative | 144 /// The base directory for [inputs]. Module imports will be generated relative |
148 /// to this directory. | 145 /// to this directory. |
149 final String inputBaseDir; | 146 final String inputBaseDir; |
150 | 147 |
151 CompilerOptions( | 148 CompilerOptions( |
152 {this.strongOptions: const StrongModeOptions(), | 149 {this.sourceOptions: const SourceResolverOptions(), |
153 this.sourceOptions: const SourceResolverOptions(), | |
154 this.codegenOptions: const CodegenOptions(), | 150 this.codegenOptions: const CodegenOptions(), |
155 this.runnerOptions: const RunnerOptions(), | 151 this.runnerOptions: const RunnerOptions(), |
156 this.checkSdk: false, | 152 this.checkSdk: false, |
157 this.dumpInfo: false, | 153 this.dumpInfo: false, |
158 this.dumpInfoFile, | 154 this.dumpInfoFile, |
159 this.useColors: true, | 155 this.useColors: true, |
160 this.help: false, | 156 this.help: false, |
161 this.version: false, | 157 this.version: false, |
162 this.logLevel: Level.WARNING, | 158 this.logLevel: Level.WARNING, |
163 this.serverMode: false, | 159 this.serverMode: false, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 dartSdkPath: sdkPath, | 227 dartSdkPath: sdkPath, |
232 useImplicitHtml: serverMode && | 228 useImplicitHtml: serverMode && |
233 args.rest.length == 1 && | 229 args.rest.length == 1 && |
234 args.rest[0].endsWith('.dart'), | 230 args.rest[0].endsWith('.dart'), |
235 customUrlMappings: customUrlMappings, | 231 customUrlMappings: customUrlMappings, |
236 useMultiPackage: args['use-multi-package'], | 232 useMultiPackage: args['use-multi-package'], |
237 packageRoot: args['package-root'], | 233 packageRoot: args['package-root'], |
238 packagePaths: args['package-paths'].split(','), | 234 packagePaths: args['package-paths'].split(','), |
239 resources: | 235 resources: |
240 args['resources'].split(',').where((s) => s.isNotEmpty).toList()), | 236 args['resources'].split(',').where((s) => s.isNotEmpty).toList()), |
241 strongOptions: new StrongModeOptions.fromArguments(args), | |
242 runnerOptions: new RunnerOptions(v8Binary: v8Binary), | 237 runnerOptions: new RunnerOptions(v8Binary: v8Binary), |
243 checkSdk: args['sdk-check'], | 238 checkSdk: args['sdk-check'], |
244 dumpInfo: dumpInfo, | 239 dumpInfo: dumpInfo, |
245 dumpInfoFile: args['dump-info-file'], | 240 dumpInfoFile: args['dump-info-file'], |
246 useColors: useColors, | 241 useColors: useColors, |
247 help: showUsage, | 242 help: showUsage, |
248 version: showVersion, | 243 version: showVersion, |
249 logLevel: logLevel, | 244 logLevel: logLevel, |
250 serverMode: serverMode, | 245 serverMode: serverMode, |
251 enableHashing: enableHashing, | 246 enableHashing: enableHashing, |
252 widget: args['widget'], | 247 widget: args['widget'], |
253 host: args['host'], | 248 host: args['host'], |
254 port: int.parse(args['port']), | 249 port: int.parse(args['port']), |
255 runtimeDir: runtimeDir, | 250 runtimeDir: runtimeDir, |
256 inputs: args.rest); | 251 inputs: args.rest); |
257 } | 252 } |
258 | 253 |
259 final ArgParser argParser = StrongModeOptions.addArguments(new ArgParser() | 254 final ArgParser argParser = new ArgParser() |
260 ..addFlag('sdk-check', | 255 ..addFlag('sdk-check', |
261 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) | 256 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) |
262 ..addFlag('mock-sdk', | 257 ..addFlag('mock-sdk', |
263 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false) | 258 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false) |
264 | 259 |
265 // input/output options | 260 // input/output options |
266 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null) | 261 ..addOption('out', abbr: 'o', help: 'Output directory', defaultsTo: null) |
267 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) | 262 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) |
268 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null) | 263 ..addOption('dump-src-to', help: 'Dump dart src code', defaultsTo: null) |
269 ..addOption('package-root', | 264 ..addOption('package-root', |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 help: 'Compile code with static errors', defaultsTo: false) | 309 help: 'Compile code with static errors', defaultsTo: false) |
315 ..addOption('log', abbr: 'l', help: 'Logging level (defaults to warning)') | 310 ..addOption('log', abbr: 'l', help: 'Logging level (defaults to warning)') |
316 ..addFlag('dump-info', | 311 ..addFlag('dump-info', |
317 abbr: 'i', help: 'Dump summary information', defaultsTo: null) | 312 abbr: 'i', help: 'Dump summary information', defaultsTo: null) |
318 ..addOption('v8-binary', | 313 ..addOption('v8-binary', |
319 help: 'V8-based binary to run JavaScript output with (iojs, node, d8)', | 314 help: 'V8-based binary to run JavaScript output with (iojs, node, d8)', |
320 defaultsTo: 'iojs') | 315 defaultsTo: 'iojs') |
321 ..addOption('dump-info-file', | 316 ..addOption('dump-info-file', |
322 abbr: 'f', | 317 abbr: 'f', |
323 help: 'Dump info json file (requires dump-info)', | 318 help: 'Dump info json file (requires dump-info)', |
324 defaultsTo: null)); | 319 defaultsTo: null); |
325 | 320 |
326 // TODO: Switch over to the `pub_cache` package (or the Resource API)? | 321 // TODO: Switch over to the `pub_cache` package (or the Resource API)? |
327 | 322 |
328 /// Tries to find the `lib/runtime/` directory of the dev_compiler package. This | 323 /// Tries to find the `lib/runtime/` directory of the dev_compiler package. This |
329 /// works when running devc from it's sources or from a snapshot that is | 324 /// works when running devc from it's sources or from a snapshot that is |
330 /// activated via `pub global activate`. | 325 /// activated via `pub global activate`. |
331 String _computeRuntimeDir() { | 326 String _computeRuntimeDir() { |
332 var scriptPath = path.fromUri(Platform.script); | 327 var scriptPath = path.fromUri(Platform.script); |
333 var file = path.basename(scriptPath); | 328 var file = path.basename(scriptPath); |
334 var dir = path.dirname(scriptPath); | 329 var dir = path.dirname(scriptPath); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // The pub-cache directory is two levels up, but we verify that the layout | 367 // The pub-cache directory is two levels up, but we verify that the layout |
373 // looks correct. | 368 // looks correct. |
374 if (path.basename(dir) != 'dev_compiler') return null; | 369 if (path.basename(dir) != 'dev_compiler') return null; |
375 dir = path.dirname(dir); | 370 dir = path.dirname(dir); |
376 if (path.basename(dir) != 'global_packages') return null; | 371 if (path.basename(dir) != 'global_packages') return null; |
377 dir = path.dirname(dir); | 372 dir = path.dirname(dir); |
378 return path.join(dir, cacheDir, 'lib', 'runtime'); | 373 return path.join(dir, cacheDir, 'lib', 'runtime'); |
379 } | 374 } |
380 return null; | 375 return null; |
381 } | 376 } |
OLD | NEW |