Skip to content

Commit dec5515

Browse files
committed
Simplify scenario-tests test invocation & define dependencies
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.
1 parent ace21a6 commit dec5515

File tree

7 files changed

+57
-55
lines changed

7 files changed

+57
-55
lines changed

src/SourceBuild/content/repo-projects/Directory.Build.targets

+29
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,35 @@
620620
ExtractToolPackage;
621621
CleanupRepo" />
622622

623+
<Target Name="Test"
624+
Inputs="$(MSBuildProjectFullPath)"
625+
Outputs="$(BaseIntermediateOutputPath)Test.complete">
626+
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Testing $(RepositoryName)" />
627+
<Message Importance="High" Text="Running command:" />
628+
<Message Importance="High" Text=" $(TestCommand)" />
629+
<Message Importance="High" Text=" With Environment Variables:"/>
630+
<Message Importance="High" Text=" %(TestEnvironmentVariable.Identity)" />
631+
632+
<PropertyGroup>
633+
<FullTestCommand>$(TestCommand)</FullTestCommand>
634+
<FullTestCommand Condition="'$(LogVerbosityOptOut)' != 'true'">$(FullTestCommand) /v:$(LogVerbosity)</FullTestCommand>
635+
</PropertyGroup>
636+
637+
<Exec Command="$(FullTestCommand)"
638+
WorkingDirectory="$(ProjectDirectory)"
639+
EnvironmentVariables="@(TestEnvironmentVariable)">
640+
<Output TaskParameter="ExitCode" PropertyName="RepoTestExitCode" />
641+
</Exec>
642+
643+
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Testing $(RepositoryName)...done" />
644+
645+
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
646+
<Touch Files="$(BaseIntermediateOutputPath)Test.complete" AlwaysCreate="true">
647+
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
648+
</Touch>
649+
</Target>
650+
<Target Name="VSTest" DependsOnTargets="Test" />
651+
623652
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.UsageReport.WritePackageUsageData" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
624653
<Target Name="WritePrebuiltUsageData"
625654
Inputs="$(MSBuildProjectFullPath)"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<Project Sdk="Microsoft.Build.NoTargets" TreatAsLocalProperty="CleanWhileBuilding">
22

3+
<PropertyGroup>
4+
<!-- The scenario-tests repo shouldn't be cleaned after building as we run tests from it. -->
5+
<CleanWhileBuilding>false</CleanWhileBuilding>
6+
7+
<ScenarioTestsArtifactsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'scenario-tests'))</ScenarioTestsArtifactsDir>
8+
<ScenarioTestsResultsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsTestResultsDir)', 'scenario-tests'))</ScenarioTestsResultsDir>
9+
<NuGetConfigInputForScenarioTests>$([MSBuild]::NormalizePath('$(SrcDir)', 'sdk', 'NuGet.config'))</NuGetConfigInputForScenarioTests>
10+
<NuGetConfigOutputForScenarioTests>$(ScenarioTestsArtifactsDir)NuGet.config</NuGetConfigOutputForScenarioTests>
11+
</PropertyGroup>
12+
313
<ItemGroup>
414
<RepositoryReference Include="arcade" />
515
<RepositoryReference Include="command-line-api" />
@@ -10,28 +20,16 @@
1020
<RepositoryReference Include="source-build-reference-packages" />
1121
</ItemGroup>
1222

13-
<PropertyGroup>
14-
<!-- The scenario-tests repo shouldn't be cleaned after building as we run tests from it. -->
15-
<CleanWhileBuilding>false</CleanWhileBuilding>
16-
17-
<ScenarioTestsArtifactsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'scenario-tests'))</ScenarioTestsArtifactsDir>
18-
<ScenarioTestsResultsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsTestResultsDir)', 'scenario-tests'))</ScenarioTestsResultsDir>
19-
<_ScenarioTestsNuGetConfig>$(ScenarioTestsArtifactsDir)NuGet.config</_ScenarioTestsNuGetConfig>
20-
<_SdkNuGetConfig>$([MSBuild]::NormalizePath('$(SrcDir)', 'sdk', 'NuGet.config'))</_SdkNuGetConfig>
21-
</PropertyGroup>
22-
2323
<Target Name="SetupNuGetConfig"
24-
Inputs="$(_SdkNuGetConfig)"
25-
Outputs="$(_ScenarioTestsNuGetConfig)">
26-
27-
<Copy SourceFiles="$(_SdkNuGetConfig)"
28-
DestinationFiles="$(_ScenarioTestsNuGetConfig)" />
29-
24+
Inputs="$(NuGetConfigInputForScenarioTests)"
25+
Outputs="$(NuGetConfigOutputForScenarioTests)">
26+
<Copy SourceFiles="$(NuGetConfigInputForScenarioTests)"
27+
DestinationFiles="$(NuGetConfigOutputForScenarioTests)" />
3028
</Target>
3129

