package opam-core

  1. Overview
  2. Docs

Source file opamVersion.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(**************************************************************************)
(*                                                                        *)
(*    Copyright 2012-2015 OCamlPro                                        *)
(*    Copyright 2012 INRIA                                                *)
(*                                                                        *)
(*  All rights reserved. This file is distributed under the terms of the  *)
(*  GNU Lesser General Public License version 2.1, with the special       *)
(*  exception on linking described in the file LICENSE.                   *)
(*                                                                        *)
(**************************************************************************)

type t = string

let to_string x = x

let of_string x = x

let to_json x = `String x

let compare v w = OpamVersionCompare.compare v w

module O = struct
  type t = string
  let to_string = to_string
  let to_json = to_json
  let compare = compare
end

module Set = OpamStd.Set.Make(O)

module Map = OpamStd.Map.Make(O)

let current_raw = "2.0.8"

let current = of_string current_raw

let major v =
  try
    let i = String.index v '.' in
    of_string (String.sub v 0 i)
  with Not_found -> v

let nopatch v =
  try
    let i = String.index v '.' in
    let i = String.index_from v (i+1) '.' in
    (String.sub v 0 i)
  with Not_found ->
    let rec f i =
      if i >= String.length v then v
      else match String.get v i with
        | '0'..'9' | '.' -> f (i+1)
        | _ -> String.sub v 0 i
    in
    f 0

let current_nopatch = nopatch current_raw

let message () =
  OpamConsole.msg "\n\
    %s version %s\n\
    \n\
    Copyright (C) 2012 OCamlPro - INRIA, 2013-2015 OCamlPro\n\
    \n\
    This is free software; see the source for copying conditions.  There is NO\n\
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
    Sys.argv.(0) current_raw;
  exit 0

let gitversion = ref None

let set_git s = gitversion := Some s

let git () =
  match !gitversion with
  | None   -> None
  | Some v -> Some (of_string v)

let full () =
  let git_version = match git () with
    | None   -> ""
    | Some v -> Printf.sprintf " (%s)" (to_string v) in
  Printf.sprintf "%s%s" (to_string current) git_version

let magic () =
  let hash = Hashtbl.hash (full ()) in
  String.sub (Printf.sprintf "%08X" hash) 0 8
OCaml

Innovation. Community. Security.