aspnetcore/build/RepositoryBuild.targets

186 строки
10 KiB
XML

<Project>
<PropertyGroup>
<!-- Experimental flag to run assemblies AND repos tests in parallel...if you dare. -->
<TestReposInParallel>false</TestReposInParallel>
<_NoBuildRepos>$(NoBuild)</_NoBuildRepos>
<_BuildScriptToExecute Condition="'$(OS)'!='Windows_NT'">build.sh</_BuildScriptToExecute>
<_BuildScriptToExecute Condition="'$(OS)'=='Windows_NT'">build.cmd</_BuildScriptToExecute>
</PropertyGroup>
<Target Name="GetRepoBatches" DependsOnTargets="GeneratePropsFiles;ComputeGraph">
<ItemGroup>
<RepositoryBuildOrder Condition="'%(RootPath)' == ''">
<RootPath>$(SubmoduleRoot)%(Identity)\</RootPath>
</RepositoryBuildOrder>
<BatchedRepository Include="$(MSBuildProjectFullPath)">
<BuildGroup>%(RepositoryBuildOrder.Order)</BuildGroup>
<Repository>%(RepositoryBuildOrder.Identity)</Repository>
<AdditionalProperties>
RepositoryToBuild=%(RepositoryBuildOrder.Identity);
BuildRepositoryRoot=$([MSBuild]::NormalizeDirectory(%(RepositoryBuildOrder.RootPath)))
</AdditionalProperties>
</BatchedRepository>
</ItemGroup>
</Target>
<Target Name="_BuildRepositories" DependsOnTargets="GetRepoBatches" Condition=" @(RepositoryBuildOrder->Count()) != 0 ">
<MSBuild
Projects="@(BatchedRepository)"
BuildInParallel="true"
StopOnFirstFailure="true"
Targets="_BuildRepository"
Properties="BuildGroup=%(BatchedRepository.BuildGroup);BuildNumber=$(BuildNumber);IsFinalBuild=$(IsFinalBuild);Configuration=$(Configuration)" />
<PropertyGroup>
<_NoBuildRepos>true</_NoBuildRepos>
</PropertyGroup>
</Target>
<Target Name="_TestRepositories" DependsOnTargets="GetRepoBatches" Condition=" @(RepositoryBuildOrder->Count()) != 0 ">
<!--
Use the task to sort instead of batching (i.e. using %(BatchedRepository.BuildGroup))
When batching, StopOnFirstFailure doesn't help because the MSBuild task would be invoked multiple times
instead of invoking once with many projects.
-->
<RepoTasks.OrderBy Items="@(BatchedRepository)" Key="BuildGroup">
<Output TaskParameter="Items" ItemName="_BatchedTestRepo" />
</RepoTasks.OrderBy>
<MSBuild
Projects="@(_BatchedTestRepo)"
BuildInParallel="$(TestProjectsInParallel)"
StopOnFirstFailure="false"
Targets="_TestRepository"
Properties="BuildNumber=$(BuildNumber);IsFinalBuild=$(IsFinalBuild);Configuration=$(Configuration);_NoBuildRepos=$(_NoBuildRepos)"
ContinueOnError="true">
<Output TaskParameter="TargetOutputs" ItemName="_RepoTestResults" />
</MSBuild>
<Warning Text="No test results were found from running repos." Condition="@(_RepoTestResults->Count()) == 0"/>
<Message Text="Tests passed for the following repos:%0A - @(_RepoTestResults->WithMetadataValue('Success', 'true'), '%0A - ')"
Importance="High"
Condition="@(_RepoTestResults->WithMetadataValue('Success', 'true')->Count()) != 0 " />
<Error Text="Tests failed for the following repos:%0A - @(_RepoTestResults->WithMetadataValue('Success', 'false'), '%0A - ')"
Condition="@(_RepoTestResults->WithMetadataValue('Success', 'false')->Count()) != 0 " />
</Target>
<!-- Inner build context -->
<Target Name="GetRepoBuildProps">
<PropertyGroup>
<SkipTestsDueToMissingSharedFx Condition="'$(InstallSharedRuntimeFromPreviousBuild)' != 'true' And '$(TestsRequiredTheSharedRuntime)' == 'true' ">true</SkipTestsDueToMissingSharedFx>
<RepositoryBuildArguments Condition="'$(CI)'== 'true'">$(RepositoryBuildArguments) -ci</RepositoryBuildArguments>
<RepositoryBuildArguments Condition="'$(CI)'== 'true' AND '$(OS)' != 'Windows_NT'">$(RepositoryBuildArguments) --dotnet-home '$(DOTNET_HOME)'</RepositoryBuildArguments>
<RepositoryBuildArguments Condition="'$(CI)'== 'true' AND '$(OS)' == 'Windows_NT'">$(RepositoryBuildArguments) -DotNetHome '$(DOTNET_HOME)'</RepositoryBuildArguments>
<!-- Should reduce allowable package feeds to only nuget.org. -->
<RepositoryBuildArguments>$(RepositoryBuildArguments) /p:AspNetUniverseBuildOffline=true</RepositoryBuildArguments>
<!-- If there are duplicate properties, the properties which are defined later in the order would override the earlier ones -->
<RepositoryBuildArguments>$(RepositoryBuildArguments) /p:DotNetRestoreSourcePropsPath=$(GeneratedRestoreSourcesPropsPath)</RepositoryBuildArguments>
<RepositoryBuildArguments>$(RepositoryBuildArguments) /p:DotNetPackageVersionPropsPath=$(GeneratedPackageVersionPropsPath)</RepositoryBuildArguments>
<RepositoryBuildArguments>$(RepositoryBuildArguments) /p:BuildNumber=$(BuildNumber)</RepositoryBuildArguments>
<RepositoryBuildArguments>$(RepositoryBuildArguments) /p:Configuration=$(Configuration)</RepositoryBuildArguments>
<RepositoryBuildArguments>$(RepositoryBuildArguments) /p:IsFinalBuild=$(IsFinalBuild)</RepositoryBuildArguments>
<!-- We collect all output and code sign at the end. We don't need to code sign when we build each submodule. -->
<RepositoryBuildArguments>$(RepositoryBuildArguments) /p:DisableCodeSigning=true</RepositoryBuildArguments>
<RepositoryBuildArguments>$(RepositoryBuildArguments) '/p:DotNetAssetRootAccessTokenSuffix=$(DotNetAssetRootAccessTokenSuffix)'</RepositoryBuildArguments>
<RepositoryBuildArguments>$(RepositoryBuildArguments) '/p:DotNetAssetRootUrl=$(DotNetAssetRootUrl)'</RepositoryBuildArguments>
<RepositoryBuildArguments Condition=" '$(SkipTestsDueToMissingSharedFx)' == 'true' ">$(RepositoryBuildArguments) /p:SkipAspNetCoreRuntimeInstall=true</RepositoryBuildArguments>
<SourceLockFile>$(RepositoryRoot)korebuild-lock.txt</SourceLockFile>
<RepoLockFile>$(BuildRepositoryRoot)korebuild-lock.txt</RepoLockFile>
<BackupRepoLockFile>$(IntermediateDir)$(RepositoryToBuild)-korebuild-lock.txt</BackupRepoLockFile>
</PropertyGroup>
</Target>
<Target Name="_UpdateRepoLockFile">
<!-- Copy Korebuild lock file to individual repos to align version if the repo doesn't already have one -->
<Message Text="Copying KoreBuild lockfile from repo to submodule $(BuildRepositoryRoot)"/>
<Move SourceFiles="$(RepoLockFile)" DestinationFiles="$(BackupRepoLockFile)" Condition="Exists($(RepoLockFile))" />
<Copy SourceFiles="$(SourceLockFile)" DestinationFiles="$(RepoLockFile)" />
</Target>
<Target Name="_RestoreOriginalRepoLockFile">
<!-- Restore original Korebuild lock file -->
<Delete Files="$(RepoLockFile)" ContinueOnError="true" />
<Move SourceFiles="$(BackupRepoLockFile)" DestinationFiles="$(RepoLockFile)" Condition="Exists($(BackupRepoLockFile))" />
</Target>
<Target Name="_BuildRepository" DependsOnTargets="GetRepoBuildProps;_UpdateRepoLockFile">
<PropertyGroup>
<BuildArguments>/t:CleanArtifacts /t:Build /p:SkipTests=true $(RepositoryBuildArguments)</BuildArguments>
<BuildArguments Condition="'$(ProduceRepoBinLog)' == 'true'">$(BuildArguments) /bl:$(LogOutputDir)$(RepositoryToBuild).build.binlog</BuildArguments>
<RepositoryArtifactsRoot>$(BuildRepositoryRoot)artifacts</RepositoryArtifactsRoot>
<RepositoryArtifactsBuildDirectory>$(RepositoryArtifactsRoot)\build\</RepositoryArtifactsBuildDirectory>
<RepositoryArtifactsMSBuildDirectory>$(RepositoryArtifactsRoot)\msbuild\</RepositoryArtifactsMSBuildDirectory>
</PropertyGroup>
<Message Text="============ Building $(RepositoryToBuild) ============" Importance="High" />
<!-- Remove final slash in $(BuildRepositoryRoot) to avoid problems due to KoreBuild adding one on Windows. -->
<Exec
Command="./$(_BuildScriptToExecute) -Path $(BuildRepositoryRoot.TrimEnd('\\')) $(BuildArguments)"
IgnoreStandardErrorWarningFormat="true"
WorkingDirectory="$(RepositoryRoot)"
IgnoreExitCode="true"
ContinueOnError="WarnAndContinue">
<Output TaskParameter="ExitCode" PropertyName="BuildExitCode" />
</Exec>
<CallTarget Targets="_RestoreOriginalRepoLockFile" />
<!-- Fail if build.cmd didn't exit code 0 or process failed to start. -->
<Error Text="Building $(RepositoryToBuild) failed: $(_BuildScriptToExecute) exited code $(BuildExitCode)" Condition=" '$(BuildExitCode)' != '0' " />
<ItemGroup>
<RepositoryArtifacts Include="$(RepositoryArtifactsBuildDirectory)*" />
<RepositoryMSBuildArtifacts Include="$(RepositoryArtifactsMSBuildDirectory)**\*" />
</ItemGroup>
<Copy
SourceFiles="@(RepositoryArtifacts)"
DestinationFolder="$(BuildDir)" />
<Move
SourceFiles="@(RepositoryMSBuildArtifacts)"
DestinationFolder="$(ArtifactsDir)msbuild\$(RepositoryToBuild)\%(RecursiveDir)" />
<Message Text="============ Done building $(RepositoryToBuild) ============" Importance="High" />
</Target>
<Target Name="_TestRepository" DependsOnTargets="GetRepoBuildProps;_UpdateRepoLockFile" Returns="@(RepositoryTestResult)">
<PropertyGroup>
<BuildArguments>/t:Test /p:NoBuild=$(_NoBuildRepos) $(RepositoryBuildArguments)</BuildArguments>
</PropertyGroup>
<ItemGroup>
<RepositoryTestResult Include="$(RepositoryToBuild)" Success="false" />
</ItemGroup>
<!-- To enable this test, either publish the shared runtime to https://dotnetcli.blob.core.windows.net/dotnet, or override the install location by setting AspNetCoreFxFeed. -->
<Warning Text="Skipping tests because InstallSharedRuntimeFromPreviousBuild != 'true'." Condition="'$(SkipTestsDueToMissingSharedFx)' == 'true' "/>
<Message Text="============ Testing $(RepositoryToBuild) ============" Importance="High" />
<!-- Remove final slash in $(BuildRepositoryRoot) to avoid problems due to KoreBuild adding one on Windows. -->
<Exec Condition="'$(SkipTestsDueToMissingSharedFx)' != 'true' "
Command="./$(_BuildScriptToExecute) -Path $(BuildRepositoryRoot.TrimEnd('\\')) $(BuildArguments)"
IgnoreStandardErrorWarningFormat="true"
WorkingDirectory="$(RepositoryRoot)"
IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="TestExitCode" />
</Exec>
<CallTarget Targets="_RestoreOriginalRepoLockFile" />
<ItemGroup>
<RepositoryTestResult Update="$(RepositoryToBuild)" Success="true" Condition="'$(TestExitCode)' == '0' OR '$(SkipTestsDueToMissingSharedFx)' == 'true' " />
</ItemGroup>
<Message Text="============ Done testing $(RepositoryToBuild) ============" Importance="High" />
</Target>
</Project>