forked from dotnet/coreclr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLRTest.Execute.Batch.targets
203 lines (171 loc) · 7.02 KB
/
CLRTest.Execute.Batch.targets
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
<!--
***********************************************************************************************
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">
<!--
Target: GetExecuteCmdFullPath
Return Executed Cmd Relative Full Path
We can use this target get its toRun Project's Cmd Full Path to avoid hard-code
-->
<Target
Name="GetExecuteCmdFullPath"
Returns="$(ExecuteCmdFullPath)">
<PropertyGroup>
<ExecuteCmdFullPath>$(OutputPath)\$(AssemblyName).cmd</ExecuteCmdFullPath>
</PropertyGroup>
</Target>
<!--
*******************************************************************************************
TARGET: GenerateExecutionScriptInternal
For tests that "run" we will generate an execution script that wraps any arguments or other
goo. This allows generated .lst files to be very simple and reusable to invoke any "stage"
of test execution.
Notice this is hooked up to run after targets that generate the stores that are marked with GenerateScripts metadata.
Note also that this means it will run after the first of such targets.
-->
<Target Name="GenerateBatchExecutionScript"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(OutputPath)\$(AssemblyName).cmd">
<PropertyGroup>
<!-- TODO:2 build in debugger experience support -->
<BatchCLRTestExitCodePrep Condition="$(_CLRTestNeedsToRun)"><![CDATA[
set CLRTestExpectedExitCode=$(CLRTestExitCode)
ECHO BEGIN EXECUTION
]]></BatchCLRTestExitCodePrep>
<BatchCLRTestArgPrep Condition=" '$(CLRTestExecutionArguments)'!='' "><![CDATA[
set CLRTestExecutionArguments=$(CLRTestExecutionArguments)
]]></BatchCLRTestArgPrep>
<!-- By default, be prepared to do a full check -->
<BatchCLRTestExitCodeCheck><![CDATA[
ECHO Expected: %CLRTestExpectedExitCode%
ECHO Actual: %CLRTestExitCode%
IF NOT "%CLRTestExitCode%"=="%CLRTestExpectedExitCode%" (
ECHO END EXECUTION - FAILED
ECHO FAILED
Exit /b 1
) ELSE (
ECHO END EXECUTION - PASSED
ECHO PASSED
Exit /b 0
)
]]></BatchCLRTestExitCodeCheck>
</PropertyGroup>
<ItemGroup Condition="$(_CLRTestNeedsToRun)">
<Clean Include="$(OutputPath)\$(AssemblyName).cmd"/>
<BatchCLRTestExecutionScriptArgument Include="debug">
<HasParam>true</HasParam>
<ParamName>debuggerFullPath</ParamName>
<Command><![CDATA[
IF EXIST "%2" (
set _DebuggerFullPath=%2
) ELSE (
ECHO The Debugger FullPath "%2" doesn't exist
GOTO :USAGE
)
]]></Command>
<Description>Run testcases under debugger.</Description>
</BatchCLRTestExecutionScriptArgument>
</ItemGroup>
<!--Call GetExecuteCmdFullPath to get ToRunProject cmd file Path -->
<MSBuild Projects="$(CLRTestProjectToRun)" Targets="GetExecuteCmdFullPath" Condition="'$(_CLRTestNeedsProjectToRun)' == 'True'">
<Output TaskParameter="TargetOutputs" PropertyName="_CLRTestToRunFileFullPath"/>
</MSBuild>
<PropertyGroup>
<!-- Calculate the thing we're going to run -->
<_CLRTestRunFile Condition="'$(_CLRTestNeedsProjectToRun)' != 'True'">"$(AssemblyName).exe"</_CLRTestRunFile>
<!-- TODO: make this better? -->
<_CLRTestRunFile Condition=" '$(CLRTestIsHosted)'=='true' And !$(_CLRTestNeedsProjectToRun) ">"%Core_Root%\corerun.exe" $(_CLRTestRunFile)</_CLRTestRunFile>
<BatchCLRTestLaunchCmds Condition=" '$(BatchCLRTestLaunchCmds)'=='' "><![CDATA[
ECHO $(_CLRTestRunFile) %CLRTestExecutionArguments% %Host_Args%
%_DebuggerFullPath% $(_CLRTestRunFile) %CLRTestExecutionArguments% %Host_Args%
set CLRTestExitCode=%ERRORLEVEL%
]]></BatchCLRTestLaunchCmds>
</PropertyGroup>
<Message Text="MSBuildProjectDirectory:$(MSBuildProjectDirectory)" />
<Message Text="_CLRTestToRunFileFullPath:$(_CLRTestToRunFileFullPath)"/>
<Message Text="_CLRTestRunFile:$(_CLRTestRunFile)" />
<ItemGroup>
<_RequiredProperties Include="_CLRTestRunFile">
<Value>$(_CLRTestRunFile)</Value>
</_RequiredProperties>
</ItemGroup>
<!-- 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.
The Command metadata for BatchCLRTestExecutionScriptArgument items is executed
when the argument is found.
-->
<BatchCLRTestArgPrep><![CDATA[
REM Parse Command Line
:NextArg
IF /I '%1' == '-?' GOTO :USAGE
IF /I '%1' == '/?' GOTO :USAGE
IF /I '%1' == '-h' GOTO :USAGE
IF /I '%1' == '/h' GOTO :USAGE
@(BatchCLRTestExecutionScriptArgument -> 'set cond=0
IF /I [%1] == [-%(Identity)] set cond=1
IF /I [%1] == [/%(Identity)] set cond=1
IF %cond% EQU 1 (
%(Command)
shift
IF /I [%(HasParam)] == [true] shift
goto NextArg
)','
')
if NOT "%1" == "" (
set CLRTestExecutionArguments=%*
goto :ArgsDone
)
goto ArgsDone
:USAGE
ECHO.Usage
ECHO %0 $(_CLRTestParamList)
ECHO.
ECHO - OPTIONS -
@(BatchCLRTestExecutionScriptArgument -> 'ECHO -%(Identity) %(ParamName)
ECHO %(Description)', '
')
Exit /b 1
:ArgsDone
$(BatchCLRTestArgPrep)
]]></BatchCLRTestArgPrep>
<!-- NOTE! semicolons must be escaped with %3B boooo -->
<_CLRTestExecutionScriptText><![CDATA[
@ECHO OFF
setlocal
pushd %~dp0
$(BatchCLRTestArgPrep)
$(BatchCLRTestExitCodePrep)
REM Precommands
$(_CLRTestPreCommands)
REM Launch
$(BatchCLRTestLaunchCmds)
REM PostCommands
$(_CLRTestPostCommands)
$(BatchCLRTestExitCodeCheck)
]]></_CLRTestExecutionScriptText>
</PropertyGroup>
<!-- Write the file -->
<WriteLinesToFile
File="$(OutputPath)\$(AssemblyName).cmd"
Lines="$(_CLRTestExecutionScriptText)"
Overwrite="true" />
</Target>
</Project>