Skip to content

Commit 5134617

Browse files
committed
feat: support generated cmm-sources
1 parent 98242d4 commit 5134617

File tree

11 files changed

+473
-394
lines changed

11 files changed

+473
-394
lines changed

Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 140 additions & 131 deletions
Large diffs are not rendered by default.

Cabal-syntax/src/Distribution/Types/BuildInfo.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ data BuildInfo = BuildInfo
7272
-- ^ support frameworks for Mac OS X
7373
, extraFrameworkDirs :: [SymbolicPath Pkg (Dir Framework)]
7474
-- ^ extra locations to find frameworks
75-
, asmSources :: [ExtraSource]
75+
, asmSources :: [ExtraSource Pkg]
7676
-- ^ Assembly source files
77-
, cmmSources :: [ExtraSource]
77+
, cmmSources :: [ExtraSource Pkg]
7878
-- ^ C-- source files
79-
, cSources :: [ExtraSource]
79+
, autogenCmmSources :: [ExtraSource Build]
80+
-- ^ C-- generated source files
81+
, cSources :: [ExtraSource Pkg]
8082
-- ^ C source files
81-
, cxxSources :: [ExtraSource]
83+
, cxxSources :: [ExtraSource Pkg]
8284
-- ^ C++ source files
83-
, jsSources :: [ExtraSource]
85+
, jsSources :: [ExtraSource Pkg]
8486
-- ^ JavaScript source file
8587
, hsSourceDirs :: [SymbolicPath Pkg (Dir Source)]
8688
-- ^ where to look for the Haskell module hierarchy
@@ -172,6 +174,7 @@ instance Monoid BuildInfo where
172174
, extraFrameworkDirs = []
173175
, asmSources = []
174176
, cmmSources = []
177+
, autogenCmmSources = []
175178
, cSources = []
176179
, cxxSources = []
177180
, jsSources = []
@@ -225,6 +228,7 @@ instance Semigroup BuildInfo where
225228
, extraFrameworkDirs = combineNub extraFrameworkDirs
226229
, asmSources = combineNub asmSources
227230
, cmmSources = combineNub cmmSources
231+
, autogenCmmSources = combineNub autogenCmmSources
228232
, cSources = combineNub cSources
229233
, cxxSources = combineNub cxxSources
230234
, jsSources = combineNub jsSources

