Skip to content

Commit cf7dec1

Browse files
Alidrafblanqui
andauthored
Fix display of version (#336)
This PR fixes the display of Dedukti version (#300) when called in command line (for instance dk --version). * fix of modules in dune file (add misc/gen_version.ml) * remove variable version in subcommands because it is useless --------- Co-authored-by: Frédéric Blanqui <[email protected]>
1 parent 8a9bece commit cf7dec1

File tree

9 files changed

+36
-8
lines changed

9 files changed

+36
-8
lines changed

commands/dkcheck.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ let cmd =
136136
`P "Report bugs to <[email protected]>.";
137137
]
138138
in
139-
Cmd.v (Cmd.info "check" ~version:"%%VERSION%%" ~doc ~man) cmd_t
139+
Cmd.v (Cmd.info "check" ~doc ~man) cmd_t

commands/dkdep.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ let cmd_t = Term.(const dkdep $ Config.t $ ignore $ output $ sort $ files)
103103

104104
let cmd =
105105
let doc = "Dependency list generator for Dedukti files" in
106-
Cmd.(v (info "dep" ~version:"%%VERSION%%" ~doc) cmd_t)
106+
Cmd.(v (info "dep" ~doc) cmd_t)

commands/dkmeta.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ let cmd_t =
115115

116116
let cmd =
117117
let doc = "Transform dk signatures using dk." in
118-
Cmdliner.Cmd.(v (info "meta" ~doc ~version:"%%VERSION%%") cmd_t)
118+
Cmdliner.Cmd.(v (info "meta" ~doc) cmd_t)

commands/dkpretty.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ let cmd_t = Term.(const beautify $ Config.t $ files)
2828
let cmd =
2929
let doc = "Pretty print Dedukti files" in
3030
let man = [] in
31-
Cmd.(v (info "beautify" ~version:"%%VERSION%%" ~doc ~man) cmd_t)
31+
Cmd.(v (info "beautify" ~doc ~man) cmd_t)

commands/dkprune.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,4 @@ let cmd_t = Cmdliner.Term.(const prune $ Config.t $ log $ output $ files)
303303

304304
let cmd =
305305
let doc = "Compute dependencies of a set of Dedukti files." in
306-
Cmdliner.Cmd.(v (info "prune" ~version:"%%VERSION%%" ~doc) cmd_t)
306+
Cmdliner.Cmd.(v (info "prune" ~doc) cmd_t)

commands/dktop.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ let cmd_t = Cmdliner.Term.(const top $ Config.t)
1313

1414
let cmd =
1515
let doc = "Run a read-eval-print-loop using dk-check." in
16-
Cmdliner.Cmd.(v (info "top" ~doc ~version:"%%VERSION%%") cmd_t)
16+
Cmdliner.Cmd.(v (info "top" ~doc) cmd_t)

commands/dune

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
(rule
2+
(targets version.ml)
3+
(action
4+
(with-stdout-to version.ml
5+
(run ocaml -I +unix unix.cma %{dep:../misc/gen_version.ml})))
6+
(mode fallback))
7+
18
(executable
29
(name main)
3-
(modules main dkcheck dkdep dkpretty dkprune dkmeta dktop config)
10+
(modules main dkcheck dkdep dkpretty dkprune dkmeta dktop config version)
411
(public_name dk)
512
(package dedukti)
613
(libraries cmdliner kernel parsers api))

commands/main.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ let default_i =
1313
Dedukti language.";
1414
]
1515
in
16-
Cmd.info "dk" ~version:"%%VERSION%%" ~doc ~sdocs ~man
16+
let version = Version.version in
17+
Cmd.info "dk" ~version ~doc ~sdocs ~man
1718

1819
let cmds =
1920
[Dkcheck.cmd; Dkdep.cmd; Dkpretty.cmd; Dkprune.cmd; Dkmeta.cmd; Dktop.cmd]

misc/gen_version.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
let version =
2+
(* Trick to check whether the watermark has been substituted. *)
3+
if "%%VERSION%%" <> "%%" ^ "VERSION%%" then "%%VERSION%%" else
4+
(* If not, we fallback to git version. *)
5+
let cmd = "git describe --dirty --always" in
6+
let (oc, ic, ec) = Unix.open_process_full cmd (Unix.environment ()) in
7+
let version =
8+
try Printf.sprintf "dev-%s" (input_line oc)
9+
with End_of_file -> "unknown"
10+
in
11+
match Unix.close_process_full (oc, ic, ec) with
12+
| Unix.WEXITED(0) -> version
13+
| _ -> "unknown"
14+
15+
let _ =
16+
let line fmt = Format.printf (fmt ^^ "@.") in
17+
line "(** Version informations. *)";
18+
line "";
19+
line "(** [version] gives a version description. *)";
20+
line "let version : string = %S" version

0 commit comments

Comments
 (0)