Reify the git environment at compile time into the code
Use it to output a minimal `./tezos-node --version` Works both when you compile inside a git repository or from an archive generated by `git archive` (which is what gitlab does when you click on "Download zip/tar.gz/tar.bz2" in the web interface)
This commit is contained in:
parent
a35f7a0de5
commit
7bcd3892b7
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.gitignore export-ignore
|
||||||
|
.gitattributes export-ignore
|
||||||
|
.gitlab-ci.yml export-ignore
|
||||||
|
src/lib_base/current_git_info.ml export-subst
|
@ -51,9 +51,13 @@ let man =
|
|||||||
Node_run_command.Manpage.examples
|
Node_run_command.Manpage.examples
|
||||||
|
|
||||||
let info =
|
let info =
|
||||||
|
let version =
|
||||||
|
Tezos_base.Current_git_info.abbreviated_commit_hash ^
|
||||||
|
" ("^Tezos_base.Current_git_info.committer_date^")" in
|
||||||
Cmdliner.Term.info
|
Cmdliner.Term.info
|
||||||
~doc:"The Tezos node"
|
~doc:"The Tezos node"
|
||||||
~man
|
~man
|
||||||
|
~version
|
||||||
"tezos-node"
|
"tezos-node"
|
||||||
|
|
||||||
let commands = [
|
let commands = [
|
||||||
|
45
src/lib_base/current_git_info.ml
Normal file
45
src/lib_base/current_git_info.ml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
(*****************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* Open Source License *)
|
||||||
|
(* Copyright (c) 2019 Nomadic Labs, <contact@nomadic-labs.com> *)
|
||||||
|
(* *)
|
||||||
|
(* Permission is hereby granted, free of charge, to any person obtaining a *)
|
||||||
|
(* copy of this software and associated documentation files (the "Software"),*)
|
||||||
|
(* to deal in the Software without restriction, including without limitation *)
|
||||||
|
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
|
||||||
|
(* and/or sell copies of the Software, and to permit persons to whom the *)
|
||||||
|
(* Software is furnished to do so, subject to the following conditions: *)
|
||||||
|
(* *)
|
||||||
|
(* The above copyright notice and this permission notice shall be included *)
|
||||||
|
(* in all copies or substantial portions of the Software. *)
|
||||||
|
(* *)
|
||||||
|
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
|
||||||
|
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
|
||||||
|
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
|
||||||
|
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
|
||||||
|
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
|
||||||
|
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
|
||||||
|
(* DEALINGS IN THE SOFTWARE. *)
|
||||||
|
(* *)
|
||||||
|
(*****************************************************************************)
|
||||||
|
|
||||||
|
let raw_commit_hash = "$Format:%H$"
|
||||||
|
|
||||||
|
let commit_hash =
|
||||||
|
if String.equal raw_commit_hash ("$Format:"^"%H$"(*trick to avoid git-subst*))
|
||||||
|
then Generated_git_info.commit_hash
|
||||||
|
else raw_commit_hash
|
||||||
|
|
||||||
|
let raw_abbreviated_commit_hash = "$Format:%h$"
|
||||||
|
|
||||||
|
let abbreviated_commit_hash =
|
||||||
|
if String.equal raw_abbreviated_commit_hash ("$Format:"^"%h$")
|
||||||
|
then Generated_git_info.abbreviated_commit_hash
|
||||||
|
else raw_abbreviated_commit_hash
|
||||||
|
|
||||||
|
let raw_committer_date = "$Format:%ci$"
|
||||||
|
|
||||||
|
let committer_date =
|
||||||
|
if String.equal raw_committer_date ("$Format:"^"%ci$")
|
||||||
|
then Generated_git_info.committer_date
|
||||||
|
else raw_committer_date
|
28
src/lib_base/current_git_info.mli
Normal file
28
src/lib_base/current_git_info.mli
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
(*****************************************************************************)
|
||||||
|
(* *)
|
||||||
|
(* Open Source License *)
|
||||||
|
(* Copyright (c) 2019 Nomadic Labs, <contact@nomadic-labs.com> *)
|
||||||
|
(* *)
|
||||||
|
(* Permission is hereby granted, free of charge, to any person obtaining a *)
|
||||||
|
(* copy of this software and associated documentation files (the "Software"),*)
|
||||||
|
(* to deal in the Software without restriction, including without limitation *)
|
||||||
|
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
|
||||||
|
(* and/or sell copies of the Software, and to permit persons to whom the *)
|
||||||
|
(* Software is furnished to do so, subject to the following conditions: *)
|
||||||
|
(* *)
|
||||||
|
(* The above copyright notice and this permission notice shall be included *)
|
||||||
|
(* in all copies or substantial portions of the Software. *)
|
||||||
|
(* *)
|
||||||
|
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
|
||||||
|
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
|
||||||
|
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
|
||||||
|
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
|
||||||
|
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
|
||||||
|
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
|
||||||
|
(* DEALINGS IN THE SOFTWARE. *)
|
||||||
|
(* *)
|
||||||
|
(*****************************************************************************)
|
||||||
|
|
||||||
|
val commit_hash : string
|
||||||
|
val abbreviated_commit_hash : string
|
||||||
|
val committer_date : string
|
@ -1,6 +1,7 @@
|
|||||||
(library
|
(library
|
||||||
(name tezos_base)
|
(name tezos_base)
|
||||||
(public_name tezos-base)
|
(public_name tezos-base)
|
||||||
|
(modules :standard \ Get-git-info)
|
||||||
(flags (:standard -w -30
|
(flags (:standard -w -30
|
||||||
-open Tezos_stdlib
|
-open Tezos_stdlib
|
||||||
-open Tezos_crypto
|
-open Tezos_crypto
|
||||||
@ -24,6 +25,11 @@
|
|||||||
mtime.clock.os
|
mtime.clock.os
|
||||||
ipaddr.unix))
|
ipaddr.unix))
|
||||||
|
|
||||||
|
(rule
|
||||||
|
(targets generated_git_info.ml)
|
||||||
|
(deps get-git-info.ml)
|
||||||
|
(action (with-stdout-to %{targets} (run %{ocaml} unix.cma %{deps}))))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
(name runtest_indent)
|
(name runtest_indent)
|
||||||
(deps (glob_files *.ml{,i}))
|
(deps (glob_files *.ml{,i}))
|
||||||
|
19
src/lib_base/get-git-info.ml
Executable file
19
src/lib_base/get-git-info.ml
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env ocaml
|
||||||
|
|
||||||
|
#load "unix.cma"
|
||||||
|
|
||||||
|
let query cmd =
|
||||||
|
let chan = Unix.open_process_in cmd in
|
||||||
|
try
|
||||||
|
let out = input_line chan in
|
||||||
|
if Unix.close_process_in chan = Unix.WEXITED 0 then out
|
||||||
|
else "unkown"
|
||||||
|
with End_of_file -> "unkown"
|
||||||
|
|
||||||
|
let () =
|
||||||
|
Format.printf "@[<v>let commit_hash = \"%s\"@,"
|
||||||
|
(query "git show -s --pretty=format:%H");
|
||||||
|
Format.printf "let abbreviated_commit_hash = \"%s\"@,"
|
||||||
|
(query "git show -s --pretty=format:%h");
|
||||||
|
Format.printf "let committer_date = \"%s\"@]@."
|
||||||
|
(query "git show -s --pretty=format:%ci")
|
Loading…
Reference in New Issue
Block a user