blob: 5f94ca060e986d6957266940a9121a2fca449766 [file] [log] [blame]
The Android Open Source Project5c118522008-10-21 07:00:00 -07001#!/bin/bash
2
3# build script for eclipse adt build on linux platform
4#
The Android Open Source Projecte943f2f2008-12-17 18:04:04 -08005# Usage: development/tools/eclipse/scripts/build_plugins <build_version>
The Android Open Source Project5c118522008-10-21 07:00:00 -07006#
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
24set -e # abort this script early if any command fails
25
26#
27# -- Utility methods --
28#
29
30function 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
38function die() {
39 echo $@
40 exit 1
41}
42
43function 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.
59HOST=`uname`
60[ "$HOST" == "Linux" ] || die "ERROR: This script is currently only supported on Linux platform"
61
The Android Open Source Projecte943f2f2008-12-17 18:04:04 -080062# Make sure this runs from the tools/eclipse plugin.
63D=`dirname "$0"`
64cd "$D/.."
65[ `basename "$PWD"` == "eclipse" ] || dieWithUsage "Please run this script from the device/tools/eclipse directory"
The Android Open Source Project5c118522008-10-21 07:00:00 -070066
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)
72if [ -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"`
89fi
90
The Android Open Source Projecte943f2f2008-12-17 18:04:04 -080091echo "PWD=`pwd`"
92echo "ECLIPSE_HOME=$ECLIPSE_HOME"
The Android Open Source Project5c118522008-10-21 07:00:00 -070093
94#
95# -- Site parameters and Build version --
96#
97
98BUILD_VERSION="$1" ; shift
99
100# parse for build internal site flag. If set, pass in internalSite property to ant scripts
101if [ "-i" == "$1" ]; then
102 shift
103 echo "Setting for internal site build"
104 SITE_PARAM="-DinternalSite=1 -DupdateSiteSource=$PWD/sites/internal"
105else
106 SITE_PARAM="-DupdateSiteSource=$PWD/sites/external"
107fi
108
109if [ "-d" == $1 ]; then
110 shift
111 echo "Setting destination directory to $1"
112 SITE_PARAM="$SITE_PARAM -DupdateSiteRoot=$1"
113 shift
114fi
115
116if [ "-a" == "$1" ]; then
117 shift
118 echo "Setting archivePrefix to $1"
119 SITE_PARAM="$SITE_PARAM -DarchivePrefix=$1"
120 shift
121fi
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.
The Android Open Source Projecte943f2f2008-12-17 18:04:04 -0800131CONFIG_DIR="../../../out/eclipse-configuration-$BUILD_VERSION"
The Android Open Source Project5c118522008-10-21 07:00:00 -0700132[ -d "$CONFIG_DIR" ] && rm -rfv "$CONFIG_DIR"
133mkdir -p "$CONFIG_DIR"
134
135# The "buildConfig" directory contains our customized ant rules
136BUILDCONFIG="$PWD/buildConfig"
137
138
139#
140# -- Find Eclipse Launcher --
141#
142
143# Get the Eclipse launcher and build script to use
144function findFirst() {
145 for i in "$@"; do
146 if [ -f "$i" ]; then
147 echo "$i"
148 return
149 fi
150 done
151}
152
153LAUNCHER=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.equinox.launcher_*.jar`
154BUILDFILE=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.pde.build_*/scripts/build.xml`
155
156# make sure we found valid files
157if [ ! -f "$LAUNCHER" ]; then
158 echo "Installation Error: Eclipse plugin org.eclipse.equinox.launcher...jar not detected. " \
159 "Found '$LAUNCHER'. Aborting."
160 exit 1
161fi
162if [ ! -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
166fi
167
168
169#
170# -- Print configuration used and actually execute the build --
171#
172
173echo "Eclipse configuration found:"
174echo " Eclipse Home: $ECLIPSE_HOME"
175echo " Launcher: $LAUNCHER"
176echo " Build File: $BUILDFILE"
177echo " Build Config: $BUILDCONFIG"
178echo " Config Dir: $CONFIG_DIR"
179
The Android Open Source Projecte943f2f2008-12-17 18:04:04 -0800180# clean input directories to make sure there's nothing left from previous run
181
182rm -fv *.properties *.xml
183find . -name "@*" | xargs rm -rfv
184
185# Now execute the ant runner
186
187set +e # don't stop on errors anymore, we want to catch there here
188
The Android Open Source Project5c118522008-10-21 07:00:00 -0700189java \
190 -jar $LAUNCHER \
The Android Open Source Projecte943f2f2008-12-17 18:04:04 -0800191 -data "$CONFIG_DIR" \
The Android Open Source Project5c118522008-10-21 07:00:00 -0700192 -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
The Android Open Source Projecte943f2f2008-12-17 18:04:04 -0800200RESULT=$?
201
202if [ "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
214fi
The Android Open Source Project5c118522008-10-21 07:00:00 -0700215
216#
217# -- Cleanup
218#
219
220if [ -n "$ECLIPSE_PID" ] && [ -f "$PID_FILE" ]; then
221 rm -fv "$PID_FILE"
222 kill -9 "$ECLIPSE_PID"
223fi
224
225# we're done!