summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVanessasaurus <814322+vsoch@users.noreply.github.com>2021-07-09 19:22:26 -0600
committerGitHub <noreply@github.com>2021-07-09 21:22:26 -0400
commit775c8223c34f96f23c6ed314c085b0307b1ecd03 (patch)
tree179185941efabcab671b2034399087c69a72b928 /lib
parentebf2076755beabea00de0ff1588c6eec6af2b304 (diff)
downloadspack-775c8223c34f96f23c6ed314c085b0307b1ecd03.tar.gz
spack-775c8223c34f96f23c6ed314c085b0307b1ecd03.tar.bz2
spack-775c8223c34f96f23c6ed314c085b0307b1ecd03.tar.xz
spack-775c8223c34f96f23c6ed314c085b0307b1ecd03.zip
debug: initial global debug flag support (#24285)
The developer can export environment variables that are seen by the compiler wrapper to then add the flags
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/docs/developer_guide.rst32
-rwxr-xr-xlib/spack/env/cc42
2 files changed, 74 insertions, 0 deletions
diff --git a/lib/spack/docs/developer_guide.rst b/lib/spack/docs/developer_guide.rst
index 0ceb5d84a1..fe67b90950 100644
--- a/lib/spack/docs/developer_guide.rst
+++ b/lib/spack/docs/developer_guide.rst
@@ -785,6 +785,38 @@ Unit tests
Unit testing
------------
+---------------------
+Developer environment
+---------------------
+
+.. warning::
+
+ This is an experimental feature. It is expected to change and you should
+ not use it in a production environment.
+
+
+When installing a package, we currently have support to export environment
+variables to specify adding debug flags to the build. By default, a package
+install will build without any debug flag. However, if you want to add them,
+you can export:
+
+.. code-block:: console
+
+ export SPACK_ADD_DEBUG_FLAGS=true
+ spack install zlib
+
+
+If you want to add custom flags, you should export an additional variable:
+
+.. code-block:: console
+
+ export SPACK_ADD_DEBUG_FLAGS=true
+ export SPACK_DEBUG_FLAGS="-g"
+ spack install zlib
+
+These environment variables will eventually be integrated into spack so
+they are set from the command line.
+
------------------
Developer commands
------------------
diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index bd479f05ec..5157a5f381 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -40,6 +40,14 @@ parameters=(
SPACK_SYSTEM_DIRS
)
+# Optional parameters that aren't required to be set
+
+# Boolean (true/false/custom) if we want to add debug flags
+# SPACK_ADD_DEBUG_FLAGS
+
+# If a custom flag is requested, it will be defined
+# SPACK_DEBUG_FLAGS
+
# The compiler input variables are checked for sanity later:
# SPACK_CC, SPACK_CXX, SPACK_F77, SPACK_FC
# The default compiler flags are passed from these variables:
@@ -87,6 +95,25 @@ for param in "${parameters[@]}"; do
fi
done
+# Check if optional parameters are defined
+# If we aren't asking for debug flags, don't add them
+if [[ -z ${SPACK_ADD_DEBUG_FLAGS+x} ]]; then
+ SPACK_ADD_DEBUG_FLAGS="false"
+fi
+
+# SPACK_ADD_DEBUG_FLAGS must be true/false/custom
+is_valid="false"
+for param in "true" "false" "custom"; do
+ if [ "$param" == "$SPACK_ADD_DEBUG_FLAGS" ]; then
+ is_valid="true"
+ fi
+done
+
+# Exit with error if we are given an incorrect value
+if [ "$is_valid" == "false" ]; then
+ die "SPACK_ADD_DEBUG_FLAGS, if defined, must be one of 'true' 'false' or 'custom'"
+fi
+
# Figure out the type of compiler, the language, and the mode so that
# the compiler script knows what to do.
#
@@ -106,30 +133,35 @@ comp="CC"
case "$command" in
cpp)
mode=cpp
+ debug_flags="-g"
;;
cc|c89|c99|gcc|clang|armclang|icc|icx|pgcc|nvc|xlc|xlc_r|fcc)
command="$SPACK_CC"
language="C"
comp="CC"
lang_flags=C
+ debug_flags="-g"
;;
c++|CC|g++|clang++|armclang++|icpc|icpx|pgc++|nvc++|xlc++|xlc++_r|FCC)
command="$SPACK_CXX"
language="C++"
comp="CXX"
lang_flags=CXX
+ debug_flags="-g"
;;
ftn|f90|fc|f95|gfortran|flang|armflang|ifort|ifx|pgfortran|nvfortran|xlf90|xlf90_r|nagfor|frt)
command="$SPACK_FC"
language="Fortran 90"
comp="FC"
lang_flags=F
+ debug_flags="-g"
;;
f77|xlf|xlf_r|pgf77)
command="$SPACK_F77"
language="Fortran 77"
comp="F77"
lang_flags=F
+ debug_flags="-g"
;;
ld)
mode=ld
@@ -415,6 +447,16 @@ done
#
flags=()
+# Add debug flags
+if [ "${SPACK_ADD_DEBUG_FLAGS}" == "true" ]; then
+ flags=("${flags[@]}" "${debug_flags}")
+
+# If a custom flag is requested, derive from environment
+elif [ "$SPACK_ADD_DEBUG_FLAGS" == "custom" ]; then
+ IFS=' ' read -ra SPACK_DEBUG_FLAGS <<< "$SPACK_DEBUG_FLAGS"
+ flags=("${flags[@]}" "${SPACK_DEBUG_FLAGS[@]}")
+fi
+
# Fortran flags come before CPPFLAGS
case "$mode" in
cc|ccld)