Skip to content

Commit

Permalink
update build system
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus committed Mar 24, 2021
1 parent 6b9543d commit 4bc1c7a
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 116 deletions.
171 changes: 124 additions & 47 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open System.Text
open Fake
open Fake.DotNetCli
open Fake.DocFxHelper
open Fake.NuGet.Install

// Information about the project for Nuget and Assembly info files
let product = "Hyperion"
Expand All @@ -18,36 +19,58 @@ let signingName = "Hyperion"
let signingDescription = "A high performance polymorphic serializer for the .NET framework"
let signingUrl = ""

// Directories
let toolsDir = __SOURCE_DIRECTORY__ @@ "tools"
let output = __SOURCE_DIRECTORY__ @@ "bin"
let outputTests = __SOURCE_DIRECTORY__ @@ "TestResults"
let outputPerfTests = __SOURCE_DIRECTORY__ @@ "PerfResults"
let outputBinaries = output @@ "binaries"
let outputBinariesNet461 = outputBinaries @@ "net461"
let outputBinariesNetStandard = outputBinaries @@ "netstandard2.0"
let outputBinariesNet = outputBinaries @@ "net5.0"
let outputNuGet = output @@ "nuget"

// Read release notes and version
let solutionFile = FindFirstMatchingFile "*.sln" __SOURCE_DIRECTORY__ // dynamically look up the solution
let buildNumber = environVarOrDefault "BUILD_NUMBER" "0"
let hasTeamCity = (not (buildNumber = "0")) // check if we have the TeamCity environment variable for build # set
let preReleaseVersionSuffix = "beta" + (if (not (buildNumber = "0")) then (buildNumber) else DateTime.UtcNow.Ticks.ToString())
let versionSuffix =
match (getBuildParam "nugetprerelease") with
| "dev" -> preReleaseVersionSuffix
| _ -> ""

let releaseNotes =
File.ReadLines "./RELEASE_NOTES.md"
File.ReadLines (__SOURCE_DIRECTORY__ @@ "RELEASE_NOTES.md")
|> ReleaseNotesHelper.parseReleaseNotes

// Directories
let toolsDir = __SOURCE_DIRECTORY__ @@ "tools"
let output = __SOURCE_DIRECTORY__ @@ "bin"
let outputTests = __SOURCE_DIRECTORY__ @@ "TestResults"
let outputPerfTests = __SOURCE_DIRECTORY__ @@ "PerfResults"
let outputNuGet = output @@ "nuget"
let versionFromReleaseNotes =
match releaseNotes.SemVer.PreRelease with
| Some r -> r.Origin
| None -> ""

let versionSuffix =
match (getBuildParam "nugetprerelease") with
| "dev" -> preReleaseVersionSuffix
| "" -> versionFromReleaseNotes
| str -> str

// Configuration values for tests
let testNetFrameworkVersion = "net461"
let testNetCoreVersion = "netcoreapp3.1"
let testNetVersion = "net5.0"

Target "Clean" (fun _ ->
ActivateFinalTarget "KillCreatedProcesses"

CleanDir output
CleanDir outputTests
CleanDir outputPerfTests
CleanDir outputBinaries
CleanDir outputNuGet
CleanDir outputBinariesNet461
CleanDir outputBinariesNetStandard
CleanDir outputBinariesNet
CleanDir "docs/_site"

CleanDirs !! "./**/bin"
CleanDirs !! "./**/obj"
)

Target "AssemblyInfo" (fun _ ->
Expand All @@ -56,17 +79,20 @@ Target "AssemblyInfo" (fun _ ->
)

Target "Build" (fun _ ->
let additionalArgs = if versionSuffix.Length > 0 then [sprintf "/p:VersionSuffix=%s" versionSuffix] else []
DotNetCli.Build
(fun p ->
{ p with
Project = solutionFile
Configuration = configuration }) // "Rebuild"
Configuration = configuration
AdditionalArgs = additionalArgs }) // "Rebuild"
)


//--------------------------------------------------------------------------------
// Tests targets
//--------------------------------------------------------------------------------

module internal ResultHandling =
let (|OK|Failure|) = function
| 0 -> OK
Expand Down Expand Up @@ -94,8 +120,32 @@ Target "RunTests" (fun _ ->
let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --results-directory %s -- -parallel none -teamcity" (outputTests))
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --results-directory %s -- -parallel none" (outputTests))
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none -teamcity" testNetFrameworkVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none" testNetFrameworkVersion outputTests)

let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)

ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result

CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
)

Target "RunTestsNetCore" (fun _ ->
let projects =
match (isWindows) with
| true -> !! "./src/**/*.Tests.csproj"
| _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here

let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none -teamcity" testNetCoreVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none" testNetCoreVersion outputTests)

let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
Expand All @@ -104,44 +154,64 @@ Target "RunTests" (fun _ ->

ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result

CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
)

Target "RunTestsNet" (fun _ ->
let projects =
match (isWindows) with
| true -> !! "./src/**/*.Tests.csproj"
| _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here

let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none -teamcity" testNetVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none" testNetVersion outputTests)

let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)

ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result

CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
)

Target "NBench" <| fun _ ->
let nbenchTestPath = findToolInSubPath "NBench.Runner.exe" (toolsDir @@ "NBench.Runner*")
printfn "Using NBench.Runner: %s" nbenchTestPath

let nbenchTestAssemblies = !! "./src/**/bin/**/*Tests.Performance.dll" // doesn't support .NET Core at the moment

let runNBench assembly =
let includes = getBuildParam "include"
let excludes = getBuildParam "exclude"
let teamcityStr = (getBuildParam "teamcity")
let enableTeamCity =
match teamcityStr with
| null -> false
| "" -> false
| _ -> bool.Parse teamcityStr

