blob: 13627402fd720a244ea0449c0651e1dc201cc763 [file] [log] [blame]
xingdai4bea46a2014-11-20 14:41:02 -08001@echo off
2
3:: Copyright (C) 2014 The Android Open Source Project
4
5:: Licensed under the Apache License, Version 2.0 (the "License");
6:: you may not use this file except in compliance with the License.
7:: You may obtain a copy of the License at
8
9:: http://www.apache.org/licenses/LICENSE-2.0
10
11:: Unless required by applicable law or agreed to in writing, software
12:: distributed under the License is distributed on an "AS IS" BASIS,
13:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14:: See the License for the specific language governing permissions and
15:: limitations under the License.
16
17:: A helper script that launches TradeFederation from the current build
18:: environment.
19
xingdaif5d9b952014-12-03 16:52:14 -080020setlocal EnableDelayedExpansion
xingdai4bea46a2014-11-20 14:41:02 -080021call:checkCommand adb
22call:checkCommand java
23
24:: check java version
25set JAVA_VERSION=
26
Julien Desprez45431db2016-06-13 15:17:40 +010027for /f "delims=" %%j in ('java -version 2^>^&1 ^| findstr /i """1.8"') do (
28 set JAVA_VERSION=8
xingdai4bea46a2014-11-20 14:41:02 -080029)
30
31if "%JAVA_VERSION%" == "" (
Julien Desprez45431db2016-06-13 15:17:40 +010032 echo "Wrong java version. 1.8 is required."
xingdai4bea46a2014-11-20 14:41:02 -080033 exit /B
34)
35
36:: check debug flag and set up remote debugging
37if not "%TF_DEBUG%"=="" (
38 if "%TF_DEBUG_PORT%" == "" (
39 set TF_DEBUG_PORT=10088
40 )
xingdaif5d9b952014-12-03 16:52:14 -080041 set RDBG_FLAG=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=!TF_DEBUG_PORT!
xingdai4bea46a2014-11-20 14:41:02 -080042)
43
44:: first try to find TF jars in same dir as this script
45set CUR_DIR=%CD%
46
47if exist "%CUR_DIR%\tradefed.jar" (
48 set tf_path="%CUR_DIR%\*"
49) else (
50 if not "%ANDROID_HOST_OUT%" == "" (
51 if exist "%ANDROID_HOST_OUT%\tradefed\tradefed.jar" (
52 set tf_path="%ANDROID_HOST_OUT%\tradefed\*"
53 )
54 )
55)
56
57if "%tf_path%" == "" (
58 echo "ERROR: Could not find tradefed jar files"
59 exit /B
60)
61
62:: set any host specific options
63:: file format for file at $TRADEFED_OPTS_FILE is one line per host with the following format:
64:: <hostname>=<options>
65:: for example:
66:: hostname.domain.com=-Djava.io.tmpdir=/location/on/disk -Danother=false ...
67:: hostname2.domain.com=-Djava.io.tmpdir=/different/location -Danother=true ...
68if exist "%TRADEFED_OPTS_FILE%" (
69 call:commandResult "hostname" HOST_NAME
70 call:commandResult "findstr /i /b "%HOST_NAME%" "%TRADEFED_OPTS_FILE%"" TRADEFED_OPTS
71:: delete the hostname part
72 set TRADEFED_OPTS=!TRADEFED_OPTS:%HOST_NAME%=!
73:: delete the first =
74 set TRADEFED_OPTS=!TRADEFED_OPTS:~1!
75)
76
77java %RDBG_FLAG% -XX:+HeapDumpOnOutOfMemoryError ^
78-XX:-OmitStackTraceInFastThrow %TRADEFED_OPTS% -cp %tf_path% com.android.tradefed.command.Console %*
79
xingdaif5d9b952014-12-03 16:52:14 -080080endlocal
xingdai4bea46a2014-11-20 14:41:02 -080081::end of file
82goto:eof
83
84:: check command exist or not
85:: if command not exist, exit
86:checkCommand
87for /f "delims=" %%i in ('where %~1') do (
88 if %%i == "" (
89 echo %~1 not exist
90 exit /B
91 )
92 goto:eof
93)
94goto:eof
95
96:: get the command result
97:: usage: call:commandResult "command" result
98:commandResult
99for /f "delims=" %%i in ('%~1') do (
100 set %~2=%%i
101 goto:eof
102)
103goto:eof