-packageConfigId = mkPackageId . package
-
-unpackPackageId :: PackageId -> Maybe PackageIdentifier
-unpackPackageId p
- = case [ pid | (pid,"") <- readP_to_S parsePackageId str ] of
- [] -> Nothing
- (pid:_) -> Just pid
- where str = packageIdString p
+packageConfigId = mkPackageId . sourcePackageId
+
+-- | Turn a 'PackageConfig', which contains GHC 'Module.ModuleName's into a Cabal specific
+-- 'InstalledPackageInfo' which contains Cabal 'Distribution.ModuleName.ModuleName's
+packageConfigToInstalledPackageInfo :: PackageConfig -> InstalledPackageInfo
+packageConfigToInstalledPackageInfo
+ (pkgconf@(InstalledPackageInfo { exposedModules = e,
+ hiddenModules = h })) =
+ pkgconf{ exposedModules = map convert e,
+ hiddenModules = map convert h }
+ where convert :: Module.ModuleName -> Distribution.ModuleName.ModuleName
+ convert = (expectJust "packageConfigToInstalledPackageInfo") . simpleParse . moduleNameString
+
+-- | Turn an 'InstalledPackageInfo', which contains Cabal 'Distribution.ModuleName.ModuleName's
+-- into a GHC specific 'PackageConfig' which contains GHC 'Module.ModuleName's
+installedPackageInfoToPackageConfig :: InstalledPackageInfo_ String -> PackageConfig
+installedPackageInfoToPackageConfig
+ (pkgconf@(InstalledPackageInfo { exposedModules = e,
+ hiddenModules = h })) =
+ pkgconf{ exposedModules = map mkModuleName e,
+ hiddenModules = map mkModuleName h }