summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2024-09-22 22:44:39 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2024-09-27 05:27:26 -0700
commita76a48c42e8d6657f9dcb0500bff574651f317d9 (patch)
tree08828bfc63c761a3027528c37e5106889aa6b5fc /lib
parent0619a8bd4f2238d87b22779b30b6b923d83eb846 (diff)
downloadspack-a76a48c42e8d6657f9dcb0500bff574651f317d9.tar.gz
spack-a76a48c42e8d6657f9dcb0500bff574651f317d9.tar.bz2
spack-a76a48c42e8d6657f9dcb0500bff574651f317d9.tar.xz
spack-a76a48c42e8d6657f9dcb0500bff574651f317d9.zip
`cc`: simplify ordered list handling
`cc` divides most paths up into system paths, spack managed paths, and other paths. This gets really repetitive and makes the code hard to read. Simplify the script by adding some functions to do most of the redundant work for us. Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
Diffstat (limited to 'lib')
-rwxr-xr-xlib/spack/env/cc179
1 files changed, 65 insertions, 114 deletions
diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index ccfc14bb89..44f8b9316a 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -238,6 +238,36 @@ esac
}
"
+# path_list functions. Path_lists have 3 parts: spack_store_<list>, <list> and system_<list>,
+# which are used to prioritize paths when assembling the final command line.
+
+# init_path_lists LISTNAME
+# Set <LISTNAME>, spack_store_<LISTNAME>, and system_<LISTNAME> to "".
+init_path_lists() {
+ eval "spack_store_$1=\"\""
+ eval "$1=\"\""
+ eval "system_$1=\"\""
+}
+
+# assign_path_lists LISTNAME1 LISTNAME2
+# Copy contents of LISTNAME2 into LISTNAME1, for each path_list prefix.
+assign_path_lists() {
+ eval "spack_store_$1=\"\${spack_store_$2}\""
+ eval "$1=\"\${$2}\""
+ eval "system_$1=\"\${system_$2}\""
+}
+
+# append_path_lists LISTNAME ELT
+# Append the provided ELT to the appropriate list, based on the result of path_order().
+append_path_lists() {
+ path_order "$2"
+ case $? in
+ 0) eval "append spack_store_$1 \"\$2\"" ;;
+ 1) eval "append $1 \"\$2\"" ;;
+ 2) eval "append system_$1 \"\$2\"" ;;
+ esac
+}
+
# Check if optional parameters are defined
# If we aren't asking for debug flags, don't add them
if [ -z "${SPACK_ADD_DEBUG_FLAGS:-}" ]; then
@@ -470,12 +500,7 @@ input_command="$*"
parse_Wl() {
while [ $# -ne 0 ]; do
if [ "$wl_expect_rpath" = yes ]; then
- path_order "$1"
- case $? in
- 0) append return_spack_store_rpath_dirs_list "$1" ;;
- 1) append return_rpath_dirs_list "$1" ;;
- 2) append return_system_rpath_dirs_list "$1" ;;
- esac
+ append_path_lists return_rpath_dirs_list "$1"
wl_expect_rpath=no
else
case "$1" in
@@ -484,24 +509,14 @@ parse_Wl() {
if [ -z "$arg" ]; then
shift; continue
fi
- path_order "$arg"
- case $? in
- 0) append return_spack_store_rpath_dirs_list "$arg" ;;
- 1) append return_rpath_dirs_list "$arg" ;;
- 2) append return_system_rpath_dirs_list "$arg" ;;
- esac
+ append_path_lists return_rpath_dirs_list "$arg"
;;
--rpath=*)
arg="${1#--rpath=}"
if [ -z "$arg" ]; then
shift; continue
fi
- path_order "$arg"
- case $? in
- 0) append return_spack_store_rpath_dirs_list "$arg" ;;
- 1) append return_rpath_dirs_list "$arg" ;;
- 2) append return_system_rpath_dirs_list "$arg" ;;
- esac
+ append_path_lists return_rpath_dirs_list "$arg"
;;
-rpath|--rpath)
wl_expect_rpath=yes
@@ -509,8 +524,7 @@ parse_Wl() {
"$dtags_to_strip")
;;
-Wl)
- # Nested -Wl,-Wl means we're in NAG compiler territory, we don't support
- # it.
+ # Nested -Wl,-Wl means we're in NAG compiler territory. We don't support it.
return 1
;;
*)
@@ -529,21 +543,10 @@ categorize_arguments() {
return_other_args_list=""
return_isystem_was_used=""
- return_isystem_spack_store_include_dirs_list=""
- return_isystem_system_include_dirs_list=""
- return_isystem_include_dirs_list=""
-
- return_spack_store_include_dirs_list=""
- return_system_include_dirs_list=""
- return_include_dirs_list=""
-
- return_spack_store_lib_dirs_list=""
- return_system_lib_dirs_list=""
- return_lib_dirs_list=""
-
- return_spack_store_rpath_dirs_list=""
- return_system_rpath_dirs_list=""
- return_rpath_dirs_list=""
+ init_path_lists return_isystem_include_dirs_list
+ init_path_lists return_include_dirs_list
+ init_path_lists return_lib_dirs_list
+ init_path_lists return_rpath_dirs_list
# Global state for keeping track of -Wl,-rpath -Wl,/path
wl_expect_rpath=no
@@ -609,32 +612,17 @@ categorize_arguments() {
arg="${1#-isystem}"
return_isystem_was_used=true
if [ -z "$arg" ]; then shift; arg="$1"; fi
- path_order "$arg"
- case $? in
- 0) append return_isystem_spack_store_include_dirs_list "$arg" ;;
- 1) append return_isystem_include_dirs_list "$arg" ;;
- 2) append return_isystem_system_include_dirs_list "$arg" ;;
- esac
+ append_path_lists return_isystem_include_dirs_list "$arg"
;;
-I*)
arg="${1#-I}"
if [ -z "$arg" ]; then shift; arg="$1"; fi
- path_order "$arg"
- case $? in
- 0) append return_spack_store_include_dirs_list "$arg" ;;
- 1) append return_include_dirs_list "$arg" ;;
- 2) append return_system_include_dirs_list "$arg" ;;
- esac
+ append_path_lists return_include_dirs_list "$arg"
;;
-L*)
arg="${1#-L}"
if [ -z "$arg" ]; then shift; arg="$1"; fi
- path_order "$arg"
- case $? in
- 0) append return_spack_store_lib_dirs_list "$arg" ;;
- 1) append return_lib_dirs_list "$arg" ;;
- 2) append return_system_lib_dirs_list "$arg" ;;
- esac
+ append_path_lists return_lib_dirs_list "$arg"
;;
-l*)
# -loopopt=0 is generated erroneously in autoconf <= 2.69,
@@ -667,32 +655,17 @@ categorize_arguments() {
break
elif [ "$xlinker_expect_rpath" = yes ]; then
# Register the path of -Xlinker -rpath <other args> -Xlinker <path>
- path_order "$1"
- case $? in
- 0) append return_spack_store_rpath_dirs_list "$1" ;;
- 1) append return_rpath_dirs_list "$1" ;;
- 2) append return_system_rpath_dirs_list "$1" ;;
- esac
+ append_path_lists return_rpath_dirs_list "$1"
xlinker_expect_rpath=no
else
case "$1" in
-rpath=*)
arg="${1#-rpath=}"
- path_order "$arg"
- case $? in
- 0) append return_spack_store_rpath_dirs_list "$arg" ;;
- 1) append return_rpath_dirs_list "$arg" ;;
- 2) append return_system_rpath_dirs_list "$arg" ;;
- esac
+ append_path_lists return_rpath_dirs_list "$arg"
;;
--rpath=*)
arg="${1#--rpath=}"
- path_order "$arg"
- case $? in
- 0) append return_spack_store_rpath_dirs_list "$arg" ;;
- 1) append return_rpath_dirs_list "$arg" ;;
- 2) append return_system_rpath_dirs_list "$arg" ;;
- esac
+ append_path_lists return_rpath_dirs_list "$arg"
;;
-rpath|--rpath)
xlinker_expect_rpath=yes
@@ -731,21 +704,10 @@ categorize_arguments() {
categorize_arguments "$@"
-spack_store_include_dirs_list="$return_spack_store_include_dirs_list"
-system_include_dirs_list="$return_system_include_dirs_list"
-include_dirs_list="$return_include_dirs_list"
-
-spack_store_lib_dirs_list="$return_spack_store_lib_dirs_list"
-system_lib_dirs_list="$return_system_lib_dirs_list"
-lib_dirs_list="$return_lib_dirs_list"
-
-spack_store_rpath_dirs_list="$return_spack_store_rpath_dirs_list"
-system_rpath_dirs_list="$return_system_rpath_dirs_list"
-rpath_dirs_list="$return_rpath_dirs_list"
-
-isystem_spack_store_include_dirs_list="$return_isystem_spack_store_include_dirs_list"
-isystem_system_include_dirs_list="$return_isystem_system_include_dirs_list"
-isystem_include_dirs_list="$return_isystem_include_dirs_list"
+assign_path_lists isystem_include_dirs_list return_isystem_include_dirs_list
+assign_path_lists include_dirs_list return_include_dirs_list
+assign_path_lists lib_dirs_list return_lib_dirs_list
+assign_path_lists rpath_dirs_list return_rpath_dirs_list
isystem_was_used="$return_isystem_was_used"
other_args_list="$return_other_args_list"
@@ -821,21 +783,10 @@ IFS="$lsep"
categorize_arguments $spack_flags_list
unset IFS
-spack_flags_isystem_spack_store_include_dirs_list="$return_isystem_spack_store_include_dirs_list"
-spack_flags_isystem_system_include_dirs_list="$return_isystem_system_include_dirs_list"
-spack_flags_isystem_include_dirs_list="$return_isystem_include_dirs_list"
-
-spack_flags_spack_store_include_dirs_list="$return_spack_store_include_dirs_list"
-spack_flags_system_include_dirs_list="$return_system_include_dirs_list"
-spack_flags_include_dirs_list="$return_include_dirs_list"
-
-spack_flags_spack_store_lib_dirs_list="$return_spack_store_lib_dirs_list"
-spack_flags_system_lib_dirs_list="$return_system_lib_dirs_list"
-spack_flags_lib_dirs_list="$return_lib_dirs_list"
-
-spack_flags_spack_store_rpath_dirs_list="$return_spack_store_rpath_dirs_list"
-spack_flags_system_rpath_dirs_list="$return_system_rpath_dirs_list"
-spack_flags_rpath_dirs_list="$return_rpath_dirs_list"
+assign_path_lists spack_flags_isystem_include_dirs_list return_isystem_include_dirs_list
+assign_path_lists spack_flags_include_dirs_list return_include_dirs_list
+assign_path_lists spack_flags_lib_dirs_list return_lib_dirs_list
+assign_path_lists spack_flags_rpath_dirs_list return_rpath_dirs_list
spack_flags_isystem_was_used="$return_isystem_was_used"
spack_flags_other_args_list="$return_other_args_list"
@@ -894,7 +845,7 @@ esac
case "$mode" in
cpp|cc|as|ccld)
if [ "$spack_flags_isystem_was_used" = "true" ] || [ "$isystem_was_used" = "true" ]; then
- extend isystem_spack_store_include_dirs_list SPACK_STORE_INCLUDE_DIRS
+ extend spack_store_isystem_include_dirs_list SPACK_STORE_INCLUDE_DIRS
extend isystem_include_dirs_list SPACK_INCLUDE_DIRS
else
extend spack_store_include_dirs_list SPACK_STORE_INCLUDE_DIRS
@@ -910,32 +861,32 @@ args_list="$flags_list"
# Include search paths partitioned by (in store, non-sytem, system)
# NOTE: adding ${lsep} to the prefix here turns every added element into two
-extend args_list spack_flags_spack_store_include_dirs_list -I
+extend args_list spack_store_spack_flags_include_dirs_list -I
extend args_list spack_store_include_dirs_list -I
extend args_list spack_flags_include_dirs_list -I
extend args_list include_dirs_list -I
-extend args_list spack_flags_isystem_spack_store_include_dirs_list "-isystem${lsep}"
-extend args_list isystem_spack_store_include_dirs_list "-isystem${lsep}"
+extend args_list spack_store_spack_flags_isystem_include_dirs_list "-isystem${lsep}"
+extend args_list spack_store_isystem_include_dirs_list "-isystem${lsep}"
extend args_list spack_flags_isystem_include_dirs_list "-isystem${lsep}"
extend args_list isystem_include_dirs_list "-isystem${lsep}"
-extend args_list spack_flags_system_include_dirs_list -I
+extend args_list system_spack_flags_include_dirs_list -I
extend args_list system_include_dirs_list -I
-extend args_list spack_flags_isystem_system_include_dirs_list "-isystem${lsep}"
-extend args_list isystem_system_include_dirs_list "-isystem${lsep}"
+extend args_list system_spack_flags_isystem_include_dirs_list "-isystem${lsep}"
+extend args_list system_isystem_include_dirs_list "-isystem${lsep}"
# Library search paths partitioned by (in store, non-sytem, system)
-extend args_list spack_flags_spack_store_lib_dirs_list "-L"
+extend args_list spack_store_spack_flags_lib_dirs_list "-L"
extend args_list spack_store_lib_dirs_list "-L"
extend args_list spack_flags_lib_dirs_list "-L"
extend args_list lib_dirs_list "-L"
-extend args_list spack_flags_system_lib_dirs_list "-L"
+extend args_list system_spack_flags_lib_dirs_list "-L"
extend args_list system_lib_dirs_list "-L"
# RPATHs arguments
@@ -944,26 +895,26 @@ case "$mode" in
if [ -n "$dtags_to_add" ] ; then
append args_list "$linker_arg$dtags_to_add"
fi
- extend args_list spack_flags_spack_store_rpath_dirs_list "$rpath"
+ extend args_list spack_store_spack_flags_rpath_dirs_list "$rpath"
extend args_list spack_store_rpath_dirs_list "$rpath"
extend args_list spack_flags_rpath_dirs_list "$rpath"
extend args_list rpath_dirs_list "$rpath"
- extend args_list spack_flags_system_rpath_dirs_list "$rpath"
+ extend args_list system_spack_flags_rpath_dirs_list "$rpath"
extend args_list system_rpath_dirs_list "$rpath"
;;
ld)
if [ -n "$dtags_to_add" ] ; then
append args_list "$dtags_to_add"
fi
- extend args_list spack_flags_spack_store_rpath_dirs_list "-rpath${lsep}"
+ extend args_list spack_store_spack_flags_rpath_dirs_list "-rpath${lsep}"
extend args_list spack_store_rpath_dirs_list "-rpath${lsep}"
extend args_list spack_flags_rpath_dirs_list "-rpath${lsep}"
extend args_list rpath_dirs_list "-rpath${lsep}"
- extend args_list spack_flags_system_rpath_dirs_list "-rpath${lsep}"
+ extend args_list system_spack_flags_rpath_dirs_list "-rpath${lsep}"
extend args_list system_rpath_dirs_list "-rpath${lsep}"
;;
esac