Skip to content

Commit

Permalink
Don't silence errors in init scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectreAAS committed Mar 4, 2024
1 parent 911d78c commit 70ebbdc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ users)
* Disable ACL in Cygwin internal install to avoid permission mismatch errors [#5796 @kit-ty-kate - fix #5781]
* Add `sys-pkg-manager-cmd` as an accepted field in opamrc files [#5847 @rjbou - fix #5844]
* Fix `git-location` handling in init config file [#5848 @rjbou - fix #5845]
* Don't silence errors in init scripts [#5865 @ElectreAAS]

## Config report

Expand Down
10 changes: 5 additions & 5 deletions src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -887,19 +887,19 @@ let source root shell f =
fname fname
| SH_fish ->
let fname = unix_transform ~using_backslashes:true () in
Printf.sprintf "source '%s' > /dev/null 2> /dev/null; or true\n" fname
Printf.sprintf "source '%s'; or true\n" fname
| SH_sh | SH_bash ->
let fname = unix_transform () in
Printf.sprintf "test -r '%s' && . '%s' > /dev/null 2> /dev/null || true\n"
Printf.sprintf "test -r '%s' && . '%s' || true\n"
fname fname
| SH_zsh ->
let fname = unix_transform () in
Printf.sprintf "[[ ! -r '%s' ]] || source '%s' > /dev/null 2> /dev/null\n"
Printf.sprintf "[[ ! -r '%s' ]] || source '%s'\n"
fname fname
| SH_cmd ->
Printf.sprintf "if exist \"%s\" call \"%s\" >NUL 2>NUL\n" fname fname
Printf.sprintf "if exist \"%s\" call \"%s\"\n" fname fname
| SH_pwsh _ ->
Printf.sprintf ". \"%s\" *> $null\n" fname
Printf.sprintf ". \"%s\"\n" fname

let if_interactive_script shell t e =
let ielse else_opt = match else_opt with
Expand Down
24 changes: 12 additions & 12 deletions tests/reftests/init-scripts.unix.test
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,36 @@ variables.sh
### : Init scripts :
### cat root/opam-init/init.sh
if [ -t 0 ]; then
test -r '${BASEDIR}/root/opam-init/complete.sh' && . '${BASEDIR}/root/opam-init/complete.sh' > /dev/null 2> /dev/null || true
test -r '${BASEDIR}/root/opam-init/complete.sh' && . '${BASEDIR}/root/opam-init/complete.sh' || true

test -r '${BASEDIR}/root/opam-init/env_hook.sh' && . '${BASEDIR}/root/opam-init/env_hook.sh' > /dev/null 2> /dev/null || true
test -r '${BASEDIR}/root/opam-init/env_hook.sh' && . '${BASEDIR}/root/opam-init/env_hook.sh' || true
fi

test -r '${BASEDIR}/root/opam-init/variables.sh' && . '${BASEDIR}/root/opam-init/variables.sh' > /dev/null 2> /dev/null || true
test -r '${BASEDIR}/root/opam-init/variables.sh' && . '${BASEDIR}/root/opam-init/variables.sh' || true
### cat root/opam-init/init.zsh
if [[ -o interactive ]]; then
[[ ! -r '${BASEDIR}/root/opam-init/complete.zsh' ]] || source '${BASEDIR}/root/opam-init/complete.zsh' > /dev/null 2> /dev/null
[[ ! -r '${BASEDIR}/root/opam-init/complete.zsh' ]] || source '${BASEDIR}/root/opam-init/complete.zsh'

[[ ! -r '${BASEDIR}/root/opam-init/env_hook.zsh' ]] || source '${BASEDIR}/root/opam-init/env_hook.zsh' > /dev/null 2> /dev/null
[[ ! -r '${BASEDIR}/root/opam-init/env_hook.zsh' ]] || source '${BASEDIR}/root/opam-init/env_hook.zsh'
fi

[[ ! -r '${BASEDIR}/root/opam-init/variables.sh' ]] || source '${BASEDIR}/root/opam-init/variables.sh' > /dev/null 2> /dev/null
[[ ! -r '${BASEDIR}/root/opam-init/variables.sh' ]] || source '${BASEDIR}/root/opam-init/variables.sh'
### cat root/opam-init/init.fish
if isatty
source '${BASEDIR}/root/opam-init/env_hook.fish' > /dev/null 2> /dev/null; or true
source '${BASEDIR}/root/opam-init/env_hook.fish'; or true
end

source '${BASEDIR}/root/opam-init/variables.fish' > /dev/null 2> /dev/null; or true
source '${BASEDIR}/root/opam-init/variables.fish'; or true
### cat root/opam-init/init.csh
if ( $?prompt ) then
if ( -f '${BASEDIR}/root/opam-init/env_hook.csh' ) source '${BASEDIR}/root/opam-init/env_hook.csh' >& /dev/null
if ( -f '${BASEDIR}/root/opam-init/env_hook.csh' ) source '${BASEDIR}/root/opam-init/env_hook.csh'
endif

if ( -f '${BASEDIR}/root/opam-init/variables.csh' ) source '${BASEDIR}/root/opam-init/variables.csh' >& /dev/null
if ( -f '${BASEDIR}/root/opam-init/variables.csh' ) source '${BASEDIR}/root/opam-init/variables.csh'
### cat root/opam-init/init.cmd
if exist "${BASEDIR}/root/opam-init/variables.cmd" call "${BASEDIR}/root/opam-init/variables.cmd" >NUL 2>NUL
if exist "${BASEDIR}/root/opam-init/variables.cmd" call "${BASEDIR}/root/opam-init/variables.cmd"
### cat root/opam-init/init.ps1
. "${BASEDIR}/root/opam-init/variables.ps1" *> $null
. "${BASEDIR}/root/opam-init/variables.ps1"
### : Variables scripts :
### cat root/opam-init/variables.sh | grep -v man | grep -v MANPATH
# Prefix of the current opam switch
Expand Down
24 changes: 12 additions & 12 deletions tests/reftests/init-scripts.win32.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,36 @@ variables.sh
### : Init scripts :
### cat root/opam-init/init.sh
if [ -t 0 ]; then
test -r '${BASEDIR}/root/opam-init/complete.sh' && . '${BASEDIR}/root/opam-init/complete.sh' > /dev/null 2> /dev/null || true
test -r '${BASEDIR}/root/opam-init/complete.sh' && . '${BASEDIR}/root/opam-init/complete.sh' || true

test -r '${BASEDIR}/root/opam-init/env_hook.sh' && . '${BASEDIR}/root/opam-init/env_hook.sh' > /dev/null 2> /dev/null || true
test -r '${BASEDIR}/root/opam-init/env_hook.sh' && . '${BASEDIR}/root/opam-init/env_hook.sh' || true
fi

test -r '${BASEDIR}/root/opam-init/variables.sh' && . '${BASEDIR}/root/opam-init/variables.sh' > /dev/null 2> /dev/null || true
test -r '${BASEDIR}/root/opam-init/variables.sh' && . '${BASEDIR}/root/opam-init/variables.sh' || true
### cat root/opam-init/init.zsh
if [[ -o interactive ]]; then
[[ ! -r '${BASEDIR}/root/opam-init/complete.zsh' ]] || source '${BASEDIR}/root/opam-init/complete.zsh' > /dev/null 2> /dev/null
[[ ! -r '${BASEDIR}/root/opam-init/complete.zsh' ]] || source '${BASEDIR}/root/opam-init/complete.zsh'

[[ ! -r '${BASEDIR}/root/opam-init/env_hook.zsh' ]] || source '${BASEDIR}/root/opam-init/env_hook.zsh' > /dev/null 2> /dev/null
[[ ! -r '${BASEDIR}/root/opam-init/env_hook.zsh' ]] || source '${BASEDIR}/root/opam-init/env_hook.zsh'
fi

[[ ! -r '${BASEDIR}/root/opam-init/variables.sh' ]] || source '${BASEDIR}/root/opam-init/variables.sh' > /dev/null 2> /dev/null
[[ ! -r '${BASEDIR}/root/opam-init/variables.sh' ]] || source '${BASEDIR}/root/opam-init/variables.sh'
### cat root/opam-init/init.fish
if isatty
source '${BASEDIR}/root/opam-init/env_hook.fish' > /dev/null 2> /dev/null; or true
source '${BASEDIR}/root/opam-init/env_hook.fish'; or true
end

source '${BASEDIR}/root/opam-init/variables.fish' > /dev/null 2> /dev/null; or true
source '${BASEDIR}/root/opam-init/variables.fish'; or true
### cat root/opam-init/init.csh
if ( $?prompt ) then
if ( -f '${BASEDIR}/root/opam-init/env_hook.csh' ) source '${BASEDIR}/root/opam-init/env_hook.csh' >& /dev/null
if ( -f '${BASEDIR}/root/opam-init/env_hook.csh' ) source '${BASEDIR}/root/opam-init/env_hook.csh'
endif

if ( -f '${BASEDIR}/root/opam-init/variables.csh' ) source '${BASEDIR}/root/opam-init/variables.csh' >& /dev/null
if ( -f '${BASEDIR}/root/opam-init/variables.csh' ) source '${BASEDIR}/root/opam-init/variables.csh'
### cat root/opam-init/init.cmd
if exist "${BASEDIR}/root/opam-init/variables.cmd" call "${BASEDIR}/root/opam-init/variables.cmd" >NUL 2>NUL
if exist "${BASEDIR}/root/opam-init/variables.cmd" call "${BASEDIR}/root/opam-init/variables.cmd"
### cat root/opam-init/init.ps1
. "${BASEDIR}/root/opam-init/variables.ps1" *> $null
. "${BASEDIR}/root/opam-init/variables.ps1"
### : Variables scripts :
### cat root/opam-init/variables.sh | grep -v man | grep -v MANPATH
# Prefix of the current opam switch
Expand Down

0 comments on commit 70ebbdc

Please sign in to comment.