32-
<Target Name="RunScenarioTests"
33-
DependsOnTargets="SetupNuGetConfig;DetermineSourceBuiltSdkVersion">
34-
30+
<Target Name="PrepareScenarioTestsInputs"
31+
DependsOnTargets="SetupNuGetConfig;DetermineSourceBuiltSdkVersion"
32+
BeforeTargets="Test">
3533
<PropertyGroup>
3634
<_CurrentDateTime>$([System.DateTime]::Now.ToString("yyyy-MM-dd_HH_mm_ss"))</_CurrentDateTime>
3735
<_TestXmlOutputPath>$(ScenarioTestsResultsDir)$(_CurrentDateTime).xml</_TestXmlOutputPath>
@@ -49,18 +47,14 @@
4947
<MakeDir Directories="$(ScenarioTestsResultsDir)" />
5048

5149
<ItemGroup>
52-
<_ScenarioTestEnvVars Include="
50+
<TestEnvironmentVariable Include="
5351
TestRoot=$(_TestRoot);
5452
DotNetRoot=$(DotNetSdkExtractDir);
5553
TestSdkVersion=$(SourceBuiltSdkVersion);
5654
AdditionalTestArgs=$(_ScenarioTestsAdditionalArgs);
5755
DotNetTool=$(_DotNetTool);
5856
_InitializeDotNetCli=$(DotNetSdkExtractDir)" />
5957
</ItemGroup>
60-
61-
<Exec Command="$(TestCommand)"
62-
WorkingDirectory="$(ProjectDirectory)"
63-
EnvironmentVariables="@(_ScenarioTestEnvVars)" />
6458
</Target>
6559

6660
</Project>

src/SourceBuild/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/Microsoft.DotNet.SourceBuild.SmokeTests.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20+
<ProjectReference Include="$(RepositoryEngineeringDir)extract-sdk-archive.proj" ReferenceOutputAssembly="false" />
2021
<ProjectReference Include="..\TestUtilities\TestUtilities.csproj" />
2122
</ItemGroup>
2223

@@ -71,7 +72,7 @@
7172
</RuntimeHostConfigurationOption>
7273
<RuntimeHostConfigurationOption Include="$(MSBuildProjectName).MsftSdkTarballPath">
7374
<Value>$(MsftSdkTarballPath)</Value>
74-
</RuntimeHostConfigurationOption>
75+
</RuntimeHostConfigurationOption>
7576
<RuntimeHostConfigurationOption Include="$(MSBuildProjectName).PoisonReportPath"
7677
Condition="'$(EnablePoison)' == 'true'">
7778
<Value>$(PoisonUsageReportFile)</Value>

src/SourceBuild/content/test/Microsoft.DotNet.UnifiedBuild.Tests/Microsoft.DotNet.UnifiedBuild.Tests.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" />
1313
<PackageReference Include="NuGet.Protocol" />
14-
<ProjectReference Include="$(RepositoryEngineeringDir)merge-asset-manifests.proj" ReferenceOutputAssembly="false" PrivateAssets="all" />
14+
<ProjectReference Include="$(RepositoryEngineeringDir)extract-sdk-archive.proj" ReferenceOutputAssembly="false" />
15+
<ProjectReference Include="$(RepositoryEngineeringDir)merge-asset-manifests.proj" ReferenceOutputAssembly="false" />
1516
</ItemGroup>
1617

1718
<ItemGroup>

src/SourceBuild/content/test/scenario-tests/Directory.Build.targets

-9
This file was deleted.

src/SourceBuild/content/test/scenario-tests/scenario-tests.proj

-17
This file was deleted.

src/SourceBuild/content/test/tests.proj

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<_RunScenarioTests>true</_RunScenarioTests>
55

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

@@ -18,12 +18,15 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<ProjectReference Include="$(RepositoryEngineeringDir)extract-sdk-archive.proj" />
2221
<ProjectReference Include="Microsoft.DotNet.SourceBuild.SmokeTests\Microsoft.DotNet.SourceBuild.SmokeTests.csproj"
2322
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
2423
<ProjectReference Include="Microsoft.DotNet.UnifiedBuild.Tests\Microsoft.DotNet.UnifiedBuild.Tests.csproj"
2524
Condition="'$(ShortStack)' != 'true' and '$(PortableBuild)' == 'true' and '$(PgoInstrument)' != 'true'" />
26-
<ProjectReference Include="scenario-tests\scenario-tests.proj" Condition="'$(_RunScenarioTests)' == 'true'" />
25+
26+
<!-- Make sure that the sdk archive is extracted before running the scenario-tests. Need to do this here as it's hard
27+
to define the dependency directly in scneario-tests.proj. -->
28+
<ProjectReference Include="$(RepositoryEngineeringDir)extract-sdk-archive.proj" BuildInParallel="false" />
29+
<ProjectReference Include="$(RepoProjectsDir)scenario-tests.proj" Condition="'$(_RunScenarioTests)' == 'true'" BuildInParallel="false" />
2730
</ItemGroup>
2831

2932
</Project>

0 commit comments

Comments
 (0)