From fc1e09811851b703c2ac9560b9001140b6109e42 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Fri, 17 Dec 2021 00:59:18 -0700 Subject: [PATCH] Update NUKE version and build script dependencies --- .gitignore | 1 + .nuke | 0 .nuke/build.schema.json | 135 ++++++++++++++++++++++++++ .nuke/parameters.json | 4 + appveyor.yml | 3 +- build.cmd | 2 +- build.ps1 | 30 +++--- build.sh | 17 ++-- build/Build.cs | 75 +++----------- build/CodeGen/Stage1/ResultCodegen.cs | 2 +- build/CodeGen/_buildCodeGen.csproj | 2 +- build/_build.csproj | 11 ++- 12 files changed, 194 insertions(+), 88 deletions(-) delete mode 100644 .nuke create mode 100644 .nuke/build.schema.json create mode 100644 .nuke/parameters.json diff --git a/.gitignore b/.gitignore index 934b03dc..70b6d4ac 100644 --- a/.gitignore +++ b/.gitignore @@ -261,6 +261,7 @@ __pycache__/ *.pyc **/launchSettings.json +.nuke/temp global.json diff --git a/.nuke b/.nuke deleted file mode 100644 index e69de29b..00000000 diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json new file mode 100644 index 00000000..a5fa31d4 --- /dev/null +++ b/.nuke/build.schema.json @@ -0,0 +1,135 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Build Schema", + "$ref": "#/definitions/build", + "definitions": { + "build": { + "type": "object", + "properties": { + "_solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded. Default is LibHac.sln" + }, + "Configuration": { + "type": "string", + "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)" + }, + "Continue": { + "type": "boolean", + "description": "Indicates to continue a previously failed build attempt" + }, + "Help": { + "type": "boolean", + "description": "Shows the help text for this build assembly" + }, + "Host": { + "type": "string", + "description": "Host for execution. Default is 'automatic'", + "enum": [ + "AppVeyor", + "AzurePipelines", + "Bamboo", + "Bitrise", + "GitHubActions", + "GitLab", + "Jenkins", + "Rider", + "SpaceAutomation", + "TeamCity", + "Terminal", + "TravisCI", + "VisualStudio", + "VSCode" + ] + }, + "NoLogo": { + "type": "boolean", + "description": "Disables displaying the NUKE logo" + }, + "NoReflection": { + "type": "boolean", + "description": "Disable reflection in native builds" + }, + "Partition": { + "type": "string", + "description": "Partition to use on CI" + }, + "Plan": { + "type": "boolean", + "description": "Shows the execution plan (HTML)" + }, + "Profile": { + "type": "array", + "description": "Defines the profiles to load", + "items": { + "type": "string" + } + }, + "Root": { + "type": "string", + "description": "Root directory during build execution" + }, + "Skip": { + "type": "array", + "description": "List of targets to be skipped. Empty list skips all dependencies", + "items": { + "type": "string", + "enum": [ + "AppVeyorBuild", + "Clean", + "Codegen", + "Compile", + "Full", + "Native", + "Pack", + "Publish", + "Restore", + "SetVersion", + "Sign", + "Standard", + "Test", + "Zip" + ] + } + }, + "Target": { + "type": "array", + "description": "List of targets to be invoked. Default is '{default_target}'", + "items": { + "type": "string", + "enum": [ + "AppVeyorBuild", + "Clean", + "Codegen", + "Compile", + "Full", + "Native", + "Pack", + "Publish", + "Restore", + "SetVersion", + "Sign", + "Standard", + "Test", + "Zip" + ] + } + }, + "Untrimmed": { + "type": "boolean", + "description": "Don't enable any size-reducing settings on native builds" + }, + "Verbosity": { + "type": "string", + "description": "Logging verbosity during build execution. Default is 'Normal'", + "enum": [ + "Minimal", + "Normal", + "Quiet", + "Verbose" + ] + } + } + } + } +} \ No newline at end of file diff --git a/.nuke/parameters.json b/.nuke/parameters.json new file mode 100644 index 00000000..42521bb7 --- /dev/null +++ b/.nuke/parameters.json @@ -0,0 +1,4 @@ +{ + "$schema": "./build.schema.json", + "Solution": "" +} \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 7936c6c0..2b3872d9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,7 @@ version: 0.0.0-{build} -image: Visual Studio 2019 +image: Visual Studio 2022 environment: + IGNORE_NORMALISATION_GIT_HEAD_MOVE: 1 myget_api_key: secure: 0xJoYAtR6psXCRvk1qm5czDObkeRjHKPjfe5gIExXVFPwA0VVODYv/hBZYUtz2F3 build_script: diff --git a/build.cmd b/build.cmd index 8b8b89dc..b08cc590 100644 --- a/build.cmd +++ b/build.cmd @@ -4,4 +4,4 @@ :; exit $? @ECHO OFF -powershell -ExecutionPolicy ByPass -NoProfile "%~dp0build.ps1" %* +powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %* diff --git a/build.ps1 b/build.ps1 index 922a8030..d1a4863d 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,6 +1,6 @@ [CmdletBinding()] Param( - [Parameter(Position = 0, Mandatory = $false, ValueFromRemainingArguments = $true)] + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$BuildArguments ) @@ -14,9 +14,9 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent ########################################################################### $BuildProjectFile = "$PSScriptRoot\build\_build.csproj" -$TempDirectory = "$PSScriptRoot\.tmp" +$TempDirectory = "$PSScriptRoot\\.nuke\temp" -$DotNetGlobalFile = "$PSScriptRoot\global.json" +$DotNetGlobalFile = "$PSScriptRoot\\global.json" $DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" $DotNetChannel = "Current" $DotNetCliVersion = Get-Content DotnetCliVersion.txt @@ -38,22 +38,26 @@ function ExecSafe([scriptblock] $cmd) { try { $json = "{`"sdk`":{`"version`":`"$DotNetCliVersion`"}}" Out-File -FilePath $DotNetGlobalFile -Encoding utf8 -InputObject $json - + # If global.json exists, load expected version if (Test-Path $DotNetGlobalFile) { - $DotNetVersion = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json).sdk.version + $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) + if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) { + $DotNetVersion = $DotNetGlobal.sdk.version + } } - + $DotNetDirectory = "$TempDirectory\dotnet-win" $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" - # If dotnet is installed locally, and expected version is not set or installation matches the expected version + # If dotnet CLI is installed globally and it matches requested version, use for execution if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and ` - (!(Test-Path variable:DotNetVersion) -or $(& cmd.exe /c 'dotnet --version 2>&1') -eq $DotNetVersion)) { + $(dotnet --version) -eq $DotNetVersion) { $env:DOTNET_EXE = (Get-Command "dotnet").Path } + # If dotnet CLI is installed locally and it matches requested version, use for execution elseif ($null -eq (Get-Command $env:DOTNET_EXE -ErrorAction SilentlyContinue) -or ` - !(Test-Path variable:DotNetVersion) -or $(& cmd.exe /c "$env:DOTNET_EXE --version 2>&1") -ne $DotNetVersion) { + !(Test-Path variable:DotNetVersion) -or $(& $env:DOTNET_EXE --version) -ne $DotNetVersion) { # Download install script $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" @@ -63,11 +67,11 @@ try { # Install by channel or version if (!(Test-Path variable:DotNetVersion)) { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } - } - else { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } + } else { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } } + $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" } Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)" diff --git a/build.sh b/build.sh index 5565e1ef..347776b7 100755 --- a/build.sh +++ b/build.sh @@ -10,9 +10,9 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) ########################################################################### BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj" -TEMP_DIRECTORY="$SCRIPT_DIR/.tmp" +TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" -DOTNET_GLOBAL_FILE="$SCRIPT_DIR/global.json" +DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" DOTNET_CHANNEL="Current" @@ -25,7 +25,7 @@ export DOTNET_MULTILEVEL_LOOKUP=0 ########################################################################### function FirstJsonValue { - perl -nle 'print $1 if m{"'$1'": "([^"\-]+)",?}' <<< ${@:2} + perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}" } trap "rm -f \"$DOTNET_GLOBAL_FILE\"" INT TERM EXIT @@ -35,18 +35,18 @@ json="{\"sdk\":{\"version\":\"$dotnetCliVersion\"}}" echo "$json" > "$DOTNET_GLOBAL_FILE" # If global.json exists, load expected version -if [ -f "$DOTNET_GLOBAL_FILE" ]; then +if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then DOTNET_VERSION=$dotnetCliVersion fi DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" -# If dotnet is installed locally, and expected version is not set or installation matches the expected version +# If dotnet CLI is installed globally and it matches requested version, use for execution if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version) == "$DOTNET_VERSION") ]]; then export DOTNET_EXE="$(command -v dotnet)" elif [[ ! (-x "$DOTNET_EXE" && (-z ${DOTNET_VERSION+x} || $($DOTNET_EXE --version) == "$DOTNET_VERSION")) ]]; then - + # Download install script DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" mkdir -p "$TEMP_DIRECTORY" @@ -55,9 +55,10 @@ elif [[ ! (-x "$DOTNET_EXE" && (-z ${DOTNET_VERSION+x} || $($DOTNET_EXE --versio curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" chmod +x "$DOTNET_INSTALL_FILE" fi - + # Install by channel or version - if [ -z ${DOTNET_VERSION+x} ]; then + + if [[ -z ${DOTNET_VERSION+x} ]]; then "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path else "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path diff --git a/build/Build.cs b/build/Build.cs index dbe6a0a4..bbd255e7 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -43,7 +43,7 @@ partial class Build : NukeBuild AbsolutePath TestsDirectory => RootDirectory / "tests"; AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed"; - AbsolutePath TempDirectory => RootDirectory / ".tmp"; + AbsolutePath TempDirectory => RootDirectory / ".nuke" / "temp"; AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net5.0"; AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}"; AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet{NativeProgramExtension}"; @@ -142,21 +142,21 @@ partial class Build : NukeBuild suffix += $"+{gitVersion.Sha.Substring(0, 8)}"; } - if (Host == HostType.AppVeyor) + if (Host is AppVeyor appVeyor) { - // Workaround GitVersion issue by getting PR info manually https://github.com/GitTools/GitVersion/issues/1927 - string prNumber = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER"); + // Workaround GitVersion issue by getting PR info manually https://github.com/GitTools/GitVersion/issues/1927 + int? prNumber = appVeyor.PullRequestNumber; string branchName = Environment.GetEnvironmentVariable("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH"); - if (int.TryParse(prNumber, out int prInt) && branchName != null) + if (prNumber != null && branchName != null) { - string prString = $"PullRequest{prInt:D4}"; + string prString = $"PullRequest{prNumber:D4}"; VersionString = VersionString.Replace(branchName, prString); - suffix = suffix.Replace(branchName, prString); + suffix = suffix?.Replace(branchName, prString) ?? ""; } - SetAppVeyorVersion(VersionString); + appVeyor.UpdateBuildVersion(VersionString); } VersionProps = new Dictionary @@ -226,8 +226,8 @@ partial class Build : NukeBuild .SetNoBuild(true) .SetProperties(VersionProps)); - // Hack around OS newline differences - if (EnvironmentInfo.IsUnix) + // Hack around OS newline differences + if (EnvironmentInfo.IsUnix) { foreach (string filename in Directory.EnumerateFiles(CliCoreDir, "*.json")) { @@ -256,8 +256,6 @@ partial class Build : NukeBuild RepackNugetPackage(filename); } - if (Host != HostType.AppVeyor) return; - foreach (string filename in Directory.EnumerateFiles(ArtifactsDirectory, "*.*nupkg")) { PushArtifact(filename); @@ -292,10 +290,7 @@ partial class Build : NukeBuild ZipFiles(CliCoreZip, namesCore); Logger.Normal($"Created {CliCoreZip}"); - if (Host == HostType.AppVeyor) - { - PushArtifact(CliCoreZip); - } + PushArtifact(CliCoreZip); }); Target Publish => _ => _ @@ -396,10 +391,7 @@ partial class Build : NukeBuild ZipFile(CliNativeZip, CliNativeExe, $"hactoolnet{NativeProgramExtension}"); Logger.Normal($"Created {CliNativeZip}"); - if (Host == HostType.AppVeyor) - { - PushArtifact(CliNativeZip); - } + PushArtifact(CliNativeZip); } public static void ZipFiles(string outFile, IEnumerable files) @@ -530,55 +522,20 @@ partial class Build : NukeBuild return compressed; } - public static void PushArtifact(string path) + public static void PushArtifact(string path, string name = null) { + if (Host is not AppVeyor appVeyor) return; + if (!File.Exists(path)) { Logger.Warn($"Unable to add artifact {path}"); } - 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(); + appVeyor.PushArtifact(path, name); Logger.Normal($"Added AppVeyor artifact {path}"); } - public static void SetAppVeyorVersion(string version) - { - var psi = new ProcessStartInfo - { - FileName = "appveyor", - Arguments = $"UpdateBuild -Version \"{version}\"", - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true - }; - - var proc = new Process - { - StartInfo = psi - }; - - proc.Start(); - - proc.WaitForExit(); - } - public static void ReplaceLineEndings(string filename) { string text = File.ReadAllText(filename); diff --git a/build/CodeGen/Stage1/ResultCodegen.cs b/build/CodeGen/Stage1/ResultCodegen.cs index 296d8184..d67cd325 100644 --- a/build/CodeGen/Stage1/ResultCodegen.cs +++ b/build/CodeGen/Stage1/ResultCodegen.cs @@ -42,7 +42,7 @@ public static class ResultCodeGen WriteOutput("LibHac/ResultNameResolver.Generated.cs", archiveStr); string enumStr = PrintEnum(modules); - WriteOutput("../.tmp/result_enums.txt", enumStr); + WriteOutput("../.nuke/temp/result_enums.txt", enumStr); } private static ResultSet ReadResults() diff --git a/build/CodeGen/_buildCodeGen.csproj b/build/CodeGen/_buildCodeGen.csproj index 158f7aee..1da37816 100644 --- a/build/CodeGen/_buildCodeGen.csproj +++ b/build/CodeGen/_buildCodeGen.csproj @@ -17,7 +17,7 @@ - + diff --git a/build/_build.csproj b/build/_build.csproj index 58c95916..fcf53886 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -7,14 +7,17 @@ LibHacBuild False CS0649;CS0169 + .. + .. + 1 - - - - + + + +