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