Skip to content

Commit

Permalink
Merge pull request #484 from dotnet/buildOnLinux
Browse files Browse the repository at this point in the history
Get NB.GV building on Linux
  • Loading branch information
AArnott committed May 24, 2020
2 parents d4fcc3a + 1fb4e07 commit 57a4826
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 15 deletions.
16 changes: 16 additions & 0 deletions Directory.Build.rsp
@@ -0,0 +1,16 @@
#------------------------------------------------------------------------------
# This file contains command-line options that MSBuild will process as part of
# every build, unless the "/noautoresponse" switch is specified.
#
# MSBuild processes the options in this file first, before processing the
# options on the command line. As a result, options on the command line can
# override the options in this file. However, depending on the options being
# set, the overriding can also result in conflicts.
#
# NOTE: The "/noautoresponse" switch cannot be specified in this file, nor in
# any response file that is referenced by this file.
#------------------------------------------------------------------------------
/nr:false
/m
/verbosity:minimal
/clp:Summary;ForceNoAlign
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Expand Up @@ -37,7 +37,7 @@ stages:
steps:
- checkout: self
clean: true
submodules: false
submodules: true # keep the warnings quiet about the wiki not being enlisted
- script: |
git config --global user.name ci
git config --global user.email me@ci.com
Expand Down
79 changes: 79 additions & 0 deletions azure-pipelines/Set-EnvVars.ps1
@@ -0,0 +1,79 @@
<#
.SYNOPSIS
Set environment variables in the environment.
Azure Pipeline and CMD environments are considered.
.PARAMETER Variables
A hashtable of variables to be set.
.OUTPUTS
A boolean indicating whether the environment variables can be expected to propagate to the caller's environment.
#>
[CmdletBinding(SupportsShouldProcess=$true)]
Param(
[Parameter(Mandatory=$true, Position=1)]
$Variables,
[string[]]$PrependPath
)

if ($Variables.Count -eq 0) {
return $true
}

$cmdInstructions = !$env:TF_BUILD -and !$env:GITHUB_ACTIONS -and $env:PS1UnderCmd -eq '1'
if ($cmdInstructions) {
Write-Warning "Environment variables have been set that will be lost because you're running under cmd.exe"
Write-Host "Environment variables that must be set manually:" -ForegroundColor Blue
} else {
Write-Host "Environment variables set:" -ForegroundColor Blue
Write-Host ($Variables | Out-String)
if ($PrependPath) {
Write-Host "Paths prepended to PATH: $PrependPath"
}
}

if ($env:TF_BUILD) {
Write-Host "Azure Pipelines detected. Logging commands will be used to propagate environment variables and prepend path."
}

if ($env:GITHUB_ACTIONS) {
Write-Host "GitHub Actions detected. Logging commands will be used to propagate environment variables and prepend path."
}

$Variables.GetEnumerator() |% {
Set-Item -Path env:$($_.Key) -Value $_.Value

# If we're running in a cloud CI, set these environment variables so they propagate.
if ($env:TF_BUILD) {
Write-Host "##vso[task.setvariable variable=$($_.Key);]$($_.Value)"
}
if ($env:GITHUB_ACTIONS) {
Write-Host "::set-env name=$($_.Key)::$($_.Value)"
}

if ($cmdInstructions) {
Write-Host "SET $($_.Key)=$($_.Value)"
}
}

$pathDelimiter = ';'
if ($IsMacOS -or $IsLinux) {
$pathDelimiter = ':'
}

if ($PrependPath) {
$PrependPath |% {
$newPathValue = "$_$pathDelimiter$env:PATH"
Set-Item -Path env:PATH -Value $newPathValue
if ($cmdInstructions) {
Write-Host "SET PATH=$newPathValue"
}

if ($env:TF_BUILD) {
Write-Host "##vso[task.prependpath]$_"
}
if ($env:GITHUB_ACTIONS) {
Write-Host "::add-path::$_"
}
}
}

return !$cmdInstructions
2 changes: 2 additions & 0 deletions azure-pipelines/variables/DotNetSdkVersion.ps1
@@ -0,0 +1,2 @@
$globalJson = Get-Content -Path "$PSScriptRoot\..\..\global.json" | ConvertFrom-Json
$globalJson.sdk.version
5 changes: 4 additions & 1 deletion init.cmd
@@ -1 +1,4 @@
powershell.exe -ExecutionPolicy bypass -NoProfile -Command "& '%~dpn0.ps1'" %*
@echo off
SETLOCAL
set PS1UnderCmd=1
powershell.exe -NoProfile -NoLogo -ExecutionPolicy bypass -Command "try { & '%~dpn0.ps1' %*; exit $LASTEXITCODE } catch { write-host $_; exit 1 }"
46 changes: 41 additions & 5 deletions init.ps1 100644 → 100755
@@ -1,17 +1,53 @@
#!/usr/bin/env pwsh

