Commit 4ce85874 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Switch to computing package version only through the Cabal library

parent acd5c375
......@@ -10,35 +10,43 @@
-- @.cabal@ files.
-----------------------------------------------------------------------------
module Hadrian.Haskell.Cabal (
pkgNameVersion, pkgIdentifier, pkgDependencies
pkgVersion, pkgIdentifier, pkgDependencies
) where
import Control.Monad
import Development.Shake
import Hadrian.Haskell.Cabal.Parse
import Hadrian.Haskell.Package
import Hadrian.Oracles.TextFile
import Hadrian.Utilities
-- | Read the @.cabal@ file of a given package and return the package name and
-- version. The @.cabal@ file is tracked.
pkgNameVersion :: Package -> Action (PackageName, String)
pkgNameVersion pkg = do
-- | Read the @.cabal@ file of a given package and return the package version.
-- The @.cabal@ file is tracked.
pkgVersion :: Package -> Action String
pkgVersion pkg = do
cabal <- readCabalFile (pkgCabalFile pkg)
return (name cabal, version cabal)
return (version cabal)
-- | Read the @.cabal@ file of a given package and return the package identifier.
-- If the @.cabal@ file does not exist return the package name. If the @.cabal@
-- file exists it is tracked.
-- | Read the @.cabal@ file of a given package and return the package identifier,
-- e.g. @base-4.10.0.0@. If the @.cabal@ file does not exist return just the
-- package name, e.g. @rts@. If the @.cabal@ file exists then it is tracked, and
-- furthermore we check that the recorded package name matches the name of the
-- package passed as the parameter and raise an error otherwise.
pkgIdentifier :: Package -> Action String
pkgIdentifier pkg = do
cabalExists <- doesFileExist (pkgCabalFile pkg)
if cabalExists
then do
if not cabalExists
then return (pkgName pkg)
else do
cabal <- readCabalFile (pkgCabalFile pkg)
when (pkgName pkg /= name cabal) $
error $ "[Hadrian.Haskell.Cabal] Inconsistent package name: expected "
++ quote (pkgName pkg) ++ ", but " ++ quote (pkgCabalFile pkg)
++ " specifies " ++ quote (name cabal) ++ "."
return $ if (null $ version cabal)
then name cabal
else name cabal ++ "-" ++ version cabal
else return (pkgName pkg)
then pkgName pkg
else pkgName pkg ++ "-" ++ version cabal
-- | Read the @.cabal@ file of a given package and return the sorted list of its
-- dependencies. The current version does not take care of Cabal conditionals
......
......@@ -8,7 +8,6 @@ import Base
data PackageData = BuildGhciLib FilePath
| Synopsis FilePath
| Version FilePath
data PackageDataList = AsmSrcs FilePath
| CcArgs FilePath
......@@ -40,7 +39,6 @@ pkgData :: PackageData -> Action String
pkgData packageData = case packageData of
BuildGhciLib path -> askPackageData path "BUILD_GHCI_LIB"
Synopsis path -> askPackageData path "SYNOPSIS"
Version path -> askPackageData path "VERSION"
-- | @PackageDataList path@ is used for multiple string options separated by
-- spaces, such as @path_MODULES = Data.Array Data.Array.Base ...@.
......
......@@ -61,9 +61,7 @@ generatePackageData context@Context {..} file = do
cSrcs <- packageCSources package
cmmSrcs <- packageCmmSources package
genPath <- buildRoot <&> (-/- generatedDir)
let pkgKey = if isLibrary package then "COMPONENT_ID = " else "PROGNAME = "
writeFileChanged file . unlines $
[ pkgKey ++ pkgName package ] ++
[ "S_SRCS = " ++ unwords asmSrcs ] ++
[ "C_SRCS = " ++ unwords cSrcs ] ++
[ "CMM_SRCS = " ++ unwords cmmSrcs ] ++
......
......@@ -95,8 +95,8 @@ bootPackageConstraints = stage0 ? do
bootPkgs <- expr $ stagePackages Stage0
let pkgs = filter (\p -> p /= compiler && isLibrary p) bootPkgs
constraints <- expr $ forM (sort pkgs) $ \pkg -> do
(name, version) <- pkgNameVersion pkg
return (name ++ " == " ++ version)
version <- pkgVersion pkg
return (pkgName pkg ++ " == " ++ version)
pure $ concat [ ["--constraint", c] | c <- constraints ]
cppArgs :: Args
......
module Settings.Builders.Haddock (haddockBuilderArgs) where
import Hadrian.Utilities
import Hadrian.Haskell.Cabal
import Rules.Documentation
import Settings.Builders.Common
......@@ -17,12 +18,11 @@ haddockBuilderArgs = builder Haddock ? do
output <- getOutput
pkg <- getPackage
path <- getBuildPath
version <- getPkgData Version
version <- expr $ pkgVersion pkg
synopsis <- getPkgData Synopsis
deps <- getPkgDataList Deps
haddocks <- expr . haddockDependencies =<< getContext
progPath <- expr $ buildPath (vanillaContext Stage2 haddock)
hVersion <- expr $ pkgData (Version progPath)
hVersion <- expr $ pkgVersion haddock
ghcOpts <- haddockGhcArgs
mconcat
[ arg $ "--odir=" ++ takeDirectory output
......
......@@ -9,8 +9,8 @@ import Utilities
ghcCabalPackageArgs :: Args
ghcCabalPackageArgs = stage0 ? package ghcCabal ? builder Ghc ? do
cabalDeps <- expr $ stage1Dependencies cabal
(_, cabalVersion) <- expr $ pkgNameVersion cabal
cabalDeps <- expr $ stage1Dependencies cabal
cabalVersion <- expr $ pkgVersion cabal
mconcat
[ pure [ "-package " ++ pkgName pkg | pkg <- cabalDeps, pkg /= parsec ]
, arg "--make"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment