Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
4a46d14e
Commit
4a46d14e
authored
Aug 16, 2017
by
Andrey Mokhov
Browse files
Factor out cabal parsing functionality into the library
See
#347
parent
8fc676e4
Changes
4
Hide whitespace changes
Inline
Side-by-side
hadrian.cabal
View file @
4a46d14e
...
...
@@ -27,6 +27,7 @@ executable hadrian
, Flavour
, GHC
, Hadrian.Expression
, Hadrian.Haskell.Cabal
, Hadrian.Oracles.ArgsHash
, Hadrian.Oracles.DirectoryContents
, Hadrian.Oracles.KeyValue
...
...
src/Hadrian/Haskell/Cabal.hs
0 → 100644
View file @
4a46d14e
module
Hadrian.Haskell.Cabal
(
readCabal
,
cabalNameVersion
,
cabalDependencies
)
where
import
Development.Shake
import
Distribution.Package
import
Distribution.PackageDescription
import
Distribution.PackageDescription.Parse
import
Distribution.Text
import
Distribution.Types.CondTree
import
Distribution.Verbosity
-- TODO: Track the values?
-- | Read a given @.cabal@ file and return the 'GenericPackageDescription'.
readCabal
::
FilePath
->
Action
GenericPackageDescription
readCabal
cabal
=
do
need
[
cabal
]
liftIO
$
readGenericPackageDescription
silent
cabal
-- | Read a given @.cabal@ file and return the package name and version.
cabalNameVersion
::
FilePath
->
Action
(
String
,
String
)
cabalNameVersion
cabal
=
do
identifier
<-
package
.
packageDescription
<$>
readCabal
cabal
return
(
unPackageName
$
pkgName
identifier
,
display
$
pkgVersion
identifier
)
-- | Read a given @.cabal@ file and return the package dependencies.
cabalDependencies
::
FilePath
->
Action
[
String
]
cabalDependencies
cabal
=
do
gpd
<-
readCabal
cabal
let
depsLib
=
collectDeps
$
condLibrary
gpd
depsExes
=
map
(
collectDeps
.
Just
.
snd
)
$
condExecutables
gpd
deps
=
concat
$
depsLib
:
depsExes
return
$
[
unPackageName
name
|
Dependency
name
_
<-
deps
]
collectDeps
::
Maybe
(
CondTree
v
[
Dependency
]
a
)
->
[
Dependency
]
collectDeps
Nothing
=
[]
collectDeps
(
Just
(
CondNode
_
deps
ifs
))
=
deps
++
concatMap
f
ifs
where
f
(
CondBranch
_
t
mt
)
=
collectDeps
(
Just
t
)
++
collectDeps
mt
src/Rules/Cabal.hs
View file @
4a46d14e
module
Rules.Cabal
(
cabalRules
)
where
import
Distribution.Package
as
DP
import
Distribution.PackageDescription
import
Distribution.PackageDescription.Parse
import
Distribution.Text
import
Distribution.Types.CondTree
import
Distribution.Verbosity
import
Hadrian.Haskell.Cabal
import
Base
import
GHC
...
...
@@ -18,32 +13,18 @@ cabalRules = do
bootPkgs
<-
stagePackages
Stage0
let
pkgs
=
filter
(
\
p
->
p
/=
compiler
&&
isLibrary
p
)
bootPkgs
constraints
<-
forM
(
sort
pkgs
)
$
\
pkg
->
do
need
[
pkgCabalFile
pkg
]
pd
<-
liftIO
.
readGenericPackageDescription
silent
$
pkgCabalFile
pkg
let
identifier
=
package
.
packageDescription
$
pd
version
=
display
.
pkgVersion
$
identifier
return
$
unPackageName
(
DP
.
pkgName
identifier
)
++
" == "
++
version
(
name
,
version
)
<-
cabalNameVersion
(
pkgCabalFile
pkg
)
return
$
name
++
" == "
++
version
writeFileChanged
out
.
unlines
$
constraints
putSuccess
$
"| Successfully generated boot package constraints"
-- Cache package dependencies.
"//"
-/-
packageDependencies
%>
\
out
->
do
pkgDeps
<-
forM
(
sort
knownPackages
)
$
\
pkg
->
do
exists
<-
doesFileExist
$
pkgCabalFile
pkg
exists
<-
doesFileExist
(
pkgCabalFile
pkg
)
if
not
exists
then
return
$
pkgNameString
pkg
else
do
need
[
pkgCabalFile
pkg
]
pd
<-
liftIO
.
readGenericPackageDescription
silent
$
pkgCabalFile
pkg
let
depsLib
=
collectDeps
$
condLibrary
pd
depsExes
=
map
(
collectDeps
.
Just
.
snd
)
$
condExecutables
pd
deps
=
concat
$
depsLib
:
depsExes
depNames
=
[
unPackageName
name
|
Dependency
name
_
<-
deps
]
return
.
unwords
$
pkgNameString
pkg
:
(
sort
depNames
\\
[
pkgNameString
pkg
])
deps
<-
sort
<$>
cabalDependencies
(
pkgCabalFile
pkg
)
return
.
unwords
$
pkgNameString
pkg
:
(
deps
\\
[
pkgNameString
pkg
])
writeFileChanged
out
$
unlines
pkgDeps
putSuccess
$
"| Successfully generated package dependencies"
collectDeps
::
Maybe
(
CondTree
v
[
Dependency
]
a
)
->
[
Dependency
]
collectDeps
Nothing
=
[]
collectDeps
(
Just
(
CondNode
_
deps
ifs
))
=
deps
++
concatMap
f
ifs
where
f
(
CondBranch
_
t
mt
)
=
collectDeps
(
Just
t
)
++
collectDeps
mt
src/Settings/Packages/GhcCabal.hs
View file @
4a46d14e
module
Settings.Packages.GhcCabal
(
ghcCabalPackageArgs
)
where
import
Distribution.Package
(
pkgVersion
)
import
Distribution.PackageDescription
(
packageDescription
)
import
Distribution.PackageDescription.Parse
import
qualified
Distribution.PackageDescription
as
DP
import
Distribution.Text
(
display
)
import
Distribution.Verbosity
(
silent
)
import
Hadrian.Haskell.Cabal
import
Base
import
Expression
...
...
@@ -15,11 +10,7 @@ import Utilities
ghcCabalPackageArgs
::
Args
ghcCabalPackageArgs
=
stage0
?
package
ghcCabal
?
builder
Ghc
?
do
cabalDeps
<-
expr
$
pkgDependencies
cabal
expr
$
need
[
pkgCabalFile
cabal
]
pd
<-
exprIO
.
readGenericPackageDescription
silent
$
pkgCabalFile
cabal
let
identifier
=
DP
.
package
.
packageDescription
$
pd
cabalVersion
=
display
.
pkgVersion
$
identifier
(
_
,
cabalVersion
)
<-
expr
$
cabalNameVersion
(
pkgCabalFile
cabal
)
mconcat
[
pure
[
"-package "
++
pkgNameString
pkg
|
pkg
<-
cabalDeps
]
,
arg
"--make"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment