diff --git a/cc.sh b/cc.sh index d0a6f90..5d24bc2 100755 --- a/cc.sh +++ b/cc.sh @@ -754,6 +754,15 @@ elif [ "$SPACK_ADD_DEBUG_FLAGS" = "custom" ]; then extend flags_list SPACK_DEBUG_FLAGS fi +# -ffile-prefix-map==. injection for build reproducibility +case "$mode" in + cpp|as|cc|ccld) + if [ -n "${SPACK_DEBUG_PREFIX_MAP:-}" ]; then + append flags_list "-ffile-prefix-map=${SPACK_DEBUG_PREFIX_MAP}=." + fi + ;; +esac + spack_flags_list="" # Fortran flags come before CPPFLAGS diff --git a/test/run.sh b/test/run.sh index 4e64a83..7cb23b0 100755 --- a/test/run.sh +++ b/test/run.sh @@ -187,7 +187,7 @@ SPACK_COMPILER_EXTRA_RPATHS SPACK_COMPILER_IMPLICIT_RPATHS SPACK_CC_HAS_FRANDOM_SEED SPACK_CXX_HAS_FRANDOM_SEED SPACK_FC_HAS_FRANDOM_SEED SPACK_F77_HAS_FRANDOM_SEED SPACK_CCACHE_BINARY SPACK_TEST_COMMAND SPACK_ADD_DEBUG_FLAGS SPACK_DEBUG_FLAGS -SPACK_DEBUG +SPACK_DEBUG SPACK_DEBUG_PREFIX_MAP ' wrapper_environment() { @@ -1309,6 +1309,52 @@ test_add_debug_flags_validation() { unset SPACK_ADD_DEBUG_FLAGS } +# --------------------------------------------------------------------------- +# SPACK_DEBUG_PREFIX_MAP injection +# --------------------------------------------------------------------------- + +test_debug_prefix_map() { + wrapper_environment + + # When SPACK_DEBUG_PREFIX_MAP is unset, -ffile-prefix-map must NOT appear. + unset SPACK_DEBUG_PREFIX_MAP + _out=$(dump_args cc '') + expect_not_contains debug_prefix_map_absent "$_out" \ + '-ffile-prefix-map=/some/stage/path=.' + + # When set, -ffile-prefix-map==. must appear for C. + SPACK_DEBUG_PREFIX_MAP='/some/stage/path' + export SPACK_DEBUG_PREFIX_MAP + _out=$(dump_args cc '') + expect_contains debug_prefix_map_cc "$_out" \ + '-ffile-prefix-map=/some/stage/path=.' + + # Must appear for C++ wrapper too. + _out=$(dump_args c++ '') + expect_contains debug_prefix_map_cxx "$_out" \ + '-ffile-prefix-map=/some/stage/path=.' + + # Must appear for Fortran wrapper too. + _out=$(dump_args fc '') + expect_contains debug_prefix_map_fc "$_out" \ + '-ffile-prefix-map=/some/stage/path=.' + + # Must NOT appear in vcheck mode + _out=$(dump_args cc '--version') + expect_not_contains debug_prefix_map_vcheck "$_out" \ + '-ffile-prefix-map=/some/stage/path=.' + + # Must NOT appear in ld mode + SPACK_DEBUG_PREFIX_MAP='/some/stage/path' + export SPACK_DEBUG_PREFIX_MAP + _out=$(dump_args ld '') + expect_not_contains debug_prefix_map_ld "$_out" \ + '-ffile-prefix-map=/some/stage/path=.' + + unset SPACK_DEBUG_PREFIX_MAP + +} + # --------------------------------------------------------------------------- # Runner # --------------------------------------------------------------------------- @@ -1359,6 +1405,7 @@ test_spack_managed_dirs_are_prioritized test_frandom_seed_not_added_without_env test_frandom_seed_filters_args test_add_debug_flags_validation +test_debug_prefix_map ' all_tests="$wrapper_tests $list_ops_tests"