@@ -30,32 +30,17 @@ let get_files ext dir =
30
30
if Ext_string. ends_with x ext then Some (Filename. concat dir x) else None )
31
31
|> Array. to_list
32
32
33
- (* * the cache should be readable and also update *)
34
- let check_digest output_file digest : bool =
35
- if Sys. file_exists output_file then
36
- match
37
- Ext_list. filter
38
- (String. split_on_char ' ' (Ext_io. load_file output_file))
39
- (fun x -> x <> " " )
40
- with
41
- | _head :: old_digest :: _tail -> Digest. equal digest old_digest
42
- | _ -> false
43
- else false
44
-
45
- let ( +> ) = Ext_buffer. add_string
46
-
47
33
let from_cmj ~mode (files : string list ) (output_file : string ) : unit =
48
34
let files =
49
35
let cmp = Ext_filename. module_name in
50
- List. sort
51
- (fun filea fileb -> Ext_string_array. cmp (cmp filea) (cmp fileb))
52
- files
36
+ files
37
+ |> List. sort (fun filea fileb ->
38
+ Ext_string_array. cmp (cmp filea) (cmp fileb))
39
+ |> Array. of_list
53
40
in
54
- let buf = Ext_buffer. create 10000 in
55
-
56
- let abs =
57
- Ext_list. map files (fun file ->
58
- let module_name = Ext_filename. module_name file in
41
+ let module_names = Ext_array. map files Ext_filename. module_name in
42
+ let module_data =
43
+ Ext_array. map files (fun file ->
59
44
let content : Js_cmj_format.t = Js_cmj_format. from_file file in
60
45
let () =
61
46
match mode with
@@ -72,29 +57,13 @@ let from_cmj ~mode (files : string list) (output_file : string) : unit =
72
57
| Playground _ -> ()
73
58
in
74
59
(* prerr_endline (Ext_obj.dump content.package_spec); *)
75
- let c = Marshal. to_string (content.values, content.pure) [] in
76
- ( Printf. sprintf {|% S (* %d *) | } module_name (String. length c),
77
- Printf. sprintf {| (* %s *) % S | } module_name c ))
60
+ let { Js_cmj_format. values; pure } = content in
61
+ Cmij_cache. marshal_cmj_data { values; pure })
78
62
in
79
- buf
80
- +> Printf. sprintf
81
- {| let module_names : string array = Obj. magic (
82
- % s
83
- )
84
- let module_data : string array = Obj. magic (
85
- % s
86
- )
87
- | }
88
- (String. concat " ,\n " (Ext_list. map abs fst))
89
- (String. concat " ,\n " (Ext_list. map abs snd));
90
- buf +> " \n " ;
91
- let digest = Digest. to_hex (Ext_buffer. digest buf) in
92
- let same = check_digest output_file digest in
93
- if not same then
94
- let v = open_out_bin output_file in
95
- Ext_pervasives. finally v ~clean: close_out (fun f ->
96
- output_string f (" (* " ^ digest ^ " *) \n " );
97
- Ext_buffer. output_buffer f buf)
63
+ let cmj_cache = { Cmij_cache. module_names; module_data } in
64
+ let v = open_out_bin output_file in
65
+ Ext_pervasives. finally v ~clean: close_out (fun f ->
66
+ Marshal. to_channel f cmj_cache [] )
98
67
99
68
let from_cmi files output_file =
100
69
let files =
@@ -110,21 +79,19 @@ let from_cmi files output_file =
110
79
let module_name = Ext_filename. module_name file in
111
80
let cmi = Cmi_format. read_cmi file in
112
81
assert (cmi.cmi_name = module_name);
113
- let content = Marshal. to_bytes cmi [] in
114
- content)
82
+ Cmij_cache. marshal_cmi_data cmi)
115
83
in
116
- let cmi_cache = { Cmij . module_names; module_data } in
84
+ let cmi_cache = { Cmij_cache . module_names; module_data } in
117
85
let v = open_out_bin output_file in
118
86
Ext_pervasives. finally v ~clean: close_out (fun f ->
119
87
Marshal. to_channel f cmi_cache [] )
120
88
121
89
let stdlib = " stdlib-406"
122
90
let ( // ) = Filename. concat
123
91
let ( |~ ) = Ext_string. contain_substring
124
-
125
- let cmi_target_file =
126
- Filename. dirname Sys. argv.(0 ) // " .." // " .." // " lib" // " cmi_cache.bin"
127
-
92
+ let lib_dir = Filename. dirname Sys. argv.(0 ) // " .." // " .." // " lib"
93
+ let cmi_target_file = lib_dir // " cmi_cache.bin"
94
+ let cmj_target_file = lib_dir // " cmj_cache.bin"
128
95
let release_cmi = Array. exists (( = ) " -release" ) Sys. argv
129
96
130
97
let () =
@@ -158,9 +125,7 @@ let () =
158
125
(Filename. dirname Sys. argv.(0 ) // " .." // " others" )
159
126
@ third_party_cmj_files
160
127
in
161
- from_cmj ~mode cmj_files
162
- (Filename. dirname Sys. argv.(0 )
163
- // " .." // " core" // " builtin_cmj_datasets.ml" );
128
+ from_cmj ~mode cmj_files cmj_target_file;
164
129
let third_party_cmi_files =
165
130
match mode with
166
131
| Native -> []
0 commit comments