Skip to content

Commit 9d5f3a0

Browse files
committed
reduce bash 4.2 and 4.3 to unsupported
due to their crashes not returning the correct exit status, mark them as unsupported / only partially supported for now, at a later point once this PR is merged, we can focus on more improvements here
1 parent 3ab4cf0 commit 9d5f3a0

File tree

5 files changed

+85
-58
lines changed

5 files changed

+85
-58
lines changed

.github/workflows/dorothy-workflow.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,20 @@ jobs:
226226
bash:
227227
- '3.2.57'
228228
- '4.0'
229+
- '4.1'
229230
- '4.2.53'
230231
- '4.3.30'
231232
- '4.4.18'
232233
- '5.0'
233234
- '5.1.16'
234235
- '5.2.37'
235236
- '5.3'
236-
# ^ this should all mirror [setup-util-bash]
237+
# This should match all versions known in [bash.bash] and include in [continue-on-error] the unsupported versions
237238
steps:
238239
- name: 'Dorothy Test'
239240
env:
240241
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # prevent rate limiting
242+
continue-on-error: ${{ matrix.bash == '4.1' || matrix.bash == '4.2.53' || matrix.bash == '4.3.30' }}
241243
run: |
242244
# ensure dorothy is cloned, and run command
243245
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/run?slug=${{ github.event.pull_request.head.repo.full_name || github.repository }}&commit=${{ github.event.pull_request.head.sha || github.sha }}')" -- dorothy test --bash-version="${{ matrix.bash }}"

commands/debug-bash

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,32 +136,27 @@ function debug_bash() (
136136
__get_all_bash_binaries
137137
continue
138138
fi
139+
# convert version number to executable
139140
if [[ $bash_input =~ ^[0-9] ]]; then
140-
# convert version number to executable
141-
setup-util-bash --version="$bash_input"
142-
# should match [setup-util-bash]
143-
case "$bash_input" in
144-
3 | 3. | 3.2*) bash_input='3.2.57' ;;
145-
4.0*) bash_input='4.0' ;;
146-
4.2*) bash_input='4.2.53' ;;
147-
4.3*) bash_input='4.3.30' ;;
148-
4 | 4. | 4.4*) bash_input='4.4.18' ;;
149-
5.0*) bash_input='5.0' ;;
150-
5.1*) bash_input='5.1.16' ;;
151-
5 | 5. | 5.2*) bash_input='5.2.37' ;;
152-
5.3*) bash_input='5.3' ;; # still too new
153-
*)
154-
echo-style --error="The bash version [$item] is not supported by Dorothy."
155-
return 75 # EPROGMISMATCH 75 Program version wrong
156-
;;
157-
esac
158-
bash_input="$(expand-path -- "$XDG_BIN_HOME/bash-$bash_input*" | echo-first-line --stdin)"
159-
# if it doesn't exist, install it
141+
bash_input="$(__get_coerced_bash_version "$bash_input" || :)"
142+
if [[ -n $bash_input ]]; then
143+
bash_input="$(expand-path -- "$XDG_BIN_HOME/bash-$bash_input*" | echo-first-line --stdin || :)"
144+
if [[ -z $bash_input ]]; then
145+
setup-util-bash --version="$bash_input" || return
146+
bash_input="$(expand-path -- "$XDG_BIN_HOME/bash-$bash_input*" | echo-first-line --stdin || :)"
147+
fi
148+
fi
149+
fi
150+
# convert input to binary path
151+
if [[ -n $bash_input ]]; then
152+
bash_binary="$(type -P "$bash_input" || :)"
153+
else
154+
bash_binary=''
160155
fi
161-
bash_binary="$(type -P "$bash_input" || :)"
156+
# add binary path or note failure
162157
if [[ -z $bash_binary ]]; then
163158
echo-style --error='The bash binary ' --code="$bash_input" ' does not exist.'
164-
__exit_status=2 # ENOENT 2 No such file or directory
159+
__exit_status=75 # EPROGMISMATCH 75 Program version wrong
165160
continue
166161
else
167162
bash_binaries+=("$bash_binary")

commands/setup-util-bash

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
#!/usr/bin/env bash
22

33
# https://repology.org/project/bash/versions
4+
# https://ftp.gnu.org/gnu/bash/?C=M;O=D
45

