vinix-ports / tools / release-closure.v
111 lines · 108 sloc · 3.76 KB
Raw
1module main
2
3import alpinecore
4import os
5
6// Resolve exactly as the Vinix release builder does, including its provider
7// preferences. APK's origin field identifies split packages built from a
8// single source. Source build dependencies come from the native recipes.
9fn release_inputs(arch string, profile_file string, indexes []string, installed string) ! {
10 if arch !in ['x86_64', 'aarch64'] {
11 return error('unknown Vinix release architecture: ${arch}')
12 }
13 mut profiles := map[string][]string{}
14 for line in os.read_lines(profile_file)! {
15 if line == 'arch\tprofile\troot' || line.trim_space() == '' {
16 continue
17 }
18 fields := line.split('\t')
19 if fields.len != 3 || fields[0] !in ['both', 'x86_64', 'aarch64'] {
20 return error('invalid profile row: ${line}')
21 }
22 if fields[0] in ['both', arch] {
23 if installed != '' && fields[1] == 'minirootfs' {
24 continue
25 }
26 profiles[fields[1]] << fields[2]
27 }
28 }
29 mut packages := []alpinecore.Package{}
30 mut origins := map[string]string{}
31 for i, path in indexes {
32 body := os.read_file(path)!
33 repository := ['main', 'community'][i]
34 packages << alpinecore.parse_text(body, repository)!
35 for record in body.split('\n\n') {
36 mut name := ''
37 mut origin := ''
38 for field in record.split_into_lines() {
39 if field.starts_with('P:') {
40 name = field[2..]
41 } else if field.starts_with('o:') {
42 origin = field[2..]
43 }
44 }
45 if name != '' && name !in origins {
46 origins[name] = if origin == '' { name } else { origin }
47 }
48 }
49 }
50 mut names := profiles.keys()
51 names.sort()
52 mut applies := map[string][]string{}
53 mut roots := []string{}
54 for profile in names {
55 roots << profiles[profile]
56 for pkg in alpinecore.resolve(packages, profiles[profile])! {
57 // X11 explicitly fetches the named payloads. Its transitive APK
58 // requirements are candidates for a source build and ELF audit.
59 if installed != '' && profile == 'x11-sidecar' && pkg.name !in profiles[profile] {
60 applies[pkg.name] << 'x11-index-dependency'
61 } else {
62 applies[pkg.name] << profile
63 }
64 }
65 }
66 println('arch\tbinary\tversion\tsource\trepository\tprofiles')
67 for pkg in alpinecore.resolve(packages, roots)! {
68 println([arch, pkg.name, pkg.version, origins[pkg.name], pkg.repository, applies[pkg.name].join(',')].join('\t'))
69 }
70 if installed == '' {
71 return
72 }
73 // The release unpacks a checksum-pinned tarball before overlaying packages
74 // from the live branch. Preserve both versions when an overlay updates a file.
75 mut seen := map[string]bool{}
76 for record in os.read_file(installed)!.trim_space().split('\n\n') {
77 mut fields := map[string]string{}
78 for line in record.split_into_lines() {
79 if line.len > 2 && line[1] == `:` && line[0] in [`P`, `V`, `A`, `o`] {
80 fields[line[..1]] = line[2..]
81 }
82 }
83 name := fields['P']
84 if name == '' || fields['V'] == '' || name in seen || fields['A'] !in [arch, 'noarch'] {
85 return error('invalid or duplicate installed package in ${installed}: ${name}')
86 }
87 seen[name] = true
88 println([arch, name, fields['V'], fields['o'] or { name }, 'minirootfs', 'minirootfs'].join('\t'))
89 }
90 if 'musl' !in seen || 'busybox' !in seen {
91 return error('missing bootstrap packages in ${installed}')
92 }
93 for name in ['mesa-dri-gallium', 'mesa-gl', 'mesa-glapi', 'llvm17-libs'] {
94 llvm := name == 'llvm17-libs'
95 version := if llvm { '17.0.6-r2' } else { '24.0.9-r1' }
96 origin := if llvm { 'llvm17' } else { 'mesa' }
97 println([arch, name, version, origin, 'v3.20/main', 'x11-legacy-glx'].join('\t'))
98 }
99}
100
101fn main() {
102 if os.args.len !in [5, 6] {
103 eprintln('usage: release-closure ARCH PROFILES.tsv MAIN-APKINDEX COMMUNITY-APKINDEX [MINIROOTFS-INSTALLED]')
104 exit(2)
105 }
106 installed := if os.args.len == 6 { os.args[5] } else { '' }
107 release_inputs(os.args[1], os.args[2], os.args[3..5], installed) or {
108 eprintln(err)
109 exit(1)
110 }
111}
112