Skip to content

Commit d82ef59

Browse files
committed
Add -frandom-seed support and shellcheck fixes
Signed-off-by: Harmen Stoppels <me@harmenstoppels.nl>
1 parent c345a26 commit d82ef59

3 files changed

Lines changed: 45 additions & 14 deletions

File tree

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly

.github/workflows/shellcheck.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: shellcheck
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
8+
jobs:
9+
shellcheck:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
13+
- name: Run shellcheck
14+
run: shellcheck cc.sh

cc.sh

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ execute() {
196196
output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_DEBUG_LOG_ID.out.log"
197197
echo "[$mode] $command $input_command" >> "$input_log"
198198
IFS="$lsep"
199+
# shellcheck disable=SC2086
199200
echo "[$mode] "$full_command_list >> "$output_log"
200201
unset IFS
201202
fi
@@ -365,20 +366,17 @@ if [ -z "$mode" ] || [ "$mode" = ld ]; then
365366
done
366367
fi
367368

368-
# Finish setting up the mode.
369+
# Finish setting up the mode, and check whether -frandom-seed needs to be set.
370+
eval "_set_frandom_seed=\${SPACK_${comp}_HAS_FRANDOM_SEED:-}"
369371
if [ -z "$mode" ]; then
370372
mode=ccld
371373
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
374+
case $arg in
375+
-E) mode=cpp ;;
376+
-S) mode=as ;;
377+
-c) mode=cc ;;
378+
-frandom-seed=*) _set_frandom_seed= ;;
379+
esac
382380
done
383381
fi
384382

@@ -437,9 +435,10 @@ export PATH="$new_dirs"
437435

438436
if [ "$mode" = vcheck ]; then
439437
full_command_list="$command"
440-
args="$@"
441438
extend full_command_list vcheck_flags
442-
extend full_command_list args
439+
for arg in "$@"; do
440+
append full_command_list "$arg"
441+
done
443442
execute
444443
fi
445444

@@ -580,6 +579,7 @@ categorize_arguments() {
580579
eval "\
581580
stripped=\"\${1##$before}\"
582581
"
582+
# shellcheck disable=SC2154 # shellcheck doesn't see eval
583583
if [ "$stripped" = "$1" ] ; then
584584
continue
585585
fi
@@ -633,6 +633,7 @@ categorize_arguments() {
633633
;;
634634
-Wl,*)
635635
IFS=,
636+
# shellcheck disable=SC2086 # intentional splitting
636637
if ! parse_Wl ${1#-Wl,}; then
637638
append return_other_args_list "$1"
638639
fi
@@ -803,7 +804,8 @@ case "$mode" in
803804
esac
804805

805806
IFS="$lsep"
806-
categorize_arguments $spack_flags_list
807+
# shellcheck disable=SC2086 # intentional splitting
808+
categorize_arguments $spack_flags_list
807809
unset IFS
808810

809811
assign_path_lists spack_flags_isystem_include_dirs_list return_isystem_include_dirs_list
@@ -951,6 +953,15 @@ extend args_list libs_list "-l"
951953
full_command_list="$command"
952954
extend full_command_list args_list
953955

956+
if [ -n "$_set_frandom_seed" ]; then
957+
case "$mode" in
958+
cc|ccld)
959+
# Make GCC deterministic by setting the random seed to command line arguments
960+
append full_command_list "-frandom-seed=$input_command"
961+
;;
962+
esac
963+
fi
964+
954965
# prepend the ccache binary if we're using ccache
955966
if [ -n "$SPACK_CCACHE_BINARY" ]; then
956967
case "$lang_flags" in

0 commit comments

Comments
 (0)