Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use absolute paths for executables #639

Merged
merged 3 commits into from
May 16, 2020
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
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ library:
- bytestring
- Cabal
- containers
- dhall >= 1.29.0
- dhall >= 1.31.1
- directory >= 1.3.4.0
- either
- exceptions
Expand All @@ -104,7 +104,7 @@ library:
- prettyprinter
- process
- retry
- rio
- rio >= 0.1.13.0
- rio-orphans
- safe
- semver-range
Expand Down
7 changes: 5 additions & 2 deletions src/Spago/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ pretty = PrettyText.renderStrict
-- or die trying
findExecutableOrDie :: HasLogFunc env => String -> RIO env Text
findExecutableOrDie cmd = do
Directory.findExecutable cmd >>= \case
Directory.findExecutable cmd >>= \case
Nothing -> die [ "Executable was not found in path: " <> displayShow cmd ]
Just path -> pure $ Text.pack path
-- 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.
-- See: https://github.com/purescript/spago/issues/635
Just _path -> pure $ Text.pack cmd
16 changes: 8 additions & 8 deletions src/Spago/RunEnv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 Turtle
Expand Down Expand Up @@ -120,14 +121,13 @@ getPurs usePsa = do
UsePsa -> findExecutable "psa" >>= \case
Just _ -> pure "psa"
Nothing -> pure "purs"
try (findExecutableOrDie pursCandidate) >>= \case
Right p -> pure p
-- one last try for Windows
Left (err :: SomeException) -> case OS.buildOS of
OS.Windows -> do
logDebug $ displayShow err
findExecutableOrDie (pursCandidate <> ".cmd")
_ -> throwIO err
-- We first try this for Windows
case OS.buildOS of
OS.Windows -> do
findExecutable (pursCandidate <> ".cmd") >>= \case
Just _ -> pure (Text.pack pursCandidate <> ".cmd")
Nothing -> findExecutableOrDie pursCandidate
_ -> findExecutableOrDie pursCandidate

getPackageSet :: (HasLogFunc env, HasConfigPath env) => RIO env PackageSet
getPackageSet = do
Expand Down