package opam_bin_lib

  1. Overview
  2. Docs

Source file globals.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
128
129
130
131
132
133
134
135
136
137
(**************************************************************************)
(*                                                                        *)
(*    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 Ez_file.V1
open EzFile.OP

let command = "opam-bin"
let about =
  Printf.sprintf "%s %s by OCamlPro SAS <contact@ocamlpro.com>"
    command Version.version

let home_dir = try Sys.getenv "HOME" with Not_found ->
  Printf.eprintf "Error: HOME variable not defined\n%!";
  exit 2


let opam_dir = try
    Sys.getenv "OPAMROOT"
  with Not_found -> home_dir // ".opam"

let command_exe = command ^ ".exe"
let command_log = command ^ ".log"
let command_info = command ^ ".info"

let opam_cache_dir = opam_dir // "download-cache"
let opam_repo_dir = opam_dir // "repo"
let opam_plugins_dir = opam_dir // "plugins"
let opam_plugins_bin_dir = opam_plugins_dir // "bin"
let opambin_dir = opam_plugins_dir // command
let opambin_bin = opambin_dir // command_exe
let opambin_info = opambin_dir // command_info
let opambin_store_dir = opambin_dir // "store"
let opambin_share_dir = opambin_dir // "share"
let opambin_cache_dir = opambin_dir // "cache"
let opambin_header_html = opambin_dir // "header.html"
let opambin_trailer_html = opambin_dir // "trailer.html"
let opambin_store_archives_dir = opambin_store_dir // "archives"
let opambin_store_repo_dir = opambin_store_dir // "repo"
let opambin_store_repo_packages_dir = opambin_store_repo_dir // "packages"
let opambin_patches_dir = opambin_dir // "patches"
let opambin_patches_temp_dir = opambin_dir // "patches.tmp"

let opam_config_file = opam_dir // "config"
let opam_config_file_backup = opam_config_file ^ ".1"
let opam_opambin_repo = "local-bin"

let opam_switch_prefix =
  lazy (
    try
      Sys.getenv "OPAM_SWITCH_PREFIX"
    with Not_found ->
      Printf.eprintf
        "Error in %s: OPAM_SWITCH_PREFIX not defined.\n%!"
        command ;
      exit 2
  )
let opam_switch_prefix () = Lazy.force opam_switch_prefix


let opam_switch_dir = opam_switch_prefix
let opam_switch_internal_dir () =
  opam_switch_dir () // ".opam-switch"

let opam_switch_internal_config_dir () =
  opam_switch_internal_dir () // "config"

let opam_switch_internal_build_dir () =
  opam_switch_internal_dir () // "build"

let opambin_switch_temp_dir () =
  opam_switch_internal_dir () // command

(* Where bin versions are stored to solve deps *)
let opambin_switch_packages_dir () =
  opam_switch_dir () // "etc" // command // "packages"

let opambin_log ~nvo =
  match nvo with
  | None -> opambin_dir // command_log
  | Some nvo ->
      opam_switch_internal_dir () // command // nvo ^ ".log"


let opambin_session_msg_file () =
  opam_switch_internal_dir () // ( command ^ ".msg" )

(* names of the files created in the package `files` sub-dir *)
let package_version = "bin-package.version"
let package_config = "bin-package.config"
let package_info = "bin-package.info"

let marker_skip = ".binskip"
let marker_cached = "_bincached"
let marker_source = ".binsource"
let marker_opam = ".binopam"
let marker_patch = ".binpatch"

let backup_marker ~name ext =
  opambin_switch_temp_dir () // ( name ^ ext )
let backup_skip ~name = backup_marker ~name ".skip"
let backup_opam ~name = backup_marker ~name ".opam"
let backup_source ~name = backup_marker ~name ".source"
let backup_patch ~name = backup_marker ~name ".patch"


let config_file = opambin_dir // "config"

let curdir = Sys.getcwd ()

let system = "debian-buster-x86_64"


(*

File structure:

$HOME/.opam
   plugins/opam-bin/
     opam-bin.exe
     opam-bin.log
     cache/
     store/
       archives/
       repo/
         packages/

$OPAM_SWITCH_PREFIX/
   etc/opam-bin/packages/$NAME

*)