summaryrefslogtreecommitdiff
path: root/tests/helixprep.proj
blob: 50d7d9bd76724c3d7f7cca5cc1781db571951c77 (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
<Project ToolsVersion="12.0" DefaultTargets="ArchiveAll" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(ToolsDir)\net46\Microsoft.DotNet.Build.Tasks.dll"
             Condition=" '$(MSBuildRuntimeType)' != 'Core' " />
  <UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(ToolsDir)\Microsoft.DotNet.Build.Tasks.dll"
             Condition=" '$(MSBuildRuntimeType)' == 'Core' " />

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

  <PropertyGroup>
    <DiscoveryDirectory>$(TestWorkingDir)</DiscoveryDirectory>
    <CoreRootName>Core_Root_$(RuntimeID)</CoreRootName>
    <UsePython Condition=" '$(UsePython)' == '' ">false</UsePython>
  </PropertyGroup>

  <ItemGroup>
    <XunitDlls Include="$(DiscoveryDirectory)\**\*.XUnitWrapper.dll" ></XunitDlls>
    <RequiresSigningFilesToDelete Include="$(DiscoveryDirectory)\**\*.requires_signing" />
  </ItemGroup>

  <!-- Build the platform-specific wrapper to run an individual xunit wrapper -->
  <!-- We should remove the generated wrappers once we have transitioned our official build -->

  <Target Name="GenerateWrapperExecutables"
    Inputs="@(XunitDlls)"
    Outputs="$(TestWorkingDir)*\runtests.cmd" >

    <MSBuild Projects="helixprep.proj"
             Properties="BuildPath=%(XunitDlls.RootDir)%(XunitDlls.Directory);ProjectName=%(XunitDlls.Filename)%(XunitDlls.Extension)"
             Targets="GenerateWrapperCmd" />

    <MSBuild Projects="helixprep.proj"
             Properties="BuildPath=%(XunitDlls.RootDir)%(XunitDlls.Directory);ProjectName=%(XunitDlls.Filename)%(XunitDlls.Extension)"
             Targets="GenerateWrapperSh" />
  </Target>

  <!-- Copy the wrapper script to the xunit directory -->
  <Target Name="CopyWrapperScript"
    Inputs="@(XunitDlls)"
    Outputs="$(TestWorkingDir)*\runtest_helix.py" >

    <Copy SourceFiles="$(MSBuildThisFileDirectory)\runtest_helix.py"
          DestinationFolder="%(XunitDlls.RootDir)%(XunitDlls.Directory)" />

  </Target>

  <!-- Zip each top-level test folder to send to Helix -->

  <Target Name="ArchiveTests"
    Inputs="@(XunitDlls)"
    Outputs="$(TestWorkingDir)archive\**" >

    <Copy SourceFiles="$(CORE_ROOT)\xunit.console.dll"
          DestinationFolder="%(XunitDlls.RootDir)%(XunitDlls.Directory)"
          Condition=" '$(UsePython)' == 'false' " />

    <Message Text="Deleting '.requires_signing' files to avoid file name lengths exceeding MAX_PATH" Importance="Low" />
    <Delete Files="@(RequiresSigningFilesToDelete)" />
    <MSBuild Projects="helixprep.proj"
             Properties="BuildPath=%(XunitDlls.RootDir)%(XunitDlls.Directory);ProjectName=%(XunitDlls.Filename);BuildArchiveDir=$(TestWorkingDir)archive\tests\"
             BuildInParallel="true"
             Targets="ArchiveBuild" />
  </Target>

  <!-- Zip Core_Root & Packages payload to send to Helix -->

  <Target Name="ArchiveCoreRoot"
    Inputs="$(CORE_ROOT)"
    Outputs="$(TestWorkingDir)archive\Core_Root" >
    <MSBuild Projects="helixprep.proj"
             Properties="BuildPath=$(CORE_ROOT);ProjectName=$(CoreRootName);BuildArchiveDir=$(TestWorkingDir)archive\Core_Root\"
             Targets="ArchiveBuild" />

    <!-- Make dummy packages.zip to upload to Helix -->
    <PropertyGroup>
      <DummyDir>$(TestWorkingDir)\archive\dummy</DummyDir>
      <DummyPackageDir>$(TestWorkingDir)\archive\packages</DummyPackageDir>
    </PropertyGroup>

    <MakeDir Directories="$(DummyDir)" />
    <MakeDir Directories="$(DummyPackageDir)" />
    <ZipFileCreateFromDirectory SourceDirectory="$(DummyDir)" DestinationArchive="$(DummyPackageDir)\Packages.zip" OverwriteDestination="true" />
  </Target>

  <!-- Generate wrapper .cmd file for an Xunit wrapper -->
  <Target Name="GenerateWrapperCmd"
    Condition="'$(TargetsWindows)' == 'true' ">

    <PropertyGroup>
      <CmdCrossgenVar Condition="'$(Crossgen)' == 'true'">set RunCrossGen=true</CmdCrossgenVar>
      <WrapperCmdContents>
        <![CDATA[
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
pushd %~dp0

set CORE_ROOT=%HELIX_CORRELATION_PAYLOAD%
$(CmdCrossgenVar)

ECHO BEGIN EXECUTION
ECHO %HELIX_CORRELATION_PAYLOAD%\CoreRun.exe %HELIX_WORKITEM_PAYLOAD%\xunit.console.dll %HELIX_WORKITEM_PAYLOAD%\$(ProjectName) -noshadow -xml testResults.xml -notrait category=outerloop -notrait category=failing
%HELIX_CORRELATION_PAYLOAD%\CoreRun.exe %HELIX_WORKITEM_PAYLOAD%\xunit.console.dll %HELIX_WORKITEM_PAYLOAD%\$(ProjectName) -noshadow -xml testResults.xml -notrait category=outerloop -notrait category=failing

echo Finished running tests. Exit code = %ERRORLEVEL%
EXIT /B %ERRORLEVEL%

        ]]>
      </WrapperCmdContents>
    </PropertyGroup>

    <!-- Write the file -->
    <WriteLinesToFile
      File="$(BuildPath)\runtests.cmd"
      Lines="$(WrapperCmdContents)"
      Overwrite="true" />

  </Target>

  <Target Name="GenerateWrapperSh"
    Condition="'$(TargetsWindows)' != 'true' ">

    <!-- Need to force in Unix line endings for Shell script -->
    <PropertyGroup>
      <WrapperShContents>#!/bin/sh%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)%0a</WrapperShContents> 
      <WrapperShContents>$(WrapperShContents)export CORE_ROOT="%24HELIX_CORRELATION_PAYLOAD"%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)for scriptFilePath in %24(find . -type f -iname '%2A.sh' ! -iname "runtests.sh" | sort)%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)do%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents) perl -pi -e 's/\r\n|\n|\r/\n/g' "%24scriptFilePath"%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents) chmod +x "%24scriptFilePath"%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)done%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)%0a</WrapperShContents>

      <!-- Crossgen FX assemblies, if running R2R tests. 
      TODO - remove this when we build tests on Linux -->
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)export RunCrossGen=true%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)overlayDir=%24CORE_ROOT%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)if [ ! -f %24overlayDir/crossgenCompleted.mrk ]%3B then%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)  filesToPrecompile=%24(find -L %24overlayDir -iname \%2A.dll -not -iname \%2A.ni.dll -not -iname \%2A-ms-win-\%2A -type f )%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)  for fileToPrecompile in %24{filesToPrecompile}%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)  do%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    filename=%24{fileToPrecompile}%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    echo Precompiling %24filename%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    %24overlayDir/crossgen /Platform_Assemblies_Paths %24overlayDir /in %24filename /out %24overlayDir/temp.ni.dll 1> %24filename.stdout 2>%24filename.stderr%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    exitCode=%24%3F%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    if [ %24exitCode != 0 ]%3B then%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)      if grep -q -e '(COR_E_ASSEMBLYEXPECTED)' %24filename.stderr%3B then%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)        printf "\n\t%24filename is not a managed assembly.\n\n"%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)      else%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)        echo Unable to precompile %24filename.%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)      fi%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    else%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)      rm %24filename%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)      mv %24overlayDir/temp.ni.dll %24filename%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    fi%0a</WrapperShContents> 
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    rm %24filename.stdout%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)    rm %24filename.stderr%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)  done%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)  touch %24overlayDir/crossgenCompleted.mrk%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)fi%0a</WrapperShContents>
      <WrapperShContents Condition="'$(Crossgen)' == 'true'">$(WrapperShContents)%0a</WrapperShContents>

      <WrapperShContents>$(WrapperShContents)echo BEGIN EXECUTION%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)echo "%24{HELIX_CORRELATION_PAYLOAD}/corerun" %24HELIX_WORKITEM_PAYLOAD/xunit.console.dll %24HELIX_WORKITEM_PAYLOAD/$(ProjectName) -noshadow -xml testResults.xml -notrait category=outerloop -notrait category=failing%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)"%24{HELIX_CORRELATION_PAYLOAD}/corerun" %24HELIX_WORKITEM_PAYLOAD/xunit.console.dll %24HELIX_WORKITEM_PAYLOAD/$(ProjectName) -noshadow -xml testResults.xml -notrait category=outerloop -notrait category=failing%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)ErrorLevel=%24%3F%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)echo Finished running tests. Exit code = %24ErrorLevel%0a</WrapperShContents>
      <WrapperShContents>$(WrapperShContents)exit %24ErrorLevel%0a</WrapperShContents>

    </PropertyGroup>

    <!-- Write the file -->
    <WriteLinesToFile
      File="$(BuildPath)\runtests.sh"
      Lines="$(WrapperShContents)"
      Overwrite="true" />

  </Target>

  <!-- archive the test binaries along with some supporting files -->
  <Target Name="ArchiveBuild">
    <PropertyGroup Condition="'$(ProjectName)'==''">
      <TestProjectName>$(MSBuildProjectName)</TestProjectName>
    </PropertyGroup>

    <!-- the project json and runner script files need to be included in the archive -->
    <MakeDir Directories="$(BuildArchiveDir)" />
    <ZipFileCreateFromDirectory SourceDirectory="$(BuildPath)" DestinationArchive="$(BuildArchiveDir)$(ProjectName).zip" OverwriteDestination="true" />
  </Target>

  <!-- Default target to run - builds executables & archives everything needed for Helix run -->

  <Target Name="ArchiveAll" >
    <PropertyGroup>
      <_ArchiveTargets Condition=" '$(UsePython)' == 'false' ">GenerateWrapperExecutables</_ArchiveTargets>
      <_ArchiveTargets Condition=" '$(UsePython)' == 'true' ">CopyWrapperScript</_ArchiveTargets>
      <_ArchiveTargets>$(_ArchiveTargets);ArchiveTests;ArchiveCoreRoot</_ArchiveTargets>
    </PropertyGroup>
    <MSBuild Projects="helixprep.proj"
             Targets="$(_ArchiveTargets)" />
  </Target>

</Project>