1#!/bin/bash 2# See usage() below for the description. 3 4function usage() { 5 cat <<EOF 6# This script copies the .jar files that each plugin depends on into the plugins libs folder. 7# By default, on Mac & Linux, this script creates symlinks from the libs folder to the jar file. 8# Since Windows does not support symlinks, the jar files are copied. 9# 10# Options: 11# -f : to copy files rather than creating symlinks on the Mac/Linux platforms. 12# -d : print make dependencies instead of running make; doesn't copy files. 13# -c : copy files expected after make dependencies (reported by -d) have been built. 14# 15# The purpose of -d/-c is to include the workflow in a make file: 16# - the make rule should depend on \$(shell create_all_symlinks -d) 17# - the rule body should perform \$(shell create_all_symlinks -c [-f]) 18EOF 19} 20 21# CD to the top android directory 22PROG_DIR=`dirname "$0"` 23cd "${PROG_DIR}/../../../" 24 25HOST=`uname` 26USE_COPY="" # force copy dependent jar files rather than creating symlinks 27ONLY_SHOW_DEPS="" # only report make dependencies but don't build them nor copy. 28ONLY_COPY_DEPS="" # only copy dependencies built by make; uses -f as needed. 29 30function die() { 31 echo "Error: $*" >/dev/stderr 32 exit 1 33} 34 35function warn() { 36 # Only print something if not in show-deps mode 37 if [[ -z $ONLY_SHOW_DEPS ]]; then 38 echo "$*" 39 fi 40} 41 42## parse arguments 43while [ $# -gt 0 ]; do 44 case "$1" in 45 "-f" ) 46 USE_COPY="1" 47 ;; 48 "-d" ) 49 ONLY_SHOW_DEPS="1" 50 ;; 51 "-c" ) 52 ONLY_COPY_DEPS="1" 53 ;; 54 * ) 55 usage 56 exit 2 57 esac 58 shift 59done 60 61warn "## Running $0" 62 63if [[ "${HOST:0:6}" == "CYGWIN" || "$USE_MINGW" == "1" ]]; then 64 # This is either Cygwin or Linux/Mingw cross-compiling to Windows. 65 PLATFORM="windows-x86" 66 if [[ "${HOST:0:6}" == "CYGWIN" ]]; then 67 # We can't use symlinks under Cygwin 68 USE_COPY="1" 69 fi 70elif [[ "$HOST" == "Linux" ]]; then 71 PLATFORM="linux-x86" 72elif [[ "$HOST" == "Darwin" ]]; then 73 PLATFORM="darwin-x86" 74else 75 die "Unsupported platform ($HOST). Aborting." 76fi 77 78if [[ "$USE_COPY" == "1" ]]; then 79 function cpfile { # $1=source $2=dest 80 cp -fv $1 $2/ 81 } 82 83 function cpdir() { # $1=source $2=dest 84 rsync -avW --delete-after $1 $2 85 } 86else 87 # computes the "reverse" path, e.g. "a/b/c" => "../../.." 88 function back() { 89 echo $1 | sed 's@[^/]*@..@g' 90 } 91 92 function cpfile { # $1=source $2=dest 93 ln -svf `back $2`/$1 $2/ 94 } 95 96 function cpdir() { # $1=source $2=dest 97 ln -svf `back $2`/$1 $2 98 } 99fi 100 101DEST="sdk/eclipse/scripts" 102 103set -e # fail early 104 105LIBS="" 106CP_FILES="" 107 108 109### BASE ### 110 111BASE_PLUGIN_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.base/libs" 112BASE_PLUGIN_LIBS="common sdkstats sdklib dvlib layoutlib_api sdk_common" 113BASE_PLUGIN_PREBUILTS="\ 114 prebuilts/misc/common/kxml2/kxml2-2.3.0.jar \ 115 prebuilts/tools/common/commons-compress/commons-compress-1.0.jar \ 116 prebuilts/tools/common/guava-tools/guava-13.0.1.jar \ 117 prebuilts/tools/common/http-client/commons-logging-1.1.1.jar \ 118 prebuilts/tools/common/http-client/commons-codec-1.4.jar \ 119 prebuilts/tools/common/http-client/httpclient-4.1.1.jar \ 120 prebuilts/tools/common/http-client/httpcore-4.1.jar \ 121 prebuilts/tools/common/http-client/httpmime-4.1.1.jar" 122 123LIBS="$LIBS $BASE_PLUGIN_LIBS" 124CP_FILES="$CP_FILES @:$BASE_PLUGIN_DEST $BASE_PLUGIN_LIBS $BASE_PLUGIN_PREBUILTS" 125 126 127### ADT ### 128 129ADT_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.adt/libs" 130ADT_LIBS="ant-glob assetstudio lint_api lint_checks ninepatch propertysheet rule_api sdkuilib swtmenubar manifmerger" 131ADT_PREBUILTS="\ 132 prebuilts/tools/common/freemarker/freemarker-2.3.19.jar \ 133 prebuilts/tools/common/asm-tools/asm-4.0.jar \ 134 prebuilts/tools/common/asm-tools/asm-tree-4.0.jar \ 135 prebuilts/tools/common/asm-tools/asm-analysis-4.0.jar \ 136 prebuilts/tools/common/lombok-ast/lombok-ast-0.2.jar" 137 138LIBS="$LIBS $ADT_LIBS" 139CP_FILES="$CP_FILES @:$ADT_DEST $ADT_LIBS $ADT_PREBUILTS" 140 141 142### DDMS ### 143 144DDMS_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.ddms/libs" 145DDMS_LIBS="ddmlib ddmuilib swtmenubar uiautomatorviewer" 146 147DDMS_PREBUILTS="\ 148 prebuilts/tools/common/jfreechart/jcommon-1.0.12.jar \ 149 prebuilts/tools/common/jfreechart/jfreechart-1.0.9.jar \ 150 prebuilts/tools/common/jfreechart/jfreechart-1.0.9-swt.jar" 151 152LIBS="$LIBS $DDMS_LIBS" 153CP_FILES="$CP_FILES @:$DDMS_DEST $DDMS_LIBS $DDMS_PREBUILTS" 154 155 156### TEST ### 157 158TEST_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.tests" 159TEST_LIBS="easymock" 160TEST_PREBUILTS="prebuilts/misc/common/kxml2/kxml2-2.3.0.jar" 161 162LIBS="$LIBS $TEST_LIBS" 163CP_FILES="$CP_FILES @:$TEST_DEST $TEST_LIBS $TEST_PREBUILTS" 164 165 166### BRIDGE ### 167 168if [[ $PLATFORM != "windows-x86" ]]; then 169 # We can't build enough of the platform on Cygwin to create layoutlib 170 BRIDGE_LIBS="layoutlib ninepatch" 171 172 LIBS="$LIBS $BRIDGE_LIBS" 173fi 174 175 176### HIERARCHYVIEWER ### 177 178HV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/libs" 179HV_LIBS="hierarchyviewerlib swtmenubar" 180 181LIBS="$LIBS $HV_LIBS" 182CP_FILES="$CP_FILES @:$HV_DEST $HV_LIBS" 183 184 185### TRACEVIEW ### 186 187TV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.traceview/libs" 188TV_LIBS="traceview" 189 190LIBS="$LIBS $TV_LIBS" 191CP_FILES="$CP_FILES @:$TV_DEST $TV_LIBS" 192 193 194### MONITOR ### 195 196MONITOR_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.monitor/libs" 197MONITOR_LIBS="sdkuilib" 198 199LIBS="$LIBS $MONITOR_LIBS" 200CP_FILES="$CP_FILES @:$MONITOR_DEST $MONITOR_LIBS" 201 202 203### SDKMANAGER ### 204 205SDKMAN_LIBS="swtmenubar" 206 207LIBS="$LIBS $SDKMAN_LIBS" 208 209 210### GL DEBUGGER ### 211 212if [[ $PLATFORM != "windows-x86" ]]; then 213 # liblzf doesn't build under cygwin. If necessary, this should be fixed first. 214 215 GLD_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.gldebugger/libs" 216 GLD_LIBS="host-libprotobuf-java-2.3.0-lite liblzf" 217 218 LIBS="$LIBS $GLD_LIBS" 219 CP_FILES="$CP_FILES @:$GLD_DEST $GLD_LIBS" 220fi 221 222# In the mode to only echo dependencies, output them and we're done 223if [[ -n $ONLY_SHOW_DEPS ]]; then 224 echo $LIBS 225 exit 0 226fi 227 228if [[ -z $ONLY_COPY_DEPS ]]; then 229 # Make sure we have lunch sdk-<something> 230 if [[ ! "$TARGET_PRODUCT" ]]; then 231 warn "## TARGET_PRODUCT is not set, running build/envsetup.sh" 232 . build/envsetup.sh 233 warn "## lunch sdk-eng" 234 lunch sdk-eng 235 fi 236 237 # Run make on all libs 238 239 J="4" 240 [[ $(uname) == "Darwin" ]] && J=$(sysctl hw.ncpu | cut -d : -f 2 | tr -d ' ') 241 [[ $(uname) == "Linux" ]] && J=$(cat /proc/cpuinfo | grep processor | wc -l) 242 243 warn "## Building libs: make -j$J $LIBS" 244 make -j${J} $LIBS 245fi 246 247# Copy resulting files 248DEST="" 249for SRC in $CP_FILES; do 250 if [[ "${SRC:0:2}" == "@:" ]]; then 251 DEST="${SRC:2}" 252 mkdir -vp "$DEST" 253 continue 254 fi 255 if [[ ! -f "$SRC" ]]; then 256 ORIG_SRC="$SRC" 257 SRC="out/host/$PLATFORM/framework/$SRC.jar" 258 fi 259 if [[ -f "$SRC" ]]; then 260 if [[ ! -d "$DEST" ]]; then 261 die "Invalid cp_file dest directory: $DEST" 262 fi 263 264 cpfile "$SRC" "$DEST" 265 else 266 die "## Unknown source '$ORIG_SRC' to copy in '$DEST'" 267 fi 268done 269 270# OS-specific post operations 271 272if [ "${HOST:0:6}" == "CYGWIN" ]; then 273 chmod -v a+rx "$ADT_DEST"/*.jar 274fi 275 276echo "### $0 done" 277