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 LIBS=""
    105 CP_FILES=""
    106 
    107 
    108 ### BASE ###
    109 
    110 BASE_PLUGIN_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.base/libs"
    111 BASE_PLUGIN_LIBS="common sdkstats sdklib dvlib layoutlib-api sdk-common"
    112 BASE_PLUGIN_PREBUILTS="\
    113     prebuilts/tools/common/m2/repository/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar \
    114     prebuilts/tools/common/m2/repository/org/apache/commons/commons-compress/1.0/commons-compress-1.0.jar \
    115     prebuilts/tools/common/m2/repository/com/google/guava/guava/13.0.1/guava-13.0.1.jar \
    116     prebuilts/tools/common/m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar \
    117     prebuilts/tools/common/m2/repository/commons-codec/commons-codec/1.4/commons-codec-1.4.jar \
    118     prebuilts/tools/common/m2/repository/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.jar \
    119     prebuilts/tools/common/m2/repository/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.jar \
    120     prebuilts/tools/common/m2/repository/org/apache/httpcomponents/httpmime/4.1/httpmime-4.1.jar \
    121     prebuilts/tools/common/m2/repository/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.jar \
    122     prebuilts/tools/common/m2/repository/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.jar"
    123 
    124 LIBS="$LIBS $BASE_PLUGIN_LIBS"
    125 CP_FILES="$CP_FILES @:$BASE_PLUGIN_DEST $BASE_PLUGIN_LIBS $BASE_PLUGIN_PREBUILTS"
    126 
    127 
    128 ### ADT ###
    129 
    130 ADT_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.adt/libs"
    131 ADT_LIBS="ant-glob asset-studio lint-api lint-checks ninepatch propertysheet rule-api sdkuilib swtmenubar manifest-merger"
    132 ADT_PREBUILTS="\
    133     prebuilts/tools/common/freemarker/freemarker-2.3.19.jar \
    134     prebuilts/tools/common/m2/repository/org/ow2/asm/asm/4.0/asm-4.0.jar \
    135     prebuilts/tools/common/m2/repository/org/ow2/asm/asm-tree/4.0/asm-tree-4.0.jar \
    136     prebuilts/tools/common/m2/repository/org/ow2/asm/asm-analysis/4.0/asm-analysis-4.0.jar \
    137     prebuilts/tools/common/lombok-ast/lombok-ast-0.2.jar"
    138 
    139 LIBS="$LIBS $ADT_LIBS"
    140 CP_FILES="$CP_FILES @:$ADT_DEST $ADT_LIBS $ADT_PREBUILTS"
    141 
    142 
    143 ### DDMS ###
    144 
    145 DDMS_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.ddms/libs"
    146 DDMS_LIBS="ddmlib ddmuilib swtmenubar uiautomatorviewer"
    147 
    148 DDMS_PREBUILTS="\
    149     prebuilts/tools/common/m2/repository/jfree/jcommon/1.0.12/jcommon-1.0.12.jar \
    150     prebuilts/tools/common/m2/repository/jfree/jfreechart/1.0.9/jfreechart-1.0.9.jar \
    151     prebuilts/tools/common/m2/repository/jfree/jfreechart-swt/1.0.9/jfreechart-swt-1.0.9.jar"
    152 
    153 LIBS="$LIBS $DDMS_LIBS"
    154 CP_FILES="$CP_FILES @:$DDMS_DEST $DDMS_LIBS $DDMS_PREBUILTS"
    155 
    156 
    157 ### TEST ###
    158 
    159 TEST_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.tests"
    160 TEST_LIBS="easymock sdktestutils"
    161 TEST_PREBUILTS="prebuilts/tools/common/m2/repository/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar"
    162 
    163 LIBS="$LIBS $TEST_LIBS"
    164 CP_FILES="$CP_FILES @:$TEST_DEST $TEST_LIBS $TEST_PREBUILTS"
    165 
    166 
    167 ### BRIDGE ###
    168 
    169 if [[ $PLATFORM != "windows-x86" ]]; then
    170   # We can't build enough of the platform on Cygwin to create layoutlib
    171   BRIDGE_LIBS="layoutlib ninepatch"
    172 
    173   LIBS="$LIBS $BRIDGE_LIBS"
    174 fi
    175 
    176 
    177 ### HIERARCHYVIEWER ###
    178 
    179 HV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/libs"
    180 HV_LIBS="hierarchyviewer2lib swtmenubar"
    181 
    182 LIBS="$LIBS $HV_LIBS"
    183 CP_FILES="$CP_FILES @:$HV_DEST $HV_LIBS"
    184 
    185 
    186 ### TRACEVIEW ###
    187 
    188 TV_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.traceview/libs"
    189 TV_LIBS="traceview"
    190 
    191 LIBS="$LIBS $TV_LIBS"
    192 CP_FILES="$CP_FILES @:$TV_DEST $TV_LIBS"
    193 
    194 
    195 ### MONITOR ###
    196 
    197 MONITOR_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.monitor/libs"
    198 MONITOR_LIBS="sdkuilib"
    199 
    200 LIBS="$LIBS $MONITOR_LIBS"
    201 CP_FILES="$CP_FILES @:$MONITOR_DEST $MONITOR_LIBS"
    202 
    203 
    204 ### SDKMANAGER ###
    205 
    206 SDKMAN_LIBS="swtmenubar"
    207 
    208 LIBS="$LIBS $SDKMAN_LIBS"
    209 
    210 
    211 ### GL DEBUGGER ###
    212 
    213 if [[ $PLATFORM != "windows-x86" ]]; then
    214   # liblzf doesn't build under cygwin. If necessary, this should be fixed first.
    215 
    216   GLD_DEST="sdk/eclipse/plugins/com.android.ide.eclipse.gldebugger/libs"
    217   GLD_LIBS="host-libprotobuf-java-2.3.0-lite liblzf"
    218 
    219   LIBS="$LIBS $GLD_LIBS"
    220   CP_FILES="$CP_FILES @:$GLD_DEST $GLD_LIBS"
    221 fi
    222 
    223 # If some of the libs are available in prebuilts/devtools, use link to them directly
    224 # instead of trying to rebuild them so remove them from the libs to build. Note that
    225 # they are already listed in CP_FILES so we'll adjust the source to copy later.
    226 
    227 LIBS2=""
    228 for LIB in $LIBS; do
    229   J="prebuilts/devtools/tools/lib/$LIB.jar"
    230   if [[ ! -f $J ]]; then
    231     J="prebuilts/devtools/adt/lib/$LIB.jar"
    232   fi
    233   if [[ -f $J ]]; then
    234     warn "## Using existing $J"
    235   else
    236     LIBS2="$LIBS2 $LIB"
    237   fi
    238 done
    239 LIBS="$LIBS2"
    240 unset LIBS2
    241 
    242 # In the mode to only echo dependencies, output them and we're done
    243 if [[ -n $ONLY_SHOW_DEPS ]]; then
    244   echo $LIBS
    245   exit 0
    246 fi
    247 
    248 if [[ -z $ONLY_COPY_DEPS ]]; then
    249   # Make sure we have lunch sdk-<something>
    250   if [[ ! "$TARGET_PRODUCT" ]]; then
    251     warn "## TARGET_PRODUCT is not set, running build/envsetup.sh"
    252     . build/envsetup.sh
    253     warn "## lunch sdk-eng"
    254     lunch sdk-eng
    255   fi
    256 
    257   # Run make on all libs
    258 
    259   J="4"
    260   [[ $(uname) == "Darwin" ]] && J=$(sysctl hw.ncpu | cut -d : -f 2 | tr -d ' ')
    261   [[ $(uname) == "Linux"  ]] && J=$(cat /proc/cpuinfo | grep processor | wc -l)
    262 
    263   warn "## Building libs: make -j$J $LIBS"
    264   make -j${J} $LIBS
    265 fi
    266 
    267 # Copy resulting files
    268 DEST=""
    269 for SRC in $CP_FILES; do
    270   if [[ "${SRC:0:2}" == "@:" ]]; then
    271     DEST="${SRC:2}"
    272     mkdir -vp "$DEST"
    273     continue
    274   fi
    275   if [[ ! -f "$SRC" ]]; then
    276     ORIG_SRC="$SRC"
    277     # Take a prebuilts/devtools instead of a framework one if possible.
    278     SRC="prebuilts/devtools/tools/lib/$SRC.jar"
    279     if [[ ! -f "$SRC" ]]; then
    280       SRC="prebuilts/devtools/adt/lib/$ORIG_SRC.jar"
    281     fi
    282     if [[ ! -f "$SRC" ]]; then
    283       SRC="out/host/$PLATFORM/framework/$ORIG_SRC.jar"
    284     fi
    285   fi
    286   if [[ -f "$SRC" ]]; then
    287     if [[ ! -d "$DEST" ]]; then
    288       die "Invalid cp_file dest directory: $DEST"
    289     fi
    290 
    291     cpfile "$SRC" "$DEST"
    292   else
    293     die "## Unknown source '$ORIG_SRC' to copy in '$DEST'"
    294   fi
    295 done
    296 
    297 # OS-specific post operations
    298 
    299 if [ "${HOST:0:6}" == "CYGWIN" ]; then
    300   chmod -v a+rx "$ADT_DEST"/*.jar
    301 fi
    302 
    303 echo "### $0 done"
    304