Fix repo builds not getting propagated when using the minimal console log (#18501)

Noticed in https://github.com/dotnet/installer/pull/18409 that errors aren't propagated which resulted in builds not to fail.

The fix here is to use `OnError` in the correct target (but only when using the minimal console log feature) and not set `IgnoreStandardErrorWarningFormat=true` on the Exec task that invokes the repo build script.

I also cleaned targets up as those introduced unnecessary complexity and logged in cases when they shouldn't (i.e. in dotnet.proj or package-source-build.proj).

This affected runtime which errors after 30s of building because of RuntimeOS and BaseOS being passed in in-correctly. Regressed with cca2b7bede (diff-86602308e6bb519266bc2f224ea65e39589d273804d40ad0f9c6e0eea2a263dc). Fixed that in runtime.proj. Kudos to Alexander who made the fix. I just copied it in form his CI PR.
This commit is contained in:
Viktor Hofer 2024-02-02 18:38:41 +01:00 committed by GitHub
parent db6f1a6e17
commit d693228ff8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 39 additions and 38 deletions

View file

@ -57,7 +57,6 @@
<!-- Update NuGet feeds in the repo -->
<Target Name="UpdateNuGetConfig"
BeforeTargets="Build"
Condition="'$(NuGetConfigFile)' != '' or '@(NuGetConfigFiles)' != ''"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)UpdateNuGetConfig.complete">
@ -146,7 +145,6 @@
<!-- Update the SDK version in the repo's global.json file.
This guarantees that all repositories build with the VMR's SDK version. -->
<Target Name="UpdateGlobalJsonVersions"
BeforeTargets="Build"
Condition="'$(GlobalJsonFile)' != ''"
Inputs="$(MSBuildProjectFullPath);$(MSBuildThisFileFullPath)"
Outputs="$(BaseIntermediateOutputPath)UpdateGlobalJsonVersions.complete">
@ -173,8 +171,7 @@
<!-- TODO: Remove when all repos use a consistent set of eng/common files: https://github.com/dotnet/source-build/issues/3710. -->
<Target Name="UpdateEngCommonFiles"
Condition="'$(UpdateEngCommonFiles)' == 'true' or '$(DotNetBuildSourceOnly)' != 'true'"
BeforeTargets="Build">
Condition="'$(UpdateEngCommonFiles)' == 'true' or '$(DotNetBuildSourceOnly)' != 'true'">
<ItemGroup>
<OrchestratorEngCommonFile Include="$(RepositoryEngineeringDir)common\**\*" />
</ItemGroup>
@ -187,7 +184,6 @@
<!-- Before a repository builds, set up the version property files that override the repo's defaults.
There are 3 files generated -->
<Target Name="CreateBuildInputProps"
BeforeTargets="Build"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)CreateBuildInputProps.complete">
<ItemGroup>
@ -268,31 +264,25 @@
StopOnFirstFailure="true" />
</Target>
<Target Name="Build"
DependsOnTargets="BuildRepoReferences"
<Target Name="RepoBuild"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)Build.complete">
Outputs="$(BaseIntermediateOutputPath)Build.complete"
Condition="'$(BuildCommand)' != ''"
DependsOnTargets="BuildRepoReferences;
UpdateNuGetConfig;
UpdateGlobalJsonVersions;
CreateBuildInputProps;
UpdateEngCommonFiles;
SetSourceBuiltSdkOverrides">
<Exec Command="$(DotnetTool) build-server shutdown" />
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(RepositoryName)" />
<Message Importance="High" Text="Running command:" Condition="'$(BuildCommand)' != ''" />
<Message Importance="High" Text=" $(BuildCommand)" Condition="'$(BuildCommand)' != ''" />
<Message Importance="High" Text=" Log: $(RepoConsoleLogFile)" Condition="'$(BuildCommand)' != '' and '$(MinimalConsoleLogOutput)' == 'true'" />
<Message Importance="High" Text=" With Environment Variables:" Condition="'$(BuildCommand)' != ''" />
<Message Importance="High" Text=" %(EnvironmentVariables.Identity)" Condition="'$(BuildCommand)' != ''" />
<CallTarget Targets="RepoBuild" />
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(RepositoryName)...done" />
<Message Importance="High" Text="Running command:" />
<Message Importance="High" Text=" $(BuildCommand)" />
<Message Importance="High" Text=" Log: $(RepoConsoleLogFile)" Condition="'$(MinimalConsoleLogOutput)' == 'true'" />
<Message Importance="High" Text=" With Environment Variables:"/>
<Message Importance="High" Text=" %(EnvironmentVariables.Identity)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)Build.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
<OnError ExecuteTargets="ReportRepoError" />
</Target>
<Target Name="RepoBuild"
Condition="'$(BuildCommand)' != ''">
<Message Text="DirSize Before Building $(RepositoryName)" Importance="High"
Condition=" '$(CleanWhileBuilding)' == 'true' and '$(BuildOS)' != 'windows'" />
<Exec Command="df -h $(RepoRoot)"
@ -315,16 +305,27 @@
<Exec Command="$(FullCommand)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(EnvironmentVariables)"
IgnoreStandardErrorWarningFormat="true" />
EnvironmentVariables="@(EnvironmentVariables)" />
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(RepositoryName)...done" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)Build.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
<!-- Propagate errors to the output when using the minimal console log feature. -->
<OnError ExecuteTargets="LogRepoBuildError" Condition="'$(MinimalConsoleLogOutput)' == 'true'" />
</Target>
<Target Name="ReportRepoError">
<Target Name="LogRepoBuildError">
<Message Importance="High" Text="$([System.IO.File]::ReadAllText('$(RepoConsoleLogFile)'))" Condition="Exists('$(RepoConsoleLogFile)') and '$(MinimalConsoleLogOutput)' == 'true'" />
<Message Importance="High" Text="'$(RepositoryName)' failed during build." />
<Message Importance="High" Text="See '$(RepoConsoleLogFile)' for more information." Condition="Exists('$(RepoConsoleLogFile)') and '$(MinimalConsoleLogOutput)' == 'true'" />
</Target>
<Target Name="Build" DependsOnTargets="BuildRepoReferences;RepoBuild" />
<Target Name="Package" AfterTargets="Build" />
<Target Name="GatherBuiltPackages">
@ -643,7 +644,6 @@
</Target>
<Target Name="SetSourceBuiltSdkOverrides"
BeforeTargets="Build"
Condition="'@(SourceBuiltSdkOverride)' != ''">
<ItemGroup>
<EnvironmentVariables Include="SOURCE_BUILT_SDK_ID_%(SourceBuiltSdkOverride.Group)=%(SourceBuiltSdkOverride.Identity)" />