56
function setup_util_bash() (
67
source "$DOROTHY/sources/bash.bash"
78
# imports:
89
# IS_BASH_VERSION_OUTDATED
910
# BASH_VERSION_CURRENT
1011
# BASH_VERSION_LATEST
12+
# BASH_VERSIONS_SUPPORTED
1113

12-
local all_versions=(
13-
# they all compile on ubuntu x86 without any flags, however byacc is needed for a few of them
14-
# 3.0.16 # compiles on macos with CPPFLAGS modification <-- not supported by dorothy
15-
# 3.1 # compiles on macos with CPPFLAGS modification <-- not supported by dorothy
16-
3.2.57 # compiles on macos with CPPFLAGS modification
17-
4.0 # compiles on macos with CPPFLAGS modification
18-
# 4.1 # compiles on macos with CPPFLAGS modification <-- not supported by dorothy
19-
4.2.53 # compiles on macos with CPPFLAGS modification
20-
4.3.30 # compiles on macos with CPPFLAGS modification
21-
4.4.18 # compiles on macos with CPPFLAGS modification
22-
5.0 # compiles on macos with CPPFLAGS modification
23-
5.1.16 # compiles on macos x86 without any flags
24-
5.2.37 # compiles on macos x86 without any flags
25-
5.3 # compiles on macos x86 without any flags
26-
)
2714
local item versions=() util_options=()
2815
while [[ $# -ne 0 ]]; do
2916
item="$1"
3017
shift
3118
case "$item" in
32-
--all | --av | --all-versions | --all-bash-versions) versions+=("${all_versions[@]}") ;;
19+
--all | --av | --all-versions | --all-bash-versions) versions+=("${BASH_VERSIONS_SUPPORTED[@]}") ;;
3320
--v=* | --version=* | --versions=* | --bash-version=* | --bash-versions=*) __split --target={versions} --append --no-zero-length --delimiters=$'\n\t ,|' -- "${item#*=}" ;;
3421
*) util_options+=("$item") ;;
3522
esac
@@ -39,25 +26,10 @@ function setup_util_bash() (
3926
# setup bash
4027
if [[ ${#versions[@]} -ne 0 ]]; then
4128
# convert short versions into preferred versions
42-
local index __exit_status=0
29+
local index
4330
for index in "${!versions[@]}"; do
4431
item="${versions[index]}"
45-
# should match [debug-bash]
46-
case "$item" in
47-
3 | 3. | 3.2*) versions[index]='3.2.57' ;;
48-
4.0*) versions[index]='4.0' ;;
49-
4.2*) versions[index]='4.2.53' ;;
50-
4.3*) versions[index]='4.3.30' ;;
51-
4 | 4. | 4.4*) versions[index]='4.4.18' ;;
52-
5.0*) versions[index]='5.0' ;;
53-
5.1*) versions[index]='5.1.16' ;;
54-
5 | 5. | 5.2*) versions[index]='5.2.37' ;;
55-
5.3*) versions[index]='5.3' ;; # still too new
56-
*)
57-
echo-style --error="The bash version [$item] is not supported by Dorothy."
58-
return 75 # EPROGMISMATCH 75 Program version wrong
59-
;;
60-
esac
32+
versions[index]="$(__get_coerced_bash_version "$item")" || return
6133
done
6234

6335
# this block offers no benefit as it is already fast enough

docs/bash/versions.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ From manual discovery:
1818

1919
## bash v3.2
2020

21-
> [!CAUTION]
21+
> [!IMPORTANT]
2222
> This is this is the minimum required version for Dorothy.
2323
2424
From manual discovery:
@@ -72,9 +72,16 @@ Changelog:
7272
7373
## bash v4.1
7474

75+
> [!CAUTION]
76+
> Because of the bugs in this version, this version is discouraged.
77+
7578
> [!NOTE]
7679
> Dorothy's `bash.bash` includes cross-version compatible implementations of `__open_fd`.
7780
81+
From manual discovery:
82+
83+
- Has a bug where modifications of a file do not actually modify the file, see comment at `bash.bash:__wait_for_semaphores`.
84+
7885
From changelog:
7986

8087
- Introduces `${arr:0:-N}` for getting the last N items or characters of an array or string.
@@ -93,6 +100,9 @@ Changelog:
93100
94101
## bash v4.2
95102

