6e9a2e76b994f14c00fa7d1e7333ea8cb25b2999
[platform/upstream/coreclr.git] / tests / src / dir.targets
1 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2   <!-- Default priority building values. -->
3   <PropertyGroup>
4     <CLRTestKind Condition="'$(CLRTestKind)' == '' and '$(OutputType)' == 'Library'">SharedLibrary</CLRTestKind>
5     <CLRTestKind Condition="'$(CLRTestKind)' == ''">BuildAndRun</CLRTestKind>
6     <CLRTestPriority Condition="'$(CLRTestPriority)' == ''">0</CLRTestPriority>
7   </PropertyGroup>
8   
9   <PropertyGroup Condition="'$(UsingMicrosoftNETSdk)' == 'true'">
10     <!-- 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 -->
11     <TargetExt Condition="'$(OutputType)' == 'Exe' and '$(TargetExt)' == '.dll'">.exe</TargetExt>
12   </PropertyGroup>
13
14   <!-- All CLRTests need to be of a certain "kind". These kinds are enumerated below.
15   By default all tests are BuildAndRun. This means that the build system will Build them
16   and construct a run-batch-script for them. -->
17   <Choose>
18     <When Condition=" '$(CLRTestKind)'=='SharedLibrary'">
19       <PropertyGroup>
20         <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
21         <_CLRTestNeedsToRun>false</_CLRTestNeedsToRun>
22         <GenerateRunScript>false</GenerateRunScript>
23         <_CLRTestBuildsExecutable>false</_CLRTestBuildsExecutable>
24       </PropertyGroup>
25     </When>
26     <When Condition=" '$(CLRTestKind)'=='BuildAndRun' ">
27       <PropertyGroup>
28         <GenerateRunScript>true</GenerateRunScript>
29         <_CLRTestNeedsToRun>true</_CLRTestNeedsToRun>
30         <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
31         <_CLRTestBuildsExecutable>true</_CLRTestBuildsExecutable>
32       </PropertyGroup>
33     </When>
34     <When Condition=" '$(CLRTestKind)'=='BuildOnly'">
35       <PropertyGroup>
36         <_CLRTestNeedsToRun>false</_CLRTestNeedsToRun>
37         <GenerateRunScript>false</GenerateRunScript>
38         <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
39         <_CLRTestBuildsExecutable>true</_CLRTestBuildsExecutable>
40       </PropertyGroup>
41     </When>
42     <When Condition=" '$(CLRTestKind)'=='RunOnly' ">
43       <PropertyGroup>
44         <GenerateRunScript>true</GenerateRunScript>
45         <SkipSigning>true</SkipSigning>
46         <_CLRTestBuildsExecutable>false</_CLRTestBuildsExecutable>
47         <_CLRTestNeedsToRun>true</_CLRTestNeedsToRun>
48         <_CLRTestCompilesSource>false</_CLRTestCompilesSource>
49       </PropertyGroup>
50     </When>
51   </Choose>
52   
53   <PropertyGroup> 
54     <_CLRTestNeedsProjectToRun>false</_CLRTestNeedsProjectToRun>
55     <_CLRTestNeedsProjectToRun Condition=" '$(_CLRTestNeedsToRun)' and '!$(_CLRTestBuildsExecutable)' ">true</_CLRTestNeedsProjectToRun>
56   </PropertyGroup>
57
58   <PropertyGroup>
59     <!-- Since bug in Roslyn for Linux empty DebugType property leads to build failure. See issue Roslyn@20343 -->
60     <DebugType Condition=" '$(DebugType)' == '' and '$(RunningOnUnix)' == 'true' ">None</DebugType>
61   </PropertyGroup>
62
63   <!--
64   If it needs ProjectToRun, turn the project into a ProjectReference so it gets built
65   -->
66   <ItemGroup Condition=" $(_CLRTestNeedsProjectToRun) ">
67     <ProjectReference Include="$(CLRTestProjectToRun)">
68       <Private>false</Private>
69     </ProjectReference>
70   </ItemGroup>
71         
72   <PropertyGroup>
73     <ErrorIfBuildToolsRestoredFromIndividualProject Condition="!Exists('$(ToolsDir)')">true</ErrorIfBuildToolsRestoredFromIndividualProject>
74   </PropertyGroup>
75   
76   <Import Project="..\dir.targets" />
77
78   <!-- Determine if this project should be built or not -->
79   <PropertyGroup>
80     <BuildAllProjects Condition="'$(BuildAllProjects)' == ''">false</BuildAllProjects>
81     <_WillCLRTestProjectBuild Condition="'$(_WillCLRTestProjectBuild)' == ''">false</_WillCLRTestProjectBuild>
82     <_WillCLRTestProjectBuild Condition="'$(BuildAllProjects)' != 'true'">true</_WillCLRTestProjectBuild>
83     <_WillCLRTestProjectBuild Condition="'$(DisableProjectBuild)' != 'true' And '$(BuildAllProjects)' == 'true' And '$(CLRTestPriority)' &lt;= '$(CLRTestPriorityToBuild)'">true</_WillCLRTestProjectBuild>
84   </PropertyGroup>
85     
86   <!-- if we have determined that there is nothing to build, overwrite the build targets so that nothing happens -->
87   <Import Project="nobuild.targets" Condition="'$(_WillCLRTestProjectBuild)' == 'false'" />
88  
89   <!-- RunOnly projects have a special build for dependent projects -->
90   <Import Project="runonly.targets" Condition="'$(CLRTestKind)' == 'RunOnly'" />
91   
92   <!-- 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
93   a test with a higher priority. -->
94   <Import Project="$(ToolsDir)Build.Common.targets" Condition="('$(UsingMicrosoftNETSdk)' != 'true') And ('$(CLRTestKind)'!='RunOnly') And $(_CLRTestCompilesSource) And ('$(_WillCLRTestProjectBuild)' == 'true')"/>
95
96
97   <Import Project="..\override.targets" Condition="Exists('..\override.targets')"/>
98
99   <!-- We enable auto-unification of assembly references after importing the common targets.  Binding redirects are not needed
100        for coreclr since it auto-unifies, so the warnings we get without this setting are just noise -->
101   <PropertyGroup>
102     <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
103   </PropertyGroup>
104
105   <!-- Project language -->
106   <!-- TODO: This might just be the Language property -->
107   <PropertyGroup Condition="'$(ProjectLanguage)' == ''">
108     <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.ilproj' OR '$(Language)' == 'IL'">IL</ProjectLanguage>
109     <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.csproj' OR '$(Language)' == 'C#' OR '$(ProjectLanguage)'==''">CSharp</ProjectLanguage>
110
111     <SkipImportILTargets Condition="'$(CLRTestPriority)' &gt; '$(CLRTestPriorityToBuild)'">true</SkipImportILTargets>
112   </PropertyGroup>
113
114   <Import Project="CLRTest.Execute.targets" />
115   <Target Name="CreateExecuteScript" 
116           AfterTargets="Build"
117           Condition="'$(GenerateRunScript)' != 'false' And ('$(_WillCLRTestProjectBuild)' == 'true')"
118           DependsOnTargets="GenerateExecutionScriptsInternal" />
119
120   <Target Name="CopyNativeProjectBinaries">
121      <ItemGroup>
122         <NativeProjectBinaries Condition="'$(RunningOnUnix)' != 'true'" Include="$(NativeProjectOutputFolder)\**\*.*" />
123
124         <!-- ############################################################### -->
125         <!-- The following is unix only. It is required because the unix test-->
126         <!-- build, unlike the windows test build, do not place the binaries -->
127         <!-- built into a separate Debug/Checked/Release directory. Therefore-->
128         <!-- we must filter the folder to only include dynamic libraries,    -->
129         <!-- static libraries and executables.                               -->
130         <!--                                                                 -->
131         <!-- Please take care when modifying the following lines of code.    -->
132         <!-- At a minimum to test any changes to the below, please run a     -->
133         <!-- pri1 test build.                                                -->
134         <!-- ############################################################### -->
135
136         <!-- Include everything and then filter. -->
137         <NativeProjectBinariesMatched Condition="'$(RunningOnUnix)' == 'true'" Include="$(NativeProjectOutputFolder)\**\*.*" />
138
139         <!-- Filter executables on unix -->
140         <NativeProjectBinariesExeFilter Condition="'$(RunningOnUnix)' == 'true' and $([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `(.*\/)([^.]+)$`))" Include="@(NativeProjectBinariesMatched)" />
141         <!-- Filter out the *Make* files -->
142         <NativeProjectBinariesExeFilterRemovedMakeFile Condition="'$(RunningOnUnix)' == 'true' and !$([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `.*Makefile.*`))" Include="@(NativeProjectBinariesExeFilter)" />
143
144         <!-- Filter out the CMakeFiles files -->
145         <NativeProjectBinariesExeFilterRemovedCMakeFile Condition="'$(RunningOnUnix)' == 'true' and !$([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `.*CMakeFiles.*`))" Include="@(NativeProjectBinariesExeFilterRemovedMakeFile)" />
146
147         <!-- Filter .dylib files on OSX -->
148         <NativeProjectBinariesDyLibFilter Condition="'$(__BuildOS)' == 'OSX' and $([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `(.*\/).*\.dylib`))" Include="@(NativeProjectBinariesMatched)" />
149
150         <!-- Filter .so files on Linux -->
151         <NativeProjectBinariesDyLibFilter Condition="'$(__BuildOS)' == 'Linux' and $([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `(.*\/).*\.so`))" Include="@(NativeProjectBinariesMatched)" />
152
153         <!-- Filter static lib files on Unix -->
154         <NativeProjectBinariesStaticLibFilter Condition="'$(RunningOnUnix)' == 'true' and $([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `(.*\/).*\.a`))" Include="@(NativeProjectBinariesMatched)" />
155
156         <!-- Merge the filtered lists -->
157         <NativeProjectBinaries Condition="'$(RunningOnUnix)' == 'true'" Include="@(NativeProjectBinariesExeFilterRemovedCMakeFile)" />
158         <NativeProjectBinaries Condition="'$(RunningOnUnix)' == 'true'" Include="@(NativeProjectBinariesDyLibFilter)" />
159         <NativeProjectBinaries Condition="'$(RunningOnUnix)' == 'true'" Include="@(NativeProjectBinariesStaticLibFilter)" />
160
161      </ItemGroup>
162
163      <Error  Text="The native project files are missing in $(NativeProjectOutputFolder) please run build from the root of the repo at least once"
164              Condition="'@(NativeProjectBinaries)' == ''" />
165
166      <Copy
167         SourceFiles="@(NativeProjectBinaries)"
168         DestinationFiles="@(NativeProjectBinaries -> '$(OutDir)%(Filename)%(Extension)')"
169         SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
170         OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
171         Retries="$(CopyRetryCount)"
172         RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
173         UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)">
174         <Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
175      </Copy>
176   </Target>
177
178   <Target Name="ResolveCmakeNativeProjectReference"
179           Condition="'@(ProjectReference)' != ''"
180           BeforeTargets="BeforeResolveReferences;BeforeClean" >
181      <ItemGroup>
182         <NativeProjectReference Include="%(ProjectReference.Identity)" Condition="$([System.String]::Copy(%(ProjectReference.FileName)).ToUpper()) == 'CMAKELISTS'" />
183         <ProjectReference Remove="%(NativeProjectReference.Identity)" />
184         <NativeProjectReferenceNormalized Include="@(NativeProjectReference -> '%(FullPath)')" />
185      </ItemGroup>
186   </Target>
187
188   <Target Name="ConsolidateNativeProjectReference"
189           Condition="'@(NativeProjectReferenceNormalized)' != ''"
190           BeforeTargets="Build" >
191      <ItemGroup>
192         <NativeProjectOutputFoldersToCopy Include="$([System.String]::Copy('%(NativeProjectReferenceNormalized.RelativeDir)').Replace($(SourceDir),$(__NativeTestIntermediatesDir)\src\))" Condition="'$(RunningOnUnix)' == 'true'" />
193         <NativeProjectOutputFoldersToCopy Include="$([System.String]::Copy('%(NativeProjectReferenceNormalized.RelativeDir)').Replace($(SourceDir),$(__NativeTestIntermediatesDir)\src\))$(Configuration)\" Condition="'$(RunningOnUnix)' != 'true'" />
194      </ItemGroup>
195
196     <Message Text= "Full native project references are :%(NativeProjectReferenceNormalized.Identity)" />
197     <Message Text= "Native binaries will be copied from :%(NativeProjectOutputFoldersToCopy.Identity)" />
198    <MSBuild Projects="$(MSBuildProjectFile)" Targets="CopyNativeProjectBinaries" Properties="NativeProjectOutputFolder=%(NativeProjectOutputFoldersToCopy.Identity)" Condition="'@(NativeProjectReference)' != ''" />
199
200   </Target>
201
202   <PropertyGroup>
203      <PrepareForRunDependsOn>$(PrepareForRunDependsOn);ResetReferenceCopyLocalPaths</PrepareForRunDependsOn>
204   </PropertyGroup>
205
206   <Target Name="ResetReferenceCopyLocalPaths"
207           Condition="'@(ReferenceCopyLocalPaths)' != ''"
208           BeforeTargets="_CopyFilesMarkedCopyLocal">
209     <ItemGroup>
210        <ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.CopyLocal)' != 'true'"/>
211     </ItemGroup>
212   </Target>
213
214   <Target Name="UpdateReferenceItems"
215           BeforeTargets="BeforeResolveReferences"
216   >
217     <ItemGroup>
218       <Reference Include="$(TargetingPackPath)/*.dll" >
219         <Private>false</Private>
220       </Reference>
221     </ItemGroup>
222
223   </Target>
224
225   <Target Name="AfterBuild">
226      <Copy SourceFiles="$(AssemblyName).reflect.xml"
227            DestinationFolder="$(OutputPath)"
228        Condition="Exists('$(AssemblyName).reflect.xml')"/>
229   </Target>
230
231   <PropertyGroup>
232     <ProjectAssetsFile>$(SourceDir)Common\test_dependencies\obj-$(TargetRid)\project.assets.json</ProjectAssetsFile>
233   </PropertyGroup>
234
235   <PropertyGroup Condition="'$(ReferenceSystemPrivateCoreLib)' == 'true' and '$(UsingMicrosoftNETSdk)' != 'true'">
236     <ProjectAssetsFile></ProjectAssetsFile>
237   </PropertyGroup>
238
239   <Import Project="../../clr.featuredefines.props" />
240
241 </Project>