• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
20setlocal EnableDelayedExpansion
21call:checkCommand adb
22call:checkCommand java
23
24:: check java version
25
26%JAVA% -version 2>&1 | findstr /R "version\ \"1*\.*[89].*\"$" || (
27    echo "Wrong java version. 1.8 or 9 is required."
28    exit /B
29)
30
31:: check debug flag and set up remote debugging
32if not "%TF_DEBUG%"=="" (
33    if "%TF_DEBUG_PORT%" == "" (
34        set TF_DEBUG_PORT=10088
35    )
36    set RDBG_FLAG=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=!TF_DEBUG_PORT!
37)
38
39:: first try to find TF jars in same dir as this script
40set CUR_DIR=%CD%
41
42if exist "%CUR_DIR%\tradefed.jar" (
43    set tf_path="%CUR_DIR%\*"
44) else (
45    if not "%ANDROID_HOST_OUT%" == "" (
46        if exist "%ANDROID_HOST_OUT%\tradefed\tradefed.jar" (
47            set tf_path="%ANDROID_HOST_OUT%\tradefed\*"
48        )
49    )
50)
51
52if "%tf_path%" == "" (
53    echo "ERROR: Could not find tradefed jar files"
54    exit /B
55)
56
57:: set any host specific options
58:: file format for file at $TRADEFED_OPTS_FILE is one line per host with the following format:
59:: <hostname>=<options>
60:: for example:
61:: hostname.domain.com=-Djava.io.tmpdir=/location/on/disk -Danother=false ...
62:: hostname2.domain.com=-Djava.io.tmpdir=/different/location -Danother=true ...
63if exist "%TRADEFED_OPTS_FILE%" (
64    call:commandResult "hostname" HOST_NAME
65    call:commandResult "findstr /i /b "%HOST_NAME%" "%TRADEFED_OPTS_FILE%"" TRADEFED_OPTS
66:: delete the hostname part
67    set TRADEFED_OPTS=!TRADEFED_OPTS:%HOST_NAME%=!
68:: delete the first =
69    set TRADEFED_OPTS=!TRADEFED_OPTS:~1!
70)
71
72java %RDBG_FLAG% -XX:+HeapDumpOnOutOfMemoryError ^
73-XX:-OmitStackTraceInFastThrow %TRADEFED_OPTS% -cp %tf_path% com.android.tradefed.command.Console %*
74
75endlocal
76::end of file
77goto:eof
78
79:: check command exist or not
80:: if command not exist, exit
81:checkCommand
82for /f "delims=" %%i in ('where %~1') do (
83    if %%i == "" (
84        echo %~1 not exist
85        exit /B
86    )
87    goto:eof
88)
89goto:eof
90
91:: get the command result
92:: usage: call:commandResult "command" result
93:commandResult
94for /f "delims=" %%i in ('%~1') do (
95    set %~2=%%i
96    goto:eof
97)
98goto:eof
99