From 5b45399f5a57278dd2c8c15f27186d18147ad0b6 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Fri, 8 Aug 2025 15:57:18 +1000 Subject: [PATCH] Add posix sh env script This amounted taking the bash env script and removing its use of the `local` keyword and changing is extension to ".sh". The posix env script also doesn't source the bash completion script as it uses some bash-specific features. This allows the dune binary distro to be used on machines with minimal shells such as the ash shell in the default environment on alpine linux. Also adds a test that runs shellcheck on env.sh to make sure it stays posix-compatible. Signed-off-by: Stephen Sherratt --- .github/workflows/test.yml | 17 +++++++++++++++++ extra/share/dune/env/env.bash | 3 +++ extra/share/dune/env/env.sh | 22 ++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 extra/share/dune/env/env.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..0e9cfb2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,17 @@ +name: test +on: [push, pull_request] +jobs: + + shellcheck: + name: "Run shellcheck on the shell env script" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: "Install shellcheck" + run: | + sudo apt-get update + sudo apt-get install -y shellcheck + - name: "Run shellcheck on the shell env script" + run: | + # exclude warning for sourcing missing external file + shellcheck extra/share/dune/env/env.sh extra/share/dune/env/env.bash diff --git a/extra/share/dune/env/env.bash b/extra/share/dune/env/env.bash index 6f27d2a..de9292f 100644 --- a/extra/share/dune/env/env.bash +++ b/extra/share/dune/env/env.bash @@ -20,5 +20,8 @@ __dune_env() { ;; esac + # Load bash completions for dune. + # Suppress warning from shellcheck as it can't see the completion script. + # shellcheck disable=SC1091 . "$ROOT"/share/bash-completion/completions/dune } diff --git a/extra/share/dune/env/env.sh b/extra/share/dune/env/env.sh new file mode 100644 index 0000000..f6ad1dc --- /dev/null +++ b/extra/share/dune/env/env.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +__dune_env() { + if [ "$#" != "1" ]; then + echo "__dune_env expected 1 argument, got $#" + return + fi + __dune_root="$1" + + # Add dune to PATH unless it's already present. + # Affix colons on either side of $PATH to simplify matching (based on + # rustup's env script). + case :"$PATH": in + *:"$__dune_root/bin":*) + # Do nothing since the bin directory is already in PATH. + ;; + *) + # Prepending path in case a system-installed dune needs to be overridden + export PATH="$__dune_root/bin:$PATH" + ;; + esac +}