summaryrefslogtreecommitdiff
path: root/tests/src/dir.targets
blob: 6e9a2e76b994f14c00fa7d1e7333ea8cb25b2999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Default priority building values. -->
  <PropertyGroup>
    <CLRTestKind Condition="'$(CLRTestKind)' == '' and '$(OutputType)' == 'Library'">SharedLibrary</CLRTestKind>
    <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
  and construct a run-batch-script for them. -->
  <Choose>
    <When Condition=" '$(CLRTestKind)'=='SharedLibrary'">
      <PropertyGroup>
        <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
        <_CLRTestNeedsToRun>false</_CLRTestNeedsToRun>
        <GenerateRunScript>false</GenerateRunScript>
        <_CLRTestBuildsExecutable>false</_CLRTestBuildsExecutable>
      </PropertyGroup>
    </When>
    <When Condition=" '$(CLRTestKind)'=='BuildAndRun' ">
      <PropertyGroup>
        <GenerateRunScript>true</GenerateRunScript>
        <_CLRTestNeedsToRun>true</_CLRTestNeedsToRun>
        <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
        <_CLRTestBuildsExecutable>true</_CLRTestBuildsExecutable>
      </PropertyGroup>
    </When>
    <When Condition=" '$(CLRTestKind)'=='BuildOnly'">
      <PropertyGroup>
        <_CLRTestNeedsToRun>false</_CLRTestNeedsToRun>
        <GenerateRunScript>false</GenerateRunScript>
        <_CLRTestCompilesSource>true</_CLRTestCompilesSource>
        <_CLRTestBuildsExecutable>true</_CLRTestBuildsExecutable>
      </PropertyGroup>
    </When>
    <When Condition=" '$(CLRTestKind)'=='RunOnly' ">
      <PropertyGroup>
        <GenerateRunScript>true</GenerateRunScript>
        <SkipSigning>true</SkipSigning>
        <_CLRTestBuildsExecutable>false</_CLRTestBuildsExecutable>
        <_CLRTestNeedsToRun>true</_CLRTestNeedsToRun>
        <_CLRTestCompilesSource>false</_CLRTestCompilesSource>
      </PropertyGroup>
    </When>
  </Choose>
  
  <PropertyGroup> 
    <_CLRTestNeedsProjectToRun>false</_CLRTestNeedsProjectToRun>
    <_CLRTestNeedsProjectToRun Condition=" '$(_CLRTestNeedsToRun)' and '!$(_CLRTestBuildsExecutable)' ">true</_CLRTestNeedsProjectToRun>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Since bug in Roslyn for Linux empty DebugType property leads to build failure. See issue Roslyn@20343 -->
    <DebugType Condition=" '$(DebugType)' == '' and '$(RunningOnUnix)' == 'true' ">None</DebugType>
  </PropertyGroup>

  <!--
  If it needs ProjectToRun, turn the project into a ProjectReference so it gets built
  -->
  <ItemGroup Condition=" $(_CLRTestNeedsProjectToRun) ">
    <ProjectReference Include="$(CLRTestProjectToRun)">
      <Private>false</Private>
    </ProjectReference>
  </ItemGroup>
        
  <PropertyGroup>
    <ErrorIfBuildToolsRestoredFromIndividualProject Condition="!Exists('$(ToolsDir)')">true</ErrorIfBuildToolsRestoredFromIndividualProject>
  </PropertyGroup>
  
  <Import Project="..\dir.targets" />

  <!-- 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>
    
  <!-- 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'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="('$(UsingMicrosoftNETSdk)' != 'true') And ('$(CLRTestKind)'!='RunOnly') And $(_CLRTestCompilesSource) And ('$(_WillCLRTestProjectBuild)' == 'true')"/>


  <Import Project="..\override.targets" Condition="Exists('..\override.targets')"/>

  <!-- We enable auto-unification of assembly references after importing the common targets.  Binding redirects are not needed
       for coreclr since it auto-unifies, so the warnings we get without this setting are just noise -->
  <PropertyGroup>
    <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
  </PropertyGroup>

  <!-- Project language -->
  <!-- TODO: This might just be the Language property -->
  <PropertyGroup Condition="'$(ProjectLanguage)' == ''">
    <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.ilproj' OR '$(Language)' == 'IL'">IL</ProjectLanguage>
    <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.csproj' OR '$(Language)' == 'C#' OR '$(ProjectLanguage)'==''">CSharp</ProjectLanguage>

    <SkipImportILTargets Condition="'$(CLRTestPriority)' &gt; '$(CLRTestPriorityToBuild)'">true</SkipImportILTargets>
  </PropertyGroup>

  <Import Project="CLRTest.Execute.targets" />
  <Target Name="CreateExecuteScript" 
          AfterTargets="Build"
          Condition="'$(GenerateRunScript)' != 'false' And ('$(_WillCLRTestProjectBuild)' == 'true')"
          DependsOnTargets="GenerateExecutionScriptsInternal" />

  <Target Name="CopyNativeProjectBinaries">
     <ItemGroup>
        <NativeProjectBinaries Condition="'$(RunningOnUnix)' != 'true'" Include="$(NativeProjectOutputFolder)\**\*.*" />

        <!-- ############################################################### -->
        <!-- The following is unix only. It is required because the unix test-->
        <!-- build, unlike the windows test build, do not place the binaries -->
        <!-- built into a separate Debug/Checked/Release directory. Therefore-->
        <!-- we must filter the folder to only include dynamic libraries,    -->
        <!-- static libraries and executables.                               -->
        <!--                                                                 -->
        <!-- Please take care when modifying the following lines of code.    -->
        <!-- At a minimum to test any changes to the below, please run a     -->
        <!-- pri1 test build.                                                -->
        <!-- ############################################################### -->

        <!-- Include everything and then filter. -->
        <NativeProjectBinariesMatched Condition="'$(RunningOnUnix)' == 'true'" Include="$(NativeProjectOutputFolder)\**\*.*" />

        <!-- Filter executables on unix -->
        <NativeProjectBinariesExeFilter Condition="'$(RunningOnUnix)' == 'true' and $([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `(.*\/)([^.]+)$`))" Include="@(NativeProjectBinariesMatched)" />
        <!-- Filter out the *Make* files -->
        <NativeProjectBinariesExeFilterRemovedMakeFile Condition="'$(RunningOnUnix)' == 'true' and !$([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `.*Makefile.*`))" Include="@(NativeProjectBinariesExeFilter)" />

        <!-- Filter out the CMakeFiles files -->
        <NativeProjectBinariesExeFilterRemovedCMakeFile Condition="'$(RunningOnUnix)' == 'true' and !$([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `.*CMakeFiles.*`))" Include="@(NativeProjectBinariesExeFilterRemovedMakeFile)" />

        <!-- Filter .dylib files on OSX -->
        <NativeProjectBinariesDyLibFilter Condition="'$(__BuildOS)' == 'OSX' and $([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `(.*\/).*\.dylib`))" Include="@(NativeProjectBinariesMatched)" />

        <!-- Filter .so files on Linux -->
        <NativeProjectBinariesDyLibFilter Condition="'$(__BuildOS)' == 'Linux' and $([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `(.*\/).*\.so`))" Include="@(NativeProjectBinariesMatched)" />

        <!-- Filter static lib files on Unix -->
        <NativeProjectBinariesStaticLibFilter Condition="'$(RunningOnUnix)' == 'true' and $([System.Text.RegularExpressions.Regex]::IsMatch(['%(Identity)', `(.*\/).*\.a`))" Include="@(NativeProjectBinariesMatched)" />

        <!-- Merge the filtered lists -->
        <NativeProjectBinaries Condition="'$(RunningOnUnix)' == 'true'" Include="@(NativeProjectBinariesExeFilterRemovedCMakeFile)" />
        <NativeProjectBinaries Condition="'$(RunningOnUnix)' == 'true'" Include="@(NativeProjectBinariesDyLibFilter)" />
        <NativeProjectBinaries Condition="'$(RunningOnUnix)' == 'true'" Include="@(NativeProjectBinariesStaticLibFilter)" />

     </ItemGroup>

     <Error  Text="The native project files are missing in $(NativeProjectOutputFolder) please run build from the root of the repo at least once"
             Condition="'@(NativeProjectBinaries)' == ''" />

     <Copy
        SourceFiles="@(NativeProjectBinaries)"
        DestinationFiles="@(NativeProjectBinaries -> '$(OutDir)%(Filename)%(Extension)')"
        SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
        OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
        Retries="$(CopyRetryCount)"
        RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
        UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)">
        <Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
     </Copy>
  </Target>

  <Target Name="ResolveCmakeNativeProjectReference"
          Condition="'@(ProjectReference)' != ''"
          BeforeTargets="BeforeResolveReferences;BeforeClean" >
     <ItemGroup>
        <NativeProjectReference Include="%(ProjectReference.Identity)" Condition="$([System.String]::Copy(%(ProjectReference.FileName)).ToUpper()) == 'CMAKELISTS'" />
        <ProjectReference Remove="%(NativeProjectReference.Identity)" />
        <NativeProjectReferenceNormalized Include="@(NativeProjectReference -> '%(FullPath)')" />
     </ItemGroup>
  </Target>

  <Target Name="ConsolidateNativeProjectReference"
          Condition="'@(NativeProjectReferenceNormalized)' != ''"
          BeforeTargets="Build" >
     <ItemGroup>
        <NativeProjectOutputFoldersToCopy Include="$([System.String]::Copy('%(NativeProjectReferenceNormalized.RelativeDir)').Replace($(SourceDir),$(__NativeTestIntermediatesDir)\src\))" Condition="'$(RunningOnUnix)' == 'true'" />
        <NativeProjectOutputFoldersToCopy Include="$([System.String]::Copy('%(NativeProjectReferenceNormalized.RelativeDir)').Replace($(SourceDir),$(__NativeTestIntermediatesDir)\src\))$(Configuration)\" Condition="'$(RunningOnUnix)' != 'true'" />
     </ItemGroup>

    <Message Text= "Full native project references are :%(NativeProjectReferenceNormalized.Identity)" />
    <Message Text= "Native binaries will be copied from :%(NativeProjectOutputFoldersToCopy.Identity)" />
   <MSBuild Projects="$(MSBuildProjectFile)" Targets="CopyNativeProjectBinaries" Properties="NativeProjectOutputFolder=%(NativeProjectOutputFoldersToCopy.Identity)" Condition="'@(NativeProjectReference)' != ''" />

  </Target>

  <PropertyGroup>
     <PrepareForRunDependsOn>$(PrepareForRunDependsOn);ResetReferenceCopyLocalPaths</PrepareForRunDependsOn>
  </PropertyGroup>

  <Target Name="ResetReferenceCopyLocalPaths"
          Condition="'@(ReferenceCopyLocalPaths)' != ''"
          BeforeTargets="_CopyFilesMarkedCopyLocal">
    <ItemGroup>
       <ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.CopyLocal)' != 'true'"/>
    </ItemGroup>
  </Target>

  <Target Name="UpdateReferenceItems"
          BeforeTargets="BeforeResolveReferences"
  >
    <ItemGroup>
      <Reference Include="$(TargetingPackPath)/*.dll" >
        <Private>false</Private>
      </Reference>
    </ItemGroup>

  </Target>

  <Target Name="AfterBuild">
     <Copy SourceFiles="$(AssemblyName).reflect.xml"
           DestinationFolder="$(OutputPath)"
       Condition="Exists('$(AssemblyName).reflect.xml')"/>
  </Target>

  <PropertyGroup>
    <ProjectAssetsFile>$(SourceDir)Common\test_dependencies\obj-$(TargetRid)\project.assets.json</ProjectAssetsFile>
  </PropertyGroup>

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

  <Import Project="../../clr.featuredefines.props" />

</Project>