Skip to content

Commit 44c5610

Browse files
committed
Add option --clean for the install script.
1 parent 53cf0a4 commit 44c5610

File tree

1 file changed

+77
-6
lines changed

1 file changed

+77
-6
lines changed

Diff for: diffpy-cmi/install

+77-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ usage: ./install [options]
88
Options:
99
1010
-n, --dry-run list what would be done without making any changes.
11-
Display a list of steps when run with --build or --update.
11+
Display a list of steps when run with --update, --build
12+
or --clean.
13+
1214
--update[=steps] perform all or selected software updates from online
1315
source repositories. Update steps are comma separated
1416
integers or ranges such as '1,3,5-6'. Use option -n to
1517
display the steps.
18+
1619
--build[=steps] rebuild all or specified packages from sources in the
1720
src folder. Use option -n to display the build steps.
21+
22+
--clean[=steps] remove generated files from the source folders of the
23+
specified packages. This ensures that --build is run
24+
from a pristine state.
25+
1826
-h, --help display this message and exit
1927
"
2028

@@ -66,7 +74,8 @@ SRCDIR=${BASEDIR}/src
6674
PTHFILE=${BASEDIR}/diffpy_cmi.pth
6775
VERSION=$(cd $BASEDIR && test -s VERSION.txt && <VERSION.txt)
6876

69-
typeset -aU build_selection update_selection
77+
typeset -aU clean_selection build_selection update_selection
78+
clean_selection=( )
7079
build_selection=( )
7180
update_selection=( )
7281
HASHLINE=${(l:78::#:):-}
@@ -92,13 +101,14 @@ export LIBRARY_PATH=${BASEDIRSHORT}/lib:\$LIBRARY_PATH
92101
# Extract command-line options -----------------------------------------------
93102

94103
zmodload zsh/zutil
95-
zparseopts -K -E -D \
104+
zparseopts -D -E \
96105
n=opt_dryrun -dry-run=opt_dryrun \
97-
h=opt_help -help=opt_help -update::=opt_update -build::=opt_build ||
106+
h=opt_help -help=opt_help \
107+
-clean::=opt_clean -update::=opt_update -build::=opt_build ||
98108
exit $?
99109

100110
if [[ -n $* ]]; then
101-
print -u2 "Invalid arguments or options: $*"
111+
print -u2 "Invalid option: $*"
102112
exit 2
103113
fi
104114

@@ -223,6 +233,7 @@ adjust_macosx_environment() {
223233
}
224234

225235

236+
integer CIDX=0
226237
integer UIDX=0
227238
integer BIDX=0
228239

@@ -231,6 +242,10 @@ ListSkipOrDo() {
231242
local idx
232243
typeset -gA didheader
233244
case $1 in
245+
(clean)
246+
idx=$(( ++CIDX ))
247+
selection=( $clean_selection )
248+
;;
234249
(build)
235250
idx=$(( ++BIDX ))
236251
selection=( $build_selection )
@@ -264,6 +279,57 @@ ListSkipOrDo() {
264279
}
265280

266281

282+
do_clean() {
283+
local PS4=">> "
284+
local msg_noupdate
285+
MSG_NOCLEAN="No cleanup needed for this package. Skipped."
286+
ListSkipOrDo clean "src/pycifrw (N/A)" || {
287+
print $MSG_NOCLEAN
288+
} || return $?
289+
ListSkipOrDo clean "src/diffpy.Structure" || (
290+
setopt xtrace
291+
cd $SRCDIR/diffpy.Structure &&
292+
rm -rf build temp diffpy.Structure.egg-info
293+
) || return $?
294+
ListSkipOrDo clean "src/diffpy.utils" || (
295+
setopt xtrace
296+
cd $SRCDIR/diffpy.utils &&
297+
rm -rf build temp diffpy.utils.egg-info
298+
) || return $?
299+
ListSkipOrDo clean "src/periodictable (N/A)" || {
300+
print $MSG_NOCLEAN
301+
} || return $?
302+
ListSkipOrDo clean "src/libobjcryst" || (
303+
setopt xtrace
304+
cd $SRCDIR/libobjcryst && $SCONS --clean
305+
) || return $?
306+
ListSkipOrDo clean "src/pyobjcryst" || (
307+
setopt xtrace
308+
cd $SRCDIR/pyobjcryst &&
309+
rm -rf build temp pyobjcryst.egg-info
310+
) || return $?
311+
ListSkipOrDo clean "src/libdiffpy" || (
312+
setopt xtrace
313+
cd $SRCDIR/libdiffpy && $SCONS --clean
314+
) || return $?
315+
ListSkipOrDo clean "src/diffpy.srreal" || (
316+
setopt xtrace
317+
cd $SRCDIR/diffpy.srreal &&
318+
rm -rf build temp diffpy.srreal.egg-info
319+
) || return $?
320+
ListSkipOrDo clean "src/diffpy.srfit" || (
321+
setopt xtrace
322+
cd $SRCDIR/diffpy.srfit &&
323+
rm -rf build temp diffpy.srreal.egg-info
324+
) || return $?
325+
ListSkipOrDo clean "src/srfit-sasview" || {
326+
setopt xtrace
327+
cd $SRCDIR/srfit-sasview &&
328+
rm -rf build temp srfit_sasview.egg-info
329+
} || return $?
330+
}
331+
332+
267333
do_update() {
268334
local PS4=">> "
269335
local msg_noupdate
@@ -483,6 +549,11 @@ do_install() {
483549

484550
# Main section here ----------------------------------------------------------
485551

552+
if [[ -n ${opt_clean} ]]; then
553+
expand_ranges clean_selection ${${opt_clean##--clean=#}:-all}
554+
do_clean || exit $?
555+
fi
556+
486557
if [[ -n ${opt_update} ]]; then
487558
expand_ranges update_selection ${${opt_update##--update=#}:-all}
488559
do_update || exit $?
@@ -493,6 +564,6 @@ if [[ -n ${opt_build} ]]; then
493564
do_build || exit $?
494565
fi
495566

496-
if [[ -z "${opt_update}${opt_build}" ]]; then
567+
if [[ -z "${opt_clean}${opt_update}${opt_build}" ]]; then
497568
do_install
498569
fi

0 commit comments

Comments
 (0)