From 5d618886570e98e6745593701246b877998a5367 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 23 Nov 2015 16:51:16 -0500 Subject: Correct Spack cc script --- lib/spack/env/cc | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 75a63f6fac..f3fadfcf45 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -126,6 +126,11 @@ if [ -z "$mode" ]; then elif [ "$arg" = -c ]; then mode=cc break + elif [ "$arg" = -S ]; then + mode=as + echo "spac cc mode as" "$@" + exit 1 + break fi done fi @@ -155,6 +160,7 @@ libraries=() libs=() rpaths=() other_args=() +all_args=("$@") while [ -n "$1" ]; do case "$1" in @@ -178,6 +184,8 @@ while [ -n "$1" ]; do if [ -z "$arg" ]; then shift; arg="$1"; fi if [[ "$arg" = -rpath=* ]]; then rpaths+=("${arg#-rpath=}") + elif [[ "$arg" = -rpath,* ]]; then + rpaths+=("${arg#-rpath,}") elif [[ "$arg" = -rpath ]]; then shift; arg="$1" if [[ "$arg" != -Wl,* ]]; then @@ -193,6 +201,8 @@ while [ -n "$1" ]; do if [ -z "$arg" ]; then shift; arg="$1"; fi if [[ "$arg" = -rpath=* ]]; then rpaths+=("${arg#-rpath=}") + elif [[ "$arg" = -rpath,* ]]; then + rpaths+=("${arg#-rpath,}") elif [[ "$arg" = -rpath ]]; then shift; arg="$1" if [[ "$arg" != -Xlinker,* ]]; then @@ -247,25 +257,46 @@ IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES" for dep in "${deps[@]}"; do if [ -d "$dep/include" ]; then includes+=("$dep/include") + all_args=("-I$dep/include" ${all_args[@]}) fi if [ -d "$dep/lib" ]; then libraries+=("$dep/lib") rpaths+=("$dep/lib") + if [ "$mode" = ccld ]; then + all_args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" ${all_args[@]}) + elif [ "$mode" = ld ]; then + all_args=("-L$dep/lib" "-rpath" "$dep/lib" ${all_args[@]}) + fi fi if [ -d "$dep/lib64" ]; then libraries+=("$dep/lib64") rpaths+=("$dep/lib64") + if [ "$mode" = ccld ]; then + all_args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" ${all_args[@]}) + elif [ "$mode" = ld ]; then + all_args=("-L$dep/lib" "-rpath" "$dep/lib" ${all_args[@]}) + fi fi done # Include all -L's and prefix/whatever dirs in rpath for dir in "${libraries[@]}"; do [[ dir = $SPACK_INSTALL* ]] && rpaths+=("$dir") + if [ "$mode" = ccld ]; then + [[ dir = $SPACK_INSTALL* ]] && all_args=("-Wl,-rpath,$dir" ${all_args[@]}) + elif [ "$mode" = ld ]; then + [[ dir = $SPACK_INSTALL* ]] && all_args=("-rpath" "$dir" ${all_args[@]}) + fi done rpaths+=("$SPACK_PREFIX/lib") rpaths+=("$SPACK_PREFIX/lib64") +if [ "$mode" = ccld ]; then + all_args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" ${all_args[@]}) +elif [ "$mode" = ld ]; then + all_args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" ${all_args[@]}) +fi # Put the arguments together args=() @@ -317,7 +348,8 @@ done export PATH full_command=("$command") -full_command+=("${args[@]}") +# full_command+=("${args[@]}") +full_command+=("${all_args[@]}") # # Write the input and output commands to debug logs if it's asked for. -- cgit v1.2.3-60-g2f50 From ba22fc8b78841728500966d471db7b5bfd26cf56 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 21 Dec 2015 10:21:33 -0500 Subject: Simplify Spack cc script --- lib/spack/env/cc | 283 +++++++++++++++++++++++++------------------------------ 1 file changed, 130 insertions(+), 153 deletions(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index f3fadfcf45..053295f42d 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -65,7 +65,7 @@ function die { } for param in $parameters; do - if [ -z "${!param}" ]; then + if [[ -z ${!param} ]]; then die "Spack compiler must be run from spack! Input $param was missing!" fi done @@ -114,114 +114,118 @@ case "$command" in esac # Finish setting up the mode. -if [ -z "$mode" ]; then +if [[ -z $mode ]]; then mode=ccld for arg in "$@"; do - if [ "$arg" = -v -o "$arg" = -V -o "$arg" = --version -o "$arg" = -dumpversion ]; then - mode=vcheck - break - elif [ "$arg" = -E ]; then - mode=cpp - break - elif [ "$arg" = -c ]; then - mode=cc - break - elif [ "$arg" = -S ]; then - mode=as - echo "spac cc mode as" "$@" - exit 1 - break - fi + case "$arg" in + -v|-V|--version|-dumpversion) + mode=vcheck + break + ;; + -E) + mode=cpp + break + ;; + -c) + mode=cc + break + ;; + -S) + mode=as + break + ;; + esac done fi # Dump the version and exist if we're in testing mode. -if [ "$SPACK_TEST_COMMAND" = "dump-mode" ]; then +if [[ $SPACK_TEST_COMMAND = dump-mode ]]; then echo "$mode" exit fi # Check that at least one of the real commands was actually selected, # otherwise we don't know what to execute. -if [ -z "$command" ]; then +if [[ -z $command ]]; then die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs." fi # Save original command for debug logging input_command="$@" +args=("$@") -# -# Now do real parsing of the command line args, trying hard to keep -# non-rpath linker arguments in the proper order w.r.t. other command -# line arguments. This is important for things like groups. -# -includes=() -libraries=() -libs=() -rpaths=() -other_args=() -all_args=("$@") +# Dump parsed values for unit testing if asked for +if [[ -n $SPACK_TEST_COMMAND ]]; then -while [ -n "$1" ]; do - case "$1" in - -I*) - arg="${1#-I}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - includes+=("$arg") - ;; - -L*) - arg="${1#-L}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - libraries+=("$arg") - ;; - -l*) - arg="${1#-l}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - libs+=("$arg") - ;; - -Wl,*) - arg="${1#-Wl,}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - if [[ "$arg" = -rpath=* ]]; then - rpaths+=("${arg#-rpath=}") - elif [[ "$arg" = -rpath,* ]]; then - rpaths+=("${arg#-rpath,}") - elif [[ "$arg" = -rpath ]]; then - shift; arg="$1" - if [[ "$arg" != -Wl,* ]]; then - die "-Wl,-rpath was not followed by -Wl,*" + # + # Now do real parsing of the command line args, trying hard to keep + # non-rpath linker arguments in the proper order w.r.t. other command line + # arguments. This is important for things like groups. + # + includes=() + libraries=() + libs=() + rpaths=() + other_args=() + + while [[ -n $1 ]]; do + case "$1" in + -I*) + arg="${1#-I}" + if [[ -z $arg ]]; then shift; arg="$1"; fi + includes+=("$arg") + ;; + -L*) + arg="${1#-L}" + if [[ -z $arg ]]; then shift; arg="$1"; fi + libraries+=("$arg") + ;; + -l*) + arg="${1#-l}" + if [[ -z $arg ]]; then shift; arg="$1"; fi + libs+=("$arg") + ;; + -Wl,*) + arg="${1#-Wl,}" + if [[ -z $arg ]]; then shift; arg="$1"; fi + if [[ $arg = -rpath=* ]]; then + rpaths+=("${arg#-rpath=}") + elif [[ $arg = -rpath,* ]]; then + rpaths+=("${arg#-rpath,}") + elif [[ $arg = -rpath ]]; then + shift; arg="$1" + if [[ $arg != -Wl,* ]]; then + die "-Wl,-rpath was not followed by -Wl,*" + fi + rpaths+=("${arg#-Wl,}") + else + other_args+=("-Wl,$arg") fi - rpaths+=("${arg#-Wl,}") - else - other_args+=("-Wl,$arg") - fi - ;; - -Xlinker,*) - arg="${1#-Xlinker,}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - if [[ "$arg" = -rpath=* ]]; then - rpaths+=("${arg#-rpath=}") - elif [[ "$arg" = -rpath,* ]]; then - rpaths+=("${arg#-rpath,}") - elif [[ "$arg" = -rpath ]]; then - shift; arg="$1" - if [[ "$arg" != -Xlinker,* ]]; then - die "-Xlinker,-rpath was not followed by -Xlinker,*" + ;; + -Xlinker,*) + arg="${1#-Xlinker,}" + if [[ -z $arg ]]; then shift; arg="$1"; fi + if [[ $arg = -rpath=* ]]; then + rpaths+=("${arg#-rpath=}") + elif [[ $arg = -rpath,* ]]; then + rpaths+=("${arg#-rpath,}") + elif [[ $arg = -rpath ]]; then + shift; arg="$1" + if [[ $arg != -Xlinker,* ]]; then + die "-Xlinker,-rpath was not followed by -Xlinker,*" + fi + rpaths+=("${arg#-Xlinker,}") + else + other_args+=("-Xlinker,$arg") fi - rpaths+=("${arg#-Xlinker,}") - else - other_args+=("-Xlinker,$arg") - fi - ;; - *) - other_args+=("$1") - ;; - esac - shift -done + ;; + *) + other_args+=("$1") + ;; + esac + shift + done -# Dump parsed values for unit testing if asked for -if [ -n "$SPACK_TEST_COMMAND" ]; then IFS=$'\n' case "$SPACK_TEST_COMMAND" in dump-includes) echo "${includes[*]}";; @@ -246,8 +250,8 @@ if [ -n "$SPACK_TEST_COMMAND" ]; then echo "${other_args[*]}" ;; *) - echo "ERROR: Unknown test command" - exit 1 ;; + die "ERROR: Unknown test command" + ;; esac exit fi @@ -255,66 +259,44 @@ fi # Read spack dependencies from the path environment variable IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES" for dep in "${deps[@]}"; do - if [ -d "$dep/include" ]; then - includes+=("$dep/include") - all_args=("-I$dep/include" ${all_args[@]}) + if [[ -d $dep/include ]]; then + args=("-I$dep/include" "${args[@]}") fi - if [ -d "$dep/lib" ]; then - libraries+=("$dep/lib") - rpaths+=("$dep/lib") - if [ "$mode" = ccld ]; then - all_args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" ${all_args[@]}) - elif [ "$mode" = ld ]; then - all_args=("-L$dep/lib" "-rpath" "$dep/lib" ${all_args[@]}) - fi + if [[ -d $dep/lib ]]; then + # libraries+=("$dep/lib") + if [[ $mode = ccld ]]; then + args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") + elif [[ $mode = ld ]]; then + args=("-L$dep/lib" "-rpath" "$dep/lib" "${args[@]}") + fi fi - if [ -d "$dep/lib64" ]; then - libraries+=("$dep/lib64") - rpaths+=("$dep/lib64") - if [ "$mode" = ccld ]; then - all_args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" ${all_args[@]}) - elif [ "$mode" = ld ]; then - all_args=("-L$dep/lib" "-rpath" "$dep/lib" ${all_args[@]}) - fi + if [[ -d $dep/lib64 ]]; then + # libraries+=("$dep/lib64") + if [[ $mode = ccld ]]; then + args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") + elif [[ $mode = ld ]]; then + args=("-L$dep/lib" "-rpath" "$dep/lib" "${args[@]}") + fi fi done # Include all -L's and prefix/whatever dirs in rpath -for dir in "${libraries[@]}"; do - [[ dir = $SPACK_INSTALL* ]] && rpaths+=("$dir") - if [ "$mode" = ccld ]; then - [[ dir = $SPACK_INSTALL* ]] && all_args=("-Wl,-rpath,$dir" ${all_args[@]}) - elif [ "$mode" = ld ]; then - [[ dir = $SPACK_INSTALL* ]] && all_args=("-rpath" "$dir" ${all_args[@]}) - fi -done -rpaths+=("$SPACK_PREFIX/lib") -rpaths+=("$SPACK_PREFIX/lib64") -if [ "$mode" = ccld ]; then - all_args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" ${all_args[@]}) -elif [ "$mode" = ld ]; then - all_args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" ${all_args[@]}) -fi - -# Put the arguments together -args=() -for dir in "${includes[@]}"; do args+=("-I$dir"); done -args+=("${other_args[@]}") -for dir in "${libraries[@]}"; do args+=("-L$dir"); done -for lib in "${libs[@]}"; do args+=("-l$lib"); done - -if [ "$mode" = ccld ]; then - for dir in "${rpaths[@]}"; do - args+=("-Wl,-rpath") - args+=("-Wl,$dir"); - done -elif [ "$mode" = ld ]; then - for dir in "${rpaths[@]}"; do - args+=("-rpath") - args+=("$dir"); - done +if [[ $mode = ccld ]]; then + # for dir in "${libraries[@]}"; do + # if [[ dir = $SPACK_INSTALL* ]]; then + # args=("-Wl,-rpath,$dir" "${args[@]}") + # fi + # done + args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" ${args[@]}) +elif [[ $mode = ld ]]; then + # for dir in "${libraries[@]}"; do + # if [[ dir = $SPACK_INSTALL* ]]; then + # args=("-rpath" "$dir" "${args[@]}") + # fi + # done + args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" ${args[@]}) fi # @@ -330,34 +312,29 @@ unset DYLD_LIBRARY_PATH # IFS=':' read -ra env_path <<< "$PATH" IFS=':' read -ra spack_env_dirs <<< "$SPACK_ENV_PATH" -spack_env_dirs+=(".") +spack_env_dirs+=("" ".") PATH="" for dir in "${env_path[@]}"; do remove="" for rm_dir in "${spack_env_dirs[@]}"; do - if [ "$dir" = "$rm_dir" ]; then remove=True; fi + if [[ $dir = $rm_dir ]]; then remove=True; fi done - if [ -z "$remove" ]; then - if [ -z "$PATH" ]; then - PATH="$dir" - else - PATH="$PATH:$dir" - fi + if [[ -z $remove ]]; then + PATH="${PATH:+$PATH:}$dir" fi done export PATH full_command=("$command") -# full_command+=("${args[@]}") -full_command+=("${all_args[@]}") +full_command+=("${args[@]}") # # Write the input and output commands to debug logs if it's asked for. # -if [ "$SPACK_DEBUG" = "TRUE" ]; then +if [[ $SPACK_DEBUG = TRUE ]]; then input_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.in.log" output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.out.log" - echo "$input_command" >> $input_log + echo "$input_command" >> $input_log echo "$mode ${full_command[@]}" >> $output_log fi -- cgit v1.2.3-60-g2f50 From 3427174eb065a6e74fc279076423c2c5c5e8e737 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 22 Dec 2015 15:49:14 -0500 Subject: Correct quoting --- lib/spack/env/cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 565f959ca4..4ac8f2e7f4 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -265,7 +265,7 @@ for dep in "${deps[@]}"; do if [[ -d $dep/lib ]]; then # libraries+=("$dep/lib") - if [[ $mode = ccld ]]; then + if [[ $mode = ccld ]]; then args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") elif [[ $mode = ld ]]; then args=("-L$dep/lib" "-rpath" "$dep/lib" "${args[@]}") @@ -289,14 +289,14 @@ if [[ $mode = ccld ]]; then # args=("-Wl,-rpath,$dir" "${args[@]}") # fi # done - args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" ${args[@]}) + args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}") elif [[ $mode = ld ]]; then # for dir in "${libraries[@]}"; do # if [[ dir = $SPACK_INSTALL* ]]; then # args=("-rpath" "$dir" "${args[@]}") # fi # done - args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" ${args[@]}) + args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}") fi # @@ -325,8 +325,7 @@ for dir in "${env_path[@]}"; do done export PATH -full_command=("$command") -full_command+=("${args[@]}") +full_command=("$command" "${args[@]}") # # Write the input and output commands to debug logs if it's asked for. -- cgit v1.2.3-60-g2f50 From ff81aff2540f9eadd8d0ce123ae3143ebcb68789 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Fri, 12 Feb 2016 13:05:42 -0500 Subject: Remove source-code optimization and cleanup --- lib/spack/env/cc | 106 +++++++++++++++++++++++-------------------------------- 1 file changed, 44 insertions(+), 62 deletions(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index b83731404b..ac8f717cc7 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -65,7 +65,7 @@ function die { } for param in $parameters; do - if [[ -z ${!param} ]]; then + if [ -z "${!param}" ]; then die "Spack compiler must be run from spack! Input $param was missing!" fi done @@ -114,39 +114,31 @@ case "$command" in esac # Finish setting up the mode. -if [[ -z $mode ]]; then +if [ -z "$mode" ]; then mode=ccld for arg in "$@"; do - case "$arg" in - -v|-V|--version|-dumpversion) - mode=vcheck - break - ;; - -E) - mode=cpp - break - ;; - -c) - mode=cc - break - ;; - -S) - mode=as - break - ;; - esac + if [ "$arg" = -v -o "$arg" = -V -o "$arg" = --version -o "$arg" = -dumpversion ]; then + mode=vcheck + break + elif [ "$arg" = -E ]; then + mode=cpp + break + elif [ "$arg" = -c ]; then + mode=cc + break + fi done fi # Dump the version and exist if we're in testing mode. -if [[ $SPACK_TEST_COMMAND = dump-mode ]]; then +if [ "$SPACK_TEST_COMMAND" = "dump-mode" ]; then echo "$mode" exit fi # Check that at least one of the real commands was actually selected, # otherwise we don't know what to execute. -if [[ -z $command ]]; then +if [ -z "$command" ]; then die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs." fi @@ -159,8 +151,8 @@ if [[ -n $SPACK_TEST_COMMAND ]]; then # # Now do real parsing of the command line args, trying hard to keep - # non-rpath linker arguments in the proper order w.r.t. other command line - # arguments. This is important for things like groups. + # non-rpath linker arguments in the proper order w.r.t. other command + # line arguments. This is important for things like groups. # includes=() libraries=() @@ -168,33 +160,31 @@ if [[ -n $SPACK_TEST_COMMAND ]]; then rpaths=() other_args=() - while [[ -n $1 ]]; do + while [ -n "$1" ]; do case "$1" in -I*) arg="${1#-I}" - if [[ -z $arg ]]; then shift; arg="$1"; fi + if [ -z "$arg" ]; then shift; arg="$1"; fi includes+=("$arg") ;; -L*) arg="${1#-L}" - if [[ -z $arg ]]; then shift; arg="$1"; fi + if [ -z "$arg" ]; then shift; arg="$1"; fi libraries+=("$arg") ;; -l*) arg="${1#-l}" - if [[ -z $arg ]]; then shift; arg="$1"; fi + if [ -z "$arg" ]; then shift; arg="$1"; fi libs+=("$arg") ;; -Wl,*) arg="${1#-Wl,}" - if [[ -z $arg ]]; then shift; arg="$1"; fi - if [[ $arg = -rpath=* ]]; then + if [ -z "$arg" ]; then shift; arg="$1"; fi + if [[ "$arg" = -rpath=* ]]; then rpaths+=("${arg#-rpath=}") - elif [[ $arg = -rpath,* ]]; then - rpaths+=("${arg#-rpath,}") - elif [[ $arg = -rpath ]]; then + elif [[ "$arg" = -rpath ]]; then shift; arg="$1" - if [[ $arg != -Wl,* ]]; then + if [[ "$arg" != -Wl,* ]]; then die "-Wl,-rpath was not followed by -Wl,*" fi rpaths+=("${arg#-Wl,}") @@ -204,14 +194,12 @@ if [[ -n $SPACK_TEST_COMMAND ]]; then ;; -Xlinker,*) arg="${1#-Xlinker,}" - if [[ -z $arg ]]; then shift; arg="$1"; fi - if [[ $arg = -rpath=* ]]; then + if [ -z "$arg" ]; then shift; arg="$1"; fi + if [[ "$arg" = -rpath=* ]]; then rpaths+=("${arg#-rpath=}") - elif [[ $arg = -rpath,* ]]; then - rpaths+=("${arg#-rpath,}") - elif [[ $arg = -rpath ]]; then + elif [[ "$arg" = -rpath ]]; then shift; arg="$1" - if [[ $arg != -Xlinker,* ]]; then + if [[ "$arg" != -Xlinker,* ]]; then die "-Xlinker,-rpath was not followed by -Xlinker,*" fi rpaths+=("${arg#-Xlinker,}") @@ -250,8 +238,8 @@ if [[ -n $SPACK_TEST_COMMAND ]]; then echo "${other_args[*]}" ;; *) - die "ERROR: Unknown test command" - ;; + echo "ERROR: Unknown test command" + exit 1 ;; esac exit fi @@ -259,12 +247,11 @@ fi # Read spack dependencies from the path environment variable IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES" for dep in "${deps[@]}"; do - if [[ -d $dep/include ]]; then + if [ -d "$dep/include" ]; then args=("-I$dep/include" "${args[@]}") fi - if [[ -d $dep/lib ]]; then - # libraries+=("$dep/lib") + if [ -d "$dep/lib" ]; then if [[ $mode = ccld ]]; then args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") elif [[ $mode = ld ]]; then @@ -272,7 +259,7 @@ for dep in "${deps[@]}"; do fi fi - if [[ -d $dep/lib64 ]]; then + if [ -d "$dep/lib64" ]; then # libraries+=("$dep/lib64") if [[ $mode = ccld ]]; then args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") @@ -284,18 +271,8 @@ done # Include all -L's and prefix/whatever dirs in rpath if [[ $mode = ccld ]]; then - # for dir in "${libraries[@]}"; do - # if [[ dir = $SPACK_INSTALL* ]]; then - # args=("-Wl,-rpath,$dir" "${args[@]}") - # fi - # done args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}") elif [[ $mode = ld ]]; then - # for dir in "${libraries[@]}"; do - # if [[ dir = $SPACK_INSTALL* ]]; then - # args=("-rpath" "$dir" "${args[@]}") - # fi - # done args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}") fi @@ -317,23 +294,28 @@ PATH="" for dir in "${env_path[@]}"; do remove="" for rm_dir in "${spack_env_dirs[@]}"; do - if [[ $dir = $rm_dir ]]; then remove=True; fi + if [ "$dir" = "$rm_dir" ]; then remove=True; fi done - if [[ -z $remove ]]; then - PATH="${PATH:+$PATH:}$dir" + if [ -z "$remove" ]; then + if [ -z "$PATH" ]; then + PATH="$dir" + else + PATH="$PATH:$dir" + fi fi done export PATH -full_command=("$command" "${args[@]}") +full_command=("$command") +full_command+=("${args[@]}") # # Write the input and output commands to debug logs if it's asked for. # -if [[ $SPACK_DEBUG = TRUE ]]; then +if [ "$SPACK_DEBUG" = "TRUE" ]; then input_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.in.log" output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.out.log" - echo "$input_command" >> $input_log + echo "$input_command" >> $input_log echo "$mode ${full_command[@]}" >> $output_log fi -- cgit v1.2.3-60-g2f50 From f3ea0420f80f418a0f3e628479c782f197e6a43e Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Thu, 17 Mar 2016 21:53:13 -0400 Subject: Import recent changes --- lib/spack/env/cc | 185 +++++++++++++++++++------------------------------------ 1 file changed, 65 insertions(+), 120 deletions(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index df6795c264..c6a09724e9 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -65,7 +65,7 @@ function die { } for param in $parameters; do - if [ -z "${!param}" ]; then + if [[ -z ${!param} ]]; then die "Spack compiler must be run from spack! Input $param was missing!" fi done @@ -78,10 +78,11 @@ done # 'command' is set based on the input command to $SPACK_[CC|CXX|F77|F90] # # 'mode' is set to one of: +# cpp preprocess # cc compile +# as assemble # ld link # ccld compile & link -# cpp preprocessor # vcheck version check # command=$(basename "$0") @@ -131,6 +132,9 @@ if [ -z "$mode" ]; then if [ "$arg" = -E ]; then mode=cpp break + elif [ "$arg" = -S ]; then + mode=as + break elif [ "$arg" = -c ]; then mode=cc break @@ -146,22 +150,25 @@ fi # Check that at least one of the real commands was actually selected, # otherwise we don't know what to execute. -if [ -z "$command" ]; then +if [[ -z $command ]]; then die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs." fi +if [ "$mode" == vcheck ] ; then + exec ${command} "$@" +fi + # Save original command for debug logging input_command="$@" args=("$@") -<<<<<<< HEAD # Dump parsed values for unit testing if asked for if [[ -n $SPACK_TEST_COMMAND ]]; then # # Now do real parsing of the command line args, trying hard to keep - # non-rpath linker arguments in the proper order w.r.t. other command - # line arguments. This is important for things like groups. + # non-rpath linker arguments in the proper order w.r.t. other command line + # arguments. This is important for things like groups. # includes=() libraries=() @@ -188,32 +195,44 @@ if [[ -n $SPACK_TEST_COMMAND ]]; then ;; -Wl,*) arg="${1#-Wl,}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - if [[ "$arg" = -rpath=* ]]; then - rpaths+=("${arg#-rpath=}") - elif [[ "$arg" = -rpath ]]; then + # TODO: Handle multiple -Wl, continuations of -Wl,-rpath + if [[ $arg == -rpath=* ]]; then + arg="${arg#-rpath=}" + for rpath in ${arg//,/ }; do + rpaths+=("$rpath") + done + elif [[ $arg == -rpath,* ]]; then + arg="${arg#-rpath,}" + for rpath in ${arg//,/ }; do + rpaths+=("$rpath") + done + elif [[ $arg == -rpath ]]; then shift; arg="$1" - if [[ "$arg" != -Wl,* ]]; then + if [[ $arg != '-Wl,'* ]]; then die "-Wl,-rpath was not followed by -Wl,*" fi - rpaths+=("${arg#-Wl,}") + arg="${arg#-Wl,}" + for rpath in ${arg//,/ }; do + rpaths+=("$rpath") + done else other_args+=("-Wl,$arg") fi ;; - -Xlinker,*) - arg="${1#-Xlinker,}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - if [[ "$arg" = -rpath=* ]]; then + -Xlinker) + shift; arg="$1"; + if [[ $arg = -rpath=* ]]; then rpaths+=("${arg#-rpath=}") - elif [[ "$arg" = -rpath ]]; then + elif [[ $arg = -rpath ]]; then shift; arg="$1" - if [[ "$arg" != -Xlinker,* ]]; then - die "-Xlinker,-rpath was not followed by -Xlinker,*" + if [[ $arg != -Xlinker ]]; then + die "-Xlinker -rpath was not followed by -Xlinker " fi - rpaths+=("${arg#-Xlinker,}") + shift; arg="$1" + rpaths+=("$arg") else - other_args+=("-Xlinker,$arg") + other_args+=("-Xlinker") + other_args+=("$arg") fi ;; *) @@ -222,88 +241,6 @@ if [[ -n $SPACK_TEST_COMMAND ]]; then esac shift done -======= -if [ "$mode" == vcheck ] ; then - exec ${command} "$@" -fi - -# -# Now do real parsing of the command line args, trying hard to keep -# non-rpath linker arguments in the proper order w.r.t. other command -# line arguments. This is important for things like groups. -# -includes=() -libraries=() -libs=() -rpaths=() -other_args=() - -while [ -n "$1" ]; do - case "$1" in - -I*) - arg="${1#-I}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - includes+=("$arg") - ;; - -L*) - arg="${1#-L}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - libraries+=("$arg") - ;; - -l*) - arg="${1#-l}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - libs+=("$arg") - ;; - -Wl,*) - arg="${1#-Wl,}" - # TODO: Handle multiple -Wl, continuations of -Wl,-rpath - if [[ $arg == -rpath=* ]]; then - arg="${arg#-rpath=}" - for rpath in ${arg//,/ }; do - rpaths+=("$rpath") - done - elif [[ $arg == -rpath,* ]]; then - arg="${arg#-rpath,}" - for rpath in ${arg//,/ }; do - rpaths+=("$rpath") - done - elif [[ $arg == -rpath ]]; then - shift; arg="$1" - if [[ $arg != '-Wl,'* ]]; then - die "-Wl,-rpath was not followed by -Wl,*" - fi - arg="${arg#-Wl,}" - for rpath in ${arg//,/ }; do - rpaths+=("$rpath") - done - else - other_args+=("-Wl,$arg") - fi - ;; - -Xlinker) - shift; arg="$1"; - if [[ $arg = -rpath=* ]]; then - rpaths+=("${arg#-rpath=}") - elif [[ $arg = -rpath ]]; then - shift; arg="$1" - if [[ $arg != -Xlinker ]]; then - die "-Xlinker -rpath was not followed by -Xlinker " - fi - shift; arg="$1" - rpaths+=("$arg") - else - other_args+=("-Xlinker") - other_args+=("$arg") - fi - ;; - *) - other_args+=("$1") - ;; - esac - shift -done ->>>>>>> develop IFS=$'\n' case "$SPACK_TEST_COMMAND" in @@ -329,8 +266,8 @@ done echo "${other_args[*]}" ;; *) - echo "ERROR: Unknown test command" - exit 1 ;; + die "ERROR: Unknown test command" + ;; esac exit fi @@ -338,11 +275,14 @@ fi # Read spack dependencies from the path environment variable IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES" for dep in "${deps[@]}"; do - if [ -d "$dep/include" ]; then - args=("-I$dep/include" "${args[@]}") + if [[ -d $dep/include ]]; then + if [[ $mode = cpp || $mode = cc || $mode = as || $mode = ccld ]]; then + args=("-I$dep/include" "${args[@]}") + fi fi - if [ -d "$dep/lib" ]; then + if [[ -d $dep/lib ]]; then + # libraries+=("$dep/lib") if [[ $mode = ccld ]]; then args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") elif [[ $mode = ld ]]; then @@ -350,7 +290,7 @@ for dep in "${deps[@]}"; do fi fi - if [ -d "$dep/lib64" ]; then + if [[ -d $dep/lib64 ]]; then # libraries+=("$dep/lib64") if [[ $mode = ccld ]]; then args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") @@ -362,8 +302,18 @@ done # Include all -L's and prefix/whatever dirs in rpath if [[ $mode = ccld ]]; then + # for dir in "${libraries[@]}"; do + # if [[ dir = $SPACK_INSTALL* ]]; then + # args=("-Wl,-rpath,$dir" "${args[@]}") + # fi + # done args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}") elif [[ $mode = ld ]]; then + # for dir in "${libraries[@]}"; do + # if [[ dir = $SPACK_INSTALL* ]]; then + # args=("-rpath" "$dir" "${args[@]}") + # fi + # done args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}") fi @@ -385,28 +335,23 @@ PATH="" for dir in "${env_path[@]}"; do remove="" for rm_dir in "${spack_env_dirs[@]}"; do - if [ "$dir" = "$rm_dir" ]; then remove=True; fi + if [[ $dir = $rm_dir ]]; then remove=True; fi done - if [ -z "$remove" ]; then - if [ -z "$PATH" ]; then - PATH="$dir" - else - PATH="$PATH:$dir" - fi + if [[ -z $remove ]]; then + PATH="${PATH:+$PATH:}$dir" fi done export PATH -full_command=("$command") -full_command+=("${args[@]}") +full_command=("$command" "${args[@]}") # # Write the input and output commands to debug logs if it's asked for. # -if [ "$SPACK_DEBUG" = "TRUE" ]; then +if [[ $SPACK_DEBUG = TRUE ]]; then input_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.in.log" output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.out.log" - echo "$input_command" >> $input_log + echo "$input_command" >> $input_log echo "$mode ${full_command[@]}" >> $output_log fi -- cgit v1.2.3-60-g2f50 From f3dd889d4462d14c9f0233540bccbf6a9720bcf0 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 28 Mar 2016 03:51:05 -0700 Subject: Fix bug with lib64 RPATH setting in cc. --- lib/spack/env/cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index c6a09724e9..17740250d1 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -293,9 +293,9 @@ for dep in "${deps[@]}"; do if [[ -d $dep/lib64 ]]; then # libraries+=("$dep/lib64") if [[ $mode = ccld ]]; then - args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") + args=("-L$dep/lib64" "-Wl,-rpath,$dep/lib64" "${args[@]}") elif [[ $mode = ld ]]; then - args=("-L$dep/lib" "-rpath" "$dep/lib" "${args[@]}") + args=("-L$dep/lib64" "-rpath" "$dep/lib64" "${args[@]}") fi fi done -- cgit v1.2.3-60-g2f50 From d8579a5b80efd8b09e5332a922dee533f2a0a55e Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 28 Mar 2016 03:51:41 -0700 Subject: Simplify cc: Remove old logic and add better tests. - removed a lot of old logic that was only still needed for tests. - Added better unit tests for dependency RPATH, -L, and -I args - tests now check whether the compiler omits -I args in link mode. --- lib/spack/env/cc | 138 +++++---------------------------------------- lib/spack/spack/test/cc.py | 127 +++++++++++++++++++++++++++++++++++------ 2 files changed, 123 insertions(+), 142 deletions(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 17740250d1..4217159a25 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -114,7 +114,9 @@ case "$command" in ;; esac -# If any of the arguments below is present then the mode is vcheck. In vcheck mode nothing is added in terms of extra search paths or libraries +# If any of the arguments below is present then the mode is vcheck. In +# vcheck mode nothing is added in terms of extra search paths or +# libraries if [ -z "$mode" ]; then for arg in "$@"; do if [ "$arg" = -v -o "$arg" = -V -o "$arg" = --version -o "$arg" = -dumpversion ]; then @@ -125,7 +127,6 @@ if [ -z "$mode" ]; then fi # Finish setting up the mode. - if [ -z "$mode" ]; then mode=ccld for arg in "$@"; do @@ -162,127 +163,18 @@ fi input_command="$@" args=("$@") -# Dump parsed values for unit testing if asked for -if [[ -n $SPACK_TEST_COMMAND ]]; then - - # - # Now do real parsing of the command line args, trying hard to keep - # non-rpath linker arguments in the proper order w.r.t. other command line - # arguments. This is important for things like groups. - # - includes=() - libraries=() - libs=() - rpaths=() - other_args=() - - while [ -n "$1" ]; do - case "$1" in - -I*) - arg="${1#-I}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - includes+=("$arg") - ;; - -L*) - arg="${1#-L}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - libraries+=("$arg") - ;; - -l*) - arg="${1#-l}" - if [ -z "$arg" ]; then shift; arg="$1"; fi - libs+=("$arg") - ;; - -Wl,*) - arg="${1#-Wl,}" - # TODO: Handle multiple -Wl, continuations of -Wl,-rpath - if [[ $arg == -rpath=* ]]; then - arg="${arg#-rpath=}" - for rpath in ${arg//,/ }; do - rpaths+=("$rpath") - done - elif [[ $arg == -rpath,* ]]; then - arg="${arg#-rpath,}" - for rpath in ${arg//,/ }; do - rpaths+=("$rpath") - done - elif [[ $arg == -rpath ]]; then - shift; arg="$1" - if [[ $arg != '-Wl,'* ]]; then - die "-Wl,-rpath was not followed by -Wl,*" - fi - arg="${arg#-Wl,}" - for rpath in ${arg//,/ }; do - rpaths+=("$rpath") - done - else - other_args+=("-Wl,$arg") - fi - ;; - -Xlinker) - shift; arg="$1"; - if [[ $arg = -rpath=* ]]; then - rpaths+=("${arg#-rpath=}") - elif [[ $arg = -rpath ]]; then - shift; arg="$1" - if [[ $arg != -Xlinker ]]; then - die "-Xlinker -rpath was not followed by -Xlinker " - fi - shift; arg="$1" - rpaths+=("$arg") - else - other_args+=("-Xlinker") - other_args+=("$arg") - fi - ;; - *) - other_args+=("$1") - ;; - esac - shift - done - - IFS=$'\n' - case "$SPACK_TEST_COMMAND" in - dump-includes) echo "${includes[*]}";; - dump-libraries) echo "${libraries[*]}";; - dump-libs) echo "${libs[*]}";; - dump-rpaths) echo "${rpaths[*]}";; - dump-other-args) echo "${other_args[*]}";; - dump-all) - echo "INCLUDES:" - echo "${includes[*]}" - echo - echo "LIBRARIES:" - echo "${libraries[*]}" - echo - echo "LIBS:" - echo "${libs[*]}" - echo - echo "RPATHS:" - echo "${rpaths[*]}" - echo - echo "ARGS:" - echo "${other_args[*]}" - ;; - *) - die "ERROR: Unknown test command" - ;; - esac - exit -fi - # Read spack dependencies from the path environment variable IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES" for dep in "${deps[@]}"; do + # Prepend include directories if [[ -d $dep/include ]]; then if [[ $mode = cpp || $mode = cc || $mode = as || $mode = ccld ]]; then args=("-I$dep/include" "${args[@]}") fi fi + # Prepend lib and RPATH directories if [[ -d $dep/lib ]]; then - # libraries+=("$dep/lib") if [[ $mode = ccld ]]; then args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") elif [[ $mode = ld ]]; then @@ -290,8 +182,8 @@ for dep in "${deps[@]}"; do fi fi + # Prepend lib64 and RPATH directories if [[ -d $dep/lib64 ]]; then - # libraries+=("$dep/lib64") if [[ $mode = ccld ]]; then args=("-L$dep/lib64" "-Wl,-rpath,$dep/lib64" "${args[@]}") elif [[ $mode = ld ]]; then @@ -302,18 +194,8 @@ done # Include all -L's and prefix/whatever dirs in rpath if [[ $mode = ccld ]]; then - # for dir in "${libraries[@]}"; do - # if [[ dir = $SPACK_INSTALL* ]]; then - # args=("-Wl,-rpath,$dir" "${args[@]}") - # fi - # done args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}") elif [[ $mode = ld ]]; then - # for dir in "${libraries[@]}"; do - # if [[ dir = $SPACK_INSTALL* ]]; then - # args=("-rpath" "$dir" "${args[@]}") - # fi - # done args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}") fi @@ -345,6 +227,14 @@ export PATH full_command=("$command" "${args[@]}") +# In test command mode, write out full command for Spack tests. +if [[ $SPACK_TEST_COMMAND = dump-args ]]; then + echo "${full_command[@]}" + exit +elif [[ -n $SPACK_TEST_COMMAND ]]; then + die "ERROR: Unknown test command" +fi + # # Write the input and output commands to debug logs if it's asked for. # diff --git a/lib/spack/spack/test/cc.py b/lib/spack/spack/test/cc.py index f3f6d4a22e..0b1aeb2a8f 100644 --- a/lib/spack/spack/test/cc.py +++ b/lib/spack/spack/test/cc.py @@ -28,6 +28,8 @@ arguments correctly. """ import os import unittest +import tempfile +import shutil from llnl.util.filesystem import * import spack @@ -55,13 +57,40 @@ class CompilerTest(unittest.TestCase): self.ld = Executable(join_path(spack.build_env_path, "ld")) self.cpp = Executable(join_path(spack.build_env_path, "cpp")) - os.environ['SPACK_CC'] = "/bin/mycc" - os.environ['SPACK_PREFIX'] = "/usr" + self.realcc = "/bin/mycc" + self.prefix = "/spack-test-prefix" + + os.environ['SPACK_CC'] = self.realcc + os.environ['SPACK_PREFIX'] = self.prefix os.environ['SPACK_ENV_PATH']="test" os.environ['SPACK_DEBUG_LOG_DIR'] = "." os.environ['SPACK_COMPILER_SPEC'] = "gcc@4.4.7" os.environ['SPACK_SHORT_SPEC'] = "foo@1.2" + # Make some fake dependencies + self.tmp_deps = tempfile.mkdtemp() + self.dep1 = join_path(self.tmp_deps, 'dep1') + self.dep2 = join_path(self.tmp_deps, 'dep2') + self.dep3 = join_path(self.tmp_deps, 'dep3') + self.dep4 = join_path(self.tmp_deps, 'dep4') + + mkdirp(join_path(self.dep1, 'include')) + mkdirp(join_path(self.dep1, 'lib')) + + mkdirp(join_path(self.dep2, 'lib64')) + + mkdirp(join_path(self.dep3, 'include')) + mkdirp(join_path(self.dep3, 'lib64')) + + mkdirp(join_path(self.dep4, 'include')) + + if 'SPACK_DEPENDENCIES' in os.environ: + del os.environ['SPACK_DEPENDENCIES'] + + + def tearDown(self): + shutil.rmtree(self.tmp_deps, True) + def check_cc(self, command, args, expected): os.environ['SPACK_TEST_COMMAND'] = command @@ -92,6 +121,10 @@ class CompilerTest(unittest.TestCase): self.check_cpp('dump-mode', [], "cpp") + def test_as_mode(self): + self.check_cc('dump-mode', ['-S'], "as") + + def test_ccld_mode(self): self.check_cc('dump-mode', [], "ccld") self.check_cc('dump-mode', ['foo.c', '-o', 'foo'], "ccld") @@ -104,27 +137,85 @@ class CompilerTest(unittest.TestCase): self.check_ld('dump-mode', ['foo.o', 'bar.o', 'baz.o', '-o', 'foo', '-Wl,-rpath,foo'], "ld") - def test_includes(self): - self.check_cc('dump-includes', test_command, - "\n".join(["/test/include", "/other/include"])) + def test_dep_rpath(self): + """Ensure RPATHs for root package are added.""" + self.check_cc('dump-args', test_command, + self.realcc + ' ' + + '-Wl,-rpath,' + self.prefix + '/lib ' + + '-Wl,-rpath,' + self.prefix + '/lib64 ' + + ' '.join(test_command)) + + + def test_dep_include(self): + """Ensure a single dependency include directory is added.""" + os.environ['SPACK_DEPENDENCIES'] = self.dep4 + self.check_cc('dump-args', test_command, + self.realcc + ' ' + + '-Wl,-rpath,' + self.prefix + '/lib ' + + '-Wl,-rpath,' + self.prefix + '/lib64 ' + + '-I' + self.dep4 + '/include ' + + ' '.join(test_command)) + + + def test_dep_lib(self): + """Ensure a single dependency RPATH is added.""" + os.environ['SPACK_DEPENDENCIES'] = self.dep2 + self.check_cc('dump-args', test_command, + self.realcc + ' ' + + '-Wl,-rpath,' + self.prefix + '/lib ' + + '-Wl,-rpath,' + self.prefix + '/lib64 ' + + '-L' + self.dep2 + '/lib64 ' + + '-Wl,-rpath,' + self.dep2 + '/lib64 ' + + ' '.join(test_command)) + + + def test_all_deps(self): + """Ensure includes and RPATHs for all deps are added. """ + os.environ['SPACK_DEPENDENCIES'] = ':'.join([ + self.dep1, self.dep2, self.dep3, self.dep4]) + + # This is probably more constrained than it needs to be; it + # checks order within prepended args and doesn't strictly have + # to. We could loosen that if it becomes necessary + self.check_cc('dump-args', test_command, + self.realcc + ' ' + + '-Wl,-rpath,' + self.prefix + '/lib ' + + '-Wl,-rpath,' + self.prefix + '/lib64 ' + + + '-I' + self.dep4 + '/include ' + + + '-L' + self.dep3 + '/lib64 ' + + '-Wl,-rpath,' + self.dep3 + '/lib64 ' + + '-I' + self.dep3 + '/include ' + + + '-L' + self.dep2 + '/lib64 ' + + '-Wl,-rpath,' + self.dep2 + '/lib64 ' + + + '-L' + self.dep1 + '/lib ' + + '-Wl,-rpath,' + self.dep1 + '/lib ' + + '-I' + self.dep1 + '/include ' + + + ' '.join(test_command)) - def test_libraries(self): - self.check_cc('dump-libraries', test_command, - "\n".join(["/test/lib", "/other/lib"])) + def test_ld_deps(self): + """Ensure no (extra) -I args or -Wl, are passed in ld mode.""" + os.environ['SPACK_DEPENDENCIES'] = ':'.join([ + self.dep1, self.dep2, self.dep3, self.dep4]) + self.check_ld('dump-args', test_command, + 'ld ' + + '-rpath ' + self.prefix + '/lib ' + + '-rpath ' + self.prefix + '/lib64 ' + - def test_libs(self): - self.check_cc('dump-libs', test_command, - "\n".join(["lib1", "lib2", "lib3", "lib4"])) + '-L' + self.dep3 + '/lib64 ' + + '-rpath ' + self.dep3 + '/lib64 ' + + '-L' + self.dep2 + '/lib64 ' + + '-rpath ' + self.dep2 + '/lib64 ' + - def test_rpaths(self): - self.check_cc('dump-rpaths', test_command, - "\n".join(["/first/rpath", "/second/rpath", "/third/rpath", "/fourth/rpath"])) + '-L' + self.dep1 + '/lib ' + + '-rpath ' + self.dep1 + '/lib ' + + ' '.join(test_command)) - def test_other_args(self): - self.check_cc('dump-other-args', test_command, - "\n".join(["arg1", "-Wl,--start-group", "arg2", "arg3", "arg4", - "-Wl,--end-group", "arg5", "arg6"])) -- cgit v1.2.3-60-g2f50 From a14527ec0619151d6defc909a46aefd2a9378cb7 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 28 Mar 2016 15:34:25 -0700 Subject: Add command to compiler input log. --- lib/spack/env/cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 4217159a25..68cd8514f4 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -241,7 +241,7 @@ fi if [[ $SPACK_DEBUG = TRUE ]]; then input_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.in.log" output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.out.log" - echo "$input_command" >> $input_log + echo "$command $input_command" >> $input_log echo "$mode ${full_command[@]}" >> $output_log fi -- cgit v1.2.3-60-g2f50 From f80e839ff48809a5ba8b7343d2378133a3fbce82 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 29 Mar 2016 02:58:05 -0700 Subject: Handle Darwin's ld -r option properly - ld -r doesn't work with RPATH on OS X. - for GNU ld, the -r option only means 'relocatable', and doesn't affect RPATH. - This adds special handling to omit RPATHs for ld -r on OS X --- lib/spack/env/cc | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 68cd8514f4..2eb6f46afe 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -85,6 +85,10 @@ done # ccld compile & link # vcheck version check # +# Depending on the mode, we may or may not add extra rpaths. +# This variable controls whether they are added. +add_rpaths=true + command=$(basename "$0") case "$command" in cc|c89|c99|gcc|clang|icc|pgcc|xlc) @@ -108,6 +112,17 @@ case "$command" in ;; ld) mode=ld + + # Darwin's linker has a -r argument that merges object files + # together. It doesn't work with -rpath. + if [[ $OSTYPE = darwin* ]]; then + for arg in "$@"; do + if [ "$arg" = -r ]; then + add_rpaths=false + break + fi + done + fi ;; *) die "Unkown compiler: $command" @@ -176,27 +191,31 @@ for dep in "${deps[@]}"; do # Prepend lib and RPATH directories if [[ -d $dep/lib ]]; then if [[ $mode = ccld ]]; then - args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}") + $add_rpaths && args=("-Wl,-rpath,$dep/lib" "${args[@]}") + args=("-L$dep/lib" "${args[@]}") elif [[ $mode = ld ]]; then - args=("-L$dep/lib" "-rpath" "$dep/lib" "${args[@]}") + $add_rpaths && args=("-rpath" "$dep/lib" "${args[@]}") + args=("-L$dep/lib" "${args[@]}") fi fi # Prepend lib64 and RPATH directories if [[ -d $dep/lib64 ]]; then if [[ $mode = ccld ]]; then - args=("-L$dep/lib64" "-Wl,-rpath,$dep/lib64" "${args[@]}") + $add_rpaths && args=("-Wl,-rpath,$dep/lib64" "${args[@]}") + args=("-L$dep/lib64" "${args[@]}") elif [[ $mode = ld ]]; then - args=("-L$dep/lib64" "-rpath" "$dep/lib64" "${args[@]}") + $add_rpaths && args=("-rpath" "$dep/lib64" "${args[@]}") + args=("-L$dep/lib64" "${args[@]}") fi fi done # Include all -L's and prefix/whatever dirs in rpath if [[ $mode = ccld ]]; then - args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}") + $add_rpaths && args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}") elif [[ $mode = ld ]]; then - args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}") + $add_rpaths && args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}") fi # @@ -241,8 +260,8 @@ fi if [[ $SPACK_DEBUG = TRUE ]]; then input_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.in.log" output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.out.log" - echo "$command $input_command" >> $input_log - echo "$mode ${full_command[@]}" >> $output_log + echo "[$mode] $command $input_command" >> $input_log + echo "[$mode] ${full_command[@]}" >> $output_log fi exec "${full_command[@]}" -- cgit v1.2.3-60-g2f50