namespace ReleaseBuilder.Build;
public static partial class Command
{
///
/// Support for building packages
///
private static class PackageSupport
{
///
/// Introduces symbolic links for executables that have a different name
///
/// The build path to use
/// The target directory to create the symlinks in
/// An awaitable task
public static Task MakeSymlinks(string buildDir, string? targetDir = null)
{
foreach (var k in ExecutableRenames)
if (File.Exists(Path.Combine(buildDir, k.Key)) && !File.Exists(Path.Combine(buildDir, k.Value)))
File.CreateSymbolicLink(Path.Combine(buildDir, k.Value), Path.Combine(targetDir ?? ".", k.Key));
return Task.CompletedTask;
}
///
/// Sets the executable flags for the build output
///
/// The build directory
/// The runtime configuration
/// An awaitable task
public static Task SetExecutableFlags(string buildDir, RuntimeConfig rtcfg)
{
if (!OperatingSystem.IsWindows())
{
// Mark executables with the execute flag
var executables = ExecutableRenames.Keys.Select(x => Path.Combine(buildDir, x))
.Concat(Directory.EnumerateFiles(buildDir, "*.sh", SearchOption.AllDirectories));
var filemode = EnvHelper.GetUnixFileMode("+x");
foreach (var x in executables)
if (File.Exists(x))
EnvHelper.AddFilemode(x, filemode);
}
return Task.CompletedTask;
}
///
/// Writes the package type identifier to the build directory
///
/// The build directory to update
/// The target configuration
/// An awaitable task
public static Task InstallPackageIdentifier(string buildDir, PackageTarget target)
=> File.WriteAllTextAsync(Path.Combine(buildDir, "package_type_id.txt"), target.PackageTargetString);
}
}