Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Dune dependency, setup Fmt through Cmdliner #1

Open
wants to merge 3 commits into
base: dune-external-libs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions deps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let copy_rules =
(fun d_item ->
d_item
|> Describe_external_lib.get_item
|> (fun (item:Describe_external_lib.item) -> item.source_dir ^ "/dune")
|> (fun (item:Describe_external_lib.item) -> String.cat item.source_dir "/dune")
|> (Dune_rules.Copy_rules.get_copy_rules))
|> Dune_rules.Copy_rules.copy_rules_map

Expand All @@ -54,7 +54,7 @@ let find_exe_item_package (item:Describe_external_lib.item) =
(* Only allow for private executables to find the package *)
item.extensions
|> List.find_map (fun extension ->
let bin_name = Dune_rules.Copy_rules.find_dest_name ~name:(item.name ^ extension) copy_rules in
let bin_name = Dune_rules.Copy_rules.find_dest_name ~name:(String.cat item.name extension) copy_rules in
Option.map (fun (item:Describe_entries.item) -> item.package) (Item_map.find_opt bin_name bin_of_entries))

let get_dune_items dir_types ~pkg ~target =
Expand All @@ -65,18 +65,21 @@ let get_dune_items dir_types ~pkg ~target =
* because it will be resolve with separate request*)
let open Describe_external_lib in
let get_name = function
| Lib item -> item.name ^ ".lib"
| Exe item -> item.name ^ ".exe"
| Test item -> item.name ^ ".test"
| Lib item -> String.cat item.name ".lib"
| Exe item -> String.cat item.name ".exe"
| Test item -> String.cat item.name ".test"
in
let d_items_lib =
d_items
|> List.filter is_lib_item
|> List.map (fun d_item ->
d_item
|> get_item
|> (fun (item:Describe_external_lib.item) ->
(item.name ^ ".lib", Lib item)))
|> List.filter_map (fun d_item ->
match is_lib_item d_item with
| true ->
d_item
|> get_item
|> (fun (item:Describe_external_lib.item) ->
(String.cat item.name ".lib", Lib item))
|> Option.some
| false -> None)
|> List.to_seq |> Hashtbl.of_seq
in
let rec add_internal acc = function
Expand All @@ -87,12 +90,12 @@ let get_dune_items dir_types ~pkg ~target =
else begin
Hashtbl.add acc (get_name item) item;
(get_item item).internal_deps
|> List.filter (fun (_, k) -> Kind.is_required k)
|> List.filter_map (fun (name, _) ->
match Hashtbl.find_opt d_items_lib (name ^ ".lib") with
|> List.filter_map (fun (name, k) ->
match Hashtbl.find_opt d_items_lib (String.cat name ".lib") with
| None -> None
| Some d_item_lib ->
if Option.is_some (get_item d_item_lib).package then None else Some d_item_lib)
if Kind.is_required k && Option.is_some (get_item d_item_lib).package then None
else Some d_item_lib)
|> fun internals -> add_internal acc (tl @ internals)
end
in
Expand Down Expand Up @@ -129,13 +132,13 @@ let get_dune_items dir_types ~pkg ~target =
let lib_deps ~pkg ~target =
get_dune_items (Hashtbl.create 10) ~pkg ~target
|> List.map Describe_external_lib.get_item
|> List.fold_left (fun acc (item:Describe_external_lib.item) ->
List.map (fun dep -> (fst dep, item.source_dir)) item.external_deps @ acc) []
|> List.fold_left (fun acc (lib,path) ->
if Astring.String.take ~sat:((<>) '.') lib <> pkg then
let dirs = Libraries.find_opt lib acc |> Option.value ~default:Dir_set.empty in
Libraries.add lib (Dir_set.add path dirs) acc
else
acc) Libraries.empty
|> List.fold_left (fun libs (item:Describe_external_lib.item) ->
List.map (fun dep -> fst dep, item.source_dir) item.external_deps
|> List.fold_left (fun acc (lib,path) ->
if Astring.String.take ~sat:((<>) '.') lib <> pkg then
let dirs = Libraries.find_opt lib acc |> Option.value ~default:Dir_set.empty in
Libraries.add lib (Dir_set.add path dirs) acc
else
acc) libs) Libraries.empty

