Skip to content

Commit 82e68be

Browse files
committed
Fix finding psa on Windows (#693)
In `getPurs` we were just using the standard `Directory.findExecutable` to look for `psa`, forgetting to check for `psa.cmd` too. In windows this was looking for `psa.exe`, which doesn't exist. To help prevent this happening again, a self-written `findExecutable` function in `Prelude` is added, instead of just exporting `Directory.findExecutable`. This new version will always first check for a `.cmd` version of the executable name on Windows.
1 parent a8e61fc commit 82e68be

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
Other improvements:
1111
- Bump `dhall` dependency from 1.37.1 to 1.38.0 (#739)
12+
- Fix `psa` not being found on Windows (#740, #693)
1213

1314
## [0.19.0] - 2021-01-02
1415

src/Spago/Prelude.hs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module Spago.Prelude
6363
, systemStrictWithErr
6464
, viewShell
6565
, findExecutableOrDie
66-
, Directory.findExecutable
66+
, findExecutable
6767

6868
-- * Other
6969
, Dhall.Core.throws
@@ -81,6 +81,7 @@ import qualified Data.Text.Prettyprint.Doc.Render.Text as PrettyText
8181
import qualified Data.Time as Time
8282
import Dhall (Text)
8383
import qualified Dhall.Core
84+
import qualified Distribution.System as OS
8485
import qualified RIO
8586
import qualified System.FilePath as FilePath
8687
import qualified System.IO
@@ -246,11 +247,22 @@ pretty = PrettyText.renderStrict
246247
. Pretty.layoutPretty Pretty.defaultLayoutOptions
247248
. Pretty.pretty
248249

250+
-- | Return the full path of the executable we're trying to call. On Windows we
251+
-- first try the `.cmd` version.
252+
findExecutable :: MonadIO m => String -> m (Maybe String)
253+
findExecutable x =
254+
case OS.buildOS of
255+
OS.Windows -> Directory.findExecutable (x <> ".cmd") >>= \case
256+
Nothing -> Directory.findExecutable x
257+
success -> pure success
258+
_ -> Directory.findExecutable x
259+
260+
249261
-- | Return the full path of the executable we're trying to call,
250262
-- or die trying
251263
findExecutableOrDie :: HasLogFunc env => String -> RIO env Text
252264
findExecutableOrDie cmd = do
253-
Directory.findExecutable cmd >>= \case
265+
findExecutable cmd >>= \case
254266
Nothing -> die [ "Executable was not found in path: " <> displayShow cmd ]
255267
-- Note: we ignore the path and just return the input because the one we get
256268
-- here is absolute, and Windows doesn't seem to be able to deal with that.
@@ -276,4 +288,4 @@ logDebug, logInfo, logWarn, logError
276288
logDebug = liftLog RIO.logDebug
277289
logInfo = liftLog RIO.logInfo
278290
logWarn = liftLog RIO.logWarn
279-
logError = liftLog RIO.logError
291+
logError = liftLog RIO.logError

src/Spago/RunEnv.hs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module Spago.RunEnv where
33
import Spago.Prelude
44
import Spago.Env
55

6-
import qualified Data.Text as Text
76
import qualified System.Environment as Env
87
import qualified Distribution.System as OS
98
import qualified RIO
@@ -161,13 +160,7 @@ getPurs usePsa = do
161160
UsePsa -> findExecutable "psa" >>= \case
162161
Just _ -> pure "psa"
163162
Nothing -> pure "purs"
164-
-- We first try this for Windows
165-
PursCmd <$> case OS.buildOS of
166-
OS.Windows -> do
167-
findExecutable (pursCandidate <> ".cmd") >>= \case
168-
Just _ -> pure (Text.pack pursCandidate <> ".cmd")
169-
Nothing -> findExecutableOrDie pursCandidate
170-
_ -> findExecutableOrDie pursCandidate
163+
PursCmd <$> findExecutableOrDie pursCandidate
171164

172165
getGit :: HasLogFunc env => RIO env GitCmd
173166
getGit = GitCmd <$> findExecutableOrDie "git"

0 commit comments

Comments
 (0)