execute method

  1. @override
Future<NativeStepResult> execute(
  1. NativeBuildContext context,
  2. ResolvedSource source
)
override

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 args = <String>[];
  if (stripAll) {
    args.add('-s');
  }
  args.addAll(['-o', output, input]);

  // Try system strip first, fall back to llvm-strip
  try {
    await r.runStreaming('strip', args);
  } on ProcessException {
    logger?.info('[strip] System strip failed, trying llvm-strip');
    await r.runStreaming('llvm-strip', args);
  }
  logger?.info('[strip] Stripped: $outputPath');

  return const NativeStepResult();
}