2018-11-22 04:57:18 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
2019-06-07 00:15:43 +02:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2018-11-22 04:57:18 +01:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Security.Cryptography;
|
2019-02-17 02:03:56 +01:00
|
|
|
using System.Text;
|
|
|
|
using System.Text.RegularExpressions;
|
2018-11-22 04:57:18 +01:00
|
|
|
using ICSharpCode.SharpZipLib.Zip;
|
2020-02-24 22:45:51 +01:00
|
|
|
using LibHacBuild.CodeGen;
|
2018-11-22 04:57:18 +01:00
|
|
|
using Nuke.Common;
|
2019-10-15 04:10:53 +02:00
|
|
|
using Nuke.Common.CI.AppVeyor;
|
2018-11-22 04:57:18 +01:00
|
|
|
using Nuke.Common.Git;
|
2019-05-31 03:20:01 +02:00
|
|
|
using Nuke.Common.IO;
|
2018-11-22 04:57:18 +01:00
|
|
|
using Nuke.Common.ProjectModel;
|
2019-11-29 20:11:04 +01:00
|
|
|
using Nuke.Common.Tooling;
|
2018-11-22 04:57:18 +01:00
|
|
|
using Nuke.Common.Tools.DotNet;
|
2019-02-17 02:03:56 +01:00
|
|
|
using Nuke.Common.Tools.GitVersion;
|
|
|
|
using Nuke.Common.Tools.SignTool;
|
2018-11-22 04:57:18 +01:00
|
|
|
using static Nuke.Common.IO.FileSystemTasks;
|
|
|
|
using static Nuke.Common.IO.PathConstruction;
|
|
|
|
using static Nuke.Common.Tools.DotNet.DotNetTasks;
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
namespace LibHacBuild
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
partial class Build : NukeBuild
|
|
|
|
{
|
2019-11-29 20:11:04 +01:00
|
|
|
public static int Main() => Execute<Build>(x => x.Standard);
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
|
2019-05-31 04:00:22 +02:00
|
|
|
public readonly string Configuration = IsLocalBuild ? "Debug" : "Release";
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-11-28 02:52:20 +01:00
|
|
|
[Parameter("Don't enable any size-reducing settings on native builds.")]
|
|
|
|
public readonly bool Untrimmed;
|
|
|
|
|
2019-04-19 22:13:07 +02:00
|
|
|
[Solution("LibHac.sln")] readonly Solution _solution;
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
AbsolutePath SourceDirectory => RootDirectory / "src";
|
|
|
|
AbsolutePath TestsDirectory => RootDirectory / "tests";
|
|
|
|
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
|
|
|
|
AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed";
|
|
|
|
AbsolutePath TempDirectory => RootDirectory / ".tmp";
|
2019-12-31 07:05:29 +01:00
|
|
|
AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_netcoreapp3.1";
|
2019-11-29 20:11:04 +01:00
|
|
|
AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}";
|
2020-01-17 08:01:25 +01:00
|
|
|
AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet{NativeProgramExtension}";
|
2019-11-29 20:11:04 +01:00
|
|
|
AbsolutePath CliCoreZip => ArtifactsDirectory / $"hactoolnet-{VersionString}-netcore.zip";
|
|
|
|
AbsolutePath CliNativeZip => ArtifactsDirectory / $"hactoolnet-{VersionString}-{HostOsName}.zip";
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-04-19 22:13:07 +02:00
|
|
|
Project LibHacProject => _solution.GetProject("LibHac").NotNull();
|
|
|
|
Project LibHacTestProject => _solution.GetProject("LibHac.Tests").NotNull();
|
|
|
|
Project HactoolnetProject => _solution.GetProject("hactoolnet").NotNull();
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-12-31 07:05:29 +01:00
|
|
|
private bool HasGitDir { get; set; }
|
|
|
|
|
2019-11-28 02:52:20 +01:00
|
|
|
private string NativeRuntime { get; set; }
|
2019-11-29 20:11:04 +01:00
|
|
|
private string HostOsName { get; set; }
|
|
|
|
private string NativeProgramExtension { get; set; }
|
2019-11-28 02:52:20 +01:00
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
string VersionString { get; set; }
|
2019-02-17 02:03:56 +01:00
|
|
|
Dictionary<string, object> VersionProps { get; set; } = new Dictionary<string, object>();
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
const string CertFileName = "cert.pfx";
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-11-28 02:52:20 +01:00
|
|
|
public Build()
|
|
|
|
{
|
2019-11-29 20:11:04 +01:00
|
|
|
if (EnvironmentInfo.IsWin)
|
2019-11-28 02:52:20 +01:00
|
|
|
{
|
|
|
|
NativeRuntime = "win-x64";
|
2019-11-29 20:11:04 +01:00
|
|
|
NativeProgramExtension = ".exe";
|
|
|
|
HostOsName = "win";
|
2019-11-28 02:52:20 +01:00
|
|
|
}
|
2019-11-29 20:11:04 +01:00
|
|
|
else if (EnvironmentInfo.IsLinux)
|
2019-11-28 02:52:20 +01:00
|
|
|
{
|
|
|
|
NativeRuntime = "linux-x64";
|
2019-11-29 20:11:04 +01:00
|
|
|
NativeProgramExtension = "";
|
|
|
|
HostOsName = "linux";
|
2019-11-28 02:52:20 +01:00
|
|
|
}
|
2019-11-29 20:11:04 +01:00
|
|
|
else if (EnvironmentInfo.IsOsx)
|
2019-11-28 02:52:20 +01:00
|
|
|
{
|
|
|
|
NativeRuntime = "osx-x64";
|
2019-11-29 20:11:04 +01:00
|
|
|
NativeProgramExtension = "";
|
|
|
|
HostOsName = "macos";
|
2019-11-28 02:52:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
Target SetVersion => _ => _
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
2019-12-31 07:05:29 +01:00
|
|
|
GitRepository gitRepository = null;
|
|
|
|
GitVersion gitVersion = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gitRepository = (GitRepository)new GitRepositoryAttribute().GetValue(null, null);
|
|
|
|
|
|
|
|
gitVersion = GitVersionTasks.GitVersion(s => s
|
|
|
|
.SetFramework("netcoreapp3.1")
|
|
|
|
.DisableLogOutput())
|
|
|
|
.Result;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
2019-02-17 03:50:41 +01:00
|
|
|
{
|
2019-12-31 07:05:29 +01:00
|
|
|
Logger.Error(e);
|
2019-02-17 03:50:41 +01:00
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-12-31 07:05:29 +01:00
|
|
|
if (gitRepository == null || gitVersion == null)
|
|
|
|
{
|
|
|
|
Logger.Normal("Unable to read Git version.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HasGitDir = true;
|
|
|
|
|
|
|
|
VersionString = $"{gitVersion.MajorMinorPatch}";
|
|
|
|
if (!string.IsNullOrWhiteSpace(gitVersion.PreReleaseTag))
|
|
|
|
{
|
|
|
|
VersionString += $"-{gitVersion.PreReleaseTag}+{gitVersion.Sha.Substring(0, 8)}";
|
|
|
|
}
|
|
|
|
|
|
|
|
string suffix = gitVersion.PreReleaseTag;
|
2019-02-17 03:31:35 +01:00
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(suffix))
|
|
|
|
{
|
2019-12-31 07:05:29 +01:00
|
|
|
if (!gitRepository.IsOnMasterBranch())
|
2019-02-17 03:31:35 +01:00
|
|
|
{
|
|
|
|
suffix = $"-{suffix}";
|
|
|
|
}
|
|
|
|
|
2019-12-31 07:05:29 +01:00
|
|
|
suffix += $"+{gitVersion.Sha.Substring(0, 8)}";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Host == HostType.AppVeyor)
|
|
|
|
{
|
|
|
|
// Workaround GitVersion issue by getting PR info manually https://github.com/GitTools/GitVersion/issues/1927
|
|
|
|
string prNumber = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER");
|
|
|
|
string branchName = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH");
|
|
|
|
|
|
|
|
if (int.TryParse(prNumber, out int prInt) && branchName != null)
|
|
|
|
{
|
|
|
|
string prString = $"PullRequest{prInt:D4}";
|
|
|
|
|
|
|
|
VersionString = VersionString.Replace(branchName, prString);
|
|
|
|
suffix = suffix.Replace(branchName, prString);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetAppVeyorVersion(VersionString);
|
2019-02-17 03:31:35 +01:00
|
|
|
}
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
VersionProps = new Dictionary<string, object>
|
|
|
|
{
|
2019-12-31 07:05:29 +01:00
|
|
|
["VersionPrefix"] = gitVersion.AssemblySemVer,
|
2019-02-17 03:31:35 +01:00
|
|
|
["VersionSuffix"] = suffix
|
2019-02-17 02:03:56 +01:00
|
|
|
};
|
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
Logger.Normal($"Building version {VersionString}");
|
2019-02-17 02:03:56 +01:00
|
|
|
});
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
Target Clean => _ => _
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
2019-05-31 03:20:01 +02:00
|
|
|
List<string> toDelete = GlobDirectories(SourceDirectory, "**/bin", "**/obj")
|
|
|
|
.Concat(GlobDirectories(TestsDirectory, "**/bin", "**/obj")).ToList();
|
|
|
|
|
|
|
|
foreach (string dir in toDelete)
|
|
|
|
{
|
|
|
|
DeleteDirectory(dir);
|
|
|
|
}
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
EnsureCleanDirectory(ArtifactsDirectory);
|
|
|
|
EnsureCleanDirectory(CliCoreDir);
|
2019-06-07 00:15:43 +02:00
|
|
|
EnsureCleanDirectory(CliNativeDir);
|
2019-02-17 02:03:56 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
Target Restore => _ => _
|
|
|
|
.DependsOn(Clean)
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
|
|
|
DotNetRestoreSettings settings = new DotNetRestoreSettings()
|
2019-04-19 22:13:07 +02:00
|
|
|
.SetProjectFile(_solution);
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
DotNetRestore(s => settings);
|
|
|
|
});
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2020-02-24 22:45:51 +01:00
|
|
|
Target Codegen => _ => _
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
|
|
|
ResultCodeGen.Run();
|
|
|
|
});
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
Target Compile => _ => _
|
2020-02-24 22:45:51 +01:00
|
|
|
.DependsOn(Restore, SetVersion, Codegen)
|
2019-02-17 02:03:56 +01:00
|
|
|
.Executes(() =>
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
DotNetBuildSettings buildSettings = new DotNetBuildSettings()
|
2019-04-19 22:13:07 +02:00
|
|
|
.SetProjectFile(_solution)
|
2019-02-17 02:03:56 +01:00
|
|
|
.EnableNoRestore()
|
2019-05-31 04:00:22 +02:00
|
|
|
.SetConfiguration(Configuration)
|
2019-03-15 18:27:43 +01:00
|
|
|
.SetProperties(VersionProps)
|
2019-12-31 07:05:29 +01:00
|
|
|
.SetProperty("BuildType", "Release")
|
|
|
|
.SetProperty("HasGitDir", HasGitDir);
|
2019-02-17 02:03:56 +01:00
|
|
|
|
|
|
|
DotNetBuild(s => buildSettings);
|
|
|
|
|
|
|
|
DotNetPublishSettings publishSettings = new DotNetPublishSettings()
|
|
|
|
.EnableNoRestore()
|
2019-05-31 04:00:22 +02:00
|
|
|
.SetConfiguration(Configuration);
|
2019-02-17 02:03:56 +01:00
|
|
|
|
2018-11-22 04:57:18 +01:00
|
|
|
DotNetPublish(s => publishSettings
|
|
|
|
.SetProject(HactoolnetProject)
|
2019-12-31 07:05:29 +01:00
|
|
|
.SetFramework("netcoreapp3.1")
|
2019-02-17 02:03:56 +01:00
|
|
|
.SetOutput(CliCoreDir)
|
2019-08-10 03:29:06 +02:00
|
|
|
.SetNoBuild(true)
|
2019-02-17 02:03:56 +01:00
|
|
|
.SetProperties(VersionProps));
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
// Hack around OS newline differences
|
|
|
|
if (EnvironmentInfo.IsUnix)
|
|
|
|
{
|
|
|
|
foreach (string filename in Directory.EnumerateFiles(CliCoreDir, "*.json"))
|
|
|
|
{
|
|
|
|
ReplaceLineEndings(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Target Pack => _ => _
|
|
|
|
.DependsOn(Compile)
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
|
|
|
DotNetPackSettings settings = new DotNetPackSettings()
|
|
|
|
.SetProject(LibHacProject)
|
|
|
|
.EnableNoBuild()
|
2019-05-31 04:00:22 +02:00
|
|
|
.SetConfiguration(Configuration)
|
2019-02-17 02:03:56 +01:00
|
|
|
.EnableIncludeSymbols()
|
|
|
|
.SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg)
|
|
|
|
.SetOutputDirectory(ArtifactsDirectory)
|
|
|
|
.SetProperties(VersionProps);
|
|
|
|
|
|
|
|
DotNetPack(s => settings);
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
foreach (string filename in Directory.EnumerateFiles(ArtifactsDirectory, "*.*nupkg"))
|
|
|
|
{
|
|
|
|
RepackNugetPackage(filename);
|
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
if (Host != HostType.AppVeyor) return;
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
foreach (string filename in Directory.EnumerateFiles(ArtifactsDirectory, "*.*nupkg"))
|
|
|
|
{
|
|
|
|
PushArtifact(filename);
|
|
|
|
}
|
|
|
|
});
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
Target Test => _ => _
|
|
|
|
.DependsOn(Compile)
|
|
|
|
.Executes(() =>
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
DotNetTestSettings settings = new DotNetTestSettings()
|
|
|
|
.SetProjectFile(LibHacTestProject)
|
|
|
|
.EnableNoBuild()
|
2019-05-31 04:00:22 +02:00
|
|
|
.SetConfiguration(Configuration);
|
2019-02-17 02:03:56 +01:00
|
|
|
|
2019-12-31 07:05:29 +01:00
|
|
|
if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "netcoreapp3.1");
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
DotNetTest(s => settings);
|
|
|
|
});
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
Target Zip => _ => _
|
|
|
|
.DependsOn(Pack)
|
2019-11-29 20:11:04 +01:00
|
|
|
.After(Native)
|
2019-02-17 02:03:56 +01:00
|
|
|
.Executes(() =>
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
string[] namesCore = Directory.EnumerateFiles(CliCoreDir, "*.json")
|
|
|
|
.Concat(Directory.EnumerateFiles(CliCoreDir, "*.dll"))
|
|
|
|
.ToArray();
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2020-01-17 08:01:25 +01:00
|
|
|
EnsureExistingDirectory(ArtifactsDirectory);
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
ZipFiles(CliCoreZip, namesCore);
|
2019-11-29 20:11:04 +01:00
|
|
|
Logger.Normal($"Created {CliCoreZip}");
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
if (Host == HostType.AppVeyor)
|
|
|
|
{
|
|
|
|
PushArtifact(CliCoreZip);
|
|
|
|
}
|
|
|
|
});
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
Target Publish => _ => _
|
2019-11-29 20:11:04 +01:00
|
|
|
.DependsOn(Test, Pack)
|
2019-05-31 03:20:01 +02:00
|
|
|
.OnlyWhenStatic(() => AppVeyor.Instance != null && AppVeyor.Instance.PullRequestTitle == null)
|
2019-02-17 02:03:56 +01:00
|
|
|
.Executes(() =>
|
|
|
|
{
|
|
|
|
AbsolutePath nupkgFile = ArtifactsDirectory.GlobFiles("*.nupkg").Single();
|
|
|
|
AbsolutePath snupkgFile = ArtifactsDirectory.GlobFiles("*.snupkg").Single();
|
|
|
|
|
2019-10-15 04:10:53 +02:00
|
|
|
string apiKey = EnvironmentInfo.GetVariable<string>("myget_api_key");
|
2019-02-17 02:03:56 +01:00
|
|
|
DotNetNuGetPushSettings settings = new DotNetNuGetPushSettings()
|
|
|
|
.SetApiKey(apiKey)
|
|
|
|
.SetSymbolApiKey(apiKey)
|
|
|
|
.SetSource("https://www.myget.org/F/libhac/api/v2/package")
|
|
|
|
.SetSymbolSource("https://www.myget.org/F/libhac/symbols/api/v2/package");
|
|
|
|
|
|
|
|
DotNetNuGetPush(settings.SetTargetPath(nupkgFile));
|
|
|
|
DotNetNuGetPush(settings.SetTargetPath(snupkgFile));
|
|
|
|
});
|
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
Target Sign => _ => _
|
|
|
|
.DependsOn(Test, Zip)
|
|
|
|
.OnlyWhenStatic(() => File.Exists(CertFileName))
|
|
|
|
.OnlyWhenStatic(() => EnvironmentInfo.IsWin)
|
2019-06-07 00:15:43 +02:00
|
|
|
.Executes(() =>
|
|
|
|
{
|
2019-11-29 20:11:04 +01:00
|
|
|
string pwd = ReadPassword();
|
2019-06-07 00:15:43 +02:00
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
if (pwd == string.Empty)
|
2019-06-07 00:15:43 +02:00
|
|
|
{
|
2019-11-29 20:11:04 +01:00
|
|
|
Logger.Normal("Skipping sign task");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SignAndReZip(pwd);
|
|
|
|
});
|
2019-06-07 00:15:43 +02:00
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
Target Native => _ => _
|
|
|
|
.DependsOn(SetVersion)
|
|
|
|
.After(Compile)
|
|
|
|
.Executes(BuildNative);
|
2019-06-07 00:15:43 +02:00
|
|
|
|
2020-02-29 09:18:10 +01:00
|
|
|
// ReSharper disable once UnusedMember.Local
|
2019-11-29 20:11:04 +01:00
|
|
|
Target AppVeyorBuild => _ => _
|
|
|
|
.DependsOn(Zip, Native, Publish)
|
|
|
|
.Unlisted()
|
|
|
|
.Executes(PrintResults);
|
2019-06-07 00:15:43 +02:00
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
Target Standard => _ => _
|
|
|
|
.DependsOn(Test, Zip)
|
|
|
|
.Executes(PrintResults);
|
2019-06-07 00:15:43 +02:00
|
|
|
|
2020-02-29 09:18:10 +01:00
|
|
|
// ReSharper disable once UnusedMember.Local
|
2019-11-29 20:11:04 +01:00
|
|
|
Target Full => _ => _
|
|
|
|
.DependsOn(Sign, Native)
|
|
|
|
.Executes(PrintResults);
|
2019-11-28 02:52:20 +01:00
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
public void PrintResults()
|
|
|
|
{
|
|
|
|
Logger.Normal("SHA-1:");
|
2019-12-28 23:16:21 +01:00
|
|
|
using (var sha = SHA1.Create())
|
2019-11-29 20:11:04 +01:00
|
|
|
{
|
|
|
|
foreach (string filename in Directory.EnumerateFiles(ArtifactsDirectory))
|
|
|
|
{
|
|
|
|
using (var stream = new FileStream(filename, FileMode.Open))
|
2019-11-28 02:52:20 +01:00
|
|
|
{
|
2019-11-29 20:11:04 +01:00
|
|
|
string hash = BitConverter.ToString(sha.ComputeHash(stream)).Replace("-", "");
|
|
|
|
Logger.Normal($"{hash} - {Path.GetFileName(filename)}");
|
2019-11-28 02:52:20 +01:00
|
|
|
}
|
2019-11-29 20:11:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-28 02:52:20 +01:00
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
|
|
|
|
public void BuildNative()
|
|
|
|
{
|
2020-01-17 08:01:25 +01:00
|
|
|
string buildType = Untrimmed ? "native-untrimmed" : "native";
|
2019-06-07 00:15:43 +02:00
|
|
|
|
2020-01-17 08:01:25 +01:00
|
|
|
DotNetPublishSettings publishSettings = new DotNetPublishSettings()
|
|
|
|
.SetConfiguration(Configuration)
|
|
|
|
.SetProject(HactoolnetProject)
|
|
|
|
.SetRuntime(NativeRuntime)
|
|
|
|
.SetOutput(CliNativeDir)
|
|
|
|
.SetProperties(VersionProps)
|
|
|
|
.AddProperty("BuildType", buildType);
|
2019-11-29 20:11:04 +01:00
|
|
|
|
2020-01-17 08:01:25 +01:00
|
|
|
DotNetPublish(publishSettings);
|
2019-06-07 00:15:43 +02:00
|
|
|
|
2020-01-17 08:01:25 +01:00
|
|
|
if (EnvironmentInfo.IsUnix && !Untrimmed)
|
|
|
|
{
|
2020-02-29 09:18:10 +01:00
|
|
|
File.Copy(CliNativeExe, CliNativeExe + "_unstripped", true);
|
2020-01-17 08:01:25 +01:00
|
|
|
ProcessTasks.StartProcess("strip", CliNativeExe).AssertZeroExitCode();
|
|
|
|
}
|
2019-11-29 20:11:04 +01:00
|
|
|
|
2020-01-17 08:01:25 +01:00
|
|
|
EnsureExistingDirectory(ArtifactsDirectory);
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2020-01-17 08:01:25 +01:00
|
|
|
ZipFile(CliNativeZip, CliNativeExe, $"hactoolnet{NativeProgramExtension}");
|
|
|
|
Logger.Normal($"Created {CliNativeZip}");
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2020-01-17 08:01:25 +01:00
|
|
|
if (Host == HostType.AppVeyor)
|
2019-11-29 20:11:04 +01:00
|
|
|
{
|
2020-01-17 08:01:25 +01:00
|
|
|
PushArtifact(CliNativeZip);
|
2019-11-29 20:11:04 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-17 02:03:56 +01:00
|
|
|
|
|
|
|
public static void ZipFiles(string outFile, IEnumerable<string> files)
|
|
|
|
{
|
|
|
|
using (var s = new ZipOutputStream(File.Create(outFile)))
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
s.SetLevel(9);
|
|
|
|
|
|
|
|
foreach (string file in files)
|
|
|
|
{
|
|
|
|
var entry = new ZipEntry(Path.GetFileName(file));
|
|
|
|
entry.DateTime = DateTime.UnixEpoch;
|
|
|
|
|
|
|
|
using (FileStream fs = File.OpenRead(file))
|
|
|
|
{
|
|
|
|
entry.Size = fs.Length;
|
|
|
|
s.PutNextEntry(entry);
|
|
|
|
fs.CopyTo(s);
|
|
|
|
}
|
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
2019-02-17 02:03:56 +01:00
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
public static void ZipFile(string outFile, string file, string nameInsideZip)
|
|
|
|
{
|
|
|
|
using (var s = new ZipOutputStream(File.Create(outFile)))
|
|
|
|
{
|
|
|
|
s.SetLevel(9);
|
|
|
|
|
|
|
|
var entry = new ZipEntry(nameInsideZip);
|
|
|
|
entry.DateTime = DateTime.UnixEpoch;
|
|
|
|
|
|
|
|
using (FileStream fs = File.OpenRead(file))
|
|
|
|
{
|
|
|
|
entry.Size = fs.Length;
|
|
|
|
s.PutNextEntry(entry);
|
|
|
|
fs.CopyTo(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
public static void ZipDirectory(string outFile, string directory)
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
using (var s = new ZipOutputStream(File.Create(outFile)))
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
s.SetLevel(9);
|
|
|
|
|
|
|
|
foreach (string filePath in Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories))
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
string relativePath = Path.GetRelativePath(directory, filePath);
|
|
|
|
|
|
|
|
var entry = new ZipEntry(relativePath);
|
|
|
|
entry.DateTime = DateTime.UnixEpoch;
|
|
|
|
|
|
|
|
using (FileStream fs = File.OpenRead(filePath))
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
entry.Size = fs.Length;
|
|
|
|
s.PutNextEntry(entry);
|
|
|
|
fs.CopyTo(s);
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-17 02:03:56 +01:00
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
public static void ZipDirectory(string outFile, string directory, IEnumerable<string> files)
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
using (var s = new ZipOutputStream(File.Create(outFile)))
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
s.SetLevel(9);
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
foreach (string filePath in files)
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
string absolutePath = Path.Combine(directory, filePath);
|
|
|
|
|
|
|
|
var entry = new ZipEntry(filePath);
|
|
|
|
entry.DateTime = DateTime.UnixEpoch;
|
|
|
|
|
|
|
|
using (FileStream fs = File.OpenRead(absolutePath))
|
|
|
|
{
|
|
|
|
entry.Size = fs.Length;
|
|
|
|
s.PutNextEntry(entry);
|
|
|
|
fs.CopyTo(s);
|
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
public static void UnzipFiles(string zipFile, string outDir)
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
using (var s = new ZipInputStream(File.OpenRead(zipFile)))
|
|
|
|
{
|
|
|
|
ZipEntry entry;
|
|
|
|
while ((entry = s.GetNextEntry()) != null)
|
|
|
|
{
|
|
|
|
string outPath = Path.Combine(outDir, entry.Name);
|
|
|
|
|
|
|
|
string directoryName = Path.GetDirectoryName(outPath);
|
|
|
|
string fileName = Path.GetFileName(outPath);
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(directoryName))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(directoryName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(fileName))
|
|
|
|
{
|
|
|
|
using (FileStream outFile = File.Create(outPath))
|
|
|
|
{
|
|
|
|
s.CopyTo(outFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
public static void PushArtifact(string path)
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
if (!File.Exists(path))
|
|
|
|
{
|
2019-11-29 20:11:04 +01:00
|
|
|
Logger.Warn($"Unable to add artifact {path}");
|
2019-02-17 02:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var psi = new ProcessStartInfo
|
|
|
|
{
|
|
|
|
FileName = "appveyor",
|
|
|
|
Arguments = $"PushArtifact \"{path}\"",
|
|
|
|
UseShellExecute = false,
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
RedirectStandardError = true
|
|
|
|
};
|
|
|
|
|
|
|
|
var proc = new Process
|
|
|
|
{
|
|
|
|
StartInfo = psi
|
|
|
|
};
|
|
|
|
|
|
|
|
proc.Start();
|
|
|
|
|
|
|
|
proc.WaitForExit();
|
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
Logger.Normal($"Added AppVeyor artifact {path}");
|
2019-02-17 02:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void SetAppVeyorVersion(string version)
|
2018-11-22 04:57:18 +01:00
|
|
|
{
|
2019-02-17 02:03:56 +01:00
|
|
|
var psi = new ProcessStartInfo
|
|
|
|
{
|
|
|
|
FileName = "appveyor",
|
|
|
|
Arguments = $"UpdateBuild -Version \"{version}\"",
|
|
|
|
UseShellExecute = false,
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
RedirectStandardError = true
|
|
|
|
};
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
var proc = new Process
|
|
|
|
{
|
|
|
|
StartInfo = psi
|
|
|
|
};
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
proc.Start();
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
proc.WaitForExit();
|
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
public static void ReplaceLineEndings(string filename)
|
|
|
|
{
|
|
|
|
string text = File.ReadAllText(filename);
|
|
|
|
File.WriteAllText(filename, Regex.Replace(text, @"\r\n|\n\r|\n|\r", "\r\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void SignAssemblies(string password, params string[] fileNames)
|
|
|
|
{
|
|
|
|
SignToolSettings settings = new SignToolSettings()
|
|
|
|
.SetFileDigestAlgorithm("SHA256")
|
|
|
|
.SetFile(CertFileName)
|
|
|
|
.SetFiles(fileNames)
|
|
|
|
.SetPassword(password)
|
|
|
|
.SetTimestampServerDigestAlgorithm("SHA256")
|
|
|
|
.SetRfc3161TimestampServerUrl("http://timestamp.digicert.com");
|
|
|
|
|
|
|
|
SignToolTasks.SignTool(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SignAndReZip(string password)
|
|
|
|
{
|
|
|
|
AbsolutePath nupkgFile = ArtifactsDirectory.GlobFiles("*.nupkg").Single();
|
|
|
|
AbsolutePath snupkgFile = ArtifactsDirectory.GlobFiles("*.snupkg").Single();
|
|
|
|
AbsolutePath nupkgDir = TempDirectory / ("sign_" + Path.GetFileName(nupkgFile));
|
|
|
|
AbsolutePath coreFxDir = TempDirectory / ("sign_" + Path.GetFileName(CliCoreZip));
|
2019-11-29 20:11:04 +01:00
|
|
|
AbsolutePath nativeZipDir = TempDirectory / ("sign_" + Path.GetFileName(CliNativeZip));
|
|
|
|
|
|
|
|
bool signNative = FileExists(CliNativeExe);
|
2019-02-17 02:03:56 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
UnzipFiles(CliCoreZip, coreFxDir);
|
|
|
|
List<string> pkgFileList = UnzipPackage(nupkgFile, nupkgDir);
|
|
|
|
|
|
|
|
var toSign = new List<AbsolutePath>();
|
|
|
|
toSign.AddRange(nupkgDir.GlobFiles("**/LibHac.dll"));
|
|
|
|
toSign.Add(coreFxDir / "hactoolnet.dll");
|
2019-11-29 20:11:04 +01:00
|
|
|
|
|
|
|
if (signNative)
|
|
|
|
{
|
|
|
|
UnzipFiles(CliNativeZip, nativeZipDir);
|
|
|
|
toSign.Add(nativeZipDir / "hactoolnet.exe");
|
|
|
|
}
|
2019-02-17 02:03:56 +01:00
|
|
|
|
|
|
|
Directory.CreateDirectory(SignedArtifactsDirectory);
|
|
|
|
|
|
|
|
SignAssemblies(password, toSign.Select(x => x.ToString()).ToArray());
|
|
|
|
|
|
|
|
// Avoid having multiple signed versions of the same file
|
2019-10-15 04:10:53 +02:00
|
|
|
File.Copy(nupkgDir / "lib" / "netcoreapp3.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true);
|
2019-02-17 02:03:56 +01:00
|
|
|
|
|
|
|
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), nupkgDir, pkgFileList);
|
|
|
|
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliCoreZip), coreFxDir);
|
|
|
|
|
2019-11-29 20:11:04 +01:00
|
|
|
if (signNative)
|
|
|
|
{
|
|
|
|
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliNativeZip), nativeZipDir);
|
|
|
|
}
|
|
|
|
|
2019-02-17 02:03:56 +01:00
|
|
|
File.Copy(snupkgFile, SignedArtifactsDirectory / Path.GetFileName(snupkgFile));
|
|
|
|
|
|
|
|
SignNupkg(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), password);
|
|
|
|
SignNupkg(SignedArtifactsDirectory / Path.GetFileName(snupkgFile), password);
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
Directory.Delete(SignedArtifactsDirectory, true);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
Directory.Delete(nupkgDir, true);
|
|
|
|
Directory.Delete(coreFxDir, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string ReadPassword()
|
|
|
|
{
|
|
|
|
var pwd = new StringBuilder();
|
|
|
|
ConsoleKeyInfo key;
|
|
|
|
|
|
|
|
Console.Write("Enter certificate password (Empty password to skip): ");
|
|
|
|
do
|
|
|
|
{
|
|
|
|
key = Console.ReadKey(true);
|
|
|
|
|
|
|
|
// Ignore any key out of range.
|
|
|
|
if (((int)key.Key) >= '!' && ((int)key.Key <= '~'))
|
|
|
|
{
|
|
|
|
// Append the character to the password.
|
|
|
|
pwd.Append(key.KeyChar);
|
|
|
|
Console.Write("*");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exit if Enter key is pressed.
|
|
|
|
} while (key.Key != ConsoleKey.Enter);
|
|
|
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
|
|
|
return pwd.ToString();
|
|
|
|
}
|
2018-11-22 04:57:18 +01:00
|
|
|
}
|
|
|
|
}
|