103+
> [!CAUTION]
104+
> Because of the exit status bug in this version, this version is discouraged.
105+
96106
From manual discovery:
97107

98108
- If a crash occurs via `errexit` the exit status will always be `1` instead of the intended exit status. Refer to <errors.md> for guidance.
@@ -111,6 +121,9 @@ Changelog:
111121
112122
## bash v4.3
113123

124+
> [!CAUTION]
125+
> Because of the exit status bug in this version, this version is discouraged.
126+
114127
> [!NOTE]
115128
> Dorothy's `bash.bash` includes cross-version compatible implementations of `__get_var_declaration`.
116129
@@ -134,12 +147,16 @@ Changelog:
134147
135148
## bash v4.4
136149

137-
> [!CAUTION]
150+
> [!IMPORTANT]
138151
> This is this is the recommended minimum version for Dorothy.
139152
140153
> [!NOTE]
141154
> Dorothy's `bash.bash` disables `nounset` on earlier bash versions to prevent crashes on accessing empty arrays. This has no notable downside, as the exact same logic paths are hit on modern bash versions, so undefined variables will be still be caught for resolution on them.
142155
156+
From manual discovery:
157+
158+
- Crashes now return the correct exit status.
159+
143160
From changelog:
144161

145162
- No longer throws upon accessing an empty array. Previously must do `[[ "${#arr[@]}" -ne 0 ]] && for item in "${arr[@]}"; do`.

sources/bash.bash

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,47 @@ if [[ -z ${BASH_VERSION_CURRENT-} ]]; then
361361
fi
362362
fi
363363

364+
# Unsupported versions should be reflected in `dorothy-workflow.yml`
365+
# trunk-ignore(shellcheck/SC2034)
366+
BASH_VERSIONS_SUPPORTED=(
367+
# they all compile on ubuntu x86 without any flags, however byacc is needed for a few of them
368+
# 3.0.16 # compiles on macos with CPPFLAGS modification <-- not supported by dorothy
369+
# 3.1 # compiles on macos with CPPFLAGS modification <-- not supported by dorothy
370+
3.2.57 # compiles on macos with CPPFLAGS modification
371+
4.0 # compiles on macos with CPPFLAGS modification
372+
# 4.1 # compiles on macos with CPPFLAGS modification <-- not supported by dorothy, see note at `__wait_for_semaphores`
373+
# 4.2.53 # compiles on macos with CPPFLAGS modification <-- partially supported by dorothy, crashes can fail to return the correct exit status
374+
# 4.3.30 # compiles on macos with CPPFLAGS modification <-- partially supported by dorothy, crashes can fail to return the correct exit status
375+
4.4.18 # compiles on macos with CPPFLAGS modification
376+
5.0 # compiles on macos with CPPFLAGS modification
377+
5.1.16 # compiles on macos x86 without any flags
378+
5.2.37 # compiles on macos x86 without any flags
379+
5.3 # compiles on macos x86 without any flags
380+
)
381+
382+
function __get_coerced_bash_version {
383+
local input="$1" result
384+
case "$input" in
385+
3.0*) result='3.0.16' ;;
386+
3.1*) result='3.1' ;;
387+
3 | 3. | 3.2*) result='3.2.57' ;;
388+
4.0*) result='4.0' ;;
389+
4.1*) result='4.1' ;;
390+
4.2*) result='4.2.53' ;;
391+
4.3*) result='4.3.30' ;;
392+
4 | 4. | 4.4*) result='4.4.18' ;;
393+
5.0*) result='5.0' ;;
394+
5.1*) result='5.1.16' ;;
395+
5.2*) result='5.2.37' ;;
396+
'' | 5 | 5. | 5.3*) result='5.3' ;;
397+
*)
398+
__print_lines "ERROR: The bash version $(__dump --value="$input" || :) is not supported by Dorothy." >&2 || :
399+
return 75 # EPROGMISMATCH 75 Program version wrong
400+
;;
401+
esac
402+
printf '%s' "$result" || return
403+
}
404+
364405
# CONSIDER
365406
# bash v5: localvar_inherit: If set, local variables inherit the value and attributes of a variable of the same name that exists at a previous scope before any new value is assigned. The nameref attribute is not inherited.
366407
# shopt -s localvar_inherit 2>/dev/null || :

0 commit comments

Comments
 (0)