Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: lib/src/options.dart

Issue 1322333003: DDC: mostly incremental compilation, fixes #223 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 /// package (if we can infer where that is located). 138 /// package (if we can infer where that is located).
139 final String runtimeDir; 139 final String runtimeDir;
140 140
141 /// The files to compile. 141 /// The files to compile.
142 final List<String> inputs; 142 final List<String> inputs;
143 143
144 /// The base directory for [inputs]. Module imports will be generated relative 144 /// The base directory for [inputs]. Module imports will be generated relative
145 /// to this directory. 145 /// to this directory.
146 final String inputBaseDir; 146 final String inputBaseDir;
147 147
148 /// True to save compiler messages to a file.
149 /// Useful for incremental compilation and tests.
150 final bool saveMessages;
151
148 CompilerOptions( 152 CompilerOptions(
149 {this.strongOptions: const StrongModeOptions(), 153 {this.strongOptions: const StrongModeOptions(),
150 this.sourceOptions: const SourceResolverOptions(), 154 this.sourceOptions: const SourceResolverOptions(),
151 this.codegenOptions: const CodegenOptions(), 155 this.codegenOptions: const CodegenOptions(),
152 this.runnerOptions: const RunnerOptions(), 156 this.runnerOptions: const RunnerOptions(),
153 this.checkSdk: false, 157 this.checkSdk: false,
154 this.dumpInfo: false, 158 this.dumpInfo: false,
155 this.dumpInfoFile, 159 this.dumpInfoFile,
156 this.useColors: true, 160 this.useColors: true,
157 this.help: false, 161 this.help: false,
158 this.logLevel: Level.SEVERE, 162 this.logLevel: Level.SEVERE,
159 this.serverMode: false, 163 this.serverMode: false,
160 this.enableHashing: false, 164 this.enableHashing: false,
161 this.widget: true, 165 this.widget: true,
162 this.host: 'localhost', 166 this.host: 'localhost',
163 this.port: 8080, 167 this.port: 8080,
164 this.runtimeDir, 168 this.runtimeDir,
165 this.inputs, 169 this.inputs: const [],
166 this.inputBaseDir}); 170 this.inputBaseDir,
171 this.saveMessages: false});
167 } 172 }
168 173
169 /// Parses options from the command-line 174 /// Parses options from the command-line
170 CompilerOptions parseOptions(List<String> argv, {bool forceOutDir: false}) { 175 CompilerOptions parseOptions(List<String> argv, {bool forceOutDir: false}) {
171 ArgResults args = argParser.parse(argv); 176 ArgResults args = argParser.parse(argv);
172 bool showUsage = args['help']; 177 bool showUsage = args['help'];
173 178
174 var serverMode = args['server']; 179 var serverMode = args['server'];
175 var enableHashing = args['hashing']; 180 var enableHashing = args['hashing'];
176 if (enableHashing == null) { 181 if (enableHashing == null) {
177 enableHashing = serverMode; 182 enableHashing = serverMode;
178 } 183 }
179 // TODO(jmesserly): shouldn't level always default to warning? 184 // TODO(jmesserly): shouldn't level always default to warning?
180 var logLevel = serverMode ? Level.WARNING : Level.SEVERE; 185 var logLevel = serverMode ? Level.WARNING : Level.SEVERE;
181 var levelName = args['log']; 186 var levelName = args['log'];
182 if (levelName != null) { 187 if (levelName != null) {
183 levelName = levelName.toUpperCase(); 188 levelName = levelName.toUpperCase();
184 logLevel = Level.LEVELS 189 logLevel = Level.LEVELS
185 .firstWhere((l) => l.name == levelName, orElse: () => logLevel); 190 .firstWhere((l) => l.name == levelName, orElse: () => logLevel);
186 } 191 }
187 var useColors = stdioType(stdout) == StdioType.TERMINAL; 192 var useColors = stdioType(stdout) == StdioType.TERMINAL;
188 var sdkPath = args['dart-sdk']; 193 var sdkPath = args['dart-sdk'];
189 if (sdkPath == null && !args['mock-sdk']) { 194 if (sdkPath == null && !args['mock-sdk']) {
190 sdkPath = getSdkDir(argv).path; 195 sdkPath = getSdkDir(argv).path;
191 } 196 }
192 var runtimeDir = args['runtime-dir']; 197 var runtimeDir = args['runtime-dir'];
193 if (runtimeDir == null) { 198 if (runtimeDir == null) {
194 runtimeDir = _computeRuntimeDir(); 199 runtimeDir = _computedRuntimeDir;
195 } 200 }
196 var outputDir = args['out']; 201 var outputDir = args['out'];
197 if (outputDir == null && (serverMode || forceOutDir)) { 202 if (outputDir == null && (serverMode || forceOutDir)) {
198 outputDir = Directory.systemTemp.createTempSync("dev_compiler_out_").path; 203 outputDir = Directory.systemTemp.createTempSync("dev_compiler_out_").path;
199 } 204 }
200 var dumpInfo = args['dump-info']; 205 var dumpInfo = args['dump-info'];
201 if (dumpInfo == null) dumpInfo = serverMode; 206 if (dumpInfo == null) dumpInfo = serverMode;
202 207
203 var v8Binary = args['v8-binary']; 208 var v8Binary = args['v8-binary'];
204 if (v8Binary == null) v8Binary = 'iojs'; 209 if (v8Binary == null) v8Binary = 'iojs';
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 dumpInfoFile: args['dump-info-file'], 246 dumpInfoFile: args['dump-info-file'],
242 useColors: useColors, 247 useColors: useColors,
243 help: showUsage, 248 help: showUsage,
244 logLevel: logLevel, 249 logLevel: logLevel,
245 serverMode: serverMode, 250 serverMode: serverMode,
246 enableHashing: enableHashing, 251 enableHashing: enableHashing,
247 widget: args['widget'], 252 widget: args['widget'],
248 host: args['host'], 253 host: args['host'],
249 port: int.parse(args['port']), 254 port: int.parse(args['port']),
250 runtimeDir: runtimeDir, 255 runtimeDir: runtimeDir,
256 saveMessages: args['save-messages'],
251 inputs: args.rest); 257 inputs: args.rest);
252 } 258 }
253 259
254 final ArgParser argParser = StrongModeOptions.addArguments(new ArgParser() 260 final ArgParser argParser = StrongModeOptions.addArguments(new ArgParser()
255 ..addFlag('sdk-check', 261 ..addFlag('sdk-check',
256 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false) 262 abbr: 's', help: 'Typecheck sdk libs', defaultsTo: false)
257 ..addFlag('mock-sdk', 263 ..addFlag('mock-sdk',
258 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false) 264 abbr: 'm', help: 'Use a mock Dart SDK', defaultsTo: false)
259 265
260 // input/output options 266 // input/output options
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 help: 'Compile code with static errors', defaultsTo: false) 314 help: 'Compile code with static errors', defaultsTo: false)
309 ..addOption('log', abbr: 'l', help: 'Logging level (defaults to severe)') 315 ..addOption('log', abbr: 'l', help: 'Logging level (defaults to severe)')
310 ..addFlag('dump-info', 316 ..addFlag('dump-info',
311 abbr: 'i', help: 'Dump summary information', defaultsTo: null) 317 abbr: 'i', help: 'Dump summary information', defaultsTo: null)
312 ..addOption('v8-binary', 318 ..addOption('v8-binary',
313 help: 'V8-based binary to run JavaScript output with (iojs, node, d8)', 319 help: 'V8-based binary to run JavaScript output with (iojs, node, d8)',
314 defaultsTo: 'iojs') 320 defaultsTo: 'iojs')
315 ..addOption('dump-info-file', 321 ..addOption('dump-info-file',
316 abbr: 'f', 322 abbr: 'f',
317 help: 'Dump info json file (requires dump-info)', 323 help: 'Dump info json file (requires dump-info)',
318 defaultsTo: null)); 324 defaultsTo: null)
325 ..addFlag('save-messages', help: 'Save compiler messages to a text file'));
319 326
320 /// Tries to find the `lib/runtime/` directory of the dev_compiler package. This 327 /// Tries to find the `lib/runtime/` directory of the dev_compiler package. This
321 /// works when running devc from it's sources or from a snapshot that is 328 /// works when running devc from it's sources or from a snapshot that is
322 /// activated via `pub global activate`. 329 /// activated via `pub global activate`.
323 String _computeRuntimeDir() { 330 final String _computedRuntimeDir = () {
331 // TODO(jmesserly): if we're in the test runner we can't get our runtime path.
332 if (Platform.script.scheme == 'data') return null;
333
324 var scriptPath = path.fromUri(Platform.script); 334 var scriptPath = path.fromUri(Platform.script);
325 var file = path.basename(scriptPath); 335 var file = path.basename(scriptPath);
326 var dir = path.dirname(scriptPath); 336 var dir = path.dirname(scriptPath);
327 var lastdir = path.basename(dir); 337 var lastdir = path.basename(dir);
328 dir = path.dirname(dir); 338 dir = path.dirname(dir);
329 339
330 // Both the source devc.dart and the snapshot generated by pub global activate 340 // Both the source devc.dart and the snapshot generated by pub global activate
331 // are under a bin folder. 341 // are under a bin folder.
332 if (lastdir != 'bin') return null; 342 if (lastdir != 'bin') return null;
333 343
(...skipping 26 matching lines...) Expand all
360 // We should be under "/path/to/pub-cache/global_packages/dev_compiler". 370 // We should be under "/path/to/pub-cache/global_packages/dev_compiler".
361 // The pub-cache directory is two levels up, but we verify that the layout 371 // The pub-cache directory is two levels up, but we verify that the layout
362 // looks correct. 372 // looks correct.
363 if (path.basename(dir) != 'dev_compiler') return null; 373 if (path.basename(dir) != 'dev_compiler') return null;
364 dir = path.dirname(dir); 374 dir = path.dirname(dir);
365 if (path.basename(dir) != 'global_packages') return null; 375 if (path.basename(dir) != 'global_packages') return null;
366 dir = path.dirname(dir); 376 dir = path.dirname(dir);
367 return path.join(dir, cacheDir, 'lib', 'runtime'); 377 return path.join(dir, cacheDir, 'lib', 'runtime');
368 } 378 }
369 return null; 379 return null;
370 } 380 }();
381
382 /// The timestamp of the compiler itself. Used to invalidate output if the
383 /// compiler itself changes.
Leaf 2015/09/04 21:46:31 At some point, we should probably include a versio
384 final DateTime compilerLastModified = () {
385 if (_computedRuntimeDir == null) return null;
386
387 DateTime lastModify = null;
388 var compilerLib = new Directory(path.join(_computedRuntimeDir, '..'));
389 for (var file in compilerLib.listSync(recursive: true)) {
390 if (file is File && file.path.endsWith('.dart')) {
391 var modify = file.lastModifiedSync();
392 if (lastModify == null || modify.isAfter(lastModify)) lastModify = modify;
393 }
394 }
395 return lastModify;
396 }();
OLDNEW
« lib/src/compiler.dart ('K') | « lib/src/compiler.dart ('k') | lib/src/report.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698