package opam_bin_lib

  1. Overview
  2. Docs

Source file config.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
(**************************************************************************)
(*                                                                        *)
(*    Copyright 2020 OCamlPro & Origin Labs                               *)
(*                                                                        *)
(*  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.                   *)
(*                                                                        *)
(**************************************************************************)

open EzConfig.OP

let config_filename = Globals.config_file
let config = EzConfig.create_config_file
    ( EzFile.Abstract.of_string config_filename )

let save () =
  EzConfig.save_with_help config;
  Printf.eprintf "%s config saved in %s .\n%!"
    Globals.command Globals.config_file

let base_url = EzConfig.create_option config
    [ "base_url" ]
    [
      "The `base url` of the website where the archives folder will be stored";
      "if you want to share your binary packages.";
      Printf.sprintf
        "Locally, the archives folder is stored in $HOME/.opam/%s/store ."
        Globals.command ;
    ]
    EzConfig.string_option
    "/change-this-option"

let rsync_url = EzConfig.create_option config
    [ "rsync_url" ]
    [
      Printf.sprintf
        "This is the argument passed to rsync when calling `%s push`."
        Globals.command ;
      "The directory should exist on the remote server.";
    ]
    (EzConfig.option_option EzConfig.string_option)
    None

let patches_url = EzConfig.create_option config
    [ "patches_url" ]
    [
      "The path to the repository containing relocation patches";
      "Either using GIT (git@), local (file://) or an http archive";
      "(https://.../x.tar.gz).";
      "Example: git@github.com:OCamlPro/relocation-patches";
    ]
    EzConfig.string_option
    "https://www.typerex.org/opam-bin/relocation-patches.tar.gz"

let title = EzConfig.create_option config
    [ "title" ]
    [
      "The title of the repository in the index.html generated by";
      Printf.sprintf
        "`opam-bin push`. Only used if %s is not defined."
        Globals.opambin_header_html;
    ]
    EzConfig.string_option
    "Repository of Binary Packages"

let enabled = EzConfig.create_option config
    [ "enabled" ]
    [ "Whether we do something or not. When [true], existing binary packages";
      "will be used instead of equivalent source packages";]
    EzConfig.bool_option
    true

let create_enabled = EzConfig.create_option config
    [ "create_enabled" ]
    [ "Whether we produce binary packages after installing source packages" ]
    EzConfig.bool_option
    true

let share_enabled = EzConfig.create_option config
    [ "share_enabled" ]
    [ "Whether we share binary files between switches (default: disabled)" ]
    EzConfig.bool_option
    false

let all_switches = EzConfig.create_option config
    [ "all_switches" ]
    [ "Whether we use a binary package for all switches. The config variable" ;
      "`switches` will only be used if this variable is false";
    ]
    EzConfig.bool_option
    true

let switches = EzConfig.create_option config
    [ "switches" ]
    [ "This list of switches (or regexp such as '*bin') for which" ;
      "creating/caching binary packages should be used" ]
    ( EzConfig.list_option EzConfig.string_option )
    []

let protected_switches = EzConfig.create_option config
    [ "protected_switches" ]
    [ "This list of switches (or regexp such as '*bin') for which" ;
      "creating/caching binary packages should NOT be used" ]
    ( EzConfig.list_option EzConfig.string_option )
    []

let current_version = 1
(* This option should be used in the future to automatically upgrade
   configuration *)
let version = EzConfig.create_option config
    [ "version" ]
    [ "Version of the configuration file" ]
    EzConfig.int_option
    current_version

let () =
  try
    EzConfig.load config
  with _ ->
    Printf.eprintf "No configuration file.\n%!"

let () =
  if !!version < current_version then begin
    version =:= current_version ;
    save ()
  end