Skip to content

Commit 52fa3cb

Browse files
Adding debug option for all build scripts (NOAA-EMC#2326)
This PR addresses issue NOAA-EMC#300 that allows building in `debug` mode. Co-authored-by: David Huber <69919478+DavidHuber-NOAA@users.noreply.github.com> Co-authored-by: Rahul Mahajan <aerorahul@users.noreply.github.com>
1 parent 91738cb commit 52fa3cb

12 files changed

+87
-92
lines changed

sorc/build_all.sh

+31-29
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ function _usage() {
1616
Builds all of the global-workflow components by calling the individual build
1717
scripts in sequence.
1818
19-
Usage: ${BASH_SOURCE[0]} [-a UFS_app][-c build_config][-h][-j n][-v][-w]
19+
Usage: ${BASH_SOURCE[0]} [-a UFS_app][-c build_config][-d][-h][-j n][-v][-w]
2020
-a UFS_app:
2121
Build a specific UFS app instead of the default
22+
-d:
23+
Build in debug mode
2224
-g:
2325
Build GSI
2426
-h:
@@ -29,26 +31,29 @@ Usage: ${BASH_SOURCE[0]} [-a UFS_app][-c build_config][-h][-j n][-v][-w]
2931
Build UFS-DA
3032
-v:
3133
Execute all build scripts with -v option to turn on verbose where supported
32-
-w:
33-
Use unstructured wave grid
34+
-w:
35+
Use unstructured wave grid
3436
EOF
3537
exit 1
3638
}
3739

38-
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
39-
cd "${script_dir}" || exit 1
40+
# shellcheck disable=SC2155
41+
readonly HOMEgfs=$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )/.." && pwd -P)
42+
cd "${HOMEgfs}/sorc" || exit 1
4043

4144
_build_ufs_opt=""
4245
_build_ufsda="NO"
4346
_build_gsi="NO"
47+
_build_debug=""
4448
_verbose_opt=""
4549
_wave_unst=""
4650
_build_job_max=20
4751
# Reset option counter in case this script is sourced
4852
OPTIND=1
49-
while getopts ":a:ghj:uvw" option; do
53+
while getopts ":a:dghj:uvw" option; do
5054
case "${option}" in
5155
a) _build_ufs_opt+="-a ${OPTARG} ";;
56+
d) _build_debug="-d" ;;
5257
g) _build_gsi="YES" ;;
5358
h) _usage;;
5459
j) _build_job_max="${OPTARG} ";;
@@ -68,24 +73,24 @@ done
6873

6974
shift $((OPTIND-1))
7075

71-
logs_dir="${script_dir}/logs"
76+
logs_dir="${HOMEgfs}/sorc/logs"
7277
if [[ ! -d "${logs_dir}" ]]; then
7378
echo "Creating logs folder"
74-
mkdir "${logs_dir}" || exit 1
79+
mkdir -p "${logs_dir}" || exit 1
7580
fi
7681

7782
# Check final exec folder exists
78-
if [[ ! -d "../exec" ]]; then
79-
echo "Creating ../exec folder"
80-
mkdir ../exec
83+
if [[ ! -d "${HOMEgfs}/exec" ]]; then
84+
echo "Creating ${HOMEgfs}/exec folder"
85+
mkdir -p "${HOMEgfs}/exec"
8186
fi
8287

8388
#------------------------------------
8489
# GET MACHINE
8590
#------------------------------------
8691
export COMPILER="intel"
87-
source gfs_utils.fd/ush/detect_machine.sh
88-
source gfs_utils.fd/ush/module-setup.sh
92+
source "${HOMEgfs}/ush/detect_machine.sh"
93+
source "${HOMEgfs}/ush/module-setup.sh"
8994
if [[ -z "${MACHINE_ID}" ]]; then
9095
echo "FATAL: Unable to determine target machine"
9196
exit 1
@@ -117,19 +122,19 @@ declare -A build_opts
117122
big_jobs=0
118123
build_jobs["ufs"]=8
119124
big_jobs=$((big_jobs+1))
120-
build_opts["ufs"]="${_wave_unst} ${_verbose_opt} ${_build_ufs_opt}"
125+
build_opts["ufs"]="${_wave_unst} ${_verbose_opt} ${_build_ufs_opt} ${_build_debug}"
121126

