The Android Open Source Project | 5c11852 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # build script for eclipse adt build on linux platform |
| 4 | # |
| 5 | # Usage: doBuild <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 | # Check which directory this is invoked from |
| 63 | [ "${PWD: -13}" == "tools/eclipse" ] || dieWithUsage "Please run this script from the device/tools/eclipse directory" |
| 64 | |
| 65 | # check for number of parameters |
| 66 | [ $# -lt 1 ] && dieWithUsage "ERROR: Not enough parameters" |
| 67 | |
| 68 | # check if ECLIPSE_HOME set (ECLIPSE_HOME is were the "eclipse" binary and the |
| 69 | # "plugins" sub-directory are located) |
| 70 | if [ -z "$ECLIPSE_HOME" ]; then |
| 71 | BASE_DIR=/buildbot/eclipse-android |
| 72 | |
| 73 | echo "ECLIPSE_HOME not set, using $BASE_DIR as default" |
| 74 | |
| 75 | if [ ! -d "$BASE_DIR" ]; then |
| 76 | 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'." |
| 77 | fi |
| 78 | |
| 79 | # download the version if not available |
| 80 | VERSION="3.4.0" |
| 81 | BASE_DIR="$BASE_DIR/$VERSION" |
| 82 | scripts/setup_eclipse.sh -p "$BASE_DIR" |
| 83 | |
| 84 | ECLIPSE_HOME="$BASE_DIR/eclipse" # path to installed directory |
| 85 | PID_FILE="$BASE_DIR/eclipse.pid" |
| 86 | [ -f "$PID_FILE" ] && ECLIPSE_PID=`cat "$PID_FILE"` |
| 87 | fi |
| 88 | |
| 89 | |
| 90 | # |
| 91 | # -- Site parameters and Build version -- |
| 92 | # |
| 93 | |
| 94 | BUILD_VERSION="$1" ; shift |
| 95 | |
| 96 | # parse for build internal site flag. If set, pass in internalSite property to ant scripts |
| 97 | if [ "-i" == "$1" ]; then |
| 98 | shift |
| 99 | echo "Setting for internal site build" |
| 100 | SITE_PARAM="-DinternalSite=1 -DupdateSiteSource=$PWD/sites/internal" |
| 101 | else |
| 102 | SITE_PARAM="-DupdateSiteSource=$PWD/sites/external" |
| 103 | fi |
| 104 | |
| 105 | if [ "-d" == $1 ]; then |
| 106 | shift |
| 107 | echo "Setting destination directory to $1" |
| 108 | SITE_PARAM="$SITE_PARAM -DupdateSiteRoot=$1" |
| 109 | shift |
| 110 | fi |
| 111 | |
| 112 | if [ "-a" == "$1" ]; then |
| 113 | shift |
| 114 | echo "Setting archivePrefix to $1" |
| 115 | SITE_PARAM="$SITE_PARAM -DarchivePrefix=$1" |
| 116 | shift |
| 117 | fi |
| 118 | |
| 119 | |
| 120 | # |
| 121 | # -- Configuration directory -- |
| 122 | # |
| 123 | |
| 124 | # The "configuration directory" will hold the workspace for this build. |
| 125 | # If it contains old data the build may fail so we need to clean it first |
| 126 | # and create it if it doesn't exist. |
| 127 | CONFIG_DIR="../../out/eclipse-configuration-$BUILD_VERSION" |
| 128 | [ -d "$CONFIG_DIR" ] && rm -rfv "$CONFIG_DIR" |
| 129 | mkdir -p "$CONFIG_DIR" |
| 130 | |
| 131 | # The "buildConfig" directory contains our customized ant rules |
| 132 | BUILDCONFIG="$PWD/buildConfig" |
| 133 | |
| 134 | |
| 135 | # |
| 136 | # -- Find Eclipse Launcher -- |
| 137 | # |
| 138 | |
| 139 | # Get the Eclipse launcher and build script to use |
| 140 | function findFirst() { |
| 141 | for i in "$@"; do |
| 142 | if [ -f "$i" ]; then |
| 143 | echo "$i" |
| 144 | return |
| 145 | fi |
| 146 | done |
| 147 | } |
| 148 | |
| 149 | LAUNCHER=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.equinox.launcher_*.jar` |
| 150 | BUILDFILE=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.pde.build_*/scripts/build.xml` |
| 151 | |
| 152 | # make sure we found valid files |
| 153 | if [ ! -f "$LAUNCHER" ]; then |
| 154 | echo "Installation Error: Eclipse plugin org.eclipse.equinox.launcher...jar not detected. " \ |
| 155 | "Found '$LAUNCHER'. Aborting." |
| 156 | exit 1 |
| 157 | fi |
| 158 | if [ ! -f "$BUILDFILE" ]; then |
| 159 | echo "Installation Error: Eclipse build file org.eclipse.pde.build_.../scripts/build.xml " \ |
| 160 | "not detected. Found '$BUILDFILE'. Aborting." |
| 161 | exit 1 |
| 162 | fi |
| 163 | |
| 164 | |
| 165 | # |
| 166 | # -- Print configuration used and actually execute the build -- |
| 167 | # |
| 168 | |
| 169 | echo "Eclipse configuration found:" |
| 170 | echo " Eclipse Home: $ECLIPSE_HOME" |
| 171 | echo " Launcher: $LAUNCHER" |
| 172 | echo " Build File: $BUILDFILE" |
| 173 | echo " Build Config: $BUILDCONFIG" |
| 174 | echo " Config Dir: $CONFIG_DIR" |
| 175 | |
| 176 | java \ |
| 177 | -jar $LAUNCHER \ |
| 178 | -configuration "$CONFIG_DIR" \ |
| 179 | -application org.eclipse.ant.core.antRunner \ |
| 180 | -buildfile $BUILDFILE \ |
| 181 | -Dbuilder=$BUILDCONFIG \ |
| 182 | -DbuildDirectory=$PWD \ |
| 183 | -DforceContextQualifier=$BUILD_VERSION \ |
| 184 | -DECLIPSE_HOME=$ECLIPSE_HOME \ |
| 185 | $SITE_PARAM |
| 186 | |
| 187 | # |
| 188 | # -- Cleanup |
| 189 | # |
| 190 | |
| 191 | if [ -n "$ECLIPSE_PID" ] && [ -f "$PID_FILE" ]; then |
| 192 | rm -fv "$PID_FILE" |
| 193 | kill -9 "$ECLIPSE_PID" |
| 194 | fi |
| 195 | |
| 196 | # we're done! |