2017-09-08 06:42:29 +03:00
|
|
|
##
|
|
|
|
## Psake build file for the Software Entitlement Service SDK
|
|
|
|
##
|
|
|
|
|
|
|
|
properties {
|
|
|
|
$baseDir = resolve-path ..\
|
|
|
|
$srcDir = resolve-path $baseDir\src
|
|
|
|
$testsDir = resolve-path $baseDir\tests
|
|
|
|
$outDir = join-path $baseDir out
|
2018-05-02 05:01:17 +03:00
|
|
|
$libDir = join-path $baseDir lib
|
2017-09-08 06:42:29 +03:00
|
|
|
$publishDir = join-path $baseDir publish
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
# Clean up build artifacts
|
2017-09-08 06:42:29 +03:00
|
|
|
Task Clean -Depends Clean.SourceFolder, Clean.OutFolder, Clean.PublishFolder
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
# Build just the cross platform pieces
|
|
|
|
Task Build.Xplat -Depends Clean, Build.SesTest, Unit.Tests
|
2017-09-08 06:42:29 +03:00
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
# Publish distributable zip files for the each tool and platform
|
2018-04-27 07:39:33 +03:00
|
|
|
Task Publish.Archives -Depends Clean, Request.Release, Publish.SesTest.Win64, Publish.SesTest.Linux64, Publish.SesClient.x64, Publish.SesClient.x86
|
2017-09-08 06:42:29 +03:00
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
# Build all the components for use on Windows
|
2018-04-27 07:39:33 +03:00
|
|
|
Task Build.Windows -Depends Clean, Build.SesClient.x64, Build.SesTest
|
2017-09-08 06:42:29 +03:00
|
|
|
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Preparation Targets
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Tasks used to prepare for the actual build
|
|
|
|
|
|
|
|
Task Restore.NuGetPackages -Depends Requires.DotNetExe {
|
2017-11-02 04:56:09 +03:00
|
|
|
# Restore for each C# project to avoid the errors that happen when we try to restore for a C++ project
|
|
|
|
foreach ($project in (resolve-path $srcDir\*\*.csproj, $testsDir\*\*.csproj)){
|
|
|
|
$projectName = split-path $project -Leaf
|
|
|
|
Write-SubtaskName "Restoring packages for $projectName"
|
|
|
|
exec {
|
|
|
|
& $dotnetExe restore $project --verbosity minimal
|
|
|
|
}
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Task Clean.SourceFolder {
|
2017-11-02 04:56:09 +03:00
|
|
|
remove-item $srcDir\*\bin\* -recurse -ErrorAction SilentlyContinue
|
2017-09-08 06:42:29 +03:00
|
|
|
remove-item $srcDir\*\obj\* -recurse -ErrorAction SilentlyContinue
|
2017-11-02 04:56:09 +03:00
|
|
|
remove-item $srcDir\*\publish\* -recurse -ErrorAction SilentlyContinue
|
|
|
|
|
|
|
|
remove-item $testsDir\*\bin\* -recurse -ErrorAction SilentlyContinue
|
2017-09-08 06:42:29 +03:00
|
|
|
remove-item $testsDir\*\obj\* -recurse -ErrorAction SilentlyContinue
|
2017-11-02 04:56:09 +03:00
|
|
|
remove-item $testsDir\*\publish\* -recurse -ErrorAction SilentlyContinue
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Task Clean.OutFolder {
|
2017-09-13 04:33:22 +03:00
|
|
|
remove-item $outDir\* -recurse -ErrorAction SilentlyContinue
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Task Clean.PublishFolder {
|
2017-09-13 04:33:22 +03:00
|
|
|
remove-item $publishDir -Force -Recurse -ErrorAction SilentlyContinue
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Build Targets
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Tasks used to perform steps of the actual build
|
|
|
|
|
2017-09-13 04:33:22 +03:00
|
|
|
Task Generate.Version {
|
|
|
|
|
|
|
|
$script:versionBase = get-content $baseDir\version.txt -ErrorAction SilentlyContinue
|
2017-09-27 21:56:54 +03:00
|
|
|
if ($versionBase -eq $null) {
|
|
|
|
throw "Unable to load $baseDir\version.txt"
|
2017-09-13 04:33:22 +03:00
|
|
|
}
|
2017-11-02 04:56:09 +03:00
|
|
|
|
2017-09-13 04:33:22 +03:00
|
|
|
$versionLastUpdated = git rev-list -1 HEAD $baseDir\version.txt
|
|
|
|
$script:patchVersion = git rev-list "$versionLastUpdated..HEAD" --count
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
$branch = git name-rev --name-only HEAD
|
|
|
|
Write-Output "Branch $branch"
|
|
|
|
|
2018-07-24 03:03:35 +03:00
|
|
|
$commit = git rev-parse --short HEAD
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "Commit $commit"
|
|
|
|
|
2017-09-13 04:33:22 +03:00
|
|
|
$script:version = "$versionBase.$patchVersion"
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "Version: $version"
|
|
|
|
|
|
|
|
if ($branch -eq "master") {
|
|
|
|
$script:semanticVersion = $version
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$semverBranch = $branch -replace "[^A-Za-z0-9-]+", "."
|
|
|
|
$script:semanticVersion = "$version-beta.$semverBranch.$commit"
|
|
|
|
}
|
2017-09-13 04:33:22 +03:00
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "Semver: $semanticVersion"
|
2017-09-13 04:33:22 +03:00
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
Task Build.SesTest -Depends Requires.DotNetExe, Restore.NuGetPackages, Generate.Version {
|
2017-09-13 04:33:22 +03:00
|
|
|
$project = resolve-path $srcDir\sestest\sestest.csproj
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "Building $project"
|
2017-09-08 06:42:29 +03:00
|
|
|
exec {
|
2017-11-02 04:56:09 +03:00
|
|
|
& $dotnetExe build $project /property:Version=$semanticVersion /verbosity:minimal /fileLogger /flp:verbosity=detailed`;logfile=$outDir\sestest.msbuild.log --no-restore
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 07:39:33 +03:00
|
|
|
Task Build.SesLibrary.x86 -Depends Requires.MsBuild, Requires.Configuration, Generate.Version {
|
2017-09-08 06:42:29 +03:00
|
|
|
exec {
|
2018-04-27 07:39:33 +03:00
|
|
|
& $msbuildExe $srcDir\Microsoft.Azure.Batch.SoftwareEntitlement.Client.Native\ /p:Version=$version /property:Configuration=$configuration /property:Platform=x86 /verbosity:minimal /fileLogger /flp:verbosity=detailed`;logfile=$outDir\seslibrary.x86.msbuild.log
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 07:39:33 +03:00
|
|
|
Task Build.SesLibrary.x64 -Depends Requires.MsBuild, Requires.Configuration, Generate.Version {
|
2017-09-08 06:42:29 +03:00
|
|
|
exec {
|
2018-04-27 07:39:33 +03:00
|
|
|
& $msbuildExe $srcDir\Microsoft.Azure.Batch.SoftwareEntitlement.Client.Native\ /p:Version=$version /property:Configuration=$configuration /property:Platform=x64 /verbosity:minimal /fileLogger /flp:verbosity=detailed`;logfile=$outDir\seslibrary.msbuild.log
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Task Build.SesClient.x86 -Depends Requires.MsBuild, Requires.Configuration, Build.SesLibrary.x86, Generate.Version {
|
|
|
|
exec {
|
|
|
|
& $msbuildExe $srcDir\sesclient.native\ /property:Configuration=$configuration /p:Version=$version /property:Platform=x86 /verbosity:minimal /fileLogger /flp:verbosity=detailed`;logfile=$outDir\sesclient.msbuild.log
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Task Build.SesClient.x64 -Depends Requires.MsBuild, Requires.Configuration, Build.SesLibrary.x64, Generate.Version {
|
|
|
|
exec {
|
|
|
|
& $msbuildExe $srcDir\sesclient.native\ /property:Configuration=$configuration /p:Version=$version /property:Platform=x64 /verbosity:minimal /fileLogger /flp:verbosity=detailed`;logfile=$outDir\sesclient.msbuild.log
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
Task Build.UnitTests -Depends Requires.DotNetExe {
|
2017-09-08 06:42:29 +03:00
|
|
|
foreach ($project in (resolve-path $testsDir\*\*.csproj)){
|
2017-11-02 04:56:09 +03:00
|
|
|
$projectName = split-path $project -Leaf
|
|
|
|
Write-SubtaskName "Building $projectName"
|
2017-09-08 06:42:29 +03:00
|
|
|
exec {
|
2017-11-02 04:56:09 +03:00
|
|
|
& $dotnetExe build $project /property:Version=$semanticVersion /verbosity:minimal /fileLogger /flp:verbosity=detailed`;logfile=$outDir\$projectName.msbuild.log --no-restore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Task Unit.Tests -Depends Requires.DotNetExe, Build.UnitTests {
|
|
|
|
foreach ($project in (resolve-path $testsDir\*\*.csproj)){
|
|
|
|
$projectName = split-path $project -Leaf
|
|
|
|
Write-SubtaskName "Running unit tests from $projectName"
|
|
|
|
exec {
|
|
|
|
& $dotnetExe test $project --no-build
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 21:56:54 +03:00
|
|
|
Task Cover.Tests -Depends Requires.Opencover, Requires.ReportGenerator, Requires.OutDir, Build.SesTest {
|
|
|
|
$filter = "+[*]* -[xunit.*]* -[Fluent*]* -[*.Tests]*"
|
|
|
|
$logLevel = "info"
|
|
|
|
|
|
|
|
foreach ($project in (resolve-path $testsDir\*\*.csproj)){
|
|
|
|
$projectName = split-path $project -Leaf
|
|
|
|
Write-SubtaskName $projectName
|
|
|
|
|
|
|
|
exec {
|
|
|
|
& $openCoverExe -oldStyle "-target:$dotnetExe" "-targetargs:test $project" -register:user "-filter:$filter" -log:$loglevel -output:$outDir\$projectName.cover.xml
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-SubtaskName "Generating Coverage Report"
|
|
|
|
|
|
|
|
& $reportGeneratorExe "-reports:$outDir\*.cover.xml" "-targetdir:$outDir\cover\"
|
|
|
|
}
|
|
|
|
|
2018-04-13 08:18:41 +03:00
|
|
|
Task Publish.SesTest.Win64 -Depends Requires.DotNetExe, Restore.NuGetPackages, Generate.Version {
|
2017-09-08 06:42:29 +03:00
|
|
|
exec {
|
2017-09-13 04:33:22 +03:00
|
|
|
& $dotnetExe publish $srcDir\sestest\sestest.csproj --self-contained --output $publishDir\sestest\win10-x64 --runtime win10-x64 /p:Version=$semanticVersion
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
$archive = "$publishDir\sestest-$semanticVersion-win10-x64.zip"
|
2017-09-08 06:42:29 +03:00
|
|
|
exec {
|
2017-11-02 04:56:09 +03:00
|
|
|
compress-archive $publishDir\sestest\win10-x64\* $archive
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
2017-11-02 04:56:09 +03:00
|
|
|
|
|
|
|
Write-Output "Created archive $archive"
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 08:18:41 +03:00
|
|
|
Task Publish.SesTest.Linux64 -Depends Requires.DotNetExe, Restore.NuGetPackages, Generate.Version {
|
2017-09-08 06:42:29 +03:00
|
|
|
exec {
|
2017-09-13 04:33:22 +03:00
|
|
|
& $dotnetExe publish $srcDir\sestest\sestest.csproj --self-contained --output $publishDir\sestest\linux-x64 --runtime linux-x64 /p:Version=$semanticVersion
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
$archive = "$publishDir\sestest-$semanticVersion-linux-x64.zip"
|
2017-09-08 06:42:29 +03:00
|
|
|
exec {
|
2017-11-02 04:56:09 +03:00
|
|
|
compress-archive $publishDir\sestest\linux-x64\* $archive
|
2017-09-13 04:33:22 +03:00
|
|
|
}
|
2017-11-02 04:56:09 +03:00
|
|
|
|
|
|
|
Write-Output "Created archive $archive"
|
2017-09-13 04:33:22 +03:00
|
|
|
}
|
|
|
|
|
2018-04-27 07:39:33 +03:00
|
|
|
Task Publish.SesClient.x86 -Depends Build.SesLibrary.x86, Build.SesClient.x86 {
|
|
|
|
$clientDir = resolve-path $srcDir\sesclient.native\$configuration
|
|
|
|
$archive = "$publishDir\sesclient-$semanticVersion-x86.zip"
|
2018-05-02 05:01:17 +03:00
|
|
|
|
|
|
|
$redist = "$libDir\vc_redist\vc_redist.x86.exe"
|
|
|
|
if (test-path $redist) {
|
|
|
|
copy-item $redist -Destination $clientDir
|
|
|
|
} else {
|
|
|
|
Write-Output "Didn't find vc_redist.x86.exe to include in archive for distribution."
|
|
|
|
Write-Output "(Download vc_redist.x86.exe from https://www.microsoft.com/en-in/download/details.aspx?id=48145"
|
|
|
|
Write-Output " and copy it to $redist to have it included.)"
|
|
|
|
Write-Output ""
|
|
|
|
}
|
2018-04-27 07:39:33 +03:00
|
|
|
|
|
|
|
exec {
|
2018-05-02 05:01:17 +03:00
|
|
|
compress-archive $clientDir\*.exe, $clientDir\*.dll $archive
|
2018-04-27 07:39:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Write-Output "Created archive $archive"
|
|
|
|
}
|
|
|
|
|
|
|
|
Task Publish.SesClient.x64 -Depends Build.SesLibrary.x64, Build.SesClient.x64 {
|
|
|
|
$clientDir = resolve-path $srcDir\sesclient.native\x64\$configuration
|
|
|
|
$archive = "$publishDir\sesclient-$semanticVersion-x64.zip"
|
|
|
|
|
2018-05-02 05:01:17 +03:00
|
|
|
$redist = "$libDir\vc_redist\vc_redist.x64.exe"
|
|
|
|
if (test-path $redist) {
|
|
|
|
copy-item $redist -Destination $clientDir
|
|
|
|
} else {
|
|
|
|
Write-Output "Didn't find vc_redist.x64.exe to include in archive for distribution."
|
|
|
|
Write-Output "(Download vc_redist.x64.exe from https://www.microsoft.com/en-in/download/details.aspx?id=48145"
|
|
|
|
Write-Output " and copy it to $redist to have it included.)"
|
|
|
|
Write-Output ""
|
|
|
|
}
|
|
|
|
|
2017-09-13 04:33:22 +03:00
|
|
|
exec {
|
2018-05-02 05:01:17 +03:00
|
|
|
compress-archive $clientDir\*.exe, $clientDir\*.dll $archive
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
2017-11-02 04:56:09 +03:00
|
|
|
|
|
|
|
Write-Output "Created archive $archive"
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Configuration Targets
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Tasks used to configure the build
|
|
|
|
|
|
|
|
Task Request.Debug {
|
2018-04-13 08:18:41 +03:00
|
|
|
Write-Output "Debug build"
|
2017-09-08 06:42:29 +03:00
|
|
|
$script:configuration = "Debug"
|
|
|
|
}
|
|
|
|
|
|
|
|
Task Request.Release {
|
2018-04-13 08:18:41 +03:00
|
|
|
Write-Output "Release build"
|
2017-09-08 06:42:29 +03:00
|
|
|
$script:configuration = "Release"
|
|
|
|
}
|
|
|
|
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Prerequisite Targets
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Tasks used to ensure that prerequisites are available when needed.
|
|
|
|
|
|
|
|
Task Requires.Configuration {
|
|
|
|
if ($configuration -eq $null) {
|
|
|
|
$script:configuration = "Debug"
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "Build configuration is $configuration"
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Task Requires.DotNetExe {
|
|
|
|
$script:dotnetExe = (get-command dotnet).Path
|
|
|
|
|
2017-09-27 21:56:54 +03:00
|
|
|
if ($dotnetExe -eq $null) {
|
2017-09-08 06:42:29 +03:00
|
|
|
$script:dotnetExe = resolve-path $env:ProgramFiles\dotnet\dotnet.exe -ErrorAction SilentlyContinue
|
|
|
|
}
|
|
|
|
|
2017-09-27 21:56:54 +03:00
|
|
|
if ($dotnetExe -eq $null) {
|
2017-09-08 06:42:29 +03:00
|
|
|
throw "Failed to find dotnet.exe"
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "Dotnet executable: $dotnetExe"
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Task Requires.MsBuild {
|
|
|
|
# prefer MSBuild from VS2017 if its there
|
|
|
|
$script:msbuildExe = resolve-path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\*\MSBuild\*\Bin\MSBuild.exe" -ErrorAction SilentlyContinue
|
|
|
|
|
2017-09-27 21:56:54 +03:00
|
|
|
if ($msbuildExe -eq $null) {
|
2017-09-08 06:42:29 +03:00
|
|
|
$script:msbuildExe = (get-command msbuild).Path
|
|
|
|
}
|
|
|
|
|
2017-09-27 21:56:54 +03:00
|
|
|
if ($msbuildExe -eq $null) {
|
2017-09-08 06:42:29 +03:00
|
|
|
throw "Failed to find msbuild.exe"
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "MSBuild executable: $msbuildExe"
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|
|
|
|
|
2017-09-27 21:56:54 +03:00
|
|
|
Task Requires.OpenCover {
|
|
|
|
|
|
|
|
$script:openCoverExe = resolve-path $env:userprofile\.nuget\packages\OpenCover\*\tools\OpenCover.Console.exe -ErrorAction SilentlyContinue
|
|
|
|
|
|
|
|
if ($openCoverExe -eq $null) {
|
|
|
|
throw "Failed to find OpenCover.Console.exe"
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Output "Opencover executable: $openCoverExe"
|
|
|
|
}
|
|
|
|
|
|
|
|
Task Requires.OutDir {
|
|
|
|
if (!(test-path $outDir)) {
|
|
|
|
mkdir $outDir -ErrorAction SilentlyContinue | Out-Null
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(test-path $outDir)) {
|
|
|
|
throw "Output folder does not exist"
|
|
|
|
}
|
|
|
|
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "Output folder is $outDir"
|
2017-09-27 21:56:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Task Requires.ReportGenerator {
|
|
|
|
|
|
|
|
$script:reportGeneratorExe = resolve-path $env:userprofile\.nuget\packages\reportgenerator\*\tools\ReportGenerator.exe -ErrorAction SilentlyContinue |
|
|
|
|
Sort-Object -Property "Name" |
|
|
|
|
select-object -last 1
|
|
|
|
|
|
|
|
if ($reportGeneratorExe -eq $null) {
|
|
|
|
throw "Failed to find ReportGenerator.exe"
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Output "Report Generator executable: $reportGeneratorExe"
|
|
|
|
}
|
|
|
|
|
2017-09-08 06:42:29 +03:00
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
## Support Functions
|
|
|
|
## --------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
formatTaskName {
|
|
|
|
param($taskName)
|
|
|
|
|
|
|
|
$divider = "-" * ((get-host).UI.RawUI.WindowSize.Width - 2)
|
|
|
|
return "`r`n$divider`r`n $taskName`r`n$divider`r`n"
|
|
|
|
}
|
|
|
|
|
|
|
|
function Write-SubtaskName($subtaskName) {
|
|
|
|
$divider = "-" * ($subtaskName.Length + 4)
|
2017-11-02 04:56:09 +03:00
|
|
|
Write-Output "`r`n$divider`r`n $subtaskName`r`n$divider"
|
2017-09-08 06:42:29 +03:00
|
|
|
}
|