diff options
Diffstat (limited to 'ddmlib/build_ddmlib.sh')
-rwxr-xr-x | ddmlib/build_ddmlib.sh | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/ddmlib/build_ddmlib.sh b/ddmlib/build_ddmlib.sh new file mode 100755 index 0000000..67a26dd --- /dev/null +++ b/ddmlib/build_ddmlib.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64/ +CUR_DIR=$(pwd) +link_src=$(readlink $0) +if [ -z "${link_src}" ]; then + PARENT=$(cd $(dirname $0); pwd) +else + PARENT=$(cd $(dirname ${link_src}); pwd) +fi + +function getTop(){ + local parent_dir=$1 + if [ -z "${parent_dir}" ] || [ "X${parent_dir}" == "X/" ]; then + return + fi + if [ -f "${parent_dir}/build/envsetup.sh" ]; then + echo "${parent_dir}" + return + fi + local new_parent=$(cd $(dirname ${parent_dir}); pwd) + getTop "${new_parent}" +} + +function clone_master(){ + ## clone the tools/external/gradle repository which will be used to compile the ddmlib jar file + clone=true + gradle_dir="${tools_dir}/external/gradle" + if [ -d "${gradle_dir}" ]; then + cd ${gradle_dir} + git status &>/dev/null + if [ $? -eq 0 ]; then + clone=false + fi + fi + if ${clone}; then + rm -fr ${gradle_dir} + cd $(dirname ${gradle_dir}) + git clone https://android.googlesource.com/platform/tools/external/gradle + fi + + ## clone the tools/base repository which includes the ddmlib source + clone=true + base_dir="${tools_dir}/base" + if [ -d "${base_dir}" ]; then + cd ${base_dir} + git status &>/dev/null + if [ $? -eq 0 ]; then + clone=false + fi + fi + if ${clone}; then + rm -fr ${base_dir} + cd $(dirname ${base_dir}) + git clone https://android.googlesource.com/platform/tools/base + fi +} + + +function patch_4.3_r2(){ + cd ${tools_dir}/base/ + git checkout -b android-4.3_r2 android-4.3_r2 + ## apply patch for Device.java for INSTALL_TIMEOUT + patch_f="${PARENT}/0001-ddmlib-Device.java-change-the-INSTALL_TIMEOUT-to-20-.patch" + git am ${patch_f} + if [ $? -ne 0 ]; then + echo "Failed to apply the patch: ${patch_f}" + exit 1 + fi + + ## apply patch for RemoteAndroidTestRunner.java for max output response timeout + patch_f="${PARENT}/0002-ddmlib-RemoteAndroidTestRunner.java-increase-the-tim.patch" + git am ${patch_f} + if [ $? -ne 0 ]; then + echo "Failed to apply the patch: ${patch_f}" + exit 1 + fi +} + +function main(){ + root_dir=$(getTop ${PARENT}) + if [ -z "${root_dir}" ]; then + echo "Failed to find root directory, please put this script under the root directory of android source" + exit 1 + fi + rm -fr ${root_dir}/out/host/gradle/ + tools_dir="${root_dir}/tools/" + + clone_master + patch_4.3_r2 + + ## compile the ddmlib jar file + cd ${tools_dir}/base/ + ./gradlew :ddmlib:build + + ddmlib=$(find ${root_dir}/out/host/ -name ddmlib*.jar ! -name *sources.jar ! -name *javadoc.jar) + if [ -z "$ddmlib" ]; then + echo "Failed to compile the ddmlib jar file" + exit 1 + fi + cp ${ddmlib} ${CUR_DIR}/ddmlib-prebuilt.jar + echo "The generated ddmlib jar file is: ${CUR_DIR}/ddmlib-prebuilt.jar" +} +main "$@" |