Skip to content

Commit 6f8d9ba

Browse files
author
John Luo
committed
Add support for source-build
1 parent 3b4ca06 commit 6f8d9ba

File tree

12 files changed

+207
-77
lines changed

12 files changed

+207
-77
lines changed

.azure/pipelines/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,50 @@ jobs:
471471
- name: Linux_Test_Results
472472
path: artifacts/TestResults/
473473
publishOnError: true
474+
475+
# Source build
476+
- job: Source_Build
477+
displayName: 'Test: Linux Source Build'
478+
container: centos:7
479+
pool:
480+
vmImage: 'ubuntu-16.04'
481+
variables:
482+
DotNetCoreSdkDir: $(Agent.ToolsDirectory)/dotnet
483+
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: true
484+
steps:
485+
- script: |
486+
source eng/common/native/common-library.sh
487+
mkdir -p $HOME/bin
488+
GetFile https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 $HOME/bin/jq
489+
chmod +x $HOME/bin/jq
490+
echo "##vso[task.prependpath]$HOME/bin"
491+
displayName: Install jq
492+
- task: UseDotNet@2
493+
displayName: 'Use .NET Core sdk'
494+
inputs:
495+
packageType: sdk
496+
# The SDK version selected here is intentionally supposed to use the latest release
497+
# For the purpose of building Linux distros, we can't depend on features of the SDK
498+
# which may not exist in pre-built versions of the SDK
499+
version: 3.0.x
500+
installationPath: $(DotNetCoreSdkDir)
501+
includePreviewVersions: true
502+
- script: ./eng/scripts/ci-source-build.sh --ci --configuration Release /p:BuildManaged=true
503+
displayName: Run ci-source-build.sh
504+
- task: PublishBuildArtifacts@1
505+
displayName: Upload logs
506+
condition: always()
507+
continueOnError: true
508+
inputs:
509+
pathtoPublish: artifacts/log/
510+
artifactName: Source_Build_Logs
511+
artifactType: Container
512+
parallel: true
513+
- task: PublishBuildArtifacts@1
514+
displayName: Upload package artifacts
515+
condition: always()
516+
inputs:
517+
pathtoPublish: artifacts/packages/
518+
artifactName: Source_Build_Packages
519+
artifactType: Container
520+
parallel: true

Directory.Build.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
By default, assemblies which are only in the Microsoft.AspNetCore.App shared framework are not available as NuGet packages.
1515
-->
1616
<IsPackable Condition="'$(IsAspNetCoreApp)' == 'true' AND '$(IsShippingPackage)' != 'true'">false</IsPackable>
17+
18+
<!-- Only build assemblies in Microsoft.AspNetCore.App in source build -->
19+
<ExcludeFromSourceBuild Condition="'$(ExcludeFromSourceBuild)' == '' and '$(DotNetBuildFromSource)' == 'true' and '$(IsAspNetCoreApp)' != 'true'">true</ExcludeFromSourceBuild>
1720
</PropertyGroup>
1821

1922
<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />

eng/Build.props

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
Use caution to avoid deep recursion. If the globbing pattern picks up something which exceeds MAX_PATH,
122122
the entire pattern will silently fail to evaluate correctly.
123123
-->
124+
125+
<!-- Tool projects except FirstRunCertGenerator are not neede in source build -->
126+
<ProjectToExclude Condition="'$(DotNetBuildFromSource)' == 'true'"
127+
Include="$(RepoRoot)src\Tools\**\*.*proj"
128+
Exclude="$(RepoRoot)src\Tools\FirstRunCertGenerator\Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj"/>
129+
124130
<DotNetProjects Include="
125131
$(RepoRoot)src\Framework\ref\Microsoft.AspNetCore.App.Ref.csproj;
126132
$(RepoRoot)src\Framework\src\Microsoft.AspNetCore.App.Runtime.csproj;
@@ -148,8 +154,8 @@
148154
$(RepoRoot)src\Analyzers\**\*.csproj;
149155
$(RepoRoot)src\ProjectTemplates\*\*.csproj;
150156
$(RepoRoot)src\ProjectTemplates\testassets\*\*.csproj;
151-
"
152-
Exclude="
157+
" />
158+
<DotNetProjects Remove="
153159
@(ProjectToBuild);
154160
@(ProjectToExclude);
155161
$(RepoRoot)**\node_modules\**\*;

eng/Dependencies.props

Lines changed: 76 additions & 67 deletions
Large diffs are not rendered by default.

eng/Workarounds.targets

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121
</ItemGroup>
2222

2323
<!-- Workaround https://github.com/aspnet/AspNetCore/issues/7503. This chains GenerateSourceLinkFile before razor component targets run. -->
24-
<Target Name="_EnsureSourceLinkHappensBeforeRazorComponentGeneration"
24+
<!-- Workaround https://github.com/dotnet/source-build/issues/1112. Source link is currently disabled in source build so do not apply this worksaround. -->
25+
<Target Condition="'$(DotNetBuildFromSource)' != 'true'"
26+
Name="_EnsureSourceLinkHappensBeforeRazorComponentGeneration"
2527
BeforeTargets="PrepareForRazorComponentGenerate"
2628
DependsOnTargets="GenerateSourceLinkFile" />
2729

