1 @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 20 setlocal EnableDelayedExpansion 21 call:checkCommand adb 22 call:checkCommand java 23 24 :: check java version 25 set JAVA_VERSION= 26 27 for /f "delims=" %%j in ('java -version 2^>^&1 ^| findstr /i """1.8"') do ( 28 set JAVA_VERSION=8 29 ) 30 31 if "%JAVA_VERSION%" == "" ( 32 echo "Wrong java version. 1.8 is required." 33 exit /B 34 ) 35 36 :: check debug flag and set up remote debugging 37 if not "%TF_DEBUG%"=="" ( 38 if "%TF_DEBUG_PORT%" == "" ( 39 set TF_DEBUG_PORT=10088 40 ) 41 set RDBG_FLAG=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=!TF_DEBUG_PORT! 42 ) 43 44 :: first try to find TF jars in same dir as this script 45 set CUR_DIR=%CD% 46 47 if 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 57 if "%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 ... 68 if 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 77 java %RDBG_FLAG% -XX:+HeapDumpOnOutOfMemoryError ^ 78 -XX:-OmitStackTraceInFastThrow %TRADEFED_OPTS% -cp %tf_path% com.android.tradefed.command.Console %* 79 80 endlocal 81 ::end of file 82 goto:eof 83 84 :: check command exist or not 85 :: if command not exist, exit 86 :checkCommand 87 for /f "delims=" %%i in ('where %~1') do ( 88 if %%i == "" ( 89 echo %~1 not exist 90 exit /B 91 ) 92 goto:eof 93 ) 94 goto:eof 95 96 :: get the command result 97 :: usage: call:commandResult "command" result 98 :commandResult 99 for /f "delims=" %%i in ('%~1') do ( 100 set %~2=%%i 101 goto:eof 102 ) 103 goto:eof 104