Skip to content

Commit

Permalink
add first step of bootstrap.go automation
Browse files Browse the repository at this point in the history
related to #70
  • Loading branch information
stapelberg committed May 19, 2020
1 parent 2c1b713 commit e535899
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions bootstrap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}
}

0 comments on commit e535899

Please sign in to comment.