Skip to content

Commit 8ec873b

Browse files
authored
exposes git commit ID in the bap version (#1071)
* adds a build-id oasis variable * try with `with` param * play with var * wip * don't fail if we are not in a git repo * edited description * uses add_variable instead of var_define * no error message in case is not a git repo * catch all the exceptions * search for .git
1 parent 757733b commit 8ec873b

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/bap_main/bap_main.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,9 @@ let init
11611161
List.partition_map result ~f:(function
11621162
| Ok p -> `Fst p
11631163
| Error (p,e) -> `Snd (p,e)) in
1164+
let version = match Bap_main_config.build_id with
1165+
| "" -> version
1166+
| id -> sprintf "%s+%s" version id in
11641167
if List.is_empty failures
11651168
then match Grammar.eval argv
11661169
?name ~version ?env ?help:out

lib/bap_main/bap_main_config.ml.ab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ let suffix_program = "$suffix_program"
2828
let debug = "$debug"
2929
let profile = "$profile"
3030
let standard_library = "$standard_library"
31+
let build_id = "$build_id"

oasis/main.setup.ml.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
let () =
3+
add_variable "build_id"
4+
~doc:"Adds a build id to bap version"
5+
~define:(function
6+
| Some x -> x
7+
| None ->
8+
try
9+
if Sys.file_exists ".git" && Sys.is_directory ".git" then
10+
OASISExec.run_read_one_line ~ctxt
11+
~f_exit_code:ignore
12+
"git" ["rev-parse"; "--verify"; "--quiet"; "--short=7"; "HEAD"; ]
13+
else ""
14+
with _ -> "")

0 commit comments

Comments
 (0)