aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/setup.sh
blob: 813d2772ca77d37947f05ff2010cfef98a071025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#!/bin/bash

#setup Yocto Eclipse plug-in build environment for Neon.1
#comment out the following line if you wish to use your own http proxy settings
#export http_proxy=http://proxy.yourproxyinfo.com:8080

help ()
{
  echo -e "\nThis script sets up the Yocto Project Eclipse plugins build environment"
  echo -e "All files are downloaded from the Yocto Project mirror by default\n"
  echo -e "Usage: $0 [-u|--upstream] [-q|--quiet]\n";
  echo "Options:"
  echo -e "--upstream - download from the upstream Eclipse repository\n"
  echo -e "--quiet - suppress installation trace\n"
  echo -e "Example: $0 --upstream\n";
  exit 1;
}

err_exit()
{
  echo "[FAILED $1] $2"
  exit $1
}

OPTS="$@"
GETOPT=`getopt -o huq --long help,upstream,quiet -n 'setup.sh' -- $OPTS`
STATUS=$?

[ $STATUS -eq 0 ] || err_exit $STATUS "Problem parsing options: $OPTS"

eval set -- "$GETOPT"

# By default, do not download Eclipse archives or features from
# upstream mirrors
USE_UPSTREAM=0

# Enable P2 debug traces by default
P2_INSTALL_TRACE=1

while true; do
  case $1 in
    -h|--help) help; shift;;
    -u|--upstream) USE_UPSTREAM=1; shift;;
    -q|--quiet) P2_INSTALL_TRACE=0; shift;;
    --) shift; break;;
    *) break;;
  esac
done

uname_s=`uname -s`
uname_m=`uname -m`
case ${uname_s}${uname_m} in
  Linuxppc*) ep_arch=linux-gtk-ppc
             cdt_arch=linux.ppc
             ;;
  Linuxx86_64*) ep_arch=linux-gtk-x86_64
                cdt_arch=linux.x86_64
                ;;
  Linuxi*86) ep_arch=linux-gtk
             cdt_arch=linux.x86
             ;;
  *)
    echo "Unknown ${uname_s}${uname_m}"
    exit 1
    ;;
esac

#make sure that the utilities we need exist
command -v wget > /dev/null 2>&1 || { echo >&2 "wget not found. Aborting installation."; exit 1; }
command -v tar > /dev/null 2>&1 || { echo >&2 "tar not found. Aborting installation."; exit 1; }

#parsing proxy URLS
url=${http_proxy}
if [ "x$url" != "x" ]; then
    proto=`echo $url | grep :// | sed -e 's,^\(.*://\).*,\1,g'`
    url=`echo $url | sed s,$proto,,g`
    userpass=`echo $url | grep @ | cut -d@ -f1`
    user=`echo $userpass | cut -d: -f1`
    pass=`echo $userpass | grep : | cut -d: -f2`
    url=`echo $url | sed s,$userpass@,,g`
    host=`echo $url | cut -d: -f1`
    port=`echo $url | cut -d: -f2 | sed -e 's,[^0-9],,g'`
    [ "x$host" = "x" ] && err_exit 1 "Undefined proxy host"
    PROXY_PARAM="-Dhttp.proxySet=true -Dhttp.proxyHost=$host"
    [ "x$port" != "x" ] && PROXY_PARAM="${PROXY_PARAM} -Dhttp.proxyPort=$port"
fi

echo "#### Checking that Java is available ####"
if type -p java; then
    echo java found in PATH
    _java=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
    echo java found in JAVA_HOME
    _java="$JAVA_HOME/bin/java"
else
    err_exit 2 "no java"
fi
echo "#### Checking that the appropriate Java version is available ####"
JAVA_VER_STRING=1.8
JAVA_VER_INT=001008
if [[ "$_java" ]]; then
    version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
    echo java version as string = $version
    version_int=$(echo "$version" | awk -F. '{printf("%03d%03d",$1,$2);}')
    echo java version as integer = $version_int
    if [ $version_int -lt $JAVA_VER_INT ]; then
        err_exit 1 "Java version must be $JAVA_VER_STRING+"
    fi
fi

# prepare the base Eclipse installation in folder "eclipse"
ep_rel="R-"
ep_ver="4.7.3a"
ep_date="-201803300640"
P2_disabled=false
P2_no_dropins=false


