forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.dart
94 lines (79 loc) · 2.51 KB
/
run.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io' as io;
import 'package:args/command_runner.dart';
import 'common.dart';
import 'pipeline.dart';
import 'steps/compile_tests_step.dart';
import 'steps/run_tests_step.dart';
import 'utils.dart';
/// Runs build and test steps.
///
/// This command is designed to be invoked by the LUCI build graph. However, it
/// is also usable locally.
///
/// Usage:
///
/// felt run name_of_build_step
class RunCommand extends Command<bool> with ArgUtils<bool> {
RunCommand() {
argParser.addFlag(
'list',
abbr: 'l',
defaultsTo: false,
help: 'Lists all available build steps.',
);
}
@override
String get name => 'run';
bool get isListSteps => boolArg('list');
@override
String get description => 'Runs a build step.';
/// Build steps to run, in order specified.
List<String> get stepNames => argResults!.rest;
@override
FutureOr<bool> run() async {
// All available build steps.
final Map<String, PipelineStep> buildSteps = <String, PipelineStep>{
'compile_tests': CompileTestsStep(),
for (final String browserName in kAllBrowserNames)
'run_tests_$browserName': RunTestsStep(
browserEnvironment: getBrowserEnvironment(browserName),
isDebug: false,
doUpdateScreenshotGoldens: false,
),
};
if (isListSteps) {
buildSteps.keys.forEach(print);
return true;
}
if (stepNames.isEmpty) {
throw UsageException('No build steps specified.', argParser.usage);
}
final List<String> unrecognizedStepNames = <String>[];
for (final String stepName in stepNames) {
if (!buildSteps.containsKey(stepName)) {
unrecognizedStepNames.add(stepName);
}
}
if (unrecognizedStepNames.isNotEmpty) {
io.stderr.writeln(
'Unknown build steps specified: ${unrecognizedStepNames.join(', ')}',
);
return false;
}
final List<PipelineStep> steps = <PipelineStep>[];
print('Running steps ${steps.join(', ')}');
for (final String stepName in stepNames) {
steps.add(buildSteps[stepName]!);
}
final Stopwatch stopwatch = Stopwatch()..start();
final Pipeline pipeline = Pipeline(steps: steps);
await pipeline.run();
stopwatch.stop();
print('Finished running steps in ${stopwatch.elapsedMilliseconds / 1000} seconds.');
return true;
}
}