122127
build_jobs["upp"]=2
123-
build_opts["upp"]=""
128+
build_opts["upp"]="${_build_debug}"
124129

125130
build_jobs["ufs_utils"]=2
126-
build_opts["ufs_utils"]="${_verbose_opt}"
131+
build_opts["ufs_utils"]="${_verbose_opt} ${_build_debug}"
127132

128133
build_jobs["gfs_utils"]=1
129-
build_opts["gfs_utils"]="${_verbose_opt}"
134+
build_opts["gfs_utils"]="${_verbose_opt} ${_build_debug}"
130135

131136
build_jobs["ww3prepost"]=2
132-
build_opts["ww3prepost"]="${_wave_unst} ${_verbose_opt} ${_build_ufs_opt}"
137+
build_opts["ww3prepost"]="${_wave_unst} ${_verbose_opt} ${_build_ufs_opt} ${_build_debug}"
133138

134139
# Optional DA builds
135140
if [[ "${_build_ufsda}" == "YES" ]]; then
@@ -138,21 +143,21 @@ if [[ "${_build_ufsda}" == "YES" ]]; then
138143
else
139144
build_jobs["gdas"]=8
140145
big_jobs=$((big_jobs+1))
141-
build_opts["gdas"]="${_verbose_opt}"
146+
build_opts["gdas"]="${_verbose_opt} ${_build_debug}"
142147
fi
143148
fi
144149
if [[ "${_build_gsi}" == "YES" ]]; then
145150
build_jobs["gsi_enkf"]=8
146-
build_opts["gsi_enkf"]="${_verbose_opt}"
151+
build_opts["gsi_enkf"]="${_verbose_opt} ${_build_debug}"
147152
fi
148153
if [[ "${_build_gsi}" == "YES" || "${_build_ufsda}" == "YES" ]] ; then
149154
build_jobs["gsi_utils"]=1
150-
build_opts["gsi_utils"]="${_verbose_opt}"
155+
build_opts["gsi_utils"]="${_verbose_opt} ${_build_debug}"
151156
if [[ "${MACHINE_ID}" == "hercules" ]]; then
152157
echo "NOTE: The GSI Monitor is not supported on Hercules. Disabling build."
153158
else
154159
build_jobs["gsi_monitor"]=1
155-
build_opts["gsi_monitor"]="${_verbose_opt}"
160+
build_opts["gsi_monitor"]="${_verbose_opt} ${_build_debug}"
156161
fi
157162
fi
158163

@@ -196,13 +201,10 @@ while [[ ${builds_started} -lt ${#build_jobs[@]} ]]; do
196201
if [[ -n "${build_jobs[${build}]+0}" && -z "${build_ids[${build}]+0}" ]]; then
197202
# Do we have enough processors to run it?
198203
if [[ ${_build_job_max} -ge $(( build_jobs[build] + procs_in_use )) ]]; then
199-
if [[ "${build}" != "upp" ]]; then
200-
"./build_${build}.sh" -j "${build_jobs[${build}]}" "${build_opts[${build}]:-}" > \
201-
"${logs_dir}/build_${build}.log" 2>&1 &
202-
else
203-
"./build_${build}.sh" "${build_opts[${build}]}" > \
204-
"${logs_dir}/build_${build}.log" 2>&1 &
205-
fi
204+
# double-quoting build_opts here will not work since it is a string of options
205+
#shellcheck disable=SC2086
206+
"./build_${build}.sh" ${build_opts[${build}]:-} -j "${build_jobs[${build}]}" > \
207+
"${logs_dir}/build_${build}.log" 2>&1 &
206208
build_ids["${build}"]=$!
207209
echo "Starting build_${build}.sh"
208210
procs_in_use=$(( procs_in_use + build_jobs[${build}] ))

sorc/build_gdas.sh

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
set -eux
33

44
OPTIND=1
5+
_opts="-f " # forces a clean build
56
while getopts ":j:dv" option; do
67
case "${option}" in
7-
d) export BUILD_TYPE="DEBUG";;
8-
j) export BUILD_JOBS=${OPTARG};;
9-
v) export BUILD_VERBOSE="YES";;
8+
d) _opts+="-c -DCMAKE_BUILD_TYPE=Debug " ;;
9+
j) BUILD_JOBS=${OPTARG};;
10+
v) _opts+="-v ";;
1011
:)
1112
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
1213
usage
@@ -19,12 +20,10 @@ while getopts ":j:dv" option; do
1920
done
2021
shift $((OPTIND-1))
2122