if [ ! -f eclipse/plugins/org.eclipse.swt_3.106.3.v20180329-0507.jar ]; then

  pushd .

  if [ ! -d eclipse -o -h eclipse ]; then
    if [ -d eclipse-${ep_ver}-${ep_arch} ]; then
      rm -rf eclipse-${ep_ver}-${ep_arch}
    fi
    mkdir eclipse-${ep_ver}-${ep_arch}
    cd eclipse-${ep_ver}-${ep_arch}
  else
    rm -rf eclipse
  fi

  # Eclipse SDK: Need the SDK so we can link into docs
  echo -e "\nPlease wait. Downloading Eclipse SDK ${ep_rel}${ep_ver}${ep_date} \n"

  if [ $USE_UPSTREAM -eq 1 ]
  then
        wget "http://archive.eclipse.org/eclipse/downloads/drops4/${ep_rel}${ep_ver}${ep_date}/eclipse-SDK-${ep_ver}-${ep_arch}.tar.gz"
  else

        #
        # The eclipse-full mirror on:
        #
        #   https://downloads.yoctoproject.org/eclipse-full/eclipse/downloads/drops4/...
        #
        # is mirrored from upstream:
        #
        #   https://download.eclipse.org/eclipse/downloads/drops4/...
        #
        # although the upstream appears to only host the lastest 3
        # Eclipse releases. On the other hand, the eclipse partial
        # mirror on:
        #
        #   https://downloads.yoctoproject.org/eclipse/downloads/drops4/...
        #
        # is manually managed where files with extension matching
        # *linux-gtk-x86_64.tar.gz will be copied from the full mirror
        # to the partial mirror so that the partial mirror such that
        # the eclipse archives that's been mirrored would always be
        # cached in the partial mirror even after it has been removed
        # from the full mirror. For more details, see:
        #
        #   https://bugzilla.yoctoproject.org/show_bug.cgi?id=13101#c17
        #

        wget "http://downloads.yoctoproject.org/eclipse/downloads/drops4/${ep_rel}${ep_ver}${ep_date}/eclipse-SDK-${ep_ver}-${ep_arch}.tar.gz"
  fi

  echo -e "Please wait. Extracting Eclipse SDK: eclipse-SDK-${ep_ver}-${ep_arch}.tar.gz\n"

  tar xfz eclipse-SDK-${ep_ver}-${ep_arch}.tar.gz || err_exit $? "extracting Eclipse SDK failed"

  rm eclipse-SDK-${ep_ver}-${ep_arch}.tar.gz

  popd

  if [ ! -d eclipse -o -h eclipse ]; then
    if [ -e eclipse ]; then
      rm eclipse
    fi
    ln -s eclipse-${ep_ver}-${ep_arch}/eclipse eclipse
  fi

  # Disable P2 mirrors if we're not using upstream URLs to download
  # Eclipse artifacts and features. The following wiki page suggests
  # adding -vmargs -Declipse.p2.mirrors=false at the end of the Java
  # command line, in our case this means when the P2 director being
  # invoked for feature installation:
  #
  #   https://wiki.eclipse.org/Equinox/p2/p2.mirrorsURL#Avoiding_mirrors.2C_even_when_using_p2.mirrorsURL
  #
  # Unfortunate this doesn't seem to work, so instead we modify the
  # generated config.ini to force P2 to not use mirrors. This should be
  # fine for as long as the eclipse installation directory which
  # contains the modified config.ini is only used for building the
  # plugins.

  [ $USE_UPSTREAM -eq 0 ] && echo "eclipse.p2.mirrors=false" >> eclipse/configuration/config.ini

fi

if [ ! -f eclipse/startup.jar ]; then

  pushd .

  cd eclipse/plugins

  if [ -h ../startup.jar ]; then
    rm ../startup.jar
  fi

  LAUNCHER="`ls org.eclipse.equinox.launcher_*.jar | sort | tail -1`"

  if [ "x${LAUNCHER}" != "x" ]; then
    echo "eclipse LAUNCHER=${LAUNCHER}"
    ln -s plugins/${LAUNCHER} ../startup.jar
  else
    echo "Eclipse: NO startup.jar LAUNCHER FOUND!"
  fi
  popd
fi

LAUNCHER="eclipse/startup.jar"

#$1: repository_url
#$2: featureId
#$3: 'all' or 'max' or 'min', 'max' if not specified
get_version()
{
  local remote_vers="`java ${PROXY_PARAM} \
    -jar ${LAUNCHER} \
    -application org.eclipse.equinox.p2.director \
    -destination ./eclipse \
    -profile SDKProfile \
    -repository $1 \
    -list $2\
    | awk 'BEGIN { FS="=" } { print $2 }'`"

  #find larget remote vers
  local remote_ver="`echo ${remote_vers} | cut -d ' ' -f1`"
  case $3 in
    all)
      remote_ver=${remote_vers}
      ;;
    min)
      for i in ${remote_vers}; do
        [ "${remote_ver}" \> "$i" ] && remote_ver="$i"
      done
      ;;
    *)
      for i in ${remote_vers}; do
        [ "${remote_ver}" \< "$i" ] && remote_ver="$i"
      done
      ;;
  esac

  echo ${remote_ver}
}

# $1 unitId
# $2 min version
# $3 max version (optional)
check_local_version()
{
  curdir=`pwd`
  version="`get_version file:///${curdir}/eclipse/p2/org.eclipse.equinox.p2.engine/profileRegistry/SDKProfile.profile $1`"
  [ "$version" \< "$2" ] && return 1
  if [ "x$3" != "x" ]; then
    [ "$version" \> "$3" ] && return -1
  fi
  return 0
}

