Skip to content

Commit

Permalink
Simplify dependencies in this gen-dune
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Feb 17, 2025
1 parent 8e71b84 commit 1730b7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
5 changes: 3 additions & 2 deletions test/bop2c/gen-dune/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
-open
Base
-open
Fpath_base
-open
Cmdlang)
(libraries
auto-format
base
cmdlang
cmdlang-cmdliner-runner
eio
eio_main
fpath-base
parsing-utils)
(lint
(pps ppx_js_style -check-doc-comments))
Expand Down
27 changes: 16 additions & 11 deletions test/bop2c/gen-dune/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@
]}
*)

let find_files_in_cwd_by_extensions ~cwd ~extensions =
Stdlib.Sys.readdir cwd
|> Array.map ~f:Fpath.v
|> Array.to_list
|> List.filter ~f:(fun file ->
Stdlib.Sys.is_regular_file (Fpath.to_string file)
&& List.exists extensions ~f:(fun extension -> Fpath.has_ext extension file))
|> List.sort ~compare:Fpath.compare
;;

let gen_dune_cmd =
Command.make
~summary:
"generate dune stanza for all c files present in the cwd to be generated by bopkit"
(let%map_open.Command () = Arg.return () in
Eio_main.run
@@ fun env ->
let files =
Auto_format.find_files_in_cwd_by_extensions
~cwd:(Eio.Stdenv.cwd env)
~extensions:[ "bop" ]
in
let cwd = Stdlib.Sys.getcwd () in
let files = find_files_in_cwd_by_extensions ~cwd ~extensions:[ "bop" ] in
let generate_rules ~file =
let file_prefix = Stdlib.Filename.chop_extension file in
let file_prefix = Fpath.rem_ext file in
let open Sexp in
let c_file = file_prefix ^ ".c" in
let c_file = Fpath.to_string file_prefix ^ ".c" in
let list s = List s
and atom s = Atom s in
let atoms s = List.map s ~f:atom in
Expand All @@ -42,7 +47,7 @@ let gen_dune_cmd =
[ atom "run"
; atom "%{bin:bopkit}"
; atom "bop2c"
; atom (Printf.sprintf "%%{dep:%s}" file)
; atom (Printf.sprintf "%%{dep:%s}" (Fpath.to_string file))
]
]
]
Expand All @@ -51,7 +56,7 @@ let gen_dune_cmd =
let gcc =
list
[ atom "rule"
; list (atoms [ "target"; file_prefix ^ ".exe" ])
; list (atoms [ "target"; Fpath.to_string file_prefix ^ ".exe" ])
; list
[ atom "action"
; list
Expand Down

0 comments on commit 1730b7d

Please sign in to comment.