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

Side by Side Diff: tools/testing/dart/command.dart

Issue 2946783002: Simplify CommandOutput and friends. (Closed)
Patch Set: Merge branch 'master' into simplify-command-output Created 3 years, 6 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
« no previous file with comments | « tools/testing/dart/browser_controller.dart ('k') | tools/testing/dart/command_output.dart » ('j') | 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 // We need to use the 'io' prefix here, otherwise io.exitCode will shadow 6 // We need to use the 'io' prefix here, otherwise io.exitCode will shadow
7 // CommandOutput.exitCode in subclasses of CommandOutput. 7 // CommandOutput.exitCode in subclasses of CommandOutput.
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 import 'command_output.dart'; 10 import 'command_output.dart';
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 this._alwaysCompile, 230 this._alwaysCompile,
231 this._bootstrapDependencies, 231 this._bootstrapDependencies,
232 String executable, 232 String executable,
233 List<String> arguments, 233 List<String> arguments,
234 Map<String, String> environmentOverrides) 234 Map<String, String> environmentOverrides)
235 : super._(displayName, executable, arguments, environmentOverrides); 235 : super._(displayName, executable, arguments, environmentOverrides);
236 236
237 bool get outputIsUpToDate { 237 bool get outputIsUpToDate {
238 if (_alwaysCompile) return false; 238 if (_alwaysCompile) return false;
239 239
240 List<Uri> readDepsFile(String path) { 240 var file = new io.File(new Path("$_outputFile.deps").toNativePath());
241 var file = new io.File(new Path(path).toNativePath()); 241 if (!file.existsSync()) return false;
242 if (!file.existsSync()) return null;
243 242
244 var lines = file.readAsLinesSync(); 243 var lines = file.readAsLinesSync();
245 var dependencies = <Uri>[]; 244 var dependencies = <Uri>[];
246 for (var line in lines) { 245 for (var line in lines) {
247 line = line.trim(); 246 line = line.trim();
248 if (line.isNotEmpty) { 247 if (line.isNotEmpty) {
249 dependencies.add(Uri.parse(line)); 248 dependencies.add(Uri.parse(line));
250 }
251 } 249 }
252
253 return dependencies;
254 } 250 }
255 251
256 var dependencies = readDepsFile("$_outputFile.deps");
257 if (dependencies == null) return false;
258
259 dependencies.addAll(_bootstrapDependencies); 252 dependencies.addAll(_bootstrapDependencies);
260 var jsOutputLastModified = TestUtils.lastModifiedCache 253 var jsOutputLastModified = TestUtils.lastModifiedCache
261 .getLastModified(new Uri(scheme: 'file', path: _outputFile)); 254 .getLastModified(new Uri(scheme: 'file', path: _outputFile));
262 if (jsOutputLastModified == null) return false; 255 if (jsOutputLastModified == null) return false;
263 256
264 for (var dependency in dependencies) { 257 for (var dependency in dependencies) {
265 var dependencyLastModified = 258 var dependencyLastModified =
266 TestUtils.lastModifiedCache.getLastModified(dependency); 259 TestUtils.lastModifiedCache.getLastModified(dependency);
267 if (dependencyLastModified == null || 260 if (dependencyLastModified == null ||
268 dependencyLastModified.isAfter(jsOutputLastModified)) { 261 dependencyLastModified.isAfter(jsOutputLastModified)) {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 498 }
506 499
507 bool _equal(PubCommand other) => 500 bool _equal(PubCommand other) =>
508 super._equal(other) && command == other.command; 501 super._equal(other) && command == other.command;
509 } 502 }
510 503
511 /// [ScriptCommand]s are executed by dart code. 504 /// [ScriptCommand]s are executed by dart code.
512 abstract class ScriptCommand extends Command { 505 abstract class ScriptCommand extends Command {
513 ScriptCommand._(String displayName) : super._(displayName); 506 ScriptCommand._(String displayName) : super._(displayName);
514 507
515 Future<ScriptCommandOutputImpl> run(); 508 Future<ScriptCommandOutput> run();
516 } 509 }
517 510
518 class CleanDirectoryCopyCommand extends ScriptCommand { 511 class CleanDirectoryCopyCommand extends ScriptCommand {
519 final String _sourceDirectory; 512 final String _sourceDirectory;
520 final String _destinationDirectory; 513 final String _destinationDirectory;
521 514
522 CleanDirectoryCopyCommand._(this._sourceDirectory, this._destinationDirectory) 515 CleanDirectoryCopyCommand._(this._sourceDirectory, this._destinationDirectory)
523 : super._('dir_copy'); 516 : super._('dir_copy');
524 517
525 String get reproductionCommand => 518 String get reproductionCommand =>
526 "Copying '$_sourceDirectory' to '$_destinationDirectory'."; 519 "Copying '$_sourceDirectory' to '$_destinationDirectory'.";
527 520
528 Future<ScriptCommandOutputImpl> run() { 521 Future<ScriptCommandOutput> run() {
529 var watch = new Stopwatch()..start(); 522 var watch = new Stopwatch()..start();
530 523
531 var destination = new io.Directory(_destinationDirectory); 524 var destination = new io.Directory(_destinationDirectory);
532 525
533 return destination.exists().then((bool exists) { 526 return destination.exists().then((bool exists) {
534 Future cleanDirectoryFuture; 527 Future cleanDirectoryFuture;
535 if (exists) { 528 if (exists) {
536 cleanDirectoryFuture = TestUtils.deleteDirectory(_destinationDirectory); 529 cleanDirectoryFuture = TestUtils.deleteDirectory(_destinationDirectory);
537 } else { 530 } else {
538 cleanDirectoryFuture = new Future.value(null); 531 cleanDirectoryFuture = new Future.value(null);
539 } 532 }
540 return cleanDirectoryFuture.then((_) { 533 return cleanDirectoryFuture.then((_) {
541 return TestUtils.copyDirectory(_sourceDirectory, _destinationDirectory); 534 return TestUtils.copyDirectory(_sourceDirectory, _destinationDirectory);
542 }); 535 });
543 }).then((_) { 536 }).then((_) {
544 return new ScriptCommandOutputImpl( 537 return new ScriptCommandOutput(this, Expectation.pass, "", watch.elapsed);
545 this, Expectation.pass, "", watch.elapsed);
546 }).catchError((error) { 538 }).catchError((error) {
547 return new ScriptCommandOutputImpl( 539 return new ScriptCommandOutput(
548 this, Expectation.fail, "An error occured: $error.", watch.elapsed); 540 this, Expectation.fail, "An error occured: $error.", watch.elapsed);
549 }); 541 });
550 } 542 }
551 543
552 void _buildHashCode(HashCodeBuilder builder) { 544 void _buildHashCode(HashCodeBuilder builder) {
553 super._buildHashCode(builder); 545 super._buildHashCode(builder);
554 builder.addJson(_sourceDirectory); 546 builder.addJson(_sourceDirectory);
555 builder.addJson(_destinationDirectory); 547 builder.addJson(_destinationDirectory);
556 } 548 }
557 549
558 bool _equal(CleanDirectoryCopyCommand other) => 550 bool _equal(CleanDirectoryCopyCommand other) =>
559 super._equal(other) && 551 super._equal(other) &&
560 _sourceDirectory == other._sourceDirectory && 552 _sourceDirectory == other._sourceDirectory &&
561 _destinationDirectory == other._destinationDirectory; 553 _destinationDirectory == other._destinationDirectory;
562 } 554 }
563 555
564 /// Makes a symbolic link to another directory. 556 /// Makes a symbolic link to another directory.
565 class MakeSymlinkCommand extends ScriptCommand { 557 class MakeSymlinkCommand extends ScriptCommand {
566 String _link; 558 String _link;
567 String _target; 559 String _target;
568 560
569 MakeSymlinkCommand._(this._link, this._target) : super._('make_symlink'); 561 MakeSymlinkCommand._(this._link, this._target) : super._('make_symlink');
570 562
571 String get reproductionCommand => 563 String get reproductionCommand =>
572 "Make symbolic link '$_link' (target: $_target)'."; 564 "Make symbolic link '$_link' (target: $_target)'.";
573 565
574 Future<ScriptCommandOutputImpl> run() { 566 Future<ScriptCommandOutput> run() {
575 var watch = new Stopwatch()..start(); 567 var watch = new Stopwatch()..start();
576 var targetFile = new io.Directory(_target); 568 var targetFile = new io.Directory(_target);
577 return targetFile.exists().then((bool targetExists) { 569 return targetFile.exists().then((bool targetExists) {
578 if (!targetExists) { 570 if (!targetExists) {
579 throw new Exception("Target '$_target' does not exist"); 571 throw new Exception("Target '$_target' does not exist");
580 } 572 }
581 var link = new io.Link(_link); 573 var link = new io.Link(_link);
582 574
583 return link.exists().then((bool exists) { 575 return link.exists().then((bool exists) {
584 if (exists) return link.delete(); 576 if (exists) return link.delete();
585 }).then((_) => link.create(_target)); 577 }).then((_) => link.create(_target));
586 }).then((_) { 578 }).then((_) {
587 return new ScriptCommandOutputImpl( 579 return new ScriptCommandOutput(this, Expectation.pass, "", watch.elapsed);
588 this, Expectation.pass, "", watch.elapsed);
589 }).catchError((error) { 580 }).catchError((error) {
590 return new ScriptCommandOutputImpl( 581 return new ScriptCommandOutput(
591 this, Expectation.fail, "An error occured: $error.", watch.elapsed); 582 this, Expectation.fail, "An error occured: $error.", watch.elapsed);
592 }); 583 });
593 } 584 }
594 585
595 void _buildHashCode(HashCodeBuilder builder) { 586 void _buildHashCode(HashCodeBuilder builder) {
596 super._buildHashCode(builder); 587 super._buildHashCode(builder);
597 builder.addJson(_link); 588 builder.addJson(_link);
598 builder.addJson(_target); 589 builder.addJson(_target);
599 } 590 }
600 591
601 bool _equal(MakeSymlinkCommand other) => 592 bool _equal(MakeSymlinkCommand other) =>
602 super._equal(other) && _link == other._link && _target == other._target; 593 super._equal(other) && _link == other._link && _target == other._target;
603 } 594 }
OLDNEW
« no previous file with comments | « tools/testing/dart/browser_controller.dart ('k') | tools/testing/dart/command_output.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698