# install a feature with version requirement [min, max]
#$1: reporsitory url
#$2: featureId
#$3: min version
#$4: max version(optional)
update_feature_remote()
{
  [ $# -lt 3 ] && err_exit 1 "update_feature_remote: invalid parameters, $*"
  echo -e "\nPlease wait. Installing $2 $3 $4"
  check_local_version $2 $3 $4 && echo "Feature $2 is already installed" && return 0
  local installIU=""
  local all_versions=$(get_version $1 $2 'all')

  echo "Feature $2 versions available: $all_versions"

  if [ "x$4" != "x" ]; then
      #has max version requirement
      for i in $all_versions; do
        if [ "$i" \> "$3" ] || [ "$i" = "$3" ] && [ "$i" \< "$4" ]; then
          [ "$i" \> "$installIU" ] && installIU=$i
        fi
      done
  else
      #only has minimum version requirement
      for i in $all_versions; do
        if [ "$i" \> "$3" ] || [ "$i" = "$3" ]; then
          installIU=$i
          break
        fi
      done
  fi

  [ "x$installIU" = "x" ] && err_exit 1 "Can NOT find candidates of $2 version($3, $4) at $1!"

  TRACE_INI=`pwd`/trace.ini

  if [ "$P2_INSTALL_TRACE" == "1" ]; then
    echo "org.eclipse.equinox.p2.core/debug=true" > $TRACE_INI
    echo "org.eclipse.equinox.p2.core/artifacts/mirrors=true" >> $TRACE_INI
    TRACE_OPTS="-debug $TRACE_INI"
  else
    rm -f $TRACE_INI
    TRACE_OPTS=
  fi

  installIU="$2/$installIU"
  java ${PROXY_PARAM} -jar ${LAUNCHER} \
    $TRACE_OPTS \
    -application org.eclipse.equinox.p2.director \
    -destination ./eclipse \
    -profile SDKProfile \
    -repository $1 \
    -installIU ${installIU} || err_exit $? "installing ${installIU} failed"
}

#Main Site
if [ $USE_UPSTREAM -eq 1 ]
then
        MAIN_SITE="http://download.eclipse.org/releases/oxygen"
        TM_SITE="http://download.eclipse.org/tm/updates/4.0"
        TM_TERMINAL_SITE="http://download.eclipse.org/tm/terminal/marketplace"
else
        MAIN_SITE="http://downloads.yoctoproject.org/eclipse-full/releases/oxygen/"
        TM_SITE="http://downloads.yoctoproject.org/eclipse-full/tm/updates/4.0/"
        TM_TERMINAL_SITE="http://downloads.yoctoproject.org/eclipse-full/tm/terminal/marketplace"
fi

#Update Site - We have a full mirror of eclipse now, so default to that
if [ $USE_UPSTREAM -eq 1 ]
then
        UPDATE_SITE="http://download.eclipse.org/eclipse/updates/4.7"
else
        UPDATE_SITE="http://downloads.yoctoproject.org/eclipse-full/eclipse/updates/4.7/"
fi

# CDT features from simrel
update_feature_remote ${MAIN_SITE} org.eclipse.cdt.sdk.feature.group 9.4.3
update_feature_remote ${MAIN_SITE} org.eclipse.cdt.launch.remote.feature.group 9.4.3
update_feature_remote ${MAIN_SITE} org.eclipse.cdt.autotools.feature.group 9.4.3

# TM Terminal features from simrel
update_feature_remote ${MAIN_SITE} org.eclipse.tm.terminal.feature.feature.group 4.3.0
update_feature_remote ${MAIN_SITE} org.eclipse.tm.terminal.view.rse.feature.feature.group 4.3.0
update_feature_remote ${MAIN_SITE} org.eclipse.tm.terminal.control.feature.feature.group 4.3.0

# Trace Compass features from simrel
update_feature_remote ${MAIN_SITE} org.eclipse.tracecompass.lttng2.ust.feature.group 3.3.0

# Extra features from main update site
update_feature_remote ${UPDATE_SITE} org.eclipse.osgi.compatibility.plugins.feature.feature.group 1.1.1

# RSE features from update site
update_feature_remote ${TM_SITE} org.eclipse.rse.sdk.feature.group 3.7.0
update_feature_remote ${TM_SITE} org.eclipse.rse.terminals.feature.group 3.8.0

echo -e "\nYour build environment is successfully created."
echo -e "\nPlease execute the following command to build the plugins and their documentation."
echo -e "\nThe build log will be stored at `pwd`/build.log."

echo -e "\nECLIPSE_HOME=`pwd`/eclipse `dirname $0`/build.sh <plugin branch or tag name> <documentation branch or tag name> <release name> 2>&1 | tee -a build.log\n"

exit 0