Skip to content

Commit

Permalink
Fix psa detection (#327)
Browse files Browse the repository at this point in the history
Before this change `spago` would fail to run if `psa` was not installed.
So we fix this and add a test to ensure that `spago` runs in both cases

This also adds the `stack.yaml.lock` file generated by `stack2`
  • Loading branch information
f-f authored Jul 22, 2019
1 parent 41aff2f commit 553e8cb
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ script:
'cd spago && stack build --test --no-run-tests --copy-bins --local-bin-path ./artifacts'
fi
nvm install 10 && nvm use 10
npm install -g psc-package@3.0.1 bower@1.8.8 purescript-psa
npm install -g psc-package@3.0.1 bower@1.8.8
# get newest purescript from github releases
TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
Expand All @@ -104,6 +104,10 @@ script:
# run the test suite executable
./.stack-work/dist/*/*/build/spec/spec
# install psa and rerun tests that exercise it
npm install -g purescript-psa
./.stack-work/dist/*/*/build/spec/spec --match "/Spago/spago run"
before_deploy:
Expand Down
5 changes: 4 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install:
- choco install -y haskell-stack --version %STACK_VERSION%
- stack setup > nul
- choco install psc-package
- npm install -g bower purescript-psa
- npm install -g bower
- ps: |
$releases = "https://api.github.com/repos/purescript/purescript/releases"
$tag = "v0.13.2"
Expand All @@ -43,6 +43,9 @@ test_script:
- set PATH=C:\projects\spago\bin;C:\projects\spago\purescript;%PATH%
- set XDG_CACHE_HOME=C:\cache
- stack test
# We install psa and rerun the tests that exercise it
- npm install -g purescript-psa
- stack test --ta "--match \"/Spago/spago run\""

artifacts:
- path: windows.tar.gz
Expand Down
4 changes: 3 additions & 1 deletion src/Spago/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module Spago.Prelude
, callCommand
, shell
, shellStrict
, shellStrictWithErr
, systemStrictWithErr
, viewShell
, repr
Expand Down Expand Up @@ -105,7 +106,8 @@ import System.FilePath (isAbsolute, pathSeparator, (</>)
import System.IO (hPutStrLn)
import Turtle (ExitCode (..), FilePath, appendonly, chmod,
executable, mktree, repr, shell, shellStrict,
systemStrictWithErr, testdir, testfile)
shellStrictWithErr, systemStrictWithErr, testdir,
testfile)
import UnliftIO (MonadUnliftIO, withRunInIO)
import UnliftIO.Directory (getModificationTime, makeAbsolute)
import UnliftIO.Exception (IOException, handleAny, try, tryIO)
Expand Down
8 changes: 4 additions & 4 deletions src/Spago/Purs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ compile sourcePaths extraArgs = do
usePsa <- asks globalUsePsa
purs <- case usePsa of
NoPsa -> pure "purs"
UsePsa -> tryIO psaVersion >>= \case
UsePsa -> try psaVersion >>= \case
Right _ -> pure "psa"
Left _ -> pure "purs"
Left (_err :: SomeException) -> pure "purs"

echoDebug $ "Compiling with " <> Messages.surroundQuote purs

Expand Down Expand Up @@ -115,8 +115,8 @@ psaVersion = versionImpl "psa"

versionImpl :: Spago m => Text -> m (Maybe Version.SemVer)
versionImpl purs = do
fullVersionText <- shellStrict (purs <> " --version") empty >>= \case
(ExitSuccess, out) -> pure out
fullVersionText <- shellStrictWithErr (purs <> " --version") empty >>= \case
(ExitSuccess, out, _err) -> pure out
_ -> die $ "Failed to run '" <> purs <> " --version'"
versionText <- pure $ headMay $ Text.split (== ' ') fullVersionText
parsed <- pure $ versionText >>= (hush . Version.semver)
Expand Down
96 changes: 96 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages:
- completed:
hackage: dhall-1.23.0@sha256:12a699b7ed30ee40b1a3e05dfd3eef1b053914a5aebeb2f76cc568306570e51b,30737
pantry-tree:
size: 127759
sha256: d5c6ff3a3628ac42975364405f9c0dfac4ad0286667e2535839b4806e5438109
original:
hackage: dhall-1.23.0
- completed:
hackage: dhall-json-1.2.8@sha256:e098f4f7891ea9ab2ac38c126614e07c821166dea47f10d876eaeda0ad5ceb11,3722
pantry-tree:
size: 632
sha256: c73951ed3564a1650d11d282c21cb284c884ff5524349f0d67298af7ea6ea90c
original:
hackage: dhall-json-1.2.8
- completed:
hackage: async-pool-0.9.0.2@sha256:3aca5861a7b839d02a3f5c52ad6d1ce368631003f68c3d9cb6d711c29e9618db,1599
pantry-tree:
size: 443
sha256: 6e97326dc06f9c32fbe7b312e17c427a716a9c2688529ab356de61b0effdb684
original:
hackage: async-pool-0.9.0.2
- completed:
hackage: cborg-json-0.2.1.0@sha256:af9137557002ca5308fe80570a9a29398dfb9708423870875223796760689ac3,1268
pantry-tree:
size: 274
sha256: fa0ca2dc2d6cdab48e5ef74ffe248670045fca98339d939e47215a5c3ebe47c0
original:
hackage: cborg-json-0.2.1.0@sha256:af9137557002ca5308fe80570a9a29398dfb9708423870875223796760689ac3
- completed:
hackage: versions-3.5.0@sha256:4eacd2eb31d6048b87ce3aa2c5cce98b79ac603cfd0e9c52706fcdb68625eb8d,2550
pantry-tree:
size: 319
sha256: 95f204e361a7fb2d943ca580ba60eda9cfb989ca7a9420bf56e7904cbbc9b5a6
original:
hackage: versions-3.5.0
- completed:
hackage: dotgen-0.4.2@sha256:309b7cc8a3593a8e48bee7b53020d5f72db156d58edf78a0214f58fbb84b292b,1402
pantry-tree:
size: 357
sha256: d03f332855d4d9b02e96931596e358202bd18032c323fb1abd8fe84299d259cd
original:
hackage: dotgen-0.4.2
- completed:
hackage: megaparsec-7.0.3@sha256:2dd155e03b373ebf082bfea1dcc805a7ec1921b4fb3909c47dee4ab8a3aaf68a,6202
pantry-tree:
size: 2647
sha256: 730ec04d25a37b28e19568730d4dda75cd44c7fe9f408316c3117c0a38453763
original:
hackage: megaparsec-7.0.3
- completed:
hackage: repline-0.2.1.0@sha256:0f8e92d78e771afb9d41243c2b6ab9609fe02f94e676fae3caed66fa4ce09b18,1187
pantry-tree:
size: 323
sha256: f48833fb8a89fc4ede1b254bdfbc8937d82e694eb05bf936bf89293bab691700
original:
hackage: repline-0.2.1.0
- completed:
hackage: serialise-0.2.1.0@sha256:8d6051f64c6ebfaf705195dd0b8dfb667617f2e674b290ed2e44985009e4f951,8242
pantry-tree:
size: 4056
sha256: 26f4c5d503a78001152b73868bd66c5b3479d9b62bb0134c6557815ced34402a
original:
hackage: serialise-0.2.1.0
- completed:
hackage: Win32-2.5.4.1@sha256:e623a1058bd8134ec14d62759f76cac52eee3576711cb2c4981f398f1ec44b85,3970
pantry-tree:
size: 5866
sha256: 34a2d4724363d2f509aba87672b87a24a5246737421ba904d242b1766c6df080
original:
hackage: Win32-2.5.4.1@sha256:e623a1058bd8134ec14d62759f76cac52eee3576711cb2c4981f398f1ec44b85
- completed:
hackage: Glob-0.10.0@sha256:bbccaf21bff9071dcf369f55cc1a07250bdc84c432bdf4277ed53e5e2327cd7d,2947
pantry-tree:
size: 1432
sha256: 2b14578b5cf51af20efeaf332a1e1ea0c9c24fe2fcb2afba64f77d9249395844
original:
hackage: Glob-0.10.0
- completed:
hackage: turtle-1.5.14@sha256:be0f9d3102e11458554d17f581a69984e511f15d6d51a4c4816743783576b566,4908
pantry-tree:
size: 1114
sha256: 191eed87a5e8713a212ddfe4c5f4b819d07771c56becd92b8b5c6119f7ddad5d
original:
hackage: turtle-1.5.14
snapshots:
- completed:
size: 508406
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/12/21.yaml
sha256: 609dd00c32f59e11bb333b9113d9d2e54269627de1268cbb3cc576af8c7b6237
original: lts-12.21
9 changes: 6 additions & 3 deletions test/SpagoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import qualified Data.Text as Text
import Prelude hiding (FilePath)
import qualified System.IO.Temp as Temp
import Test.Hspec (Spec, around_, describe, it, shouldBe)
import Turtle (cd, cp, decodeString, fromText, mkdir, mktree, mv,
readTextFile, rm, testdir, writeTextFile)
import Turtle (ExitCode (..), cd, cp, decodeString, fromText, mkdir, mktree,
mv, readTextFile, rm, testdir, writeTextFile, shell, empty)
import Utils (checkFixture, readFixture, runFor, shouldBeFailure,
shouldBeFailureOutput, shouldBeSuccess, shouldBeSuccessOutput,
spago, withCwd)
Expand Down Expand Up @@ -226,7 +226,10 @@ spec = around_ setup $ do
-- Note: apparently purs starts caching the compiled modules only after three builds
spago ["build"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt"

shell "psa --version" empty >>= \case
ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt"
ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output-psa-not-installed.txt"

it "Spago should be able to not use `psa`" $ do

Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/run-output-psa-not-installed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
🍝
Running NodeJS
Running `spago build`
Ensuring that the package set is frozen
Getting transitive deps
Running `fetchPackages`
Checking if `purs` is up to date
Running `getGlobalCacheDir`
Installation complete.
Compiling with "purs"
Running command: `purs compile ".spago/console/v4.2.0/src/**/*.purs" ".spago/effect/v2.0.1/src/**/*.purs" ".spago/prelude/v4.1.1/src/**/*.purs" ".spago/psci-support/v4.0.0/src/**/*.purs" "src/**/*.purs" "test/**/*.purs"`
Build succeeded.
Writing .spago/run.js

0 comments on commit 553e8cb

Please sign in to comment.