From c73a8752a5aa9f1ebd7acff0de5bbf47fe19c5cd Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Tue, 10 Jan 2023 20:05:19 +0100 Subject: [PATCH] Fix #130: ensure cabal installdir is in the PATH (#165) Add `~/.cabal/bin` to the PATH under Linux and macOS. Windows' chocolatey install already takes care of this. That the `installdir` is in the `PATH` is now tested in CI via a `cabal install` with subsequent call to the installed executable. Original commits: * CI issue #130: test whether installdir is in the PATH * Linux/macOS: add ~/.cabal/bin to PATH * Inform that installdir is added to PATH --- .github/workflows/workflow.yml | 18 +++++++++++++----- setup/__tests__/project/project.cabal | 2 +- setup/dist/index.js | 4 ++++ setup/lib/setup-haskell.js | 4 ++++ setup/src/setup-haskell.ts | 4 ++++ 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 12e98a5b..1a3b77ec 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -78,6 +78,11 @@ jobs: cabal-version: ${{ matrix.cabal }} cabal-update: ${{ matrix.cabal_update }} + - name: Show installed versions + run: | + cabal --version + ghc --version + - name: Test runghc run: | runghc --version @@ -91,16 +96,19 @@ jobs: working-directory: setup/__tests__/project run: cabal run + - name: Install test project + working-directory: setup/__tests__/project + run: cabal install + + - name: Run installed test project + run: hello-haskell-setup + # This tests whether the default installdir has been added to the PATH (issue #130). + - name: Build and run test with Hackage dependency if: ${{ matrix.cabal_update != 'false' }} working-directory: setup/__tests__/project-with-hackage-dependency run: cabal build && cabal run - - name: Show installed versions - run: | - cabal --version - ghc --version - - name: Confirm installed and expected versions match shell: bash # check that if given in the matrix, the actual version matches: diff --git a/setup/__tests__/project/project.cabal b/setup/__tests__/project/project.cabal index b6db4d02..3629af10 100644 --- a/setup/__tests__/project/project.cabal +++ b/setup/__tests__/project/project.cabal @@ -3,7 +3,7 @@ name: project version: 0.1.0.0 build-type: Simple -executable project +executable hello-haskell-setup main-is: Main.hs build-depends: base default-language: Haskell2010 diff --git a/setup/dist/index.js b/setup/dist/index.js index 898a6cac..bf46e761 100644 --- a/setup/dist/index.js +++ b/setup/dist/index.js @@ -13849,6 +13849,10 @@ async function run(inputs) { } else { core.setOutput('cabal-store', `${process.env.HOME}/.cabal/store`); + // Issue #130: for non-choco installs, add ~/.cabal/bin to PATH + const installdir = `${process.env.HOME}/.cabal/bin`; + core.info(`Adding ${installdir} to PATH`); + core.addPath(installdir); } // Workaround the GHC nopie linking errors for ancient GHC versions // NB: Is this _just_ for GHC 7.10.3? diff --git a/setup/lib/setup-haskell.js b/setup/lib/setup-haskell.js index b9438e14..2abb1fd2 100644 --- a/setup/lib/setup-haskell.js +++ b/setup/lib/setup-haskell.js @@ -70,6 +70,10 @@ async function run(inputs) { } else { core.setOutput('cabal-store', `${process.env.HOME}/.cabal/store`); + // Issue #130: for non-choco installs, add ~/.cabal/bin to PATH + const installdir = `${process.env.HOME}/.cabal/bin`; + core.info(`Adding ${installdir} to PATH`); + core.addPath(installdir); } // Workaround the GHC nopie linking errors for ancient GHC versions // NB: Is this _just_ for GHC 7.10.3? diff --git a/setup/src/setup-haskell.ts b/setup/src/setup-haskell.ts index 077c0c6b..25dfed44 100644 --- a/setup/src/setup-haskell.ts +++ b/setup/src/setup-haskell.ts @@ -57,6 +57,10 @@ export default async function run( core.setOutput('cabal-store', 'C:\\sr'); } else { core.setOutput('cabal-store', `${process.env.HOME}/.cabal/store`); + // Issue #130: for non-choco installs, add ~/.cabal/bin to PATH + const installdir = `${process.env.HOME}/.cabal/bin`; + core.info(`Adding ${installdir} to PATH`); + core.addPath(installdir); } // Workaround the GHC nopie linking errors for ancient GHC versions