Skip to content

Commit d506be8

Browse files
committed
WIP
1 parent 9796a4d commit d506be8

File tree

2 files changed

+51
-40
lines changed

2 files changed

+51
-40
lines changed

cabal-install-parsers/src/Cabal/Project.hs

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DeriveFoldable #-}
3-
{-# LANGUAGE DeriveFunctor #-}
4-
{-# LANGUAGE DeriveGeneric #-}
5-
{-# LANGUAGE DeriveTraversable #-}
6-
{-# LANGUAGE MultiWayIf #-}
7-
{-# LANGUAGE OverloadedStrings #-}
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE DeriveFoldable #-}
3+
{-# LANGUAGE DeriveFunctor #-}
4+
{-# LANGUAGE DeriveGeneric #-}
5+
{-# LANGUAGE DeriveTraversable #-}
6+
{-# LANGUAGE MultiWayIf #-}
7+
{-# LANGUAGE OverloadedStrings #-}
88
{-# LANGUAGE ScopedTypeVariables #-}
99
-- | License: GPL-3.0-or-later AND BSD-3-Clause
1010
--
@@ -58,9 +58,9 @@ import qualified Data.Map.Strict as M
5858
import qualified Distribution.CabalSpecVersion as C
5959
import qualified Distribution.FieldGrammar as C
6060
import qualified Distribution.Fields as C
61+
import qualified Distribution.Fields.ConfVar as C
6162
import qualified Distribution.PackageDescription as C
6263
import qualified Distribution.Parsec as C
63-
import qualified Distribution.Fields.ConfVar as C
6464

6565
import Cabal.Internal.Glob
6666
import Cabal.Internal.Newtypes
@@ -433,38 +433,48 @@ parseCondTree
433433
parseCondTree subparse = go
434434
where
435435
go fields = do
436-
let (fs, ss) = C.partitionFields fields
437-
(ss', branches) <- second concat . unzip <$> traverse (parseIfs id id) ss
438-
x <- subparse fs ss'
439-
return $ C.CondNode x () branches
436+
let (fs, ss) = C.partitionFields fields
437+
(ss', branches) <- second concat . unzip <$> traverse (goIfs id id) ss
438+
x <- subparse fs ss'
439+
return $ C.CondNode x () branches
440440

441-
parseIfs
441+
goIfs
442442
:: ([C.Section C.Position] -> [C.Section C.Position])
443443
-> ([C.CondBranch C.ConfVar () a] -> [C.CondBranch C.ConfVar () a])
444444
-> [C.Section C.Position]
445445
-> C.ParseResult ([C.Section C.Position], [C.CondBranch C.ConfVar () a])
446-
parseIfs accS accB [] = return (accS [], accB [])
447-
parseIfs accS accB (C.MkSection (C.Name _ name) test fields : sections) | name == "if" = do
448-
test' <- C.parseConditionConfVar test
449-
fields' <- go fields
450-
parseElseIfs (C.CondBranch test' fields') accS accB sections
451-
parseIfs accS accB (section : sections) = do
452-
parseIfs (accS . (section :)) accB sections
453-
454-
parseElseIfs
446+
goIfs accS accB [] =
447+
return (accS [], accB [])
448+
goIfs accS accB (C.MkSection (C.Name pos name) test fields : sections)
449+
| name == "if" = do
450+
test' <- C.parseConditionConfVar test
451+
fields' <- go fields
452+
goElse (C.CondBranch test' fields') accS accB sections
453+
| name == "else" = do
454+
C.parseFailure pos "standalone else"
455+
return ([], [])
456+
| name == "elif" = do
457+
C.parseFailure pos "standalone elif"
458+
goIfs accS accB sections
459+
goIfs accS accB (section : sections) = do
460+
goIfs (accS . (section :)) accB sections
461+
462+
goElse
455463
:: (Maybe (C.CondTree C.ConfVar () a) -> C.CondBranch C.ConfVar () a)
456464
-> ([C.Section C.Position] -> [C.Section C.Position])
457465
-> ([C.CondBranch C.ConfVar () a] -> [C.CondBranch C.ConfVar () a])
458466
-> [C.Section C.Position]
459467
-> C.ParseResult ([C.Section C.Position], [C.CondBranch C.ConfVar () a])
460-
parseElseIfs make accS accB [] = do
468+
goElse make accS accB [] = do
461469
let condTree = make Nothing
462470
return (accS [], accB [condTree])
463-
parseElseIfs make accS accB (C.MkSection (C.Name pos name) _args _fields : _sections) | name == "else" = do
464-
C.parseFailure pos "else is not supprted yet"
465-
return ([], [])
466-
parseElseIfs make accS accB (C.MkSection (C.Name pos name) _args _fields : _sections) | name == "elif" = do
467-
C.parseFailure pos "elif is not supprted yet"
468-
return ([], [])
469-
parseElseIfs make accS accB (section : sections) = do
470-
parseIfs (accS . (section :)) (accB . (make Nothing :)) sections
471+
goElse _make _accS _accB (C.MkSection (C.Name pos name) _args _fields : _sections)
472+
| name == "else" = do
473+
C.parseFailure pos "else is not supprted yet"
474+
return ([], [])
475+
| name == "elif" = do
476+
C.parseFailure pos "elif is not supprted yet"
477+
return ([], [])
478+
goElse make accS accB (section : sections) = do
479+
let condTree = make Nothing
480+
goIfs (accS . (section :)) (accB . (condTree :)) sections

src/HaskellCI.hs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import System.Process (readProcessWithExitCode)
3535

3636
import Distribution.PackageDescription (GenericPackageDescription, package, packageDescription, testedWith)
3737
import Distribution.Text
38+
import Distribution.Types.CondTree (CondBranch (..), CondTree (..))
3839
import Distribution.Version
39-
import Distribution.Types.CondTree (CondTree (..), CondBranch (..))
4040

4141
import qualified Data.ByteString as BS
4242
import qualified Data.List.NonEmpty as NE
@@ -363,7 +363,7 @@ getCabalFiles InputTypeProject path = do
363363
contents <- liftIO $ BS.readFile path
364364
prj0 <- either (putStrLnErr . renderParseError) return $ parseProjectWithConditionals path contents
365365
let prj0' :: Project Void String String
366-
prj0' = simplifyProject prj0
366+
prj0' = simplifyProject prj0
367367
prj1 <- either (putStrLnErr . renderResolveError) return =<< liftIO (resolveProject path prj0')
368368
either (putStrLnErr . renderParseError) return =<< liftIO (readPackagesOfProject prj1)
369369
getCabalFiles InputTypePackage path = do
@@ -378,18 +378,19 @@ simplifyProject' :: CondBranch v d (Project Void String String) -> Project Void
378378
simplifyProject' (CondBranch _ t Nothing) = simplifyProject t
379379
simplifyProject' (CondBranch _ t (Just e)) = simplifyProject t <<>> simplifyProject e
380380

381+
-- TODO: we preserve only top-level structure and packages specs.
381382
(<<>>) :: Project pkg opt uri -> Project pkg opt uri -> Project pkg opt uri
382383
x <<>> y = Project
383-
{ prjPackages = prjPackages x <> prjPackages y
384+
{ prjPackages = prjPackages x <> prjPackages y
384385
, prjOptPackages = prjOptPackages x <> prjOptPackages y
385386
, prjUriPackages = prjUriPackages x <> prjUriPackages y
386-
, prjConstraints = prjConstraints x <> prjConstraints y
387-
, prjAllowNewer = prjAllowNewer x <> prjAllowNewer y
388-
, prjReorderGoals = prjReorderGoals x || prjReorderGoals y
389-
, prjMaxBackjumps = max (prjMaxBackjumps x) (prjMaxBackjumps y)
387+
, prjConstraints = prjConstraints x
388+
, prjAllowNewer = prjAllowNewer x
389+
, prjReorderGoals = prjReorderGoals x
390+
, prjMaxBackjumps = prjMaxBackjumps x
390391
, prjOptimization = prjOptimization x
391-
, prjSourceRepos = prjSourceRepos x <> prjSourceRepos y
392-
, prjOtherFields = prjOtherFields x<> prjOtherFields y
392+
, prjSourceRepos = prjSourceRepos x
393+
, prjOtherFields = prjOtherFields x
393394
}
394395

395396
-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)