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 = false; | 20 bool prettyPrint; |
21 bool lcov = false; | 21 bool lcov; |
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: "override path to the package root " | 408 help: "path to the package root"); |
409 "(default: inherited from dart)"); | |
410 parser.addOption("in", abbr: "i", | 409 parser.addOption("in", abbr: "i", |
411 help: "input(s): may be file or directory"); | 410 help: "input(s): may be file or directory"); |
412 parser.addOption("out", abbr: "o", | 411 parser.addOption("out", abbr: "o", |
413 help: "output: may be file or stdout", | 412 help: "output: may be file or stdout", |
414 defaultsTo: "stdout"); | 413 defaultsTo: "stdout"); |
415 parser.addOption("workers", abbr: "j", | 414 parser.addOption("workers", abbr: "j", |
416 help: "number of workers", | 415 help: "number of workers", |
417 defaultsTo: "1"); | 416 defaultsTo: "1"); |
418 parser.addFlag("pretty-print", abbr: "r", | 417 parser.addFlag("pretty-print", abbr: "r", |
419 help: "convert coverage data to pretty print format", | 418 help: "convert coverage data to pretty print format", |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 fail("Provided SDK root '${args["sdk-root"]}' is not a valid SDK " | 458 fail("Provided SDK root '${args["sdk-root"]}' is not a valid SDK " |
460 "top-level directory"); | 459 "top-level directory"); |
461 } | 460 } |
462 | 461 |
463 env.pkgRoot = args["package-root"]; | 462 env.pkgRoot = args["package-root"]; |
464 if (env.pkgRoot != null) { | 463 if (env.pkgRoot != null) { |
465 env.pkgRoot = absolute(normalize(args["package-root"])); | 464 env.pkgRoot = absolute(normalize(args["package-root"])); |
466 if (!FileSystemEntity.isDirectorySync(env.pkgRoot)) { | 465 if (!FileSystemEntity.isDirectorySync(env.pkgRoot)) { |
467 fail("Provided package root '${args["package-root"]}' is not directory."); | 466 fail("Provided package root '${args["package-root"]}' is not directory."); |
468 } | 467 } |
469 } else { | |
470 env.pkgRoot = Platform.packageRoot; | |
471 } | 468 } |
472 | 469 |
473 if (args["in"] == null) { | 470 if (args["in"] == null) { |
474 fail("No input files given."); | 471 fail("No input files given."); |
475 } else { | 472 } else { |
476 env.input = absolute(normalize(args["in"])); | 473 env.input = absolute(normalize(args["in"])); |
477 if (!FileSystemEntity.isDirectorySync(env.input) && | 474 if (!FileSystemEntity.isDirectorySync(env.input) && |
478 !FileSystemEntity.isFileSync(env.input)) { | 475 !FileSystemEntity.isFileSync(env.input)) { |
479 fail("Provided input '${args["in"]}' is neither a directory, nor a file.")
; | 476 fail("Provided input '${args["in"]}' is neither a directory, nor a file.")
; |
480 } | 477 } |
(...skipping 15 matching lines...) Expand all Loading... |
496 } | 493 } |
497 | 494 |
498 try { | 495 try { |
499 env.workers = int.parse("${args["workers"]}"); | 496 env.workers = int.parse("${args["workers"]}"); |
500 } catch (e) { | 497 } catch (e) { |
501 fail("Invalid worker count: $e"); | 498 fail("Invalid worker count: $e"); |
502 } | 499 } |
503 | 500 |
504 env.verbose = args["verbose"]; | 501 env.verbose = args["verbose"]; |
505 } | 502 } |
OLD | NEW |