[commit: ghc] wip/nfs-locking: Switch to computing package version only through the Cabal library (4ce8587)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:40:25 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/4ce85874126d7356b6c442e45c593797283f7108/ghc

>---------------------------------------------------------------

commit 4ce85874126d7356b6c442e45c593797283f7108
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Sun Aug 20 17:05:30 2017 +0100

    Switch to computing package version only through the Cabal library


>---------------------------------------------------------------

4ce85874126d7356b6c442e45c593797283f7108
 src/Hadrian/Haskell/Cabal.hs      | 36 ++++++++++++++++++++++--------------
 src/Oracles/PackageData.hs        |  2 --
 src/Rules/Data.hs                 |  2 --
 src/Settings/Builders/GhcCabal.hs |  4 ++--
 src/Settings/Builders/Haddock.hs  |  6 +++---
 src/Settings/Packages/GhcCabal.hs |  4 ++--
 6 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/Hadrian/Haskell/Cabal.hs b/src/Hadrian/Haskell/Cabal.hs
index 02fcd82..23cfdc7 100644
--- a/src/Hadrian/Haskell/Cabal.hs
+++ b/src/Hadrian/Haskell/Cabal.hs
@@ -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 at . If the @.cabal@ file does not exist return just the
+-- package name, e.g. @rts at . 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
diff --git a/src/Oracles/PackageData.hs b/src/Oracles/PackageData.hs
index 991caf1..7d98c98 100644
--- a/src/Oracles/PackageData.hs
+++ b/src/Oracles/PackageData.hs
@@ -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 ... at .
diff --git a/src/Rules/Data.hs b/src/Rules/Data.hs
index ef2f017..194bf62 100644
--- a/src/Rules/Data.hs
+++ b/src/Rules/Data.hs
@@ -61,9 +61,7 @@ generatePackageData context at 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                                  ] ++
diff --git a/src/Settings/Builders/GhcCabal.hs b/src/Settings/Builders/GhcCabal.hs
index ba1de93..cf6bcb3 100644
--- a/src/Settings/Builders/GhcCabal.hs
+++ b/src/Settings/Builders/GhcCabal.hs
@@ -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
diff --git a/src/Settings/Builders/Haddock.hs b/src/Settings/Builders/Haddock.hs
index 7319f80..bc3ebf4 100644
--- a/src/Settings/Builders/Haddock.hs
+++ b/src/Settings/Builders/Haddock.hs
@@ -1,6 +1,7 @@
 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
diff --git a/src/Settings/Packages/GhcCabal.hs b/src/Settings/Packages/GhcCabal.hs
index 0a0fe15..3c07c67 100644
--- a/src/Settings/Packages/GhcCabal.hs
+++ b/src/Settings/Packages/GhcCabal.hs
@@ -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"



More information about the ghc-commits mailing list