Skip to content

Commit

Permalink
Simplify scenario-tests test invocation & define dependencies
Browse files Browse the repository at this point in the history
1. Simplify scenario-tests test invocation by avoiding
   the intermediate NoTargets wrapper project.
2. Declare the dependency on extract-sdk-archive.proj
   in the test projects directly to avoid race
   conditions. #41014
   failed because the scenario-tests already ran
   but the SDK test folder wasn't yet ready.
  • Loading branch information
ViktorHofer committed May 21, 2024
1 parent ace21a6 commit dec5515
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 55 deletions.
29 changes: 29 additions & 0 deletions src/SourceBuild/content/repo-projects/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,35 @@
ExtractToolPackage;
CleanupRepo" />

<Target Name="Test"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)Test.complete">
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Testing $(RepositoryName)" />
<Message Importance="High" Text="Running command:" />
<Message Importance="High" Text=" $(TestCommand)" />
<Message Importance="High" Text=" With Environment Variables:"/>
<Message Importance="High" Text=" %(TestEnvironmentVariable.Identity)" />

<PropertyGroup>
<FullTestCommand>$(TestCommand)</FullTestCommand>
<FullTestCommand Condition="'$(LogVerbosityOptOut)' != 'true'">$(FullTestCommand) /v:$(LogVerbosity)</FullTestCommand>
</PropertyGroup>

<Exec Command="$(FullTestCommand)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(TestEnvironmentVariable)">
<Output TaskParameter="ExitCode" PropertyName="RepoTestExitCode" />
</Exec>

<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Testing $(RepositoryName)...done" />

<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)Test.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<Target Name="VSTest" DependsOnTargets="Test" />

<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.UsageReport.WritePackageUsageData" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="WritePrebuiltUsageData"
Inputs="$(MSBuildProjectFullPath)"
Expand Down
42 changes: 18 additions & 24 deletions src/SourceBuild/content/repo-projects/scenario-tests.proj
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<Project Sdk="Microsoft.Build.NoTargets" TreatAsLocalProperty="CleanWhileBuilding">

<PropertyGroup>
<!-- The scenario-tests repo shouldn't be cleaned after building as we run tests from it. -->
<CleanWhileBuilding>false</CleanWhileBuilding>

<ScenarioTestsArtifactsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'scenario-tests'))</ScenarioTestsArtifactsDir>
<ScenarioTestsResultsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsTestResultsDir)', 'scenario-tests'))</ScenarioTestsResultsDir>
<NuGetConfigInputForScenarioTests>$([MSBuild]::NormalizePath('$(SrcDir)', 'sdk', 'NuGet.config'))</NuGetConfigInputForScenarioTests>
<NuGetConfigOutputForScenarioTests>$(ScenarioTestsArtifactsDir)NuGet.config</NuGetConfigOutputForScenarioTests>
</PropertyGroup>

<ItemGroup>
<RepositoryReference Include="arcade" />
<RepositoryReference Include="command-line-api" />
Expand All @@ -10,28 +20,16 @@
<RepositoryReference Include="source-build-reference-packages" />
</ItemGroup>

<PropertyGroup>
<!-- The scenario-tests repo shouldn't be cleaned after building as we run tests from it. -->
<CleanWhileBuilding>false</CleanWhileBuilding>

<ScenarioTestsArtifactsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'scenario-tests'))</ScenarioTestsArtifactsDir>
<ScenarioTestsResultsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsTestResultsDir)', 'scenario-tests'))</ScenarioTestsResultsDir>
<_ScenarioTestsNuGetConfig>$(ScenarioTestsArtifactsDir)NuGet.config</_ScenarioTestsNuGetConfig>
<_SdkNuGetConfig>$([MSBuild]::NormalizePath('$(SrcDir)', 'sdk', 'NuGet.config'))</_SdkNuGetConfig>
</PropertyGroup>

<Target Name="SetupNuGetConfig"
Inputs="$(_SdkNuGetConfig)"
Outputs="$(_ScenarioTestsNuGetConfig)">

<Copy SourceFiles="$(_SdkNuGetConfig)"
DestinationFiles="$(_ScenarioTestsNuGetConfig)" />

Inputs="$(NuGetConfigInputForScenarioTests)"
Outputs="$(NuGetConfigOutputForScenarioTests)">
<Copy SourceFiles="$(NuGetConfigInputForScenarioTests)"
DestinationFiles="$(NuGetConfigOutputForScenarioTests)" />
</Target>

