Commit cb31b23d authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺 Committed by Ben Gamari

Update `Cabal` submodule

This also requires adapting `ghc-pkg` to use the new Cabal parsing API
as the old ReadP-based one has finally been evicted for good.

Hadrian bit finished by: Ben Gamari <ben@smart-cactus.org>
parent ce11f6f2
......@@ -451,9 +451,6 @@ PACKAGES_STAGE1 += text
PACKAGES_STAGE1 += transformers
PACKAGES_STAGE1 += mtl
PACKAGES_STAGE1 += parsec
# temporary until Cabal switches to parsec mode by default
libraries/Cabal/Cabal_dist-boot_CONFIGURE_OPTS += --flag parsec
libraries/Cabal/Cabal_dist-install_CONFIGURE_OPTS += --flag parsec
PACKAGES_STAGE1 += Cabal/Cabal
PACKAGES_STAGE1 += ghc-boot-th
PACKAGES_STAGE1 += ghc-boot
......
......@@ -10,10 +10,11 @@ import Settings.Default
import Target
import Utilities
import Distribution.ParseUtils
import Distribution.Version (Version)
import qualified Distribution.Parsec as Cabal
import qualified Distribution.Types.PackageName as Cabal
import qualified Distribution.Types.PackageId as Cabal
import qualified Distribution.Compat.ReadP as Parse
import qualified Hadrian.Haskell.Cabal.Parse as Cabal
import qualified System.Directory as IO
import qualified Text.Parsec as Parsec
......@@ -127,13 +128,14 @@ getPackageNameFromConfFile :: FilePath -> Action String
getPackageNameFromConfFile conf
| takeBaseName conf == "rts" = return "rts"
| otherwise = case parseCabalName (takeBaseName conf) of
Nothing -> error $ "getPackageNameFromConfFile: couldn't parse " ++ conf
Just (name, _) -> return name
Left err -> error $ "getPackageNameFromConfFile: couldn't parse " ++ takeBaseName conf ++ ": " ++ err
Right (name, _) -> return name
parseCabalName :: String -> Maybe (String, Version)
parseCabalName = readPToMaybe parse
parseCabalName :: String -> Either String (String, Version)
parseCabalName = fmap f . Cabal.eitherParsec
where
parse = (,) <$> (parsePackageName <* Parse.char '-') <*> parseOptVersion
f :: Cabal.PackageId -> (String, Version)
f pkg_id = (Cabal.unPackageName $ Cabal.pkgName pkg_id, Cabal.pkgVersion pkg_id)
getPackageByName :: String -> Action Package
getPackageByName n = case findPackageByName n of
......
Subproject commit 064d9e9082c825f538655db1868108c48240377e
Subproject commit b96c601d084e89361ff867a90424d4aef7fa0207
local01.package.conf
(no packages)
Reading package info from "test.pkg" ... done.
name: testpkg
version: 1.2.3.4
id: testpkg-1.2.3.4-XXX
key: testpkg-1.2.3.4-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: stable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description:
A Test Package
category: none
exposed: True
exposed-modules:
A
hidden-modules: B C.D
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-1.2.3.4-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
name: testpkg
version: 1.2.3.4
id: testpkg-1.2.3.4-XXX
key: testpkg-1.2.3.4-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: stable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description: A Test Package
category: none
exposed: True
exposed-modules: A
hidden-modules: B C.D
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-1.2.3.4-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
pkgroot:
name: testpkg
version: 1.2.3.4
id: testpkg-1.2.3.4-XXX
key: testpkg-1.2.3.4-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: stable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description:
A Test Package
category: none
exposed: True
exposed-modules:
A
hidden-modules: B C.D
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-1.2.3.4-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
name: testpkg
version: 1.2.3.4
id: testpkg-1.2.3.4-XXX
key: testpkg-1.2.3.4-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: stable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description: A Test Package
category: none
exposed: True
exposed-modules: A
hidden-modules: B C.D
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-1.2.3.4-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
pkgroot:
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
......@@ -55,74 +51,68 @@ local01.package.conf
testpkg-1.2.3.4
(testpkg-2.0)
name: testpkg
version: 2.0
id: testpkg-2.0-XXX
key: testpkg-2.0-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: unstable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description:
A Test Package (new version)
category: none
exposed-modules:
A
hidden-modules: B C.D C.E
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-2.0-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
name: testpkg
version: 2.0
id: testpkg-2.0-XXX
key: testpkg-2.0-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: unstable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description: A Test Package (new version)
category: none
exposed-modules: A
hidden-modules: B C.D C.E
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-2.0-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
pkgroot:
name: testpkg
version: 2.0
id: testpkg-2.0-XXX
key: testpkg-2.0-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: unstable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description:
A Test Package (new version)
category: none
exposed-modules:
A
hidden-modules: B C.D C.E
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-2.0-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
name: testpkg
version: 2.0
id: testpkg-2.0-XXX
key: testpkg-2.0-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: unstable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description: A Test Package (new version)
category: none
exposed-modules: A
hidden-modules: B C.D C.E
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-2.0-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
pkgroot:
---
name: testpkg
version: 1.2.3.4
id: testpkg-1.2.3.4-XXX
key: testpkg-1.2.3.4-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: stable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description:
A Test Package
category: none
exposed: True
exposed-modules:
A
hidden-modules: B C.D
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-1.2.3.4-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
name: testpkg
version: 1.2.3.4
id: testpkg-1.2.3.4-XXX
key: testpkg-1.2.3.4-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: stable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description: A Test Package
category: none
exposed: True
exposed-modules: A
hidden-modules: B C.D
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-1.2.3.4-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
pkgroot:
version: 2.0
......@@ -132,27 +122,25 @@ exposed: True
exposed: False
exposed: False
Reading package info from "test3.pkg" ... done.
name: testpkg
version: 1.2.3.4
id: testpkg-1.2.3.4-XXX
key: testpkg-1.2.3.4-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: stable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description:
A Test Package
category: none
exposed-modules:
A
hidden-modules: B C.D
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-1.2.3.4-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
name: testpkg
version: 1.2.3.4
id: testpkg-1.2.3.4-XXX
key: testpkg-1.2.3.4-XXX
license: BSD3
copyright: (c) The Univsersity of Glasgow 2004
maintainer: glasgow-haskell-users@haskell.org
author: simonmar@microsoft.com
stability: stable
homepage: http://www.haskell.org/ghc
package-url: http://www.haskell.org/ghc
description: A Test Package
category: none
exposed-modules: A
hidden-modules: B C.D
import-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
library-dirs: /usr/local/lib/testpkg "c:/Program Files/testpkg"
hs-libraries: testpkg-1.2.3.4-XXX
include-dirs: /usr/local/include/testpkg "c:/Program Files/testpkg"
pkgroot:
local01.package.conf
......
Reading package info from "test.pkg" ... done.
exposed-modules:
E, A from testpkg-1.2.3.4-XXX:A, A1 from testpkg-1.2.3.4-XXX:A,
E2 from testpkg7a-1.0-XXX:E
exposed-modules: E, A from testpkg-1.2.3.4-XXX:A,
A1 from testpkg-1.2.3.4-XXX:A, E2 from testpkg7a-1.0-XXX:E
testpkg7b-1.0: module reexport refers to a module A that is reexported but not defined in the defining package testpkg7a-1.0-XXX (ignoring)
testpkg7b-1.0: module reexport refers to a module A1 that is reexported but not defined in the defining package testpkg7a-1.0-XXX (ignoring)
testpkg7b-1.0: module reexport refers to a module E2 that is reexported but not defined in the defining package testpkg7a-1.0-XXX (ignoring)
exposed-modules:
F1 from testpkg-1.2.3.4-XXX:A, F2 from testpkg7a-1.0-XXX:A,
F3 from testpkg7a-1.0-XXX:A1, F4 from testpkg7a-1.0-XXX:E,
E from testpkg7a-1.0-XXX:E, E3 from testpkg7a-1.0-XXX:E2
exposed-modules: F1 from testpkg-1.2.3.4-XXX:A,
F2 from testpkg7a-1.0-XXX:A, F3 from testpkg7a-1.0-XXX:A1,
F4 from testpkg7a-1.0-XXX:E, E from testpkg7a-1.0-XXX:E,
E3 from testpkg7a-1.0-XXX:E2
......@@ -37,15 +37,15 @@ $(ghc-cabal_INPLACE) : $(ghc-cabal_DIST_BINARY) | $$(dir $$@)/.
"$(CP)" $< $@
# Minor hack, since we can't reuse the `hs-suffix-rules-srcdir` macro
ifneq ($(wildcard libraries/Cabal/Cabal/Distribution/Parsec/Lexer.x),)
ifneq ($(wildcard libraries/Cabal/Cabal/Distribution/Fields/Lexer.x),)
# Lexer.x exists so we have to call Alex ourselves
CABAL_LEXER_DEP := bootstrapping/Cabal/Distribution/Parsec/Lexer.hs
CABAL_LEXER_DEP := bootstrapping/Cabal/Distribution/Fields/Lexer.hs
bootstrapping/Cabal/Distribution/Parsec/Lexer.hs: libraries/Cabal/Cabal/Distribution/Parsec/Lexer.x
mkdir -p bootstrapping/Cabal/Distribution/Parsec
bootstrapping/Cabal/Distribution/Fields/Lexer.hs: libraries/Cabal/Cabal/Distribution/Fields/Lexer.x
mkdir -p bootstrapping/Cabal/Distribution/Fields
$(call cmd,ALEX) $< -o $@
else
CABAL_LEXER_DEP := libraries/Cabal/Cabal/Distribution/Parsec/Lexer.hs
CABAL_LEXER_DEP := libraries/Cabal/Cabal/Distribution/Fields/Lexer.hs
endif
$(ghc-cabal_DIST_BINARY): $(wildcard libraries/Cabal/Cabal/Distribution/*/*/*.hs)
......
......@@ -36,13 +36,13 @@ import qualified Data.Graph as Graph
import qualified Distribution.ModuleName as ModuleName
import Distribution.ModuleName (ModuleName)
import Distribution.InstalledPackageInfo as Cabal
import Distribution.Compat.ReadP hiding (get)
import Distribution.ParseUtils
import qualified Distribution.Parsec as Cabal
import Distribution.Package hiding (installedUnitId)
import Distribution.Text
import Distribution.Version
import Distribution.Backpack
import Distribution.Types.UnqualComponentName
import Distribution.Types.LibraryName
import Distribution.Types.MungedPackageName
import Distribution.Types.MungedPackageId
import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS, writeUTF8File, readUTF8File)
......@@ -59,7 +59,7 @@ import System.Console.GetOpt
import qualified Control.Exception as Exception
import Data.Maybe
import Data.Char ( isSpace, toLower )
import Data.Char ( toLower )
import Control.Monad
import System.Directory ( doesDirectoryExist, getDirectoryContents,
doesFileExist, removeFile,
......@@ -501,11 +501,11 @@ runit verbosity cli nonopts = do
(_cmd:_) -> do
die ("command-line syntax error\n" ++ shortUsage prog)
parseCheck :: ReadP a a -> String -> String -> IO a
parseCheck parser str what =
case [ x | (x,ys) <- readP_to_S parser str, all isSpace ys ] of
[x] -> return x
_ -> die ("cannot parse \'" ++ str ++ "\' as a " ++ what)
parseCheck :: Cabal.Parsec a => String -> String -> IO a
parseCheck str what =
case Cabal.eitherParsec str of
Left e -> die ("cannot parse \'" ++ str ++ "\' as a " ++ what ++ ": " ++ e)
Right x -> pure x
-- | Either an exact 'PackageIdentifier', or a glob for all packages
-- matching 'PackageName'.
......@@ -518,20 +518,14 @@ displayGlobPkgId (ExactPackageIdentifier pid) = display pid
displayGlobPkgId (GlobPackageIdentifier pn) = display pn ++ "-*"
readGlobPkgId :: String -> IO GlobPackageIdentifier
readGlobPkgId str = parseCheck parseGlobPackageId str "package identifier"
parseGlobPackageId :: ReadP r GlobPackageIdentifier
parseGlobPackageId =
fmap ExactPackageIdentifier parse
+++
(do n <- parse
_ <- string "-*"
return (GlobPackageIdentifier n))
readGlobPkgId str
| "-*" `isSuffixOf` str =
GlobPackageIdentifier <$> parseCheck (init (init str)) "package identifier (glob)"
| otherwise = ExactPackageIdentifier <$> parseCheck str "package identifier (exact)"
readPackageArg :: AsPackageArg -> String -> IO PackageArg
readPackageArg AsUnitId str =
parseCheck (IUId `fmap` parse) str "installed package id"
readPackageArg AsDefault str = Id `fmap` readGlobPkgId str
readPackageArg AsUnitId str = IUId <$> parseCheck str "installed package id"
readPackageArg AsDefault str = Id <$> readGlobPkgId str
-- -----------------------------------------------------------------------------
-- Package databases
......@@ -1160,13 +1154,11 @@ parsePackageInfo
-> IO (InstalledPackageInfo, [ValidateWarning])
parsePackageInfo str =
case parseInstalledPackageInfo str of
ParseOk warnings ok -> return (mungePackageInfo ok, ws)
Right (warnings, ok) -> pure (mungePackageInfo ok, ws)
where
ws = [ msg | PWarning msg <- warnings
ws = [ msg | msg <- warnings
, not ("Unrecognized field pkgroot" `isPrefixOf` msg) ]
ParseFailed err -> case locatedErrorMsg err of
(Nothing, s) -> die s
(Just l, s) -> die (show l ++ ": " ++ s)
Left err -> die (unlines err)
mungePackageInfo :: InstalledPackageInfo -> InstalledPackageInfo
mungePackageInfo ipi = ipi
......@@ -1352,7 +1344,7 @@ convertPackageInfoToCacheFormat pkg =
GhcPkg.packageName = packageName pkg,
GhcPkg.packageVersion = Version.Version (versionNumbers (packageVersion pkg)) [],
GhcPkg.sourceLibName =
fmap (mkPackageName . unUnqualComponentName) (sourceLibName pkg),
fmap (mkPackageName . unUnqualComponentName) (libraryNameString $ sourceLibName pkg),
GhcPkg.depends = depends pkg,
GhcPkg.abiDepends = map (\(AbiDependency k v) -> (k,unAbiHash v)) (abiDepends pkg),
GhcPkg.abiHash = unAbiHash (abiHash pkg),
......@@ -1902,10 +1894,9 @@ checkPackageConfig pkg verbosity db_stack
checkPackageId :: InstalledPackageInfo -> Validate ()
checkPackageId ipi =
let str = display (mungedId ipi) in
case [ x :: MungedPackageId | (x,ys) <- readP_to_S parse str, all isSpace ys ] of
[_] -> return ()
[] -> verror CannotForce ("invalid package identifier: " ++ str)
_ -> verror CannotForce ("ambiguous package identifier: " ++ str)
case Cabal.eitherParsec str :: Either String MungedPackageId of
Left e -> verror CannotForce ("invalid package identifier: '" ++ str ++ "': " ++ e)
Right _ -> pure ()
checkUnitId :: InstalledPackageInfo -> PackageDBStack -> Bool
-> Validate ()
......
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