[project @ 2000-10-10 12:20:46 by sewardj]
[ghc-hetmet.git] / ghc / compiler / ghci / CmStaticInfo.lhs
1 %
2 % (c) The University of Glasgow, 2000
3 %
4 \section[CmStaticInfo]{Session-static info for the Compilation Manager}
5
6 \begin{code}
7 module CmStaticInfo ( Path, ModName, PkgName,
8                       Package(..), PCI(..), mkPCI )
9 where
10
11 #include "HsVersions.h"
12
13 import List             ( nub )
14 import Char             ( isUpper )
15 import Directory        ( getDirectoryContents )
16 \end{code}
17
18 \begin{code}
19 type Path    = String
20 type ModName = String
21 type PkgName = String
22
23 data PCI 
24    = PCI { 
25         raw_package_info :: [Package],  -- contents of packages.conf
26         module_table     :: [(ModName, PkgName, Path)]
27                             -- maps each available module to pkg and path
28      }
29
30 -- copied from the driver
31 data Package
32    = Package {
33         name            :: String,
34         import_dirs     :: [String],
35         library_dirs    :: [String],
36         hs_libraries    :: [String],
37         extra_libraries :: [String],
38         include_dirs    :: [String],
39         c_includes      :: [String],
40         package_deps    :: [String],
41         extra_ghc_opts  :: [String],
42         extra_cc_opts   :: [String],
43         extra_ld_opts   :: [String]
44      }
45   deriving Read
46
47 mkPCI :: [Package] -> IO PCI
48 mkPCI raw_package_info
49    = do mtab <- mk_module_table raw_package_info
50         return (PCI { raw_package_info = raw_package_info,
51                       module_table = mtab })
52
53 mk_module_table :: [Package] -> IO [(ModName,PkgName,Path)]
54 mk_module_table raw_info
55    = do 
56         -- the list of directories where package interfaces are
57         let p_i_dirs :: [(PkgName,Path)]
58             p_i_dirs = concatMap nm_and_paths raw_info
59
60         -- interface names in each directory
61         ifacess <- mapM ifaces_in_dir p_i_dirs
62         let iface_table :: [(ModName,PkgName,Path)] 
63             iface_table = concat ifacess
64
65         -- ToDo: allow a range of home package directories
66         return iface_table
67      where
68         nm_and_paths :: Package -> [(PkgName,Path)]
69         nm_and_paths package 
70            = [(name package, path) | path <- nub (import_dirs package)]
71
72         ifaces_in_dir :: (PkgName,Path) -> IO [(ModName,PkgName,Path)]
73         ifaces_in_dir (pkgname,path)
74            = getDirectoryContents path >>= \ entries ->
75              return [(zap_hi if_nm, pkgname, path) 
76                     | if_nm <- entries, looks_like_iface_name if_nm]
77         looks_like_iface_name e
78            = not (null e) && isUpper (head e) 
79                           && take 3 (reverse e) == "ih."
80         zap_hi 
81            = reverse . drop 3 . reverse
82
83 \end{code}