[et] Run GN before looking for targets. Default to build config targets (flutter/engine#51956)
Addresses the notes I left on https://github.com/flutter/engine/pull/51868. Mainly fixes an issue in which the `build`, `query`, and `test` commands would fail if GN had not yet been run for the requested configuration. Instead, in this PR, if the build output directory doesn't exist yet, then it will run GN before querying the targets. Additionally, for the `build` command, if no targets are specified on the command line, the PR uses the targets in the build config as the default rather than all targets. `query` and `test` keep the same behavior.
This commit is contained in:
@@ -176,3 +176,43 @@ Future<int> runBuild(Environment environment, Build build,
|
||||
final bool buildResult = await buildRunner.run(handler);
|
||||
return buildResult ? 0 : 1;
|
||||
}
|
||||
|
||||
/// Given a [Build] object, run only its GN step.
|
||||
Future<int> runGn(
|
||||
Environment environment,
|
||||
Build build, {
|
||||
List<String> extraGnArgs = const <String>[],
|
||||
}) async {
|
||||
// If RBE config files aren't in the tree, then disable RBE.
|
||||
final String rbeConfigPath = p.join(
|
||||
environment.engine.srcDir.path,
|
||||
'flutter',
|
||||
'build',
|
||||
'rbe',
|
||||
);
|
||||
final List<String> gnArgs = <String>[
|
||||
if (!io.Directory(rbeConfigPath).existsSync()) '--no-rbe',
|
||||
...extraGnArgs,
|
||||
];
|
||||
|
||||
final BuildRunner buildRunner = BuildRunner(
|
||||
platform: environment.platform,
|
||||
processRunner: environment.processRunner,
|
||||
abi: environment.abi,
|
||||
engineSrcDir: environment.engine.srcDir,
|
||||
build: build,
|
||||
extraGnArgs: gnArgs,
|
||||
runNinja: false,
|
||||
runGenerators: false,
|
||||
runTests: false,
|
||||
);
|
||||
|
||||
final bool buildResult = await buildRunner.run((RunnerEvent event) {
|
||||
switch (event) {
|
||||
case RunnerResult(ok: false):
|
||||
environment.logger.error(event);
|
||||
default:
|
||||
}
|
||||
});
|
||||
return buildResult ? 0 : 1;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import '../build_utils.dart';
|
||||
import '../gn_utils.dart';
|
||||
@@ -63,22 +60,27 @@ et build //flutter/fml:fml_benchmarks # Build a specific target in `//flutter/f
|
||||
if (!useRbe) '--no-rbe',
|
||||
];
|
||||
|
||||
final Map<String, BuildTarget> allTargets = await findTargets(environment,
|
||||
Directory(p.join(environment.engine.outDir.path, build.ninja.config)));
|
||||
final Set<BuildTarget> selectedTargets =
|
||||
selectTargets(argResults!.rest, allTargets);
|
||||
if (selectedTargets.isEmpty) {
|
||||
environment.logger.error(
|
||||
'No build targets matched ${argResults!.rest}\nRun `et query targets` to see list of targets.');
|
||||
final List<BuildTarget>? selectedTargets = await targetsFromCommandLine(
|
||||
environment,
|
||||
build,
|
||||
argResults!.rest,
|
||||
);
|
||||
if (selectedTargets == null) {
|
||||
// The user typed something wrong and targetsFromCommandLine has already
|
||||
// logged the error message.
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Chop off the '//' prefix.
|
||||
final List<String> buildTargets = selectedTargets
|
||||
.map<String>(
|
||||
(BuildTarget target) => target.label.substring('//'.length))
|
||||
.toList();
|
||||
return runBuild(environment, build,
|
||||
extraGnArgs: extraGnArgs, targets: buildTargets);
|
||||
final List<String> ninjaTargets = selectedTargets.map<String>(
|
||||
(BuildTarget target) => target.label.substring('//'.length),
|
||||
).toList();
|
||||
|
||||
return runBuild(
|
||||
environment,
|
||||
build,
|
||||
extraGnArgs: extraGnArgs,
|
||||
targets: ninjaTargets,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import '../build_utils.dart';
|
||||
import '../gn_utils.dart';
|
||||
import 'command.dart';
|
||||
@@ -180,15 +176,24 @@ et query targets //flutter/fml/... # List all targets under `//flutter/fml`
|
||||
environment.logger.error('Could not find config $configName');
|
||||
return 1;
|
||||
}
|
||||
final Map<String, BuildTarget> allTargets = await findTargets(environment,
|
||||
Directory(p.join(environment.engine.outDir.path, build.ninja.config)));
|
||||
final Set<BuildTarget> selectedTargets =
|
||||
selectTargets(argResults!.rest, allTargets);
|
||||
if (selectedTargets.isEmpty) {
|
||||
environment.logger.error(
|
||||
'No build targets matched ${argResults!.rest}\nRun `et query targets` to see list of targets.');
|
||||
|
||||
final List<BuildTarget>? selectedTargets = await targetsFromCommandLine(
|
||||
environment,
|
||||
build,
|
||||
argResults!.rest,
|
||||
defaultToAll: true,
|
||||
);
|
||||
if (selectedTargets == null) {
|
||||
// The user typed something wrong and targetsFromCommandLine has already
|
||||
// logged the error message.
|
||||
return 1;
|
||||
}
|
||||
if (selectedTargets.isEmpty) {
|
||||
environment.logger.fatal(
|
||||
'targetsFromCommandLine unexpectedly returned an empty list',
|
||||
);
|
||||
}
|
||||
|
||||
for (final BuildTarget target in selectedTargets) {
|
||||
if (testOnly &&
|
||||
(!target.testOnly || target.type != BuildTargetType.executable)) {
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import '../build_utils.dart';
|
||||
import '../gn_utils.dart';
|
||||
@@ -54,15 +51,23 @@ et test //flutter/fml:fml_benchmarks # Run a single test target in `//flutter/f
|
||||
return 1;
|
||||
}
|
||||
|
||||
final Map<String, BuildTarget> allTargets = await findTargets(environment,
|
||||
Directory(p.join(environment.engine.outDir.path, build.ninja.config)));
|
||||
final Set<BuildTarget> selectedTargets =
|
||||
selectTargets(argResults!.rest, allTargets);
|
||||
if (selectedTargets.isEmpty) {
|
||||
environment.logger.error(
|
||||
'No build targets matched ${argResults!.rest}\nRun `et query targets --testonly` to see list of targets.');
|
||||
final List<BuildTarget>? selectedTargets = await targetsFromCommandLine(
|
||||
environment,
|
||||
build,
|
||||
argResults!.rest,
|
||||
defaultToAll: true,
|
||||
);
|
||||
if (selectedTargets == null) {
|
||||
// The user typed something wrong and targetsFromCommandLine has already
|
||||
// logged the error message.
|
||||
return 1;
|
||||
}
|
||||
if (selectedTargets.isEmpty) {
|
||||
environment.logger.fatal(
|
||||
'targetsFromCommandLine unexpectedly returned an empty list',
|
||||
);
|
||||
}
|
||||
|
||||
for (final BuildTarget target in selectedTargets) {
|
||||
if (!target.testOnly || target.type != BuildTargetType.executable) {
|
||||
// Remove any targets that aren't testOnly and aren't executable.
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:process_runner/process_runner.dart';
|
||||
|
||||
import 'build_utils.dart';
|
||||
import 'environment.dart';
|
||||
import 'json_utils.dart';
|
||||
import 'proc_utils.dart';
|
||||
@@ -178,3 +180,66 @@ Set<BuildTarget> selectTargets(
|
||||
}
|
||||
return selected;
|
||||
}
|
||||
|
||||
/// Given a list of target specifications from the command line, return a list
|
||||
/// of [BuildTarget]s from the [Build] that match those specifications.
|
||||
///
|
||||
/// If `commandLineTargets` is empty, by default this will return the empty
|
||||
/// list, which indicates that the caller should delegate the selection of
|
||||
/// build targets to whatever is specified by the [Build] object. However,
|
||||
/// if `defaultToAll` is `true`, then this function will return the list of
|
||||
/// all build targets.
|
||||
Future<List<BuildTarget>?> targetsFromCommandLine(
|
||||
Environment environment,
|
||||
Build build,
|
||||
List<String> commandLineTargets, {
|
||||
bool defaultToAll = false,
|
||||
}) async {
|
||||
// If there are no targets specified on the command line, then delegate to
|
||||
// the default targets specified in the Build object unless directed
|
||||
// otherwise by the defaultToAll argument.
|
||||
if (commandLineTargets.isEmpty && !defaultToAll) {
|
||||
return <BuildTarget>[];
|
||||
}
|
||||
|
||||
final Directory buildDir = Directory(p.join(
|
||||
environment.engine.outDir.path,
|
||||
build.ninja.config,
|
||||
));
|
||||
// If the expected build output directory doesn't exist yet, eagerly run
|
||||
// the build's GN step to try to produce it.
|
||||
if (!buildDir.existsSync()) {
|
||||
environment.logger.status(
|
||||
'Build output directory at ${buildDir.path} not found. Running GN.',
|
||||
);
|
||||
final int gnResult = await runGn(environment, build);
|
||||
if (gnResult != 0 || !buildDir.existsSync()) {
|
||||
environment.logger.error(
|
||||
'The specified build did not produce the expected build '
|
||||
'output directory.',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Find all targets buildable in the configuration.
|
||||
final Map<String, BuildTarget> allTargets = await findTargets(
|
||||
environment,
|
||||
buildDir,
|
||||
);
|
||||
// Use the targets specified on the command line to filter the list of
|
||||
// all targets.
|
||||
final Set<BuildTarget> selectedTargets = selectTargets(
|
||||
commandLineTargets,
|
||||
allTargets,
|
||||
);
|
||||
// Report an error if applying the filter yields no results.
|
||||
if (selectedTargets.isEmpty) {
|
||||
environment.logger.error(
|
||||
'No build targets matched ${commandLineTargets.join(',')}\n'
|
||||
'Run `et query targets` to see list of targets.',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
return selectedTargets.toList();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert' as convert;
|
||||
import 'dart:ffi' as ffi show Abi;
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:engine_repo_tools/engine_repo_tools.dart';
|
||||
import 'package:engine_tool/src/build_utils.dart';
|
||||
import 'package:engine_tool/src/commands/command_runner.dart';
|
||||
import 'package:engine_tool/src/environment.dart';
|
||||
@@ -49,43 +46,23 @@ void main() {
|
||||
stdout: fixtures.gnDescOutput()),
|
||||
];
|
||||
|
||||
TestEnvironment makeTestEnv({bool withRbe = false}) {
|
||||
final io.Directory rootDir = io.Directory.systemTemp.createTempSync('et');
|
||||
final TestEngine engine = TestEngine.createTemp(rootDir: rootDir);
|
||||
if (withRbe) {
|
||||
io.Directory(path.join(
|
||||
engine.srcDir.path,
|
||||
'flutter',
|
||||
'build',
|
||||
'rbe',
|
||||
)).createSync(recursive: true);
|
||||
}
|
||||
final TestEnvironment testEnvironment = TestEnvironment(engine,
|
||||
abi: ffi.Abi.linuxX64, cannedProcesses: cannedProcesses);
|
||||
return testEnvironment;
|
||||
}
|
||||
|
||||
void cleanupEnv(TestEnvironment testEnv) {
|
||||
try {
|
||||
testEnv.environment.engine.srcDir.parent.deleteSync(recursive: true);
|
||||
} catch (_) {
|
||||
// Ignore failure to clean up.
|
||||
}
|
||||
}
|
||||
|
||||
test('can find host runnable build', () async {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final List<Build> result = runnableBuilds(testEnv.environment, configs);
|
||||
expect(result.length, equals(8));
|
||||
expect(result[0].name, equals('ci/build_name'));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command invokes gn', () async {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
@@ -96,17 +73,18 @@ void main() {
|
||||
'--config',
|
||||
'ci/build_name',
|
||||
]);
|
||||
print(testEnv.processHistory);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory.length, greaterThanOrEqualTo(1));
|
||||
expect(testEnv.processHistory[0].command[0], contains('gn'));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command invokes ninja', () async {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
@@ -119,14 +97,16 @@ void main() {
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory.length, greaterThanOrEqualTo(2));
|
||||
expect(testEnv.processHistory[2].command[0], contains('ninja'));
|
||||
expect(testEnv.processHistory[1].command[0], contains('ninja'));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command invokes generator', () async {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
@@ -140,16 +120,18 @@ void main() {
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory.length, greaterThanOrEqualTo(3));
|
||||
expect(
|
||||
testEnv.processHistory[3].command,
|
||||
testEnv.processHistory[2].command,
|
||||
containsStringsInOrder(<String>['python3', 'gen/script.py']),
|
||||
);
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command does not invoke tests', () async {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
@@ -163,12 +145,15 @@ void main() {
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory.length, lessThanOrEqualTo(4));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command runs rbe on an rbe build', () async {
|
||||
final TestEnvironment testEnv = makeTestEnv(withRbe: true);
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
withRbe: true,
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
@@ -180,18 +165,21 @@ void main() {
|
||||
'ci/android_debug_rbe_arm64',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory[1].command[0],
|
||||
expect(testEnv.processHistory[0].command[0],
|
||||
contains(path.join('tools', 'gn')));
|
||||
expect(testEnv.processHistory[1].command[4], equals('--rbe'));
|
||||
expect(testEnv.processHistory[2].command[0],
|
||||
expect(testEnv.processHistory[0].command[4], equals('--rbe'));
|
||||
expect(testEnv.processHistory[1].command[0],
|
||||
contains(path.join('reclient', 'bootstrap')));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command does not run rbe when disabled', () async {
|
||||
final TestEnvironment testEnv = makeTestEnv(withRbe: true);
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
withRbe: true,
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
@@ -204,20 +192,22 @@ void main() {
|
||||
'--no-rbe',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory[1].command[0],
|
||||
expect(testEnv.processHistory[0].command[0],
|
||||
contains(path.join('tools', 'gn')));
|
||||
expect(testEnv.processHistory[1].command,
|
||||
expect(testEnv.processHistory[0].command,
|
||||
doesNotContainAny(<String>['--rbe']));
|
||||
expect(testEnv.processHistory[2].command[0],
|
||||
expect(testEnv.processHistory[1].command[0],
|
||||
contains(path.join('ninja', 'ninja')));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command does not run rbe when rbe configs do not exist',
|
||||
() async {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
@@ -229,35 +219,53 @@ void main() {
|
||||
'ci/android_debug_rbe_arm64',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory[1].command[0],
|
||||
expect(testEnv.processHistory[0].command[0],
|
||||
contains(path.join('tools', 'gn')));
|
||||
expect(testEnv.processHistory[1].command,
|
||||
expect(testEnv.processHistory[0].command,
|
||||
doesNotContainAny(<String>['--rbe']));
|
||||
expect(testEnv.processHistory[2].command[0],
|
||||
expect(testEnv.processHistory[1].command[0],
|
||||
contains(path.join('ninja', 'ninja')));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('mangleConfigName removes the OS and adds ci/ as needed', () {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final Environment env = testEnv.environment;
|
||||
expect(mangleConfigName(env, 'linux/build'), equals('build'));
|
||||
expect(mangleConfigName(env, 'ci/build'), equals('ci/build'));
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final Environment env = testEnv.environment;
|
||||
expect(mangleConfigName(env, 'linux/build'), equals('build'));
|
||||
expect(mangleConfigName(env, 'ci/build'), equals('ci/build'));
|
||||
} finally {
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('mangleConfigName throws when the input config name is malformed', () {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final Environment env = testEnv.environment;
|
||||
expectArgumentError(() => mangleConfigName(env, 'build'));
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final Environment env = testEnv.environment;
|
||||
expectArgumentError(() => mangleConfigName(env, 'build'));
|
||||
} finally {
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('demangleConfigName adds the OS and removes ci/ as needed', () {
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final Environment env = testEnv.environment;
|
||||
expect(demangleConfigName(env, 'build'), equals('linux/build'));
|
||||
expect(demangleConfigName(env, 'ci/build'), equals('ci/build'));
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final Environment env = testEnv.environment;
|
||||
expect(demangleConfigName(env, 'build'), equals('linux/build'));
|
||||
expect(demangleConfigName(env, 'ci/build'), equals('ci/build'));
|
||||
} finally {
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('local config name on the command line is correctly translated',
|
||||
@@ -270,7 +278,9 @@ void main() {
|
||||
final Map<String, BuilderConfig> configs = <String, BuilderConfig>{
|
||||
'namespace_test_config': namespaceTestConfigs,
|
||||
};
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
@@ -282,12 +292,12 @@ void main() {
|
||||
'host_debug',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory[2].command[0],
|
||||
expect(testEnv.processHistory[1].command[0],
|
||||
contains(path.join('ninja', 'ninja')));
|
||||
expect(
|
||||
testEnv.processHistory[2].command[2], contains('local_host_debug'));
|
||||
testEnv.processHistory[1].command[2], contains('local_host_debug'));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -300,7 +310,9 @@ void main() {
|
||||
final Map<String, BuilderConfig> configs = <String, BuilderConfig>{
|
||||
'namespace_test_config': namespaceTestConfigs,
|
||||
};
|
||||
final TestEnvironment testEnv = makeTestEnv();
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
final Environment env = testEnv.environment;
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
@@ -313,11 +325,75 @@ void main() {
|
||||
'ci/host_debug',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory[2].command[0],
|
||||
expect(testEnv.processHistory[1].command[0],
|
||||
contains(path.join('ninja', 'ninja')));
|
||||
expect(testEnv.processHistory[2].command[2], contains('ci/host_debug'));
|
||||
expect(testEnv.processHistory[1].command[2], contains('ci/host_debug'));
|
||||
} finally {
|
||||
cleanupEnv(testEnv);
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command invokes ninja with the specified target', () async {
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'build',
|
||||
'--config',
|
||||
'host_debug',
|
||||
'//flutter/fml:fml_arc_unittests',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory.length, greaterThanOrEqualTo(2));
|
||||
expect(testEnv.processHistory[3].command[0], contains('ninja'));
|
||||
expect(testEnv.processHistory[3].command[2], endsWith('/host_debug'));
|
||||
expect(
|
||||
testEnv.processHistory[3].command[5],
|
||||
equals('flutter/fml:fml_arc_unittests'),
|
||||
);
|
||||
} finally {
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('build command invokes ninja with all matched targets', () async {
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: testEnv.environment,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'build',
|
||||
'--config',
|
||||
'host_debug',
|
||||
'//flutter/...',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnv.processHistory.length, greaterThanOrEqualTo(2));
|
||||
expect(testEnv.processHistory[3].command[0], contains('ninja'));
|
||||
expect(testEnv.processHistory[3].command[2], endsWith('/host_debug'));
|
||||
expect(
|
||||
testEnv.processHistory[3].command[5],
|
||||
equals('flutter/display_list:display_list_unittests'),
|
||||
);
|
||||
expect(
|
||||
testEnv.processHistory[3].command[6],
|
||||
equals('flutter/flow:flow_unittests'),
|
||||
);
|
||||
expect(
|
||||
testEnv.processHistory[3].command[7],
|
||||
equals('flutter/fml:fml_arc_unittests'),
|
||||
);
|
||||
} finally {
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,14 +2,18 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert' as convert;
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:engine_repo_tools/engine_repo_tools.dart';
|
||||
import 'package:engine_tool/src/build_utils.dart';
|
||||
import 'package:engine_tool/src/environment.dart';
|
||||
import 'package:engine_tool/src/gn_utils.dart';
|
||||
import 'package:litetest/litetest.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
import 'fixtures.dart' as fixtures;
|
||||
import 'utils.dart';
|
||||
|
||||
void main() {
|
||||
@@ -22,9 +26,19 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
final BuilderConfig linuxTestConfig = BuilderConfig.fromJson(
|
||||
path: 'ci/builders/linux_test_config.json',
|
||||
map: convert.jsonDecode(fixtures.testConfig('Linux', Platform.linux))
|
||||
as Map<String, Object?>,
|
||||
);
|
||||
|
||||
final Map<String, BuilderConfig> configs = <String, BuilderConfig>{
|
||||
'linux_test_config': linuxTestConfig,
|
||||
};
|
||||
|
||||
final List<CannedProcess> cannedProcesses = <CannedProcess>[
|
||||
CannedProcess((List<String> command) => command.contains('desc'),
|
||||
stdout: gnDescOutput()),
|
||||
stdout: fixtures.gnDescOutput()),
|
||||
];
|
||||
|
||||
test('find test targets', () async {
|
||||
@@ -63,4 +77,44 @@ void main() {
|
||||
.length,
|
||||
equals(1));
|
||||
});
|
||||
|
||||
test('targetsFromCommandLine respects defaultToAll when false', () async {
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final Environment env = testEnv.environment;
|
||||
final List<Build> builds = runnableBuilds(env, configs);
|
||||
final Build? build = builds.where(
|
||||
(Build build) => build.name == 'linux/host_debug',
|
||||
).firstOrNull;
|
||||
final List<BuildTarget>? selectedTargets = await targetsFromCommandLine(
|
||||
env, build!, <String>[],
|
||||
);
|
||||
expect(selectedTargets, isNotNull);
|
||||
expect(selectedTargets, isEmpty);
|
||||
} finally {
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('targetsFromCommandLine respects defaultToAll when true', () async {
|
||||
final TestEnvironment testEnv = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final Environment env = testEnv.environment;
|
||||
final List<Build> builds = runnableBuilds(env, configs);
|
||||
final Build? build = builds.where(
|
||||
(Build build) => build.name == 'linux/host_debug',
|
||||
).firstOrNull;
|
||||
final List<BuildTarget>? selectedTargets = await targetsFromCommandLine(
|
||||
env, build!, <String>[], defaultToAll: true,
|
||||
);
|
||||
expect(selectedTargets, isNotNull);
|
||||
expect(selectedTargets, isNotEmpty);
|
||||
} finally {
|
||||
testEnv.cleanup();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert' as convert;
|
||||
import 'dart:ffi' as ffi show Abi;
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:engine_repo_tools/engine_repo_tools.dart';
|
||||
import 'package:engine_tool/src/commands/command_runner.dart';
|
||||
import 'package:engine_tool/src/environment.dart';
|
||||
import 'package:litetest/litetest.dart';
|
||||
@@ -18,15 +15,6 @@ import 'fixtures.dart' as fixtures;
|
||||
import 'utils.dart';
|
||||
|
||||
void main() {
|
||||
final Engine engine;
|
||||
try {
|
||||
engine = Engine.findWithin();
|
||||
} catch (e) {
|
||||
io.stderr.writeln(e);
|
||||
io.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
final BuilderConfig linuxTestConfig = BuilderConfig.fromJson(
|
||||
path: 'ci/builders/linux_test_config.json',
|
||||
map: convert.jsonDecode(fixtures.testConfig('Linux', Platform.linux))
|
||||
@@ -62,54 +50,21 @@ void main() {
|
||||
];
|
||||
|
||||
test('query command returns builds for the host platform.', () async {
|
||||
final TestEnvironment testEnvironment = TestEnvironment(engine,
|
||||
abi: ffi.Abi.linuxX64, cannedProcesses: cannedProcesses);
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
final TestEnvironment testEnvironment = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'query',
|
||||
'builders',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(
|
||||
stringsFromLogs(env.logger.testLogs),
|
||||
equals(<String>[
|
||||
'Add --verbose to see detailed information about each builder\n',
|
||||
'\n',
|
||||
'"linux_test_config" builder:\n',
|
||||
' "ci/build_name" config\n',
|
||||
' "linux/host_debug" config\n',
|
||||
' "linux/android_debug_arm64" config\n',
|
||||
' "ci/android_debug_rbe_arm64" config\n',
|
||||
'"linux_test_config2" builder:\n',
|
||||
' "ci/build_name" config\n',
|
||||
' "linux/host_debug" config\n',
|
||||
' "linux/android_debug_arm64" config\n',
|
||||
' "ci/android_debug_rbe_arm64" config\n',
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('query command with --builder returns only from the named builder.',
|
||||
() async {
|
||||
final TestEnvironment testEnvironment = TestEnvironment(engine,
|
||||
abi: ffi.Abi.linuxX64, cannedProcesses: cannedProcesses);
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'query',
|
||||
'builders',
|
||||
'--builder',
|
||||
'linux_test_config',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(
|
||||
try {
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'query',
|
||||
'builders',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(
|
||||
stringsFromLogs(env.logger.testLogs),
|
||||
equals(<String>[
|
||||
'Add --verbose to see detailed information about each builder\n',
|
||||
@@ -119,47 +74,100 @@ void main() {
|
||||
' "linux/host_debug" config\n',
|
||||
' "linux/android_debug_arm64" config\n',
|
||||
' "ci/android_debug_rbe_arm64" config\n',
|
||||
]));
|
||||
'"linux_test_config2" builder:\n',
|
||||
' "ci/build_name" config\n',
|
||||
' "linux/host_debug" config\n',
|
||||
' "linux/android_debug_arm64" config\n',
|
||||
' "ci/android_debug_rbe_arm64" config\n',
|
||||
]),
|
||||
);
|
||||
} finally {
|
||||
testEnvironment.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('query command with --builder returns only from the named builder.',
|
||||
() async {
|
||||
final TestEnvironment testEnvironment = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'query',
|
||||
'builders',
|
||||
'--builder',
|
||||
'linux_test_config',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(
|
||||
stringsFromLogs(env.logger.testLogs),
|
||||
equals(<String>[
|
||||
'Add --verbose to see detailed information about each builder\n',
|
||||
'\n',
|
||||
'"linux_test_config" builder:\n',
|
||||
' "ci/build_name" config\n',
|
||||
' "linux/host_debug" config\n',
|
||||
' "linux/android_debug_arm64" config\n',
|
||||
' "ci/android_debug_rbe_arm64" config\n',
|
||||
]));
|
||||
} finally {
|
||||
testEnvironment.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('query command with --all returns all builds.', () async {
|
||||
final TestEnvironment testEnvironment = TestEnvironment(engine,
|
||||
abi: ffi.Abi.linuxX64, cannedProcesses: cannedProcesses);
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'query',
|
||||
'builders',
|
||||
'--all',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(
|
||||
env.logger.testLogs.length,
|
||||
equals(30),
|
||||
final TestEnvironment testEnvironment = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
try {
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'query',
|
||||
'builders',
|
||||
'--all',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(
|
||||
env.logger.testLogs.length,
|
||||
equals(30),
|
||||
);
|
||||
} finally {
|
||||
testEnvironment.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('query targets', () async {
|
||||
final TestEnvironment testEnvironment = TestEnvironment(engine,
|
||||
abi: ffi.Abi.linuxX64, cannedProcesses: cannedProcesses);
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
final TestEnvironment testEnvironment = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'query',
|
||||
'targets',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(
|
||||
env.logger.testLogs.length,
|
||||
equals(3),
|
||||
);
|
||||
expect(env.logger.testLogs[0].message,
|
||||
startsWith('//flutter/display_list:display_list_unittests'));
|
||||
try {
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'query',
|
||||
'targets',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(
|
||||
env.logger.testLogs.length,
|
||||
equals(4),
|
||||
);
|
||||
expect(env.logger.testLogs[1].message,
|
||||
startsWith('//flutter/display_list:display_list_unittests'));
|
||||
} finally {
|
||||
testEnvironment.cleanup();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert' as convert;
|
||||
import 'dart:ffi' as ffi show Abi;
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:engine_build_configs/engine_build_configs.dart';
|
||||
import 'package:engine_repo_tools/engine_repo_tools.dart';
|
||||
import 'package:engine_tool/src/commands/command_runner.dart';
|
||||
import 'package:engine_tool/src/environment.dart';
|
||||
import 'package:litetest/litetest.dart';
|
||||
@@ -17,15 +14,6 @@ import 'fixtures.dart' as fixtures;
|
||||
import 'utils.dart';
|
||||
|
||||
void main() {
|
||||
final Engine engine;
|
||||
try {
|
||||
engine = Engine.findWithin();
|
||||
} catch (e) {
|
||||
io.stderr.writeln(e);
|
||||
io.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
final BuilderConfig linuxTestConfig = BuilderConfig.fromJson(
|
||||
path: 'ci/builders/linux_test_config.json',
|
||||
map: convert.jsonDecode(fixtures.testConfig('Linux', Platform.linux))
|
||||
@@ -57,21 +45,26 @@ void main() {
|
||||
];
|
||||
|
||||
test('test command executes test', () async {
|
||||
final TestEnvironment testEnvironment = TestEnvironment(engine,
|
||||
abi: ffi.Abi.linuxX64, cannedProcesses: cannedProcesses);
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
final TestEnvironment testEnvironment = TestEnvironment.withTestEngine(
|
||||
cannedProcesses: cannedProcesses,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'test',
|
||||
'//flutter/display_list:display_list_unittests',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnvironment.processHistory.length, greaterThan(3));
|
||||
final int offset = testEnvironment.processHistory.length - 1;
|
||||
expect(testEnvironment.processHistory[offset].command[0],
|
||||
endsWith('display_list_unittests'));
|
||||
try {
|
||||
final Environment env = testEnvironment.environment;
|
||||
final ToolCommandRunner runner = ToolCommandRunner(
|
||||
environment: env,
|
||||
configs: configs,
|
||||
);
|
||||
final int result = await runner.run(<String>[
|
||||
'test',
|
||||
'//flutter/display_list:display_list_unittests',
|
||||
]);
|
||||
expect(result, equals(0));
|
||||
expect(testEnvironment.processHistory.length, greaterThan(3));
|
||||
final int offset = testEnvironment.processHistory.length - 1;
|
||||
expect(testEnvironment.processHistory[offset].command[0],
|
||||
endsWith('display_list_unittests'));
|
||||
} finally {
|
||||
testEnvironment.cleanup();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'dart:io' as io;
|
||||
import 'package:engine_repo_tools/engine_repo_tools.dart';
|
||||
import 'package:engine_tool/src/environment.dart';
|
||||
import 'package:engine_tool/src/logger.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:platform/platform.dart';
|
||||
import 'package:process_fakes/process_fakes.dart';
|
||||
import 'package:process_runner/process_runner.dart';
|
||||
@@ -79,6 +80,47 @@ class TestEnvironment {
|
||||
);
|
||||
}
|
||||
|
||||
factory TestEnvironment.withTestEngine({
|
||||
bool withRbe = false,
|
||||
ffi.Abi abi = ffi.Abi.linuxX64,
|
||||
List<CannedProcess> cannedProcesses = const <CannedProcess>[],
|
||||
}) {
|
||||
final io.Directory rootDir = io.Directory.systemTemp.createTempSync('et');
|
||||
final TestEngine engine = TestEngine.createTemp(rootDir: rootDir);
|
||||
if (withRbe) {
|
||||
io.Directory(path.join(
|
||||
engine.srcDir.path,
|
||||
'flutter',
|
||||
'build',
|
||||
'rbe',
|
||||
)).createSync(recursive: true);
|
||||
}
|
||||
// When GN runs, always try to create out/host_debug.
|
||||
final CannedProcess cannedGn = CannedProcess((List<String> command) {
|
||||
if (command[0].endsWith('/gn') && !command.contains('desc')) {
|
||||
io.Directory(path.join(
|
||||
engine.outDir.path,
|
||||
'host_debug',
|
||||
)).createSync(recursive: true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
final TestEnvironment testEnvironment = TestEnvironment(engine,
|
||||
abi: abi, cannedProcesses: cannedProcesses + <CannedProcess>[cannedGn]);
|
||||
return testEnvironment;
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
try {
|
||||
if (environment.engine is TestEngine) {
|
||||
environment.engine.srcDir.parent.deleteSync(recursive: true);
|
||||
}
|
||||
} catch (_) {
|
||||
// Ignore failure to clean up.
|
||||
}
|
||||
}
|
||||
|
||||
/// Environment.
|
||||
late final Environment environment;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user