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;
final resolvedUrl = expandRecipeValue(url, context, source);
logger?.info('[download_archive] Downloading archive from $resolvedUrl');
final r = runner ?? ProcessRunner(logger: logger);
final resolvedOutputDirectory = outputDirectory == null
? p.join(context.directories.work.path, id)
: expandRecipeValue(outputDirectory!, context, source);
final outputDir = p.isAbsolute(resolvedOutputDirectory)
? resolvedOutputDirectory
: p.join(context.directories.work.path, resolvedOutputDirectory);
final archivePath = p.join(
outputDir,
'archive${_extensionFromUrl(Uri.parse(resolvedUrl))}',
);
Directory(outputDir).createSync(recursive: true);
// Download using curl
await r.runStreaming('curl', ['-L', '-o', archivePath, resolvedUrl]);
// Verify SHA-256 if provided
if (sha256 != null) {
final resolvedSha256 = expandRecipeValue(sha256!, context, source);
final result = await r.runStreaming('shasum', ['-a', '256', archivePath]);
final hash = result.stdout.split(' ').first;
if (hash != resolvedSha256) {
throw StateError(
'SHA-256 mismatch: expected $resolvedSha256, got $hash',
);
}
}
await _extractArchive(r, archivePath, outputDir);
logger?.info('[download_archive] Archive downloaded to $archivePath');
return const NativeStepResult();
}