let args = StringBuilder()
|> append assembly
|> append (sprintf "output-directory=\"%s\"" outputPerfTests)
|> append (sprintf "concurrent=\"%b\"" true)
|> append (sprintf "trace=\"%b\"" true)
|> append (sprintf "teamcity=\"%b\"" enableTeamCity)
|> appendIfNotNullOrEmpty includes "include="
|> appendIfNotNullOrEmpty excludes "include="
ensureDirectory outputPerfTests
let projects =
match (isWindows) with
| true -> !! "./src/**/*Tests.Performance.csproj"
| _ -> !! "./src/**/*Tests.Performance.csproj" // if you need to filter specs for Linux vs. Windows, do it here

projects |> Seq.iter(fun project ->
let args = new StringBuilder()
|> append "run"
|> append "--no-build"
|> append "-c"
|> append configuration
|> append " -- "
|> append "--output"
|> append outputPerfTests
|> append "--concurrent"
|> append "true"
|> append "--trace"
|> append "true"
|> append "--diagnostic"
|> toText

let result = ExecProcess(fun info ->
info.FileName <- nbenchTestPath
info.WorkingDirectory <- (Path.GetDirectoryName (FullName nbenchTestPath))
info.Arguments <- args) (System.TimeSpan.FromMinutes 45.0) (* Reasonably long-running task. *)

if result <> 0 then failwithf "NBench.Runner failed. %s %s" nbenchTestPath args

nbenchTestAssemblies |> Seq.iter runNBench
let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- args) (System.TimeSpan.FromMinutes 15.0) (* Reasonably long-running task. *)
if result <> 0 then failwithf "NBench.Runner failed. %s %s" "dotnet" args
)


//--------------------------------------------------------------------------------
Expand Down Expand Up @@ -301,23 +371,30 @@ Target "Help" <| fun _ ->
Target "BuildRelease" DoNothing
Target "All" DoNothing
Target "Nuget" DoNothing
Target "RunTestsFull" DoNothing
Target "RunTestsNetCoreFull" DoNothing

// build dependencies
"Clean" ==> "AssemblyInfo" ==> "Build" ==> "BuildRelease"

// tests dependencies
"Build" ==> "RunTests"
"Build" ==> "RunTestsNetCore"
"Build" ==> "RunTestsNet"
"Build" ==> "NBench"

// nuget dependencies
"Clean" ==> "Build" ==> "CreateNuget"
"BuildRelease" ==> "CreateNuget"
"CreateNuget" ==> "SignPackages" ==> "PublishNuget" ==> "Nuget"

// docs
"Clean" ==> "BuildRelease" ==> "Docfx"
"BuildRelease" ==> "Docfx"

// all
"BuildRelease" ==> "All"
"RunTests" ==> "All"
"RunTestsNetCore" ==> "All"
"RunTestsNet" ==> "All"
"NBench" ==> "All"
"Nuget" ==> "All"

Expand Down
56 changes: 4 additions & 52 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ Param(
[string[]]$ScriptArgs
)

$FakeVersion = "4.61.2"
$DotNetChannel = "LTS";
$DotNetVersion = "3.0.100";
$DotNetInstallerUri = "https://dot.net/v1/dotnet-install.ps1";
$NugetVersion = "4.1.0";
$FakeVersion = "4.63.2"
$NugetVersion = "5.8.0";
$NugetUrl = "https://dist.nuget.org/win-x86-commandline/v$NugetVersion/nuget.exe"
$ProtobufVersion = "3.2.0"
$DocfxVersion = "2.40.5"
$ProtobufVersion = "3.13.0"
$DocfxVersion = "2.48.1"

# Make sure tools folder exists
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
Expand All @@ -46,51 +43,6 @@ if (!(Test-Path $ToolPath)) {
New-Item -Path $ToolPath -Type directory | out-null
}

###########################################################################
# INSTALL .NET CORE CLI
###########################################################################

Function Remove-PathVariable([string]$VariableToRemove)
{
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($path -ne $null)
{
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
}

$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
if ($path -ne $null)
{
$newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
}
}

# Get .NET Core CLI path if installed.
$FoundDotNetCliVersion = $null;
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
$FoundDotNetCliVersion = dotnet --version;
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
}

if($FoundDotNetCliVersion -ne $DotNetVersion) {
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
if (!(Test-Path $InstallPath)) {
mkdir -Force $InstallPath | Out-Null;
}
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1");
& $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath -Architecture x64;

Remove-PathVariable "$InstallPath"
$env:PATH = "$InstallPath;$env:PATH"
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
$env:DOTNET_ROOT=$InstallPath
}


###########################################################################
# INSTALL NUGET
###########################################################################
Expand Down
17 changes: 0 additions & 17 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,6 @@ if [ ! -d "$TOOLS_DIR" ]; then
mkdir "$TOOLS_DIR"
fi

###########################################################################
# INSTALL .NET CORE CLI
###########################################################################

echo "Installing .NET CLI..."
if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then
mkdir "$SCRIPT_DIR/.dotnet"
fi
curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" $DOTNET_INSTALLER_URL
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --channel $DOTNET_CHANNEL --install-dir .dotnet --no-path
export PATH="$SCRIPT_DIR/.dotnet":$PATH
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
chmod -R 0755 ".dotnet"
"$SCRIPT_DIR/.dotnet/dotnet" --info


###########################################################################
# INSTALL NUGET
###########################################################################
Expand Down

0 comments on commit 4bc1c7a

Please sign in to comment.