Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace the ugly shell script into a awesome ocamlscript

We update src/core/opamGitVersion.ml only if the current git revision has really changed
  • Loading branch information...
commit 99fb4058649bc021582702ffb445c8c0d2b2e644 1 parent ae9a43b
@samoht samoht authored
Showing with 41 additions and 17 deletions.
  1. +3 −6 Makefile
  2. +38 −0 shell/get-git-id.ml
  3. +0 −11 shell/get-git-id.sh
View
9 Makefile
@@ -103,12 +103,9 @@ src/core/opamVersion.ml:
@echo
@exit 1
-.git/refs/heads/master:
- mkdir -p .git/refs/heads/
- touch $<
-
-src/core/opamGitVersion.ml: .git/HEAD
- ./shell/get-git-id.sh > $@
+.PHONY: src/core/opamGitVersion.ml
+src/core/opamGitVersion.ml:
+ ocaml shell/get-git-id.ml $@
src/core/opamScript.ml: shell/ src/core/opamVersion.ml
ocaml shell/crunch.ml "complete" < shell/opam_completion.sh > $@
View
38 shell/get-git-id.ml
@@ -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"
View
11 shell/get-git-id.sh
@@ -1,11 +0,0 @@
-#!/bin/sh -e
-
-trap 'echo "let version = None"' INT TERM EXIT
-
-if [ -e .git/logs/HEAD ]; then
- describe=`git rev-parse HEAD`
- echo let version = Some \"${describe}\"
- trap - INT TERM EXIT
-else
- echo "let version = None"
-fi
Please sign in to comment.
Something went wrong with that request. Please try again.