summaryrefslogtreecommitdiff
path: root/ddmlib/build_ddmlib.sh
blob: 67a26ddbc3c4fb1303bcb2ad09bfb1c7a5c6a9c4 (plain)
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
#!/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 "$@"