Cabal-syntax/src/Distribution/Types/BuildInfo/Lens.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Distribution.Types.BuildInfo (BuildInfo)
1616
import Distribution.Types.ExtraSource (ExtraSource)
1717
import Distribution.Types.Dependency (Dependency)
1818
import Distribution.Types.ExeDependency (ExeDependency)
19+
import Distribution.Types.ExtraSource (ExtraSource)
1920
import Distribution.Types.LegacyExeDependency (LegacyExeDependency)
2021
import Distribution.Types.Mixin (Mixin)
2122
import Distribution.Types.PkgconfigDependency (PkgconfigDependency)
@@ -80,23 +81,27 @@ class HasBuildInfo a where
8081
extraFrameworkDirs = buildInfo . extraFrameworkDirs
8182
{-# INLINE extraFrameworkDirs #-}
8283

83-
asmSources :: Lens' a [ExtraSource]
84+
asmSources :: Lens' a [ExtraSource Pkg]
8485
asmSources = buildInfo . asmSources
8586
{-# INLINE asmSources #-}
8687

87-
cmmSources :: Lens' a [ExtraSource]
88+
autogenCmmSources :: Lens' a [ExtraSource Build]
89+
autogenCmmSources = buildInfo . autogenCmmSources
90+
{-# INLINE autogenCmmSources #-}
91+
92+
cmmSources :: Lens' a [ExtraSource Pkg]
8893
cmmSources = buildInfo . cmmSources
8994
{-# INLINE cmmSources #-}
9095

91-
cSources :: Lens' a [ExtraSource]
96+
cSources :: Lens' a [ExtraSource Pkg]
9297
cSources = buildInfo . cSources
9398
{-# INLINE cSources #-}
9499

95-
cxxSources :: Lens' a [ExtraSource]
100+
cxxSources :: Lens' a [ExtraSource Pkg]
96101
cxxSources = buildInfo . cxxSources
97102
{-# INLINE cxxSources #-}
98103

99-
jsSources :: Lens' a [ExtraSource]
104+
jsSources :: Lens' a [ExtraSource Pkg]
100105
jsSources = buildInfo . jsSources
101106
{-# INLINE jsSources #-}
102107

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,79 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE DeriveDataTypeable #-}
23
{-# LANGUAGE DeriveGeneric #-}
3-
{-# LANGUAGE DataKinds #-}
4+
{-# LANGUAGE FlexibleInstances #-}
5+
{-# LANGUAGE TypeFamilies #-}
46

57
module Distribution.Types.ExtraSource
68
( ExtraSource (..)
7-
, extraSourceFromPath
9+
, ExtraSourceClass (..)
810
) where
911

1012
import Distribution.Compat.Prelude
1113
import Prelude ()
1214

1315
import Distribution.Parsec
1416
import Distribution.Pretty
15-
import Distribution.Utils.Path (SymbolicPath, FileOrDir(..), Pkg)
17+
import Distribution.Utils.Path (Build, FileOrDir (..), Pkg, RelativePath, SymbolicPath, relativeSymbolicPath, unsafeCoerceSymbolicPath)
1618

1719
import qualified Distribution.Compat.CharParsing as P
1820
import qualified Text.PrettyPrint as PP
19-
import Distribution.FieldGrammar.Newtypes (SymbolicPathNT(..))
2021

21-
data ExtraSource = ExtraSource
22-
{ extraSourceFile :: SymbolicPath Pkg File
23-
, extraSourceOpts :: [String]
24-
}
22+
data family ExtraSource pkg
23+
24+
data instance ExtraSource Pkg = ExtraSourcePkg (SymbolicPath Pkg File) [String]
25+
deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)
26+
27+
data instance ExtraSource Build = ExtraSourceBuild (RelativePath Build File) [String]
2528
deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)
2629

27-
instance Binary ExtraSource
28-
instance Structured ExtraSource
29-
instance NFData ExtraSource where rnf = genericRnf
30+
class ExtraSourceClass e where
31+
extraSourceOpts :: e -> [String]
32+
extraSourceFile :: e -> SymbolicPath Pkg 'File
33+
34+
instance ExtraSourceClass (ExtraSource Pkg) where
35+
extraSourceOpts (ExtraSourcePkg _ opts) = opts
36+
extraSourceFile (ExtraSourcePkg f _) = f
37+
38+
instance ExtraSourceClass (ExtraSource Build) where
39+
extraSourceOpts (ExtraSourceBuild _ opts) = opts
40+
41+
-- FIXME
42+
extraSourceFile (ExtraSourceBuild f _) = unsafeCoerceSymbolicPath (relativeSymbolicPath f)
3043

31-
instance Parsec ExtraSource where
44+
instance Binary (ExtraSource Pkg)
45+
instance Structured (ExtraSource Pkg)
46+
instance NFData (ExtraSource Pkg) where rnf = genericRnf
47+
48+
instance Binary (ExtraSource Build)
49+
instance Structured (ExtraSource Build)
50+
instance NFData (ExtraSource Build) where rnf = genericRnf
51+
52+
instance Parsec (ExtraSource Pkg) where
3253
parsec = do
33-
SymbolicPathNT path <- parsec <* P.spaces
34-
opts <- P.optional (parensLax (P.sepBy p P.spaces))
35-
return (ExtraSource path (fromMaybe mempty opts))
54+
path <- parsec <* P.spaces
55+
opts <- P.optional (parensLax (P.sepBy p P.spaces))
56+
return (ExtraSourcePkg path (fromMaybe mempty opts))
3657
where
3758
p :: P.CharParsing p => p String
38-
p = some $ P.satisfy (\c -> not (isSpace c) && not (c == ')'))
59+
p = some $ P.satisfy (\c -> not (isSpace c) && (c /= ')'))
3960

40-
parensLax :: (P.CharParsing m) => m a -> m a
41-
parensLax p = P.between (P.char '(' *> P.spaces) (P.char ')' *> P.spaces) p
61+
instance Parsec (ExtraSource Build) where
62+
parsec = do
63+
path <- parsec <* P.spaces
64+
opts <- P.optional (parensLax (P.sepBy p P.spaces))
65+
return (ExtraSourceBuild path (fromMaybe mempty opts))
66+
where
67+
p :: P.CharParsing p => p String
68+
p = some $ P.satisfy (\c -> not (isSpace c) && (c /= ')'))
4269

43-
instance Pretty ExtraSource where
44-
pretty (ExtraSource path opts) =
45-
pretty (SymbolicPathNT path) <<>> PP.parens (PP.hsep (map PP.text opts))
70+
instance Pretty (ExtraSource Pkg) where
71+
pretty (ExtraSourcePkg path opts) =
72+
pretty path <<>> PP.parens (PP.hsep (map PP.text opts))
4673

47-
extraSourceFromPath :: SymbolicPath Pkg File -> ExtraSource
48-
extraSourceFromPath fp = ExtraSource fp mempty
74+
instance Pretty (ExtraSource Build) where
75+
pretty (ExtraSourceBuild path opts) =
76+
pretty path <<>> PP.parens (PP.hsep (map PP.text opts))
77+
78+
parensLax :: P.CharParsing m => m a -> m a
79+
parensLax p = P.between (P.char '(' *> P.spaces) (P.char ')' *> P.spaces) p

Cabal-syntax/src/Distribution/Utils/Path.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ data CWD
460460
-- | Abstract directory: package directory (e.g. a directory containing the @.cabal@ file).
461461
--
462462
-- See Note [Symbolic paths] in Distribution.Utils.Path.
463-
data Pkg
463+
data Pkg deriving (Data)
464464

465465
-- | Abstract directory: dist directory (e.g. @dist-newstyle@).
466466
--
@@ -490,7 +490,7 @@ data Framework
490490
-- | Abstract directory: build directory.
491491
--
492492
-- See Note [Symbolic paths] in Distribution.Utils.Path.
493-
data Build
493+
data Build deriving (Data)
494494

495495
-- | Abstract directory: directory for build artifacts, such as documentation or @.hie@ files.
496496
--

0 commit comments

Comments
 (0)