execute method
Execute this build step.
The context provides access to the build configuration and logger.
Returns a NativeStepResult containing any artifacts produced by this step.
Implementation
@override
Future<NativeStepResult> execute(
NativeBuildContext context,
ResolvedSource source,
) async {
final logger = context.logger;
logger?.info('[strip] Stripping binary');
final r = runner ?? ProcessRunner(logger: logger);
final resolvedInputPath = expandRecipeValue(inputPath, context, source);
final resolvedOutputPath = expandRecipeValue(outputPath, context, source);
final input = p.isAbsolute(resolvedInputPath)
? resolvedInputPath
: p.join(context.directories.work.path, resolvedInputPath);
final output = p.isAbsolute(resolvedOutputPath)
? resolvedOutputPath
: p.join(context.directories.work.path, resolvedOutputPath);
final resolver = const NativeToolchainResolver();
final stripCmd = resolver.stripCommand(context.target);
final args = <String>[];
if (stripAll) {
args.add('-s');
}
// xcrun strip needs `xcrun strip ...`, plain strip is `strip ...`
final resolvedArgs = stripCmd.length > 1
? [...stripCmd.sublist(1), ...args, '-o', output, input]
: [...args, '-o', output, input];
final exe = stripCmd.first;
try {
await r.runStreaming(exe, resolvedArgs);
} on ProcessException {
// Fallback chain: try llvm-strip then system strip
if (exe != 'llvm-strip') {
logger?.info('[strip] $exe failed, trying llvm-strip');
try {
await r.runStreaming('llvm-strip', [...args, '-o', output, input]);
} on ProcessException {
logger?.info('[strip] llvm-strip failed, trying strip');
await r.runStreaming('strip', [...args, '-o', output, input]);
}
} else {
logger?.info('[strip] llvm-strip failed, trying strip');
await r.runStreaming('strip', [...args, '-o', output, input]);
}
}
logger?.info('[strip] Stripped: $outputPath');
return const NativeStepResult();
}