File tree Expand file tree Collapse file tree
repos/spack_repo/builtin/packages/compiler_wrapper Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -365,20 +365,21 @@ if [ -z "$mode" ] || [ "$mode" = ld ]; then
365365 done
366366fi
367367
368- # Finish setting up the mode.
368+ # Finish setting up the mode, and find the first positional arguments as a value
369+ # for -frandom-seed (to make GCC deterministic)
370+ _rseed=" "
371+ eval _has_frandom_seed=\$ {SPACK_${comp} _HAS_FRANDOM_SEED:-}
369372if [ -z " $mode " ]; then
370373 mode=ccld
371374 for arg in " $@ " ; do
372- if [ " $arg " = " -E" ]; then
373- mode=cpp
374- break
375- elif [ " $arg " = " -S" ]; then
376- mode=as
377- break
378- elif [ " $arg " = " -c" ]; then
379- mode=cc
380- break
381- fi
375+ case $arg in
376+ -E) mode=cpp ;;
377+ -S) mode=as ;;
378+ -c) mode=cc ;;
379+ -frandom-seed=* ) [ -n " $_has_frandom_seed " ] && _rseed=_set ;;
380+ -* |* .h* ) ;;
381+ * ) if [ -n " $_has_frandom_seed " ] && [ -z " $_rseed " ]; then _rseed=$arg ; fi ;;
382+ esac
382383 done
383384fi
384385
@@ -951,6 +952,14 @@ extend args_list libs_list "-l"
951952full_command_list=" $command "
952953extend full_command_list args_list
953954
955+ if [ " $mode " = cc ] && [ -n " $_has_frandom_seed " ]; then
956+ case " $_rseed " in
957+ _set|' ' ) ;;
958+ * ) append full_command_list " -frandom-seed=$_rseed " ;;
959+ esac
960+ fi
961+ unset _rseed _has_frandom_seed
962+
954963# prepend the ccache binary if we're using ccache
955964if [ -n " $SPACK_CCACHE_BINARY " ]; then
956965 case " $lang_flags " in
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ class CompilerWrapper(Package):
4040 if sys .platform != "win32" :
4141 version (
4242 "1.0" ,
43- sha256 = "c7b816479554fd32f677db15ceec6627b91c86074a5d65498688afcbe2796188 " ,
43+ sha256 = "21afdc01e2d8d1f4ea3438ab81b2d3bc16b235c01fbbb9357ac71390ec563b67 " ,
4444 expand = False ,
4545 )
4646 else :
@@ -175,6 +175,10 @@ def setup_dependent_build_environment(
175175 compiler = getattr (compiler_pkg , attr_name )
176176 env .set (spack_var_name , compiler )
177177
178+ # -frandom-seed= is needed for deterministic builds with GCC
179+ if compiler_pkg .name == "gcc" :
180+ env .set (f"SPACK_{ wrapper_var_name } _HAS_FRANDOM_SEED" , "1" )
181+
178182 if language not in compiler_pkg .compiler_wrapper_link_paths :
179183 continue
180184
You can’t perform that action at this time.
0 commit comments