-
Notifications
You must be signed in to change notification settings - Fork 373
/
Copy pathopamInitDefaults.ml
177 lines (154 loc) · 5.53 KB
/
opamInitDefaults.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
(**************************************************************************)
(* *)
(* Copyright 2016-2019 OCamlPro *)
(* *)
(* 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 OpamTypes
let repository_url = {
OpamUrl.
transport = "https";
path = "opam.ocaml.org";
hash = None;
backend = `http;
}
let default_compiler =
OpamFormula.Atom (OpamPackage.Name.of_string "ocaml-base-compiler",
OpamFormula.Empty)
let default_invariant =
OpamFormula.Atom
(OpamPackage.Name.of_string "ocaml",
OpamFormula.Atom
(`Geq, OpamPackage.Version.of_string "4.05.0"))
let sys_ocaml_version =
OpamVariable.of_string "sys-ocaml-version", ["ocamlc"; "-vnum"],
"OCaml version present on your system independently of opam, if any"
let eval_variables =
sys_ocaml_version :: OpamEnv.sys_ocaml_eval_variables
let os_filter os =
FOp (FIdent ([], OpamVariable.of_string "os", None), `Eq, FString os)
let linux_filter = os_filter "linux"
let macos_filter = os_filter "macos"
let openbsd_filter = os_filter "openbsd"
let freebsd_filter = os_filter "freebsd"
let netbsd_filter = os_filter "netbsd"
let dragonflybsd_filter = os_filter "dragonfly"
let not_bsd_filter =
FNot (FOr (FOr (openbsd_filter, netbsd_filter),
FOr (freebsd_filter, dragonflybsd_filter)))
let win32_filter = os_filter "win32"
let not_win32_filter =
FOp (FIdent ([], OpamVariable.of_string "os", None), `Neq, FString "win32")
let sandbox_filter = FOr (linux_filter, macos_filter)
let gpatch_filter =
FOr (FOr (openbsd_filter, netbsd_filter),
FOr (freebsd_filter, FOr (dragonflybsd_filter, macos_filter)))
let patch_filter = FNot gpatch_filter
let gtar_filter = openbsd_filter
let tar_filter = FNot gtar_filter
let getconf_filter = FNot (FOr (win32_filter, freebsd_filter))
let sandbox_wrappers =
let cmd t = [
CString "%{hooks}%/sandbox.sh", None;
CString t, None;
] in
[ `build [cmd "build", Some sandbox_filter];
`install [cmd "install", Some sandbox_filter];
`remove [cmd "remove", Some sandbox_filter];
]
let wrappers ~sandboxing () =
let w = OpamFile.Wrappers.empty in
if sandboxing then
List.fold_left OpamFile.Wrappers.(fun w -> function
| `build wrap_build -> { w with wrap_build }
| `install wrap_install -> { w with wrap_install }
| `remove wrap_remove -> { w with wrap_remove }
) OpamFile.Wrappers.empty sandbox_wrappers
else w
let bwrap_cmd = "bwrap"
let bwrap_filter = linux_filter
let bwrap_string () = Printf.sprintf
"Sandboxing tool %s was not found. You should install 'bubblewrap'. \
See https://opam.ocaml.org/doc/FAQ.html#Why-does-opam-require-bwrap."
bwrap_cmd
let req_dl_tools () =
let msg =
Some "A download tool is required, check env variables OPAMCURL or OPAMFETCH"
in
(* Keep synchronised with [OpamRepositoryConfig.default] *)
let default =
[
(* BSDs have download tools (fetch or ftp) that are part of the
base system so there is no need to check for those tools. *)
["curl"; "wget"], msg, Some not_bsd_filter;
]
in
let open OpamStd.Option.Op in
let cmd =
(OpamRepositoryConfig.E.fetch_t ()
>>= fun s ->
match OpamStd.String.split s ' ' with
| c::_ -> Some c
| _ -> None)
>>+ fun () -> OpamRepositoryConfig.E.curl_t ()
in
match cmd with
| Some cmd ->
[[cmd], Some "Custom download tool, check OPAMCURL or OPAMFETCH", None]
| None -> default
let dl_tool () =
let open OpamStd.Option.Op in
(OpamRepositoryConfig.E.fetch_t ()
>>+ fun () -> OpamRepositoryConfig.E.curl_t ())
>>| fun cmd -> [(CString cmd), None]
let recommended_tools () =
let make = OpamStateConfig.(Lazy.force !r.makecmd) in
[
[make], None, None;
["cc"], None, Some not_win32_filter;
]
let required_tools ~sandboxing () =
req_dl_tools () @
[
["diff"], None, None;
["patch"], None, Some patch_filter;
["gpatch"], None, Some gpatch_filter;
["tar"], None, Some tar_filter;
["gtar"], None, Some gtar_filter;
["unzip"], None, None;
["getconf"], None, Some getconf_filter;
] @
if sandboxing then [
[bwrap_cmd], Some (bwrap_string()), Some bwrap_filter;
["sandbox-exec"], None, Some macos_filter;
] else []
let required_packages_for_cygwin =
[
"diffutils";
"make";
"patch";
"tar";
"unzip";
"rsync";
] |> List.map OpamSysPkg.of_string
let init_scripts () = [
("sandbox.sh", OpamScript.bwrap), Some bwrap_filter;
("sandbox.sh", OpamScript.sandbox_exec), Some macos_filter;
]
module I = OpamFile.InitConfig
let (@|) g f = OpamStd.Op.(g @* f) ()
let init_config ?(sandboxing=true) () =
I.empty |>
I.with_repositories
[OpamRepositoryName.of_string "default", (repository_url, None)] |>
I.with_default_compiler default_compiler |>
I.with_default_invariant default_invariant |>
I.with_eval_variables eval_variables |>
I.with_wrappers @| wrappers ~sandboxing |>
I.with_recommended_tools @| recommended_tools |>
I.with_required_tools @| required_tools ~sandboxing |>
I.with_init_scripts @| init_scripts |>
I.with_dl_tool @| dl_tool