Files
duplicati/ReleaseBuilder/Build/Command.PackageSupport.cs
T

56 lines
2.4 KiB
C#
Raw Normal View History

2024-03-27 19:52:40 +01:00
namespace ReleaseBuilder.Build;
2024-03-24 17:34:20 +01:00
2024-03-27 19:52:40 +01:00
public static partial class Command
2024-03-24 17:34:20 +01:00
{
/// <summary>
/// Support for building packages
/// </summary>
private static class PackageSupport
{
/// <summary>
/// Introduces symbolic links for executables that have a different name
/// </summary>
/// <param name="buildDir">The build path to use</param>
2024-03-25 11:53:52 +01:00
/// <param name="targetDir">The target directory to create the symlinks in</param>
2024-03-24 17:34:20 +01:00
/// <returns>An awaitable task</returns>
2024-03-25 11:53:52 +01:00
public static Task MakeSymlinks(string buildDir, string? targetDir = null)
2024-03-24 17:34:20 +01:00
{
foreach (var k in ExecutableRenames)
if (File.Exists(Path.Combine(buildDir, k.Key)) && !File.Exists(Path.Combine(buildDir, k.Value)))
2024-03-25 11:53:52 +01:00
File.CreateSymbolicLink(Path.Combine(buildDir, k.Value), Path.Combine(targetDir ?? ".", k.Key));
2024-03-24 17:34:20 +01:00
return Task.CompletedTask;
}
/// <summary>
/// Sets the executable flags for the build output
/// </summary>
/// <param name="buildDir">The build directory</param>
/// <param name="rtcfg">The runtime configuration</param>
/// <returns>An awaitable task</returns>
public static Task SetExecutableFlags(string buildDir, RuntimeConfig rtcfg)
{
if (!OperatingSystem.IsWindows())
{
// Mark executables with the execute flag
2024-03-25 11:53:52 +01:00
var executables = ExecutableRenames.Keys.Select(x => Path.Combine(buildDir, x))
2024-03-24 17:34:20 +01:00
.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;
}
2024-03-25 11:53:52 +01:00
/// <summary>
/// Writes the package type identifier to the build directory
/// </summary>
/// <param name="buildDir">The build directory to update</param>
/// <param name="target">The target configuration</param>
/// <returns>An awaitable task</returns>
public static Task InstallPackageIdentifier(string buildDir, PackageTarget target)
=> File.WriteAllTextAsync(Path.Combine(buildDir, "package_type_id.txt"), target.PackageTargetString);
2024-03-24 17:34:20 +01:00
}
}