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('[copy] Copying files');
final srcPath = expandRecipeValue(sourcePath, context, source);
final destPath = expandRecipeValue(destinationPath, context, source);
final src = p.isAbsolute(srcPath)
? srcPath
: p.join(source.directory.path, srcPath);
final dest = p.isAbsolute(destPath)
? destPath
: p.join(context.directories.work.path, destPath);
logger?.info('[copy] Source: $src');
logger?.info('[copy] Destination: $dest');
final srcEntity = FileSystemEntity.typeSync(src);
if (srcEntity == FileSystemEntityType.directory) {
await _copyDirectory(
Directory(src),
Directory(dest),
recursive: recursive,
);
} else if (srcEntity == FileSystemEntityType.file) {
Directory(p.dirname(dest)).createSync(recursive: true);
File(src).copySync(dest);
} else {
throw StateError('Copy source does not exist: $src');
}
logger?.info('[copy] Copy completed');
return const NativeStepResult();
}