forked from ufs-community/ufs-srweather-app
-
Notifications
You must be signed in to change notification settings - Fork 1
/
devclean.sh
executable file
·175 lines (152 loc) · 5.02 KB
/
devclean.sh
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
#!/bin/bash
# usage instructions
usage () {
cat << EOF_USAGE
Clean the UFS-SRW Application build
Usage: $0 [OPTIONS] ...
OPTIONS
-h, --help
show this help guide
-a, --all
removes "bin", "build" directories, and other build artifacts
--remove
removes the "build" directory, keeps the "bin", "lib" and other build artifacts intact
--clean
removes "bin", "build" directories, and other build artifacts (same as "-a", "--all")
--conda
removes "conda" directory and conda_loc file in SRW
--install-dir=INSTALL_DIR
installation directory name (\${SRW_DIR} by default)
--build-dir=BUILD_DIR
main build directory, absolute path (\${SRW_DIR}/build/ by default)
--bin-dir=BIN_DIR
binary directory name ("exec" by default); full path is \${INSTALL_DIR}/\${BIN_DIR})
--conda-dir=CONDA_DIR
directory where conda is installed. caution: if outside the SRW clone, it may have broader use
--sub-modules
remove sub-module directories. They will need to be checked out again by sourcing "\${SRW_DIR}/manage_externals/checkout_externals" before attempting subsequent builds
-v, --verbose
provide more verbose output
EOF_USAGE
}
# print settings
settings () {
cat << EOF_SETTINGS
Settings:
INSTALL_DIR=${INSTALL_DIR}
BUILD_DIR=${BUILD_DIR}
BIN_DIR=${BIN_DIR}
CONDA_DIR=${CONDA_DIR}
REMOVE=${REMOVE}
VERBOSE=${VERBOSE}
Default cleaning options: (if no arguments provided, then nothing is cleaned)
REMOVE=${REMOVE}
CLEAN=${CLEAN}
INCLUDE_SUB_MODULES=${INCLUDE_SUB_MODULES}
EOF_SETTINGS
}
# print usage error and exit
usage_error () {
printf "ERROR: $1\n" >&2
usage >&2
exit 1
}
# default settings
SRW_DIR=$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)
INSTALL_DIR=${INSTALL_DIR:-${SRW_DIR}}
BUILD_DIR=${BUILD_DIR:-"${SRW_DIR}/build"}
BIN_DIR="exec"
CONDA_DIR=${CONDA_DIR:-"${SRW_DIR}/conda"}
REMOVE=false
VERBOSE=false
# default clean options
REMOVE=false
CLEAN=false
INCLUDE_SUB_MODULES=false #changes to true if '--sub-modules' option is provided
# process requires arguments
if [[ ("$1" == "--help") || ("$1" == "-h") ]]; then
usage
exit 0
fi
# process optional arguments
while :; do
case $1 in
--help|-h) usage; exit 0 ;;
--all|-a) ALL_CLEAN=true ;;
--remove) REMOVE=true ;;
--remove=?*|--remove=) usage_error "$1 argument ignored." ;;
--clean) CLEAN=true ;;
--conda) REMOVE_CONDA=true ;;
--install-dir=?*) INSTALL_DIR=${1#*=} ;;
--install-dir|--install-dir=) usage_error "$1 requires argument." ;;
--build-dir=?*) BUILD_DIR=${1#*=} ;;
--build-dir|--build-dir=) usage_error "$1 requires argument." ;;
--bin-dir=?*) BIN_DIR=${1#*=} ;;
--bin-dir|--bin-dir=) usage_error "$1 requires argument." ;;
--conda-dir=?*) CONDA_DIR=${1#*=} ;;
--conda-dir|--conda-dir=) usage_error "$1 requires argument." ;;
--sub-modules) INCLUDE_SUB_MODULES=true ;;
--verbose|-v) VERBOSE=true ;;
--verbose=?*|--verbose=) usage_error "$1 argument ignored." ;;
# targets
default) ALL_CLEAN=false ;;
# unknown
-?*|?*) usage_error "Unknown option $1" ;;
*) break ;;
esac
shift
done
# choose defaults to clean
if [ "${ALL_CLEAN}" = true ]; then
CLEAN=true
fi
# print settings
if [ "${VERBOSE}" = true ] ; then
settings
fi
# clean if build directory already exists
if [ "${REMOVE}" = true ] && [ "${CLEAN}" = false ] ; then
printf '%s\n' "Remove the \"build\" directory only, BUILD_DIR = $BUILD_DIR "
[[ -d ${BUILD_DIR} ]] && rm -rf ${BUILD_DIR} && printf '%s\n' "rm -rf ${BUILD_DIR}"
elif [ "${CLEAN}" = true ]; then
printf '%s\n' "Remove build directory, bin directory, and other build artifacts "
printf '%s\n' " from the installation directory = ${INSTALL_DIR} "
directories=( \
"${BUILD_DIR}" \
"${INSTALL_DIR}/${BIN_DIR}" \
"${INSTALL_DIR}/share" \
"${INSTALL_DIR}/include" \
"${INSTALL_DIR}/lib" \
"${INSTALL_DIR}/lib64" \
)
if [ ${#directories[@]} -ge 1 ]; then
for dir in ${directories[@]}; do
[[ -d "${dir}" ]] && rm -rfv ${dir}
done
echo " "
fi
fi
# Clean all the submodules if requested. Note: Need to check out them again before attempting subsequent builds, by sourcing ${SRW_DIR}/manage_externals/checkout_externals
if [ ${INCLUDE_SUB_MODULES} == true ]; then
printf '%s\n' "Removing submodules ..."
declare -a submodules='()'
submodules=(${SRW_DIR}/sorc/*)
# echo " submodules are: ${submodules[@]} (total of ${#submodules[@]}) "
if [ ${#submodules[@]} -ge 1 ]; then
for sub in ${submodules[@]}; do [[ -d "${sub}" ]] && ( rm -rf ${sub} && printf '%s\n' "rm -rf ${sub}" ); done
fi
printf '%s\n' "Note: Need to check out submodules again for any subsequent builds, " \
" by sourcing ${SRW_DIR}/manage_externals/checkout_externals "
fi
#
# Clean conda if requested
if [ "${REMOVE_CONDA}" = true ] ; then
printf '%s\n' "Removing conda location file"
rm -rf ${SRW_DIR}/conda_loc
printf '%s\n' "Removing conda installation"
rm -rf ${CONDA_DIR}
fi
echo " "
echo "All the requested cleaning tasks have been completed"
echo " "
exit 0