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

Enable spago install to work on advanced Dhall expressions #849

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

New Features
- `spago install` works on more advanced Dhall expressions as stored in `spago.dhall (#849)

## [0.20.4] - 2022-01-29

Bugfixes:
Expand Down
1 change: 1 addition & 0 deletions spago.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ library
Spago.Command.Path
Spago.Command.Verify
Spago.Config
Spago.Config.AST
Spago.Dhall
Spago.DryRun
Spago.Env
Expand Down
286 changes: 226 additions & 60 deletions src/Spago/Config.hs

Large diffs are not rendered by default.

690 changes: 690 additions & 0 deletions src/Spago/Config/AST.hs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Spago/Dhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ data ReadError a where
-- | a key is missing from a Dhall map
RequiredKeyMissing :: Typeable a => Text -> Dhall.Map.Map Text (DhallExpr a) -> ReadError a

deriving instance (Eq a) => Eq (ReadError a)

instance (Pretty a, Typeable a) => Exception (ReadError a)

instance (Pretty a) => Show (ReadError a) where
Expand Down
5 changes: 3 additions & 2 deletions src/Spago/Messages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Spago.Messages where

import Spago.Prelude

import qualified Data.Set as Set
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Text as Text

Expand Down Expand Up @@ -131,13 +132,13 @@ failedToReachGitHub err = makeMessage
, tshow err
]

failedToAddDeps :: NonEmpty Text -> Text
failedToAddDeps :: Set Text -> Text
failedToAddDeps pkgs = makeMessage $
[ "Some of the dependencies you tried to add were not found in the package-set."
, "Not adding any new dependencies to your new spago config."
, "We didn't find:"
]
<> map ("- " <>) (NonEmpty.toList pkgs)
<> map ("- " <>) (Set.toList pkgs)
<> [""]

updatingPackageSet :: Text -> Text
Expand Down
2 changes: 1 addition & 1 deletion src/Spago/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ install newPackages = do
-- Also skip the write if there are no new packages to be written
case existingNewPackages of
[] -> pure ()
additional -> Config.addDependencies config additional
additional -> Config.addDependencies config $ Set.fromList additional

Fetch.fetchPackages deps

Expand Down
12 changes: 12 additions & 0 deletions src/Spago/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Spago.Prelude
, lastMay
, empty
, ifM
, nubSeq

-- * Logging, errors, printing, etc
, Pretty
Expand Down Expand Up @@ -122,6 +123,8 @@ import qualified Data.ByteString.Lazy as BSL
import qualified Data.ByteString.Search as BSS
import qualified Data.ByteString.UTF8 as UTF8
import qualified System.IO as IO
import qualified Data.Sequence as Seq
import qualified Data.Set as Set


-- | Generic Error that we throw on program exit.
Expand Down Expand Up @@ -150,6 +153,15 @@ ifM p x y = p >>= \b -> if b then x else y
hush :: Either a b -> Maybe b
hush = either (const Nothing) Just

-- |
-- Removes duplicate elements in a @Seq@.
--
-- Code from https://stackoverflow.com/questions/45757839
nubSeq :: Ord a => Seq a -> Seq a
nubSeq xs = (fmap fst . Seq.filter (uncurry notElem)) (Seq.zip xs seens)
where
seens = Seq.scanl (flip Set.insert) Set.empty xs

pathFromText :: Text -> Turtle.FilePath
pathFromText = Turtle.fromText

Expand Down
3 changes: 2 additions & 1 deletion src/Spago/RunEnv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import qualified System.Environment as Env
import qualified RIO
import qualified System.Info
import qualified Turtle
import qualified Data.Set as Set

import qualified Spago.Config as Config
import qualified Spago.GlobalCache as Cache
Expand Down Expand Up @@ -205,7 +206,7 @@ getPackageSet = do
getMaybeGraph :: HasPursEnv env => BuildOptions -> Config -> [(PackageName, Package)] -> RIO env Graph
getMaybeGraph BuildOptions{ depsOnly, sourcePaths } Config{ configSourcePaths } deps = do
logDebug "Running `getMaybeGraph`"
let partitionedGlobs = Packages.getGlobs deps depsOnly $ toList configSourcePaths
let partitionedGlobs = Packages.getGlobs deps depsOnly $ Set.toList configSourcePaths
globs = Packages.getGlobsSourcePaths partitionedGlobs <> sourcePaths
supportsGraph <- Purs.hasMinPursVersion "0.14.0"
if not supportsGraph
Expand Down
6 changes: 3 additions & 3 deletions src/Spago/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data PackageSet = PackageSet
{ packagesDB :: Map PackageName Package
, packagesMinPursVersion :: Maybe Version.SemVer
}
deriving (Show, Generic)
deriving (Eq, Show, Generic)


-- | We consider a "Repo" a "box of source to include in the build"
Expand Down Expand Up @@ -190,14 +190,14 @@ data Config = Config
, alternateBackend :: Maybe Text
, configSourcePaths :: Set SourcePath
, publishConfig :: Either (Dhall.ReadError Void) PublishConfig
} deriving (Show, Generic)
} deriving (Eq, Show, Generic)


-- | The extra fields that are only needed for publishing libraries.
data PublishConfig = PublishConfig
{ publishLicense :: Text
, publishRepository :: Text
} deriving (Show, Generic)
} deriving (Eq, Show, Generic)

data PursCmd = PursCmd
{ purs :: Text
Expand Down
Loading