Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 502cf97

Browse files
committed
[et] Lookup output filesystem path, not label
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. Noticed while working on: flutter/flutter#147071
1 parent 40110ec commit 502cf97

File tree

3 files changed

+68
-32
lines changed

3 files changed

+68
-32
lines changed

tools/engine_tool/lib/src/gn_utils.dart

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,9 @@ final class BuildTarget {
7777
Future<Map<String, BuildTarget>> findTargets(
7878
Environment environment, Directory buildDir) async {
7979
final Map<String, BuildTarget> r = <String, BuildTarget>{};
80-
final List<String> getBuildInfoCommandLine = <String>[
81-
gnBinPath(environment),
82-
'desc',
83-
buildDir.path,
84-
'*',
85-
'--format=json',
86-
];
87-
88-
final ProcessRunnerResult result = await environment.processRunner.runProcess(
89-
getBuildInfoCommandLine,
90-
workingDirectory: environment.engine.srcDir,
91-
failOk: true);
92-
93-
// Handle any process failures.
94-
fatalIfFailed(environment, getBuildInfoCommandLine, result);
95-
96-
late final Map<String, Object?> jsonResult;
97-
try {
98-
jsonResult = jsonDecode(result.stdout) as Map<String, Object?>;
99-
} catch (e) {
100-
environment.logger.fatal(
101-
'gn desc output could not be parsed:\nE=$e\nIN=${result.stdout}\n');
102-
}
10380

81+
final Map<String, Object?> jsonResult =
82+
await _gnDesc(buildDir.path, '*', environment);
10483
for (final MapEntry<String, Object?> targetEntry in jsonResult.entries) {
10584
final String label = targetEntry.key;
10685
if (targetEntry.value == null) {
@@ -120,7 +99,7 @@ Future<Map<String, BuildTarget>> findTargets(
12099
}
121100
final bool testOnly = getBool(properties, 'testonly');
122101
final List<String> outputs =
123-
getListOfString(properties, 'outputs') ?? <String>[];
102+
await _gnOutputs(buildDir.path, label, environment);
124103
File? executable;
125104
if (type == BuildTargetType.executable) {
126105
if (outputs.isEmpty) {
@@ -135,6 +114,48 @@ Future<Map<String, BuildTarget>> findTargets(
135114
return r;
136115
}
137116

117+
Future<Map<String, Object?>> _gnDesc(
118+
String buildDir, String label, Environment environment) async {
119+
final List<String> getBuildInfoCommandLine = <String>[
120+
gnBinPath(environment),
121+
'desc',
122+
buildDir,
123+
label,
124+
'--format=json',
125+
];
126+
127+
final ProcessRunnerResult result = await environment.processRunner.runProcess(
128+
getBuildInfoCommandLine,
129+
workingDirectory: environment.engine.srcDir,
130+
failOk: true);
131+
132+
// Handle any process failures.
133+
fatalIfFailed(environment, getBuildInfoCommandLine, result);
134+
135+
late final Map<String, Object?> jsonResult;
136+
try {
137+
jsonResult = jsonDecode(result.stdout) as Map<String, Object?>;
138+
} catch (e) {
139+
environment.logger.fatal(
140+
'gn desc output could not be parsed:\nE=$e\nIN=${result.stdout}\n');
141+
}
142+
return jsonResult;
143+
}
144+
145+
Future<List<String>> _gnOutputs(
146+
String buildDir, String label, Environment environment) async {
147+
final List<String> getOutputsCommandLine = <String>[
148+
gnBinPath(environment),
149+
'outputs',
150+
buildDir,
151+
label,
152+
];
153+
final ProcessRunnerResult outputsResult = await environment.processRunner
154+
.runProcess(getOutputsCommandLine,
155+
workingDirectory: environment.engine.srcDir, failOk: true);
156+
return outputsResult.stdout.split('\n');
157+
}
158+
138159
/// Process selectors and filter allTargets for matches.
139160
///
140161
/// We support:

tools/engine_tool/test/fixtures.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ String attachedDevices() => '''
225225
]
226226
''';
227227

228+
String gnOutputsDisplaylistUnittestsOutput() => '''
229+
display_list_unittests
230+
''';
231+
228232
String gnDescOutput() => '''
229233
{
230234
"//flutter/display_list:display_list_unittests": {

tools/engine_tool/test/gn_utils_test.dart

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ void main() {
3939
final List<CannedProcess> cannedProcesses = <CannedProcess>[
4040
CannedProcess((List<String> command) => command.contains('desc'),
4141
stdout: fixtures.gnDescOutput()),
42+
CannedProcess((List<String> command) => command.contains('outputs'),
43+
stdout: fixtures.gnOutputsDisplaylistUnittestsOutput()),
4244
];
4345

4446
test('find test targets', () async {
@@ -85,11 +87,15 @@ void main() {
8587
try {
8688
final Environment env = testEnv.environment;
8789
final List<Build> builds = runnableBuilds(env, configs, true);
88-
final Build? build = builds.where(
89-
(Build build) => build.name == 'linux/host_debug',
90-
).firstOrNull;
90+
final Build? build = builds
91+
.where(
92+
(Build build) => build.name == 'linux/host_debug',
93+
)
94+
.firstOrNull;
9195
final List<BuildTarget>? selectedTargets = await targetsFromCommandLine(
92-
env, build!, <String>[],
96+
env,
97+
build!,
98+
<String>[],
9399
);
94100
expect(selectedTargets, isNotNull);
95101
expect(selectedTargets, isEmpty);
@@ -105,11 +111,16 @@ void main() {
105111
try {
106112
final Environment env = testEnv.environment;
107113
final List<Build> builds = runnableBuilds(env, configs, true);
108-
final Build? build = builds.where(
109-
(Build build) => build.name == 'linux/host_debug',
110-
).firstOrNull;
114+
final Build? build = builds
115+
.where(
116+
(Build build) => build.name == 'linux/host_debug',
117+
)
118+
.firstOrNull;
111119
final List<BuildTarget>? selectedTargets = await targetsFromCommandLine(
112-
env, build!, <String>[], defaultToAll: true,
120+
env,
121+
build!,
122+
<String>[],
123+
defaultToAll: true,
113124
);
114125
expect(selectedTargets, isNotNull);
115126
expect(selectedTargets, isNotEmpty);

0 commit comments

Comments
 (0)