Skip to content

Commit

Permalink
Merge pull request #21 from mjambon/subdir
Browse files Browse the repository at this point in the history
Add support for the 'subdir' stanza by simply inlining their contents.
  • Loading branch information
mjambon authored Jun 3, 2021
2 parents 48897a3 + cd68f16 commit a0d23b2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/lib/Dune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,41 @@ let read_node path get_index sexp_entry =
{ Dep_graph.Node.name; kind; deps; loc }
) names

(*
'subdir' stanzas are inlined, and subdirectory names are discarded since
we don't need them.
(subdir
foo
(executable
(name foo)
)
)
becomes:
(executable
(name foo)
)
*)
let inline_subdirs orig_sexp_entries =
orig_sexp_entries
|> List.map (function
| List (Atom "subdir" :: Atom _dirname :: contents) -> contents
| x -> [x]
)
|> List.flatten

let load_file path =
let sexp_entries =
try Sexplib.Sexp.load_sexps path
with e ->
failwith (
sprintf "Cannot parse dune file %s: exception %s"
path (Printexc.to_string e)
)
(try Sexplib.Sexp.load_sexps path
with e ->
failwith (
sprintf "Cannot parse dune file %s: exception %s"
path (Printexc.to_string e)
)
)
|> inline_subdirs
in
let index = ref (-1) in
let get_index () =
Expand Down
3 changes: 3 additions & 0 deletions test/proj-no-exe.dot.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ digraph {
"lib:ext1" [label="ext1",style=filled]
"lib:ext2" [label="ext2",style=filled]
"lib:ext3" [label="ext3",style=filled]
"lib:foosubdirlib" [label="foosubdirlib"]
"lib:foosubdirlib-dep" [label="foosubdirlib-dep",style=filled]
"lib:lib-or-exe" [label="lib-or-exe"]
"lib:lib1" [label="lib1"]
"lib:lib1-alt" [label="lib1-alt",style=filled]
Expand All @@ -10,6 +12,7 @@ digraph {
"lib:lib4" [label="lib4"]
"lib:lib5" [label="lib5"]
"lib:more" [label="more"]
"lib:foosubdirlib" -> "lib:foosubdirlib-dep"
"lib:lib2" -> "lib:lib4"
"lib:lib2" -> "lib:lib5"
"lib:lib2" -> "lib:ext2"
Expand Down
5 changes: 5 additions & 0 deletions test/proj-no-ext.dot.expected
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ digraph {
"exe:proj/dune:3" [label="prog4",shape=diamond]
"exe:proj/dune:11" [label="test<proj>",shape=diamond]
"exe:proj/dune:12" [label="test<proj>",shape=diamond]
"exe:proj/with-subdir/dune:2" [label="barnotsubdir",shape=diamond]
"exe:proj/with-subdir/dune:0" [label="foosubdir",shape=diamond]
"lib:foosubdirlib" [label="foosubdirlib"]
"lib:lib-or-exe" [label="lib-or-exe"]
"lib:lib1" [label="lib1"]
"lib:lib2" [label="lib2"]
Expand All @@ -27,6 +30,8 @@ digraph {
"exe:proj/dune:2" -> "lib:lib3"
"exe:proj/dune:3" -> "lib:lib4"
"exe:proj/dune:11" -> "lib:lib1"
"exe:proj/with-subdir/dune:2" -> "lib:foosubdirlib"
"exe:proj/with-subdir/dune:0" -> "lib:foosubdirlib"
"lib:lib2" -> "lib:lib4"
"lib:lib2" -> "lib:lib5"
"lib:lib3" -> "lib:lib4"
Expand Down
7 changes: 7 additions & 0 deletions test/proj.dot.expected
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ digraph {
"exe:proj/dune:3" [label="prog4",shape=diamond]
"exe:proj/dune:11" [label="test<proj>",shape=diamond]
"exe:proj/dune:12" [label="test<proj>",shape=diamond]
"exe:proj/with-subdir/dune:2" [label="barnotsubdir",shape=diamond]
"exe:proj/with-subdir/dune:0" [label="foosubdir",shape=diamond]
"lib:ext1" [label="ext1",style=filled]
"lib:ext2" [label="ext2",style=filled]
"lib:ext3" [label="ext3",style=filled]
"lib:foosubdirlib" [label="foosubdirlib"]
"lib:foosubdirlib-dep" [label="foosubdirlib-dep",style=filled]
"lib:lib-or-exe" [label="lib-or-exe"]
"lib:lib1" [label="lib1"]
"lib:lib1-alt" [label="lib1-alt",style=filled]
Expand All @@ -35,6 +39,9 @@ digraph {
"exe:proj/dune:3" -> "lib:lib4"
"exe:proj/dune:11" -> "lib:lib1"
"exe:proj/dune:12" -> "lib:lib1-alt"
"exe:proj/with-subdir/dune:2" -> "lib:foosubdirlib"
"exe:proj/with-subdir/dune:0" -> "lib:foosubdirlib"
"lib:foosubdirlib" -> "lib:foosubdirlib-dep"
"lib:lib2" -> "lib:lib4"
"lib:lib2" -> "lib:lib5"
"lib:lib2" -> "lib:ext2"
Expand Down
23 changes: 23 additions & 0 deletions test/proj/with-subdir/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; Check support for the 'subdir' stanza

(subdir
foosubdir
(executable
(name foosubdir)
(libraries foosubdirlib)
)
(library
(name foosubdirlib)
(libraries foosubdirlib-dep)
(flags
(:standard --hello))
(preprocess
(pps ppx_trace))
(inline_tests)
)
)

(executable
(name barnotsubdir)
(libraries foosubdirlib)
)

0 comments on commit a0d23b2

Please sign in to comment.