Skip to content

Commit

Permalink
Add extra-packages parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jgotoh committed Apr 3, 2023
1 parent 3d5d582 commit 9016a3a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ module Distribution.Client.ProjectConfig.FieldGrammar (
projectConfigFieldGrammar
) where

import Distribution.Compat.Prelude
import Distribution.Client.ProjectConfig.Legacy (ProjectConfigSkeleton)
import qualified Distribution.Client.ProjectConfig.Lens as L
import Distribution.Client.ProjectConfig.Types (ProjectConfig (..))
import Distribution.FieldGrammar
import Distribution.Types.PackageVersionConstraint (PackageVersionConstraint (..))

projectConfigFieldGrammar :: ParsecFieldGrammar' ProjectConfig
projectConfigFieldGrammar = ProjectConfig
<$> monoidalFieldAla "packages" (alaList' FSep Token') L.projectPackages
<*> monoidalFieldAla "optional-packages" (alaList' FSep Token') L.projectPackagesOptional
<*> pure mempty -- source-repository-package stanza
<*> monoidalFieldAla "extra-packages" formatPackagesNamedList L.projectPackagesNamed
<*> pure mempty
<*> pure mempty
<*> pure mempty
<*> pure mempty
<*> pure mempty
<*> pure mempty
<*> pure mempty
<*> pure mempty

formatPackagesNamedList :: [PackageVersionConstraint] -> List CommaVCat (Identity PackageVersionConstraint) PackageVersionConstraint
formatPackagesNamedList = alaList CommaVCat

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import Distribution.Client.DistDirLayout
import Distribution.Client.ProjectConfig
import Distribution.Client.RebuildMonad (runRebuild)
import Distribution.Types.CondTree (CondTree (..))
import Distribution.Types.PackageName
import Distribution.Types.PackageVersionConstraint (PackageVersionConstraint (..))
import Distribution.Types.Version (Version, mkVersion)
import Distribution.Types.VersionRange.Internal (VersionRange (..))
import Distribution.Verbosity

-- TODO create tests:
Expand All @@ -24,6 +28,7 @@ parserTests = [
-- testCase "read with legacy parser" testLegacyRead
testCase "read packages" testPackages
, testCase "read optional-packages" testOptionalPackages
, testCase "read extra-packages" testExtraPackages
]

-- Currently I compare the results of legacy parser with the new parser
Expand Down Expand Up @@ -51,7 +56,7 @@ testLegacyRead = do

testPackages :: Assertion
testPackages = do
let expected = [".", "packages/packages.cabal"] -- TODO https link, what does legacy parse?
let expected = [".", "packages/packages.cabal"] -- TODO also test https link
-- Note that I currently also run the legacy parser to make sure my expected values
-- do not differ from the non-Parsec implementation, this will be removed in the future
(config, legacy) <- readConfigDefault "packages"
Expand All @@ -63,6 +68,15 @@ testOptionalPackages = do
(config, legacy) <- readConfigDefault "optional-packages"
assertConfig expected config legacy (projectPackagesOptional . condTreeData)

testExtraPackages :: Assertion
testExtraPackages = do
let expected = [
PackageVersionConstraint (mkPackageName "a") (OrLaterVersion (mkVersion [0])),
PackageVersionConstraint (mkPackageName "b") (IntersectVersionRanges (OrLaterVersion (mkVersion [0,7,3])) (EarlierVersion (mkVersion [0,9])))
]
(config, legacy) <- readConfigDefault "extra-packages"
assertConfig expected config legacy (projectPackagesNamed . condTreeData)

readConfigDefault :: FilePath -> IO (ProjectConfigSkeleton, ProjectConfigSkeleton)
readConfigDefault rootFp = readConfig rootFp "cabal.project"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extra-packages:
a
, b >= 0.7.3 && < 0.9,

0 comments on commit 9016a3a

Please sign in to comment.