-
Notifications
You must be signed in to change notification settings - Fork 361
/
Copy pathSourceBuildArcadeBuild.targets
145 lines (121 loc) · 7.71 KB
/
SourceBuildArcadeBuild.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>
<!--
These targets inject source-build into Arcade's build process.
-->
<Import Project="SourceBuildArcade.targets" />
<PropertyGroup>
<CurrentRepoSourceBuildBinlogFile>$([MSBuild]::NormalizePath('$(CurrentRepoSourceBuildArtifactsLogsDir)', 'source-inner-build.binlog'))</CurrentRepoSourceBuildBinlogFile>
<InnerSourceBuildRepoRoot Condition="'$(InnerSourceBuildRepoRoot)' == ''">$(CurrentRepoSourceBuildSourceDir)</InnerSourceBuildRepoRoot>
<InnerSourceBuildRepoRoot Condition="'$(UseInnerClone)' != 'true'">$(RepoRoot)</InnerSourceBuildRepoRoot>
<CleanInnerSourceBuildRepoRoot Condition="'$(CleanInnerSourceBuildRepoRoot)' == ''">true</CleanInnerSourceBuildRepoRoot>
<FullAssemblySigningSupported Condition="'$(FullAssemblySigningSupported)' == ''">false</FullAssemblySigningSupported>
<_DirSeparatorEscapedCharForExecArg Condition="'$(OS)' == 'Windows_NT'">\</_DirSeparatorEscapedCharForExecArg>
<_DirSeparatorEscapedCharForExecArg Condition="'$(OS)' != 'Windows_NT'" />
</PropertyGroup>
<Target Name="ExecuteWithSourceBuiltTooling"
DependsOnTargets="
GetSourceBuildCommandConfiguration;
RunInnerSourceBuildCommand"
Condition="
('$(ArcadeBuildFromSource)' == 'true' and '$(ArcadeInnerBuildFromSource)' != 'true') or
'$(DotNetBuildPhase)' == 'Repo'"
BeforeTargets="Execute" />
<!--
Use BeforeTargets="ExecuteInnerSourceBuild" to trigger when the inner build is happening.
-->
<Target Name="ExecuteInnerSourceBuild" />
<!--
HookExecuteInnerSourceBuild triggers ExecuteInnerSourceBuild only if it's the right time. A
BeforeTargets on HookExecuteInnerSourceBuild would always execute because BeforeTargets runs
even if the condition isn't met, so we need this indirection.
-->
<Target Name="HookExecuteInnerSourceBuild"
Condition="
('$(ArcadeBuildFromSource)' == 'true' and '$(ArcadeInnerBuildFromSource)' == 'true') or
'$(DotNetBuildPhase)' == 'InnerRepo'"
DependsOnTargets="ExecuteInnerSourceBuild"
BeforeTargets="Execute"/>
<!--
Set up build args to append to the passed build command. These args specify what is unique about
building from source, such as non-overlapping artifacts dirs and package caches.
Use BeforeTargets="GetSourceBuildCommandConfiguration" or set props/items to customize.
-->
<Target Name="GetSourceBuildCommandConfiguration">
<PropertyGroup>
<!-- Based on the build mode, turn on the appropriate switches in the inner build:
ArcadeBuildFromSource
- ArcadeInnerBuildFromSource - Mark inner build, turn on key inner build infra.
- DotNetBuildFromSource - Build from source only.
DotNetBuildRepo
- DotNetBuildInnerRepo - Mark inner build, turn on key inner build infra.
- DotNetBuildSourceOnly - Build from source only. Pass through outer build value if present. -->
<InnerBuildArgs Condition="'$(DotNetBuildRepo)' == 'true'">$(InnerBuildArgs) /p:DotNetBuildInnerRepo=true</InnerBuildArgs>
<InnerBuildArgs Condition="'$(DotNetBuildSourceOnly)' != ''">$(InnerBuildArgs) /p:DotNetBuildSourceOnly=$(DotNetBuildSourceOnly)</InnerBuildArgs>
<InnerBuildArgs Condition="'$(ArcadeBuildFromSource)' == 'true'">$(InnerBuildArgs) /p:ArcadeInnerBuildFromSource=true /p:DotNetBuildFromSource=true</InnerBuildArgs>
<!-- Use a fresh clone of the repo so that source-build modifications are isolated. -->
<InnerBuildArgs>$(InnerBuildArgs) /p:RepoRoot="$(InnerSourceBuildRepoRoot)$(_DirSeparatorEscapedCharForExecArg)"</InnerBuildArgs>
<!-- Override the artifacts dir to cleanly separate the inner build from outer build. -->
<InnerBuildArgs>$(InnerBuildArgs) /p:ArtifactsDir="$(CurrentRepoSourceBuildArtifactsDir)$(_DirSeparatorEscapedCharForExecArg)"</InnerBuildArgs>
<!-- Set a custom binlog location to avoid clashing over the currenly specified file. -->
<InnerBuildArgs>$(InnerBuildArgs) /bl:"$(CurrentRepoSourceBuildBinlogFile)"</InnerBuildArgs>
<!-- Flow ContinuousIntegrationBuild to the inner build. -->
<InnerBuildArgs Condition="'$(ContinuousIntegrationBuild)' == 'true'">$(InnerBuildArgs) /p:ContinuousIntegrationBuild=true</InnerBuildArgs>
<!-- The inner build needs to reference the overall output dir for nupkg transport etc. -->
<InnerBuildArgs>$(InnerBuildArgs) /p:SourceBuildOutputDir="$(SourceBuildOutputDir)$(_DirSeparatorEscapedCharForExecArg)"</InnerBuildArgs>
<InnerBuildArgs Condition="'$(DotNetPackageVersionPropsPath)' != ''">$(InnerBuildArgs) /p:DotNetPackageVersionPropsPath="$(DotNetPackageVersionPropsPath)"</InnerBuildArgs>
<InnerBuildArgs>$(InnerBuildArgs) /p:FullAssemblySigningSupported=$(FullAssemblySigningSupported)</InnerBuildArgs>
<!-- We need to utilize publishing to copy packages, assets and manifest to shared source-build location. -->
<InnerBuildArgs>$(InnerBuildArgs) /p:DotNetPublishUsingPipelines=true</InnerBuildArgs>
</PropertyGroup>
<ItemGroup>
<!-- Override package cache to separate source-built packages from upstream. -->
<InnerBuildEnv Include="NUGET_PACKAGES=$(CurrentRepoSourceBuildPackageCache)" />
<InnerBuildEnv Include="DotNetTargetFrameworkFilter=$(SourceBuildTargetFrameworkFilter)" Condition="'$(ArcadeBuildFromSource)' == 'true' or '$(DotNetBuildSourceOnly)' == 'true'" />
</ItemGroup>
</Target>
<!--
PrepareInnerSourceBuildRepoRoot copies the source to the inner repo. Source-build
targets will change the source dynamically. Creating a fresh copy avoids overwriting
existing work or making subtle changes that might accidentally get added to the user's
existing work via a 'git add .'. Repos take a dependency on PrepareInnerSourceBuildRepoRoot.
-->
<Target Name="PrepareInnerSourceBuildRepoRoot" Condition="'$(UseInnerClone)' == 'true'">
<ItemGroup>
<SourceBuildFilesToCopy Include="$(RepoRoot)/**/*" />
<SourceBuildFilesToCopy Include="$(RepoRoot)/**/.*" />
<SourceBuildFilesToCopy Remove="$(RepoRoot)/artifacts/**/*" />
<SourceBuildFilesToCopy Remove="$(RepoRoot)/artifacts/**/.*" />
</ItemGroup>
<Copy
SourceFiles="@(SourceBuildFilesToCopy)"
DestinationFolder="$(InnerSourceBuildRepoRoot)%(RecursiveDir)" />
</Target>
<Target Name="RunInnerSourceBuildCommand"
DependsOnTargets="PrepareInnerSourceBuildRepoRoot">
<PropertyGroup>
<!-- Prevent any projects from building in the outside build: they would use prebuilts. -->
<PreventPrebuiltBuild>true</PreventPrebuiltBuild>
<!--
Normally, the inner build should run using the original build command with some extra args
appended. Allow the repo to override this default behavior if the repo is e.g. not onboarded
enough on Arcade for this to work nicely.
-->
<BaseInnerSourceBuildCommand Condition="'$(BaseInnerSourceBuildCommand)' == ''">$(ARCADE_BUILD_TOOL_COMMAND)</BaseInnerSourceBuildCommand>
</PropertyGroup>
<Exec
Command="$(BaseInnerSourceBuildCommand) $(InnerBuildArgs)"
WorkingDirectory="$(InnerSourceBuildRepoRoot)"
IgnoreStandardErrorWarningFormat="true"
EnvironmentVariables="@(InnerBuildEnv)" />
</Target>
<Target Name="PreventPrebuiltBuild"
DependsOnTargets="ExecuteWithSourceBuiltTooling"
Condition="'$(PreventPrebuiltBuild)' == 'true'"
BeforeTargets="Execute">
<ItemGroup>
<ProjectToBuild Remove="@(ProjectToBuild)" />
<ProjectToBuild Include="$(MSBuildThisFileDirectory)Noop.proj" />
</ItemGroup>
</Target>
</Project>