Skip to content

Commit 6d4c572

Browse files
committed
tweak
1 parent 0d77215 commit 6d4c572

File tree

11 files changed

+114
-42
lines changed

11 files changed

+114
-42
lines changed

Diff for: jscomp/bsb/bsb_db_encode.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ let encode (dbs : Bsb_db.ts) buf =
8989
Ext_array.iter dbs (fun x -> encode_single x buf)
9090

9191

92-
92+
(* TODO: shall we avoid writing such file (checking the digest) *)
9393
let write_build_cache ~dir (bs_files : Bsb_db.ts) : string =
9494
let oc = open_out_bin (Filename.concat dir bsbuild_cache) in
9595
let buf = Ext_buffer.create 100_000 in
9696
encode bs_files buf ;
97-
let digest = Digest.to_hex (Ext_buffer.digest buf) in
97+
let digest = Ext_buffer.digest buf in
98+
let hex_digest = Digest.to_hex digest in
9899
output_string oc digest;
99100
Ext_buffer.output_buffer oc buf;
100101
close_out oc;
101-
digest
102+
hex_digest

Diff for: jscomp/bsb_helper/bsb_db_decode.ml

+3-13
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ type t = group array * string (* string is whole content*)
3737

3838
type cursor = int ref
3939

40-
let extract_line (x : string) (cur : cursor) : string =
41-
Ext_string.extract_until x cur '\n'
42-
43-
4440

4541
(*TODO: special case when module_count is zero *)
4642
let rec decode_internal (x : string) (offset : cursor) =
@@ -83,18 +79,12 @@ and decode_modules x (offset : cursor) module_number =
8379
result
8480

8581

86-
87-
88-
89-
82+
(* TODO: shall we check the consistency of digest *)
9083
let read_build_cache ~dir : t =
9184
let ic = open_in_bin (Filename.concat dir bsbuild_cache) in
9285
let len = in_channel_length ic in
93-
let all_content = really_input_string ic len in
94-
let offset = ref 0 in
95-
let _cur_module_info_magic_number = extract_line all_content offset in
96-
(* assert (cur_module_info_magic_number = Bs_version.version); *)
97-
decode_internal all_content offset, all_content
86+
let all_content = really_input_string ic len in
87+
decode_internal all_content (ref (Ext_digest.length + 1)), all_content
9888

9989
let cmp (a : string) b = String_map.compare_key a b
10090

Diff for: jscomp/ext/ext_digest.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
let length = 16
26+
let length = 16
27+
28+
let hex_length = 32

Diff for: jscomp/ext/ext_digest.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
val length : int
26+
val length : int
27+
28+
val hex_length : int

Diff for: jscomp/ounit_tests/ounit_util_tests.ml

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ let suites =
5151
let buf = Ext_buffer.create 0 in
5252
Ext_buffer.add_string_char buf "hello" 'v';
5353
Ext_buffer.contents buf =~ "hellov";
54-
Ext_buffer.length buf =~ 5
54+
Ext_buffer.length buf =~ 6
5555
end;
5656
__LOC__ >:: begin fun _ ->
5757
let buf = Ext_buffer.create 0 in
5858
Ext_buffer.add_char_string buf 'h' "ellov";
5959
Ext_buffer.contents buf =~ "hellov";
60-
Ext_buffer.length buf =~ 5
60+
Ext_buffer.length buf =~ 6
61+
end;
62+
__LOC__ >:: begin fun _ ->
63+
String.length
64+
(Digest.to_hex(Digest.string "")) =~ 32
6165
end
6266

6367
]

Diff for: lib/4.02.3/bsb.ml

+8-3
Original file line numberDiff line numberDiff line change
@@ -13091,16 +13091,17 @@ let encode (dbs : Bsb_db.ts) buf =
1309113091
Ext_array.iter dbs (fun x -> encode_single x buf)
1309213092

1309313093

13094-
13094+
(* TODO: shall we avoid writing such file (checking the digest) *)
1309513095
let write_build_cache ~dir (bs_files : Bsb_db.ts) : string =
1309613096
let oc = open_out_bin (Filename.concat dir bsbuild_cache) in
1309713097
let buf = Ext_buffer.create 100_000 in
1309813098
encode bs_files buf ;
13099-
let digest = Digest.to_hex (Ext_buffer.digest buf) in
13099+
let digest = Ext_buffer.digest buf in
13100+
let hex_digest = Digest.to_hex digest in
1310013101
output_string oc digest;
1310113102
Ext_buffer.output_buffer oc buf;
1310213103
close_out oc;
13103-
digest
13104+
hex_digest
1310413105

1310513106
end
1310613107
module Ext_digest : sig
@@ -13131,6 +13132,8 @@ module Ext_digest : sig
1313113132

1313213133

