-
Notifications
You must be signed in to change notification settings - Fork 26
/
bootstrap.go
124 lines (118 loc) · 2.15 KB
/
bootstrap.go
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
// +build ignore
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/exec"
"strconv"
)
type bootstrapctx struct {
cross string
hermetic bool
}
func (b *bootstrapctx) build(ctx context.Context, pkgs ...string) error {
for _, pkg := range pkgs {
log.Printf("building package %s", pkg)
build := exec.CommandContext(ctx,
"distri",
"build",
"-cross="+b.cross,
"-hermetic="+strconv.FormatBool(b.hermetic),
"-pkg="+pkg)
build.Stdin = os.Stdin
build.Stdout = os.Stdout
build.Stderr = os.Stderr
if err := build.Run(); err != nil {
return fmt.Errorf("%v: %v", build.Args, err)
}
}
return nil
}
func logic(ctx context.Context) error {
var b bootstrapctx
// TODO: de-duplicate the flag help texts with build.go
// TODO: insert all supported architectures into the flag help text
flag.StringVar(&b.cross, "cross", "", "If non-empty, cross-build for the specified architecture (e.g. i686)")
flag.BoolVar(&b.hermetic, "hermetic", true, "build hermetically (if false, host dependencies are used)")
flag.Parse()
var (
glibcSet = []string{"glibc"}
gccSet = []string{"gmp", "mpfr", "mpc", "gcc"}
makeSet = []string{"make"}
bashSet = []string{"bash"}
restSet = []string{
"attr",
"autoconf",
"bc",
"binutils",
"bison",
"coreutils",
"cryptsetup",
"diffutils",
"ed",
"elfutils",
"file",
"findutils",
"flex",
"gawk",
"gettext",
"glib",
"gperf",
"grep",
"gzip",
"help2man",
"json-c",
"kmod",
"libaio",
"libcap",
"libffi",
"libgcrypt",
"libgpg-error",
"rsync",
"linux",
"lvm2",
"m4",
"meson",
"musl",
"ncurses",
"ninja",
"openssl",
"pam",
"patchelf",
"pcre",
"perl",
"pkg-config",
"popt",
"python3",
"sed",
"strace",
"systemd",
"tar",
"texinfo",
"util-linux",
"which",
"zlib",
}
)
for _, pkgset := range [][]string{
glibcSet,
gccSet,
makeSet,
bashSet,
restSet,
} {
if err := b.build(ctx, pkgset...); err != nil {
return err
}
}
return nil
}
func main() {
// TODO: cancel-correct context
if err := logic(context.Background()); err != nil {
log.Fatal(err)
}
}