vinix-ports / tests / x11 / release-elf.v
110 lines · 103 sloc · 4.48 KB · 05b5a3469216e13266a6be57db9a14d9f76266a6
Raw
1// Compare the published X11 sidecar with the exact Mesa release packages.
2// Keep extracted ELF files, readelf output and checksums outside the checkout.
3module main
4
5import os
6
7fn command(args []string) !string {
8 result := os.exec(args)
9 if result.exit_code != 0 {
10 return error('${args}: ${result.output}')
11 }
12 return result.output
13}
14
15fn extract(archive string, members []string, destination string) ! {
16 os.mkdir_all(destination)!
17 mut args := ['tar', '--ignore-zeros', '-xf', archive, '-C', destination]
18 args << members
19 command(args)!
20}
21
22fn elf(path string, name string, receipt string) !string {
23 head := command(['readelf', '-h', path])!
24 dynamic := command(['readelf', '-d', path])!
25 os.write_file(os.join_path(receipt, name + '.readelf'), head + '\n' + dynamic)!
26 return dynamic
27}
28
29fn checksum(path string) !string {
30 return command(['sha256sum', path])!.all_before(' ')
31}
32
33fn architecture(release string, refs string, out string, image string, arch string) ! {
34 os.mkdir(out)!
35 mut inventory := []string{}
36 mut digests := []string{}
37 for list in ['iso.files', 'initramfs.files', 'x11.files'] {
38 file := os.join_path(release, image, list)
39 digests << '${checksum(file)!} ${image}/${list}'
40 paths := os.read_lines(file)!
41 for path in paths {
42 name := os.base(path)
43 if name.starts_with('libgallium') || name.starts_with('libLLVM')
44 || path.contains('vinix-x11-software') || name.contains('ld-musl') && name.ends_with('.path') {
45 inventory << '${list}\t${path}'
46 }
47 if name in ['libgallium-24.2.8.so', 'libLLVM.so.19.1', 'libLLVM-19.so'] {
48 return error('found ${name} in ${image}/${list} at ${path}; reassess this release')
49 }
50 }
51 }
52 os.write_file(os.join_path(out, 'search-path-inventory.tsv'), inventory.join('\n') + '\n')!
53 side := os.join_path(release, 'vinix-x11-${image}.tar.gz')
54 digests << '${checksum(side)!} ${os.file_name(side)}'
55 content := os.join_path(out, 'sidecar')
56 lib := 'usr/lib/'
57 dri := lib + 'xorg/modules/dri/'
58 extract(side, ['./' + lib + 'libEGL.so.1.0.0', './' + lib + 'libgbm.so.1.0.0', './' + dri], content)!
59 for kind, file in {'egl': 'libEGL.so.1.0.0', 'gbm': 'libgbm.so.1.0.0'} {
60 apk := os.join_path(refs, 'v3.21/main', arch, 'mesa-${kind}-24.2.8-r0.apk')
61 sub := os.join_path(out, kind)
62 extract(apk, [lib + file], sub)!
63 published := os.join_path(content, lib, file)
64 hash := checksum(published)!
65 if hash != checksum(os.join_path(sub, lib, file))! {
66 return error('${image} ${file} differs from ${os.file_name(apk)}')
67 }
68 digests << '${hash} sidecar/${lib}${file}'
69 digests << '${checksum(apk)!} ${os.file_name(apk)}'
70 if !elf(published, kind, out)!.contains('Shared library: [libgallium-24.2.8.so]') {
71 return error('${image} ${file} lacks the expected current Gallium dependency')
72 }
73 }
74 current := os.join_path(refs, 'v3.21/main', arch, 'mesa-24.2.8-r0.apk')
75 original := os.join_path(out, 'current')
76 extract(current, [lib + 'libgallium-24.2.8.so'], original)!
77 current_file := os.join_path(original, lib, 'libgallium-24.2.8.so')
78 if !elf(current_file, 'current-gallium', out)!.contains('Shared library: [libLLVM.so.19.1]') {
79 return error('current Gallium does not request LLVM19 on ${arch}')
80 }
81 legacy := os.join_path(refs, 'v3.20/main', arch, 'mesa-dri-gallium-24.0.9-r1.apk')
82 older := os.join_path(out, 'legacy')
83 extract(legacy, [dri.trim_right('/')], older)!
84 installed := os.join_path(content, dri, 'libgallium_dri.so')
85 hash := checksum(installed)!
86 if hash != checksum(os.join_path(older, dri, 'libgallium_dri.so'))!
87 || !elf(installed, 'legacy-gallium', out)!.contains('Shared library: [libLLVM-17.so]') {
88 return error('published Gallium differs from the LLVM17-backed DRI runtime on ${image}')
89 }
90 digests << '${hash} sidecar/${dri}libgallium_dri.so'
91 digests << '${checksum(current_file)!} current/${lib}libgallium-24.2.8.so'
92 digests << '${checksum(current)!} ${os.file_name(current)}'
93 digests << '${checksum(legacy)!} ${os.file_name(legacy)}'
94 os.write_file(os.join_path(out, 'SHA256SUMS'), digests.join('\n') + '\n')!
95 println('${image}: published EGL/GBM require missing Mesa 24.2.8 Gallium + LLVM19; installed Mesa 24.0.9 DRI requires LLVM17.')
96}
97
98fn main() {
99 if os.args.len != 4 {
100 eprintln('usage: release-elf RELEASE_ASSETS_DIR REFERENCE_APK_DIR NEW_OUTPUT_DIR')
101 exit(2)
102 }
103 release := os.abs_path(os.args[1])
104 refs := os.abs_path(os.args[2])
105 out := os.abs_path(os.args[3])
106 os.mkdir(out) or { panic(err) }
107 for image, arch in {'amd64': 'x86_64', 'arm64': 'aarch64'} {
108 architecture(release, refs, os.join_path(out, image), image, arch) or { panic(err) }
109 }
110}
111