forked from dotnet/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SourceBuildArcadeTarball.targets
415 lines (346 loc) · 17.1 KB
/
SourceBuildArcadeTarball.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project Sdk="Microsoft.DotNet.Arcade.Sdk">
<Import Project="./BuildTasks.props" />
<Import Project="../tools/SourceBuild/SourceBuildArcadeTools.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
<Import Project="$(RepoRoot)/src/redist/targets/Versions.targets" />
<Import Project="$(RepoRoot)/src/redist/targets/SetBuildDefaults.targets" />
<Import Project="$(RepoRoot)/src/redist/targets/FileExtensions.targets" />
<Import Project="$(RepoRoot)/src/redist/targets/GetRuntimeInformation.targets" />
<Import Project="$(RepoRoot)/src/redist/targets/GenerateLayout.targets" />
<UsingTask TaskName="Microsoft.DotNet.SourceBuild.Tasks.Tarball_ReadSourceBuildIntermediateNupkgDependencies" AssemblyFile="$(SourceBuildTasksAssembly)" />
<UsingTask TaskName="Microsoft.DotNet.SourceBuild.Tasks.Tarball_WriteSourceRepoProperties" AssemblyFile="$(SourceBuildTasksAssembly)" />
<PropertyGroup>
<ArtifactsDir>$(RepoRoot)artifacts/</ArtifactsDir>
<TarballDir Condition=" '$(TarballDir)' == '' ">$(ArtifactsDir)tarball/</TarballDir>
<TarballRootDir>$([MSBuild]::EnsureTrailingSlash('$(TarballDir)'))</TarballRootDir>
<TarballSourceDir>$(TarballRootDir)src/</TarballSourceDir>
<TarballGitInfoDir>$(TarballRootDir)git-info/</TarballGitInfoDir>
<CloneVerbosity>quiet</CloneVerbosity> <!-- Support quiet and full -->
<ConvertInternalRepos Condition="'$(ConvertInternalRepos)' == '' and '$(VSS_NUGET_EXTERNAL_FEED_ENDPOINTS)' == '' and '$(AzDoPat)' == ''">true</ConvertInternalRepos>
</PropertyGroup>
<Target Name="CreateSourceTarball"
DependsOnTargets="
GenerateFullNuGetVersion;
GenerateVersionFile;
CreateTarballDir;
SetupSelfGithubInfo;
CloneRepoAndDependentsRecursive;
CleanClonedSource;
RestoreTextOnlyPackages;
CopyTextOnlyPackages;
CopyTarballContent;
">
<PropertyGroup>
<TarballFileDir>$([System.IO.Path]::GetDirectoryName('$(TarballFilePath)'))</TarballFileDir>
</PropertyGroup>
<Error Text="TarballFilePath not specified." Condition=" '$(TarballFilePath)' == '' " />
<MakeDir Directories="$(TarballFileDir)" Condition=" '$(TarballFileDir)' != '' " />
<Exec Command="tar --numeric-owner -zcf $(TarballFilePath) -C $(TarballDir) ." />
<Message Text="Tarball '$(TarballFilePath)' was successfully created from '$(TarballDir)'" Importance="High" />
</Target>
<Target Name="CreateTarballDir" >
<RemoveDir Directories='$(TarballRootDir)' Condition=" EXISTS('$(TarballRootDir)') " />
<Error Text="Tarball directory not specified. Pass /p:TarballDir=[new dir name] to specify a tarball directory." Condition=" '$(TarballDir)' == '' " />
<Error Text="Tarball directory already exists: $(TarballRootDir)" Condition=" '$(TarballRootDir)' != '' AND EXISTS('$(TarballRootDir)') " />
<MakeDir Directories="$(TarballRootDir)" Condition=" '$(TarballRootDir)' != '' " />
<MakeDir Directories="$(TarballSourceDir)" Condition=" '$(TarballSourceDir)' != '' " />
<MakeDir Directories="$(TarballGitInfoDir)" Condition=" '$(TarballGitInfoDir)' != '' " />
</Target>
<Target Name="SetupSelfGithubInfo" Condition=" '$(IsRootRepo)' != 'true' ">
<Exec
Command="cd $(RepoRoot);git config --get remote.origin.url"
ConsoleToMSBuild="true"
WorkingDirectory="$(RepoRoot)">
<Output TaskParameter="ConsoleOutput" ItemName="RootRepoUri" />
</Exec>
<Exec
Command="cd $(RepoRoot);git rev-parse HEAD"
ConsoleToMSBuild="true"
WorkingDirectory="$(RepoRoot)">
<Output TaskParameter="ConsoleOutput" ItemName="RootRepoCommitSha" />
</Exec>
<!-- Get commit count for installer repo only -->
<Exec
Command="cd $(RepoRoot);git rev-list --count HEAD"
ConsoleToMSBuild="true"
WorkingDirectory="$(RepoRoot)">
<Output TaskParameter="ConsoleOutput" ItemName="RootRepoCommitCount" />
</Exec>
<!-- This is hardcoding version for the root repo (installer), since there
isn't a Version.Details.xml file to read it from.
See https://github.com/dotnet/source-build/issues/2250 -->
<ItemGroup>
<SourceBuildRepos Include="$(GitHubRepositoryName)">
<Name>$(GitHubRepositoryName)</Name>
<Version>$(VersionPrefix)</Version>
<ExactVersion>$(VersionPrefix)</ExactVersion>
<Sha>@(RootRepoCommitSha)</Sha>
<Uri>@(RootRepoUri)</Uri>
<GitCommitCount>@(RootRepoCommitCount)</GitCommitCount>
<SourceBuildRepoName>$(GitHubRepositoryName)</SourceBuildRepoName>
<IsRootRepo>true</IsRootRepo>
</SourceBuildRepos>
</ItemGroup>
<Tarball_WriteSourceRepoProperties
SourceBuildMetadataDir="$(TarballGitInfoDir)"
Dependencies="@(SourceBuildRepos)" />
<PropertyGroup>
<SourceBuildRepoName>%(SourceBuildRepos.SourceBuildRepoName)</SourceBuildRepoName>
<RepoUri>%(SourceBuildRepos.Uri)</RepoUri>
<RepoSha>%(SourceBuildRepos.Sha)</RepoSha>
<IsRootRepo>%(SourceBuildRepos.IsRootRepo)</IsRootRepo>
</PropertyGroup>
<!-- Remove root repo from SourceBuildRepos so it doesn't try to clone twice -->
<ItemGroup>
<SourceBuildRepos Remove="@(SourceBuildRepos)" />
</ItemGroup>
</Target>
<Target Name="CloneRepoAndDependentsRecursive"
DependsOnTargets="GetSourceBuildIntermediateNupkgNameConvention">
<Message Text="--> Start Cloning Repo $(SourceBuildRepoName)" Importance="High" />
<PropertyGroup>
<SourceDir>$(SourceBuildRepoName)/</SourceDir>
<TarballRepoSourceDir>$(TarballSourceDir)$(SourceDir)</TarballRepoSourceDir>
<TarballRepoSourceEngDir>$(TarballSourceDir)$(SourceDir)eng/</TarballRepoSourceEngDir>
<TarballVersionDetailsFile>$(TarballRepoSourceEngDir)Version.Details.xml</TarballVersionDetailsFile>
<CloneParam Condition=" '$(CloneVerbosity)' == 'quiet' ">-q</CloneParam>
<OriginalRepoUri>$(RepoUri)</OriginalRepoUri>
<RepoUri Condition=" '$(AzDoPat)' != '' ">$(RepoUri.Replace('https://dev.azure.com', 'https://dn-bot:$(AzDoPat)@dev.azure.com'))</RepoUri>
</PropertyGroup>
<!-- Perform a local clone of the root repo, it's faster and doesn't require the RepoSha to be a tree. -->
<Exec
Command="git clone ./.git $(TarballRepoSourceDir)"
WorkingDirectory="$(RepoRoot)"
Condition="$(IsRootRepo) == 'true'" />
<!-- Because the root repo was locally cloned, the remote.origin.url needs to be updated from the local source to the real origin -->
<Exec
Command="git config --file $(TarballRepoSourceDir)/.git/config --unset remote.origin.url"
WorkingDirectory="$(RepoRoot)"
Condition="$(IsRootRepo) == 'true'" />
<Exec
Command="git config --file $(TarballRepoSourceDir)/.git/config --add remote.origin.url `git config --get remote.origin.url`"
WorkingDirectory="$(RepoRoot)"
Condition="$(IsRootRepo) == 'true'" />
<!-- Needed in cases where source-build is pinned to a version of the root repo. -->
<Exec
Command="git reset --hard $(RepoSha)"
WorkingDirectory="$(TarballRepoSourceDir)"
Condition="$(IsRootRepo) == 'true'" />
<Exec
Command="git init $(TarballRepoSourceDir)"
WorkingDirectory="$(RepoRoot)"
Condition="$(IsRootRepo) != 'true'" />
<Exec
Command="git remote add origin $(RepoUri)"
WorkingDirectory="$(TarballRepoSourceDir)"
Condition="$(IsRootRepo) != 'true'" />
<!-- Fetching a sha requires git 2.5.0 or newer -->
<Exec
Command="git fetch --depth 1 origin $(RepoSha)"
WorkingDirectory="$(TarballRepoSourceDir)"
Condition="$(IsRootRepo) != 'true'" />
<Exec
Command="git reset --hard FETCH_HEAD"
WorkingDirectory="$(TarballRepoSourceDir)"
Condition="$(IsRootRepo) != 'true'" />
<Exec
Command="git submodule update --init --recursive --depth 1"
WorkingDirectory="$(TarballRepoSourceDir)" />
<Exec
Command="git submodule foreach 'rm -rf %24%28git rev-parse --git-dir%29/objects ||:'"
WorkingDirectory="$(TarballRepoSourceDir)"
Condition="$(PreserveTarballGitFolders) != 'true'" />
<Exec
Command="git config --file $(TarballRepoSourceDir)/.git/config --unset remote.origin.url"
WorkingDirectory="$(RepoRoot)"/>
<Exec
Command="git config --file $(TarballRepoSourceDir)/.git/config --add remote.origin.url $(OriginalRepoUri)"
WorkingDirectory="$(RepoRoot)"/>
<!-- Remove the git objects folder to free up tarball space -->
<Exec
Command="rm -rf objects"
WorkingDirectory="$(TarballRepoSourceDir).git"
Condition="$(PreserveTarballGitFolders) != 'true'" />
<Message Text="--> Done Cloning Repo $(SourceBuildRepoName)" Importance="High" />
<!-- Apply source-build patches -->
<ItemGroup>
<SourceBuildPatchFile Include="$(RepoRoot)src/SourceBuild/tarball/patches/$(SourceBuildRepoName)/*.patch" />
</ItemGroup>
<Message
Text="--> Applying $(SourceBuildRepoName) Patches"
Importance="High"
Condition="'@(SourceBuildPatchFile)' != ''" />
<Exec
Command="git --work-tree=$(TarballRepoSourceDir) apply --ignore-whitespace --whitespace=nowarn "%(SourceBuildPatchFile.FullPath)""
WorkingDirectory="$(TarballRepoSourceDir)"
Condition="'@(SourceBuildPatchFile)' != ''" />
<Message
Text="--> Done Applying $(SourceBuildRepoName) Patches"
Importance="High"
Condition="'@(SourceBuildPatchFile)' != ''" />
<Tarball_ReadSourceBuildIntermediateNupkgDependencies
VersionDetailsXmlFile="$([MSBuild]::NormalizePath($(TarballVersionDetailsFile)))"
SourceBuildIntermediateNupkgPrefix="$(SourceBuildIntermediateNupkgPrefix)"
SourceBuildIntermediateNupkgRid="$(SourceBuildIntermediateNupkgRid)"
ConvertInternalRepos="$(ConvertInternalRepos)">
<Output TaskParameter="Dependencies" ItemName="SourceBuildRepos" />
</Tarball_ReadSourceBuildIntermediateNupkgDependencies>
<!-- Remove repo if it has already be cloned at any sha. This results in
The commit sha for the cloned repo in the tarball being the one that
was first encountered. -->
<ItemGroup>
<SourceBuildRepos Remove="@(SourceBuildRepos)" Condition=" EXISTS('$(TarballGitInfoDir)%(SourceBuildRepoName).props')" />
</ItemGroup>
<Tarball_WriteSourceRepoProperties
SourceBuildMetadataDir="$(TarballGitInfoDir)"
Dependencies="@(SourceBuildRepos)" />
<Message Text="--> Dependencies for $(TarballVersionDetailsFile):" Importance="High" Condition=" '@(SourceBuildRepos)' != '' " />
<Message Text="--> %(SourceBuildRepos.SourceBuildRepoName) / %(SourceBuildRepos.Sha)" Importance="High" Condition=" '@(SourceBuildRepos)' != '' " />
<MSBuild Projects="$(MSBuildProjectFile)"
Condition=" '@(SourceBuildRepos)' != '' "
Targets="CloneRepoAndDependentsRecursive"
Properties="SourceBuildRepoName=%(SourceBuildRepos.SourceBuildRepoName);RepoSha=%(SourceBuildRepos.Sha);RepoUri=%(SourceBuildRepos.Uri)" />
</Target>
<Target Name="CleanClonedSource">
<ItemGroup>
<TarballSrcBinaryExtension Include="
.dll;
.Dll;
.exe;
.pdb;
.mdb;
.zip;
.nupkg" />
<TarballSrcBinaryToRemove Include="$(TarballSourceDir)**\*%(TarballSrcBinaryExtension.Identity)" />
<!-- Runtime coreclr and installer parts have empty placeholder PDB files. Keep them. -->
<TarballSrcBinaryToRemove Remove="
$(TarballSourceDir)runtime*\src\coreclr\.nuget\**\*%(TarballSrcBinaryExtension.Identity);
$(TarballSourceDir)runtime*\src\installer\pkg\**\*%(TarballSrcBinaryExtension.Identity)" />
</ItemGroup>
<Message Importance="Normal" Text="Deleting checked in binary files: @(TarballSrcBinaryToRemove, ' ')" />
<Delete Files="@(TarballSrcBinaryToRemove)" />
</Target>
<Target Name="RestoreTextOnlyPackages">
<PropertyGroup>
<TextOnlyPackageRestoreDir>$(ArtifactsDir)text-only-packages/</TextOnlyPackageRestoreDir>
<TextOnlyPackageTarballDir>$(TarballRootDir)packages/text-only/</TextOnlyPackageTarballDir>
</PropertyGroup>
<Message Text="Restoring text only packages..." Importance="High" />
<MSBuild Projects="$(RepoRoot)src/SourceBuild/Arcade/tools/TextOnlyPackages.csproj"
Properties="TargetPackagesPath=$(TextOnlyPackageRestoreDir)"
Targets="Restore" />
</Target>
<Target Name="CopyTarballContent">
<ItemGroup>
<TarballContent Include="$(RepoRoot)src/SourceBuild/tarball/content/**/*" />
<EngCommonContent Include="$(RepoRoot)eng/common/**/*" />
</ItemGroup>
<Copy
SourceFiles="@(TarballContent)"
DestinationFiles="@(TarballContent->'$(TarballRootDir)%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy
SourceFiles="@(EngCommonContent)"
DestinationFiles="@(EngCommonContent->'$(TarballRootDir)eng/common/%(RecursiveDir)%(Filename)%(Extension)')" />
<PropertyGroup>
<ExternalTarballsDir>$(TarballRootDir)packages/archive/</ExternalTarballsDir>
<SourceBuiltArtifactsTarballName>Private.SourceBuilt.Artifacts</SourceBuiltArtifactsTarballName>
<SourceBuiltPrebuiltsTarballName>Private.SourceBuilt.Prebuilts</SourceBuiltPrebuiltsTarballName>
<SourceBuiltArtifactsTarballUrl>https://dotnetcli.azureedge.net/source-built-artifacts/assets/</SourceBuiltArtifactsTarballUrl>
<ArchiveArtifactsTextFileName>archiveArtifacts.txt</ArchiveArtifactsTextFileName>
<ArchiveArtifactsTextFile>$(ExternalTarballsDir)$(ArchiveArtifactsTextFileName)</ArchiveArtifactsTextFile>
</PropertyGroup>
<MakeDir Directories="$(ExternalTarballsDir)" />
<ItemGroup>
<ArtifactUrls Include="$(SourceBuiltArtifactsTarballUrl)$(SourceBuiltArtifactsTarballName).$(PrivateSourceBuiltArtifactsPackageVersion).tar.gz" />
<ArtifactUrls
Include="$(SourceBuiltArtifactsTarballUrl)$(SourceBuiltPrebuiltsTarballName).$(PrivateSourceBuiltPrebuiltsPackageVersion).tar.gz"
Condition="'$(PrivateSourceBuiltPrebuiltsPackageVersion)' != ''" />
</ItemGroup>
<WriteLinesToFile
File="$(ArchiveArtifactsTextFile)"
Lines="@(ArtifactUrls)"
Overwrite="true" />
<MakeDir Directories="$(TarballRootDir)packages/prebuilt" />
<!-- make sure this directory is persisted through source control, NuGet depends on it existing -->
<Exec Command="touch $(TarballRootDir)packages/prebuilt/_" />
</Target>
<!--
Read directories in which text-only packages have been downloaded and copy content to tarball.
-->
<Target Name="CopyTextOnlyPackages" DependsOnTargets="RestoreTextOnlyPackages" >
<ReadLinesFromFile File="$(TextOnlyPackageRestoreDir)/TextOnlyPackageDirectories.txt" Condition="Exists('$(TextOnlyPackageRestoreDir)/TextOnlyPackageDirectories.txt')">
<Output TaskParameter="Lines" ItemName="TextOnlyPackageDirectories" />
</ReadLinesFromFile>
<MSBuild Projects="$(MSBuildProjectFile)"
Targets="CopySingleTextOnlyDirectory"
Properties="TextOnlyDirectory=%(TextOnlyPackageDirectories.Identity);TextOnlyPackageTarballDir=$(TextOnlyPackageTarballDir)" />
</Target>
<Target Name="CopySingleTextOnlyDirectory">
<PropertyGroup>
<DirectoryName>$([System.IO.Path]::GetFileName('$(TextOnlyDirectory)'))</DirectoryName>
</PropertyGroup>
<ItemGroup>
<TextOnlyPackageContent
Include="$(TextOnlyDirectory)/**/*"
Exclude="
$(TextOnlyDirectory)/**/.nupkg.metadata;
$(TextOnlyDirectory)/**/.signature.p7s;
$(TextOnlyDirectory)/**/*.nupkg;
$(TextOnlyDirectory)/**/*.nupkg.sha512;
" />
</ItemGroup>
<ItemGroup>
<!-- ttf, woff, woff2, eot are permissible font related content -->
<AllowedTextOnlyExtensions Include="
.-;
.bowerrc;
.config;
.cs;
.cshtml;
.csproj;
.css;
.db;
.editorconfig;
.env;
.env.development;
.eot;
.fs;
.fsproj;
.gitignore;
.gitkeep;
.html;
.ico;
.js;
.json;
.map;
.md;
.nuspec;
.otf;
.png;
.props;
.proto;
.razor;
.sln;
.svg;
.targets;
.ts;
.ttf;
.tsx;
.txt;
.vb;
.vbproj;
.woff;
.woff2;
browserslist;
browserslistrc;
LICENSE;" />
<UnsupportedTextOnlyPackageContent Include="@(TextOnlyPackageContent)" />
<UnsupportedTextOnlyPackageContent Remove="$(TextOnlyDirectory)/**/*$([System.String]::Copy('%(AllowedTextOnlyExtensions.Identity)').ToLowerInvariant())" />
<UnsupportedTextOnlyPackageContent Remove="$(TextOnlyDirectory)/**/*$([System.String]::Copy('%(AllowedTextOnlyExtensions.Identity)').ToUpperInvariant())" />
</ItemGroup>
<Error Text="Unsupported content found in text-only packages: @(UnsupportedTextOnlyPackageContent)" Condition=" '@(UnsupportedTextOnlyPackageContent)' != '' " />
<Copy
SourceFiles="@(TextOnlyPackageContent)"
DestinationFiles="@(TextOnlyPackageContent->'$(TextOnlyPackageTarballDir)$(DirectoryName)/%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
</Project>