summaryrefslogtreecommitdiffstats
path: root/release-helpers/release.sh
blob: 8181bf7bdb5a085d027aca37322f8856ccc989d0 (plain) (blame)
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#! /bin/sh
#
# This script is used to do the mechanics of making an RTEMS release
# from git and associated artifacts:
#  + bootstrapped RTEMS tarball
#  + tarball of user documentation
#  + tarball of generated Doxygen documentation
#  + (TODO) ChangeLog
#
# It is assumed that the user:
#  (a) does all work on a git branch
#  (b) created that branch by hand
#  (c) will push the branch by hand if all went OK
#  (d) publish the artifacts to the ftp site
#
# The script tries to do as much error checking as possible before
# any commits or tags are added to the repository.
#
# TODO:
#   + Can this be used on all repositories? If so, then it needs to guess or
#     be told the repository.
#   + Any other error checking?
#   + Test host environment for more missing programs
#     - Can't build tests without pax installed
#   + Review against cut_release (old, cvs, etc.) and remove cut_release
#     when it is deemed useless for even ideas.

# git log --no-merges -t --stat 7fb7cb439f72b7edaca36f70e8604c52bed49078^C | unexpand -a | sed -e 's/\s\s*$$//' > ChangeLog

check_error()
{
  error=$1
  if [ $error -eq 0 ] ; then
    return
  fi
  shift
  usage
  echo
  echo "ERROR: $* " >&2
  exit $error
}

fatal()
{
  check_error 1 $*
}

usage()
{
cat <<EOF
     -D          - make dot release   (default=no)
     -B          - bump major release (default=no)
     -M MAJOR    - RTEMS Major number (default=not specified)
     -V VERSION  - RTEMS Version      (default=not specified)
     -v          - verbose            (default=no)

Major:   Example 4.11, 4.12
Version: 4.11.0, 4.11.1, 4.11.99.0

An action of making a dot release or bumping the major must be specified.

EOF

if [ ${repo} != "NOT_SET" ] ; then
  echo "An error has occurred and clean up may be needed. The following should"
  echo "help identify what may need to be done for cleanup."

  if [ ${bump_dot_release} = "yes" ] ; then
    echo "  git checkout master"
    echo "  git branch -D ${MAJOR}"
    echo "  git tag -d ${VERSION}"
    echo "  rm -rf rtems-${VERSION}.tar.bz2 rtems-${VERSION}"
    case ${repo} in
      rtems)
        echo "  rm -rf b-doc b-doxy"
        echo "  rtems-doxygen-${VERSION}.tar.bz2 rtems-doxygen-${VERSION}"
        echo "  rtemsdocs-${VERSION}.tar.bz2 rtemsdocs-${VERSION}"
        ;;
    esac
  else
    echo "  git checkout master"
    echo "  git branch -D @WORKING@"
  fi 
fi
}

toggle()
{
  if [ $1 = "no" ] ; then
    echo "yes"
    return
  fi
  echo "no"
}

vecho()
{
  if [ ${verbose} = "yes" ] ; then
    echo $*
  fi
}

check_dep()
{
  type $1 > /dev/null 2>&1
  check_error $? "$1 is not in your PATH"
}

#  Set up variables which control the scripts behavior
verbose=yes
repo=NOT_SET
VERSION=NOT_SET
MAJOR=NOT_SET
bump_dot_release=no
bump_major_version=no

while getopts BDgM:V:v OPT
do
  case "$OPT" in
    D) bump_dot_release=`toggle ${bump_dot_release}` ;;
    B) bump_major_version=`toggle ${bump_major_version}` ;;
    M) MAJOR="${OPTARG}" ;;
    V) VERSION="${OPTARG}" ;;
    v) verbose=`toggle ${verbose}` ;;
    *) usage ; exit 1 ;;
  esac
done

test -r aclocal/version.m4
check_error $? "Not at the top of an RTEMS tree"

check_dep sb-bootstrap
check_dep doxygen
check_dep mscgen
check_dep dot  # install graphviz

if [ ${bump_dot_release} = "no" -a ${bump_major_version} = "no" ] ; then
  fatal "Must select an action: bump major or dot release"
fi

if [  ${VERSION} = "NOT_SET" -a ${MAJOR} = "NOT_SET" ] ; then
  fatal "RTEMS Version and Major value not provided" 
fi

if [ ${VERSION} != "NOT_SET" -a ${MAJOR} = "NOT_SET" ] ; then
  fatal "RTEMS Version provided without providing Major value" 
fi

if [ ${VERSION} = "NOT_SET" -a ${MAJOR} != "NOT_SET" ] ; then
  fatal "Major version provided without providing RTEMS Version value" 
