-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcompat.xcb.lua
More file actions
185 lines (165 loc) · 6.04 KB
/
Copy pathcompat.xcb.lua
File metadata and controls
185 lines (165 loc) · 6.04 KB
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
package = {
spec = "1",
namespace = "compat",
name = "xcb",
description = "X C Binding core library built from upstream sources",
licenses = {"MIT"},
repo = "https://gitlab.freedesktop.org/xorg/lib/libxcb",
type = "package",
xpm = {
linux = {
deps = {
"xim:python@latest",
},
["1.17.0"] = {
url = {
GLOBAL = "https://xorg.freedesktop.org/releases/individual/lib/libxcb-1.17.0.tar.xz",
CN = "https://gitcode.com/mcpp-res/xcb/releases/download/1.17.0/xcb-1.17.0.tar.xz",
},
sha256 = "599ebf9996710fea71622e6e184f3a8ad5b43d0e5fa8c4e407123c88a59a6d55",
},
},
},
mcpp = {
language = "c++23",
import_std = false,
c_standard = "c11",
include_dirs = {"src", "include"},
cflags = {
"-D_GNU_SOURCE",
"-D_DEFAULT_SOURCE",
"-DHAVE_CONFIG_H",
},
sources = {
"src/xcb_conn.c",
"src/xcb_out.c",
"src/xcb_in.c",
"src/xcb_ext.c",
"src/xcb_xid.c",
"src/xcb_list.c",
"src/xcb_util.c",
"src/xcb_auth.c",
"src/xproto.c",
"src/bigreq.c",
"src/xc_misc.c",
},
targets = { ["xcb"] = { kind = "shared", soname = "libxcb.so.1" } },
deps = {
["compat.xau"] = "1.0.12",
["compat.xcb-proto"] = "1.17.0",
["compat.xdmcp"] = "1.1.5",
},
},
}
import("xim.libxpkg.pkginfo")
import("xim.libxpkg.log")
local generated_headers = {
"xcb.h",
"xcbext.h",
"xcb_windefs.h",
"xproto.h",
"bigreq.h",
"xc_misc.h",
}
local function write_config_header(srcdir)
io.writefile(path.join(srcdir, "config.h"), [[#ifndef MCPP_COMPAT_XCB_CONFIG_H
#define MCPP_COMPAT_XCB_CONFIG_H
#define HAVE_SENDMSG 1
#define HAVE_ABSTRACT_SOCKETS 1
#define HAVE_GETADDRINFO 1
#define XCB_QUEUE_BUFFER_SIZE 16384
#endif
]])
end
local function copy_public_headers(srcdir, installdir)
local incdir = path.join(installdir, "include", "xcb")
os.mkdir(path.join(installdir, "include"))
os.mkdir(incdir)
for _, header in ipairs(generated_headers) do
os.cp(path.join(srcdir, header), path.join(incdir, header))
end
end
local function sh_quote(value)
return "'" .. tostring(value):gsub("'", "'\\''") .. "'"
end
local function resolve_python()
local python = pkginfo.build_dep("xim:python") or pkginfo.build_dep("python")
if not python or not python.bin or not os.isdir(python.bin) then
log.error("python build dependency not found")
return nil
end
for _, name in ipairs({ "python3", "python" }) do
local candidate = path.join(python.bin, name)
if os.isfile(candidate) then
return candidate
end
end
-- Fallback glob. `python3.*` also matches helper scripts that share the
-- prefix (python3.13-config, python3.13-gdb, ...). Feeding c_client.py to
-- python3.13-config exits 0 while generating NOTHING, which silently
-- produces a broken xcb install. Keep only real interpreters
-- (python3 / python3.<minor>) and pick the canonical (shortest) name.
local interpreters = {}
for _, m in ipairs(os.files(path.join(python.bin, "python3*")) or {}) do
if path.filename(m):match("^python3%.?%d*$") then
table.insert(interpreters, m)
end
end
table.sort(interpreters)
if #interpreters > 0 then
return interpreters[1]
end
log.error("python executable not found under %s", python.bin)
return nil
end
function install()
local srcroot = pkginfo.install_file():replace(".tar.xz", "")
if not os.isdir(srcroot) then
srcroot = "libxcb-" .. pkginfo.version()
end
os.tryrm(pkginfo.install_dir())
os.mv(srcroot, pkginfo.install_dir())
-- A cross-package lookup addresses the sibling by its DECLARED identity
-- `<namespace>:<package.name>`. Since SPEC-001 that is `compat:xcb-proto`;
-- the two `compat.xcb-proto` spellings below are the pre-SPEC-001 forms,
-- kept so this descriptor still resolves against an index that has not
-- migrated yet. Getting this wrong is silent until install time: the
-- lookup simply misses and codegen has no protocol XML to read.
local proto_dir = pkginfo.install_dir("compat:xcb-proto", "1.17.0")
or pkginfo.install_dir("compat:compat.xcb-proto", "1.17.0")
or pkginfo.install_dir("compat.xcb-proto", "1.17.0")
if not proto_dir or not os.isdir(proto_dir) then
log.error("xcb-proto@1.17.0 install dir not found")
return false
end
local srcdir = path.join(pkginfo.install_dir(), "src")
write_config_header(srcdir)
local python = resolve_python()
if not python then
return false
end
os.cd(srcdir)
for _, name in ipairs({ "xproto", "bigreq", "xc_misc" }) do
local cmd = string.format(
"%s c_client.py -c %s -l %s -s 3 -p %s %s",
sh_quote(python),
sh_quote("libxcb " .. pkginfo.version()),
sh_quote("X Version 11"),
sh_quote(proto_dir),
sh_quote(path.join(proto_dir, "src", name .. ".xml"))
)
os.exec(cmd)
-- Verify the generator actually produced its outputs. c_client.py can
-- exit 0 without writing anything (e.g. a misresolved interpreter), so
-- a non-failing os.exec is not proof of success. Fail the install
-- loudly instead of leaving a broken package that only blows up later
-- at compile time with `xproto.h: No such file or directory`.
if not os.isfile(path.join(srcdir, name .. ".h"))
or not os.isfile(path.join(srcdir, name .. ".c")) then
log.error("c_client.py did not generate %s.{h,c} (python=%s)", name, python)
return false
end
end
copy_public_headers(srcdir, pkginfo.install_dir())
return true
end