Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

## [0.19.0] - 2021-01-02

Expand Down
18 changes: 15 additions & 3 deletions src/Spago/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Spago.Prelude
, systemStrictWithErr
, viewShell
, findExecutableOrDie
, Directory.findExecutable
, findExecutable

-- * Other
, Dhall.Core.throws
Expand All @@ -81,6 +81,7 @@ import qualified Data.Text.Prettyprint.Doc.Render.Text as PrettyText
import qualified Data.Time as Time
import Dhall (Text)
import qualified Dhall.Core
import qualified Distribution.System as OS
import qualified RIO
import qualified System.FilePath as FilePath
import qualified System.IO
Expand Down Expand Up @@ -246,11 +247,22 @@ pretty = PrettyText.renderStrict
. Pretty.layoutPretty Pretty.defaultLayoutOptions
. Pretty.pretty

-- | Return the full path of the executable we're trying to call. On Windows we
-- first try the `.cmd` version.
findExecutable :: MonadIO m => String -> m (Maybe String)
findExecutable x =
case OS.buildOS of
OS.Windows -> Directory.findExecutable (x <> ".cmd") >>= \case
Nothing -> Directory.findExecutable x
success -> pure success
_ -> Directory.findExecutable x


-- | Return the full path of the executable we're trying to call,
-- or die trying
findExecutableOrDie :: HasLogFunc env => String -> RIO env Text
findExecutableOrDie cmd = do
Directory.findExecutable cmd >>= \case
findExecutable cmd >>= \case
Nothing -> die [ "Executable was not found in path: " <> displayShow cmd ]
-- Note: we ignore the path and just return the input because the one we get
-- here is absolute, and Windows doesn't seem to be able to deal with that.
Expand All @@ -276,4 +288,4 @@ logDebug, logInfo, logWarn, logError
logDebug = liftLog RIO.logDebug
logInfo = liftLog RIO.logInfo
logWarn = liftLog RIO.logWarn
logError = liftLog RIO.logError
logError = liftLog RIO.logError
9 changes: 1 addition & 8 deletions src/Spago/RunEnv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Spago.RunEnv where
import Spago.Prelude
import Spago.Env

import qualified Data.Text as Text
import qualified System.Environment as Env
import qualified Distribution.System as OS
import qualified RIO
Expand Down Expand Up @@ -161,13 +160,7 @@ getPurs usePsa = do
UsePsa -> findExecutable "psa" >>= \case
Just _ -> pure "psa"
Nothing -> pure "purs"
-- We first try this for Windows
PursCmd <$> case OS.buildOS of
OS.Windows -> do
findExecutable (pursCandidate <> ".cmd") >>= \case
Just _ -> pure (Text.pack pursCandidate <> ".cmd")
Nothing -> findExecutableOrDie pursCandidate
_ -> findExecutableOrDie pursCandidate
PursCmd <$> findExecutableOrDie pursCandidate

getGit :: HasLogFunc env => RIO env GitCmd
getGit = GitCmd <$> findExecutableOrDie "git"
Expand Down