Skip to content

Commit 6940ddb

Browse files
committed
refactor: put cleaning and depana before downloading stuff
1 parent e8c5843 commit 6940ddb

File tree

1 file changed

+80
-60
lines changed

1 file changed

+80
-60
lines changed

build-coatjava.sh

Lines changed: 80 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,35 @@ set -e
55
set -u
66
set -o pipefail
77

8-
usage='''build-coatjava.sh [OPTIONS]... [MAVEN_OPTIONS]...
9-
10-
OPTIONS
11-
--clara install clara too
12-
--clean clean up built objects and exit (does not compile)
13-
--quiet run more quietly
14-
--no-progress no download progress printouts
15-
--help show this message
16-
17-
OPTIONS FOR MAGNETIC FIELD MAPS, NEURAL NETWORK MODELS, etc.
18-
--lfs use Git Large File Storage (requires `git-lfs`)
19-
--cvmfs use CernVM-FS (requires `/cvfms`)
20-
--xrootd use XRootD (requires `xrootd`)
21-
--nomaps do not download field maps
22-
23-
OPTIONS FOR TESTING
24-
--spotbugs also run spotbugs plugin
25-
--unittests also run unit tests
26-
--depana run dependency analysis (only)
27-
--data download test data (requires lfs)
28-
29-
MAVEN_OPTIONS
8+
usage='''build-coatjava.sh [OPTIONS]...
9+
10+
GENERAL OPTIONS
11+
--clara install clara too
12+
--clean clean up built objects and exit (does not compile)
13+
--quiet run more quietly
14+
--no-progress no download progress printouts
15+
--help show this message
16+
17+
DATA RETRIEVAL OPTIONS
18+
How to retrieve magnetic field maps, neural network models, etc.;
19+
choose only one:
20+
--lfs use Git Large File Storage (requires `git-lfs`)
21+
--cvmfs use CernVM-FS (requires `/cvfms`)
22+
--xrootd use XRootD (requires `xrootd`)
23+
--nomaps do not download field maps
24+
25+
TESTING OPTIONS
26+
--spotbugs also run spotbugs plugin
27+
--unittests also run unit tests
28+
--depana run dependency analysis (only)
29+
--data download test data (requires `git-lfs`)
30+
31+
MAVEN OPTIONS
3032
all other arguments will be passed to `mvn`; for example,
3133
-T4 will build with 4 parallel threads
3234
'''
3335

36+
3437
################################################################################
3538
# parse arguments
3639
################################################################################
@@ -64,9 +67,9 @@ do
6467
mvnArgs+=(--no-transfer-progress)
6568
wgetArgs+=(--no-verbose)
6669
;;
67-
--xrootd) useXrootd=true ;;
68-
--cvmfs) useCvmfs=true ;;
69-
--lfs) useLfs=true ;;
70+
--xrootd) useXrootd=true ;;
71+
--cvmfs) useCvmfs=true ;;
72+
--lfs) useLfs=true ;;
7073
--clara) installClara=true ;;
7174
--data) downloadData=true ;;
7275
-h|--help)
@@ -89,13 +92,16 @@ if ! [[ $(hostname) == *.jlab.org ]]; then
8992
useLfs=true
9093
fi
9194

95+
9296
################################################################################
9397
# setup
9498
################################################################################
9599

100+
# directories
96101
src_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
97102
prefix_dir=$src_dir/coatjava
98103
clara_home=$src_dir/clara
104+
magfield_dir=$src_dir/etc/data/magfield
99105

100106
# working directory should be the source code directory
101107
cd $src_dir
@@ -105,14 +111,55 @@ wgetArgs+=(--timestamping --no-check-certificate) # `--timestamping` only redown
105111
mvn="mvn ${mvnArgs[@]:-}"
106112
wget="wget ${wgetArgs[@]:-}"
107113

114+
# environment
115+
source libexec/env.sh --no-classpath
116+
117+
118+
################################################################################
119+
# cleaning, dependency analysis, etc.
120+
################################################################################
121+
122+
# function to clean installation prefixes
123+
clean_prefixes() {
124+
rm -rf $prefix_dir $clara_home
125+
}
126+
127+
# clean up any cache copies
128+
if $cleanBuild; then
129+
clean_prefixes
130+
$mvn clean
131+
for target_dir in $(find $src_dir -type d -name target); do
132+
echo "WARNING: target directory '$target_dir' was not removed! JAR files within may be accidentally installed!" >&2
133+
done
134+
echo """DONE CLEANING.
135+
NOTE:
136+
- to remove local magnetic field maps:
137+
rm $magfield_dir/*.dat
138+
- to clear all LFS git submodules:
139+
git submodule deinit --all
140+
141+
Now re-run without \`--clean\` to build."""
142+
exit
143+
fi
144+
145+
# run dependency analysis and exit
146+
if $anaDepends; then
147+
libexec/dependency-analysis.sh
148+
libexec/dependency-tree.sh
149+
exit 0
150+
fi
151+
152+
108153
################################################################################
109154
# download field maps, NN models, etc.
110155
################################################################################
111156

157+
# check if a command exists
112158
command_exists () {
113-
type "$1" &> /dev/null
159+
type "$1" &> /dev/null
114160
}
115161

162+
# update an LFS submodule
116163
download_lfs() {
117164
if command_exists git-lfs ; then
118165
cd $src_dir > /dev/null
@@ -125,6 +172,7 @@ download_lfs() {
125172
fi
126173
}
127174

175+
# download a magnetic field map
128176
download_map () {
129177
ret=0
130178
if $useXrootd; then
@@ -150,9 +198,7 @@ download_map () {
150198

151199
# download the default field maps, as defined in libexec/env.sh:
152200
# (and duplicated in etc/services/reconstruction.yaml):
153-
source libexec/env.sh --no-classpath
154-
magfield_dir=$src_dir/etc/data/magfield
155-
if ! $cleanBuild && $downloadMaps; then
201+
if $downloadMaps; then
156202
echo 'Retrieving field maps ...'
157203
if $useLfs; then
158204
download_lfs etc/data/magfield
@@ -191,42 +237,13 @@ if $downloadData; then
191237
download_lfs validation/advanced-tests/data
192238
fi
193239

194-
################################################################################
195-
# cleaning
196-
################################################################################
197-
198-
# always clean the installation prefix
199-
rm -rf $prefix_dir $clara_home
200-
201-
# clean up any cache copies
202-
if $cleanBuild; then
203-
$mvn clean
204-
for target_dir in $(find $src_dir -type d -name target); do
205-
echo "WARNING: target directory '$target_dir' was not removed! JAR files within may be accidentally installed!" >&2
206-
done
207-
echo """DONE CLEANING.
208-
NOTE:
209-
- to remove local magnetic field maps:
210-
rm $magfield_dir/*.dat
211-
- to clear all LFS git submodules:
212-
git submodule deinit --all
213-
214-
Now re-run without \`--clean\` to build."""
215-
exit
216-
fi
217240

218241
################################################################################
219242
# build
220243
################################################################################
221244

222-
# run dependency analysis and exit
223-
if $anaDepends; then
224-
libexec/dependency-analysis.sh
225-
libexec/dependency-tree.sh
226-
exit 0
227-
fi
228-
229245
# start new installation tree
246+
clean_prefixes # always clean the installation prefix
230247
mkdir -p $prefix_dir
231248
cp -r bin $prefix_dir/
232249
cp -r etc $prefix_dir/
@@ -240,14 +257,15 @@ $python etc/bankdefs/util/bankSplit.py $prefix_dir/etc/bankdefs/hipo4 || exit 1
240257
mkdir -p $prefix_dir/lib/utils
241258
cp external-dependencies/jclara-4.3-SNAPSHOT.jar $prefix_dir/lib/utils
242259

243-
# spotbugs, unit tests
260+
# build (and test)
244261
unset CLAS12DIR
245262
if $runUnitTests; then
246263
$mvn install # also runs unit tests
247264
else
248265
$mvn install -DskipTests
249266
fi
250267

268+
# run spotbugs
251269
if $runSpotBugs; then
252270
# mvn com.github.spotbugs:spotbugs-maven-plugin:spotbugs # spotbugs goal produces a report target/spotbugsXml.xml for each module
253271
$mvn com.github.spotbugs:spotbugs-maven-plugin:check # check goal produces a report and produces build failed if bugs
@@ -256,6 +274,7 @@ if $runSpotBugs; then
256274
if [ $? != 0 ] ; then echo "spotbugs failure" >&2 ; exit 1 ; fi
257275
fi
258276

277+
259278
################################################################################
260279
# install
261280
################################################################################
@@ -287,6 +306,7 @@ for pom in $(find common-tools -name pom.xml); do
287306
done
288307
echo "installed coatjava to: $prefix_dir"
289308

309+
# install clara
290310
if $installClara; then ./install-clara -c $prefix_dir $clara_home; fi
291311

292312
echo "COATJAVA SUCCESSFULLY BUILT !"

0 commit comments

Comments
 (0)