fi

# Crude checks on the VERSION number
if [ ${VERSION} != "NOT_SET" ] ; then
  case ${VERSION} in
    4.1[0-9].[0-9]) ;;  # TBD: This could be a better match
    5.[0-9].[0-9])  ;;  # TBD: This could be a better match
    *) fatal "${VERSION} does not match 4.x.y or 5.x.y"
  esac
fi

# Crude checks on the MAJOR number
if [ ${MAJOR} != "NOT_SET" ] ; then
  case ${MAJOR} in
    4.1[0-9]) ;;  # TBD: This could be a better match
    5.[0-9])  ;;  # TBD: This could be a better match
    *) fatal "${MAJOR} does not match 4.x or 5.x"
  esac
fi

# Must be in a git repository
test -d .git
check_error $? "You are not in a git checkout"

# Do NOT do this on the master
branch=`git branch | grep "*" | awk '{ print $2 }'`
if [ ${branch} = "master" ] ; then
  fatal "You should be on a git branch before running this script"
fi

# If making a dot release, then there are extra requirements.
if [ ${bump_dot_release} = "yes" ] ; then
  # We want to be on the release branch
  test ${branch} = ${MAJOR}
  check_error $? \
    "When making a dot release, you should be a branch named properly. " \
    "For example, when making ${MAJOR}.n, you should be on the ${MAJOR} branch."

  # VERSION should start with MAJOR
  case ${VERSION} in
    ${MAJOR}.[0-9]) ;;  # TBD: This could be a better match
    *) fatal "${VERSION} does not start with ${MAJOR}" ;;
  esac

  # We need to have access to various texi tools to build documentation
  # For CentOS, the RPMs are texinfo-tex and texi2html
  check_dep texi2dvi
  check_dep texi2pdf
  # main tool varies based on texinfo version
  type texi2any >/dev/null 2>&1
  ta=$?
  type texi2html >/dev/null 2>&1
  if [ $? -ne 0 -a ${ta} -ne 0 ] ; then
    fatal "Neither texi2any nor tex2html is available"
  fi

  # We need to have access to SPARC tools to build Doxygen.
  check_dep sparc-rtems${MAJOR}-gcc
fi

##### END OF ERROR CHECKING

# Determine the repository. This is used to trip special actions
repo=`git rev-parse --show-toplevel`
repo=`basename ${repo}`

# For the RTEMS repository, update the aclocal.m4 and VERSION file
update_aclocal_version_for_version()
{
  ACLOCAL_VERSION_M4=" testsuites/aclocal/version.m4 \
    aclocal/version.m4 cpukit/aclocal/version.m4 c/src/aclocal/version.m4"

  RV=${VERSION}
  case ${repo} in
    rtems)
      for f in ${ACLOCAL_VERSION_M4}
      do
        sed -i \
          -e "s|\[_RTEMS_VERSION\],\[.*\]|\[_RTEMS_VERSION\],\[${RV}\]|" ${f}
      done
      sed -i -e "s,\(^RTEMS Version\).*,\1 ${RV}," VERSION
      git add ${ACLOCAL_VERSION_M4} VERSION
      git commit -m "all version.m4, VERSION: Update to ${RV}"
      ;;
    rtems-source-builder)
      # XXX update version.py
      check_error 1 "Need to update version.py"
      ;;
    *)
      sed -i -e "s,\(^RTEMS Version\).*,\1 ${RV}," VERSION
      git add VERSION
      git commit -m "VERSION: Update to ${RV}"
      ;;
  esac
}

# For the RTEMS repository, update the documentation versioning information
update_doc_versions()
{
  date1=`date "+%d %B %Y"`
  date2=`date "+%B %Y"`
  find -name version.texi | while read f
  do
    (echo "@set UPDATED ${date1}" ; 
     echo "@set UPDATED-MONTH ${date2}" ; 
     echo "@set EDITION ${MAJOR}" ; 
     echo "@set VERSION ${VERSION}" ) \
    >${f}
  done
  git add `find doc -name version.texi`
  git commit -m "doc/*/version.texi: Update to ${RV} and current date"
}

