-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.ml
263 lines (244 loc) · 9.47 KB
/
generate.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
open Stdcompat
type infos = {
utils_ml_hash: string;
configure_ml_hash: string;
}
let utils_ml = "utils.ml"
let configure_ml = "configure.ml"
let get_infos () : infos = {
utils_ml_hash = Utils.hash_file utils_ml;
configure_ml_hash = Utils.hash_file configure_ml;
}
let mkdir_noerr path =
try
Sys.mkdir path 0x755
with Sys_error _ ->
()
let add_ubuntu_depext buffer opam_file_version depext_version ubuntu_version =
if opam_file_version >= depext_version then
begin
let op = if opam_file_version = depext_version then ">=" else "=" in
Buffer.add_string buffer (Printf.sprintf {| ["libclang-%d-dev" "libclang-cpp%d-dev" "llvm-%d-dev"]
{os-distribution = "ubuntu" & os-version %s "%s"}
|} depext_version depext_version depext_version op ubuntu_version);
end
type version_info = {
clang : int;
packages : string list;
}
let find_last_version_available upperbound list =
match List.filter (fun info -> info.clang <= upperbound) list with
| [] -> None
| hd :: tl ->
let max_version =
List.fold_left (fun info info' -> if info.clang > info'.clang then info else info') hd tl in
Some max_version.packages
type debian_version_info = {
debian : int;
version_info : version_info list;
}
let debian_packages version =
{ clang = version;
packages = List.map (fun pattern -> Printf.sprintf pattern version)
["libclang-%d-dev"; "libclang-cpp%d-dev"; "llvm-%d-dev"] }
let debian_version_table = [
{ debian = 10; version_info = [
{ clang = 7; packages = ["libclang-7-dev"; "llvm-7-dev"] };
debian_packages 11;
debian_packages 13]};
{ debian = 11; version_info = List.map debian_packages [11; 13; 16] };
{ debian = 12; version_info = List.map debian_packages [14; 15; 16] };
{ debian = 13; version_info = List.map debian_packages [15; 16; 17] };
{ debian = 14; version_info = List.map debian_packages [14; 15; 16; 17; 18] };
]
let quote_packages packages =
String.concat " " (List.map (fun package -> Printf.sprintf {|"%s"|} package) packages)
let add_debian_depext buffer version : unit =
let versions =
List.map (fun info -> info.debian, find_last_version_available version info.version_info)
(List.sort (fun v v' -> compare v'.debian v.debian) debian_version_table) in
match versions with
| [] -> assert false
| (max_version, packages) :: tl ->
packages |> Option.iter (fun packages ->
Printf.bprintf buffer {| [%s] { os-distribution = "debian" & os-version >= "%d" }
|}
(quote_packages packages) max_version);
tl |> List.iter (fun (version, packages) ->
packages |> Option.iter (fun packages ->
Printf.bprintf buffer {| [%s] { os-distribution = "debian" & os-version = "%d" }
|}
(quote_packages packages) version))
let add_oraclelinux_depext buffer clang_version ol_version =
Buffer.add_string buffer (Printf.sprintf {| ["clang-devel-%s" "llvm-devel-%s" "llvm-static-%s" "zlib-devel"]
{os-distribution = "ol" & %s}
|} clang_version clang_version clang_version ol_version)
let add_fedora_depext buffer clang_version =
Buffer.add_string buffer (Printf.sprintf {| ["clang%d-devel" "llvm%d-devel" "llvm%d-static" "zlib-devel" "redhat-rpm-config"]
{os-distribution = "fedora"}
|} clang_version clang_version clang_version)
let add_fedora_depext_cstr buffer clang_version fedora_version =
Buffer.add_string buffer (Printf.sprintf {| ["clang%d-devel" "llvm%d-devel" "llvm%d-static" "zlib-devel" "redhat-rpm-config"]
{os-distribution = "fedora" & os-version = "%d"}
|} clang_version clang_version clang_version fedora_version)
let generate_opam_file infos opam_file version =
let buffer = Buffer.create 1024 in
Buffer.add_string buffer (Printf.sprintf {|opam-version: "2.0"
maintainer: "Thierry Martinez <martinez@nsup.org>"
authors: "The LLVM team"
homepage: "http://llvm.org"
bug-reports: "https://github.com/thierry-martinez/conf-libclang"
license: "MIT"
build-env: [
[HOMEBREW_NO_AUTO_UPDATE = "1"]
]
build: [
["ocamlfind" "ocamlopt" "-package" "unix,stdcompat" "-linkpkg" "-o" "configure" "utils.ml" "configure.ml"]
["./configure" "%d"]
]
depends: [
"ocamlfind" {build}
"stdcompat" {build & >= "19"}
]
depexts: [
|} version);
if version >= 12 then
(* brew: llvm@9 and llvm@11 are disabled and llvm@10 does not exist *)
Buffer.add_string buffer (Printf.sprintf {| ["llvm@%d"] {os = "macos"}
|} version);
Buffer.add_string buffer (Printf.sprintf {| ["llvm%d" "clang%d"] {os-distribution = "arch"}
|} version version);
add_ubuntu_depext buffer version 18 "24.04";
add_ubuntu_depext buffer version 17 "23.10";
add_ubuntu_depext buffer version 16 "23.04";
add_ubuntu_depext buffer version 15 "22.10";
add_ubuntu_depext buffer version 14 "22.04";
add_ubuntu_depext buffer version 13 "21.10";
add_ubuntu_depext buffer version 13 "21.04";
add_ubuntu_depext buffer version 12 "20.10";
add_ubuntu_depext buffer version 12 "20.04";
if version = 11 then
add_ubuntu_depext buffer 11 11 "20.04";
if version = 10 then
add_ubuntu_depext buffer 10 10 "20.04";
add_debian_depext buffer version;
if version = 10 then
add_oraclelinux_depext buffer "10.0.1" "os-version >= 8 & os-version < 9";
if version = 11 then
add_oraclelinux_depext buffer "11.0.1" "os-version >= 8 & os-version < 9";
if version = 12 then
add_oraclelinux_depext buffer "12.0.1" "os-version >= 8 & os-version < 9";
if version = 13 then
add_oraclelinux_depext buffer "13.0.1" "os-version >= 8";
if version = 14 then
add_oraclelinux_depext buffer "14.0.6" "os-version >= 8";
if version = 15 then
add_oraclelinux_depext buffer "15.0.7" "os-version >= 8";
if version = 16 then
add_oraclelinux_depext buffer "16.0.6" "os-version >= 8";
if version = 17 then
add_oraclelinux_depext buffer "17.0.6" "os-version >= 8";
if version >= 18 then
Buffer.add_string buffer {| ["clang-devel" "llvm-devel" "llvm-static" "zlib-devel"]
{os-distribution = "ol" & os-version >= "8"}
|};
if version >= 11 && version <= 14 then
add_fedora_depext buffer version;
if version >= 15 then
begin
add_fedora_depext_cstr buffer 15 38;
if version = 15 then
begin
add_fedora_depext_cstr buffer 15 39;
add_fedora_depext_cstr buffer 15 40;
end;
end;
if version >= 16 then
begin
add_fedora_depext_cstr buffer 16 39;
if version = 16 then
add_fedora_depext_cstr buffer 16 40;
end;
if version >= 17 then
add_fedora_depext_cstr buffer 17 40;
Buffer.add_string buffer {| ["clang-dev" "llvm-dev" "clang-static"] {os-distribution = "alpine"}
["clang-devel" "llvm-devel" "llvm-static" "zlib-devel"]
{os-distribution = "centos"}
["llvm-clang-devel"] {os-family = "suse" | os-family = "opensuse"}
["sys-devel/clang"] {os-distribution = "gentoo"}
|};
if version >= 11 then
begin
(* no devel/llvm10 on FreeBSD *)
Buffer.add_string buffer (Printf.sprintf {| ["devel/llvm%d"] {os = "freebsd"}
|} version);
end;
Buffer.add_string buffer {|]
x-ci-accept-failures: [
"oraclelinux-7" # clang-devel is not available
"alpine-3.13" # unavailable system package 'llvm-dev'
"alpine-3.14" # unavailable system package 'llvm-dev'
"alpine-3.15" # unavailable system package 'llvm-dev'
"alpine-3.16" # unavailable system package 'llvm-dev'
"opensuse-15.3" # unavailable system package 'llvm-clang-devel'
|};
if version < 11 then
Buffer.add_string buffer {| "freebsd" # no devel/llvm10
|};
if version < 12 then
Buffer.add_string buffer {| "macos-homebrew" # llvm@n is not available
|};
if version < 14 then
Buffer.add_string buffer {| "ubuntu-22.04" "ubuntu-22.10" "ubuntu-23.04" "ubuntu-23.10" "ubuntu-24.04" # libclang-n-dev is not available
|};
if version < 11 then
Buffer.add_string buffer {| "debian-11" # libclang-n-dev is not available
|};
if version < 14 then
Buffer.add_string buffer {| "debian-12" "debian-unstable" # libclang-n-dev is not available
|};
if version < 15 then
Buffer.add_string buffer {| "debian-13" "debian-testing" # libclang-n-dev is not available
|};
if version < 11 then
Buffer.add_string buffer {| "fedora-38" "fedora-39" "fedora-40" # clang-devel is not available
|};
if version = 11 || version = 14 then
Buffer.add_string buffer {| "fedora-40" # clang-devel is not available
|};
if version = 12 then
Buffer.add_string buffer {| "fedora-39" "fedora-40" # clang-devel is not available
|};
if version < 13 then
Buffer.add_string buffer {| "oraclelinux-9" # clang-devel is not available
|};
Buffer.add_string buffer (Printf.sprintf {|]
extra-source "configure.ml" {
src:
"https://raw.githubusercontent.com/thierry-martinez/conf-libclang/opam.2024-05-29/configure.ml"
checksum:
"%s"
}|} infos.configure_ml_hash);
Buffer.add_string buffer (Printf.sprintf {|
extra-source "utils.ml" {
src:
"https://raw.githubusercontent.com/thierry-martinez/conf-libclang/opam.2024-05-29/utils.ml"
checksum:
"%s"
}|} infos.utils_ml_hash);
Buffer.add_string buffer (Printf.sprintf {|
synopsis: "Virtual package relying on the installation of llvm and clang libraries (<= %d.0.x)"
flags: conf
|} version);
Out_channel.with_open_text opam_file (fun oc ->
Buffer.output_buffer oc buffer)
let generate infos version =
let package_dir = Printf.sprintf "conf-libclang.%d" version in
let opam_file = Filename.concat package_dir "opam" in
mkdir_noerr package_dir;
generate_opam_file infos opam_file version
let () =
let infos = get_infos () in
for version = 10 to 18 do
generate infos version
done