Skip to content

Commit

Permalink
Sdk test projects (dotnet#19044)
Browse files Browse the repository at this point in the history
Change the associated targets and props files in the test directory to allow the test csproj's to be built as SDK style projects alongside traditional style projects.


Remove CodeTaskFactory:
- Allows the projects to be built using the core version of msbuild/dotnet build
- Converted to using msbuild property expansion instead

Add directory.build.{props,targets}:
- Currently we just import the dirs.props and targets, but means SDK style projects don't need to explicitly include these files
- We probably want to move all projects over to using these in the future, but this keeps the changes smaller for now

Specific code for SDK projects:
- There are a several changes required to build an SDK project. This change guards them behind conditionals so that only the new style projects see them. When we get to the point that there are only new projects, we can remove the guards (probably at the same time as ditching the dir.props)

Reordered build targets:
- Because SDK projects implicitly import the build targets, we can no longer re-define the build targets unconditionally knowing they will likely be overwritten.
- Instead we move the overwritten targets to separate files, and include these conditionally based on properties. In this way there is always a build defined for SDK projects, which can then be overwritten to do nothing as needed.
  • Loading branch information
chsienki authored Jul 25, 2018
1 parent 2b92e13 commit eddc1a6
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 62 deletions.
2 changes: 1 addition & 1 deletion build-test.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ set __msbuildWrn=/flp1:WarningsOnly;LogFile="%__BuildWrn%"
set __msbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"

REM Build wrappers using the local SDK's msbuild. As we move to arcade, the other builds should be moved away from run.exe as well.
call %__DotnetHost% msbuild %__ProjectDir%\tests\runtest.proj /p:BuildWrappers=true !__msbuildLog! !__msbuildWrn! !__msbuildErr! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__BuildAgainstPackagesMsbuildArg% %__unprocessedBuildArgs%
call %__DotnetHost% msbuild %__ProjectDir%\tests\runtest.proj /p:RestoreAdditionalProjectSources=https://dotnet.myget.org/F/dotnet-core/ /p:BuildWrappers=true !__msbuildLog! !__msbuildWrn! !__msbuildErr! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__BuildAgainstPackagesMsbuildArg% %__unprocessedBuildArgs%
if errorlevel 1 (
echo Xunit Wrapper build failed
exit /b 1
Expand Down
2 changes: 2 additions & 0 deletions tests/dir.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<OsEnvironment Condition="'$(OsEnvironment)'==''">$(OS)</OsEnvironment>
</PropertyGroup>

<Import Project="dir.sdkbuild.props" Condition="'$(UsingMicrosoftNETSdk)' == 'true'" />

<!-- Build Tools Versions -->
<PropertyGroup>
<RoslynVersion>1.0.0-rc3-20150510-01</RoslynVersion>
Expand Down
6 changes: 5 additions & 1 deletion tests/dir.sdkbuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
and buildtools projects should go in dir.common.props. -->

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RuntimeFrameworkVersion>$(MicrosoftNETCoreRuntimeCoreCLRPackageVersion)</RuntimeFrameworkVersion>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>

<!-- Force the CLI to allow us to target higher netcoreapp than it may know about -->
<NETCoreAppMaximumVersion>99.0</NETCoreAppMaximumVersion>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions tests/override.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
</ItemGroup>
</Target>

<!-- Remove package references when referencing System.Private.CoreLib from SDK style project -->
<Target Name="CleanResolvedCompileFileDefinitions" AfterTargets="ResolvePackageAssets" Condition="'$(ReferenceSystemPrivateCoreLib)' == 'true' and '$(UsingMicrosoftNETSdk)' == 'true'" >
<ItemGroup>
<ResolvedCompileFileDefinitions Remove="@(ResolvedCompileFileDefinitions)" />
</ItemGroup>
</Target>

<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<!--
Allow this project to setup the default target frameworks. Note this depends on the targeting packs that VS
Expand Down
3 changes: 2 additions & 1 deletion tests/runtest.proj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ $(_XunitEpilog)
<PropertyGroup>
<OutputPath>$(XUnitTestBinBase)\$(CategoryWithSlash)</OutputPath>
</PropertyGroup>
<RuntimeFrameworkVersion>$(MicrosoftNETCoreRuntimeCoreCLRPackageVersion)</RuntimeFrameworkVersion>
</PropertyGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
Expand Down
7 changes: 1 addition & 6 deletions tests/src/CLRTest.Execute.Batch.targets
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,6 @@ set CLRTestExitCode=!ERRORLEVEL!
<!-- Raise an error if any value in _RequiredProperties is missing -->
<Error Condition=" '%(_RequiredProperties.Value)'=='' "
Text="Missing required test property [%(_RequiredProperties.Identity)]. Something isn't plumbed through correctly. Contact $(_CLRTestBuildSystemOwner)." />
<!-- TODO: this is weird. Consider eliminating it. -->
<GenerateParamList ArgumentItems="@(BatchCLRTestExecutionScriptArgument)">
<Output TaskParameter="ParamList" PropertyName="_CLRTestParamList"/>
</GenerateParamList>

<PropertyGroup>
<!--
This generates the script portion to parse all of the command line arguments.
Expand Down Expand Up @@ -339,7 +334,7 @@ goto ArgsDone
:USAGE
ECHO.Usage
ECHO %0 $(_CLRTestParamList)
ECHO %0 @(BatchCLRTestExecutionScriptArgument -> '[-%(Identity) %(ParamName)]', ' ')
ECHO.
ECHO - OPTIONS -
@(BatchCLRTestExecutionScriptArgument -> 'ECHO -%(Identity) %(ParamName)
Expand Down
38 changes: 0 additions & 38 deletions tests/src/CLRTest.Execute.targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,6 @@ This file contains the logic for providing Execution Script generation.
<HasParam>false</HasParam>
</CLRTestExecutionScriptArgument>
</ItemDefinitionGroup>

<!--
TASK: GenerateParamList
This task takes a list of CLRTestExecutionScriptArgument items and
returns a string fit for the usage help message.
example:
[-arg1 param1] [-arg2] [-arg3 param3]
-->
<UsingTask
TaskName="GenerateParamList"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<ArgumentItems ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true"/>
<ParamList ParameterType="System.String" Output="true"/>
</ParameterGroup>
<Task>
<Reference Include="System.Core"/>
<Using Namespace="System"/>
<Using Namespace="System.Linq"/>
<Code Type="Fragment" Language="cs"><![CDATA[
Func<string, bool> parseBool = s =>
{
bool value;
var success = bool.TryParse(s, out value);
if (success)
return value;
return false;
};
var items = ArgumentItems.Select(i => new { Item=i, HasParam=parseBool(i.GetMetadata("HasParam"))});
var noArg = items.Where(i => !i.HasParam).Select(i => new { Identity=i.Item.ItemSpec});
var haveArg = items.Where(i => i.HasParam).Select(i => new { Identity=i.Item.ItemSpec, Name=i.Item.GetMetadata("ParamName")});
ParamList = haveArg.Aggregate("", (s,i) => string.Format("{0} [-{1} {2}]", s, i.Identity, i.Name)) +
noArg.Aggregate("", (s,i) => string.Format("{0} [-{1}]", s, i.Identity));
]]>
</Code>
</Task>
</UsingTask>

<!--
*******************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project>

<Import Project="$([MSBuild]::GetPathOfFileAbove('dependencies.props', '$(MSBuildThisFileDirectory)../'))" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('dir.sdkbuild.props', '$(MSBuildThisFileDirectory)../'))" />

<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
Expand Down
8 changes: 8 additions & 0 deletions tests/src/Common/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<!--
Common files don't take part in the root tests\src\Directory.Build.props
This file prevents them from including it as it gets included in its place
If they ever need to take part, we can conditionally include them as documented
here https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets
-->
</Project>
8 changes: 8 additions & 0 deletions tests/src/Common/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<!--
Common files don't take part in the root tests\src\Directory.Build.targets
This file prevents them from including it as it gets included in its place
If they ever need to take part, we can conditionally include them as documented
here https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets
-->
</Project>
6 changes: 6 additions & 0 deletions tests/src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<!-- SDK Style projects auto-magically include this file.
We include the dir.props for them here so they partake in the old
style of build without them needing to explicitly include anything -->
<Import Project="dir.props" Condition="'$(UsingMicrosoftNETSdk)' == 'true'" />
</Project>
6 changes: 6 additions & 0 deletions tests/src/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<!-- SDK Style projects auto-magically include this file.
We include the dir.targets for them here so they partake in the old
style of build without them needing to explicitly include anything -->
<Import Project="dir.targets" Condition="'$(UsingMicrosoftNETSdk)' == 'true'" />
</Project>
31 changes: 16 additions & 15 deletions tests/src/dir.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<CLRTestKind Condition="'$(CLRTestKind)' == ''">BuildAndRun</CLRTestKind>
<CLRTestPriority Condition="'$(CLRTestPriority)' == ''">0</CLRTestPriority>
</PropertyGroup>

<PropertyGroup Condition="'$(UsingMicrosoftNETSdk)' == 'true'">
<!-- Many parts of the tests expect the output file to be an exe. We override the extension to match here, but in future we should probably update the infrastructure to look for dlls -->
<TargetExt Condition="'$(OutputType)' == 'Exe' and '$(TargetExt)' == '.dll'">.exe</TargetExt>
</PropertyGroup>

<!-- All CLRTests need to be of a certain "kind". These kinds are enumerated below.
By default all tests are BuildAndRun. This means that the build system will Build them
Expand Down Expand Up @@ -70,27 +75,23 @@

<Import Project="..\dir.targets" />

<Target Name="CreateManifestResourceNames" />
<Target Name="CoreCompile" />

<!-- If we are a run-only, that depends on another project, this is the "Build" we use. I.e. build all dependency projects, absolutely.
-->

<!-- Determine if this project should be built or not -->
<PropertyGroup>
<BuildAllProjects Condition=" '$(BuildAllProjects)' == ''">false</BuildAllProjects>
<_WillCLRTestProjectBuild Condition="'$(_WillCLRTestProjectBuild)' == ''">false</_WillCLRTestProjectBuild>
<_WillCLRTestProjectBuild Condition="'$(BuildAllProjects)' != true">true</_WillCLRTestProjectBuild>
<_WillCLRTestProjectBuild Condition="'$(DisableProjectBuild)' != true And '$(BuildAllProjects)' == true And '$(CLRTestPriority)' &lt;= '$(CLRTestPriorityToBuild)'">true</_WillCLRTestProjectBuild>
</PropertyGroup>

<Target Name="Build" Condition="('$(CLRTestKind)'=='RunOnly') And '$(_WillCLRTestProjectBuild)'">
<MSBuild Projects="@(ProjectReference)" />
<MakeDir Condition="'$(CLRTestKind)' == 'RunOnly'" ContinueOnError="false" Directories="$(OutputPath)" />
</Target>

<!-- if we have determined that there is nothing to build, overwrite the build targets so that nothing happens -->
<Import Project="nobuild.targets" Condition="'$(_WillCLRTestProjectBuild)' == 'false'" />

<!-- RunOnly projects have a special build for dependent projects -->
<Import Project="runonly.targets" Condition="'$(CLRTestKind)' == 'RunOnly'" />

<!-- We will use an imported build here in the instance that we have source that we need to build, and we are the correct priority...OR if we are being asked to build for
<!-- We will use an imported build here in the instance that we're a non-sdk style project, have source that we need to build, and we are the correct priority...OR if we are being asked to build for
a test with a higher priority. -->
<Import Project="$(ToolsDir)Build.Common.targets" Condition="('$(CLRTestKind)'!='RunOnly') And $(_CLRTestCompilesSource) And ('$(_WillCLRTestProjectBuild)')"/>
<Import Project="$(ToolsDir)Build.Common.targets" Condition="('$(UsingMicrosoftNETSdk)' != 'true') And ('$(CLRTestKind)'!='RunOnly') And $(_CLRTestCompilesSource) And ('$(_WillCLRTestProjectBuild)')"/>


<Import Project="..\override.targets" Condition="Exists('..\override.targets')"/>
Expand Down Expand Up @@ -193,8 +194,8 @@
<ProjectAssetsFile>$(SourceDir)Common\test_dependencies\obj\project.assets.json</ProjectAssetsFile>
</PropertyGroup>

<PropertyGroup Condition="'$(ReferenceSystemPrivateCoreLib)' == 'true'">
<ProjectAssetsFile></ProjectAssetsFile >
<PropertyGroup Condition="'$(ReferenceSystemPrivateCoreLib)' == 'true' and '$(UsingMicrosoftNETSdk)' != 'true'">
<ProjectAssetsFile></ProjectAssetsFile>
</PropertyGroup>

</Project>
8 changes: 8 additions & 0 deletions tests/src/nobuild.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="CreateManifestResourceNames" />
<Target Name="Compile" />
<Target Name="CoreCompile" />
<Target Name="Build" />

</Project>
13 changes: 13 additions & 0 deletions tests/src/runonly.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="CreateManifestResourceNames" />
<Target Name="Compile" />
<Target Name="CoreCompile" />

<!-- if this is a RunOnly project that has been scheduled to build, make the output directory and build any dependent projects -->
<Target Name="Build" Condition="('$(CLRTestKind)'=='RunOnly') And '$(_WillCLRTestProjectBuild)'">
<MSBuild Projects="@(ProjectReference)" />
<MakeDir ContinueOnError="false" Directories="$(OutputPath)" />
</Target>

</Project>

0 comments on commit eddc1a6

Please sign in to comment.