# So far, this only occurs with the RTEMS repository
build_doxygen()
{
  set -x
  cpu=sparc
  bsp=leon3
  outdir=${1}
  
  rm -rf b-doxy
  mkdir b-doxy
  cd b-doxy
  ../rtems-${VERSION}/configure \
    --target=${cpu}-rtems4.11 --enable-rtemsbsp=${bsp} \
    --enable-smp --enable-multiprocessing \
    --disable-networking --disable-tests >c.log 2>&1
  make -j3 preinstall >b.log 2>&1
  cd ${cpu}-rtems4.11/c/${bsp}/cpukit

  #mv Doxyfile Doxyfile.tmp
  sed -e "s,^OUTPUT_DIRECTORY.*=.*$,OUTPUT_DIRECTORY = ${outdir}-tmp," \
      -e "s,^STRIP_FROM_PATH.*=.*$,STRIP_FROM_PATH = ," \
      -e "s,^INPUT.*=.*lib.*$,INPUT = ," \
    <Doxyfile >../../../${bsp}/lib/include/Doxyfile
  
  cd ../../../${bsp}/lib/include

  doxygen >doxy.log 2>&1
  check_error $? "Doxygen Build Failed"

  rm -rf ${outdir}
  mv ${outdir}-tmp ${outdir}
}

### Update the various version files
vecho "Updating aclocal version.m4 and VERSION files"
update_aclocal_version_for_version

### Update the documentation
if [ ${repo} = "rtems" ] ; then
  vecho "Updating version and dates in documentation"
  update_doc_versions
fi

# No further actions needed if bumping major version
if [ ${bump_major_version} = "yes" ] ; then
  echo "*** Major version bumped on this branch"
  echo "*** Merge this branch into the master."
  exit 0
fi

### Set a BASE directory variable
BASE=`pwd`

### Check that the tag does not exist
git tag | grep ${VERSION} >/dev/null
if [ $? -eq 0 ] ; then
  check_error 1 "git tag of ${VERSION} already exists"
fi

### Tag the source
git tag ${VERSION}
check_error $? "Unable to git tag"

### Now generate the tarball
if [ ${repo} = "rtems" ] ; then
  vecho "Generating the RTEMS tarball"
  rm -rf rtems-${VERSION} \
         rtems-${VERSION}-not_bootstrapped.tar \
         rtems-${VERSION}.tar.bz2
  git archive --format=tar --prefix=rtems-${VERSION}/ ${VERSION} \
     >rtems-${VERSION}-not_bootstrapped.tar
  check_error $? "Unable to perform git archive"

  tar xf rtems-${VERSION}-not_bootstrapped.tar
  cd rtems-${VERSION}/
  check_error $? "Unable to cd to untarred RTEMS source"

  # bootstrap and then remove unnecessary files
  sb-bootstrap >/dev/null 2>&1
  check_error $? "Unable to bootstrap the RTEMS source code"

  find .  -name "stamp.*" \
       -o -name "autom4te.cache" \
       -o -name "rsb-log-*.txt" \
       | xargs -e rm -rf
  cd ..
  tar cjf rtems-${VERSION}.tar.bz2 rtems-${VERSION}
  check_error $? "Unable to create bootstrapped tar.bz2 for release"

  rm -f rtems-${VERSION}-not_bootstrapped.tar

else
  vecho "Generating the ${repo} tarball"
  git archive --format=tar --prefix=${repo}-${VERSION}/ ${VERSION} \
     | bzip2 -9 >${repo}-${VERSION}.tar.bz2
  check_error $? "Unable to perform git archive on ${repo}"
fi

### RTEMS has special actions after generating the tarball
if [ ${repo} = "rtems" ] ; then
  ### Now generate the documentation
  vecho "Generating the RTEMS documentation tarball"
  rm -rf b-doc rtemsdocs-${VERSION} rtemsdocs-${VERSION}.tar.bz2
  mkdir b-doc
  cd b-doc
  ../rtems-${VERSION}/doc/configure --enable-maintainer-mode \
    --prefix=/opt/rtems-${VERSION} >c.log 2>&1
  check_error $? "Unable to configure RTEMS documentation"

  make >b.log 2>&1
  check_error $? "Unable to build RTEMS documentation"

  make prefix=${BASE}/rtemsdocs-${VERSION} install >i.log 2>&1
  check_error $? "Unable to install RTEMS documentation"

  cd ..
  test -d rtemsdocs-${VERSION}
  check_error $? "Documentation was not installed into temporary location"

  tar cjf rtemsdocs-${VERSION}.tar.bz2 rtemsdocs-${VERSION}
  check_error $? "Unable to create RTEMS Documentation tar.bz2 for release"

  rm -rf b-docs

  ### Now generate Doxygen
  doxyDir=rtems-doxygen-${VERSION}
  doxyOut=${BASE}/${doxyDir}
  rm -rf ${doxyOut}
  build_doxygen ${doxyOut}

  cd ${BASE}
  tar cjf ${doxyDir}.tar.bz2 ${doxyDir}
  check_error $? "Unable to create RTEMS Doxygen tar.bz2 for release"
fi

exit 0