Skip to content

Commit

Permalink
Add the Arcade-powered source-build wrapper. (NuGet#4105)
Browse files Browse the repository at this point in the history
  • Loading branch information
crummel authored Jun 23, 2021
1 parent b83566e commit 55e6392
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 3 deletions.
10 changes: 10 additions & 0 deletions eng/SourceBuild.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>

<PropertyGroup>
<GitHubRepositoryName>nuget-client</GitHubRepositoryName>
<SourceBuildManagedOnly>true</SourceBuildManagedOnly>

<VersionPrefix>1.0.0</VersionPrefix>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions eng/SourceBuildPrebuiltBaseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<UsageData>
<IgnorePatterns>
<UsagePattern IdentityGlob="*/*" />
</IgnorePatterns>
</UsageData>
27 changes: 27 additions & 0 deletions eng/pipelines/templates/Source_Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
steps:
- task: PowerShell@2
displayName: "Update Build Number"
inputs:
targetType: "inline"
script: |
Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER"
failOnStderr: "true"
condition: "always()"

- task: PowerShell@2
displayName: "Build source-build"
inputs:
targetType: "inline"
script: |
./eng/source-build/build.sh
condition: "always()"

- task: PublishBuildArtifacts@1
displayName: Upload source-build log
condition: "always()"
continueOnError: true
inputs:
PathToPublish: "artifacts/source-build/self/log/source-build.binlog"
ArtifactName: "Source-build log"
ArtifactType: Container

15 changes: 15 additions & 0 deletions eng/pipelines/templates/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,18 @@ jobs:

steps:
- template: Apex_Tests_On_Windows.yml

- job: Source_Build
dependsOn:
- Initialize_Build
timeoutInMinutes: 120
variables:
BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']]
FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']]
SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']]
BuildRTM: "false"
pool:
vmImage: ubuntu-latest
demands: sh
steps:
- template: Source_Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
From 4743459f7b61cb6a43e23573687e91232afcf06a Mon Sep 17 00:00:00 2001
From: Chris Rummel <[email protected]>
Date: Mon, 21 Jun 2021 15:11:21 -0500
Subject: [PATCH] Rename NuGet.Config to NuGet.config to account for an Arcade
issue.

---
NuGet.Config => NuGet.config | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename NuGet.Config => NuGet.config (100%)

diff --git a/NuGet.Config b/NuGet.config
similarity index 100%
rename from NuGet.Config
rename to NuGet.config
--
2.18.0

47 changes: 47 additions & 0 deletions eng/source-build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

source="${BASH_SOURCE[0]}"
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"

# resolve $SOURCE until the file is no longer a symlink
while [[ -h $source ]]; do
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
source="$(readlink "$source")"

# if $source was a relative symlink, we need to resolve it relative to the path where the
# symlink file was located
[[ $source != /* ]] && source="$scriptroot/$source"
done

function ReadGlobalVersion {
local key=$1
local global_json_file="$scriptroot/global.json"

if command -v jq &> /dev/null; then
_ReadGlobalVersion="$(jq -r ".[] | select(has(\"$key\")) | .\"$key\"" "$global_json_file")"
elif [[ "$(cat "$global_json_file")" =~ \"$key\"[[:space:]\:]*\"([^\"]+) ]]; then
_ReadGlobalVersion=${BASH_REMATCH[1]}
fi

if [[ -z "$_ReadGlobalVersion" ]]; then
Write-PipelineTelemetryError -category 'Build' "Error: Cannot find \"$key\" in $global_json_file"
ExitWithExitCode 1
fi
}

function GetNuGetPackageCachePath {
if [[ -z ${NUGET_PACKAGES:-} ]]; then
if [[ "$use_global_nuget_cache" == true ]]; then
export NUGET_PACKAGES="$HOME/.nuget/packages"
else
export NUGET_PACKAGES="$repo_root/.packages"
export RESTORENOCACHE=true
fi
fi
}

export DOTNET=${DOTNET:-dotnet}

ReadGlobalVersion Microsoft.DotNet.Arcade.Sdk
export ARCADE_VERSION=$_ReadGlobalVersion
"$DOTNET" msbuild "$scriptroot/source-build.proj" /p:DotNetBuildFromSource=true /p:ArcadeBuildFromSource=true "/p:RepoRoot=$scriptroot/../../" "/bl:$scriptroot/../../artifacts/source-build/self/log/source-build.binlog"
5 changes: 5 additions & 0 deletions eng/source-build/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.21309.7"
}
}
65 changes: 65 additions & 0 deletions eng/source-build/source-build.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<Project Sdk="Microsoft.DotNet.Arcade.Sdk" DefaultTargets="Build">

<Import Project="../SourceBuild.props" />

<PropertyGroup>
<ProjectRoot>$(MSBuildThisFileDirectory)../../</ProjectRoot>
</PropertyGroup>

<Target Name="Build" DependsOnTargets="SourceBuildPostBuild">
<Message Text="Running source-build Build target" Importance="High" />
</Target>

<Target Name="SourceBuildPreBuild" DependsOnTargets="ApplySourceBuildPatchFiles">
<Message Text="Running source-build PreBuild target" Importance="High" />

</Target>

<Target Name="SourceBuildPostBuild" DependsOnTargets="SourceBuildInnerBuild">
<Message Text="Running source-build PostBuild target" Importance="High" />

<MSbuild Projects="$(NuGetPackageRoot)/microsoft.dotnet.arcade.sdk/$(ARCADE_VERSION)/tools/Build.proj"
Properties="_NETCORE_ENGINEERING_TELEMETRY=AfterSourceBuild;ArcadeBuildFromSource=true;Restore=true;Build=false;Pack=false;Publish=false;Rebuild=false;Test=false;IntegrationTest=false;PerformanceTest=false;PreventPrebuiltBuild=false;BaseInnerSourceBuildCommand=echo skipping internal build with args: "
Targets="Execute"
/>

<Message Text="Finished restoring Arcade" Importance="High" />

<MSbuild Projects="$(NuGetPackageRoot)/microsoft.dotnet.arcade.sdk/$(ARCADE_VERSION)/tools/SourceBuild/AfterSourceBuild.proj"
Properties="_NETCORE_ENGINEERING_TELEMETRY=AfterSourceBuild;ArcadeBuildFromSource=true;CurrentRepoSourceBuildArtifactsPackagesDir=$(ProjectRoot)artifacts/nupkgs/"
/>

</Target>

<Target Name="SourceBuildInnerBuild" DependsOnTargets="SourceBuildPreBuild">
<Message Text="Running source-build InnerBuild target" Importance="High" />

<MSBuild Projects="$(ProjectRoot)build/build.proj"
Properties="Configuration=$(BuildConfiguration);DotNetBuildFromSource=true"
Targets="RestoreXPlat" />

<MSBuild Projects="$(ProjectRoot)build/build.proj"
Properties="Configuration=$(BuildConfiguration);DotNetBuildFromSource=true"
Targets="BuildXPlat" />

<MSBuild Projects="$(ProjectRoot)build/build.proj"
Properties="Configuration=$(BuildConfiguration);DotNetBuildFromSource=true"
Targets="PackXPlat" />

</Target>

<Target Name="ApplySourceBuildPatchFiles">
<Message Text="Check for patches in $(ProjectRoot)eng/source-build-patches/*.patch" Importance="High" />
<ItemGroup>
<SourceBuildPatchFile Include="$(ProjectRoot)eng/source-build-patches/*.patch" />
</ItemGroup>

<Exec
Command="git apply --ignore-whitespace --whitespace=nowarn &quot;%(SourceBuildPatchFile.FullPath)&quot;"
WorkingDirectory="$(ProjectRoot)"
Condition="'@(SourceBuildPatchFile)' != ''" />
</Target>


</Project>

9 changes: 9 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// This empty file has no effect and is here to support Arcade-powered source-build.
// The Arcade build process requires a global.json at the root of the repo and normally
// uses it to restore the necessary SDK and tools to build the repo.
// However, NuGet explitcly wants to use the ambient SDK (normally latest), not any particular
// version. We also don't want to introduce MS.DN.Arcade.SDK into the non-source-build build.
// eng/source-build/global.json has the entry for the Arcade version we need for
// Arcade-powered source-build.
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ using Microsoft.VisualStudio.Shell;

<Import Project="$(BuildCommonDirectory)common.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != '' and '$(DotNetBuildFromSource)' != 'true'" />
</Project>
2 changes: 1 addition & 1 deletion src/NuGet.Clients/NuGet.Tools/NuGet.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,5 @@ using Microsoft.VisualStudio.Shell;

<Import Project="$(BuildCommonDirectory)common.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != '' and '$(DotNetBuildFromSource)' != 'true'" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@
</ItemGroup>
<Import Project="$(BuildCommonDirectory)common.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != '' and '$(DotNetBuildFromSource)' != 'true'" />
</Project>

0 comments on commit 55e6392

Please sign in to comment.