Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
7a25636
proof of concept
leana8959 Oct 28, 2025
6150135
retain imports for foreignLib section
leana8959 Oct 29, 2025
cf672ab
retain imports for executable section
leana8959 Oct 29, 2025
a2cd919
retain imports for test-suite
leana8959 Oct 29, 2025
ffa5819
retain imports for benchmark
leana8959 Oct 29, 2025
d7fd48b
attepmt to insert used imports and not all imports
leana8959 Oct 30, 2025
ed82ab6
use newtype
leana8959 Nov 4, 2025
2c9de4d
change import data type; fix issues with import propagation & decoration
leana8959 Nov 4, 2025
76ae794
fix missing import names in testSuite
leana8959 Nov 5, 2025
41a4eeb
fix missing import names in benchmark
leana8959 Nov 5, 2025
f82caf2
run fourmolu
leana8959 Nov 5, 2025
e253225
run hlint
leana8959 Nov 5, 2025
21636db
defer merging prototype
leana8959 Nov 5, 2025
4985b0b
Revert "defer merging prototype"
leana8959 Nov 5, 2025
a67fa76
stop merging
leana8959 Nov 5, 2025
89c1b32
retain common stanza in GenericPackageDescription
leana8959 Nov 5, 2025
0b61013
experiment: use WithImport in gpd
leana8959 Nov 6, 2025
0274650
add function to merge imports
leana8959 Nov 6, 2025
0d506fb
mergeLibrary
leana8959 Nov 6, 2025
3de619f
test merging ability
leana8959 Nov 6, 2025
3022efe
fix transitive imports retaintion and merging
leana8959 Nov 6, 2025
8d8642d
run fourmolu
leana8959 Nov 6, 2025
c9ca3eb
deferred merging for sublibraries
leana8959 Nov 7, 2025
1cd716f
simplification; remove todos
leana8959 Nov 7, 2025
4a040df
retain foreignlib imports
leana8959 Nov 7, 2025
2d39129
retain executable imports
leana8959 Nov 7, 2025
ac75322
retain TestSuiteStanza imports
leana8959 Nov 10, 2025
4cfdbf4
retain BenchmarkStanza imports
leana8959 Nov 10, 2025
6d63351
clean up
leana8959 Nov 10, 2025
a5f2b3a
remove benchmark import field
leana8959 Nov 11, 2025
9628f8d
introduce type alias in GenericPackageDescription
leana8959 Nov 12, 2025
c204d24
add GenericPackageDescription pattern to hide internal implementation
leana8959 Nov 12, 2025
3e232f3
backward compatible accessors
leana8959 Nov 12, 2025
0d37e46
fix compiler errors
leana8959 Nov 12, 2025
9c98990
tests: add tests for accessors
leana8959 Nov 13, 2025
791eb8c
test: check equality on each field
leana8959 Nov 13, 2025
70813d1
tests: use distinct file for each field
leana8959 Nov 14, 2025
172ae45
add todo
leana8959 Nov 12, 2025
6081a30
fix compiler errors for integration test
leana8959 Nov 12, 2025
527fb2a
run fourmolu
leana8959 Nov 12, 2025
b688048
don't expose intemediary accessors
leana8959 Nov 12, 2025
7588010
remove early experiment "import" fields in TestSuite and Benchmark
leana8959 Nov 13, 2025
95cf42c
move TestSuiteStanza validation to its module
leana8959 Nov 13, 2025
3232231
clean up {TestSuite,Benchmark}Stanza exports from FieldGrammar
leana8959 Nov 13, 2025
f8c5eaf
restore old behaviour in code working with PackageDescription
leana8959 Nov 13, 2025
59d8c2b
patch {TestSuite,Benchmark}Stanza type when using accessor
leana8959 Nov 13, 2025
f06fcd0
remove accessors tests
leana8959 Nov 13, 2025
21e1326
tests: add test for failed case
leana8959 Nov 13, 2025
17a6bc6
fix accessor dropping common stanza map when non it is not required
leana8959 Nov 13, 2025
928c836
test: update expected
leana8959 Nov 14, 2025
6f81ea8
tests: improve import list
leana8959 Nov 14, 2025
1da8c79
tests: remove unused tuple instance
leana8959 Nov 14, 2025
d8a1fcc
Merge branch 'accessor-tests' into no-flatten-package-description
leana8959 Nov 14, 2025
54af5f7
tests: refactor accessor test
leana8959 Nov 14, 2025
f9eaae1
tests(UnitTests): update expected
leana8959 Nov 14, 2025
4fadd83
run fourmolu
leana8959 Nov 14, 2025
824495d
remove FieldGrammar export {TestSuite,Benchmark}Stanza
leana8959 Nov 14, 2025
a8944c3
tests: use @? operator
leana8959 Nov 14, 2025
b6362b0
Merge branch 'accessor-tests' into no-flatten-package-description
leana8959 Nov 14, 2025
aa8178c
test(HackageTests): make assertion on merging accessor fields
leana8959 Nov 15, 2025
13502a7
fix(GenericPackageDescription): "pattern" keyword deprecated after 914
leana8959 Nov 15, 2025
f371b42
test(ParserTests): correct comment of the nature of the test
leana8959 Nov 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions Cabal-syntax/Cabal-syntax.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ library
Distribution.Types.AbiDependency
Distribution.Types.AbiHash
Distribution.Types.Benchmark
Distribution.Types.BenchmarkStanza
Distribution.Types.Benchmark.Lens
Distribution.Types.BenchmarkInterface
Distribution.Types.BenchmarkType
Expand Down Expand Up @@ -160,6 +161,8 @@ library
Distribution.Types.Library.Lens
Distribution.Types.LibraryName
Distribution.Types.LibraryVisibility
Distribution.Types.Imports
Distribution.Types.Imports.Lens
Distribution.Types.MissingDependency
Distribution.Types.MissingDependencyReason
Distribution.Types.Mixin
Expand All @@ -183,6 +186,7 @@ library
Distribution.Types.SourceRepo
Distribution.Types.SourceRepo.Lens
Distribution.Types.TestSuite
Distribution.Types.TestSuiteStanza
Distribution.Types.TestSuite.Lens
Distribution.Types.TestSuiteInterface
Distribution.Types.TestType
Expand Down
8 changes: 8 additions & 0 deletions Cabal-syntax/src/Distribution/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module Distribution.PackageDescription
module Distribution.Types.PackageDescription
, module Distribution.Types.GenericPackageDescription

