| 1 |
(**************************************************************************) |
| 2 |
(* *) |
| 3 |
(* Copyright 2012-2015 OCamlPro *) |
| 4 |
(* Copyright 2012 INRIA *) |
| 5 |
(* *) |
| 6 |
(* All rights reserved. This file is distributed under the terms of the *) |
| 7 |
(* GNU Lesser General Public License version 2.1, with the special *) |
| 8 |
(* exception on linking described in the file LICENSE. *) |
| 9 |
(* *) |
| 10 |
(**************************************************************************) |
| 11 |
|
| 12 |
type t = string |
| 13 |
|
| 14 |
let to_string x = x |
| 15 |
|
| 16 |
let of_string x = x |
| 17 |
|
| 18 |
let to_json x = `String x |
| 19 |
|
| 20 |
let of_json = function |
| 21 |
| `String x -> Some x |
| 22 |
| _ -> None |
| 23 |
|
| 24 |
let compare v w = OpamVersionCompare.compare v w |
| 25 |
let equal v w = compare v w = 0 |
| 26 |
|
| 27 |
module O = struct |
| 28 |
type t = string |
| 29 |
let to_string = to_string |
| 30 |
let to_json = to_json |
| 31 |
let of_json = of_json |
| 32 |
let compare = compare |
| 33 |
end |
| 34 |
|
| 35 |
module Set = OpamStd.Set.Make(O) |
| 36 |
|
| 37 |
module Map = OpamStd.Map.Make(O) |
| 38 |
|
| 39 |
let current_raw = OpamVersionInfo.version |
| 40 |
|
| 41 |
let current = of_string current_raw |
| 42 |
|
| 43 |
let major v = |
| 44 |
try |
| 45 |
let i = String.index v '.' in |
| 46 |
of_string (String.sub v 0 i) |
| 47 |
with Not_found -> v |
| 48 |
|
| 49 |
let nopatch v = |
| 50 |
try |
| 51 |
let i = String.index v '.' in |
| 52 |
let i = String.index_from v (i+1) '.' in |
| 53 |
(String.sub v 0 i) |
| 54 |
with Not_found -> |
| 55 |
let rec f i = |
| 56 |
if i >= String.length v then v |
| 57 |
else match String.get v i with |
| 58 |
| '0'..'9' | '.' -> f (i+1) |
| 59 |
| _ -> String.sub v 0 i |
| 60 |
in |
| 61 |
f 0 |
| 62 |
|
| 63 |
let current_nopatch = nopatch current_raw |
| 64 |
|
| 65 |
let message () = |
| 66 |
OpamConsole.msg "\n\ |
| 67 |
%s version %s\n\ |
| 68 |
\n\ |
| 69 |
Copyright (C) 2012 OCamlPro - INRIA, 2013-2015 OCamlPro\n\ |
| 70 |
\n\ |
| 71 |
This is free software; see the source for copying conditions. There is NO\n\ |
| 72 |
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
| 73 |
Sys.executable_name current_raw; |
| 74 |
exit 0 |
| 75 |
|
| 76 |
let gitversion = ref None |
| 77 |
|
| 78 |
let set_git s = gitversion := Some s |
| 79 |
|
| 80 |
let git () = |
| 81 |
match !gitversion with |
| 82 |
| None -> None |
| 83 |
| Some v -> Some (of_string v) |
| 84 |
|
| 85 |
let is_dev_version () = |
| 86 |
(!gitversion <> None) |
| 87 |
|
| 88 |
let full () = |
| 89 |
let git_version = match git () with |
| 90 |
| None -> "" |
| 91 |
| Some v -> Printf.sprintf " (%s)" (to_string v) in |
| 92 |
Printf.sprintf "%s%s" (to_string current) git_version |
| 93 |
|
| 94 |
let magic () = |
| 95 |
let hash = Hashtbl.hash (full ()) in |
| 96 |
String.sub (Printf.sprintf "%08X" hash) 0 8 |