[et] Lookup output filesystem path, not label (flutter/engine#52248)
Sets BuildTarget.executable to the `root_out_dir`-relative path of the executable (e.g. `displaylist_unittests`) instead of its label (e.g. `//out/host_debug/displaylist_unittests`). This is required since, in the lines following the output lookup, we assume it to be a path relative to the build output directory. Also breaks out functions for: * `_runGnDesc`: returns the JSON output of `gn desc buildDir target` * `_runGnOutputs`: returns the output files listed by `gn outputs buildDir target` Noticed while working on: https://github.com/flutter/flutter/issues/147071 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
@@ -77,30 +77,9 @@ final class BuildTarget {
|
||||
Future<Map<String, BuildTarget>> findTargets(
|
||||
Environment environment, Directory buildDir) async {
|
||||
final Map<String, BuildTarget> r = <String, BuildTarget>{};
|
||||
final List<String> getBuildInfoCommandLine = <String>[
|
||||
gnBinPath(environment),
|
||||
'desc',
|
||||
buildDir.path,
|
||||
'*',
|
||||
'--format=json',
|
||||
];
|
||||
|
||||
final ProcessRunnerResult result = await environment.processRunner.runProcess(
|
||||
getBuildInfoCommandLine,
|
||||
workingDirectory: environment.engine.srcDir,
|
||||
failOk: true);
|
||||
|
||||
// Handle any process failures.
|
||||
fatalIfFailed(environment, getBuildInfoCommandLine, result);
|
||||
|
||||
late final Map<String, Object?> jsonResult;
|
||||
try {
|
||||
jsonResult = jsonDecode(result.stdout) as Map<String, Object?>;
|
||||
} catch (e) {
|
||||
environment.logger.fatal(
|
||||
'gn desc output could not be parsed:\nE=$e\nIN=${result.stdout}\n');
|
||||
}
|
||||
|
||||
final Map<String, Object?> jsonResult =
|
||||
await _runGnDesc(buildDir.path, '*', environment);
|
||||
for (final MapEntry<String, Object?> targetEntry in jsonResult.entries) {
|
||||
final String label = targetEntry.key;
|
||||
if (targetEntry.value == null) {
|
||||
@@ -120,7 +99,7 @@ Future<Map<String, BuildTarget>> findTargets(
|
||||
}
|
||||
final bool testOnly = getBool(properties, 'testonly');
|
||||
final List<String> outputs =
|
||||
getListOfString(properties, 'outputs') ?? <String>[];
|
||||
await _runGnOutputs(buildDir.path, label, environment);
|
||||
File? executable;
|
||||
if (type == BuildTargetType.executable) {
|
||||
if (outputs.isEmpty) {
|
||||
@@ -135,6 +114,55 @@ Future<Map<String, BuildTarget>> findTargets(
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Returns the JSON output of running `gn desc buildDir label`.
|
||||
Future<Map<String, Object?>> _runGnDesc(
|
||||
String buildDir, String label, Environment environment) async {
|
||||
final List<String> commandline = <String>[
|
||||
gnBinPath(environment),
|
||||
'desc',
|
||||
buildDir,
|
||||
label,
|
||||
'--format=json',
|
||||
];
|
||||
|
||||
final ProcessRunnerResult result = await environment.processRunner.runProcess(
|
||||
commandline,
|
||||
workingDirectory: environment.engine.srcDir,
|
||||
failOk: true);
|
||||
|
||||
// Handle any process failures.
|
||||
fatalIfFailed(environment, commandline, result);
|
||||
|
||||
late final Map<String, Object?> jsonResult;
|
||||
try {
|
||||
jsonResult = jsonDecode(result.stdout) as Map<String, Object?>;
|
||||
} catch (e) {
|
||||
environment.logger.fatal(
|
||||
'gn desc output could not be parsed:\nE=$e\nIN=${result.stdout}\n');
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/// Returns the output paths returned by `gn outputs buildDir label`.
|
||||
Future<List<String>> _runGnOutputs(
|
||||
String buildDir, String label, Environment environment) async {
|
||||
final List<String> commandline = <String>[
|
||||
gnBinPath(environment),
|
||||
'outputs',
|
||||
buildDir,
|
||||
label,
|
||||
];
|
||||
final ProcessRunnerResult result = await environment.processRunner.runProcess(
|
||||
commandline,
|
||||
workingDirectory: environment.engine.srcDir,
|
||||
failOk: true);
|
||||
|
||||
// Handle any process failures.
|
||||
fatalIfFailed(environment, commandline, result);
|
||||
|
||||
return result.stdout.split('\n');
|
||||
}
|
||||
|
||||
/// Process selectors and filter allTargets for matches.
|
||||
///
|
||||
/// We support:
|
||||
|
||||
@@ -360,11 +360,11 @@ void main() {
|
||||
'//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.length, greaterThan(6));
|
||||
expect(testEnv.processHistory[6].command[0], contains('ninja'));
|
||||
expect(testEnv.processHistory[6].command[2], endsWith('/host_debug'));
|
||||
expect(
|
||||
testEnv.processHistory[3].command[5],
|
||||
testEnv.processHistory[6].command[5],
|
||||
equals('flutter/fml:fml_arc_unittests'),
|
||||
);
|
||||
} finally {
|
||||
@@ -389,19 +389,19 @@ void main() {
|
||||
'//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.length, greaterThan(6));
|
||||
expect(testEnv.processHistory[6].command[0], contains('ninja'));
|
||||
expect(testEnv.processHistory[6].command[2], endsWith('/host_debug'));
|
||||
expect(
|
||||
testEnv.processHistory[3].command[5],
|
||||
testEnv.processHistory[6].command[5],
|
||||
equals('flutter/display_list:display_list_unittests'),
|
||||
);
|
||||
expect(
|
||||
testEnv.processHistory[3].command[6],
|
||||
testEnv.processHistory[6].command[6],
|
||||
equals('flutter/flow:flow_unittests'),
|
||||
);
|
||||
expect(
|
||||
testEnv.processHistory[3].command[7],
|
||||
testEnv.processHistory[6].command[7],
|
||||
equals('flutter/fml:fml_arc_unittests'),
|
||||
);
|
||||
} finally {
|
||||
|
||||
@@ -39,6 +39,8 @@ void main() {
|
||||
final List<CannedProcess> cannedProcesses = <CannedProcess>[
|
||||
CannedProcess((List<String> command) => command.contains('desc'),
|
||||
stdout: fixtures.gnDescOutput()),
|
||||
CannedProcess((List<String> command) => command.contains('outputs'),
|
||||
stdout: 'display_list_unittests'),
|
||||
];
|
||||
|
||||
test('find test targets', () async {
|
||||
|
||||
@@ -42,6 +42,8 @@ void main() {
|
||||
final List<CannedProcess> cannedProcesses = <CannedProcess>[
|
||||
CannedProcess((List<String> command) => command.contains('desc'),
|
||||
stdout: fixtures.gnDescOutput()),
|
||||
CannedProcess((List<String> command) => command.contains('outputs'),
|
||||
stdout: 'display_list_unittests'),
|
||||
];
|
||||
|
||||
test('test command executes test', () async {
|
||||
@@ -83,7 +85,7 @@ void main() {
|
||||
'//third_party/protobuf:protoc',
|
||||
]);
|
||||
expect(result, equals(1));
|
||||
expect(testEnvironment.processHistory.length, lessThan(3));
|
||||
expect(testEnvironment.processHistory.length, lessThan(6));
|
||||
expect(testEnvironment.processHistory.where((ExecutedProcess process) {
|
||||
return process.command[0].contains('protoc');
|
||||
}), isEmpty);
|
||||
|
||||
Reference in New Issue
Block a user