3
3
1. parse the META file of the package with ocamlfind to see which libraries
4
4
exist and what their archive name (.cma filename) is.
5
5
6
- 2. use ocamlobjinfo to get a list of all modules within the archives.
6
+ 2. use ocamlobjinfo to get a list of all modules within the archives. EDIT:
7
+ it seems this step is now skipped.
7
8
8
9
This code assumes that the META file lists for every library an archive
9
10
[archive_name], and that for this cma archive exists a corresponsing
10
11
[archive_name].ocamlobjinfo file. *)
11
12
12
- type library = {
13
- name : string ;
14
- archive_name : string ;
15
- mutable modules : string list ;
16
- dir : string option ;
17
- }
18
-
19
- type t = { libraries : library list }
13
+ type library = { name : string ; archive_name : string ; dir : string option }
20
14
21
15
let read_libraries_from_pkg_defs ~library_name pkg_defs =
22
16
try
@@ -31,12 +25,12 @@ let read_libraries_from_pkg_defs ~library_name pkg_defs =
31
25
else cma_filename
32
26
in
33
27
if String. length archive_name > 0 then
34
- [ { name = library_name; archive_name; modules = [] ; dir } ]
28
+ [ { name = library_name; archive_name; dir } ]
35
29
else []
36
30
with Not_found -> []
37
31
38
32
let process_meta_file file =
39
- let _ = Format. eprintf " process_meta_file: %s\n %!" (Fpath. to_string file) in
33
+ let () = Format. eprintf " process_meta_file: %s\n %!" (Fpath. to_string file) in
40
34
let ic = open_in (Fpath. to_string file) in
41
35
let meta = Fl_metascanner. parse ic in
42
36
let base_library_name =
@@ -72,84 +66,3 @@ let process_meta_file file =
72
66
|> List. filter is_not_private
73
67
in
74
68
libraries
75
-
76
- let process_ocamlobjinfo_file ~(libraries : library list ) file =
77
- let _ =
78
- Format. eprintf " process_ocamlobjinfo_file: %s\n %!" (Fpath. to_string file)
79
- in
80
- let ic = open_in (Fpath. to_string file) in
81
- let lines = Util. lines_of_channel ic in
82
- let affix = " Unit name: " in
83
- let len = String. length affix in
84
- close_in ic;
85
- let units =
86
- List. concat_map
87
- (fun line ->
88
- if Astring.String. is_prefix ~affix line then
89
- [ String. sub line len (String. length line - len) ]
90
- else [] )
91
- lines
92
- in
93
- let _, archive_name = Fpath. split_base file in
94
- let archive_name = archive_name |> Fpath. rem_ext |> Fpath. to_string in
95
- let _ =
96
- Format. eprintf " trying to look up archive_name: %s\n units: %s\n %!"
97
- archive_name (String. concat " ," units)
98
- in
99
- try
100
- let library =
101
- List. find (fun l -> l.archive_name = archive_name) libraries
102
- in
103
- library.modules < - library.modules @ units
104
- with Not_found ->
105
- Format. eprintf " failed to find archive_name: %s\n %!" archive_name;
106
- ()
107
-
108
- (* let get_libraries package =
109
- let path = package in
110
- let maybe_meta_files =
111
- Bos.OS.Dir.fold_contents ~dotfiles:true
112
- (fun p acc ->
113
- let is_meta = p |> Fpath.basename = "META" in
114
- if is_meta then p :: acc else acc)
115
- [] path
116
- in
117
-
118
- match maybe_meta_files with
119
- | Error (`Msg msg) ->
120
- failwith
121
- ("FIXME: error traversing directories to find the META files: " ^ msg)
122
- | Ok meta_files -> (
123
- let libraries =
124
- meta_files |> List.map process_meta_file |> List.flatten
125
- in
126
-
127
- let _ =
128
- Format.eprintf "found archive_names: [%s]\n%!"
129
- (String.concat ", "
130
- (List.map (fun (l : library) -> l.archive_name) libraries))
131
- in
132
-
133
- let maybe_ocamlobjinfo_files =
134
- Bos.OS.Dir.fold_contents ~dotfiles:true
135
- (fun p acc ->
136
- let is_ocamlobjinfo = Fpath.get_ext p = ".ocamlobjinfo" in
137
- if is_ocamlobjinfo then p :: acc else acc)
138
- [] path
139
- in
140
- match maybe_ocamlobjinfo_files with
141
- | Error (`Msg msg) ->
142
- failwith
143
- ("FIXME: error traversing directories to find the ocamlobjinfo \
144
- files: " ^ msg)
145
- | Ok ocamlobjinfo_files ->
146
- List.iter (process_ocamlobjinfo_file ~libraries) ocamlobjinfo_files;
147
- let _ =
148
- Format.eprintf "found archive_names: [%s]\n%!"
149
- (String.concat ", "
150
- (List.map
151
- (fun (l : library) ->
152
- l.archive_name ^ "/" ^ String.concat "," l.modules)
153
- libraries))
154
- in
155
- { libraries }) *)
0 commit comments