<Target Name="RunScenarioTests"
DependsOnTargets="SetupNuGetConfig;DetermineSourceBuiltSdkVersion">

<Target Name="PrepareScenarioTestsInputs"
DependsOnTargets="SetupNuGetConfig;DetermineSourceBuiltSdkVersion"
BeforeTargets="Test">
<PropertyGroup>
<_CurrentDateTime>$([System.DateTime]::Now.ToString("yyyy-MM-dd_HH_mm_ss"))</_CurrentDateTime>
<_TestXmlOutputPath>$(ScenarioTestsResultsDir)$(_CurrentDateTime).xml</_TestXmlOutputPath>
Expand All @@ -49,18 +47,14 @@
<MakeDir Directories="$(ScenarioTestsResultsDir)" />

<ItemGroup>
<_ScenarioTestEnvVars Include="
<TestEnvironmentVariable Include="
TestRoot=$(_TestRoot);
DotNetRoot=$(DotNetSdkExtractDir);
TestSdkVersion=$(SourceBuiltSdkVersion);
AdditionalTestArgs=$(_ScenarioTestsAdditionalArgs);
DotNetTool=$(_DotNetTool);
_InitializeDotNetCli=$(DotNetSdkExtractDir)" />
</ItemGroup>

<Exec Command="$(TestCommand)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(_ScenarioTestEnvVars)" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepositoryEngineeringDir)extract-sdk-archive.proj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\TestUtilities\TestUtilities.csproj" />
</ItemGroup>

Expand Down Expand Up @@ -71,7 +72,7 @@
</RuntimeHostConfigurationOption>
<RuntimeHostConfigurationOption Include="$(MSBuildProjectName).MsftSdkTarballPath">
<Value>$(MsftSdkTarballPath)</Value>
</RuntimeHostConfigurationOption>
</RuntimeHostConfigurationOption>
<RuntimeHostConfigurationOption Include="$(MSBuildProjectName).PoisonReportPath"
Condition="'$(EnablePoison)' == 'true'">
<Value>$(PoisonUsageReportFile)</Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" />
<PackageReference Include="NuGet.Protocol" />
<ProjectReference Include="$(RepositoryEngineeringDir)merge-asset-manifests.proj" ReferenceOutputAssembly="false" PrivateAssets="all" />
<ProjectReference Include="$(RepositoryEngineeringDir)extract-sdk-archive.proj" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(RepositoryEngineeringDir)merge-asset-manifests.proj" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions src/SourceBuild/content/test/scenario-tests/scenario-tests.proj

This file was deleted.

9 changes: 6 additions & 3 deletions src/SourceBuild/content/test/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<_RunScenarioTests>true</_RunScenarioTests>

<!-- Skip scenario tests if the host architecture is different from the target architecture since the tests
require the ability to execute the built SDK. But the CLI is not capable of running on a host with a
require the ability to execute the built SDK. But the CLI is not capable of running on a host with a
different architecture (i.e. "cannot execute binary file: Exec format error"). -->
<_RunScenarioTests Condition="'$(BuildArchitecture.ToLowerInvariant())' != '$(TargetArchitecture.ToLowerInvariant())'">false</_RunScenarioTests>

Expand All @@ -18,12 +18,15 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepositoryEngineeringDir)extract-sdk-archive.proj" />
<ProjectReference Include="Microsoft.DotNet.SourceBuild.SmokeTests\Microsoft.DotNet.SourceBuild.SmokeTests.csproj"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<ProjectReference Include="Microsoft.DotNet.UnifiedBuild.Tests\Microsoft.DotNet.UnifiedBuild.Tests.csproj"
Condition="'$(ShortStack)' != 'true' and '$(PortableBuild)' == 'true' and '$(PgoInstrument)' != 'true'" />
<ProjectReference Include="scenario-tests\scenario-tests.proj" Condition="'$(_RunScenarioTests)' == 'true'" />

<!-- Make sure that the sdk archive is extracted before running the scenario-tests. Need to do this here as it's hard
to define the dependency directly in scneario-tests.proj. -->
<ProjectReference Include="$(RepositoryEngineeringDir)extract-sdk-archive.proj" BuildInParallel="false" />
<ProjectReference Include="$(RepoProjectsDir)scenario-tests.proj" Condition="'$(_RunScenarioTests)' == 'true'" BuildInParallel="false" />
</ItemGroup>

</Project>

0 comments on commit dec5515

Please sign in to comment.