@@ -30,32 +30,17 @@ let get_files ext dir =
3030 if Ext_string. ends_with x ext then Some (Filename. concat dir x) else None )
3131 |> Array. to_list
3232
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-
4733let from_cmj ~mode (files : string list ) (output_file : string ) : unit =
4834 let files =
4935 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
5340 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 ->
5944 let content : Js_cmj_format.t = Js_cmj_format. from_file file in
6045 let () =
6146 match mode with
@@ -72,29 +57,13 @@ let from_cmj ~mode (files : string list) (output_file : string) : unit =
7257 | Playground _ -> ()
7358 in
7459 (* 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 })
7862 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 [] )
9867
9968let from_cmi files output_file =
10069 let files =
@@ -110,21 +79,19 @@ let from_cmi files output_file =
11079 let module_name = Ext_filename. module_name file in
11180 let cmi = Cmi_format. read_cmi file in
11281 assert (cmi.cmi_name = module_name);
113- let content = Marshal. to_bytes cmi [] in
114- content)
82+ Cmij_cache. marshal_cmi_data cmi)
11583 in
116- let cmi_cache = { Cmij . module_names; module_data } in
84+ let cmi_cache = { Cmij_cache . module_names; module_data } in
11785 let v = open_out_bin output_file in
11886 Ext_pervasives. finally v ~clean: close_out (fun f ->
11987 Marshal. to_channel f cmi_cache [] )
12088
12189let stdlib = " stdlib-406"
12290let ( // ) = Filename. concat
12391let ( |~ ) = 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"
12895let release_cmi = Array. exists (( = ) " -release" ) Sys. argv
12996
13097let () =
@@ -158,9 +125,7 @@ let () =
158125 (Filename. dirname Sys. argv.(0 ) // " .." // " others" )
159126 @ third_party_cmj_files
160127 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;
164129 let third_party_cmi_files =
165130 match mode with
166131 | Native -> []
0 commit comments