Skip to content

Commit

Permalink
Replace the ugly shell script into a awesome ocamlscript
Browse files Browse the repository at this point in the history
We update src/core/opamGitVersion.ml only if the current git revision has really changed
  • Loading branch information
samoht committed Apr 10, 2013
1 parent ae9a43b commit 99fb405
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
9 changes: 3 additions & 6 deletions Makefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -103,12 +103,9 @@ src/core/opamVersion.ml:
@echo @echo
@exit 1 @exit 1


.git/refs/heads/master: .PHONY: src/core/opamGitVersion.ml
mkdir -p .git/refs/heads/ src/core/opamGitVersion.ml:
touch $< ocaml shell/get-git-id.ml $@

src/core/opamGitVersion.ml: .git/HEAD
./shell/get-git-id.sh > $@


src/core/opamScript.ml: shell/ src/core/opamVersion.ml src/core/opamScript.ml: shell/ src/core/opamVersion.ml
ocaml shell/crunch.ml "complete" < shell/opam_completion.sh > $@ ocaml shell/crunch.ml "complete" < shell/opam_completion.sh > $@
Expand Down
38 changes: 38 additions & 0 deletions shell/get-git-id.ml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,38 @@
let file =
if Array.length Sys.argv <> 2 then (
Printf.eprintf "usage: ocaml %s <file>\n" Sys.argv.(0);
exit 1
) else
Sys.argv.(1)

let read file =
let ic = open_in_bin file in
input_line ic

let write file contents =
let write () =
let oc = open_out file in
output_string oc contents;
output_char oc '\n';
close_out oc in
if Sys.file_exists file then (
let actual = read file in
if actual <> contents then write ()
) else
write ()

let (/) = Filename.concat

let git file = ".git" / file

let () =
let opamGitVersion = "src" / "core" / "opamGitVersion.ml" in
if Sys.file_exists (git "HEAD") then (
let reference =
let s = read (git "HEAD") in
let c = String.rindex s ' ' in
String.sub s (c+1) (String.length s -c-1) in
let sha1 = read (git reference) in
write opamGitVersion (Printf.sprintf "let version = Some %S" sha1)
) else
write opamGitVersion "let version = None"
11 changes: 0 additions & 11 deletions shell/get-git-id.sh

This file was deleted.

0 comments on commit 99fb405

Please sign in to comment.