diff options
author | Simon Marlow <marlowsd@gmail.com> | 2009-09-10 10:27:03 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2009-09-10 10:27:03 +0000 |
commit | 930421d4ed09e5389e0ef4c5eef36075a6809cc0 (patch) | |
tree | f9f795c8b46a93a99f3a7495f6304f00fa42a2fb /compiler/main/Packages.lhs | |
parent | 5364ea8bd2086d3ce973988d583e3b4585d37b4d (diff) | |
download | haskell-930421d4ed09e5389e0ef4c5eef36075a6809cc0.tar.gz |
Change the representation of the package database
- the package DB is a directory containing one file per package
instance (#723)
- there is a binary cache of the database (#593, #2089)
- the binary package is now a boot package
- there is a new package, bin-package-db, containing the Binary
instance of InstalledPackageInfo for the binary cache.
Also included in this patch
- Use colour in 'ghc-pkg list' to indicate broken or hidden packages
Broken packages are red, hidden packages are
Colour support comes from the terminfo package, and is only used when
- not --simple-output
- stdout is a TTY
- the terminal type has colour capability
- Fix the bug that 'ghc-pkg list --user' shows everything as broken
Diffstat (limited to 'compiler/main/Packages.lhs')
-rw-r--r-- | compiler/main/Packages.lhs | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/compiler/main/Packages.lhs b/compiler/main/Packages.lhs index 2e91ac8ade..0cfd00f9ff 100644 --- a/compiler/main/Packages.lhs +++ b/compiler/main/Packages.lhs @@ -51,6 +51,7 @@ import Maybes import System.Environment ( getEnv ) import Distribution.InstalledPackageInfo +import Distribution.InstalledPackageInfo.Binary import Distribution.Package hiding (PackageId,depends) import FastString import ErrUtils ( debugTraceMsg, putMsg, Message ) @@ -204,44 +205,40 @@ getSystemPackageConfigs dflags = do -- System one always comes first let system_pkgconf = systemPackageConfig dflags - -- allow package.conf.d to contain a bunch of .conf files - -- containing package specifications. This is an easier way - -- to maintain the package database on systems with a package - -- management system, or systems that don't want to run ghc-pkg - -- to register or unregister packages. Undocumented feature for now. - let system_pkgconf_dir = system_pkgconf <.> "d" - system_pkgconf_dir_exists <- doesDirectoryExist system_pkgconf_dir - system_pkgconfs <- - if system_pkgconf_dir_exists - then do files <- getDirectoryContents system_pkgconf_dir - return [ system_pkgconf_dir </> file - | file <- files - , takeExtension file == ".conf" ] - else return [] - -- Read user's package conf (eg. ~/.ghc/i386-linux-6.3/package.conf) -- unless the -no-user-package-conf flag was given. - -- We only do this when getAppUserDataDirectory is available - -- (GHC >= 6.3). user_pkgconf <- do + if not (dopt Opt_ReadUserPackageConf dflags) then return [] else do appdir <- getAppUserDataDirectory "ghc" let - pkgconf = appdir - </> (TARGET_ARCH ++ '-':TARGET_OS ++ '-':cProjectVersion) - </> "package.conf" - flg <- doesFileExist pkgconf - if (flg && dopt Opt_ReadUserPackageConf dflags) - then return [pkgconf] - else return [] + dir = appdir </> (TARGET_ARCH ++ '-':TARGET_OS ++ '-':cProjectVersion) + pkgconf = dir </> "package.conf.d" + -- + exist <- doesDirectoryExist pkgconf + if exist then return [pkgconf] else return [] `catchIO` (\_ -> return []) - return (user_pkgconf ++ system_pkgconfs ++ [system_pkgconf]) - + return (user_pkgconf ++ [system_pkgconf]) readPackageConfig :: DynFlags -> FilePath -> IO [PackageConfig] readPackageConfig dflags conf_file = do - debugTraceMsg dflags 2 (text "Using package config file:" <+> text conf_file) - proto_pkg_configs <- loadPackageConfig dflags conf_file + isdir <- doesDirectoryExist conf_file + + proto_pkg_configs <- + if isdir + then do let filename = conf_file </> "package.cache" + debugTraceMsg dflags 2 (text "Using binary package database:" <+> text filename) + conf <- readBinPackageDB filename + return (map installedPackageInfoToPackageConfig conf) + + else do + isfile <- doesFileExist conf_file + when (not isfile) $ + ghcError $ InstallationError $ + "can't find a package database at " ++ conf_file + debugTraceMsg dflags 2 (text "Using package config file:" <+> text conf_file) + loadPackageConfig dflags conf_file + let top_dir = topDir dflags pkg_configs1 = mungePackagePaths top_dir proto_pkg_configs |