X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FPackages.lhs;h=41a760af3671e61351c6a7430fec887909193e38;hb=a11bb49b97eaba892730baf1565e922715dbc07f;hp=a7c01aef6adcfd5a6f79cd5278484d28021c48bd;hpb=c245355e6f2c7b7c95e9af910c4d420e13af9413;p=ghc-hetmet.git diff --git a/compiler/main/Packages.lhs b/compiler/main/Packages.lhs index a7c01ae..41a760a 100644 --- a/compiler/main/Packages.lhs +++ b/compiler/main/Packages.lhs @@ -47,8 +47,8 @@ import Panic import Outputable import System.Environment ( getEnv ) -import Distribution.InstalledPackageInfo -import Distribution.Package +import Distribution.InstalledPackageInfo hiding (depends) +import Distribution.Package hiding (depends) import Distribution.Version import FastString import ErrUtils ( debugTraceMsg, putMsg, Message ) @@ -231,7 +231,7 @@ readPackageConfig :: DynFlags -> PackageConfigMap -> FilePath -> IO PackageConfigMap readPackageConfig dflags pkg_map conf_file = do debugTraceMsg dflags 2 (text "Using package config file:" <+> text conf_file) - proto_pkg_configs <- loadPackageConfig conf_file + proto_pkg_configs <- loadPackageConfig dflags conf_file let top_dir = topDir dflags pkg_configs1 = mungePackagePaths top_dir proto_pkg_configs pkg_configs2 = maybeHidePackages dflags pkg_configs1 @@ -317,8 +317,8 @@ matchingPackages str pkgs -- A package named on the command line can either include the -- version, or just the name if it is unambiguous. matches str p - = str == showPackageId (package p) - || str == pkgName (package p) + = str == display (package p) + || str == display (pkgName (package p)) pickPackages :: [PackageConfig] -> [String] -> [PackageConfig] pickPackages pkgs strs = @@ -345,10 +345,10 @@ hideOldPackages dflags pkgs = mapM maybe_hide pkgs | not (exposed p) = return p | (p' : _) <- later_versions = do debugTraceMsg dflags 2 $ - (ptext SLIT("hiding package") <+> - text (showPackageId (package p)) <+> - ptext SLIT("to avoid conflict with later version") <+> - text (showPackageId (package p'))) + (ptext (sLit "hiding package") <+> + text (display (package p)) <+> + ptext (sLit "to avoid conflict with later version") <+> + text (display (package p'))) return (p {exposed=False}) | otherwise = return p where myname = pkgName (package p) @@ -376,15 +376,19 @@ findWiredInPackages dflags pkgs preload this_package = do -- their canonical names (eg. base-1.0 ==> base). -- let - wired_in_pkgids = [ primPackageId, - integerPackageId, - basePackageId, - rtsPackageId, - haskell98PackageId, - thPackageId, - ndpPackageId ] - - wired_in_names = map packageIdString wired_in_pkgids + wired_in_pkgids :: [(PackageId, [String])] + wired_in_pkgids = [ (primPackageId, [""]), + (integerPackageId, [""]), + (basePackageId, [""]), + (rtsPackageId, [""]), + (haskell98PackageId, [""]), + (thPackageId, [""]), + (ndpPackageId, ["-seq", "-par"]) ] + + matches :: PackageConfig -> (PackageId, [String]) -> Bool + pc `matches` (pid, suffixes) + = display (pkgName (package pc)) `elem` + (map (packageIdString pid ++) suffixes) -- find which package corresponds to each wired-in package -- delete any other packages with the same name @@ -396,46 +400,53 @@ findWiredInPackages dflags pkgs preload this_package = do -- version. To override the default choice, -hide-package -- could be used to hide newer versions. -- - findWiredInPackage :: [PackageConfig] -> String - -> IO (Maybe PackageIdentifier) + findWiredInPackage :: [PackageConfig] -> (PackageId, [String]) + -> IO (Maybe (PackageIdentifier, PackageId)) findWiredInPackage pkgs wired_pkg = - let all_ps = [ p | p <- pkgs, pkgName (package p) == wired_pkg ] in + let all_ps = [ p | p <- pkgs, p `matches` wired_pkg ] in case filter exposed all_ps of [] -> case all_ps of [] -> notfound many -> pick (head (sortByVersion many)) many -> pick (head (sortByVersion many)) where + suffixes = snd wired_pkg notfound = do debugTraceMsg dflags 2 $ - ptext SLIT("wired-in package ") - <> text wired_pkg - <> ptext SLIT(" not found.") + ptext (sLit "wired-in package ") + <> ppr (fst wired_pkg) + <> (if null suffixes + then empty + else text (show suffixes)) + <> ptext (sLit " not found.") return Nothing + pick :: InstalledPackageInfo_ ModuleName + -> IO (Maybe (PackageIdentifier, PackageId)) pick pkg = do debugTraceMsg dflags 2 $ - ptext SLIT("wired-in package ") - <> text wired_pkg - <> ptext SLIT(" mapped to ") - <> text (showPackageId (package pkg)) - return (Just (package pkg)) + ptext (sLit "wired-in package ") + <> ppr (fst wired_pkg) + <> ptext (sLit " mapped to ") + <> text (display (package pkg)) + return (Just (package pkg, fst wired_pkg)) - mb_wired_in_ids <- mapM (findWiredInPackage pkgs) wired_in_names + mb_wired_in_ids <- mapM (findWiredInPackage pkgs) wired_in_pkgids let wired_in_ids = catMaybes mb_wired_in_ids - deleteOtherWiredInPackages pkgs = filter ok pkgs - where ok p = pkgName (package p) `notElem` wired_in_names - || package p `elem` wired_in_ids + deleteOtherWiredInPackages pkgs = filterOut bad pkgs + where bad p = any (p `matches`) wired_in_pkgids + && package p `notElem` map fst wired_in_ids updateWiredInDependencies pkgs = map upd_pkg pkgs where upd_pkg p = p{ package = upd_pid (package p), depends = map upd_pid (depends p) } - upd_pid pid = case filter (== pid) wired_in_ids of + upd_pid pid = case filter ((== pid) . fst) wired_in_ids of [] -> pid - (x:_) -> x{ pkgVersion = Version [] [] } + ((x, y):_) -> x{ pkgName = PackageName (packageIdString y), + pkgVersion = Version [] [] } pkgs1 = deleteOtherWiredInPackages pkgs @@ -483,9 +494,9 @@ elimDanglingDeps dflags pkgs ignored = go [] pkgs' reportElim (p, deps) = debugTraceMsg dflags 2 $ - (ptext SLIT("package") <+> pprPkg p <+> - ptext SLIT("will be ignored due to missing or recursive dependencies:") $$ - nest 2 (hsep (map (text.showPackageId) deps))) + (ptext (sLit "package") <+> pprPkg p <+> + ptext (sLit "will be ignored due to missing or recursive dependencies:") $$ + nest 2 (hsep (map (text.display) deps))) -- ----------------------------------------------------------------------------- -- When all the command-line options are in, we can process our package @@ -574,7 +585,7 @@ mkModuleMap pkg_db = foldr extend_modmap emptyUFM pkgids hidden_mods = hiddenModules pkg pprPkg :: PackageConfig -> SDoc -pprPkg p = text (showPackageId (package p)) +pprPkg p = text (display (package p)) -- ----------------------------------------------------------------------------- -- Extracting information from the packages in scope @@ -689,12 +700,12 @@ missingPackageErr :: String -> IO [PackageConfig] missingPackageErr p = throwDyn (CmdLineError (showSDoc (missingPackageMsg p))) missingPackageMsg :: String -> SDoc -missingPackageMsg p = ptext SLIT("unknown package:") <+> text p +missingPackageMsg p = ptext (sLit "unknown package:") <+> text p missingDependencyMsg :: Maybe PackageId -> SDoc missingDependencyMsg Nothing = empty missingDependencyMsg (Just parent) - = space <> parens (ptext SLIT("dependency of") <+> ftext (packageIdFS parent)) + = space <> parens (ptext (sLit "dependency of") <+> ftext (packageIdFS parent)) -- ----------------------------------------------------------------------------- @@ -714,8 +725,8 @@ dumpPackages dflags putMsg dflags $ vcat (map (text.showInstalledPackageInfo.to_ipi) (eltsUFM pkg_map)) where - to_ipi pkgconf@InstalledPackageInfo_{ exposedModules = e, - hiddenModules = h } = + to_ipi pkgconf@(InstalledPackageInfo { exposedModules = e, + hiddenModules = h }) = pkgconf{ exposedModules = map moduleNameString e, hiddenModules = map moduleNameString h } \end{code}