Skip to content

Commit a4eb34e

Browse files
authored
dune dynamic-action-plugin: don't read files unnecessarily (rescript-lang#80)
In order to track dynamic dependencies we were: 1. reading each `*.d` file produced by `bsb_helper` 2. for each dependency in the `*.d` file, track it in dune by reading their file contents We can avoid reading files into memory altogether by calling the `read_directory_with_glob` function instead, which declares dependencies on those files without reading their contents.
1 parent 7351284 commit a4eb34e

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

jscomp/bsb/bsb_ninja_file_groups.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ let handle_files_per_dir
246246
Buffer.add_string buf rel_group_dir;
247247
Buffer.add_char buf '\n';
248248
if group.subdirs <> [] then begin
249-
Buffer.add_string buf "(dirs :standard";
249+
Buffer.add_string buf "(dirs";
250250
Ext_list.iter group.subdirs (fun subdir ->
251251
Buffer.add_char buf ' ';
252252
Buffer.add_string buf subdir);
@@ -286,11 +286,5 @@ let handle_files_per_dir
286286
Bsb_ninja_targets.output_alias buf ~name:Literals.bsb_world ~deps:(List.concat js_targets);
287287
Buffer.add_string buf ")";
288288
Buffer.add_string buf "\n"
289-
290289
end
291290

292-
(* ;
293-
Bsb_ninja_targets.phony
294-
oc ~order_only_deps:[] ~inputs:[] ~output:group.dir *)
295-
296-
(* pseuduo targets per directory *)

jscomp/main/bsb_parse_depend.ml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
module D = Dune_action_plugin.V1
22
module P = D.Path
3+
module Glob = Dune_glob.V1
34

45
open D.O
56

6-
let (let*) p f = D.stage ~f p
7-
87
let (//) = Ext_path.combine
98

109
let input_lines =
@@ -54,6 +53,12 @@ let parse_deps_exn lines =
5453
| None -> assert false
5554
| Some (_fname, deps) -> extract_blank_separated_words deps
5655

56+
let ignore_both a b =
57+
D.map ~f:(fun (_, _) -> ()) (D.both a b)
58+
59+
let realize ~rules =
60+
List.fold_left ignore_both (D.return ()) rules
61+
5762
let single_file ~cwd file =
5863
let chan = open_in_bin file in
5964
let deps = parse_deps_exn (input_lines chan) in
@@ -67,21 +72,22 @@ let single_file ~cwd file =
6772
in
6873
let rules =
6974
List.map (fun file ->
70-
let file' = rel_project_root // file in
71-
D.read_file ~path:(P.of_string file')) deps
75+
let dirname, basename =
76+
let path = rel_project_root // file in
77+
Filename.dirname path, Filename.basename path
78+
in
79+
let+ (_: string list) =
80+
D.read_directory_with_glob
81+
~path:(P.of_string dirname)
82+
~glob:(Glob.of_string basename)
83+
in
84+
()) deps
7285
in
73-
List.fold_left (fun acc item ->
74-
let+ _ = D.both acc item in ())
75-
(D.return ())
76-
rules
86+
rules
7787

7888
let parse_depends ~cwd files =
79-
let rules = List.map (single_file ~cwd) files in
80-
let rule = List.fold_left (fun acc item ->
81-
let+ _ = D.both acc item in ())
82-
(D.return ())
83-
rules
84-
in
89+
let rules = List.concat_map (single_file ~cwd) files in
90+
let rule = realize ~rules in
8591
D.run rule
8692

8793
let () =

0 commit comments

Comments
 (0)