1#!/bin/bash
2
3set -x
4set -e
5
6options="$*"
7option="$1"
8
9tmp=/tmp/test_builds.$$
10rm -f -r ${tmp}
11mkdir -p ${tmp}
12
13errMessages=${tmp}/error_messages.txt
14
15#######
16# Error function
17error() # message
18{
19   echo "ERROR: $1" | tee -a ${errMessages}
20}
21# Check errors
22checkErrors()
23{
24    if [ -s ${errMessages} ] ; then
25        cat ${errMessages}
26	exit 1
27    fi
28}
29#######
30
31os="`uname -s`"
32arch="`uname -p`"
33make=make
34
35if [ "${os}" = "SunOS" ] ; then
36  make=gmake
37  export J7="/opt/java/jdk1.7.0"
38elif [ "${os}" = "Darwin" ] ; then
39  export J7="/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home"
40elif [ "${os}" = "Linux" -a "${arch}" = "x86_64" ] ; then
41  export J7="/usr/lib/jvm/java-7-openjdk-amd64/"
42else
43  echo "What os/arch is this: ${os}/${arch}"
44  exit 1
45fi
46
47# Must have a jdk7
48if [ ! -d ${J7} ] ; then
49  echo "No JDK7 found at: ${J7}"
50  exit 1
51fi
52
53# What sources we use
54fromroot="http://hg.openjdk.java.net/build-infra/jdk8"
55
56# Where we do it
57root="testbuilds"
58mkdir -p ${root}
59
60# Three areas, last three are cloned from first to insure sameness
61t0=${root}/t0
62t1=${root}/t1
63t2=${root}/t2
64t3=${root}/t3
65repolist="${t0} ${t1} ${t2} ${t3}"
66
67# Optional complete clobber
68if [ "${option}" = "clobber" ] ; then
69  for i in ${repolist} ; do
70    rm -f -r ${i}
71  done
72fi
73
74# Get top repos
75if [ ! -d ${t0}/.hg ] ; then
76  rm -f -r ${t0}
77  hg clone ${fromroot} ${t0}
78fi
79for i in ${t1} ${t2} ${t3} ; do
80  if [ ! -d ${i}/.hg ] ; then
81    hg clone ${t0} ${i}
82  fi
83done
84
85# Get repos updated
86for i in ${repolist} ; do
87  ( \
88    set -e \
89    && cd ${i} \
90    && sh ./get_source.sh \
91    || error "Cannot get source" \
92  ) 2>&1 | tee ${i}.get_source.txt
93  checkErrors
94done
95
96# Optional clean
97if [ "${option}" = "clean" ] ; then
98  for i in ${repolist} ; do
99    rm -f -r ${i}/build
100    rm -f -r ${i}/*/build
101    rm -f -r ${i}/*/dist
102  done
103fi
104
105# Check changes on working set files
106for i in ${repolist} ; do
107  ( \
108    set -e \
109    && cd ${i} \
110    && sh ./make/scripts/hgforest.sh status \
111    || error "Cannot check status" \
112  ) 2>&1 | tee ${i}.hg.status.txt
113  checkErrors
114done
115
116# Configure for build-infra building
117for i in ${t1} ${t2} ; do
118  ( \
119    set -e \
120    && cd ${i}/common/makefiles \
121    && sh ../autoconf/configure --with-boot-jdk=${J7} \
122    || error "Cannot configure" \
123  ) 2>&1 | tee ${i}.config.txt
124  checkErrors
125done
126
127# Do build-infra builds
128for i in ${t1} ${t2} ; do
129  ( \
130    set -e \
131    && cd ${i}/common/makefiles \
132    && ${make}  \
133      FULL_VERSION:=1.8.0-internal-b00 \
134      JRE_RELEASE_VERSION:=1.8.0-internal-b00 \
135      USER_RELEASE_SUFFIX:=compare \
136      RELEASE:=1.8.0-internal \
137      VERBOSE= \
138      LIBARCH= \
139         all images \
140    || error "Cannot build" \
141  ) 2>&1 | tee ${i}.build.txt
142  checkErrors
143done
144
145# Compare build-infra builds
146( \
147  sh ${t0}/common/bin/compareimage.sh \
148    ${t1}/build/*/images/j2sdk-image \
149    ${t2}/build/*/images/j2sdk-image \
150    || error "Cannot compare" \
151) 2>&1 | tee ${root}/build-infra-comparison.txt
152checkErrors
153
154# Do old build
155unset JAVA_HOME
156export ALT_BOOTDIR="${J7}"
157( \
158  cd ${t3} \
159  && ${make} FULL_VERSION='"1.8.0-internal" sanity \
160  || error "Cannot sanity" \
161) 2>&1 | tee ${t3}.sanity.txt
162checkErrors
163( \
164  cd ${t3} \
165  && ${make} \
166      FULL_VERSION='"1.8.0-internal" \
167      JRE_RELEASE_VERSION:=1.8.0-internal-b00 \
168      USER_RELEASE_SUFFIX:=compare \
169      RELEASE:=1.8.0-internal \
170  || error "Cannot build old way" \
171) 2>&1 | tee ${t3}.build.txt
172checkErrors
173
174# Compare old build to build-infra build
175( \
176  sh ${t0}/common/bin/compareimage.sh \
177    ${t3}/build/*/j2sdk-image \
178    ${t1}/build/*/images/j2sdk-image \
179    || error "Cannot compare" \
180) 2>&1 | tee ${root}/build-comparison.txt
181checkErrors
182
183exit 0
184
185