@@ -38,74 +38,70 @@ let get_files ext dir =
38
38
Array. sort (fun (x : string ) y -> Pervasives. compare x y ) arr;
39
39
Array. to_list arr
40
40
41
+ (* * the cache should be readable and also update *)
42
+
41
43
let from_cmj (files : string list ) (output_file : string ) =
42
- let raw_to_str f str =
43
- Ext_pp. string f " \" " ;
44
- Ext_pp. string f (String. escaped str);
45
- Ext_pp. string f " \" "
46
- in
44
+ let files = List. sort (fun filea fileb ->
45
+ Ext_string_array. cmp (Filename. basename filea) (Filename. basename fileb)) files in
46
+ let keys = Ext_list. map files (fun x -> " \" " ^ Filename. basename x ^ " \" " ) in
47
47
let v = open_out_bin output_file in
48
- Ext_pervasives. finally v ~clean: close_out (fun v ->
49
- let f = Ext_pp. from_channel v in
50
- let aux file =
51
- let str = Ext_io. load_file file in
52
- begin
53
- #if 0 then
54
- prerr_endline (* can not embed corrupted data *)
55
- (Printf. sprintf " Begin Verifying %s" file);
56
- let _ = Js_cmj_format. from_string str in
57
- prerr_endline " End" ;
58
- #end
59
- Ext_pp. paren_group f 1 (fun _ ->
60
- raw_to_str f (Filename. basename file) ;
61
- Ext_pp. string f " ," ;
62
- Ext_pp. string f " lazy" ;
63
- Ext_pp. space f ;
64
- Ext_pp. paren_group f 1 (fun _ ->
65
- Ext_pp. string f " Js_cmj_format.from_string " ;
66
- raw_to_str f str));
67
- Ext_pp. string f " ;" ;
68
- Ext_pp. newline f
69
- end
70
- in
48
+ Ext_pervasives. finally v ~clean: close_out (fun f ->
49
+ output_string f
50
+ (Printf. sprintf {| let module_sets = [|
51
+ % s
52
+ |]| }
53
+ (String. concat " ;\n " keys)
54
+ ) ;
55
+ output_string f " \n " ;
56
+ output_string f
57
+ (Printf. sprintf {| let module_sets_cmj : Js_cmj_format.t Lazy.t array = [|
58
+ % s
59
+ |]
60
+ | } (String. concat " ;\n " (Ext_list. map files (fun file ->
61
+ Printf. sprintf " lazy (Js_cmj_format.from_string %S )"
62
+ (Ext_io. load_file file)))));
63
+ output_string f " \n " ;
64
+ output_string f {|
65
+ let query_by_name s =
66
+ match Ext_string_array. find_sorted
67
+ module_sets s with
68
+ | None -> None
69
+ | Some i ->
70
+ Some (Lazy. force module_sets_cmj.(i))
71
+ | }
72
+
73
+ )
71
74
72
- Ext_pp. newline f ;
73
- Ext_pp. string f " let data_sets = let map = Map_string.of_list " ;
74
- Ext_pp. bracket_vgroup f 1 (fun _ -> List. iter aux files);
75
- Ext_pp. string f " in ref map" )
76
75
77
76
78
- (* * the cache should be readable and also update *)
79
- let _raw_to_str f str =
80
- Ext_pp. string f " \" " ;
81
- Ext_pp. string f (String. escaped str);
82
- Ext_pp. string f " \" "
83
77
84
78
let from_cmi (files : string list ) (output_file : string ) =
85
79
let files = List. sort (fun filea fileb ->
86
- Ext_string_array. cmp (Ext_filename. module_name filea) (Ext_filename. module_name fileb)) files in
80
+ Ext_string_array. cmp (Ext_filename. module_name filea) (Ext_filename. module_name fileb)) files in
81
+ let keys = Ext_list. map files (fun x -> " \" " ^ Ext_filename. module_name x ^ " \" " ) in
87
82
let v = open_out_bin output_file in
88
83
Ext_pervasives. finally v ~clean: close_out (fun f ->
89
84
output_string f
90
85
(Printf. sprintf {| let module_sets = [|
91
86
% s
92
87
|]| }
93
- (String. concat " ;\n " ( Ext_list. map files ( fun x -> " \" " ^ Ext_filename. module_name x ^ " \" " )) )
94
- ) ;
88
+ (String. concat " ;\n " keys )
89
+ ) ;
95
90
output_string f " \n " ;
96
91
output_string f
97
- (Printf. sprintf {| let module_sets_cmi : Cmi_format.cmi_infos Lazy.t array = [|
92
+ (Printf. sprintf {| let module_sets_cmi : Cmi_format.cmi_infos Lazy.t array = [|
98
93
% s
99
94
|]
100
95
| } (String. concat " ;\n " (Ext_list. map files (fun file ->
101
- Printf. sprintf " lazy (Marshal.from_string %S 0)"
102
- (let content = (Cmi_format. read_cmi file) in
103
- Marshal. to_string content []
104
- (* let header_len = (String.length Config.cmi_magic_number) in
105
- String.sub content header_len (String.length content - header_len) *)
106
- )))
107
- )
108
- ))
96
+ Printf. sprintf " lazy (Marshal.from_string %S 0)"
97
+ (let content = (Cmi_format. read_cmi file) in
98
+ Marshal. to_string content []
99
+ (* let header_len = (String.length Config.cmi_magic_number) in
100
+ String.sub content header_len (String.length content - header_len) *)
101
+ )))
102
+ )
103
+ )
104
+ )
109
105
;;
110
106
111
107
let stdlib = " stdlib-406"
@@ -114,9 +110,9 @@ let () =
114
110
from_cmj ( Ext_list. append (get_files Literals. suffix_cmj stdlib)
115
111
(Ext_list. append (get_files Literals. suffix_cmj " runtime" )
116
112
(get_files Literals. suffix_cmj " others" )))
117
- (Filename. concat " core" " js_cmj_datasets .ml" )
118
- (* from_cmi ( Ext_list.append (get_files Literals.suffix_cmi stdlib)
113
+ (Filename. concat " core" " builtin_cmj_datasets .ml" );
114
+ from_cmi ( Ext_list. append (get_files Literals. suffix_cmi stdlib)
119
115
(Ext_list. append (get_files Literals. suffix_cmi " runtime" )
120
116
(get_files Literals. suffix_cmi " others" )))
121
- (Filename.concat "core" "js_cmi_datasets .ml") * )
117
+ (Filename. concat " core" " builtin_cmi_datasets .ml" )
122
118
0 commit comments