From 8c9e3748f56aa54a17c9257ba8b76c4b0f28bb72 Mon Sep 17 00:00:00 2001 From: rand00 Date: Thu, 7 Apr 2022 13:39:37 +0200 Subject: [PATCH 1/4] Main: Made 'html' render option output the same as we use at Robur --- app/main.ml | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/app/main.ml b/app/main.ml index d51fb19..66f12ea 100644 --- a/app/main.ml +++ b/app/main.ml @@ -12,24 +12,39 @@ let read_file file = with _ -> invalid_arg ("Error opening file " ^ file) let jump () transitive file output_format = + let module G = Opam_graph in let switch = read_file file in let data = OpamFile.SwitchExport.read_from_string switch in match output_format with | `Text -> - let graph = Opam_graph.dependencies ~transitive data in - Format.printf "%a" Opam_graph.pp_graph graph + let graph = G.dependencies ~transitive data in + Format.printf "%a" G.pp_graph graph | `Dot -> - let graph = Opam_graph.dependencies ~transitive data in - let dot = Opam_graph.Render.Dot.of_graph graph in - Format.printf "%a" Opam_graph.Render.Dot.pp dot + let graph = G.dependencies ~transitive data in + let dot = G.Render.Dot.of_graph graph in + Format.printf "%a" G.Render.Dot.pp dot | `Dot_ui -> - let graph = Opam_graph.Ui.dependencies ~transitive data in - let dot = Opam_graph.Render.Dot.of_assoc graph in - Format.printf "%a" Opam_graph.Render.Dot.pp dot + let graph = G.Ui.dependencies ~transitive data in + let dot = G.Render.Dot.of_assoc graph in + Format.printf "%a" G.Render.Dot.pp dot | `Html -> - let graph = Opam_graph.Ui.dependencies ~transitive data in - let html = Opam_graph.Render.Html.of_assoc graph in - Format.printf "%a" Opam_graph.Render.Html.pp html + let graph = G.Ui.dependencies ~transitive data in + let sharing_stats = + data + |> G.dependencies ~transitive:false + |> G.calc_sharing_stats in + let override_css = "\ + .deps-svg-wrap {\ + background: rgb(60, 60, 87); \ + }\ + " + in + let html = + G.Render.Html.of_assoc + ~override_css + ~sharing_stats graph + in + Format.printf "%a" G.Render.Html.pp html let setup_log style_renderer level = Fmt_tty.setup_std_outputs ?style_renderer (); From 621933fb51565d2c9ee4a2192b91db4b0fc24287 Mon Sep 17 00:00:00 2001 From: rand00 Date: Mon, 11 Apr 2022 00:22:28 +0200 Subject: [PATCH 2/4] Changed name of binary to opam-graph, to be consistent with existing tools --- app/dune | 2 +- app/main.ml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dune b/app/dune index 2fe3b23..1a70a81 100644 --- a/app/dune +++ b/app/dune @@ -1,4 +1,4 @@ (executable (name main) - (public_name opam_graph) + (public_name opam-graph) (libraries cmdliner logs logs.fmt fmt.cli fmt.tty logs.cli opam-graph)) diff --git a/app/main.ml b/app/main.ml index 66f12ea..5ba8a26 100644 --- a/app/main.ml +++ b/app/main.ml @@ -78,7 +78,7 @@ let file = let cmd = let term = Term.(const jump $ setup_log $ transitive $ file $ output_format) in - let info = Cmd.info "opam_graph" ~version:"%%VERSION%%" in + let info = Cmd.info "opam-graph" ~version:"%%VERSION%%" in Cmd.v info term let () = Cmd.eval cmd |> exit From d1cb3de48fe11adcaeff04c9e3a7bd0774f0672f Mon Sep 17 00:00:00 2001 From: rand00 Date: Mon, 11 Apr 2022 12:50:04 +0200 Subject: [PATCH 3/4] Opam_graph: Added visualization-version number --- src/opam_graph.ml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/opam_graph.ml b/src/opam_graph.ml index b9b5f9d..40942bc 100644 --- a/src/opam_graph.ml +++ b/src/opam_graph.ml @@ -1,4 +1,12 @@ +let visualization_version = 1 +(** Remember to increment this when anything changes that can affect the + visualization, e.g.: + * algorithm change + * UI change + * certain library-dependency changes +*) + let sprintf = Printf.sprintf module OSet = OpamPackage.Set From 9374398607c8eb639d56fdf98f501bd9ba607ccd Mon Sep 17 00:00:00 2001 From: rand00 Date: Thu, 28 Apr 2022 16:08:06 +0200 Subject: [PATCH 4/4] Switched to using --version for printing visualization-version - will not be the same as library version --- app/main.ml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/main.ml b/app/main.ml index 5ba8a26..efa567c 100644 --- a/app/main.ml +++ b/app/main.ml @@ -77,8 +77,15 @@ let file = Arg.(required & pos 0 (some file) None & info [ ] ~doc ~docv:"FILE") let cmd = - let term = Term.(const jump $ setup_log $ transitive $ file $ output_format) in - let info = Cmd.info "opam-graph" ~version:"%%VERSION%%" in + let term = Term.( + const jump + $ setup_log + $ transitive + $ file + $ output_format + ) in + let version = Fmt.str "%d" Opam_graph.visualization_version in + let info = Cmd.info "opam-graph" ~version in Cmd.v info term let () = Cmd.eval cmd |> exit