forked from dotnet/source-build-externals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectory.Build.targets
242 lines (203 loc) · 11.5 KB
/
Directory.Build.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<Project InitialTargets="SetNuGetPackagesEnvironment">
<PropertyGroup>
<NuGetConfigFile Condition="'$(NuGetConfigFile)' == '' and Exists('$(ProjectDirectory)NuGet.config')">$(ProjectDirectory)NuGet.config</NuGetConfigFile>
<NuGetConfigFile Condition="'$(NuGetConfigFile)' == '' and Exists('$(ProjectDirectory)NuGet.Config')">$(ProjectDirectory)NuGet.Config</NuGetConfigFile>
<NuGetConfigFile Condition="'$(NuGetConfigFile)' == '' and Exists('$(ProjectDirectory)src\NuGet.config')">$(ProjectDirectory)src\NuGet.config</NuGetConfigFile>
<NuGetConfigFile Condition="'$(NuGetConfigFile)' == '' and Exists('$(ProjectDirectory)src\NuGet.Config')">$(ProjectDirectory)src\NuGet.Config</NuGetConfigFile>
</PropertyGroup>
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.SourceBuild.AddSourceToNuGetConfig" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" />
<UsingTask TaskName="UpdateJson" AssemblyFile="$(XPlatSourceBuildTasksAssembly)" />
<Target Name="BuildRepoReferences" Condition="'@(RepositoryReference)' != '' and '$(SkipRepoReferences)' != 'true'">
<Message Importance="High" Text="Building dependencies [@(RepositoryReference)] needed by '$(RepositoryName)'." />
<ItemGroup>
<_DependentProject Include="@(RepositoryReference -> '%(Identity).proj')" />
</ItemGroup>
<MSBuild Projects="@(_DependentProject)" Targets="Build" BuildInParallel="$(BuildInParallel)" StopOnFirstFailure="true" />
</Target>
<ItemGroup Condition="Exists('$(PatchesDir)$(RepositoryName)')" >
<PatchesToApply Include="$(PatchesDir)$(RepositoryName)/*.patch" />
</ItemGroup>
<Target Name="ApplyPatches"
Condition="'@(PatchesToApply)' != '' and '$(SkipPatches)' != 'true'"
Inputs="@(PatchesToApply)"
Outputs="$(RepoCompletedSemaphorePath)ApplyPatches.complete" >
<PropertyGroup>
<PatchCommand>git --work-tree=$(ProjectDirectory) apply --ignore-whitespace --whitespace=nowarn</PatchCommand>
</PropertyGroup>
<!-- in the installer tarball, we want to remove the objects directory from the .gitdir to save space.
This causes a problem specifically in the combination of submodules which have redirected .gitdirs
when we are applying patches in the current directory (which is required due to the way Git
interprets the paths in a patch). GIT_DIR=/dev/null short-circuits the .gitdir discovery process
and lets Git treat the directory like any non-Git-controlled directory instead. -->
<Exec Command="$(PatchCommand) %(PatchesToApply.Identity)"
WorkingDirectory="$(ProjectDirectory)"
Condition="'@(PatchesToApply)' != ''"
EnvironmentVariables="GIT_DIR=/dev/null" />
<WriteLinesToFile File="$(RepoCompletedSemaphorePath)ApplyPatches.complete" Overwrite="true" />
</Target>
<!--
If a NuGet.config exists in the project, delete it, so the dotnet/source-build nuget.config is
found instead. This lets the subrepo use the incoming intermediate nupkg contents and avoids the
need to do subrepo-specific fixups like removing internet sources.
-->
<Target Name="RemoveNuGetConfig"
Condition="'$(NuGetConfigFile)' != '' OR '@(NuGetConfigFiles)' != ''">
<ItemGroup>
<NuGetConfigFiles Include="$(NuGetConfigFile)" />
</ItemGroup>
<Delete Files="@(NuGetConfigFiles)" />
</Target>
<!--
Add a new nuget config file at the root of the component that includes sources for its dependencies'
outputs.
-->
<Target Name="AddNewNuGetConfigForDependencies"
Condition="'@(RepositoryReference)' != ''">
<PropertyGroup>
<NewNuGetConfigFile>$(ProjectDirectory)NuGet.config</NewNuGetConfigFile>
</PropertyGroup>
<ItemGroup>
<_DependentProjectSources Include="@(RepositoryReference -> '%(Identity).proj')">
<RepositoryName>%(Identity)</RepositoryName>
</_DependentProjectSources>
</ItemGroup>
<MSBuild Projects="@(_DependentProjectSources)"
Targets="GetPackagesOutput">
<Output TaskParameter="TargetOutputs" ItemName="_DependencyProjectsPackagesOutput" />
</MSBuild>
<PropertyGroup>
<NewNuGetConfigContent>
<![CDATA[
<configuration>
<packageSources>
<clear />
</packageSources>
</configuration>
]]>
</NewNuGetConfigContent>
</PropertyGroup>
<WriteLinesToFile Lines="$(NewNuGetConfigContent)" File="$(NewNuGetConfigFile)" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NewNuGetConfigFile)"
SourceName="%(_DependencyProjectsPackagesOutput.RepositoryName)"
SourcePath="%(_DependencyProjectsPackagesOutput.Identity)" />
</Target>
<!-- Root target for nuget updates. Removes the existing nuget config files, then adds a new one for dependencies
if necessary. -->
<Target Name="UpdateNuGetConfig"
DependsOnTargets="RemoveNuGetConfig;AddNewNuGetConfigForDependencies"
BeforeTargets="Build"
Condition="'$(NuGetConfigFile)' != '' OR '@(NuGetConfigFiles)' != '' OR '@(RepositoryReference)' != ''"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(RepoCompletedSemaphorePath)UpdateNuGetConfig.complete">
<WriteLinesToFile File="$(RepoCompletedSemaphorePath)UpdateNuGetConfig.complete" Overwrite="true" />
</Target>
<Target Name="UpdateGlobalJsonVersions"
BeforeTargets="Build"
Condition="'$(GlobalJsonFile)' != ''"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(RepoCompletedSemaphorePath)UpdateGlobalJsonVersions.complete">
<ItemGroup>
<_PossibleCliVersionJsonPath Include="sdk.version" />
<_PossibleCliVersionJsonPath Include="tools.dotnet" />
</ItemGroup>
<UpdateJson JsonFilePath="$(GlobalJsonFile)"
PathToAttribute="%(_PossibleCliVersionJsonPath.Identity)"
NewAttributeValue="$(SDK_VERSION)"
SkipUpdateIfMissingKey="true" />
<WriteLinesToFile File="$(RepoCompletedSemaphorePath)UpdateGlobalJsonVersions.complete" Overwrite="true" />
</Target>
<Target Name="EnsureRedirectLogOutputDirExists">
<MakeDir Directories="$(LoggingDir)" />
</Target>
<Target Name="Build"
DependsOnTargets="
BuildRepoReferences;
ApplyPatches;
EnsureRedirectLogOutputDirExists"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(RepoCompletedSemaphorePath)Build.complete">
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(ProjectBuildReason)" />
<Message Importance="High" Text="Running command:" />
<Message Importance="High" Text=" $(BuildCommand)" Condition="'$(BuildCommand)' != ''" />
<Message Importance="High" Text=" Using custom build target" Condition="'$(BuildCommand)' == ''" />
<Message Importance="High" Text=" Log: $(RepoConsoleLogFile)" />
<Message Importance="High" Text=" With Environment Variables:" />
<Message Importance="High" Text=" %(EnvironmentVariables.Identity)" />
<CallTarget Targets="RepoBuild" />
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(ProjectBuildReason)...done" />
<WriteLinesToFile File="$(RepoCompletedSemaphorePath)Build.complete" Overwrite="true" />
<OnError ExecuteTargets="ReportRepoError" />
</Target>
<Target Name="RepoBuild">
<ItemGroup>
<EnvironmentVariables Condition="'$(NUGET_PACKAGES)'!=''" Include="NUGET_PACKAGES=$(NUGET_PACKAGES)" />
</ItemGroup>
<PropertyGroup>
<FullCommand Condition="'$(LogVerbosityOptOut)' != 'true'">$(BuildCommand) /v:$(LogVerbosity) $(RedirectRepoOutputToLog)</FullCommand>
<FullCommand Condition="'$(LogVerbosityOptOut)' == 'true'">$(BuildCommand) $(RedirectRepoOutputToLog)</FullCommand>
</PropertyGroup>
<Exec Command="$(FullCommand)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(EnvironmentVariables)"
IgnoreStandardErrorWarningFormat="true" />
</Target>
<Target Name="ReportRepoError">
<Message Importance="High" Text="$([System.IO.File]::ReadAllText('$(RepoConsoleLogFile)'))" Condition="Exists('$(RepoConsoleLogFile)')" />
<Message Importance="High" Text="'$(RepositoryName)' failed during build." />
<Message Importance="High" Text="See '$(RepoConsoleLogFile)' for more information." Condition="Exists('$(RepoConsoleLogFile)')" />
</Target>
<Target Name="Package" AfterTargets="Build"
Condition="'$(BuildPackagesCommand)' != ''"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(RepoCompletedSemaphorePath)Package.complete">
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Packaging $(ProjectBuildReason)" />
<Message Importance="High" Text="Running command:" />
<Message Importance="High" Text=" $(BuildPackagesCommand)" />
<Message Importance="High" Text=" Log: $(RepoConsoleLogFile)" />
<Message Importance="High" Text=" With Environment Variables:" />
<Message Importance="High" Text=" %(EnvironmentVariables.Identity)" />
<Exec Command="$(BuildPackagesCommand) /v:$(LogVerbosity) $(RedirectRepoOutputToLog)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(EnvironmentVariables)"
IgnoreStandardErrorWarningFormat="true" />
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Packaging $(ProjectBuildReason)...done" />
<WriteLinesToFile File="$(RepoCompletedSemaphorePath)Package.complete" Overwrite="true" />
<OnError ExecuteTargets="ReportRepoError" />
</Target>
<Target Name="GatherBuiltPackages">
<ItemGroup>
<!-- Filter out packages for WriteVersions -->
<_BuiltPackages Condition="'$(PackagesOutput)' != ''" Include="$(PackagesOutput)/*.nupkg" Exclude="$(PackagesOutput)/*.symbols.nupkg"/>
<_BuiltPackages Condition="'@(PackagesOutputList)' != ''" Include="%(PackagesOutputList.Identity)/*.nupkg" Exclude="%(PackagesOutputList.Identity)/*.symbols.nupkg"/>
</ItemGroup>
</Target>
<Target Name="CopyPackage"
AfterTargets="Package"
Condition="'$(PackagesOutput)' != '' OR '@(PackagesOutputList)' != ''"
DependsOnTargets="GatherBuiltPackages"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(RepoCompletedSemaphorePath)CopyPackage.complete">
<Copy SourceFiles="@(_BuiltPackages)"
DestinationFolder="$(SourceBuiltPackagesPath)"
Condition="'@(_BuiltPackages)'!=''" />
<WriteLinesToFile File="$(RepoCompletedSemaphorePath)CopyPackage.complete" Overwrite="true" />
</Target>
<Target Name="Clean" Condition="'$(CleanCommand)' != ''" >
<Exec Command="$(CleanCommand) /v:$(LogVerbosity) $(RedirectRepoOutputToLog)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(EnvironmentVariables)"
IgnoreStandardErrorWarningFormat="true" />
</Target>
<Target Name="SetNuGetPackagesEnvironment" Condition="'$(ArchiveDownloadedPackages)' == 'true'">
<PropertyGroup>
<LocalNuGetPackagesRootForRepository>$(LocalNuGetPackagesRoot)$(RepositoryName)/</LocalNuGetPackagesRootForRepository>
</PropertyGroup>
<MakeDir Directories="$(LocalNuGetPackagesRootForRepository)" />
<ItemGroup>
<EnvironmentVariables Include="NUGET_PACKAGES=$(LocalNuGetPackagesRootForRepository)" />
</ItemGroup>
</Target>
<Target Name="GetRepositoryReferences" Outputs="@(RepositoryReference)" />
<Target Name="GetPackagesOutput" Outputs="$(PackagesOutput)" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
</Project>