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

Add support for DUNE_VCS_{DESCRIBE,COMMIT_ID,FILES} #11485

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 18 additions & 3 deletions src/dune_vcs/vcs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ let make_fun name ~git ~hg =
Staged.stage (Memo.exec memo)
;;

let env_or_unstage name =
match Sys.getenv_opt name with
| None -> Staged.unstage
| Some x -> fun _ _ -> Memo.return @@ Some x
;;

let describe =
Staged.unstage
env_or_unstage "DUNE_VCS_DESCRIBE"
@@ make_fun
"vcs-describe"
~git:(fun t -> run_git t [ "describe"; "--always"; "--dirty"; "--abbrev=7" ])
Expand All @@ -144,7 +150,7 @@ let describe =
;;

let commit_id =
Staged.unstage
env_or_unstage "DUNE_VCS_COMMIT_ID"
@@ make_fun
"vcs-commit-id"
~git:(fun t -> run_git t [ "rev-parse"; "HEAD" ])
Expand All @@ -154,6 +160,15 @@ let commit_id =
Some res)
;;

let env_or_unstage_paths name =
match Sys.getenv_opt name with
| None -> Staged.unstage
| Some x ->
fun _ _ ->
let l = Io.zero_strings_of_file @@ Path.of_string x in
Memo.return @@ List.map l ~f:Path.Source.of_string
;;

let files =
let run_zero_separated_hg t args =
Process.run_capture_zero_separated
Expand Down Expand Up @@ -185,7 +200,7 @@ let files =
let+ l = run t args in
List.map l ~f:Path.Source.of_string
in
Staged.unstage
env_or_unstage_paths "DUNE_VCS_FILES"
@@ make_fun
"vcs-files"
~git:(f run_zero_separated_git [ "ls-tree"; "-z"; "-r"; "--name-only"; "HEAD" ])
Expand Down
Loading