cc: don't use sed to filter system directories
- filtering using sed causes most builds to slow down quite a bit, as the compiler wrapper has to run sed many times, and *it* runs many times - do the system directory parsing directly in bash
This commit is contained in:
parent
0e81f6cba5
commit
b84067f6db
95
lib/spack/env/cc
vendored
95
lib/spack/env/cc
vendored
@ -74,6 +74,18 @@ function die {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# test whether a path is a system directory
|
||||||
|
function system_dir {
|
||||||
|
path="$1"
|
||||||
|
for sd in ${SPACK_SYSTEM_DIRS[@]}; do
|
||||||
|
if [ "${path}" == "${sd}" -o "${path}" == "${sd}/" ]; then
|
||||||
|
# success if path starts with a system prefix
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1 # fail if path starts no system prefix
|
||||||
|
}
|
||||||
|
|
||||||
for param in ${parameters[@]}; do
|
for param in ${parameters[@]}; do
|
||||||
if [[ -z ${!param} ]]; then
|
if [[ -z ${!param} ]]; then
|
||||||
die "Spack compiler must be run from Spack! Input '$param' is missing."
|
die "Spack compiler must be run from Spack! Input '$param' is missing."
|
||||||
@ -255,21 +267,33 @@ args=()
|
|||||||
#
|
#
|
||||||
includes=()
|
includes=()
|
||||||
libdirs=()
|
libdirs=()
|
||||||
libs=()
|
|
||||||
rpaths=()
|
rpaths=()
|
||||||
|
system_includes=()
|
||||||
|
system_libdirs=()
|
||||||
|
system_rpaths=()
|
||||||
|
libs=()
|
||||||
other_args=()
|
other_args=()
|
||||||
|
|
||||||
while [ -n "$1" ]; do
|
while [ -n "$1" ]; do
|
||||||
|
rp=""
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-I*)
|
-I*)
|
||||||
arg="${1#-I}"
|
arg="${1#-I}"
|
||||||
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
||||||
|
if system_dir "$arg"; then
|
||||||
|
system_includes+=("$arg")
|
||||||
|
else
|
||||||
includes+=("$arg")
|
includes+=("$arg")
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
-L*)
|
-L*)
|
||||||
arg="${1#-L}"
|
arg="${1#-L}"
|
||||||
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
||||||
|
if system_dir "$arg"; then
|
||||||
|
system_libdirs+=("$arg")
|
||||||
|
else
|
||||||
libdirs+=("$arg")
|
libdirs+=("$arg")
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
-l*)
|
-l*)
|
||||||
arg="${1#-l}"
|
arg="${1#-l}"
|
||||||
@ -280,15 +304,15 @@ while [ -n "$1" ]; do
|
|||||||
arg="${1#-Wl,}"
|
arg="${1#-Wl,}"
|
||||||
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
||||||
if [[ "$arg" = -rpath=* ]]; then
|
if [[ "$arg" = -rpath=* ]]; then
|
||||||
rpaths+=("${arg#-rpath=}")
|
rp="${arg#-rpath=}"
|
||||||
elif [[ "$arg" = -rpath,* ]]; then
|
elif [[ "$arg" = -rpath,* ]]; then
|
||||||
rpaths+=("${arg#-rpath,}")
|
rp="${arg#-rpath,}"
|
||||||
elif [[ "$arg" = -rpath ]]; then
|
elif [[ "$arg" = -rpath ]]; then
|
||||||
shift; arg="$1"
|
shift; arg="$1"
|
||||||
if [[ "$arg" != -Wl,* ]]; then
|
if [[ "$arg" != -Wl,* ]]; then
|
||||||
die "-Wl,-rpath was not followed by -Wl,*"
|
die "-Wl,-rpath was not followed by -Wl,*"
|
||||||
fi
|
fi
|
||||||
rpaths+=("${arg#-Wl,}")
|
rp="${arg#-Wl,}"
|
||||||
else
|
else
|
||||||
other_args+=("-Wl,$arg")
|
other_args+=("-Wl,$arg")
|
||||||
fi
|
fi
|
||||||
@ -297,13 +321,13 @@ while [ -n "$1" ]; do
|
|||||||
arg="${1#-Xlinker,}"
|
arg="${1#-Xlinker,}"
|
||||||
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
||||||
if [[ "$arg" = -rpath=* ]]; then
|
if [[ "$arg" = -rpath=* ]]; then
|
||||||
rpaths+=("${arg#-rpath=}")
|
rp="${arg#-rpath=}"
|
||||||
elif [[ "$arg" = -rpath ]]; then
|
elif [[ "$arg" = -rpath ]]; then
|
||||||
shift; arg="$1"
|
shift; arg="$1"
|
||||||
if [[ "$arg" != -Xlinker,* ]]; then
|
if [[ "$arg" != -Xlinker,* ]]; then
|
||||||
die "-Xlinker,-rpath was not followed by -Xlinker,*"
|
die "-Xlinker,-rpath was not followed by -Xlinker,*"
|
||||||
fi
|
fi
|
||||||
rpaths+=("${arg#-Xlinker,}")
|
rp="${arg#-Xlinker,}"
|
||||||
else
|
else
|
||||||
other_args+=("-Xlinker,$arg")
|
other_args+=("-Xlinker,$arg")
|
||||||
fi
|
fi
|
||||||
@ -314,7 +338,7 @@ while [ -n "$1" ]; do
|
|||||||
die "-Xlinker,-rpath was not followed by -Xlinker,*"
|
die "-Xlinker,-rpath was not followed by -Xlinker,*"
|
||||||
fi
|
fi
|
||||||
shift 3;
|
shift 3;
|
||||||
rpaths+=("$1")
|
rp="$1"
|
||||||
else
|
else
|
||||||
other_args+=("$1")
|
other_args+=("$1")
|
||||||
fi
|
fi
|
||||||
@ -323,6 +347,15 @@ while [ -n "$1" ]; do
|
|||||||
other_args+=("$1")
|
other_args+=("$1")
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# test rpaths against system directories in one place.
|
||||||
|
if [ -n "$rp" ]; then
|
||||||
|
if system_dir "$rp"; then
|
||||||
|
system_rpaths+=("$rp")
|
||||||
|
else
|
||||||
|
rpaths+=("$rp")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -417,44 +450,26 @@ case "$mode" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Filter system locations to the end of each sublist of args
|
|
||||||
# (includes, library dirs, rpaths)
|
|
||||||
for sd in ${SPACK_SYSTEM_DIRS[@]}; do
|
|
||||||
stripped_includes=`echo $includes | sed "s#\b$sd/\? \b##g"`
|
|
||||||
stripped_libdirs=`echo $libdirs | sed "s#\b$sd/\? \b##g"`
|
|
||||||
stripped_rpaths=`echo $rpaths | sed "s#\b$sd/\? \b##g"`
|
|
||||||
if [[ "$includes" != "$stripped_includes" ]]; then
|
|
||||||
$includes="$stripped_includes $sd"
|
|
||||||
fi
|
|
||||||
if [[ "$libdirs" != "$stripped_libdirs" ]]; then
|
|
||||||
$libdirs="$stripped_libdirs $sd"
|
|
||||||
fi
|
|
||||||
if [[ "$rpaths" != "$stripped_rpaths" ]]; then
|
|
||||||
$rpaths="$stripped_rpaths $sd"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Put the arguments back together in one list
|
# Put the arguments back together in one list
|
||||||
# Includes first
|
# Includes and system includes first
|
||||||
for dir in "${includes[@]}"; do
|
for dir in "${includes[@]}"; do args+=("-I$dir"); done
|
||||||
args+=("-I$dir");
|
for dir in "${system_includes[@]}"; do args+=("-I$dir"); done
|
||||||
done
|
|
||||||
|
|
||||||
# Library search paths
|
# Library search paths
|
||||||
for dir in "${libdirs[@]}"; do
|
for dir in "${libdirs[@]}"; do args+=("-L$dir"); done
|
||||||
args+=("-L$dir");
|
for dir in "${system_libdirs[@]}"; do args+=("-L$dir"); done
|
||||||
done
|
|
||||||
|
|
||||||
# RPATHs arguments
|
# RPATHs arguments
|
||||||
if [ "$mode" = ccld ]; then
|
case "$mode" in
|
||||||
for dir in "${rpaths[@]}"; do
|
ccld)
|
||||||
args+=("$rpath$dir")
|
for dir in "${rpaths[@]}"; do args+=("$rpath$dir"); done
|
||||||
done
|
for dir in "${system_rpaths[@]}"; do args+=("$rpath$dir"); done
|
||||||
elif [ "$mode" = ld ]; then
|
;;
|
||||||
for dir in "${rpaths[@]}"; do
|
ld)
|
||||||
args+=("-rpath" "$dir")
|
for dir in "${rpaths[@]}"; do args+=("-rpath" "$dir"); done
|
||||||
done
|
for dir in "${system_rpaths[@]}"; do args+=("-rpath" "$dir"); done
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Other arguments from the input command
|
# Other arguments from the input command
|
||||||
args+=("${other_args[@]}")
|
args+=("${other_args[@]}")
|
||||||
|
@ -432,6 +432,42 @@ def test_cc_deps(dep1, dep2, dep3, dep4):
|
|||||||
test_args_without_paths)
|
test_args_without_paths)
|
||||||
|
|
||||||
|
|
||||||
|
def test_ccld_with_system_dirs(dep1, dep2, dep3, dep4):
|
||||||
|
"""Ensure all flags are added in ccld mode."""
|
||||||
|
deps = ':'.join((dep1, dep2, dep3, dep4))
|
||||||
|
with set_env(SPACK_DEPENDENCIES=deps,
|
||||||
|
SPACK_RPATH_DEPS=deps,
|
||||||
|
SPACK_LINK_DEPS=deps):
|
||||||
|
|
||||||
|
sys_path_args = ['-I/usr/include',
|
||||||
|
'-L/usr/local/lib',
|
||||||
|
'-Wl,-rpath,/usr/lib64',
|
||||||
|
'-I/usr/local/include',
|
||||||
|
'-L/lib64/']
|
||||||
|
check_cc(
|
||||||
|
'dump-args', sys_path_args + test_args,
|
||||||
|
[real_cc] +
|
||||||
|
test_include_paths +
|
||||||
|
['-I' + dep1 + '/include',
|
||||||
|
'-I' + dep3 + '/include',
|
||||||
|
'-I' + dep4 + '/include'] +
|
||||||
|
['-I/usr/include',
|
||||||
|
'-I/usr/local/include'] +
|
||||||
|
test_library_paths +
|
||||||
|
['-L' + dep1 + '/lib',
|
||||||
|
'-L' + dep2 + '/lib64',
|
||||||
|
'-L' + dep3 + '/lib64'] +
|
||||||
|
['-L/usr/local/lib',
|
||||||
|
'-L/lib64/'] +
|
||||||
|
test_wl_rpaths +
|
||||||
|
pkg_wl_rpaths +
|
||||||
|
['-Wl,-rpath,' + dep1 + '/lib',
|
||||||
|
'-Wl,-rpath,' + dep2 + '/lib64',
|
||||||
|
'-Wl,-rpath,' + dep3 + '/lib64'] +
|
||||||
|
['-Wl,-rpath,/usr/lib64'] +
|
||||||
|
test_args_without_paths)
|
||||||
|
|
||||||
|
|
||||||
def test_ld_deps(dep1, dep2, dep3, dep4):
|
def test_ld_deps(dep1, dep2, dep3, dep4):
|
||||||
"""Ensure no (extra) -I args or -Wl, are passed in ld mode."""
|
"""Ensure no (extra) -I args or -Wl, are passed in ld mode."""
|
||||||
deps = ':'.join((dep1, dep2, dep3, dep4))
|
deps = ':'.join((dep1, dep2, dep3, dep4))
|
||||||
|
Loading…
Reference in New Issue
Block a user