let get_external_lib_deps ~pkg ~target : t = lib_deps ~pkg ~target
2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(executable
(public_name opam-dune-lint)
(name main)
(libraries astring fmt fmt.tty bos opam-format opam-state cmdliner stdune sexplib str))
(libraries astring fmt fmt.cli fmt.tty bos opam-format opam-state cmdliner stdune sexplib str))
9 changes: 6 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
(lang dune 2.7)
(lang dune 3.7)
(name opam-dune-lint)

(formatting disabled)
(generate_opam_files true)
(cram enable)

(source (github ocurrent/opam-dune-lint))
(authors "talex5@gmail.com")
(maintainers "talex5@gmail.com")
(license ISC)
(cram enable)

(package
(name opam-dune-lint)
(synopsis "Ensure dune and opam dependencies are consistent")
Expand All @@ -17,7 +20,7 @@
(sexplib (>= v0.14.0))
(cmdliner (>= 1.1.0))
(stdune (>= 3.0))
(ocaml (>= 4.10.0))
(ocaml (>= 4.13.0))
(bos (>= 0.2.0))
(fmt (>= 0.8.9))
(opam-state (>= 2.0.9))
Expand Down
2 changes: 1 addition & 1 deletion dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let update (changes:(_ * Change.t list) Paths.t) (t:t) =
match package_name items with
| None -> failwith "Missing 'name' in (package)!"
| Some name ->
match Paths.find_opt (name ^ ".opam") changes with
match Paths.find_opt (String.cat name ".opam") changes with
| None -> items
| Some (_opam, changes) -> update_or_create "depends" (apply_changes ~changes) items
in
Expand Down
16 changes: 11 additions & 5 deletions main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ let confirm_with_user () =
false
)

let main force dir =
let main () force dir =
Sys.chdir dir;
let index = Index.create () in
let old_opam_files = get_opam_files () in
Expand Down Expand Up @@ -178,6 +178,14 @@ let main force dir =

open Cmdliner

let setup_fmt style_renderer =
Fmt_tty.setup_std_outputs ?style_renderer ();
()

let setup_fmt =
let docs = Manpage.s_common_options in
Term.(const setup_fmt $ Fmt_cli.style_renderer ~docs ())

let dir =
Arg.value @@
Arg.pos 0 Arg.dir "." @@
Expand All @@ -196,9 +204,7 @@ let force =
let cmd =
let doc = "keep dune and opam files in sync" in
let info = Cmd.info "opam-dune-lint" ~doc in
let term = Term.(const main $ force $ dir) in
let term = Term.(const main $ setup_fmt $ force $ dir) in
Cmd.v info term

let () =
Fmt_tty.setup_std_outputs ();
exit @@ Cmd.eval cmd
let () = exit @@ Cmd.eval cmd
Empty file removed main.mli
Empty file.
4 changes: 2 additions & 2 deletions opam-dune-lint.opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ license: "ISC"
homepage: "https://github.com/ocurrent/opam-dune-lint"
bug-reports: "https://github.com/ocurrent/opam-dune-lint/issues"
depends: [
"dune" {>= "2.7"}
"dune" {>= "3.7"}
"astring" {>= "0.8.5"}
"sexplib" {>= "v0.14.0"}
"cmdliner" {>= "1.1.0"}
"stdune" {>= "3.0"}
"ocaml" {>= "4.10.0"}
"ocaml" {>= "4.13.0"}
"bos" {>= "0.2.0"}
"fmt" {>= "0.8.9"}
"opam-state" {>= "2.0.9"}
Expand Down