xref: /petsc/lib/petsc/bin/maint/builddist (revision d40cffd3d81bd7714bdeb147e9a844f43a359f65)
1#!/bin/bash -ex
2#
3# This script builds the PETSc tar file distribution
4#
5# Usage: builddist petscrepo [branch/commit] [version-suffix]
6#
7# Notes:
8#  default for branch/commit is 'main'
9#  when version-suffix="SETVERSION", obtain it from include/petscversion.h
10#
11# example usages:
12#   builddist /sandbox/petsc/petsc.clone balay/foo [creates petsc-HASH.tar.gz]
13#   builddist /sandbox/petsc/petsc.clone main ver-suffix [creates petsc-ver-suffix.tar.gz]
14#   builddist /sandbox/petsc/petsc.clone release SETVERSION [creates petsc-3.24.5.tar.gz]
15#
16echo "Starting date: `date +'%a, %d %b %Y %H:%M:%S %z'`"
17#
18# ignore command line options in CI mode - and build tarball from current state setup by CI
19if [ ! -z "${CI_PIPELINE_ID+x}" ]; then
20  petscrepo=`pwd -P`
21elif [ $# = 3 ]; then
22  petscrepo=$1
23  branch=$2
24  version=-$3
25elif [ $# = 2 ]; then
26  petscrepo=$1
27  branch=$2
28elif [ $# = 1 ]; then
29  petscrepo=$1
30  branch='main'
31else
32  echo 'Error: petscrepo not specified. Usge: builddist petscrepo'
33  exit
34fi
35
36# check petscrepo to be valid
37if [ ! -d $petscrepo ]; then
38  echo 'Error: dir $petscrepo does not exist'
39  exit
40fi
41
42if [ ! -d $petscrepo/.git ]; then
43  echo 'Error: dir $petscrepo is not a git repo'
44  exit
45fi
46
47# Initialize vars
48ODIR=`pwd -P`
49PETSC_ARCH=arch-docs; export PETSC_ARCH
50PETSC_DIR=`cd $petscrepo;pwd -P`; export PETSC_DIR
51
52
53# Clean and Update the git repository and check for branch [when not in CI]
54if [ -z "${CI_PIPELINE_ID+x}" ]; then
55  cd $PETSC_DIR
56  /bin/rm -rf $PETSC_DIR/$PETSC_ARCH
57  git clean -q -f -d -x
58  git fetch -q origin $branch
59  if [ "$?" != "0" ]; then
60    echo 'Error: branch: $branch does not exist in $PETSC_DIR'
61    exit
62  fi
63  git checkout -f FETCH_HEAD
64fi
65
66pdir=`basename $PETSC_DIR`
67# Create a tmp dir
68tmpdir=$(mktemp -d -t petsc-dist.$USER.XXXXXX)
69
70# check petscversion.h and set the version string
71version_release=`grep '^#define PETSC_VERSION_RELEASE ' include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`
72version_major=`grep '^#define PETSC_VERSION_MAJOR ' include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`
73version_minor=`grep '^#define PETSC_VERSION_MINOR ' include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`
74version_subminor=`grep '^#define PETSC_VERSION_SUBMINOR ' include/petscversion.h |tr -s ' ' | cut -d ' ' -f 3`
75
76#generated a couple of more values
77version_date=`date +"%b %d, %Y"`
78version_git=`git describe --match "v*"`
79version_date_git=`git log -1 --pretty=format:%ci`
80if [ ${version}foo = foo ]; then
81    version=-`git rev-parse --short HEAD`
82elif [ ${version} = -SETVERSION ]; then
83  if  [ ${version_release} = 0 ]; then
84    version=-${version_major}.$((version_minor+1)).dev0
85  elif [ ${version_release} = 1 ]; then
86    version=-${version_major}.${version_minor}.${version_subminor}
87  else
88    echo "Unknown PETSC_VERSION_RELEASE: ${version_release}"
89    exit
90  fi
91fi
92echo "Building $ODIR/petsc$version.tar.gz, $ODIR/petsc-with-docs$version.tar.gz, and $ODIR/petsc4py$version.tar.gz"
93
94# build PETSc docs (and include petsc4py docs within).
95VENV=$PETSC_DIR/venv-petsc-docs
96python3 -m venv $VENV
97source $VENV/bin/activate
98cd $PETSC_DIR/doc
99python3 -m pip install -r requirements.txt
100PETSCBUIDTARBALL=1 make html BUILDDIR="../docs" SPHINXOPTS="-T -E -j 1"
101mv ../docs/html/* ../docs/html/.[!.]* ../docs
102make latexpdf SPHINXOPTS="-j 1" && cp _build/latex/manual.pdf ../docs/manual/
103
104# build petsc4py tarball (docs are no longer built here)
105cd $PETSC_DIR/src/binding/petsc4py
106  rm -rf petsc-doc-env # remove python2 env created when building petsc+petsc4py docs
107  make srcclean docsclean
108  make sdist PYTHON=python3 SHELL=/bin/bash
109  cp dist/petsc4py-*.tar.gz $tmpdir/
110  make srcclean docsclean
111
112# Cleanup
113cd $PETSC_DIR
114  git clean -q -f -d -x config doc
115  rm -rf docs/doctrees doc/images
116
117# now tar up the PETSc tree
118cd $PETSC_DIR/..
119cat ${PETSC_DIR}/lib/petsc/bin/maint/xclude | sed -e s/petsc-dist/$pdir/ > $tmpdir/xclude
120/bin/tar --create --file $tmpdir/petsc.tar --exclude-from  $tmpdir/xclude $pdir
121cd $tmpdir
122/bin/tar xf $tmpdir/petsc.tar
123# just make sure we are not doing 'mv petsc petsc'
124if [ ! -d petsc$version ]; then
125  /bin/mv $pdir petsc$version
126fi
127#
128# Before Creating the final tarfile, make changes to the bmakefiles/makefiles,
129# create tagfiles etc. permissions etc.
130#
131# Eliminate chmods in the makefile & conf/rules
132cd $tmpdir/petsc$version
133/bin/mv makefile makefile.bak
134/bin/grep -v 'chmod' makefile.bak > makefile
135/bin/rm -f makefile.bak
136
137/bin/mv lib/petsc/conf/rules lib/petsc/conf/rules.bak
138/bin/grep -v 'chmod' lib/petsc/conf/rules.bak > lib/petsc/conf/rules
139/bin/rm -f  lib/petsc/conf/rules.bak
140
141#add in PETSC_VERSION_DATE, PETSC_VERSION_GIT, PETSC_VERSION_DATE_GIT
142echo Using PETSC_VERSION_DATE: ${version_date}
143echo Using PETSC_VERSION_GIT: ${version_git}
144echo Using PETSC_VERSION_DATE_GIT: ${version_date_git}
145/bin/mv include/petscversion.h include/petscversion.h.bak
146cat include/petscversion.h.bak | \
147  sed -e "s/#define PETSC_VERSION_DATE\ .*/#define PETSC_VERSION_DATE       \"${version_date}\"/" | \
148  sed -e "s/#define PETSC_VERSION_GIT\ .*/#define PETSC_VERSION_GIT        \"${version_git}\"/" | \
149  sed -e "s/#define PETSC_VERSION_DATE_GIT\ .*/#define PETSC_VERSION_DATE_GIT   \"${version_date_git}\"/" \
150  > include/petscversion.h
151/bin/rm -f include/petscversion.h.bak
152
153# just to be sure
154/bin/rm -rf make.log* configure.log* RDict.* RESYNC PENDING
155# eliminate .pyc files if any
156/usr/bin/find . -type f -name "*.pyc" -exec /bin/rm -f {} \;
157# eliminate misc files mercurial leaves
158/usr/bin/find . -type f -name "*.orig" -exec /bin/rm -f {} \;
159# Create EMACS-TAGS
160cd $tmpdir/petsc$version; ${PETSC_DIR}/lib/petsc/bin/maint/generateetags.py
161
162# Set the correct file permissions.
163cd $tmpdir
164chmod -R a-w petsc$version
165chmod -R u+w petsc$version
166chmod -R a+r petsc$version
167find petsc$version -type d -name "*" -exec chmod a+x {} \;
168
169# Now create the tar files
170cd $tmpdir
171/bin/tar -czf $ODIR/petsc-with-docs$version.tar.gz petsc$version
172
173# create lite version
174/bin/rm -rf $tmpdir/petsc$version/docs $tmpdir/petsc$version/zope $tmpdir/petsc$version/config/BuildSystem/docs $tmpdir/petsc$version/config/examples/old
175find $tmpdir/petsc$version -type f -name "*.html" -exec rm {} \;
176# recreate EMACS-TAGS [after deletion]
177cd $tmpdir/petsc$version; ${PETSC_DIR}/lib/petsc/bin/maint/generateetags.py
178# generate PKG-INFO for updating PETSc version at pypi
179cd $tmpdir/petsc$version && python setup.py egg_info && /bin/cp petsc.egg-info/PKG-INFO . && /bin/rm -rf petsc.egg-info config/pypi
180
181cd $tmpdir
182/bin/tar -czf $ODIR/petsc$version.tar.gz petsc$version
183
184# process petsc4py tarball
185if [ -f petsc4py$version.tar.gz ]; then
186  cp petsc4py$version.tar.gz $ODIR/
187else
188  echo "Renaming petsc4py tarball to match petsc!"
189  dname=$(tar -tzf petsc4py-*.tar.gz | head -1)
190  /bin/tar -xzf petsc4py-*.tar.gz
191  /bin/mv $dname petsc4py$version
192  /bin/tar -czf $ODIR/petsc4py$version.tar.gz petsc4py$version
193fi
194
195#cleanup
196/bin/rm -rf $tmpdir
197
198echo "Ending date: `date +'%a, %d %b %Y %H:%M:%S %z'`"
199