Skip to content

Commit

Permalink
Revert "Rename generators to archivers and builders"
Browse files Browse the repository at this point in the history
This reverts commit 56486f3.
  • Loading branch information
rminnich authored and xchenan committed Apr 28, 2017
1 parent 763a6cd commit b35632e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 48 deletions.
10 changes: 5 additions & 5 deletions scripts/build/bb_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
)

func init() {
builders["bb"] = bbBuilder{}
buildGenerators["bb"] = bbGenerator{}
}

type bbBuilder struct {
type bbGenerator struct {
}

// TODO: This builder is not yet implemented.
func (b bbBuilder) generate(config Config) ([]file, error) {
return nil, errors.New("bb builder not implemented yet")
// TODO: This generator is not yet implemented.
func (g bbGenerator) generate(config Config) ([]file, error) {
return nil, errors.New("bb generator not implemented yet")
}
22 changes: 10 additions & 12 deletions scripts/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"sort"
)

// Builders and archivers register themselves in init() functions.
// Generators register themselves in init() functions.
var (
builders = map[string]builder{}
archivers = map[string]archiver{}
buildGenerators = map[string]buildGenerator{}
archiveGenerators = map[string]archiveGenerator{}
)

// Uniq sorts and remove duplicates from a slice of strings.
Expand All @@ -34,20 +34,20 @@ func Uniq(s []string) []string {

// Build a u-root archive and optionally run it.
func Build(config Config) error {
// Select the builders. There may be multiple!
bGens := []builder{}
// Select the build generators.
bGens := []buildGenerator{}
for _, buildFormat := range config.BuildFormats {
bGen, ok := builders[buildFormat]
bGen, ok := buildGenerators[buildFormat]
if !ok {
return errors.New("invalid builder")
return errors.New("invalid build generator")
}
bGens = append(bGens, bGen)
}

// Select the archiver.
aGen, ok := archivers[config.ArchiveFormat]
// Select the archive generator.
aGen, ok := archiveGenerators[config.ArchiveFormat]
if !ok {
return errors.New("invalid archiver")
return errors.New("invalid archive generator")
}

// Generate the files.
Expand Down Expand Up @@ -88,8 +88,6 @@ func Build(config Config) error {
// Sort the files by path. This is requires for reproducible builds.
sort.Slice(files, func(i, j int) bool {
if files[i].path == files[j].path {
// TODO: more intelligent merging. For example, when there are
// multiple inits, one must be renamed to inito.
log.Printf("warning: multiple files named %q", files[i].path)
}
return files[i].path < files[j].path
Expand Down
10 changes: 5 additions & 5 deletions scripts/build/chroot_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (
)

func init() {
archivers["chroot"] = chrootArchiver{}
archiveGenerators["chroot"] = chrootGenerator{}
}

type chrootArchiver struct {
type chrootGenerator struct {
}

// The chroot archiver dumps the rootfs tree into a directory appropriate for
// The chroot generator dumps the rootfs tree into a directory appropriate for
// running under a chroot and namespaces.
func (a chrootArchiver) generate(config Config, files []file) error {
func (g chrootGenerator) generate(config Config, files []file) error {
// Since files is sorted, we can guarantee that the directories are created
// before their children.
for _, f := range files {
Expand Down Expand Up @@ -78,7 +78,7 @@ func createFile(f file) error {
}

// Run the rootfs under a chroot jail.
func (a chrootArchiver) run(config Config) error {
func (g chrootGenerator) run(config Config) error {
// TODO: Until https://github.com/golang/go/issues/19661 is fixed,
// exec.Command is insufficient for making mount namespaces, so instead we
// rely on a moderately up-to-date unshare command.
Expand Down
14 changes: 7 additions & 7 deletions scripts/build/cpio_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
)

func init() {
archivers["cpio"] = cpioArchiver{}
archiveGenerators["cpio"] = cpioGenerator{}
}

type cpioArchiver struct {
type cpioGenerator struct {
}

// This archiver creates a cpio archive from the given list of files.
// This generator creates a cpio archive from the given list of files.
// TODO: Replace this implementation with one which does not require sudo.
// TODO: Preferably, it will share code with cmds/cpio.
func (a cpioArchiver) generate(config Config, files []file) error {
func (g cpioGenerator) generate(config Config, files []file) error {
// TODO: Delete this temporary directory which is too scary because of "sudo rm -rf" --
// especially considering the directory could contain mount points.
chrootConfig := config
Expand All @@ -33,10 +33,10 @@ func (a cpioArchiver) generate(config Config, files []file) error {
return err
}

// We cheat by calling the chroot archiver to create the directory
// We cheat by calling the chroot generator to create the directory
// structure and running cpio over it.
chrootConfig.OutputPath = filepath.Join(tmpDir, "chroot")
if err := (chrootArchiver{}).generate(chrootConfig, files); err != nil {
if err := (chrootGenerator{}).generate(chrootConfig, files); err != nil {
return err
}

Expand All @@ -52,7 +52,7 @@ func (a cpioArchiver) generate(config Config, files []file) error {
}

// Run the cpio file under Linux in QEMU. This requires a bit of setup.
func (a cpioArchiver) run(config Config) error {
func (g cpioGenerator) run(config Config) error {
envName := fmt.Sprintf("UROOT_CPIO_RUN_%s", gobuild.Default.GOARCH)
env := os.Getenv(envName)
if env == "" {
Expand Down
6 changes: 3 additions & 3 deletions scripts/build/dev_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func init() {
builders["dev"] = devBuilder{}
buildGenerators["dev"] = devGenerator{}
}

type devBuilder struct {
type devGenerator struct {
}

// There are a few dev nodes which are required to run an initramfs.
func (b devBuilder) generate(config Config) ([]file, error) {
func (g devGenerator) generate(config Config) ([]file, error) {
// TODO: there are probably some files here we don't actually need
return []file{
{"dev/console", nil, 0644 | os.ModeDevice | os.ModeCharDevice, 0, 0, dev(5, 1)},
Expand Down
12 changes: 6 additions & 6 deletions scripts/build/docker_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
)

func init() {
archivers["docker"] = dockerArchiver{}
archiveGenerators["docker"] = dockerGenerator{}
}

type dockerArchiver struct {
type dockerGenerator struct {
}

// TODO: Generate a docker image.
func (a dockerArchiver) generate(config Config, files []file) error {
return errors.New("docker archiver not implemented yet")
func (g dockerGenerator) generate(config Config, files []file) error {
return errors.New("docker generator not implemented yet")
}

// TODO: Run the docker image.
func (a dockerArchiver) run(config Config) error {
return errors.New("docker archiver not implemented yet")
func (g dockerGenerator) run(config Config) error {
return errors.New("docker generator not implemented yet")
}
8 changes: 4 additions & 4 deletions scripts/build/list_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
)

func init() {
archivers["list"] = listArchiver{}
archiveGenerators["list"] = listGenerator{}
}

type listArchiver struct {
type listGenerator struct {
}

// Rather than creating an archive, this simply outputs a list for debugging.
func (a listArchiver) generate(config Config, files []file) error {
func (g listGenerator) generate(config Config, files []file) error {
totalSize := 0
// TODO: use "text/tabwriter" for nicer alignment
for _, f := range files {
Expand All @@ -41,6 +41,6 @@ func (a listArchiver) generate(config Config, files []file) error {
return nil
}

func (a listArchiver) run(config Config) error {
func (g listGenerator) run(config Config) error {
return errors.New("not implemented")
}
6 changes: 3 additions & 3 deletions scripts/build/src_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
)

func init() {
builders["src"] = srcBuilder{}
buildGenerators["src"] = srcGenerator{}
}

type srcBuilder struct {
type srcGenerator struct {
}

type srcDstPair struct {
Expand All @@ -29,7 +29,7 @@ type srcDstPair struct {

// Generate u-root files with on-the-fly compilation. This includes the Go
// toolchain.
func (b srcBuilder) generate(config Config) ([]file, error) {
func (g srcGenerator) generate(config Config) ([]file, error) {
// For parallism, store files in a chan and convert to a slice afterwards.
fileChan := make(chan file)
wg := sync.WaitGroup{}
Expand Down
6 changes: 3 additions & 3 deletions scripts/build/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type file struct {
rdev uint64
}

// Generate files for inclusion into the archive.
type builder interface {
// Generates files for inclusion into the archive.
type buildGenerator interface {
generate(Config) ([]file, error)
}

// Create an archive given a slice of files.
type archiver interface {
type archiveGenerator interface {
generate(Config, []file) error
run(Config) error
}

0 comments on commit b35632e

Please sign in to comment.