| 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 import "dart:mirrors"; | 9 import "dart:mirrors"; |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 Map _env; | 34 Map _env; |
| 35 List failed = []; | 35 List failed = []; |
| 36 | 36 |
| 37 Resolver(this._env); | 37 Resolver(this._env); |
| 38 | 38 |
| 39 /// Returns the absolute path wrt. to the given environment or null, if the | 39 /// Returns the absolute path wrt. to the given environment or null, if the |
| 40 /// import could not be resolved. | 40 /// import could not be resolved. |
| 41 resolve(String import) { | 41 resolve(String import) { |
| 42 if (import.startsWith(DART_PREFIX)) { | 42 if (import.startsWith(DART_PREFIX)) { |
| 43 if (_env["sdkRoot"] == null) { |
| 44 // No sdk-root given, do not resolve dart: URIs. |
| 45 return null; |
| 46 } |
| 43 var slashPos = import.indexOf("/"); | 47 var slashPos = import.indexOf("/"); |
| 44 var filePath; | 48 var filePath; |
| 45 if (slashPos != -1) { | 49 if (slashPos != -1) { |
| 46 var path = import.substring(DART_PREFIX.length, slashPos); | 50 var path = import.substring(DART_PREFIX.length, slashPos); |
| 47 // Drop patch files, since we don't have their source in the compiled | 51 // Drop patch files, since we don't have their source in the compiled |
| 48 // SDK. | 52 // SDK. |
| 49 if (path.endsWith("-patch")) { | 53 if (path.endsWith("-patch")) { |
| 50 failed.add(import); | 54 failed.add(import); |
| 51 return null; | 55 return null; |
| 52 } | 56 } |
| 53 // Canonicalize path. For instance: _collection-dev => _collection_dev. | 57 // Canonicalize path. For instance: _collection-dev => _collection_dev. |
| 54 path = path.replaceAll("-", "_"); | 58 path = path.replaceAll("-", "_"); |
| 55 filePath = "${_env["sdkRoot"]}" | 59 filePath = "${_env["sdkRoot"]}" |
| 56 "/${path}${import.substring(slashPos, import.length)}"; | 60 "/${path}${import.substring(slashPos, import.length)}"; |
| 57 } else { | 61 } else { |
| 58 // Resolve 'dart:something' to be something/something.dart in the SDK. | 62 // Resolve 'dart:something' to be something/something.dart in the SDK. |
| 59 var lib = import.substring(DART_PREFIX.length, import.length); | 63 var lib = import.substring(DART_PREFIX.length, import.length); |
| 60 filePath = "${_env["sdkRoot"]}/${lib}/${lib}.dart"; | 64 filePath = "${_env["sdkRoot"]}/${lib}/${lib}.dart"; |
| 61 } | 65 } |
| 62 return filePath; | 66 return filePath; |
| 63 } | 67 } |
| 64 if (import.startsWith(PACKAGE_PREFIX)) { | 68 if (import.startsWith(PACKAGE_PREFIX)) { |
| 69 if (_env["pkgRoot"] == null) { |
| 70 // No package-root given, do not resolve package: URIs. |
| 71 return null; |
| 72 } |
| 65 var filePath = | 73 var filePath = |
| 66 "${_env["pkgRoot"]}" | 74 "${_env["pkgRoot"]}" |
| 67 "/${import.substring(PACKAGE_PREFIX.length, import.length)}"; | 75 "/${import.substring(PACKAGE_PREFIX.length, import.length)}"; |
| 68 return filePath; | 76 return filePath; |
| 69 } | 77 } |
| 70 if (import.startsWith(FILE_PREFIX)) { | 78 if (import.startsWith(FILE_PREFIX)) { |
| 71 var filePath = fromUri(Uri.parse(import)); | 79 var filePath = fromUri(Uri.parse(import)); |
| 72 return filePath; | 80 return filePath; |
| 73 } | 81 } |
| 74 if (import.startsWith(HTTP_PREFIX)) { | 82 if (import.startsWith(HTTP_PREFIX)) { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 401 } |
| 394 | 402 |
| 395 /// Checks the validity of the provided arguments. Does not initialize actual | 403 /// Checks the validity of the provided arguments. Does not initialize actual |
| 396 /// processing. | 404 /// processing. |
| 397 parseArgs() { | 405 parseArgs() { |
| 398 var parser = new ArgParser(); | 406 var parser = new ArgParser(); |
| 399 | 407 |
| 400 parser.addOption("sdk-root", abbr: "s", | 408 parser.addOption("sdk-root", abbr: "s", |
| 401 help: "path to the SDK root"); | 409 help: "path to the SDK root"); |
| 402 parser.addOption("package-root", abbr: "p", | 410 parser.addOption("package-root", abbr: "p", |
| 403 help: "path to the package root", | 411 help: "path to the package root"); |
| 404 defaultsTo: "."); | |
| 405 parser.addOption("in", abbr: "i", | 412 parser.addOption("in", abbr: "i", |
| 406 help: "input(s): may be file or directory"); | 413 help: "input(s): may be file or directory"); |
| 407 parser.addOption("out", abbr: "o", | 414 parser.addOption("out", abbr: "o", |
| 408 help: "output: may be file or stdout", | 415 help: "output: may be file or stdout", |
| 409 defaultsTo: "stdout"); | 416 defaultsTo: "stdout"); |
| 410 parser.addOption("workers", abbr: "j", | 417 parser.addOption("workers", abbr: "j", |
| 411 help: "number of workers", | 418 help: "number of workers", |
| 412 defaultsTo: "1"); | 419 defaultsTo: "1"); |
| 413 parser.addFlag("pretty-print", abbr: "r", | 420 parser.addFlag("pretty-print", abbr: "r", |
| 414 help: "convert coverage data to pretty print format", | 421 help: "convert coverage data to pretty print format", |
| (...skipping 19 matching lines...) Expand all Loading... |
| 434 print("\n$msg\n"); | 441 print("\n$msg\n"); |
| 435 printUsage(); | 442 printUsage(); |
| 436 exit(1); | 443 exit(1); |
| 437 } | 444 } |
| 438 | 445 |
| 439 if (args["help"]) { | 446 if (args["help"]) { |
| 440 printUsage(); | 447 printUsage(); |
| 441 exit(0); | 448 exit(0); |
| 442 } | 449 } |
| 443 | 450 |
| 444 if (args["sdk-root"] == null) { | 451 env.sdkRoot = args["sdk-root"]; |
| 452 if (env.sdkRoot == null) { |
| 445 if (Platform.environment.containsKey("SDK_ROOT")) { | 453 if (Platform.environment.containsKey("SDK_ROOT")) { |
| 446 env.sdkRoot = | 454 env.sdkRoot = |
| 447 join(absolute(normalize(Platform.environment["SDK_ROOT"])), "lib"); | 455 join(absolute(normalize(Platform.environment["SDK_ROOT"])), "lib"); |
| 448 } else { | |
| 449 fail("No SDK root found, please specify one using --sdk-root."); | |
| 450 } | 456 } |
| 451 } else { | 457 } else { |
| 452 env.sdkRoot = join(absolute(normalize(args["sdk-root"])), "lib"); | 458 env.sdkRoot = join(absolute(normalize(env.sdkRoot)), "lib"); |
| 453 } | 459 } |
| 454 if (!FileSystemEntity.isDirectorySync(env.sdkRoot)) { | 460 if ((env.sdkRoot != null) && !FileSystemEntity.isDirectorySync(env.sdkRoot)) { |
| 455 fail("Provided SDK root '${args["sdk-root"]}' is not a valid SDK " | 461 fail("Provided SDK root '${args["sdk-root"]}' is not a valid SDK " |
| 456 "top-level directory"); | 462 "top-level directory"); |
| 457 } | 463 } |
| 458 | 464 |
| 459 if (args["package-root"] == null) { | 465 env.pkgRoot = args["package-root"]; |
| 460 env.pkgRoot = absolute(normalize("./packages")); | 466 if (env.pkgRoot != null) { |
| 461 } else { | |
| 462 env.pkgRoot = absolute(normalize(args["package-root"])); | 467 env.pkgRoot = absolute(normalize(args["package-root"])); |
| 463 if (!FileSystemEntity.isDirectorySync(env.pkgRoot)) { | 468 if (!FileSystemEntity.isDirectorySync(env.pkgRoot)) { |
| 464 fail("Provided package root '${args["package-root"]}' is not directory."); | 469 fail("Provided package root '${args["package-root"]}' is not directory."); |
| 465 } | 470 } |
| 466 } | 471 } |
| 467 | 472 |
| 468 if (args["in"] == null) { | 473 if (args["in"] == null) { |
| 469 fail("No input files given."); | 474 fail("No input files given."); |
| 470 } else { | 475 } else { |
| 471 env.input = absolute(normalize(args["in"])); | 476 env.input = absolute(normalize(args["in"])); |
| 472 if (!FileSystemEntity.isDirectorySync(env.input) && | 477 if (!FileSystemEntity.isDirectorySync(env.input) && |
| 473 !FileSystemEntity.isFileSync(env.input)) { | 478 !FileSystemEntity.isFileSync(env.input)) { |
| 474 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.")
; |
| 475 } | 480 } |
| 476 } | 481 } |
| 477 | 482 |
| 478 if (args["out"] == "stdout") { | 483 if (args["out"] == "stdout") { |
| 479 env.output = stdout; | 484 env.output = stdout; |
| 480 } else { | 485 } else { |
| 481 env.output = absolute(normalize(args["out"])); | 486 env.output = absolute(normalize(args["out"])); |
| 482 env.output = new File(env.output).openWrite(); | 487 env.output = new File(env.output).openWrite(); |
| 483 } | 488 } |
| 484 | 489 |
| 485 if (args["pretty-print"] == args["lcov"]) { | 490 env.lcov = args["lcov"]; |
| 486 fail("Choose either pretty-print or lcov output"); | 491 if (args["pretty-print"] && env.lcov) { |
| 492 fail("Choose one of pretty-print or lcov output"); |
| 493 } else if (!env.lcov) { |
| 494 // Use pretty-print either explicitly or by default. |
| 495 env.prettyPrint = true; |
| 487 } | 496 } |
| 488 env.prettyPrint = args["pretty-print"]; | |
| 489 env.lcov = args["lcov"]; | |
| 490 | 497 |
| 491 try { | 498 try { |
| 492 env.workers = int.parse("${args["workers"]}"); | 499 env.workers = int.parse("${args["workers"]}"); |
| 493 } catch (e) { | 500 } catch (e) { |
| 494 fail("Invalid worker count: $e"); | 501 fail("Invalid worker count: $e"); |
| 495 } | 502 } |
| 496 | 503 |
| 497 env.verbose = args["verbose"]; | 504 env.verbose = args["verbose"]; |
| 498 } | 505 } |
| OLD | NEW |