-- * Working with Imports
, module Distribution.Types.Imports

-- * Components
, module Distribution.Types.ComponentName

Expand All @@ -29,11 +32,13 @@ module Distribution.PackageDescription

-- ** TestSuite
, module Distribution.Types.TestSuite
, module Distribution.Types.TestSuiteStanza
, module Distribution.Types.TestType
, module Distribution.Types.TestSuiteInterface

-- ** Benchmark
, module Distribution.Types.Benchmark
, module Distribution.Types.BenchmarkStanza
, module Distribution.Types.BenchmarkType
, module Distribution.Types.BenchmarkInterface

Expand Down Expand Up @@ -88,6 +93,7 @@ import Prelude ()

import Distribution.Types.Benchmark
import Distribution.Types.BenchmarkInterface
import Distribution.Types.BenchmarkStanza
import Distribution.Types.BenchmarkType
import Distribution.Types.BuildInfo
import Distribution.Types.BuildType
Expand All @@ -105,6 +111,7 @@ import Distribution.Types.ForeignLibOption
import Distribution.Types.ForeignLibType
import Distribution.Types.GenericPackageDescription
import Distribution.Types.HookedBuildInfo
import Distribution.Types.Imports
import Distribution.Types.IncludeRenaming
import Distribution.Types.LegacyExeDependency
import Distribution.Types.Library
Expand All @@ -124,5 +131,6 @@ import Distribution.Types.SetupBuildInfo
import Distribution.Types.SourceRepo
import Distribution.Types.TestSuite
import Distribution.Types.TestSuiteInterface
import Distribution.Types.TestSuiteStanza
import Distribution.Types.TestType
import Distribution.Types.UnqualComponentName
232 changes: 0 additions & 232 deletions Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,10 @@ module Distribution.PackageDescription.FieldGrammar
, executableFieldGrammar

