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