diff options
author | Duncan Coutts <duncan@well-typed.com> | 2015-02-09 13:46:06 -0600 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2015-02-09 21:07:26 -0600 |
commit | a1db53cc6ea03d80f097c550bae277141b03ac30 (patch) | |
tree | 494961cd3fa846354040561f7d40bbd9672ede90 /compiler/main | |
parent | de9a836cd920722a4c28dcb464ff2c8d5905acb9 (diff) | |
download | haskell-a1db53cc6ea03d80f097c550bae277141b03ac30.tar.gz |
Add a workaround to allow older cabal-install to use ghc-7.10
Summary:
This should smooth the upgrade process for people and help with testing
the 7.10 RCs. Otherwise people need to first install cabal-install-1.22
before they can use 7.10.
The problem is that older cabal still used file-style package dbs for
the inplace package db when building packages. The workaround is that
both ghc and ghc-pkg will notice when cabal tells them to use a file
style db e.g. "dist/package.conf.inplace" and, so long as that db is
empty (ie content is []) then they'll instead us a dir style db with
the same name but ".d" appended, so in this example that would be
"dist/package.conf.inplace.d". We have to use a separate dir rather
than transparently upgrading because old Cabal really assumes the path
is a file, and if it encounters a dir it will fail.
This seems to be enough for older Cabal to work, and may well be enough
for other scripts that create dbs using "echo [] > package.conf".
Test Plan:
validate and check new and old cabal can sucessfully install things,
including packages that have internal deps (ie using the inplace db)
Reviewers: hvr, tibbe, austin
Reviewed By: tibbe, austin
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D628
Diffstat (limited to 'compiler/main')
-rw-r--r-- | compiler/main/Packages.hs | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/compiler/main/Packages.hs b/compiler/main/Packages.hs index 28f2f2d2c3..db48d99bac 100644 --- a/compiler/main/Packages.hs +++ b/compiler/main/Packages.hs @@ -367,13 +367,15 @@ readPackageConfig dflags conf_file = do proto_pkg_configs <- if isdir - then do let filename = conf_file </> "package.cache" - debugTraceMsg dflags 2 (text "Using binary package database:" <+> text filename) - readPackageDbForGhc filename + then readDirStylePackageConfig conf_file else do isfile <- doesFileExist conf_file if isfile - then throwGhcExceptionIO $ InstallationError $ + then do + mpkgs <- tryReadOldFileStylePackageConfig + case mpkgs of + Just pkgs -> return pkgs + Nothing -> throwGhcExceptionIO $ InstallationError $ "ghc no longer supports single-file style package " ++ "databases (" ++ conf_file ++ ") use 'ghc-pkg init' to create the database with " ++ @@ -388,6 +390,31 @@ readPackageConfig dflags conf_file = do pkg_configs2 = setBatchPackageFlags dflags pkg_configs1 -- return pkg_configs2 + where + readDirStylePackageConfig conf_dir = do + let filename = conf_dir </> "package.cache" + debugTraceMsg dflags 2 (text "Using binary package database:" <+> text filename) + readPackageDbForGhc filename + + -- Single-file style package dbs have been deprecated for some time, but + -- it turns out that Cabal was using them in one place. So this is a + -- workaround to allow older Cabal versions to use this newer ghc. + -- We check if the file db contains just "[]" and if so, we look for a new + -- dir-style db in conf_file.d/, ie in a dir next to the given file. + -- We cannot just replace the file with a new dir style since Cabal still + -- assumes it's a file and tries to overwrite with 'writeFile'. + -- ghc-pkg also cooperates with this workaround. + tryReadOldFileStylePackageConfig = do + content <- readFile conf_file `catchIO` \_ -> return "" + if take 2 content == "[]" + then do + let conf_dir = conf_file <.> "d" + direxists <- doesDirectoryExist conf_dir + if direxists + then do debugTraceMsg dflags 2 (text "Ignoring old file-style db and trying:" <+> text conf_dir) + liftM Just (readDirStylePackageConfig conf_dir) + else return (Just []) -- ghc-pkg will create it when it's updated + else return Nothing setBatchPackageFlags :: DynFlags -> [PackageConfig] -> [PackageConfig] setBatchPackageFlags dflags pkgs = maybeDistrustAll pkgs |