From 536eaecd1071cfd25e0384b10ed9b72f98b21f46 Mon Sep 17 00:00:00 2001 From: "claus.reinke@talk21.com" Date: Fri, 9 Nov 2007 16:26:52 +0000 Subject: [PATCH] FIX 1463 (implement 'ghc-pkg find-module') - the ticket asks for a module2package lookup in ghc-pkg (this would be useful to have in cabal, as well) - we can now ask which packages expose a module we need, eg, when preparing a cabal file or when getting errors after package reorganisations: $ ./ghc-pkg-inplace find-module Var c:/fptools/ghc/driver/package.conf.inplace: (ghc-6.9.20071106) $ ./ghc-pkg-inplace find-module Data.Sequence c:/fptools/ghc/driver/package.conf.inplace: containers-0.1 - implemented as a minor variation on listPackages (as usual, it would be useful if one could combine multiple queries into one) --- utils/ghc-pkg/Main.hs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs index e0bae2f..1d26208 100644 --- a/utils/ghc-pkg/Main.hs +++ b/utils/ghc-pkg/Main.hs @@ -224,10 +224,12 @@ runit cli nonopts = do pkgid <- readGlobPkgId pkgid_str hidePackage pkgid cli ["list"] -> do - listPackages cli Nothing + listPackages cli Nothing Nothing ["list", pkgid_str] -> do pkgid <- readGlobPkgId pkgid_str - listPackages cli (Just pkgid) + listPackages cli (Just pkgid) Nothing + ["find-module", moduleName] -> do + listPackages cli Nothing (Just moduleName) ["latest", pkgid_str] -> do pkgid <- readGlobPkgId pkgid_str latestPackage cli pkgid @@ -461,14 +463,17 @@ modifyPackage fn pkgid flags = do -- ----------------------------------------------------------------------------- -- Listing packages -listPackages :: [Flag] -> Maybe PackageIdentifier -> IO () -listPackages flags mPackageName = do +listPackages :: [Flag] -> Maybe PackageIdentifier -> Maybe String -> IO () +listPackages flags mPackageName mModuleName = do let simple_output = FlagSimpleOutput `elem` flags db_stack <- getPkgDatabases False flags let db_stack_filtered -- if a package is given, filter out all other packages | Just this <- mPackageName = map (\(conf,pkgs) -> (conf, filter (this `matchesPkg`) pkgs)) db_stack + | Just this <- mModuleName = -- packages which expose mModuleName + map (\(conf,pkgs) -> (conf, filter (this `exposedInPkg`) pkgs)) + db_stack | otherwise = db_stack db_stack_sorted @@ -546,6 +551,9 @@ pid `matchesPkg` pkg = pid `matches` package pkg compPkgIdVer :: PackageIdentifier -> PackageIdentifier -> Ordering compPkgIdVer p1 p2 = pkgVersion p1 `compare` pkgVersion p2 +exposedInPkg :: String -> InstalledPackageInfo -> Bool +moduleName `exposedInPkg` pkg = moduleName `elem` exposedModules pkg + -- ----------------------------------------------------------------------------- -- Field @@ -959,8 +967,8 @@ oldRunit clis = do defines = [ (nm,val) | OF_DefinedName nm val <- clis ] case [ c | c <- clis, isAction c ] of - [ OF_List ] -> listPackages new_flags Nothing - [ OF_ListLocal ] -> listPackages new_flags Nothing + [ OF_List ] -> listPackages new_flags Nothing Nothing + [ OF_ListLocal ] -> listPackages new_flags Nothing Nothing [ OF_Add upd ] -> registerPackage input_file defines new_flags auto_ghci_libs upd force [ OF_Remove pkgid_str ] -> do -- 1.7.10.4