@@ -80,6 +80,8 @@ import qualified Data.Map.Strict as Map
80
80
import qualified Data.Set as Set
81
81
import qualified Distribution.Compat.Newtype as Newtype
82
82
import qualified Distribution.Types.BuildInfo.Lens as L
83
+ import qualified Distribution.Types.Executable.Lens as L
84
+ import qualified Distribution.Types.ForeignLib.Lens as L
83
85
import qualified Distribution.Types.GenericPackageDescription.Lens as L
84
86
import qualified Distribution.Types.PackageDescription.Lens as L
85
87
import qualified Text.Parsec as P
@@ -292,7 +294,7 @@ goSections specVer = traverse_ process
292
294
| name == " foreign-library" = do
293
295
commonStanzas <- use stateCommonStanzas
294
296
name' <- parseUnqualComponentName pos args
295
- flib <- lift $ parseCondTree' (foreignLibFieldGrammar name') fromBuildInfo' commonStanzas fields
297
+ flib <- lift $ parseCondTree' (foreignLibFieldGrammar name') ( fromBuildInfo' name') commonStanzas fields
296
298
297
299
let hasType ts = foreignLibType ts /= foreignLibType mempty
298
300
unless (onAllBranches hasType flib) $ lift $ parseFailure pos $ concat
@@ -309,14 +311,14 @@ goSections specVer = traverse_ process
309
311
| name == " executable" = do
310
312
commonStanzas <- use stateCommonStanzas
311
313
name' <- parseUnqualComponentName pos args
312
- exe <- lift $ parseCondTree' (executableFieldGrammar name') fromBuildInfo' commonStanzas fields
314
+ exe <- lift $ parseCondTree' (executableFieldGrammar name') ( fromBuildInfo' name') commonStanzas fields
313
315
-- TODO check duplicate name here?
314
316
stateGpd . L. condExecutables %= snoc (name', exe)
315
317
316
318
| name == " test-suite" = do
317
319
commonStanzas <- use stateCommonStanzas
318
320
name' <- parseUnqualComponentName pos args
319
- testStanza <- lift $ parseCondTree' testSuiteFieldGrammar fromBuildInfo' commonStanzas fields
321
+ testStanza <- lift $ parseCondTree' testSuiteFieldGrammar ( fromBuildInfo' name') commonStanzas fields
320
322
testSuite <- lift $ traverse (validateTestSuite pos) testStanza
321
323
322
324
let hasType ts = testInterface ts /= testInterface mempty
@@ -334,7 +336,7 @@ goSections specVer = traverse_ process
334
336
| name == " benchmark" = do
335
337
commonStanzas <- use stateCommonStanzas
336
338
name' <- parseUnqualComponentName pos args
337
- benchStanza <- lift $ parseCondTree' benchmarkFieldGrammar fromBuildInfo' commonStanzas fields
339
+ benchStanza <- lift $ parseCondTree' benchmarkFieldGrammar ( fromBuildInfo' name') commonStanzas fields
338
340
bench <- lift $ traverse (validateBenchmark pos) benchStanza
339
341
340
342
let hasType ts = benchmarkInterface ts /= benchmarkInterface mempty
@@ -547,10 +549,13 @@ with new AST, this all need to be rewritten.
547
549
type CondTreeBuildInfo = CondTree ConfVar [Dependency ] BuildInfo
548
550
549
551
-- | Create @a@ from 'BuildInfo'.
552
+ -- This class is used to implement common stanza parsing.
550
553
--
551
554
-- Law: @view buildInfo . fromBuildInfo = id@
555
+ --
556
+ -- This takes name, as 'FieldGrammar's take names too.
552
557
class L. HasBuildInfo a => FromBuildInfo a where
553
- fromBuildInfo' :: BuildInfo -> a
558
+ fromBuildInfo' :: UnqualComponentName -> BuildInfo -> a
554
559
555
560
libraryFromBuildInfo :: LibraryName -> BuildInfo -> Library
556
561
libraryFromBuildInfo n bi = emptyLibrary
@@ -561,15 +566,15 @@ libraryFromBuildInfo n bi = emptyLibrary
561
566
, libBuildInfo = bi
562
567
}
563
568
564
- instance FromBuildInfo BuildInfo where fromBuildInfo' = id
565
- instance FromBuildInfo ForeignLib where fromBuildInfo' bi = set L. buildInfo bi emptyForeignLib
566
- instance FromBuildInfo Executable where fromBuildInfo' bi = set L. buildInfo bi emptyExecutable
569
+ instance FromBuildInfo BuildInfo where fromBuildInfo' _ = id
570
+ instance FromBuildInfo ForeignLib where fromBuildInfo' n bi = set L. foreignLibName n $ set L. buildInfo bi emptyForeignLib
571
+ instance FromBuildInfo Executable where fromBuildInfo' n bi = set L. exeName n $ set L. buildInfo bi emptyExecutable
567
572
568
573
instance FromBuildInfo TestSuiteStanza where
569
- fromBuildInfo' = TestSuiteStanza Nothing Nothing Nothing
574
+ fromBuildInfo' _ bi = TestSuiteStanza Nothing Nothing Nothing bi
570
575
571
576
instance FromBuildInfo BenchmarkStanza where
572
- fromBuildInfo' = BenchmarkStanza Nothing Nothing Nothing
577
+ fromBuildInfo' _ bi = BenchmarkStanza Nothing Nothing Nothing bi
573
578
574
579
parseCondTreeWithCommonStanzas
575
580
:: forall a . L. HasBuildInfo a
0 commit comments