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 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
10 import 'package:cli_util/cli_util.dart' show getSdkDir; | 10 import 'package:cli_util/cli_util.dart' show getSdkDir; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 /// Output directory for generated code. | 71 /// Output directory for generated code. |
72 final String outputDir; | 72 final String outputDir; |
73 | 73 |
74 /// Emit Closure Compiler-friendly code. | 74 /// Emit Closure Compiler-friendly code. |
75 final bool closure; | 75 final bool closure; |
76 | 76 |
77 /// Enable ES6 destructuring of named parameters. | 77 /// Enable ES6 destructuring of named parameters. |
78 final bool destructureNamedParams; | 78 final bool destructureNamedParams; |
79 | 79 |
80 /// Whether to emit a workaround for missing arrow function bind-this in | |
81 /// other V8 builds | |
82 final bool arrowFnBindThisWorkaround; | |
83 | |
84 /// Which module format to support. | 80 /// Which module format to support. |
85 /// Currently 'es6' and 'legacy' are supported. | 81 /// Currently 'es6' and 'legacy' are supported. |
86 final ModuleFormat moduleFormat; | 82 final ModuleFormat moduleFormat; |
87 | 83 |
88 const CodegenOptions( | 84 const CodegenOptions( |
89 {this.emitSourceMaps: true, | 85 {this.emitSourceMaps: true, |
90 this.forceCompile: false, | 86 this.forceCompile: false, |
91 this.closure: _CLOSURE_DEFAULT, | 87 this.closure: _CLOSURE_DEFAULT, |
92 this.destructureNamedParams: _DESTRUCTURE_NAMED_PARAMS_DEFAULT, | 88 this.destructureNamedParams: _DESTRUCTURE_NAMED_PARAMS_DEFAULT, |
93 this.outputDir, | 89 this.outputDir, |
94 this.arrowFnBindThisWorkaround: false, | |
95 this.moduleFormat: ModuleFormat.legacy}); | 90 this.moduleFormat: ModuleFormat.legacy}); |
96 } | 91 } |
97 | 92 |
98 /// Options for devrun. | 93 /// Options for devrun. |
99 class RunnerOptions { | 94 class RunnerOptions { |
100 /// V8-based binary to be used to run the .js output (d8, iojs, node). | 95 /// V8-based binary to be used to run the .js output (d8, iojs, node). |
101 /// Can be just the executable name if it's in the path, or a path to the | 96 /// Can be just the executable name if it's in the path, or a path to the |
102 /// executable. | 97 /// executable. |
103 final String v8Binary; | 98 final String v8Binary; |
104 | 99 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 customUrlMappings[splitMapping[0]] = splitMapping[1]; | 228 customUrlMappings[splitMapping[0]] = splitMapping[1]; |
234 } | 229 } |
235 | 230 |
236 return new CompilerOptions( | 231 return new CompilerOptions( |
237 codegenOptions: new CodegenOptions( | 232 codegenOptions: new CodegenOptions( |
238 emitSourceMaps: args['source-maps'], | 233 emitSourceMaps: args['source-maps'], |
239 forceCompile: args['force-compile'] || serverMode, | 234 forceCompile: args['force-compile'] || serverMode, |
240 closure: args['closure'], | 235 closure: args['closure'], |
241 destructureNamedParams: args['destructure-named-params'], | 236 destructureNamedParams: args['destructure-named-params'], |
242 outputDir: outputDir, | 237 outputDir: outputDir, |
243 arrowFnBindThisWorkaround: args['arrow-fn-bind-this'], | |
244 moduleFormat: parseModuleFormat(args['modules'])), | 238 moduleFormat: parseModuleFormat(args['modules'])), |
245 sourceOptions: new SourceResolverOptions( | 239 sourceOptions: new SourceResolverOptions( |
246 useMockSdk: args['mock-sdk'], | 240 useMockSdk: args['mock-sdk'], |
247 dartSdkPath: sdkPath, | 241 dartSdkPath: sdkPath, |
248 useImplicitHtml: serverMode && | 242 useImplicitHtml: serverMode && |
249 args.rest.length == 1 && | 243 args.rest.length == 1 && |
250 args.rest[0].endsWith('.dart'), | 244 args.rest[0].endsWith('.dart'), |
251 customUrlMappings: customUrlMappings, | 245 customUrlMappings: customUrlMappings, |
252 useMultiPackage: args['use-multi-package'], | 246 useMultiPackage: args['use-multi-package'], |
253 packageRoot: args['package-root'], | 247 packageRoot: args['package-root'], |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 ..addOption('package-paths', | 291 ..addOption('package-paths', |
298 help: 'if using the multi-package resolver, the list of directories to\n' | 292 help: 'if using the multi-package resolver, the list of directories to\n' |
299 'look for packages in.', | 293 'look for packages in.', |
300 defaultsTo: '') | 294 defaultsTo: '') |
301 ..addOption('resources', | 295 ..addOption('resources', |
302 help: 'Additional resources to serve', defaultsTo: '') | 296 help: 'Additional resources to serve', defaultsTo: '') |
303 ..addFlag('source-maps', | 297 ..addFlag('source-maps', |
304 help: 'Whether to emit source map files', defaultsTo: true) | 298 help: 'Whether to emit source map files', defaultsTo: true) |
305 ..addOption('runtime-dir', | 299 ..addOption('runtime-dir', |
306 help: 'Where to find dev_compiler\'s runtime files', defaultsTo: null) | 300 help: 'Where to find dev_compiler\'s runtime files', defaultsTo: null) |
307 ..addFlag('arrow-fn-bind-this', | |
308 help: 'Work around `this` binding in => functions') | |
309 ..addOption('modules', | 301 ..addOption('modules', |
310 help: 'Which module pattern to emit', | 302 help: 'Which module pattern to emit', |
311 allowed: ModuleFormat.values.map(getEnumName).toList(), | 303 allowed: ModuleFormat.values.map(getEnumName).toList(), |
312 allowedHelp: { | 304 allowedHelp: { |
313 getEnumName(ModuleFormat.es6): 'es6 modules', | 305 getEnumName(ModuleFormat.es6): 'es6 modules', |
314 getEnumName(ModuleFormat.legacy): | 306 getEnumName(ModuleFormat.legacy): |
315 'a custom format used by dartdevc, similar to AMD', | 307 'a custom format used by dartdevc, similar to AMD', |
316 getEnumName(ModuleFormat.node): | 308 getEnumName(ModuleFormat.node): |
317 'node.js modules (https://nodejs.org/api/modules.html)' | 309 'node.js modules (https://nodejs.org/api/modules.html)' |
318 }, | 310 }, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 // The pub-cache directory is two levels up, but we verify that the layout | 400 // The pub-cache directory is two levels up, but we verify that the layout |
409 // looks correct. | 401 // looks correct. |
410 if (path.basename(dir) != 'dev_compiler') return null; | 402 if (path.basename(dir) != 'dev_compiler') return null; |
411 dir = path.dirname(dir); | 403 dir = path.dirname(dir); |
412 if (path.basename(dir) != 'global_packages') return null; | 404 if (path.basename(dir) != 'global_packages') return null; |
413 dir = path.dirname(dir); | 405 dir = path.dirname(dir); |
414 return path.join(dir, cacheDir, 'lib', 'runtime'); | 406 return path.join(dir, cacheDir, 'lib', 'runtime'); |
415 } | 407 } |
416 return null; | 408 return null; |
417 } | 409 } |
OLD | NEW |