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

Side by Side Diff: tools/full-coverage.dart

Issue 26277003: - Fix usability of coverage tool. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import "package:args/args.dart"; 11 import "package:args/args.dart";
12 import "package:path/path.dart"; 12 import "package:path/path.dart";
13 13
14 /// [Environment] stores gathered arguments information. 14 /// [Environment] stores gathered arguments information.
15 class Environment { 15 class Environment {
16 String sdkRoot; 16 String sdkRoot;
17 String pkgRoot; 17 String pkgRoot;
18 var input; 18 var input;
19 var output; 19 var output;
20 int workers; 20 int workers;
21 bool prettyPrint; 21 bool prettyPrint;
22 bool lcov; 22 bool lcov;
23 bool expectMarkers; 23 bool expectMarkers;
24 bool verbose; 24 bool verbose;
25 } 25 }
26 26
27 /// [Resolver] resolves imports with respect to a given environment. 27 /// [Resolver] resolves imports with respect to a given environment.
28 class Resolver { 28 class Resolver {
29 const DART_PREFIX = "dart:"; 29 final DART_PREFIX = "dart:";
30 const PACKAGE_PREFIX = "package:"; 30 final PACKAGE_PREFIX = "package:";
31 const FILE_PREFIX = "file://"; 31 final FILE_PREFIX = "file://";
32 const HTTP_PREFIX = "http://"; 32 final HTTP_PREFIX = "http://";
siva 2013/10/07 21:56:34 Should these be 'static const' variables instead o
Ivan Posva 2013/10/07 22:07:12 Done.
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)) {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 var start = files.length - filesPerWorker; 380 var start = files.length - filesPerWorker;
381 var end = files.length; 381 var end = files.length;
382 var workerFiles = files.getRange(start, end).toList(); 382 var workerFiles = files.getRange(start, end).toList();
383 files.removeRange(start, end); 383 files.removeRange(start, end);
384 p.send(new Message(Message.WORK, [sharedEnv, workerFiles]), port); 384 p.send(new Message(Message.WORK, [sharedEnv, workerFiles]), port);
385 } 385 }
386 // Let the last worker deal with the rest of the files (which should be only 386 // Let the last worker deal with the rest of the files (which should be only
387 // off by at max (#workers - 1). 387 // off by at max (#workers - 1).
388 var p = spawnFunction(worker); 388 var p = spawnFunction(worker);
389 workerPorts.add(p); 389 workerPorts.add(p);
390 p.send(new Message(Message.WORK, [sharedEnv, files]), port); 390 p.send(new Message(Message.WORK, [sharedEnv, files]), port.toSendPort());
391 391
392 return 0; 392 return 0;
393 } 393 }
394 394
395 /// Checks the validity of the provided arguments. Does not initialize actual 395 /// Checks the validity of the provided arguments. Does not initialize actual
396 /// processing. 396 /// processing.
397 parseArgs() { 397 parseArgs() {
398 var parser = new ArgParser(); 398 var parser = new ArgParser();
399 399
400 parser.addOption("sdk-root", abbr: "s", 400 parser.addOption("sdk-root", abbr: "s",
401 help: "path to the SDK root"); 401 help: "path to the SDK root");
402 parser.addOption("package-root", abbr: "p", 402 parser.addOption("package-root", abbr: "p",
403 help: "path to the package root", 403 help: "path to the package root",
404 defaultsTo: "."); 404 defaultsTo: ".");
405 parser.addOption("in", abbr: "i", 405 parser.addOption("in", abbr: "i",
406 help: "input(s): may be file or directory", 406 help: "input(s): may be file or directory");
407 defaultsTo: "stdin");
408 parser.addOption("out", abbr: "o", 407 parser.addOption("out", abbr: "o",
409 help: "output: may be file or stdout", 408 help: "output: may be file or stdout",
410 defaultsTo: "stdout"); 409 defaultsTo: "stdout");
411 parser.addOption("workers", abbr: "j", 410 parser.addOption("workers", abbr: "j",
412 help: "number of workers", 411 help: "number of workers",
413 defaultsTo: "1"); 412 defaultsTo: "1");
414 parser.addFlag("pretty-print", abbr: "r", 413 parser.addFlag("pretty-print", abbr: "r",
415 help: "convert coverage data to pretty print format", 414 help: "convert coverage data to pretty print format",
416 negatable: false); 415 negatable: false);
417 parser.addFlag("lcov", abbr :"l", 416 parser.addFlag("lcov", abbr :"l",
418 help: "convert coverage data to lcov format", 417 help: "convert coverage data to lcov format",
419 negatable: false); 418 negatable: false);
420 parser.addFlag("verbose", abbr :"v", 419 parser.addFlag("verbose", abbr :"v",
421 help: "verbose output", 420 help: "verbose output",
422 negatable: false); 421 negatable: false);
423 parser.addFlag("help", abbr: "h", 422 parser.addFlag("help", abbr: "h",
424 help: "show this help", 423 help: "show this help",
425 negatable: false); 424 negatable: false);
426 425
427 var args = parser.parse(new Options().arguments); 426 var args = parser.parse(new Options().arguments);
428 427
428 printUsage() {
429 print("Usage: dart full-coverage.dart [OPTION...]\n");
430 print(parser.getUsage());
431 }
432
433 fail(String msg) {
434 print("\n$msg\n");
435 printUsage();
436 exit(1);
437 }
438
429 if (args["help"]) { 439 if (args["help"]) {
430 print("Usage: coverage [OPTION...]\n"); 440 printUsage();
431 print(parser.getUsage());
432 exit(0); 441 exit(0);
433 } 442 }
434 443
435 if (args["sdk-root"] == null) { 444 if (args["sdk-root"] == null) {
436 if (Platform.environment.containsKey("SDK_ROOT")) { 445 if (Platform.environment.containsKey("SDK_ROOT")) {
437 env.sdkRoot = 446 env.sdkRoot =
438 join(absolute(normalize(Platform.environment["SDK_ROOT"])), "lib"); 447 join(absolute(normalize(Platform.environment["SDK_ROOT"])), "lib");
439 } else { 448 } else {
440 throw "No SDK root found, please specify one using --sdk-root."; 449 fail("No SDK root found, please specify one using --sdk-root.");
441 } 450 }
442 } else { 451 } else {
443 env.sdkRoot = join(absolute(normalize(args["sdk-root"])), "lib"); 452 env.sdkRoot = join(absolute(normalize(args["sdk-root"])), "lib");
444 } 453 }
445 if (!FileSystemEntity.isDirectorySync(env.sdkRoot)) { 454 if (!FileSystemEntity.isDirectorySync(env.sdkRoot)) {
446 throw "Provided SDK root ${args["sdk-root"]} is not a valid SDK " 455 fail("Provided SDK root '${args["sdk-root"]}' is not a valid SDK "
447 "top-level directory"; 456 "top-level directory");
448 } 457 }
449 458
450 if (args["package-root"] == null) { 459 if (args["package-root"] == null) {
451 env.pkgRoot = absolute(normalize("./packages")); 460 env.pkgRoot = absolute(normalize("./packages"));
452 } else { 461 } else {
453 env.pkgRoot = absolute(normalize(args["package-root"])); 462 env.pkgRoot = absolute(normalize(args["package-root"]));
454 if (!FileSystemEntity.isDirectorySync(env.pkgRoot)) { 463 if (!FileSystemEntity.isDirectorySync(env.pkgRoot)) {
455 throw "Provided package root ${args["package-root"]} is not directory."; 464 fail("Provided package root '${args["package-root"]}' is not directory.");
456 } 465 }
457 } 466 }
458 467
459 if (args["in"] == "stdin") { 468 if (args["in"] == null) {
460 env.input = "stdin"; 469 fail("No input files given.");
461 } else { 470 } else {
462 env.input = absolute(normalize(args["in"])); 471 env.input = absolute(normalize(args["in"]));
463 if (!FileSystemEntity.isDirectorySync(env.input) && 472 if (!FileSystemEntity.isDirectorySync(env.input) &&
464 !FileSystemEntity.isFileSync(env.input)) { 473 !FileSystemEntity.isFileSync(env.input)) {
465 throw "Provided input ${args["in"]} is neither a directory, nor a file."; 474 fail("Provided input '${args["in"]}' is neither a directory, nor a file.") ;
466 } 475 }
467 } 476 }
468 477
469 if (args["out"] == "stdout") { 478 if (args["out"] == "stdout") {
470 env.output = stdout; 479 env.output = stdout;
471 } else { 480 } else {
472 env.output = absolute(normalize(args["out"])); 481 env.output = absolute(normalize(args["out"]));
473 env.output = new File(env.output).openWrite(); 482 env.output = new File(env.output).openWrite();
474 } 483 }
475 484
476 if (args["pretty-print"] && 485 if (args["pretty-print"] == args["lcov"]) {
477 args["lcov"]) { 486 fail("Choose either pretty-print or lcov output");
478 throw "Choose either pretty-print or lcov output"; 487 }
488 env.prettyPrint = args["pretty-print"];
489 env.lcov = args["lcov"];
490
491 try {
492 env.workers = int.parse("${args["workers"]}");
493 } catch (e) {
494 fail("Invalid worker count: $e");
479 } 495 }
480 496
481 env.prettyPrint = args["pretty-print"];
482 env.lcov = args["lcov"];
483 env.verbose = args["verbose"]; 497 env.verbose = args["verbose"];
484 env.workers = int.parse("${args["workers"]}");
485 } 498 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698