-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrastructure for trimming and NativeAOT test apps. (#48024)
* Add infrastructure for trimming and NativeAOT test apps. This infrastructure was taken from https://github.com/dotnet/runtime/tree/c62f69be1405a8e41b56ffc05f22d791bf4c7d2d/eng/testing/linker and modified to work in dotnet/aspnetcore. Added the first test: - Generic host + value type container builder (verify that error is thrown) Contributes to #45860 * Skip IsPublishedAppTestProject projects when SkipTestBuild=true. Use `Sdk="Microsoft.NET.Sdk"` in order to skip the build correctly. Only run the AOT tests during Test. Skip "Build" and skip publishing for Helix. Ensure the IsPublishedAppTestProject projects aren't built until the shared fx is built using RequiresDelayedBuild. * Add workaround for dotnet/arcade#13406
- Loading branch information
Showing
14 changed files
with
372 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<!-- Workaround while there is no SDK available that understands the TFM; suppress unsupported version errors. --> | ||
<NETCoreAppMaximumVersion>99.9</NETCoreAppMaximumVersion> | ||
|
||
<PublishTrimmed>true</PublishTrimmed> | ||
<TrimMode>full</TrimMode> | ||
<PublishSelfContained>true</PublishSelfContained> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<!-- Enable NuGet static graph evaluation to optimize incremental restore --> | ||
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<!-- Used to silence the warning caused by the workaround for https://github.com/dotnet/runtime/issues/81382 --> | ||
<SuppressGenerateILCompilerExplicitPackageReferenceWarning>true</SuppressGenerateILCompilerExplicitPackageReferenceWarning> | ||
</PropertyGroup> | ||
|
||
<!-- needed to reference a specific version of NetCoreApp. Workaround https://github.com/dotnet/runtime/issues/81382 --> | ||
<ItemGroup> | ||
<FrameworkReference Update="Microsoft.NETCore.App" | ||
RuntimeFrameworkVersion="$(MicrosoftNETCoreAppRuntimeVersion)" /> | ||
|
||
<PackageReference Include="Microsoft.Dotnet.ILCompiler" | ||
Version="$(MicrosoftNETCoreAppRuntimeVersion)" /> | ||
</ItemGroup> | ||
|
||
<!-- | ||
Reference the Microsoft.AspNetCore.App shared framework assemblies with ProjectReference. | ||
This allows for easy dev workflow. Just need to update the product code, and re-run the tests. | ||
--> | ||
<ItemGroup> | ||
<ProjectReference Include="$(RepoRoot)src\DefaultBuilder\src\Microsoft.AspNetCore.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>{TargetFramework}</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<RuntimeIdentifier>{RuntimeIdentifier}</RuntimeIdentifier> | ||
<PublishAot>{PublishAot}</PublishAot> | ||
<MicrosoftNETCoreAppRuntimeVersion>{MicrosoftNETCoreAppRuntimeVersion}</MicrosoftNETCoreAppRuntimeVersion> | ||
<RepoRoot>{RepoRoot}</RepoRoot> | ||
<_ExtraTrimmerArgs>{ExtraTrimmerArgs} $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs> | ||
{AdditionalProperties} | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
{RuntimeHostConfigurationOptions} | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
{AdditionalProjectReferences} | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<TrimmingTestDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'trimmingTests'))</TrimmingTestDir> | ||
<TrimmingTestProjectsDir>$([MSBuild]::NormalizeDirectory('$(TrimmingTestDir)', 'projects'))</TrimmingTestProjectsDir> | ||
<ProjectTemplate>$(MSBuildThisFileDirectory)project.csproj.template</ProjectTemplate> | ||
|
||
<!-- These test projects cannot be run in helix, since there is nothing to publish. --> | ||
<BuildHelixPayload>false</BuildHelixPayload> | ||
<IsPublishable>false</IsPublishable> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<!-- Microsoft.NET.Sdk needs a TFM set. Set a default one. --> | ||
<TargetFramework Condition="'$(TargetFramework)' == '' and '$(TargetFrameworks)' == ''">$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
|
||
<!-- Enforce build order. Ensure the Shared Fx is built before generating and publishing the test apps. --> | ||
<RequiresDelayedBuild>true</RequiresDelayedBuild> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<Project> | ||
<Import Project="$(RepoRoot)eng\targets\ResolveReferences.targets" /> | ||
|
||
<ItemGroup> | ||
<TestConsoleAppSourceFiles Condition="'@(TestConsoleAppSourceFiles)' == ''" Include="$(MSBuildProjectDirectory)\*.cs" /> | ||
|
||
<TestSupportFiles Include="$(MSBuildThisFileDirectory)SupportFiles\Directory.Build.*"> | ||
<DestinationFolder>$(TrimmingTestDir)</DestinationFolder> | ||
</TestSupportFiles> | ||
</ItemGroup> | ||
|
||
<Target Name="CreateTestDir" | ||
Inputs="@(TestSupportFiles)" | ||
Outputs="@(TestSupportFiles->'%(DestinationFolder)\%(FileName)%(Extension)')"> | ||
<MakeDir Directories="%(TestSupportFiles.DestinationFolder)" /> | ||
<Copy SourceFiles="@(TestSupportFiles)" DestinationFolder="%(TestSupportFiles.DestinationFolder)" /> | ||
</Target> | ||
|
||
<Target Name="GetTestConsoleApps"> | ||
<ItemGroup> | ||
<TestConsoleAppSourceFiles> | ||
<ProjectDir>$([MSBuild]::NormalizeDirectory('$(TrimmingTestProjectsDir)', '$(MSBuildProjectName)', '%(Filename)', '$(PackageRID)'))</ProjectDir> | ||
<TestRuntimeIdentifier>$(TargetRuntimeIdentifier)</TestRuntimeIdentifier> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
<TargetFramework Condition="'%(TestConsoleAppSourceFiles.TargetOS)' != ''">$(DefaultNetCoreTargetFramework)-%(TestConsoleAppSourceFiles.TargetOS)</TargetFramework> | ||
</TestConsoleAppSourceFiles> | ||
<!-- We need to separate Item metadata declaration in two in order to be able to use ProjectDir and TestRuntimeIdentifier below --> | ||
<TestConsoleAppSourceFiles> | ||
<ProjectFile>%(ProjectDir)project.csproj</ProjectFile> | ||
<TestCommand>$([MSBuild]::NormalizePath('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish', 'project'))</TestCommand> | ||
<TestExecutionDirectory>$([MSBuild]::NormalizeDirectory('%(ProjectDir)', 'bin', '$(Configuration)', '%(TargetFramework)', '%(TestRuntimeIdentifier)', 'publish'))</TestExecutionDirectory> | ||
</TestConsoleAppSourceFiles> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<TestConsoleApps Include="@(TestConsoleAppSourceFiles->'%(ProjectFile)')"> | ||
<ProjectCompileItems>%(FullPath)</ProjectCompileItems> | ||
</TestConsoleApps> | ||
<TestConsoleApps AdditionalProperties="MSBuildEnableWorkloadResolver=$(MSBuildEnableWorkloadResolver)" Condition="'$(MSBuildEnableWorkloadResolver)' != ''" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="GenerateProjects" | ||
DependsOnTargets="GetTestConsoleApps;CreateTestDir" | ||
Inputs="@(TestConsoleAppSourceFiles);$(ProjectTemplate);@(TestSupportFiles)" | ||
Outputs="%(TestConsoleApps.Identity)"> | ||
<PropertyGroup> | ||
<_projectDir>%(TestConsoleApps.ProjectDir)\</_projectDir> | ||
<_projectFile>%(TestConsoleApps.ProjectFile)</_projectFile> | ||
<_projectSourceFile>%(TestConsoleApps.ProjectCompileItems)</_projectSourceFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(AdditionalProjectReferences)' != ''"> | ||
<_additionalProjectReferenceTemp Include="$(AdditionalProjectReferences)" /> | ||
<_additionalProjectReference Include="<ProjectReference Include="$(LibrariesProjectRoot)%(_additionalProjectReferenceTemp.Identity)\src\%(_additionalProjectReferenceTemp.Identity).csproj" SkipUseReferenceAssembly="true" />" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<_additionalProjectReferencesString>@(_additionalProjectReference, '%0a')</_additionalProjectReferencesString> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<_additionalProjectSourceFiles Include="%(TestConsoleApps.AdditionalSourceFiles)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<_switchesAsItems Include="%(TestConsoleApps.DisabledFeatureSwitches)" Value="false" /> | ||
<_switchesAsItems Include="%(TestConsoleApps.EnabledFeatureSwitches)" Value="true" /> | ||
|
||
<_propertiesAsItems Include="%(TestConsoleApps.DisabledProperties)" Value="false" /> | ||
<_propertiesAsItems Include="%(TestConsoleApps.EnabledProperties)" Value="true" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<_runtimeHostConfigurationOptionsString>@(_switchesAsItems->'<RuntimeHostConfigurationOption Include="%(Identity)" Value="%(Value)" Trim="true" />', '%0a ')</_runtimeHostConfigurationOptionsString> | ||
<_additionalPropertiesString>@(_propertiesAsItems->'<%(Identity)>%(Value)</%(Identity)>', '%0a ')</_additionalPropertiesString> | ||
</PropertyGroup> | ||
|
||
<MakeDir Directories="$(_projectDir)" /> | ||
<WriteLinesToFile File="$(_projectFile)" | ||
Lines="$([System.IO.File]::ReadAllText('$(ProjectTemplate)') | ||
.Replace('{TargetFramework}', '%(TestConsoleApps.TargetFramework)') | ||
.Replace('{RuntimeIdentifier}','%(TestConsoleApps.TestRuntimeIdentifier)') | ||
.Replace('{PublishAot}','$(IsNativeAotTestProject)') | ||
.Replace('{MicrosoftNETCoreAppRuntimeVersion}','$(MicrosoftNETCoreAppRuntimeVersion)') | ||
.Replace('{RepoRoot}', '$(RepoRoot)') | ||
.Replace('{ExtraTrimmerArgs}', '%(TestConsoleApps.ExtraTrimmerArgs)') | ||
.Replace('{AdditionalProperties}', '$(_additionalPropertiesString)') | ||
.Replace('{RuntimeHostConfigurationOptions}', '$(_runtimeHostConfigurationOptionsString)') | ||
.Replace('{AdditionalProjectReferences}', '$(_additionalProjectReferencesString)') | ||
)" | ||
Overwrite="true" /> | ||
<Copy SourceFiles="$(_projectSourceFile); | ||
@(_additionalProjectSourceFiles)" | ||
DestinationFolder="$(_projectDir)" /> | ||
<Message Text="Generated $(_projectFile)" /> | ||
</Target> | ||
|
||
<Target Name="PublishTrimmedProjects" | ||
DependsOnTargets="GenerateProjects"> | ||
|
||
<MSBuild Projects="@(TestConsoleApps)" | ||
Targets="Restore" | ||
Condition="'$(SkipTrimmingProjectsRestore)' != 'true'" | ||
Properties="MSBuildRestoreSessionId=$([System.Guid]::NewGuid());Configuration=$(Configuration)" /> | ||
|
||
<MSBuild Projects="@(TestConsoleApps)" | ||
Targets="Publish" | ||
Properties="Configuration=$(Configuration);BuildProjectReferences=false" /> | ||
</Target> | ||
|
||
<Target Name="ExecuteApplications" | ||
DependsOnTargets="PublishTrimmedProjects" | ||
Inputs="%(TestConsoleApps.Identity)" | ||
Outputs="_unused" | ||
Condition="'$(ArchiveTests)' != 'true'"> | ||
|
||
<Message Importance="High" Text="[Trimming Tests] Running test: %(TestConsoleApps.ProjectCompileItems) ..." /> | ||
<Exec IgnoreExitCode="true" Command="%(TestConsoleApps.TestCommand)" StandardOutputImportance="Low" WorkingDirectory="%(TestConsoleApps.TestExecutionDirectory)"> | ||
<Output TaskParameter="ExitCode" PropertyName="ExecutionExitCode" /> | ||
</Exec> | ||
|
||
<Error Condition="'$(ExecutionExitCode)' != '100'" Text="Error: [Failed Test]: %(TestConsoleApps.ProjectCompileItems). The Command %(TestConsoleApps.TestCommand) return a non-success exit code." ContinueOnError="ErrorAndContinue" /> | ||
</Target> | ||
|
||
<Target Name="Test" DependsOnTargets="ExecuteApplications" /> | ||
<Target Name="VSTest" DependsOnTargets="Test" /> | ||
|
||
<!-- define Restore/Build to do nothing, for this project only Test does the testing --> | ||
<Target Name="Restore" /> | ||
<Target Name="Build" /> | ||
</Project> |
7 changes: 7 additions & 0 deletions
7
...Builder/test/Microsoft.AspNetCore.NativeAotTests/Microsoft.AspNetCore.NativeAotTests.proj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<TestConsoleAppSourceFiles Include="UseStartupThrowsForStructContainersTest.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.