22-
# TODO: GDASApp does not presently handle BUILD_TYPE
23-
24-
BUILD_TYPE=${BUILD_TYPE:-"Release"} \
25-
BUILD_VERBOSE=${BUILD_VERBOSE:-"NO"} \
23+
# double quoting opts will not work since it is a string of options
24+
# shellcheck disable=SC2086
2625
BUILD_JOBS="${BUILD_JOBS:-8}" \
2726
WORKFLOW_BUILD="ON" \
28-
./gdas.cd/build.sh
27+
./gdas.cd/build.sh ${_opts} -f
2928

3029
exit

sorc/build_gfs_utils.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ EOF
1818
exit 1
1919
}
2020

21-
cwd=$(pwd)
22-
2321
OPTIND=1
2422
while getopts ":j:dvh" option; do
2523
case "${option}" in
26-
d) export BUILD_TYPE="DEBUG";;
27-
v) export BUILD_VERBOSE="YES";;
28-
j) export BUILD_JOBS="${OPTARG}";;
24+
d) BUILD_TYPE="Debug";;
25+
v) BUILD_VERBOSE="YES";;
26+
j) BUILD_JOBS="${OPTARG}";;
2927
h)
3028
usage
3129
;;
@@ -44,6 +42,6 @@ shift $((OPTIND-1))
4442
BUILD_TYPE=${BUILD_TYPE:-"Release"} \
4543
BUILD_VERBOSE=${BUILD_VERBOSE:-"NO"} \
4644
BUILD_JOBS=${BUILD_JOBS:-8} \
47-
"${cwd}/gfs_utils.fd/ush/build.sh"
45+
"./gfs_utils.fd/ush/build.sh"
4846

4947
exit

sorc/build_gsi_enkf.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ set -eux
44
OPTIND=1
55
while getopts ":j:dv" option; do
66
case "${option}" in
7-
d) export BUILD_TYPE="DEBUG";;
8-
j) export BUILD_JOBS="${OPTARG}";;
9-
v) export BUILD_VERBOSE="YES";;
7+
d) BUILD_TYPE="Debug";;
8+
j) BUILD_JOBS="${OPTARG}";;
9+
v) BUILD_VERBOSE="YES";;
1010
:)
1111
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
1212
usage

sorc/build_gsi_monitor.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#! /usr/bin/env bash
22
set -eux
33

4-
cwd=$(pwd)
5-
64
OPTIND=1
75
while getopts ":j:dv" option; do
86
case "${option}" in
9-
d) export BUILD_TYPE="DEBUG";;
10-
j) export BUILD_JOBS="${OPTARG}";;
11-
v) export BUILD_VERBOSE="YES";;
7+
d) BUILD_TYPE="Debug";;
8+
j) BUILD_JOBS="${OPTARG}";;
9+
v) BUILD_VERBOSE="YES";;
1210
:)
1311
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
1412
usage
@@ -24,6 +22,6 @@ shift $((OPTIND-1))
2422
BUILD_TYPE=${BUILD_TYPE:-"Release"} \
2523
BUILD_VERBOSE=${BUILD_VERBOSE:-"NO"} \
2624
BUILD_JOBS=${BUILD_JOBS:-8} \
27-
"${cwd}/gsi_monitor.fd/ush/build.sh"
25+
"./gsi_monitor.fd/ush/build.sh"
2826

2927
exit

sorc/build_gsi_utils.sh

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#! /usr/bin/env bash
22
set -eux
33

4-
cwd=$(pwd)
5-
64
OPTIND=1
75
while getopts ":j:dv" option; do
86
case "${option}" in
9-
d) export BUILD_TYPE="DEBUG";;
10-
j) export BUILD_JOBS="${OPTARG}";;
11-
v) export BUILD_VERBOSE="YES";;
7+
d) BUILD_TYPE="Debug";;
8+
j) BUILD_JOBS="${OPTARG}";;
9+
v) BUILD_VERBOSE="YES";;
1210
:)
1311
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
1412
usage
@@ -25,6 +23,6 @@ BUILD_TYPE=${BUILD_TYPE:-"Release"} \
2523
BUILD_VERBOSE=${BUILD_VERBOSE:-"NO"} \
2624
BUILD_JOBS=${BUILD_JOBS:-8} \
2725
UTIL_OPTS="-DBUILD_UTIL_ENKF_GFS=ON -DBUILD_UTIL_NCIO=ON" \
28-
"${cwd}/gsi_utils.fd/ush/build.sh"
26+
"./gsi_utils.fd/ush/build.sh"
2927