30+
<!-- Workaround https://github.com/dotnet/source-build/issues/1112. Source link is currently disabled in source build so define this dummy target which is required for pack. -->
31+
<Import Condition="'$(DotNetBuildFromSource)' == 'true'" Project="WorkaroundsImported.targets" />
32+
2833
<!-- Workaround https://github.com/aspnet/websdk/pull/646. If merged, once we update to a websdk with this fix, we can move the setting below to Directory.Build.props. -->
2934
<PropertyGroup>
3035
<!-- Ignore warning about calling the Pack target on Web SDK projects. Our build scripts call /t:pack on everything in this repo. -->

eng/WorkaroundsImported.targets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- Use this file to workaround issues. List the issue tracking the item to fix so we can remove the workaround when the issue is resolved. -->
2+
<Project>
3+
<!-- Workaround https://github.com/dotnet/source-build/issues/1112. Source link is currently disabled in source build so define this dummy target which is required for pack. -->
4+
<Target Name="InitializeSourceControlInformation"/>
5+
</Project>

eng/scripts/ci-source-build.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# This script is meant for testing source build by imitating some of the input parameters and conditions.
5+
#
6+
7+
set -euo pipefail
8+
9+
scriptroot="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
10+
reporoot="$(dirname "$(dirname "$scriptroot")")"
11+
12+
# For local development, make a backup copy of this file first
13+
if [ ! -f "$reporoot/global.bak.json" ]; then
14+
mv "$reporoot/global.json" "$reporoot/global.bak.json"
15+
fi
16+
17+
# Detect the current version of .NET Core installed
18+
export SDK_VERSION=$(dotnet --version)
19+
echo "The ambient version of .NET Core SDK version = $SDK_VERSION"
20+
21+
# Update the global.json file to match the current .NET environment
22+
cat "$reporoot/global.bak.json" | \
23+
jq '.sdk.version=env.SDK_VERSION' | \
24+
jq '.tools.dotnet=env.SDK_VERSION' | \
25+
jq 'del(.tools.runtimes)' \
26+
> "$reporoot/global.json"
27+
28+
# Restore the original global.json file
29+
trap "{
30+
mv "$reporoot/global.bak.json" "$reporoot/global.json"
31+
}" EXIT
32+
33+
export DotNetBuildFromSource='true'
34+
35+
# Build repo tasks
36+
"$reporoot/eng/common/build.sh" --restore --build --ci --configuration Release /p:ProjectToBuild=$reporoot/eng/tools/RepoTasks/RepoTasks.csproj
37+
38+
# Build projects
39+
"$reporoot/eng/common/build.sh" --restore --build --pack "$@"

eng/targets/CSharp.Common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<!-- Required to exist in the NuGet package cache to enable code-signing. -->
1212
<PackageReference Include="MicroBuild.Core" Version="0.3.0" PrivateAssets="All" AllowExplicitReference="true" ExcludeAssets="All" />
1313

14-
<PackageReference Include="Microsoft.DotNet.GenAPI" PrivateAssets="All" Version="$(MicrosoftDotNetGenApiPackageVersion)" IsImplicitlyDefined="true" />
14+
<PackageReference Condition="'$(DotNetBuildFromSource)' != 'true'" Include="Microsoft.DotNet.GenAPI" PrivateAssets="All" Version="$(MicrosoftDotNetGenApiPackageVersion)" IsImplicitlyDefined="true" />
1515
</ItemGroup>
1616

1717
<ItemGroup Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true' OR '$(RazorSdkCurrentVersionProps)' != ''">

eng/targets/ResolveReferences.targets

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<Project>
2020

2121
<PropertyGroup>
22+
<EnableCustomReferenceResolution Condition="'$(EnableCustomReferenceResolution)' == '' AND ('$(DotNetBuildFromSource)' != 'true' OR '$(ExcludeFromSourceBuild)' != 'true')">true</EnableCustomReferenceResolution>
23+
2224
<ResolveReferencesDependsOn>
2325
ResolveCustomReferences;
2426
$(ResolveReferencesDependsOn);
@@ -60,7 +62,7 @@
6062
</Reference>
6163
</ItemDefinitionGroup>
6264

63-
<ItemGroup>
65+
<ItemGroup Condition="'$(EnableCustomReferenceResolution)' == 'true'">
6466
<Reference Update="@(Reference)">
6567
<IsSharedSource Condition="'%(IsSharedSource)' == '' AND $([System.String]::new('%(Identity)').EndsWith('.Sources'))">true</IsSharedSource>
6668
</Reference>
@@ -129,7 +131,7 @@
129131
This target resolves remaining Referene items to Packages, if possible. If not, they are left as Reference items fo the SDK to resolve.
130132
This executes on NuGet restore and during DesignTimeBuild. It should not run in the outer, cross-targeting build.
131133
-->
132-
<Target Name="ResolveCustomReferences" BeforeTargets="CollectPackageReferences;ResolveAssemblyReferencesDesignTime;ResolveAssemblyReferences" Condition=" '$(TargetFramework)' != '' ">
134+
<Target Name="ResolveCustomReferences" BeforeTargets="CollectPackageReferences;ResolveAssemblyReferencesDesignTime;ResolveAssemblyReferences" Condition=" '$(TargetFramework)' != '' AND '$(EnableCustomReferenceResolution)' == 'true' ">
133135
<ItemGroup>
134136
<!-- Ensure only content asset are consumed from .Sources packages -->
135137
<Reference>

eng/tools/RepoTasks/RepoTasks.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<Optimize>false</Optimize>
88
<DebugType>embedded</DebugType>
99
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
10+
<!-- Need to build this project in source build -->
11+
<ExcludeFromSourceBuild>false</ExcludeFromSourceBuild>
1012
</PropertyGroup>
1113

1214
<ItemGroup>

0 commit comments

Comments
 (0)