vinix-ports / tools / release-closure.v
73 lines · 70 sloc · 2.1 KB · ef85c2809cb0063cae077f729806ca6f5b5d1090
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) ! {
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 profiles[fields[1]] << fields[2]
24 }
25 }
26 mut packages := []alpinecore.Package{}
27 mut origins := map[string]string{}
28 for i, path in indexes {
29 body := os.read_file(path)!
30 repository := ['main', 'community'][i]
31 packages << alpinecore.parse_text(body, repository)!
32 for record in body.split('\n\n') {
33 mut name := ''
34 mut origin := ''
35 for field in record.split_into_lines() {
36 if field.starts_with('P:') {
37 name = field[2..]
38 } else if field.starts_with('o:') {
39 origin = field[2..]
40 }
41 }
42 if name != '' && name !in origins {
43 origins[name] = if origin == '' { name } else { origin }
44 }
45 }
46 }
47 mut names := profiles.keys()
48 names.sort()
49 mut applies := map[string][]string{}
50 mut roots := []string{}
51 for profile in names {
52 roots << profiles[profile]
53 for pkg in alpinecore.resolve(packages, profiles[profile])! {
54 applies[pkg.name] << profile
55 }
56 }
57 println('arch\tbinary\tversion\tsource\trepository\tprofiles')
58 for pkg in alpinecore.resolve(packages, roots)! {
59 println([arch, pkg.name, pkg.version, origins[pkg.name], pkg.repository,
60 applies[pkg.name].join(',')].join('\t'))
61 }
62}
63
64fn main() {
65 if os.args.len != 5 {
66 eprintln('usage: release-closure ARCH PROFILES.tsv MAIN-APKINDEX COMMUNITY-APKINDEX')
67 exit(2)
68 }
69 release_inputs(os.args[1], os.args[2], os.args[3..]) or {
70 eprintln(err)
71 exit(1)
72 }
73}
74