Home | History | Annotate | Download | only in scripts
      1 #!/bin/bash
      2 # Entry point to build the Eclipse plugins for the build server.
      3 #
      4 # Input parameters:
      5 # $1: *Mandatory* destination directory. Must already exist. Cannot contain spaces.
      6 # $2: Optional build number. If present, will be appended to the date qualifier.
      7 #     The build number cannot contain spaces *nor* periods (dashes are ok.)
      8 # -z: Optional, prevents the final zip and leaves the udate-site directory intact.
      9 # -i: Optional, if present, the Google internal update site will be built. Otherwise, 
     10 #     the external site will be built
     11 # Workflow:
     12 # - make dx, ddms, ping
     13 # - create symlinks (for eclipse code reorg, for ddms, ping)
     14 # - call the actual builder script from Brett
     15 # - zip resulting stuff and move to $DEST
     16 # Note: currently wrap around existing shell script, reuse most of it,
     17 # eventually both might merge as needed.
     18 
     19 set -e  # Fail this script as soon as a command fails -- fail early, fail fast
     20 
     21 DEST_DIR=""
     22 BUILD_NUMBER=""
     23 CREATE_ZIP="1"
     24 INTERNAL_BUILD=""
     25 
     26 function get_params() {
     27   # parse input parameters
     28   while [ $# -gt 0 ]; do
     29     if [ "$1" == "-z" ]; then
     30       CREATE_ZIP=""
     31     elif [ "$1" == "-i" ]; then
     32       INTERNAL_BUILD="-i"
     33     elif [ "$1" != "" ] && [ -z "$DEST_DIR" ]; then
     34       DEST_DIR="$1"
     35     elif [ "$1" != "" ] && [ -z "$BUILD_NUMBER" ]; then
     36       BUILD_NUMBER="$1"
     37     fi
     38     shift
     39   done
     40 }
     41 
     42 function die() {
     43   echo "Error:" $*
     44   echo "Aborting"
     45   exit 1
     46 }
     47 
     48 function check_params() {
     49   # This needs to run from the top android directory
     50   # Automatically CD to the top android directory, whatever its name
     51   D=`dirname "$0"`
     52   cd "$D/../../../" && echo "Switched to directory $PWD"
     53 
     54   # The current Eclipse build has some Linux dependency in its config files
     55   [ `uname` == "Linux" -o `uname` == "Darwin" ] || die "This must run from a Linux or Mac OSX box."
     56 
     57   # Check dest dir exists
     58   [ -n "$DEST_DIR" ] || die "Usage: $0 <destination-directory> [build-number]"
     59   [ -d "$DEST_DIR" ] || die "Destination directory $DEST_DIR must exist."
     60 }
     61 
     62 function build_libs() {
     63   J="8"
     64   [[ $(uname) == "Darwin" ]] && J=$(sysctl hw.ncpu | cut -d : -f 2 | tr -d ' ')
     65   [[ $(uname) == "Linux"  ]] && J=$(( $(cat /proc/cpuinfo | grep processor | wc -l) + 2 ))
     66   MAKE_OPT="-j$J"
     67   LIBS="dx ping ddms androidprefs layoutlib layoutlib_api ide_common ninepatch sdklib sdkuilib traceview assetstudio"
     68   echo "*** Building: make $MAKE_OPT $LIBS"
     69   make $MAKE_OPT $LIBS
     70 }
     71 
     72 function build_plugin {
     73   sdk/eclipse/scripts/create_all_symlinks.sh
     74 
     75   # Qualifier is "v" followed by date/time in YYYYMMDDHHSS format and the optional
     76   # build number.
     77   DATE=`date +v%Y%m%d%H%M`
     78   QUALIFIER="$DATE"
     79   [ -n "$BUILD_NUMBER" ] && QUALIFIER="${QUALIFIER}-${BUILD_NUMBER}"
     80 
     81   # Compute the final directory name and remove any leftovers from previous
     82   # runs if any.
     83   BUILD_PREFIX="android-eclipse"
     84   if [ "$INTERNAL_BUILD" ]; then
     85     # append 'eng' signifier to end of archive name to denote internal build
     86     BUILD_PREFIX="${BUILD_PREFIX}-eng"
     87   fi
     88 
     89   # exclude date from build-zip name so it can be auto-calculated by continuous
     90   # test process unless there's no build number, in which case the date is
     91   # still used (useful for testing)
     92   ZIP_NAME="${BUILD_PREFIX}-${BUILD_NUMBER:-$DATE}.zip"
     93   [ -d "$DEST_DIR/$BUILD_PREFIX" ] || rm -rfv "$DEST_DIR/$BUILD_PREFIX"
     94 
     95   # Perform the Eclipse build and move the result in $DEST_DIR/android-build
     96   sdk/eclipse/scripts/build_plugins.sh $QUALIFIER $INTERNAL_BUILD -d "$DEST_DIR" -a "$BUILD_PREFIX"
     97 
     98   # Cleanup
     99   [ -d "$QUALIFIER" ] && rm -rfv "$QUALIFIER"
    100 
    101   if [ "$CREATE_ZIP" ]; then
    102     # The result is a full update-site under $DEST_DIR/BUILD_PREFIX
    103     # Zip it and remove the directory.
    104     echo "**** Package in $DEST_DIR"
    105     [ -d "$DEST_DIR/$BUILD_PREFIX" ] || \
    106       die "Build failed to produce $DEST_DIR/$BUILD_PREFIX"
    107     cd "$DEST_DIR"
    108     [ -f "$ZIP_NAME" ] && rm -rfv "$ZIP_NAME"
    109     cd "$BUILD_PREFIX"
    110     zip -9r "../$ZIP_NAME" *
    111     cd .. # back to $DEST_DIR
    112     rm -rfv "$BUILD_PREFIX"  # removes the directory, not the zip
    113     echo "ZIP of Update site available at $DEST_DIR/${ZIP_NAME}"
    114   else
    115     echo "Update site available in $DEST_DIR/$BUILD_PREFIX"
    116   fi
    117 }
    118 
    119 get_params "$@"
    120 check_params
    121 build_libs
    122 build_plugin
    123