2 % (c) The University of Glasgow, 2000
4 \section[CmStaticInfo]{Session-static info for the Compilation Manager}
7 module CmStaticInfo ( Package(..), PCI(..), mkPCI )
10 #include "HsVersions.h"
13 import Char ( isUpper )
14 import Directory ( getDirectoryContents )
16 import Module ( ModuleName, PackageName )
20 data PackageConfigInfo
22 pci_rawinfo :: [Package], -- contents of packages.conf
23 pci_modtable :: [(ModuleName, PackageName, FilePath)]
24 -- maps each available module to pkg and path
27 -- copied from the driver
31 import_dirs :: [String],
32 library_dirs :: [String],
33 hs_libraries :: [String],
34 extra_libraries :: [String],
35 include_dirs :: [String],
36 c_includes :: [String],
37 package_deps :: [String],
38 extra_ghc_opts :: [String],
39 extra_cc_opts :: [String],
40 extra_ld_opts :: [String]
44 mkPCI :: [Package] -> IO PCI
45 mkPCI raw_package_info
46 = do mtab <- mk_module_table raw_package_info
47 return (PCI { pci_rawinfo = raw_package_info,
48 pci_modtable = mtab })
50 mk_module_table :: [Package] -> IO [(ModuleName,PackageName,FilePath)]
51 mk_module_table raw_info
53 -- the list of directories where package interfaces are
54 let -- p_i_dirs :: [(PkgName,Path)]
55 p_i_dirs = concatMap nm_and_paths raw_info
57 -- interface names in each directory
58 ifacess <- mapM ifaces_in_dir p_i_dirs
59 let -- iface_table :: [(ModName,PkgName,Path)]
60 iface_table = map fsifyStrings (concat ifacess)
62 -- ToDo: allow a range of home package directories
65 fsifyStrings (mod_str, pkg_str, path_str)
66 = (mkFastString mod_str, mkFastString pkg_str, path_str)
67 -- nm_and_paths :: Package -> [(PkgName,Path)]
69 = [(name package, path) | path <- nub (import_dirs package)]
71 -- ifaces_in_dir :: (PkgName,Path) -> IO [(ModName,PkgName,Path)]
72 ifaces_in_dir (pkgname,path)
73 = getDirectoryContents path >>= \ entries ->
74 return [(zap_hi if_nm, pkgname, path)
75 | if_nm <- entries, looks_like_iface_name if_nm]
76 looks_like_iface_name e
77 = not (null e) && isUpper (head e)
78 && take 3 (reverse e) == "ih."
80 = reverse . drop 3 . reverse