Home | History | Annotate | Download | only in scripts
      1 #!/bin/bash
      2 # See usage() below for the description.
      3 
      4 function 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])
     18 EOF
     19 }
     20 
     21 # CD to the top android directory
     22 PROG_DIR=`dirname "$0"`
     23 cd "${PROG_DIR}/../../../"
     24 
     25 HOST=`uname`
     26 USE_COPY=""        # force copy dependent jar files rather than creating symlinks
     27 ONLY_SHOW_DEPS=""  # only report make dependencies but don't build them nor copy.
     28 ONLY_COPY_DEPS=""  # only copy dependencies built by make; uses -f as needed.
     29 
     30 function die() {
     31   echo "Error: $*" >/dev/stderr
     32   exit 1
     33 }
     34 
     35 function 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
     43 while [ $# -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
     59 done
     60 
     61 warn "## Running $0"
     62 
     63 if [[ "${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
     70 elif [[ "$HOST" == "Linux" ]]; then
     71   PLATFORM="linux-x86"
     72 elif [[ "$HOST" == "Darwin" ]]; then
     73   PLATFORM="darwin-x86"
     74 else
     75   die "Unsupported platform ($HOST). Aborting."
     76 fi
     77 
     78 if [[ "$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   }
     86 else
     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   }
     99 fi
    100 
    101 DEST="sdk/eclipse/scripts"
    102 
    103 set -e # fail early
    104 
    105 LIBS=""
    106 CP_FILES=""
    107 
    108 ### BASE ###
    109 
    110 BASE_PLUGIN_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.base/libs"
    111 BASE_PLUGIN_LIBS="common sdkstats androidprefs sdklib"
    112 BASE_PLUGIN_PREBUILTS="\
    113     prebuilts/tools/common/commons-compress/commons-compress-1.0.jar \
    114     prebuilts/tools/common/guava-tools/guava-10.0.1.jar \
    115     prebuilts/tools/common/http-client/commons-logging-1.1.1.jar \
    116     prebuilts/tools/common/http-client/commons-codec-1.4.jar \
    117     prebuilts/tools/common/http-client/httpclient-4.1.1.jar \
    118     prebuilts/tools/common/http-client/httpcore-4.1.jar \
    119     prebuilts/tools/common/http-client/httpmime-4.1.1.jar"
    120 
    121 LIBS="$LIBS $BASE_PLUGIN_LIBS"
    122 CP_FILES="$CP_FILES @:$BASE_PLUGIN_DEST $BASE_PLUGIN_LIBS $BASE_PLUGIN_PREBUILTS"
    123 
    124 ### ADT ###
    125 
    126 ADT_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.adt/libs"
    127 ADT_LIBS="layoutlib_api lint_api lint_checks ide_common rule_api ninepatch sdkuilib assetstudio propertysheet"
    128 ADT_PREBUILTS="\
    129     prebuilt/common/kxml2/kxml2-2.3.0.jar \
    130     prebuilts/tools/common/asm-tools/asm-4.0.jar \
    131     prebuilts/tools/common/asm-tools/asm-tree-4.0.jar \
    132     prebuilts/tools/common/lombok-ast/lombok-ast-0.2.jar"
    133 
    134 LIBS="$LIBS $ADT_LIBS"
    135 CP_FILES="$CP_FILES @:$ADT_DEST $ADT_LIBS $ADT_PREBUILTS"
    136 
    137 ### DDMS ###
    138 
    139 DDMS_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.ddms/libs"
    140 DDMS_LIBS="ddmlib ddmuilib swtmenubar"
    141 
    142 DDMS_PREBUILTS="\
    143     prebuilts/tools/common/jfreechart/jcommon-1.0.12.jar \
    144     prebuilts/tools/common/jfreechart/jfreechart-1.0.9.jar \
    145     prebuilts/tools/common/jfreechart/jfreechart-1.0.9-swt.jar"
    146 
    147 LIBS="$LIBS $DDMS_LIBS"
    148 CP_FILES="$CP_FILES @:$DDMS_DEST $DDMS_LIBS $DDMS_PREBUILTS"
    149 
    150 
    151 ### TEST ###
    152 
    153 TEST_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.tests"
    154 TEST_LIBS="easymock"
    155 TEST_PREBUILTS="prebuilt/common/kxml2/kxml2-2.3.0.jar"
    156 
    157 LIBS="$LIBS $TEST_LIBS"
    158 CP_FILES="$CP_FILES @:$TEST_DEST $TEST_LIBS $TEST_PREBUILTS"
    159 
    160 
    161 ### BRIDGE ###
    162 
    163 if [[ $PLATFORM != "windows-x86" ]]; then
    164   # We can't build enough of the platform on Cygwin to create layoutlib
    165   BRIDGE_LIBS="layoutlib ninepatch"
    166 
    167   LIBS="$LIBS $BRIDGE_LIBS"
    168 fi
    169 
    170 
    171 
    172 ### HIERARCHYVIEWER ###
    173 
    174 HV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/libs"
    175 HV_LIBS="hierarchyviewerlib swtmenubar"
    176 
    177 LIBS="$LIBS $HV_LIBS"
    178 CP_FILES="$CP_FILES @:$HV_DEST $HV_LIBS"
    179 
    180 
    181 ### TRACEVIEW ###
    182 
    183 TV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.traceview/libs"
    184 TV_LIBS="traceview"
    185 
    186 LIBS="$LIBS $TV_LIBS"
    187 CP_FILES="$CP_FILES @:$TV_DEST $TV_LIBS"
    188 
    189 
    190 ### SDKMANAGER ###
    191 
    192 SDMAN_LIBS="swtmenubar"
    193 
    194 LIBS="$LIBS $SDKMAN_LIBS"
    195 
    196 ### GL DEBUGGER ###
    197 
    198 if [[ $PLATFORM != "windows-x86" ]]; then
    199   # liblzf doesn't build under cygwin. If necessary, this should be fixed first.
    200   
    201   GLD_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.gldebugger/libs"
    202   GLD_LIBS="host-libprotobuf-java-2.3.0-lite liblzf"
    203 
    204   LIBS="$LIBS $GLD_LIBS"
    205   CP_FILES="$CP_FILES @:$GLD_DEST $GLD_LIBS"
    206 fi
    207 
    208 # In the mode to only echo dependencies, output them and we're done
    209 if [[ -n $ONLY_SHOW_DEPS ]]; then
    210   echo $LIBS
    211   exit 0
    212 fi
    213 
    214 if [[ -z $ONLY_COPY_DEPS ]]; then
    215   # Make sure we have lunch sdk-<something>
    216   if [[ ! "$TARGET_PRODUCT" ]]; then
    217     warn "## TARGET_PRODUCT is not set, running build/envsetup.sh"
    218     . build/envsetup.sh
    219     warn "## lunch sdk-eng"
    220     lunch sdk-eng
    221   fi
    222 
    223   # Run make on all libs
    224 
    225   J="4"
    226   [[ $(uname) == "Darwin" ]] && J=$(sysctl hw.ncpu | cut -d : -f 2 | tr -d ' ')
    227   [[ $(uname) == "Linux"  ]] && J=$(cat /proc/cpuinfo | grep processor | wc -l)
    228 
    229   warn "## Building libs: make -j$J $LIBS"
    230   make -j${J} $LIBS
    231 fi
    232 
    233 # Copy resulting files
    234 DEST=""
    235 for SRC in $CP_FILES; do
    236   if [[ "${SRC:0:2}" == "@:" ]]; then
    237     DEST="${SRC:2}"
    238     mkdir -vp "$DEST"
    239     continue
    240   fi
    241   if [[ ! -f "$SRC" ]]; then
    242     ORIG_SRC="$SRC"
    243     SRC="out/host/$PLATFORM/framework/$SRC.jar"
    244   fi
    245   if [[ -f "$SRC" ]]; then
    246     if [[ ! -d "$DEST" ]]; then
    247       die "Invalid cp_file dest directory: $DEST"
    248     fi
    249 
    250     cpfile "$SRC" "$DEST"
    251   else
    252     die "## Unknown source '$ORIG_SRC' to copy in '$DEST'"
    253   fi
    254 done
    255 
    256 # OS-specific post operations
    257 
    258 if [ "${HOST:0:6}" == "CYGWIN" ]; then
    259   chmod -v a+rx "$ADT_DEST"/*.jar
    260 fi
    261 
    262 echo "### $0 done"
    263