3028
exit

sorc/build_ufs.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CCPP_SUITES="FV3_GFS_v17_p8_ugwpv1,FV3_GFS_v17_coupled_p8_ugwpv1" # TODO: does
99

1010
while getopts ":da:j:vw" option; do
1111
case "${option}" in
12-
d) BUILD_TYPE="DEBUG";;
12+
d) BUILD_TYPE="Debug";;
1313
a) APP="${OPTARG}";;
1414
j) BUILD_JOBS="${OPTARG}";;
1515
v) export BUILD_VERBOSE="YES";;
@@ -30,7 +30,7 @@ source "./tests/module-setup.sh"
3030

3131
MAKE_OPT="-DAPP=${APP} -D32BIT=ON -DCCPP_SUITES=${CCPP_SUITES}"
3232
[[ ${PDLIB:-"OFF"} = "ON" ]] && MAKE_OPT+=" -DPDLIB=ON"
33-
[[ ${BUILD_TYPE:-"Release"} = "DEBUG" ]] && MAKE_OPT+=" -DDEBUG=ON"
33+
[[ ${BUILD_TYPE:-"Release"} = "Debug" ]] && MAKE_OPT+=" -DDEBUG=ON"
3434
COMPILE_NR=0
3535
CLEAN_BEFORE=YES
3636
CLEAN_AFTER=NO

sorc/build_ufs_utils.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ set -eux
44
OPTIND=1
55
while getopts ":j:dv" option; do
66
case "${option}" in
7-
j) export BUILD_JOBS="${OPTARG}";;
8-
v) export BUILD_VERBOSE="YES";;
7+
d) BUILD_TYPE="Debug" ;;
8+
j) BUILD_JOBS="${OPTARG}";;
9+
v) BUILD_VERBOSE="YES";;
910
:)
1011
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
1112
usage
@@ -18,13 +19,11 @@ while getopts ":j:dv" option; do
1819
done
1920
shift $((OPTIND-1))
2021

21-
script_dir=$(dirname "${BASH_SOURCE[0]}")
22-
cd "${script_dir}/ufs_utils.fd" || exit 1
23-
2422
CMAKE_OPTS="-DGFS=ON" \
23+
BUILD_TYPE=${BUILD_TYPE:-"Release"} \
2524
BUILD_JOBS=${BUILD_JOBS:-8} \
2625
BUILD_VERBOSE=${BUILD_VERBOSE:-} \
27-
./build_all.sh
26+
./ufs_utils.fd/build_all.sh
2827

2928
exit
3029

sorc/build_upp.sh

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ cd "${script_dir}" || exit 1
77
OPTIND=1
88
_opts=""
99
while getopts ":dj:v" option; do
10-
case "${option}" in
11-
d) _opts+="-d ";;
12-
j) export BUILD_JOBS="${OPTARG}" ;;
13-
v) _opts+="-v ";;
14-
:)
15-
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
16-
;;
17-
*)
18-
echo "[${BASH_SOURCE[0]}]: Unrecognized option: ${option}"
19-
;;
20-
esac
10+
case "${option}" in
11+
d) _opts+="-d " ;;
12+
j) BUILD_JOBS="${OPTARG}" ;;
13+
v) _opts+="-v ";;
14+
:)
15+
echo "[${BASH_SOURCE[0]}]: ${option} requires an argument"
16+
;;
17+
*)
18+
echo "[${BASH_SOURCE[0]}]: Unrecognized option: ${option}"
19+
;;
20+
esac
2121
done
2222
shift $((OPTIND-1))
2323

2424
# Check final exec folder exists
2525
if [[ ! -d "../exec" ]]; then
26-
mkdir ../exec
26+
mkdir -p ../exec
2727
fi
2828

2929
cd ufs_model.fd/FV3/upp/tests

0 commit comments

Comments
 (0)