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'; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 {this.useMockSdk: false, | 49 {this.useMockSdk: false, |
50 this.dartSdkPath, | 50 this.dartSdkPath, |
51 this.useMultiPackage: false, | 51 this.useMultiPackage: false, |
52 this.customUrlMappings: const {}, | 52 this.customUrlMappings: const {}, |
53 this.packageRoot: 'packages/', | 53 this.packageRoot: 'packages/', |
54 this.packagePaths: const <String>[], | 54 this.packagePaths: const <String>[], |
55 this.resources: const <String>[], | 55 this.resources: const <String>[], |
56 this.useImplicitHtml: false}); | 56 this.useImplicitHtml: false}); |
57 } | 57 } |
58 | 58 |
59 enum ModuleFormat { es6, dart } | |
Jennifer Messerly
2016/01/22 18:29:01
Heh, not sure the enum adds much value. More an is
ochafik
2016/01/23 12:24:18
I agree, *if only* we had Java enums...
| |
60 | |
61 ModuleFormat parseModuleFormat(String s) => | |
62 ModuleFormat.values.firstWhere((v) => s == '$v'.split('.')[1]); | |
Jennifer Messerly
2016/01/22 18:29:01
if parsing fails, are we okay because args option
ochafik
2016/01/23 12:24:18
Yes we are, but cleaned up utils (moved to utils.d
| |
63 | |
59 // TODO(jmesserly): refactor all codegen options here. | 64 // TODO(jmesserly): refactor all codegen options here. |
60 class CodegenOptions { | 65 class CodegenOptions { |
61 /// Whether to emit the source map files. | 66 /// Whether to emit the source map files. |
62 final bool emitSourceMaps; | 67 final bool emitSourceMaps; |
63 | 68 |
64 /// Whether to force compilation of code with static errors. | 69 /// Whether to force compilation of code with static errors. |
65 final bool forceCompile; | 70 final bool forceCompile; |
66 | 71 |
67 /// Output directory for generated code. | 72 /// Output directory for generated code. |
68 final String outputDir; | 73 final String outputDir; |
69 | 74 |
70 /// Emit Closure Compiler-friendly code. | 75 /// Emit Closure Compiler-friendly code. |
71 final bool closure; | 76 final bool closure; |
72 | 77 |
73 /// Enable ES6 destructuring of named parameters. | 78 /// Enable ES6 destructuring of named parameters. |
74 final bool destructureNamedParams; | 79 final bool destructureNamedParams; |
75 | 80 |
76 /// Whether to emit a workaround for missing arrow function bind-this in | 81 /// Whether to emit a workaround for missing arrow function bind-this in |
77 /// other V8 builds | 82 /// other V8 builds |
78 final bool arrowFnBindThisWorkaround; | 83 final bool arrowFnBindThisWorkaround; |
79 | 84 |
80 /// Which module format to support. | 85 /// Which module format to support. |
81 /// Currently 'es6' and 'dart' are supported. | 86 /// Currently 'es6' and 'dart' are supported. |
82 final String moduleFormat; | 87 final ModuleFormat moduleFormat; |
83 | 88 |
84 const CodegenOptions( | 89 const CodegenOptions( |
85 {this.emitSourceMaps: true, | 90 {this.emitSourceMaps: true, |
86 this.forceCompile: false, | 91 this.forceCompile: false, |
87 this.closure: _CLOSURE_DEFAULT, | 92 this.closure: _CLOSURE_DEFAULT, |
88 this.destructureNamedParams: _DESTRUCTURE_NAMED_PARAMS_DEFAULT, | 93 this.destructureNamedParams: _DESTRUCTURE_NAMED_PARAMS_DEFAULT, |
89 this.outputDir, | 94 this.outputDir, |
90 this.arrowFnBindThisWorkaround: false, | 95 this.arrowFnBindThisWorkaround: false, |
91 this.moduleFormat: 'dart'}); | 96 this.moduleFormat: ModuleFormat.dart}); |
92 } | 97 } |
93 | 98 |
94 /// Options for devrun. | 99 /// Options for devrun. |
95 class RunnerOptions { | 100 class RunnerOptions { |
96 /// V8-based binary to be used to run the .js output (d8, iojs, node). | 101 /// V8-based binary to be used to run the .js output (d8, iojs, node). |
97 /// Can be just the executable name if it's in the path, or a path to the | 102 /// Can be just the executable name if it's in the path, or a path to the |
98 /// executable. | 103 /// executable. |
99 final String v8Binary; | 104 final String v8Binary; |
100 | 105 |
101 const RunnerOptions({this.v8Binary: _V8_BINARY_DEFAULT}); | 106 const RunnerOptions({this.v8Binary: _V8_BINARY_DEFAULT}); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 /// package (if we can infer where that is located). | 156 /// package (if we can infer where that is located). |
152 final String runtimeDir; | 157 final String runtimeDir; |
153 | 158 |
154 /// The files to compile. | 159 /// The files to compile. |
155 final List<String> inputs; | 160 final List<String> inputs; |
156 | 161 |
157 /// The base directory for [inputs]. Module imports will be generated relative | 162 /// The base directory for [inputs]. Module imports will be generated relative |
158 /// to this directory. | 163 /// to this directory. |
159 final String inputBaseDir; | 164 final String inputBaseDir; |
160 | 165 |
161 CompilerOptions( | 166 const CompilerOptions( |
162 {this.sourceOptions: const SourceResolverOptions(), | 167 {this.sourceOptions: const SourceResolverOptions(), |
163 this.codegenOptions: const CodegenOptions(), | 168 this.codegenOptions: const CodegenOptions(), |
164 this.runnerOptions: const RunnerOptions(), | 169 this.runnerOptions: const RunnerOptions(), |
165 this.checkSdk: false, | 170 this.checkSdk: false, |
166 this.dumpInfo: false, | 171 this.dumpInfo: false, |
167 this.htmlReport: false, | 172 this.htmlReport: false, |
168 this.dumpInfoFile, | 173 this.dumpInfoFile, |
169 this.useColors: true, | 174 this.useColors: true, |
170 this.help: false, | 175 this.help: false, |
171 this.version: false, | 176 this.version: false, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 if (serverMode && args.rest.length != 1) showUsage = true; | 237 if (serverMode && args.rest.length != 1) showUsage = true; |
233 | 238 |
234 return new CompilerOptions( | 239 return new CompilerOptions( |
235 codegenOptions: new CodegenOptions( | 240 codegenOptions: new CodegenOptions( |
236 emitSourceMaps: args['source-maps'], | 241 emitSourceMaps: args['source-maps'], |
237 forceCompile: args['force-compile'] || serverMode, | 242 forceCompile: args['force-compile'] || serverMode, |
238 closure: args['closure'], | 243 closure: args['closure'], |
239 destructureNamedParams: args['destructure-named-params'], | 244 destructureNamedParams: args['destructure-named-params'], |
240 outputDir: outputDir, | 245 outputDir: outputDir, |
241 arrowFnBindThisWorkaround: args['arrow-fn-bind-this'], | 246 arrowFnBindThisWorkaround: args['arrow-fn-bind-this'], |
242 moduleFormat: args['modules']), | 247 moduleFormat: parseModuleFormat(args['modules'])), |
243 sourceOptions: new SourceResolverOptions( | 248 sourceOptions: new SourceResolverOptions( |
244 useMockSdk: args['mock-sdk'], | 249 useMockSdk: args['mock-sdk'], |
245 dartSdkPath: sdkPath, | 250 dartSdkPath: sdkPath, |
246 useImplicitHtml: serverMode && | 251 useImplicitHtml: serverMode && |
247 args.rest.length == 1 && | 252 args.rest.length == 1 && |
248 args.rest[0].endsWith('.dart'), | 253 args.rest[0].endsWith('.dart'), |
249 customUrlMappings: customUrlMappings, | 254 customUrlMappings: customUrlMappings, |
250 useMultiPackage: args['use-multi-package'], | 255 useMultiPackage: args['use-multi-package'], |
251 packageRoot: args['package-root'], | 256 packageRoot: args['package-root'], |
252 packagePaths: args['package-paths'].split(','), | 257 packagePaths: args['package-paths'].split(','), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 help: 'Whether to emit source map files', defaultsTo: true) | 307 help: 'Whether to emit source map files', defaultsTo: true) |
303 ..addOption('runtime-dir', | 308 ..addOption('runtime-dir', |
304 help: 'Where to find dev_compiler\'s runtime files', defaultsTo: null) | 309 help: 'Where to find dev_compiler\'s runtime files', defaultsTo: null) |
305 ..addFlag('arrow-fn-bind-this', | 310 ..addFlag('arrow-fn-bind-this', |
306 help: 'Work around `this` binding in => functions') | 311 help: 'Work around `this` binding in => functions') |
307 ..addOption('modules', | 312 ..addOption('modules', |
308 help: 'Which module pattern to emit', | 313 help: 'Which module pattern to emit', |
309 allowed: ['es6', 'dart'], | 314 allowed: ['es6', 'dart'], |
310 allowedHelp: { | 315 allowedHelp: { |
311 'es6': 'es6 modules', | 316 'es6': 'es6 modules', |
312 'custom-dart': 'a custom format used by dartdevc, similar to AMD' | 317 'dart': 'a custom format used by dartdevc, similar to AMD' |
Jennifer Messerly
2016/01/22 18:29:01
Hmmm, I don't like calling this format "dart" ...
ochafik
2016/01/23 12:24:17
Done (+ tied these values to the enum with a getEn
| |
313 }, | 318 }, |
314 defaultsTo: 'dart') | 319 defaultsTo: 'dart') |
315 | 320 |
316 // general options | 321 // general options |
317 ..addFlag('help', abbr: 'h', help: 'Display this message') | 322 ..addFlag('help', abbr: 'h', help: 'Display this message') |
318 ..addFlag('version', | 323 ..addFlag('version', |
319 negatable: false, help: 'Display the Dev Compiler verion') | 324 negatable: false, help: 'Display the Dev Compiler verion') |
320 ..addFlag('server', help: 'Run as a development server.', defaultsTo: false) | 325 ..addFlag('server', help: 'Run as a development server.', defaultsTo: false) |
321 ..addFlag('hashing', | 326 ..addFlag('hashing', |
322 help: 'Enable hash-based file caching.', defaultsTo: null) | 327 help: 'Enable hash-based file caching.', defaultsTo: null) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 // The pub-cache directory is two levels up, but we verify that the layout | 408 // The pub-cache directory is two levels up, but we verify that the layout |
404 // looks correct. | 409 // looks correct. |
405 if (path.basename(dir) != 'dev_compiler') return null; | 410 if (path.basename(dir) != 'dev_compiler') return null; |
406 dir = path.dirname(dir); | 411 dir = path.dirname(dir); |
407 if (path.basename(dir) != 'global_packages') return null; | 412 if (path.basename(dir) != 'global_packages') return null; |
408 dir = path.dirname(dir); | 413 dir = path.dirname(dir); |
409 return path.join(dir, cacheDir, 'lib', 'runtime'); | 414 return path.join(dir, cacheDir, 'lib', 'runtime'); |
410 } | 415 } |
411 return null; | 416 return null; |
412 } | 417 } |
OLD | NEW |