OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:convert"; | 6 import "dart:convert"; |
7 import "dart:io"; | 7 import "dart:io"; |
8 import "dart:isolate"; | 8 import "dart:isolate"; |
9 | 9 |
10 import "package:args/args.dart"; | 10 import "package:args/args.dart"; |
11 import "package:path/path.dart"; | 11 import "package:path/path.dart"; |
12 | 12 |
13 /// [Environment] stores gathered arguments information. | 13 /// [Environment] stores gathered arguments information. |
14 class Environment { | 14 class Environment { |
15 String sdkRoot; | 15 String sdkRoot; |
16 String pkgRoot; | 16 String pkgRoot; |
17 var input; | 17 var input; |
18 var output; | 18 var output; |
19 int workers; | 19 int workers; |
20 bool prettyPrint; | 20 bool prettyPrint = false; |
21 bool lcov; | 21 bool lcov = false; |
22 bool expectMarkers; | 22 bool expectMarkers; |
23 bool verbose; | 23 bool verbose; |
24 } | 24 } |
25 | 25 |
26 /// [Resolver] resolves imports with respect to a given environment. | 26 /// [Resolver] resolves imports with respect to a given environment. |
27 class Resolver { | 27 class Resolver { |
28 static const DART_PREFIX = "dart:"; | 28 static const DART_PREFIX = "dart:"; |
29 static const PACKAGE_PREFIX = "package:"; | 29 static const PACKAGE_PREFIX = "package:"; |
30 static const FILE_PREFIX = "file://"; | 30 static const FILE_PREFIX = "file://"; |
31 static const HTTP_PREFIX = "http://"; | 31 static const HTTP_PREFIX = "http://"; |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 398 } |
399 | 399 |
400 /// Checks the validity of the provided arguments. Does not initialize actual | 400 /// Checks the validity of the provided arguments. Does not initialize actual |
401 /// processing. | 401 /// processing. |
402 parseArgs(List<String> arguments) { | 402 parseArgs(List<String> arguments) { |
403 var parser = new ArgParser(); | 403 var parser = new ArgParser(); |
404 | 404 |
405 parser.addOption("sdk-root", abbr: "s", | 405 parser.addOption("sdk-root", abbr: "s", |
406 help: "path to the SDK root"); | 406 help: "path to the SDK root"); |
407 parser.addOption("package-root", abbr: "p", | 407 parser.addOption("package-root", abbr: "p", |
408 help: "path to the package root"); | 408 help: "override path to the package root " |
| 409 "(default: inherited from dart)"); |
409 parser.addOption("in", abbr: "i", | 410 parser.addOption("in", abbr: "i", |
410 help: "input(s): may be file or directory"); | 411 help: "input(s): may be file or directory"); |
411 parser.addOption("out", abbr: "o", | 412 parser.addOption("out", abbr: "o", |
412 help: "output: may be file or stdout", | 413 help: "output: may be file or stdout", |
413 defaultsTo: "stdout"); | 414 defaultsTo: "stdout"); |
414 parser.addOption("workers", abbr: "j", | 415 parser.addOption("workers", abbr: "j", |
415 help: "number of workers", | 416 help: "number of workers", |
416 defaultsTo: "1"); | 417 defaultsTo: "1"); |
417 parser.addFlag("pretty-print", abbr: "r", | 418 parser.addFlag("pretty-print", abbr: "r", |
418 help: "convert coverage data to pretty print format", | 419 help: "convert coverage data to pretty print format", |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 fail("Provided SDK root '${args["sdk-root"]}' is not a valid SDK " | 459 fail("Provided SDK root '${args["sdk-root"]}' is not a valid SDK " |
459 "top-level directory"); | 460 "top-level directory"); |
460 } | 461 } |
461 | 462 |
462 env.pkgRoot = args["package-root"]; | 463 env.pkgRoot = args["package-root"]; |
463 if (env.pkgRoot != null) { | 464 if (env.pkgRoot != null) { |
464 env.pkgRoot = absolute(normalize(args["package-root"])); | 465 env.pkgRoot = absolute(normalize(args["package-root"])); |
465 if (!FileSystemEntity.isDirectorySync(env.pkgRoot)) { | 466 if (!FileSystemEntity.isDirectorySync(env.pkgRoot)) { |
466 fail("Provided package root '${args["package-root"]}' is not directory."); | 467 fail("Provided package root '${args["package-root"]}' is not directory."); |
467 } | 468 } |
| 469 } else { |
| 470 env.pkgRoot = Platform.packageRoot; |
468 } | 471 } |
469 | 472 |
470 if (args["in"] == null) { | 473 if (args["in"] == null) { |
471 fail("No input files given."); | 474 fail("No input files given."); |
472 } else { | 475 } else { |
473 env.input = absolute(normalize(args["in"])); | 476 env.input = absolute(normalize(args["in"])); |
474 if (!FileSystemEntity.isDirectorySync(env.input) && | 477 if (!FileSystemEntity.isDirectorySync(env.input) && |
475 !FileSystemEntity.isFileSync(env.input)) { | 478 !FileSystemEntity.isFileSync(env.input)) { |
476 fail("Provided input '${args["in"]}' is neither a directory, nor a file.")
; | 479 fail("Provided input '${args["in"]}' is neither a directory, nor a file.")
; |
477 } | 480 } |
(...skipping 15 matching lines...) Expand all Loading... |
493 } | 496 } |
494 | 497 |
495 try { | 498 try { |
496 env.workers = int.parse("${args["workers"]}"); | 499 env.workers = int.parse("${args["workers"]}"); |
497 } catch (e) { | 500 } catch (e) { |
498 fail("Invalid worker count: $e"); | 501 fail("Invalid worker count: $e"); |
499 } | 502 } |
500 | 503 |
501 env.verbose = args["verbose"]; | 504 env.verbose = args["verbose"]; |
502 } | 505 } |
OLD | NEW |