1313313134
val length : int
13135+
13136+
val hex_length : int
1313413137
end = struct
1313513138
#1 "ext_digest.ml"
1313613139
(* Copyright (C) 2019- Authors of BuckleScript
@@ -13159,6 +13162,8 @@ end = struct
1315913162

1316013163

1316113164
let length = 16
13165+
13166+
let hex_length = 32
1316213167
end
1316313168
module Bsb_namespace_map_gen : sig
1316413169
#1 "bsb_namespace_map_gen.mli"

Diff for: lib/4.02.3/bsb_helper.ml

+64-13
Original file line numberDiff line numberDiff line change
@@ -3542,6 +3542,67 @@ let has_reason_files (map : t ) =
35423542

35433543

35443544

3545+
end
3546+
module Ext_digest : sig
3547+
#1 "ext_digest.mli"
3548+
(* Copyright (C) 2019- Authors of BuckleScript
3549+
*
3550+
* This program is free software: you can redistribute it and/or modify
3551+
* it under the terms of the GNU Lesser General Public License as published by
3552+
* the Free Software Foundation, either version 3 of the License, or
3553+
* (at your option) any later version.
3554+
*
3555+
* In addition to the permissions granted to you by the LGPL, you may combine
3556+
* or link a "work that uses the Library" with a publicly distributed version
3557+
* of this file to produce a combined library or application, then distribute
3558+
* that combined work under the terms of your choosing, with no requirement
3559+
* to comply with the obligations normally placed on you by section 4 of the
3560+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
3561+
* should you choose to use a later version).
3562+
*
3563+
* This program is distributed in the hope that it will be useful,
3564+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
3565+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3566+
* GNU Lesser General Public License for more details.
3567+
*
3568+
* You should have received a copy of the GNU Lesser General Public License
3569+
* along with this program; if not, write to the Free Software
3570+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
3571+
3572+
3573+
val length : int
3574+
3575+
val hex_length : int
3576+
end = struct
3577+
#1 "ext_digest.ml"
3578+
(* Copyright (C) 2019- Authors of BuckleScript
3579+
*
3580+
* This program is free software: you can redistribute it and/or modify
3581+
* it under the terms of the GNU Lesser General Public License as published by
3582+
* the Free Software Foundation, either version 3 of the License, or
3583+
* (at your option) any later version.
3584+
*
3585+
* In addition to the permissions granted to you by the LGPL, you may combine
3586+
* or link a "work that uses the Library" with a publicly distributed version
3587+
* of this file to produce a combined library or application, then distribute
3588+
* that combined work under the terms of your choosing, with no requirement
3589+
* to comply with the obligations normally placed on you by section 4 of the
3590+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
3591+
* should you choose to use a later version).
3592+
*
3593+
* This program is distributed in the hope that it will be useful,
3594+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
3595+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3596+
* GNU Lesser General Public License for more details.
3597+
*
3598+
* You should have received a copy of the GNU Lesser General Public License
3599+
* along with this program; if not, write to the Free Software
3600+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
3601+
3602+
3603+
let length = 16
3604+
3605+
let hex_length = 32
35453606
end
35463607
module Literals : sig
35473608
#1 "literals.mli"
@@ -3917,10 +3978,6 @@ type t = group array * string (* string is whole content*)
39173978

39183979
type cursor = int ref
39193980

3920-
let extract_line (x : string) (cur : cursor) : string =
3921-
Ext_string.extract_until x cur '\n'
3922-
3923-
39243981

39253982
(*TODO: special case when module_count is zero *)
39263983
let rec decode_internal (x : string) (offset : cursor) =
@@ -3963,18 +4020,12 @@ and decode_modules x (offset : cursor) module_number =
39634020
result
39644021

39654022

3966-
3967-
3968-
3969-
4023+
(* TODO: shall we check the consistency of digest *)
39704024
let read_build_cache ~dir : t =
39714025
let ic = open_in_bin (Filename.concat dir bsbuild_cache) in
39724026
let len = in_channel_length ic in
3973-
let all_content = really_input_string ic len in
3974-
let offset = ref 0 in
3975-
let _cur_module_info_magic_number = extract_line all_content offset in
3976-
(* assert (cur_module_info_magic_number = Bs_version.version); *)
3977-
decode_internal all_content offset, all_content
4027+
let all_content = really_input_string ic len in
4028+
decode_internal all_content (ref (Ext_digest.length + 1)), all_content
39784029

39794030
let cmp (a : string) b = String_map.compare_key a b
39804031

Diff for: lib/4.02.3/bsb_helper.ml.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../lib/4.02.3/bsb_helper.ml: ./bsb_helper/bsb_db_decode.ml ./bsb_helper/bsb_db_decode.mli ./bsb_helper/bsb_helper_depfile_gen.ml ./bsb_helper/bsb_helper_depfile_gen.mli ./ext/bsb_db.ml ./ext/bsb_db.mli ./ext/bsb_dir_index.ml ./ext/bsb_dir_index.mli ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_namespace.ml ./ext/ext_namespace.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/string_map.ml ./ext/string_map.mli ./main/bsb_helper_main.ml ./main/bsb_helper_main.mli
1+
../lib/4.02.3/bsb_helper.ml: ./bsb_helper/bsb_db_decode.ml ./bsb_helper/bsb_db_decode.mli ./bsb_helper/bsb_helper_depfile_gen.ml ./bsb_helper/bsb_helper_depfile_gen.mli ./ext/bsb_db.ml ./ext/bsb_db.mli ./ext/bsb_dir_index.ml ./ext/bsb_dir_index.mli ./ext/ext_array.ml ./ext/ext_array.mli ./ext/ext_buffer.ml ./ext/ext_buffer.mli ./ext/ext_bytes.ml ./ext/ext_bytes.mli ./ext/ext_char.ml ./ext/ext_char.mli ./ext/ext_digest.ml ./ext/ext_digest.mli ./ext/ext_filename.ml ./ext/ext_filename.mli ./ext/ext_list.ml ./ext/ext_list.mli ./ext/ext_namespace.ml ./ext/ext_namespace.mli ./ext/ext_option.ml ./ext/ext_option.mli ./ext/ext_pervasives.ml ./ext/ext_pervasives.mli ./ext/ext_string.ml ./ext/ext_string.mli ./ext/literals.ml ./ext/literals.mli ./ext/map_gen.ml ./ext/string_map.ml ./ext/string_map.mli ./main/bsb_helper_main.ml ./main/bsb_helper_main.mli

Diff for: lib/4.02.3/unstable/all_ounit_tests.ml

+10-2
Original file line numberDiff line numberDiff line change
@@ -16591,6 +16591,8 @@ module Ext_digest : sig
1659116591

1659216592

1659316593
val length : int
16594+
16595+
val hex_length : int
1659416596
end = struct
1659516597
#1 "ext_digest.ml"
1659616598
(* Copyright (C) 2019- Authors of BuckleScript
@@ -16619,6 +16621,8 @@ end = struct
1661916621

1662016622

1662116623
let length = 16
16624+
16625+
let hex_length = 32
1662216626
end
1662316627
module Ext_modulename : sig
1662416628
#1 "ext_modulename.mli"
@@ -20549,13 +20553,17 @@ let suites =
2054920553
let buf = Ext_buffer.create 0 in
2055020554
Ext_buffer.add_string_char buf "hello" 'v';
2055120555
Ext_buffer.contents buf =~ "hellov";
20552-
Ext_buffer.length buf =~ 5
20556+
Ext_buffer.length buf =~ 6
2055320557
end;
2055420558
__LOC__ >:: begin fun _ ->
2055520559
let buf = Ext_buffer.create 0 in
2055620560
Ext_buffer.add_char_string buf 'h' "ellov";
2055720561
Ext_buffer.contents buf =~ "hellov";
20558-
Ext_buffer.length buf =~ 5
20562+
Ext_buffer.length buf =~ 6
20563+
end;
20564+
__LOC__ >:: begin fun _ ->
20565+
String.length
20566+
(Digest.to_hex(Digest.string "")) =~ 32
2055920567
end
2056020568

2056120569
]

Diff for: lib/4.02.3/unstable/bsb_native.ml

+8-3
Original file line numberDiff line numberDiff line change
@@ -13091,16 +13091,17 @@ let encode (dbs : Bsb_db.ts) buf =
1309113091
Ext_array.iter dbs (fun x -> encode_single x buf)
1309213092

1309313093

13094-
13094+
(* TODO: shall we avoid writing such file (checking the digest) *)
1309513095
let write_build_cache ~dir (bs_files : Bsb_db.ts) : string =
1309613096
let oc = open_out_bin (Filename.concat dir bsbuild_cache) in
1309713097
let buf = Ext_buffer.create 100_000 in
1309813098
encode bs_files buf ;
13099-
let digest = Digest.to_hex (Ext_buffer.digest buf) in
13099+
let digest = Ext_buffer.digest buf in
13100+
let hex_digest = Digest.to_hex digest in
1310013101
output_string oc digest;
1310113102
Ext_buffer.output_buffer oc buf;
1310213103
close_out oc;
13103-
digest
13104+
hex_digest
1310413105

1310513106
end
1310613107
module Ext_digest : sig
@@ -13131,6 +13132,8 @@ module Ext_digest : sig
1313113132

1313213133

1313313134
val length : int
13135+
13136+
val hex_length : int
1313413137
end = struct
1313513138
#1 "ext_digest.ml"
1313613139
(* Copyright (C) 2019- Authors of BuckleScript
@@ -13159,6 +13162,8 @@ end = struct
1315913162

1316013163

1316113164
let length = 16
13165+
13166+
let hex_length = 32
1316213167
end
1316313168
module Bsb_namespace_map_gen : sig
1316413169
#1 "bsb_namespace_map_gen.mli"

Diff for: lib/4.02.3/whole_compiler.ml

+4
Original file line numberDiff line numberDiff line change
@@ -59211,6 +59211,8 @@ module Ext_digest : sig
5921159211

5921259212

5921359213
val length : int
59214+
59215+
val hex_length : int
5921459216
end = struct
5921559217
#1 "ext_digest.ml"
5921659218
(* Copyright (C) 2019- Authors of BuckleScript
@@ -59239,6 +59241,8 @@ end = struct
5923959241

5924059242

5924159243
let length = 16
59244+
59245+
let hex_length = 32
5924259246
end
5924359247
module Ext_io : sig
5924459248
#1 "ext_io.mli"

0 commit comments

Comments
 (0)