summaryrefslogtreecommitdiff
path: root/tests/src/CLRTest.CrossGen.targets
blob: eab4f056fd3539f8dbddf3750c53d1e5507900fe (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
<!--
***********************************************************************************************
CLRTest.Execute.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

This file contains the logic for providing Execution Script generation.

WARNING:   When setting properties based on their current state (for example:
           <Foo Condition="'$(Foo)'==''>Bar</Foo>).  Be very careful.  Another script generation
           target might be trying to do the same thing.  It's better to avoid this by instead setting a new property.
           
           Additionally, be careful with itemgroups.  Include will propagate outside of the target too!

***********************************************************************************************
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <BashScriptSnippetGen>$(BashScriptSnippetGen);GetCrossgenBashScript</BashScriptSnippetGen>
    <BatchScriptSnippetGen>$(BatchScriptSnippetGen);GetCrossgenBatchScript</BatchScriptSnippetGen>
  </PropertyGroup>
  <ItemGroup>
    <CLRTestBashEnvironmentVariable  Condition="'$(CrossGenTest)' == 'true'" Include = "export RunCrossGen=1"/>
    <CLRTestBatchEnvironmentVariable Condition="'$(CrossGenTest)' == 'true'" Include = "set RunCrossGen=1"/>
  </ItemGroup>

  <!--
    Target: GetCrossgenBatctchcript
    This returns the portion of the execution script that generates the required lines to crossgen the test executable.
  -->
  <Target Name="GetCrossgenBashScript">
    
    <PropertyGroup>
      <CrossgenBashScript Condition="'$(CLRTestKind)' == 'BuildAndRun'">
        <![CDATA[
# CrossGen Script
if [ ! -z ${RunCrossGen+x} ]%3B then
    export COMPlus_ZapRequire=$(ZapRequire)
    export COMPlus_ZapRequireList=$(MSBuildProjectName)
    if [ ! -f $(MSBuildProjectName).org ]%3B then
        TakeLock
        if [ ! -f $(MSBuildProjectName).org ]%3B then
          mkdir IL
          cp $(MSBuildProjectName).exe IL/$(MSBuildProjectName).exe
          mv $(MSBuildProjectName).exe $(MSBuildProjectName).org
          echo $_DebuggerFullPath "$CORE_ROOT/crossgen" /Platform_Assemblies_Paths $CORE_ROOT%3A$PWD/IL%3A$PWD /in $(MSBuildProjectName).org /out $(MSBuildProjectName).exe
          $_DebuggerFullPath "$CORE_ROOT/crossgen" /Platform_Assemblies_Paths $CORE_ROOT%3A$PWD/IL%3A$PWD /in $(MSBuildProjectName).org /out $(MSBuildProjectName).exe
          __cgExitCode=$?
          if [ $__cgExitCode -ne 0 ]
          then
            echo Crossgen failed with exitcode: $__cgExitCode
            ReleaseLock
            exit 1
          fi
        fi 
        ReleaseLock       
    fi        
fi        
        ]]>        
      </CrossgenBashScript>

      <BashCLRTestPreCommands>$(BashCLRTestPreCommands);$(CrossgenBashScript)</BashCLRTestPreCommands>
    </PropertyGroup>
  </Target>

  <Target Name="GetCrossgenBatchScript">
    
    <PropertyGroup>
      <CrossgenBatchScript Condition="'$(CLRTestKind)' == 'BuildAndRun'">
        <![CDATA[

REM CrossGen Script
if defined RunCrossGen ( 
    set COMPlus_ZapRequire=$(ZapRequire)
    set COMPlus_ZapRequireList=$(MSBuildProjectName)
    if not exist "$(MSBuildProjectName).org" (
        call :TakeLock
        set CrossGenStatus=0
        if not exist "$(MSBuildProjectName).org" (
            mkdir IL
            copy $(MSBuildProjectName).exe IL\$(MSBuildProjectName).exe 
            ren $(MSBuildProjectName).exe $(MSBuildProjectName).org
            echo "%_DebuggerFullPath% %CORE_ROOT%\crossgen.exe" /Platform_Assemblies_Paths %CORE_ROOT%%3B%25cd%25\IL%3B%25cd%25 /in $(MSBuildProjectName).org /out $(MSBuildProjectName).exe
            %_DebuggerFullPath% "%CORE_ROOT%\crossgen.exe" /Platform_Assemblies_Paths %CORE_ROOT%%3B%25cd%25\IL%3B%25cd%25 /in $(MSBuildProjectName).org /out $(MSBuildProjectName).exe
            set CrossGenStatus=!ERRORLEVEL!
        )
        call :ReleaseLock
        IF NOT !CrossGenStatus!==0 (
            ECHO Crossgen failed with exitcode - !CrossGenStatus!
            Exit /b 1
        )
    )
) 
        ]]>
      </CrossgenBatchScript>

      <CLRTestBatchPreCommands>$(CLRTestBatchPreCommands);$(CrossgenBatchScript)</CLRTestBatchPreCommands>
    </PropertyGroup>
  </Target>


  
</Project>