Skip to content

Commit 613ea3a

Browse files
committed
Add --exclude option.
Implements #14
1 parent 3232359 commit 613ea3a

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

src/bin/main.ml

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ open Dune_deps
88

99
type config = {
1010
roots : string list;
11+
exclude : string list;
1112
no_exe : bool;
1213
no_ext : bool;
1314
deps : string list;
1415
revdeps : string list;
1516
}
1617

17-
let optimistic_run {roots; no_exe; no_ext; deps; revdeps} =
18+
let optimistic_run {roots; exclude; no_exe; no_ext; deps; revdeps} =
1819
let graph =
19-
Find.find_dune_files roots
20+
Find.find_dune_files roots ~exclude
2021
|> Dune.load_files
2122
in
2223
let graph =
@@ -57,6 +58,15 @@ let roots_term =
5758
in
5859
Arg.value (Arg.pos_all Arg.file ["."] info)
5960

61+
let exclude_term =
62+
let info =
63+
Arg.info ["exclude"; "x"]
64+
~docv:"ROOT"
65+
~doc:"Ignore folder or file $(docv) when scanning the file tree \
66+
for 'dune' files."
67+
in
68+
Arg.value (Arg.opt_all Arg.string [] info)
69+
6070
let no_exe_term =
6171
let info =
6272
Arg.info ["no-exe"]
@@ -109,14 +119,15 @@ let revdeps_term =
109119
Arg.value (Arg.opt_all Arg.string [] info)
110120

111121
let cmdline_term =
112-
let combine roots no_exe no_ext hourglass deps revdeps =
122+
let combine roots exclude no_exe no_ext hourglass deps revdeps =
113123
let deps, revdeps =
114124
(deps @ hourglass), (revdeps @ hourglass)
115125
in
116-
{ roots; no_exe; no_ext; deps; revdeps }
126+
{ roots; exclude; no_exe; no_ext; deps; revdeps }
117127
in
118128
Term.(const combine
119129
$ roots_term
130+
$ exclude_term
120131
$ no_exe_term
121132
$ no_ext_term
122133
$ hourglass_term

src/lib/Find.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ let find ~accept_file_name ~accept_dir_name visit_tracker root =
6161
Excludes '_build' folders but doesn't honor exclusion rules specified
6262
in dune files with (dirs ... \ exclude_me).
6363
*)
64-
let find_dune_files roots =
64+
let find_dune_files ~exclude roots =
6565
let visit_tracker = create_visit_tracker () in
66+
List.iter visit_tracker.mark_visited exclude;
6667
List.fold_left (fun acc root ->
6768
find
6869
~accept_file_name:(fun name -> name = "dune")

test/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ test: output
1414

1515
.PHONY: output
1616
output:
17-
./dune-deps proj extra-proj > proj.dot
18-
./dune-deps proj extra-proj --no-exe > proj-no-exe.dot
19-
./dune-deps proj extra-proj --no-ext > proj-no-ext.dot
17+
./dune-deps proj extra-proj -x extra-proj/exclude-me > proj.dot
18+
./dune-deps proj --no-exe > proj-no-exe.dot
19+
./dune-deps proj --no-ext > proj-no-ext.dot
2020
./dune-deps proj --hourglass lib5 -h lib3 > proj-hourglass.dot
2121
./dune-deps proj --deps lib3 --revdeps lib5 > proj-deps.dot
2222

test/extra-proj/exclude-me/dune

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(library
2+
(public_name exclude-me)
3+
)

test/proj-no-ext.dot.expected

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
digraph {
2-
"exe:extra-proj/dune:0" [label="extra",shape=diamond]
32
"exe:proj/bar/test/dune:0" [label="test<bar/test>",shape=diamond]
43
"exe:proj/foo/test/dune:0" [label="test<foo/test>",shape=diamond]
54
"exe:proj/dune:10" [label="lib-or-exe",shape=diamond]

0 commit comments

Comments
 (0)