Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cabal
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
Cabal
Commits
05899742
Commit
05899742
authored
8 years ago
by
Edward Z. Yang
Browse files
Options
Downloads
Patches
Plain Diff
Fix pretty-printing PackageDescription for good.
Signed-off-by:
Edward Z. Yang
<
ezyang@cs.stanford.edu
>
parent
a090a494
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Cabal/Distribution/PackageDescription/Parse.hs
+7
-7
7 additions, 7 deletions
Cabal/Distribution/PackageDescription/Parse.hs
Cabal/Distribution/PackageDescription/PrettyPrint.hs
+91
-27
91 additions, 27 deletions
Cabal/Distribution/PackageDescription/PrettyPrint.hs
with
98 additions
and
34 deletions
Cabal/Distribution/PackageDescription/Parse.hs
+
7
−
7
View file @
05899742
...
...
@@ -24,6 +24,10 @@ module Distribution.PackageDescription.Parse (
FieldDescr
(
..
),
LineNo
,
-- ** Private, but needed for pretty-printer
TestSuiteStanza
(
..
),
BenchmarkStanza
(
..
),
-- ** Supplementary build information
readHookedBuildInfo
,
parseHookedBuildInfo
,
...
...
@@ -34,6 +38,7 @@ module Distribution.PackageDescription.Parse (
binfoFieldDescrs
,
sourceRepoFieldDescrs
,
testSuiteFieldDescrs
,
benchmarkFieldDescrs
,
flagFieldDescrs
)
where
...
...
@@ -189,12 +194,7 @@ storeXFieldsLib _ _ = Nothing
executableFieldDescrs
::
[
FieldDescr
Executable
]
executableFieldDescrs
=
[
-- note ordering: configuration must come first, for
-- showPackageDescription.
simpleField
"executable"
showToken
parseTokenQ
exeName
(
\
xs
exe
->
exe
{
exeName
=
xs
})
,
simpleField
"main-is"
[
simpleField
"main-is"
showFilePath
parseFilePathQ
modulePath
(
\
xs
exe
->
exe
{
modulePath
=
xs
})
]
...
...
@@ -1094,7 +1094,7 @@ parsePackageDescription file = do
-- Note: we don't parse the "executable" field here, hence the tail hack.
parseExeFields
::
[
Field
]
->
PM
Executable
parseExeFields
=
lift
.
parseFields
(
tail
executableFieldDescrs
)
parseExeFields
=
lift
.
parseFields
executableFieldDescrs
storeXFieldsExe
emptyExecutable
parseTestFields
::
LineNo
->
[
Field
]
->
PM
TestSuite
...
...
This diff is collapsed.
Click to expand it.
Cabal/Distribution/PackageDescription/PrettyPrint.hs
+
91
−
27
View file @
05899742
...
...
@@ -35,6 +35,7 @@ import Distribution.ParseUtils
import
Distribution.PackageDescription.Parse
import
Distribution.Package
import
Distribution.Text
import
Distribution.ModuleName
import
Text.PrettyPrint
(
hsep
,
space
,
parens
,
char
,
nest
,
isEmpty
,
(
$$
),
(
<+>
),
...
...
@@ -58,11 +59,11 @@ ppGenericPackageDescription :: GenericPackageDescription -> Doc
ppGenericPackageDescription
gpd
=
ppPackageDescription
(
packageDescription
gpd
)
$+$
ppGenPackageFlags
(
genPackageFlags
gpd
)
$+$
ppLibrary
(
condLibrary
gpd
)
$+$
ppSubLibraries
(
condSubLibraries
gpd
)
$+$
ppExecutables
(
condExecutables
gpd
)
$+$
ppTestSuites
(
condTestSuites
gpd
)
$+$
ppBenchmarks
(
condBenchmarks
gpd
)
$+$
pp
Cond
Library
(
condLibrary
gpd
)
$+$
pp
Cond
SubLibraries
(
condSubLibraries
gpd
)
$+$
pp
Cond
Executables
(
condExecutables
gpd
)
$+$
pp
Cond
TestSuites
(
condTestSuites
gpd
)
$+$
pp
Cond
Benchmarks
(
condBenchmarks
gpd
)
ppPackageDescription
::
PackageDescription
->
Doc
ppPackageDescription
pd
=
ppFields
pkgDescrFieldDescrs
pd
...
...
@@ -119,14 +120,14 @@ ppFlag flag@(MkFlag name _ _ _) =
where
fields
=
ppFieldsFiltered
flagDefaults
flagFieldDescrs
flag
ppLibrary
::
Maybe
(
CondTree
ConfVar
[
Dependency
]
Library
)
->
Doc
ppLibrary
Nothing
=
mempty
ppLibrary
(
Just
condTree
)
=
pp
Cond
Library
::
Maybe
(
CondTree
ConfVar
[
Dependency
]
Library
)
->
Doc
pp
Cond
Library
Nothing
=
mempty
pp
Cond
Library
(
Just
condTree
)
=
emptyLine
$
text
"library"
$+$
nest
indentWith
(
ppCondTree
condTree
Nothing
ppLib
)
ppSubLibraries
::
[(
String
,
CondTree
ConfVar
[
Dependency
]
Library
)]
->
Doc
ppSubLibraries
libs
=
pp
Cond
SubLibraries
::
[(
String
,
CondTree
ConfVar
[
Dependency
]
Library
)]
->
Doc
pp
Cond
SubLibraries
libs
=
vcat
[
emptyLine
$
text
(
"library "
++
n
)
$+$
nest
indentWith
(
ppCondTree
condTree
Nothing
ppLib
)
|
(
n
,
condTree
)
<-
libs
]
...
...
@@ -136,8 +137,8 @@ ppLib lib Nothing = ppFieldsFiltered libDefaults libFieldDescrs lib
ppLib
lib
(
Just
plib
)
=
ppDiffFields
libFieldDescrs
lib
plib
$$
ppCustomFields
(
customFieldsBI
(
libBuildInfo
lib
))
ppExecutables
::
[(
String
,
CondTree
ConfVar
[
Dependency
]
Executable
)]
->
Doc
ppExecutables
exes
=
pp
Cond
Executables
::
[(
String
,
CondTree
ConfVar
[
Dependency
]
Executable
)]
->
Doc
pp
Cond
Executables
exes
=
vcat
[
emptyLine
$
text
(
"executable "
++
n
)
$+$
nest
indentWith
(
ppCondTree
condTree
Nothing
ppExe
)
|
(
n
,
condTree
)
<-
exes
]
where
...
...
@@ -152,8 +153,8 @@ ppExecutables exes =
$+$
ppDiffFields
binfoFieldDescrs
buildInfo'
buildInfo2
$+$
ppCustomFields
(
customFieldsBI
buildInfo'
)
ppTestSuites
::
[(
String
,
CondTree
ConfVar
[
Dependency
]
TestSuite
)]
->
Doc
ppTestSuites
suites
=
pp
Cond
TestSuites
::
[(
String
,
CondTree
ConfVar
[
Dependency
]
TestSuite
)]
->
Doc
pp
Cond
TestSuites
suites
=
emptyLine
$
vcat
[
text
(
"test-suite "
++
n
)
$+$
nest
indentWith
(
ppCondTree
condTree
Nothing
ppTestSuite
)
|
(
n
,
condTree
)
<-
suites
]
...
...
@@ -184,8 +185,8 @@ ppTestSuites suites =
TestSuiteLibV09
_
m
->
Just
m
_
->
Nothing
ppBenchmarks
::
[(
String
,
CondTree
ConfVar
[
Dependency
]
Benchmark
)]
->
Doc
ppBenchmarks
suites
=
pp
Cond
Benchmarks
::
[(
String
,
CondTree
ConfVar
[
Dependency
]
Benchmark
)]
->
Doc
pp
Cond
Benchmarks
suites
=
emptyLine
$
vcat
[
text
(
"benchmark "
++
n
)
$+$
nest
indentWith
(
ppCondTree
condTree
Nothing
ppBenchmark
)
|
(
n
,
condTree
)
<-
suites
]
...
...
@@ -280,17 +281,80 @@ writePackageDescription fpath pkg = writeUTF8File fpath (showPackageDescription
-- | @since 1.26.0.0@
showPackageDescription
::
PackageDescription
->
String
showPackageDescription
pkg
=
render
$
ppPackage
pkg
$$
ppCustomFields
(
customFieldsPD
pkg
)
$$
(
case
library
pkg
of
Nothing
->
mempty
Just
lib
->
ppLibrary'
lib
)
$$
vcat
[
space
$$
ppLibrary'
lib
|
lib
<-
subLibraries
pkg
]
$$
vcat
[
space
$$
ppExecutable
exe
|
exe
<-
executables
pkg
]
where
ppPackage
=
ppFields
pkgDescrFieldDescrs
ppLibrary'
=
ppFields
libFieldDescrs
ppExecutable
=
ppFields
executableFieldDescrs
ppPackageDescription
pkg
$+$
ppMaybeLibrary
(
library
pkg
)
$+$
ppSubLibraries
(
subLibraries
pkg
)
$+$
ppExecutables
(
executables
pkg
)
$+$
ppTestSuites
(
testSuites
pkg
)
$+$
ppBenchmarks
(
benchmarks
pkg
)
ppMaybeLibrary
::
Maybe
Library
->
Doc
ppMaybeLibrary
Nothing
=
mempty
ppMaybeLibrary
(
Just
lib
)
=
emptyLine
$
text
"library"
$+$
nest
indentWith
(
ppFields
libFieldDescrs
lib
)
ppSubLibraries
::
[
Library
]
->
Doc
ppSubLibraries
libs
=
vcat
[
emptyLine
$
text
"library"
<+>
text
libname
$+$
nest
indentWith
(
ppFields
libFieldDescrs
lib
)
|
lib
@
Library
{
libName
=
Just
libname
}
<-
libs
]
ppExecutables
::
[
Executable
]
->
Doc
ppExecutables
exes
=
vcat
[
emptyLine
$
text
"executable"
<+>
text
(
exeName
exe
)
$+$
nest
indentWith
(
ppFields
executableFieldDescrs
exe
)
|
exe
<-
exes
]
ppTestSuites
::
[
TestSuite
]
->
Doc
ppTestSuites
tests
=
vcat
[
emptyLine
$
text
"test-suite"
<+>
text
(
testName
test
)
$+$
nest
indentWith
(
ppFields
testSuiteFieldDescrs
test_stanza
)
|
test
<-
tests
,
let
test_stanza
=
TestSuiteStanza
{
testStanzaTestType
=
Just
(
testSuiteInterfaceToTestType
(
testInterface
test
)),
testStanzaMainIs
=
testSuiteInterfaceToMaybeMainIs
(
testInterface
test
),
testStanzaTestModule
=
testSuiteInterfaceToMaybeModule
(
testInterface
test
),
testStanzaBuildInfo
=
testBuildInfo
test
}
]
testSuiteInterfaceToTestType
::
TestSuiteInterface
->
TestType
testSuiteInterfaceToTestType
(
TestSuiteExeV10
ver
_
)
=
TestTypeExe
ver
testSuiteInterfaceToTestType
(
TestSuiteLibV09
ver
_
)
=
TestTypeLib
ver
testSuiteInterfaceToTestType
(
TestSuiteUnsupported
ty
)
=
ty
testSuiteInterfaceToMaybeMainIs
::
TestSuiteInterface
->
Maybe
FilePath
testSuiteInterfaceToMaybeMainIs
(
TestSuiteExeV10
_
fp
)
=
Just
fp
testSuiteInterfaceToMaybeMainIs
TestSuiteLibV09
{}
=
Nothing
testSuiteInterfaceToMaybeMainIs
TestSuiteUnsupported
{}
=
Nothing
testSuiteInterfaceToMaybeModule
::
TestSuiteInterface
->
Maybe
ModuleName
testSuiteInterfaceToMaybeModule
(
TestSuiteLibV09
_
mod_name
)
=
Just
mod_name
testSuiteInterfaceToMaybeModule
TestSuiteExeV10
{}
=
Nothing
testSuiteInterfaceToMaybeModule
TestSuiteUnsupported
{}
=
Nothing
ppBenchmarks
::
[
Benchmark
]
->
Doc
ppBenchmarks
benchs
=
vcat
[
emptyLine
$
text
"benchmark"
<+>
text
(
benchmarkName
bench
)
$+$
nest
indentWith
(
ppFields
benchmarkFieldDescrs
bench_stanza
)
|
bench
<-
benchs
,
let
bench_stanza
=
BenchmarkStanza
{
benchmarkStanzaBenchmarkType
=
Just
(
benchmarkInterfaceToBenchmarkType
(
benchmarkInterface
bench
)),
benchmarkStanzaMainIs
=
benchmarkInterfaceToMaybeMainIs
(
benchmarkInterface
bench
),
benchmarkStanzaBenchmarkModule
=
Nothing
,
benchmarkStanzaBuildInfo
=
benchmarkBuildInfo
bench
}]
benchmarkInterfaceToBenchmarkType
::
BenchmarkInterface
->
BenchmarkType
benchmarkInterfaceToBenchmarkType
(
BenchmarkExeV10
ver
_
)
=
BenchmarkTypeExe
ver
benchmarkInterfaceToBenchmarkType
(
BenchmarkUnsupported
ty
)
=
ty
benchmarkInterfaceToMaybeMainIs
::
BenchmarkInterface
->
Maybe
FilePath
benchmarkInterfaceToMaybeMainIs
(
BenchmarkExeV10
_
fp
)
=
Just
fp
benchmarkInterfaceToMaybeMainIs
BenchmarkUnsupported
{}
=
Nothing
-- | @since 1.26.0.0@
writeHookedBuildInfo
::
FilePath
->
HookedBuildInfo
->
IO
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment