Skip to content

Commit

Permalink
start of work to add global debug flags
Browse files Browse the repository at this point in the history
The developer can export environment variables that
are seen by the compiler wrapper to then add the flags

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Jun 11, 2021
1 parent b0f3483 commit f75b1ad
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/spack/docs/developer_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,32 @@ Unit tests
Unit testing
------------

---------------------
Developer 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
------------------
Expand Down
45 changes: 45 additions & 0 deletions lib/spack/env/cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ parameters=(
SPACK_SYSTEM_DIRS
)

# This is an array of optional parameters that aren't required to be set
# We don't technically need a list here but for documentation.
optional_parameters=(

# One of true/false/custom
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:
Expand Down Expand Up @@ -87,6 +98,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.
#
Expand All @@ -106,30 +136,35 @@ comp="CC"
case "$command" in
cpp)
mode=cpp
debug_flags="-g3"
;;
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
Expand Down Expand Up @@ -415,6 +450,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)
Expand Down

0 comments on commit f75b1ad

Please sign in to comment.