<#
.SYNOPSIS
Restores all NuGet, NPM and Typings packages necessary to build this repository.
Installs dependencies required to build and test the projects in this repository.
.DESCRIPTION
This MAY not require elevation, as the SDK and runtimes are installed to a per-user location,
unless the `-InstallLocality` switch is specified directing to a per-repo or per-machine location.
See detailed help on that switch for more information.
.PARAMETER InstallLocality
A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used.
Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`.
Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it.
.PARAMETER NoPrerequisites
Skips the installation of prerequisite software (e.g. SDKs, tools).
.PARAMETER NoRestore
Skips the package restore step.
#>
[CmdletBinding(SupportsShouldProcess)]
[CmdletBinding(SupportsShouldProcess=$true)]
Param(
[ValidateSet('repo','user','machine')]
[string]$InstallLocality='user',
[Parameter()]
[switch]$NoPrerequisites,
[Parameter()]
[switch]$NoRestore
)

if (!$NoPrerequisites) {
& "$PSScriptRoot\tools\Install-DotNetSdk.ps1" -InstallLocality $InstallLocality
}

$oldPlatform=$env:Platform
$env:Platform='Any CPU' # Some people wander in here from a platform-specific build window.

Push-Location $PSScriptRoot
try {
msbuild "$PSScriptRoot\src" /t:restore /v:minimal /m /nologo
$HeaderColor = 'Green'

if (!$NoRestore -and $PSCmdlet.ShouldProcess("NuGet packages", "Restore")) {
Write-Host "Restoring NuGet packages" -ForegroundColor $HeaderColor
dotnet restore "$PSScriptRoot\src"
if ($lastexitcode -ne 0) {
throw "Failure while restoring packages."
}
}

Write-Host "Restoring NPM packages..." -ForegroundColor Yellow
Push-Location "$PSScriptRoot\src\nerdbank-gitversioning.npm"
Expand All @@ -25,8 +61,8 @@ try {

Write-Host "Successfully restored all dependencies" -ForegroundColor Yellow
} catch {
# we have the try so that PS fails when we get failure exit codes from build steps.
throw;
Write-Error $error[0]
exit $lastexitcode
} finally {
$env:Platform=$oldPlatform
Pop-Location
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.GitVersioning/Cake.GitVersioning.csproj
Expand Up @@ -32,7 +32,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" PrivateAssets="all" />
<PackageReference Include="DotNetMDDocs" Version="0.111.0" Condition=" '$(GenerateMarkdownApiDocs)' == 'true' " />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="1.6.20-beta-gfea83a8c9e" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.1.93" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -71,4 +71,4 @@
</TfmSpecificPackageFile>
</ItemGroup>
</Target>
</Project>
</Project>
1 change: 1 addition & 0 deletions src/Directory.Build.props
Expand Up @@ -24,6 +24,7 @@
<LibGit2SharpNativeVersion>2.0.306</LibGit2SharpNativeVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
</ItemGroup>

Expand Down
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="Xunit.Combinatorial" Version="1.2.7" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="1.6.20-beta-gfea83a8c9e" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.1.93" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="System.Diagnostics.Tools" Version="4.3.0" Condition=" '$(TargetFramework)' == 'netcoreapp2.0' " />
<PackageReference Include="Validation" Version="2.4.18" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="1.6.20-beta-gfea83a8c9e" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.1.93" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\**\*.cs" LinkBase="Shared" />
Expand Down
Expand Up @@ -76,7 +76,7 @@
</ItemDefinitionGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="1.6.20-beta-gfea83a8c9e" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.1.93" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NerdBank.GitVersioning\NerdBank.GitVersioning.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/nbgv/nbgv.csproj
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="NuGet.PackageManagement" Version="4.9.3" NoWarn="NU1701" />
<PackageReference Include="NuGet.Resolver" Version="4.9.3" />
<PackageReference Include="System.CommandLine" Version="0.1.0-preview2-180503-2" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="1.6.20-beta-gfea83a8c9e" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.1.93" PrivateAssets="all" />
<PackageReference Include="System.Diagnostics.Tools" Version="4.3.0" />
<PackageReference Include="Microsoft.Build" Version="15.9.20" />
</ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/nuget.config
Expand Up @@ -6,7 +6,6 @@
<packageSources>
<clear />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="myget.org/F/aarnott" value="https://www.myget.org/F/aarnott/api/v3/index.json" protocolVersion="3" />
<add key="dotnet-corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" protocolVersion="3" />
<add key="Consumption" value="https://pkgs.dev.azure.com/andrewarnott/OSS/_packaging/Consumption/nuget/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>

0 comments on commit 57a4826

Please sign in to comment.