Home | History | Annotate | Download | only in scripts
      1 #!/bin/bash
      2 
      3 # build script for eclipse adt build on linux platform
      4 #
      5 # Usage: sdk/eclipse/scripts/build_plugins <build_version> 
      6 #
      7 # It expects environment variable ECLIPSE_HOME to be defined to point to _your_
      8 # version of Eclipse RCP (must have the WTP & GEF plugins available too.)
      9 #
     10 # If ECLIPSE_HOME is not provided, this script will _download_ a reference version
     11 # of Eclipse RCP and install it in a specific location.
     12 # 
     13 # Other properties, ant scripts that drive the build are defined in ./buildConfig
     14 # Currently, this script will create an update site at ${user.home}/www/no_crawl/android-build
     15 # or at the directory specified using "-d"
     16 
     17 # Known Issues:
     18 # - Build does not properly clean up after itself (build server always executes from
     19 #   a clean state.)
     20 # - Script will fail if current absolute path has spaces in it.
     21 # - Only linux is supported for now
     22 
     23 
     24 set -e # abort this script early if any command fails
     25 
     26 #
     27 # -- Utility methods --
     28 # 
     29 
     30 function printUsage() {
     31   echo "Usage: $0 <build_qualifier> [-i] [-d <destination-directory>] [-a <archivePrefix>] "
     32   echo "<build_qualifier>: build qualifier string"
     33   echo "-i = build internal site. Otherwise, external site will be built"
     34   echo "-d = destination directory. Default is $USER/www/no_crawl/. Cannot contain spaces."
     35   echo "-a = archive prefix. Cannot contain spaces."
     36 }
     37 
     38 function die() {
     39   echo $@
     40   exit 1
     41 }
     42 
     43 function dieWithUsage() {
     44   echo $@
     45   echo
     46   printUsage
     47   exit 1
     48 }
     49 
     50 
     51 #
     52 # -- Setup our custom version of Eclipse --
     53 #
     54 
     55 # The dependency on the linux platform comes from a series of environment
     56 # variables that the eclipse ant runner expects. These are defined in the
     57 # build.properties file. We can easily support other platforms but would need
     58 # to override those values in this script.
     59 HOST=`uname`
     60 [ "$HOST" == "Linux" ] || die "ERROR: This script is currently only supported on Linux platform"
     61 
     62 # Make sure this runs from the sdk/eclipse plugin.
     63 D=`dirname "$0"`
     64 cd "$D/.."
     65 [ `basename "$PWD"` == "eclipse" ] || dieWithUsage "Please run this script from the sdk/eclipse directory"
     66 
     67 # check for number of parameters
     68 [ $# -lt 1 ] && dieWithUsage "ERROR: Not enough parameters"
     69 
     70 # check if ECLIPSE_HOME set (ECLIPSE_HOME is were the "eclipse" binary and the
     71 # "plugins" sub-directory are located)
     72 if [ -z "$ECLIPSE_HOME" ]; then
     73   BASE_DIR=/buildbot/eclipse-android
     74 
     75   echo "ECLIPSE_HOME not set, using $BASE_DIR as default"
     76 
     77   if [ ! -d "$BASE_DIR" ]; then
     78     mkdir -p "$BASE_DIR" || die "Please create a directory $BASE_DIR where Eclipse will be installed, i.e. execute 'mkdir -p $BASE_DIR && chown $USER $BASE_DIR'."
     79   fi
     80 
     81   # download the version if not available
     82   VERSION="3.4.0"
     83   BASE_DIR="$BASE_DIR/$VERSION"
     84   scripts/setup_eclipse.sh -p "$BASE_DIR"
     85 
     86   ECLIPSE_HOME="$BASE_DIR/eclipse"      # path to installed directory
     87   PID_FILE="$BASE_DIR/eclipse.pid"
     88   [ -f "$PID_FILE" ] && ECLIPSE_PID=`cat "$PID_FILE"`
     89 fi
     90 
     91 echo "PWD=`pwd`"
     92 echo "ECLIPSE_HOME=$ECLIPSE_HOME"
     93 
     94 #
     95 # -- Site parameters and Build version --
     96 #
     97 
     98 BUILD_VERSION="$1" ; shift
     99 
    100 # parse for build internal site flag. If set, pass in internalSite property to ant scripts
    101 if [ "-i" == "$1" ]; then
    102   shift
    103   echo "Setting for internal site build"
    104   SITE_PARAM="-DinternalSite=1 -DupdateSiteSource=$PWD/sites/internal"
    105 else
    106   SITE_PARAM="-DupdateSiteSource=$PWD/sites/external"
    107 fi
    108 
    109 if [ "-d" == $1 ]; then
    110   shift
    111   echo "Setting destination directory to $1"
    112   SITE_PARAM="$SITE_PARAM -DupdateSiteRoot=$1"
    113   shift
    114 fi
    115 
    116 if [ "-a" == "$1" ]; then
    117   shift
    118   echo "Setting archivePrefix to $1"
    119   SITE_PARAM="$SITE_PARAM -DarchivePrefix=$1"
    120   shift
    121 fi
    122 
    123 
    124 #
    125 # -- Configuration directory --
    126 #
    127 
    128 # The "configuration directory" will hold the workspace for this build.
    129 # If it contains old data the build may fail so we need to clean it first
    130 # and create it if it doesn't exist.
    131 CONFIG_DIR="../../../out/eclipse-configuration-$BUILD_VERSION"
    132 [ -d "$CONFIG_DIR" ] && rm -rfv "$CONFIG_DIR"
    133 mkdir -p "$CONFIG_DIR"
    134 
    135 # The "buildConfig" directory contains our customized ant rules
    136 BUILDCONFIG="$PWD/buildConfig"
    137 
    138 
    139 #
    140 # -- Find Eclipse Launcher --
    141 #
    142 
    143 # Get the Eclipse launcher and build script to use
    144 function findFirst() {
    145   for i in "$@"; do
    146     if [ -f "$i" ]; then
    147       echo "$i"
    148       return
    149     fi
    150   done
    151 }
    152 
    153 LAUNCHER=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.equinox.launcher_*.jar`
    154 BUILDFILE=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.pde.build_*/scripts/build.xml`
    155 
    156 # make sure we found valid files
    157 if [ ! -f "$LAUNCHER" ]; then
    158   echo "Installation Error: Eclipse plugin org.eclipse.equinox.launcher...jar not detected. " \
    159        "Found '$LAUNCHER'. Aborting."
    160   exit 1
    161 fi
    162 if [ ! -f "$BUILDFILE" ]; then
    163   echo "Installation Error: Eclipse build file org.eclipse.pde.build_.../scripts/build.xml " \
    164        "not detected. Found '$BUILDFILE'. Aborting."
    165   exit 1
    166 fi
    167 
    168 
    169 #
    170 # -- Print configuration used and actually execute the build --
    171 #
    172 
    173 echo "Eclipse configuration found:"
    174 echo "  Eclipse Home: $ECLIPSE_HOME"
    175 echo "  Launcher:     $LAUNCHER"
    176 echo "  Build File:   $BUILDFILE"
    177 echo "  Build Config: $BUILDCONFIG"
    178 echo "  Config Dir:   $CONFIG_DIR"
    179 
    180 # clean input directories to make sure there's nothing left from previous run
    181 
    182 rm -fv *.properties *.xml
    183 find . -name "@*" | xargs rm -rfv
    184 
    185 # Now execute the ant runner
    186 
    187 set +e  # don't stop on errors anymore, we want to catch there here
    188 
    189 java \
    190   -jar $LAUNCHER \
    191   -data "$CONFIG_DIR" \
    192   -configuration "$CONFIG_DIR" \
    193   -application org.eclipse.ant.core.antRunner \
    194   -buildfile $BUILDFILE \
    195   -Dbuilder=$BUILDCONFIG \
    196   -DbuildDirectory=$PWD \
    197   -DforceContextQualifier=$BUILD_VERSION \
    198   -DECLIPSE_HOME=$ECLIPSE_HOME \
    199   $SITE_PARAM
    200 RESULT=$?
    201 
    202 if [ "0" != "$RESULT" ]; then
    203     echo "JAVA died with error code $RESULT"
    204     echo "Dump of build config logs:"
    205     for i in "$CONFIG_DIR"/*.log; do
    206         if [ -f "$i" ]; then
    207             echo "----------------------"
    208             echo "--- $i"
    209             echo "----------------------"
    210             cat "$i"
    211             echo
    212         fi
    213     done
    214 fi
    215 
    216 #
    217 # -- Cleanup
    218 #
    219 
    220 if [ -n "$ECLIPSE_PID" ] && [ -f "$PID_FILE" ]; then
    221   rm -fv "$PID_FILE"
    222   kill -9 "$ECLIPSE_PID"
    223 fi
    224 
    225 # we're done!
    226