forked from ocaml/opam
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file was deleted.
Oops, something went wrong.