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 PROG_DIR=$(dirname "$0")
     22 
     23 DEST_DIR=""
     24 BUILD_NUMBER=""
     25 CREATE_ZIP="1"
     26 INTERNAL_BUILD=""
     27 ADT_PREVIEW="preview"   # "preview" for preview builds, "" for final release builds.
     28 
     29 function get_params() {
     30   # parse input parameters
     31   while [ $# -gt 0 ]; do
     32     if [ "$1" == "-z" ]; then
     33       CREATE_ZIP=""
     34     elif [ "$1" == "-i" ]; then
     35       INTERNAL_BUILD="-i"
     36     elif [ "$1" != "" ] && [ -z "$DEST_DIR" ]; then
     37       DEST_DIR="$1"
     38     elif [ "$1" != "" ] && [ -z "$BUILD_NUMBER" ]; then
     39       BUILD_NUMBER="$1"
     40     fi
     41     shift
     42   done
     43 }
     44 
     45 function die() {
     46   echo "Error:" $*
     47   echo "Aborting"
     48   exit 1
     49 }
     50 
     51 function check_params() {
     52   # This needs to run from the top android directory
     53   # Automatically CD to the top android directory, whatever its name
     54   D="$PROG_DIR"
     55   cd "$D/../../../" && echo "Switched to directory $PWD"
     56 
     57   # The current Eclipse build has some Linux dependency in its config files
     58   [ `uname` == "Linux" -o `uname` == "Darwin" ] || die "This must run from a Linux or Mac OSX box."
     59 
     60   # Check dest dir exists
     61   [ -n "$DEST_DIR" ] || die "Usage: $0 <destination-directory> [build-number]"
     62   [ -d "$DEST_DIR" ] || die "Destination directory $DEST_DIR must exist."
     63 
     64   # Qualifier is "v" followed by date/time in YYYYMMDDHHSS format, an optional "preview"
     65   # tag and the optional build number.
     66   DATE=`date +v%Y%m%d%H%M`
     67   QUALIFIER="${DATE}-$ADT_PREVIEW"
     68   [ -n "$BUILD_NUMBER" ] && QUALIFIER="${QUALIFIER}-${BUILD_NUMBER}"
     69 
     70   return 0
     71 }
     72 
     73 function build_plugin() {
     74   sdk/eclipse/scripts/create_all_symlinks.sh
     75 
     76   # Compute the final directory name and remove any leftovers from previous
     77   # runs if any.
     78   BUILD_PREFIX="android-eclipse"
     79   if [ "$INTERNAL_BUILD" ]; then
     80     # append 'eng' qualifier to end of archive name to denote internal build
     81     BUILD_PREFIX="${BUILD_PREFIX}-eng"
     82   fi
     83 
     84   # exclude date from build-zip name so it can be auto-calculated by continuous
     85   # test process unless there's no build number, in which case the date is
     86   # still used (useful for testing)
     87   local preview="${ADT_PREVIEW:+-}${ADT_PREVIEW}"
     88   ZIP_NAME="${BUILD_PREFIX}${preview}-${BUILD_NUMBER:-$DATE}.zip"
     89   [ -d "$DEST_DIR/$BUILD_PREFIX" ] || rm -rfv "$DEST_DIR/$BUILD_PREFIX"
     90 
     91   # Perform the Eclipse build and move the result in $DEST_DIR/android-build
     92   sdk/eclipse/scripts/build_plugins.sh $QUALIFIER $INTERNAL_BUILD -d "$DEST_DIR" -a "$BUILD_PREFIX"
     93 
     94   # Cleanup
     95   [ -d "$QUALIFIER" ] && rm -rfv "$QUALIFIER"
     96 
     97   if [ "$CREATE_ZIP" ]; then
     98     # The result is a full update-site under $DEST_DIR/BUILD_PREFIX
     99     # Zip it and remove the directory.
    100     echo "**** Package in $DEST_DIR"
    101     [ -d "$DEST_DIR/$BUILD_PREFIX" ] || \
    102       die "Build failed to produce $DEST_DIR/$BUILD_PREFIX"
    103     cd "$DEST_DIR"
    104     [ -f "$ZIP_NAME" ] && rm -rfv "$ZIP_NAME"
    105     cd "$BUILD_PREFIX"
    106     zip -9r "../$ZIP_NAME" *
    107     cd .. # back to $DEST_DIR
    108     rm -rfv "$BUILD_PREFIX"  # removes the directory, not the zip
    109     echo "ZIP of Update site available at $DEST_DIR/${ZIP_NAME}"
    110   else
    111     echo "Update site available in $DEST_DIR/$BUILD_PREFIX"
    112   fi
    113 }
    114 
    115 function build_adt_ide() {
    116   local preview="${ADT_PREVIEW}${ADT_PREVIEW:+-}"
    117   if [[ -z $INTERNAL_BUILD ]]; then
    118     # This needs to run from the top android directory
    119     D="$PROG_DIR"
    120     cd "$D/../../../" && echo "Switched to directory $PWD"
    121     for sc in */*/*/build_ide*.sh; do
    122       if [[ -x $sc ]]; then
    123         echo "RUNNING $sc from $PWD"
    124         $sc "$DEST_DIR" "$QUALIFIER" "${preview}${BUILD_NUMBER:-$QUALIFIER}"
    125       else
    126         echo "WARNING: skipping non-exec $sc script"
    127       fi
    128     done
    129   fi
    130 }
    131 
    132 get_params "$@"
    133 check_params
    134 ( build_plugin )
    135 ( build_adt_ide )
    136 
    137