1 #!/bin/bash 2 3 # build script for eclipse adt build on the Linux and Mac platforms 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 and OSX are supported for now 22 # - Do NOT manually invoke this script. Instead use the build_server.sh wrapper 23 # which does some extra preliminary steps (it builds a few libs needed here.) 24 25 26 set -e # abort this script early if any command fails 27 28 # 29 # -- Utility methods -- 30 # 31 32 function printUsage() { 33 echo "Usage: $0 <build_qualifier> [-i] [-d <destination-directory>] [-a <archivePrefix>] " 34 echo "<build_qualifier>: build qualifier string" 35 echo "-i = build internal site. Otherwise, external site will be built" 36 echo "-d = destination directory. Default is $USER/www/no_crawl/. Cannot contain spaces." 37 echo "-a = archive prefix. Cannot contain spaces." 38 } 39 40 function die() { 41 echo $@ 42 exit 1 43 } 44 45 function dieWithUsage() { 46 echo $@ 47 echo 48 printUsage 49 exit 1 50 } 51 52 53 # 54 # -- Setup our custom version of Eclipse -- 55 # 56 57 # The dependency on the linux platform comes from a series of environment 58 # variables that the eclipse ant runner expects. These are defined in the 59 # build.properties file. We can easily support other platforms but would need 60 # to override those values in this script. 61 HOST=`uname` 62 if [ "$HOST" == "Linux" ]; then 63 BASEOS=linux 64 BASEWS=gtk 65 BASEARCH=x86 66 elif [ "$HOST" == "Darwin" ]; then 67 BASEOS=macosx 68 BASEWS=cocoa 69 BASEARCH=x86 70 else 71 die "ERROR: This script is currently only supported on Linux and MacOSX." 72 fi 73 74 75 # Make sure this runs from the sdk/eclipse plugin. 76 D=`dirname "$0"` 77 cd "$D/.." 78 [ `basename "$PWD"` == "eclipse" ] || dieWithUsage "Please run this script from the sdk/eclipse directory" 79 80 # check for number of parameters 81 [ $# -lt 1 ] && dieWithUsage "ERROR: Not enough parameters" 82 83 # check if ECLIPSE_HOME set (ECLIPSE_HOME is were the "eclipse" binary and the 84 # "plugins" sub-directory are located) 85 if [ -z "$ECLIPSE_HOME" ]; then 86 BASE_DIR=/buildbot/eclipse-android 87 88 echo "ECLIPSE_HOME not set, using $BASE_DIR as default" 89 90 if [ ! -d "$BASE_DIR" ]; then 91 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'." 92 fi 93 94 # download the version if not available 95 VERSION="3.5.2" 96 BASE_DIR="$BASE_DIR/$VERSION" 97 scripts/setup_eclipse.sh -p "$BASE_DIR" 98 99 ECLIPSE_HOME="$BASE_DIR/eclipse" # path to installed directory 100 PID_FILE="$BASE_DIR/eclipse.pid" 101 [ -f "$PID_FILE" ] && ECLIPSE_PID=`cat "$PID_FILE"` 102 fi 103 104 echo "PWD=`pwd`" 105 echo "ECLIPSE_HOME=$ECLIPSE_HOME" 106 107 # 108 # -- Site parameters and Build version -- 109 # 110 111 BUILD_VERSION="$1" ; shift 112 113 # parse for build internal site flag. If set, pass in internalSite property to ant scripts 114 if [ "-i" == "$1" ]; then 115 shift 116 echo "Setting for internal site build" 117 SITE_PARAM="-DinternalSite=1 -DupdateSiteSource=$PWD/sites/internal" 118 else 119 SITE_PARAM="-DupdateSiteSource=$PWD/sites/external" 120 fi 121 122 if [ "-d" == $1 ]; then 123 shift 124 echo "Setting destination directory to $1" 125 SITE_PARAM="$SITE_PARAM -DupdateSiteRoot=$1" 126 shift 127 fi 128 129 if [ "-a" == "$1" ]; then 130 shift 131 echo "Setting archivePrefix to $1" 132 SITE_PARAM="$SITE_PARAM -DarchivePrefix=$1" 133 shift 134 fi 135 136 137 # 138 # -- Configuration directory -- 139 # 140 141 # The "configuration directory" will hold the workspace for this build. 142 # If it contains old data the build may fail so we need to clean it first 143 # and create it if it doesn't exist. 144 CONFIG_DIR="../../../out/eclipse-configuration-$BUILD_VERSION" 145 [ -d "$CONFIG_DIR" ] && rm -rfv "$CONFIG_DIR" 146 mkdir -p "$CONFIG_DIR" 147 148 # The "buildConfig" directory contains our customized ant rules 149 BUILDCONFIG="$PWD/buildConfig" 150 151 152 # 153 # -- Find Eclipse Launcher -- 154 # 155 156 # Get the Eclipse launcher and build script to use 157 function findFirst() { 158 for i in "$@"; do 159 if [ -f "$i" ]; then 160 echo "$i" 161 return 162 fi 163 done 164 } 165 166 LAUNCHER=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.equinox.launcher_*.jar` 167 BUILDFILE=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.pde.build_*/scripts/build.xml` 168 169 # make sure we found valid files 170 if [ ! -f "$LAUNCHER" ]; then 171 echo "Installation Error: Eclipse plugin org.eclipse.equinox.launcher...jar not detected. " \ 172 "Found '$LAUNCHER'. Aborting." 173 exit 1 174 fi 175 if [ ! -f "$BUILDFILE" ]; then 176 echo "Installation Error: Eclipse build file org.eclipse.pde.build_.../scripts/build.xml " \ 177 "not detected. Found '$BUILDFILE'. Aborting." 178 exit 1 179 fi 180 181 # 182 # Ensure that the src dir exists since it's empty 183 # 184 mkdir -p $PWD/plugins/com.android.ide.eclipse.adt.overlay/src 185 186 # 187 # -- Print configuration used and actually execute the build -- 188 # 189 190 echo "Eclipse configuration found:" 191 echo " Eclipse Home: $ECLIPSE_HOME" 192 echo " Launcher: $LAUNCHER" 193 echo " Build File: $BUILDFILE" 194 echo " Build Config: $BUILDCONFIG" 195 echo " Config Dir: $CONFIG_DIR" 196 197 # clean input directories to make sure there's nothing left from previous run 198 199 rm -fv *.properties *.xml 200 find . -name "@*" | xargs rm -rfv 201 202 # Now execute the ant runner 203 204 set +e # don't stop on errors anymore, we want to catch them here 205 206 207 java \ 208 -jar $LAUNCHER \ 209 -data "$CONFIG_DIR" \ 210 -configuration "$CONFIG_DIR" \ 211 -application org.eclipse.ant.core.antRunner \ 212 -buildfile $BUILDFILE \ 213 -Dbuilder=$BUILDCONFIG \ 214 -DbuildDirectory=$PWD \ 215 -DforceContextQualifier=$BUILD_VERSION \ 216 -DECLIPSE_HOME=$ECLIPSE_HOME \ 217 -Dbaseos=$BASEOS \ 218 -Dbasews=$BASEWS \ 219 -Dbasearch=$BASEARCH \ 220 $SITE_PARAM 221 RESULT=$? 222 223 if [ "0" != "$RESULT" ]; then 224 echo "JAVA died with error code $RESULT" 225 echo "Dump of build config logs:" 226 for i in "$CONFIG_DIR"/*.log; do 227 if [ -f "$i" ]; then 228 echo "----------------------" 229 echo "--- $i" 230 echo "----------------------" 231 cat "$i" 232 echo 233 fi 234 done 235 fi 236 237 # 238 # -- Cleanup 239 # 240 241 if [ -n "$ECLIPSE_PID" ] && [ -f "$PID_FILE" ]; then 242 rm -fv "$PID_FILE" 243 kill -9 "$ECLIPSE_PID" 244 fi 245 246 # Remove build files left by Eclipse all behind 247 rm -fv *.properties *.xml 248 find . -name "@*" | xargs rm -rfv 249 250 251 # we're done! 252