Skip to content

Commit 7944c5a

Browse files
authored
[native_toolchain_c] skip some checks if dumpbin tool is unavailable (#2368)
1 parent 3b66a14 commit 7944c5a

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

pkgs/native_toolchain_c/test/clinker/objects_helper.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ void runObjectsTests(
9494
expect(codeAssets, hasLength(1));
9595
final asset = codeAssets.first;
9696
expect(asset, isA<CodeAsset>());
97+
final symbols = await readSymbols(asset, targetOS);
9798
expect(
98-
await readSymbols(asset, targetOS),
99+
symbols,
99100
stringContainsInOrder(['my_func', 'my_other_func']),
101+
skip: symbols == null ? 'tool to extract symbols unavailable' : false,
100102
);
101103
});
102104
}

pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@ void runTreeshakeTests(
126126
);
127127

128128
final symbols = await readSymbols(asset, targetOS);
129+
final skipReason = symbols == null
130+
? 'tool to extract symbols unavailable'
131+
: false;
129132
if (clinker.linker != linkerAutoEmpty) {
130-
expect(symbols, contains('my_other_func'));
131-
expect(symbols, isNot(contains('my_func')));
133+
expect(symbols, contains('my_other_func'), skip: skipReason);
134+
expect(symbols, isNot(contains('my_func')), skip: skipReason);
132135
} else {
133-
expect(symbols, contains('my_other_func'));
134-
expect(symbols, contains('my_func'));
136+
expect(symbols, contains('my_other_func'), skip: skipReason);
137+
expect(symbols, contains('my_func'), skip: skipReason);
135138
}
136139

137140
final sizeInBytes = await File.fromUri(asset.file!).length();

pkgs/native_toolchain_c/test/helpers.dart

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,15 @@ List<String> nmParameterFor(OS targetOS) => switch (targetOS) {
251251
OS() => ['-D'],
252252
};
253253

254-
Future<String> readSymbols(CodeAsset asset, OS targetOS) async {
254+
/// Returns null if the tool to extract the symbols is not available.
255+
Future<String?> readSymbols(CodeAsset asset, OS targetOS) async {
255256
final assetUri = asset.file!;
256257
switch (targetOS) {
257258
case OS.windows:
258259
final result = await _runDumpbin(['/EXPORTS'], asset.file!);
260+
if (result == null) {
261+
return null;
262+
}
259263
expect(result.exitCode, 0);
260264
return result.stdout;
261265
case OS():
@@ -269,12 +273,18 @@ Future<String> readSymbols(CodeAsset asset, OS targetOS) async {
269273
}
270274
}
271275

272-
Future<RunProcessResult> _runDumpbin(List<String> arguments, Uri libUri) async {
273-
final dumpbinUri = (await dumpbin.defaultResolver!.resolve(
274-
logger: logger,
275-
)).first.uri;
276+
/// Returns null if the dumpbin tool is not available.
277+
Future<RunProcessResult?> _runDumpbin(
278+
List<String> arguments,
279+
Uri libUri,
280+
) async {
281+
final dumpbinTools = await dumpbin.defaultResolver!.resolve(logger: logger);
282+
if (dumpbinTools.isEmpty) {
283+
logger.info('Unable to locate dumpbin tool. Some expects may be skipped.');
284+
return null;
285+
}
276286
return await runProcess(
277-
executable: dumpbinUri,
287+
executable: dumpbinTools.first.uri,
278288
arguments: [...arguments, libUri.toFilePath()],
279289
logger: logger,
280290
);
@@ -369,7 +379,7 @@ const dumpbinFileFormat = {
369379
/// executed on the provided [targetArch] architecture.
370380
///
371381
/// On Linux, the format of the binary is determined by `readelf`. On MacOS,
372-
/// the `objsdump` tool is used. On Windows, `dumpbin` is used.
382+
/// the `objdump` tool is used. On Windows, `dumpbin` is used.
373383
Future<void> expectMachineArchitecture(
374384
Uri libUri,
375385
Architecture targetArch,
@@ -394,11 +404,14 @@ Future<void> expectMachineArchitecture(
394404
);
395405
} else if (Platform.isWindows && targetOS == OS.windows) {
396406
final result = await _runDumpbin(['/HEADERS'], libUri);
397-
expect(result.exitCode, 0);
398-
final machine = result.stdout
407+
final skipReason = result == null
408+
? 'tool to determine binary architecture unavailable'
409+
: false;
410+
expect(result?.exitCode, 0, skip: skipReason);
411+
final machine = result?.stdout
399412
.split('\n')
400413
.firstWhere((e) => e.contains('machine'));
401-
expect(machine, contains(dumpbinFileFormat[targetArch]));
414+
expect(machine, contains(dumpbinFileFormat[targetArch]), skip: skipReason);
402415
}
403416
}
404417

0 commit comments

Comments
 (0)