-- * Test suite
, TestSuiteStanza (..)
, testSuiteFieldGrammar
, validateTestSuite
, unvalidateTestSuite

-- ** Lenses
, testStanzaTestType
, testStanzaMainIs
, testStanzaTestModule
, testStanzaBuildInfo

-- * Benchmark
, BenchmarkStanza (..)
, benchmarkFieldGrammar
, validateBenchmark
, unvalidateBenchmark

-- * Field grammars
, formatDependencyList
Expand All @@ -48,12 +36,6 @@ module Distribution.PackageDescription.FieldGrammar
, formatOtherExtensions
, formatOtherModules

-- ** Lenses
, benchmarkStanzaBenchmarkType
, benchmarkStanzaMainIs
, benchmarkStanzaBenchmarkModule
, benchmarkStanzaBuildInfo

-- * Flag
, flagFieldGrammar

Expand Down Expand Up @@ -290,43 +272,6 @@ executableFieldGrammar n =
{-# SPECIALIZE executableFieldGrammar :: UnqualComponentName -> ParsecFieldGrammar' Executable #-}
{-# SPECIALIZE executableFieldGrammar :: UnqualComponentName -> PrettyFieldGrammar' Executable #-}

-------------------------------------------------------------------------------
-- TestSuite
-------------------------------------------------------------------------------

-- | An intermediate type just used for parsing the test-suite stanza.
-- After validation it is converted into the proper 'TestSuite' type.
data TestSuiteStanza = TestSuiteStanza
{ _testStanzaTestType :: Maybe TestType
, _testStanzaMainIs :: Maybe (RelativePath Source File)
, _testStanzaTestModule :: Maybe ModuleName
, _testStanzaBuildInfo :: BuildInfo
, _testStanzaCodeGenerators :: [String]
}

instance L.HasBuildInfo TestSuiteStanza where
buildInfo = testStanzaBuildInfo

testStanzaTestType :: Lens' TestSuiteStanza (Maybe TestType)
testStanzaTestType f s = fmap (\x -> s{_testStanzaTestType = x}) (f (_testStanzaTestType s))
{-# INLINE testStanzaTestType #-}

testStanzaMainIs :: Lens' TestSuiteStanza (Maybe (RelativePath Source File))
testStanzaMainIs f s = fmap (\x -> s{_testStanzaMainIs = x}) (f (_testStanzaMainIs s))
{-# INLINE testStanzaMainIs #-}

testStanzaTestModule :: Lens' TestSuiteStanza (Maybe ModuleName)
testStanzaTestModule f s = fmap (\x -> s{_testStanzaTestModule = x}) (f (_testStanzaTestModule s))
{-# INLINE testStanzaTestModule #-}

testStanzaBuildInfo :: Lens' TestSuiteStanza BuildInfo
testStanzaBuildInfo f s = fmap (\x -> s{_testStanzaBuildInfo = x}) (f (_testStanzaBuildInfo s))
{-# INLINE testStanzaBuildInfo #-}

testStanzaCodeGenerators :: Lens' TestSuiteStanza [String]
testStanzaCodeGenerators f s = fmap (\x -> s{_testStanzaCodeGenerators = x}) (f (_testStanzaCodeGenerators s))
{-# INLINE testStanzaCodeGenerators #-}

testSuiteFieldGrammar
:: ( FieldGrammar c g
, Applicative (g TestSuiteStanza)
Expand Down Expand Up @@ -361,117 +306,10 @@ testSuiteFieldGrammar =
<*> monoidalFieldAla "code-generators" (alaList' CommaFSep Token) testStanzaCodeGenerators
^^^ availableSince CabalSpecV3_8 []

validateTestSuite :: CabalSpecVersion -> Position -> TestSuiteStanza -> ParseResult src TestSuite
validateTestSuite cabalSpecVersion pos stanza = case testSuiteType of
Nothing -> pure basicTestSuite
Just tt@(TestTypeUnknown _ _) ->
pure
basicTestSuite
{ testInterface = TestSuiteUnsupported tt
}
Just tt
| tt `notElem` knownTestTypes ->
pure
basicTestSuite
{ testInterface = TestSuiteUnsupported tt
}
Just tt@(TestTypeExe ver) -> case _testStanzaMainIs stanza of
Nothing -> do
parseFailure pos (missingField "main-is" tt)
pure emptyTestSuite
Just file -> do
when (isJust (_testStanzaTestModule stanza)) $
parseWarning pos PWTExtraBenchmarkModule (extraField "test-module" tt)
pure
basicTestSuite
{ testInterface = TestSuiteExeV10 ver file
}
Just tt@(TestTypeLib ver) -> case _testStanzaTestModule stanza of
Nothing -> do
parseFailure pos (missingField "test-module" tt)
pure emptyTestSuite
Just module_ -> do
when (isJust (_testStanzaMainIs stanza)) $
parseWarning pos PWTExtraMainIs (extraField "main-is" tt)
pure
basicTestSuite
{ testInterface = TestSuiteLibV09 ver module_
}
where
testSuiteType =
_testStanzaTestType stanza
<|> do
guard (cabalSpecVersion >= CabalSpecV3_8)

testTypeExe <$ _testStanzaMainIs stanza
<|> testTypeLib <$ _testStanzaTestModule stanza

missingField name tt =
"The '"
++ name
++ "' field is required for the "
++ prettyShow tt
++ " test suite type."

extraField name tt =
"The '"
++ name
++ "' field is not used for the '"
++ prettyShow tt
++ "' test suite type."
basicTestSuite =
emptyTestSuite
{ testBuildInfo = _testStanzaBuildInfo stanza
, testCodeGenerators = _testStanzaCodeGenerators stanza
}

unvalidateTestSuite :: TestSuite -> TestSuiteStanza
unvalidateTestSuite t =
TestSuiteStanza
{ _testStanzaTestType = ty
, _testStanzaMainIs = ma
, _testStanzaTestModule = mo
, _testStanzaBuildInfo = testBuildInfo t
, _testStanzaCodeGenerators = testCodeGenerators t
}
where
(ty, ma, mo) = case testInterface t of
TestSuiteExeV10 ver file -> (Just $ TestTypeExe ver, Just file, Nothing)
TestSuiteLibV09 ver modu -> (Just $ TestTypeLib ver, Nothing, Just modu)
_ -> (Nothing, Nothing, Nothing)

-------------------------------------------------------------------------------
-- Benchmark
-------------------------------------------------------------------------------

-- | An intermediate type just used for parsing the benchmark stanza.
-- After validation it is converted into the proper 'Benchmark' type.
data BenchmarkStanza = BenchmarkStanza
{ _benchmarkStanzaBenchmarkType :: Maybe BenchmarkType
, _benchmarkStanzaMainIs :: Maybe (RelativePath Source File)
, _benchmarkStanzaBenchmarkModule :: Maybe ModuleName
, _benchmarkStanzaBuildInfo :: BuildInfo
}

instance L.HasBuildInfo BenchmarkStanza where
buildInfo = benchmarkStanzaBuildInfo

benchmarkStanzaBenchmarkType :: Lens' BenchmarkStanza (Maybe BenchmarkType)
benchmarkStanzaBenchmarkType f s = fmap (\x -> s{_benchmarkStanzaBenchmarkType = x}) (f (_benchmarkStanzaBenchmarkType s))
{-# INLINE benchmarkStanzaBenchmarkType #-}

benchmarkStanzaMainIs :: Lens' BenchmarkStanza (Maybe (RelativePath Source File))
benchmarkStanzaMainIs f s = fmap (\x -> s{_benchmarkStanzaMainIs = x}) (f (_benchmarkStanzaMainIs s))
{-# INLINE benchmarkStanzaMainIs #-}

benchmarkStanzaBenchmarkModule :: Lens' BenchmarkStanza (Maybe ModuleName)
benchmarkStanzaBenchmarkModule f s = fmap (\x -> s{_benchmarkStanzaBenchmarkModule = x}) (f (_benchmarkStanzaBenchmarkModule s))
{-# INLINE benchmarkStanzaBenchmarkModule #-}

benchmarkStanzaBuildInfo :: Lens' BenchmarkStanza BuildInfo
benchmarkStanzaBuildInfo f s = fmap (\x -> s{_benchmarkStanzaBuildInfo = x}) (f (_benchmarkStanzaBuildInfo s))
{-# INLINE benchmarkStanzaBuildInfo #-}

benchmarkFieldGrammar
:: ( FieldGrammar c g
, Applicative (g BenchmarkStanza)
Expand Down Expand Up @@ -503,76 +341,6 @@ benchmarkFieldGrammar =
<*> optionalField "benchmark-module" benchmarkStanzaBenchmarkModule
<*> blurFieldGrammar benchmarkStanzaBuildInfo buildInfoFieldGrammar

validateBenchmark :: CabalSpecVersion -> Position -> BenchmarkStanza -> ParseResult src Benchmark
validateBenchmark cabalSpecVersion pos stanza = case benchmarkStanzaType of
Nothing ->
pure
emptyBenchmark
{ benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza
}
Just tt@(BenchmarkTypeUnknown _ _) ->
pure
emptyBenchmark
{ benchmarkInterface = BenchmarkUnsupported tt
, benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza
}
Just tt
| tt `notElem` knownBenchmarkTypes ->
pure
emptyBenchmark
{ benchmarkInterface = BenchmarkUnsupported tt
, benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza
}
Just tt@(BenchmarkTypeExe ver) -> case _benchmarkStanzaMainIs stanza of
Nothing -> do
parseFailure pos (missingField "main-is" tt)
pure emptyBenchmark
Just file -> do
when (isJust (_benchmarkStanzaBenchmarkModule stanza)) $
parseWarning pos PWTExtraBenchmarkModule (extraField "benchmark-module" tt)
pure
emptyBenchmark
{ benchmarkInterface = BenchmarkExeV10 ver file
, benchmarkBuildInfo = _benchmarkStanzaBuildInfo stanza
}
where
benchmarkStanzaType =
_benchmarkStanzaBenchmarkType stanza <|> do
guard (cabalSpecVersion >= CabalSpecV3_8)

benchmarkTypeExe <$ _benchmarkStanzaMainIs stanza

missingField name tt =
"The '"
++ name
++ "' field is required for the "
++ prettyShow tt
++ " benchmark type."

extraField name tt =
"The '"
++ name
++ "' field is not used for the '"
++ prettyShow tt
++ "' benchmark type."

unvalidateBenchmark :: Benchmark -> BenchmarkStanza
unvalidateBenchmark b =
BenchmarkStanza
{ _benchmarkStanzaBenchmarkType = ty
, _benchmarkStanzaMainIs = ma
, _benchmarkStanzaBenchmarkModule = mo
, _benchmarkStanzaBuildInfo = benchmarkBuildInfo b
}
where
(ty, ma, mo) = case benchmarkInterface b of
BenchmarkExeV10 ver ma'
| getSymbolicPath ma' == "" ->
(Just $ BenchmarkTypeExe ver, Nothing, Nothing)
| otherwise ->
(Just $ BenchmarkTypeExe ver, Just ma', Nothing)
_ -> (Nothing, Nothing, Nothing)

-------------------------------------------------------------------------------
-- Build info
-------------------------------------------------------------------------------
Expand Down
Loading
Loading