Example #1
0
// build executes a build against a file system.
func (m *Main) build(build *bake.Build, fs bake.FileSystem, ss *bake.Snapshot) error {
	// Execute build.
	b := bake.NewBuilder()
	b.FileSystem = fs
	b.Snapshot = ss
	b.Output = m.Stderr
	b.Build(build)

	if err := build.RootErr(); err != nil {
		return err
	}

	return nil
}
Example #2
0
// pipeReaders creates goroutines for all readers to copy to stderr & stdout.
func (m *Main) pipeReaders(build *bake.Build, set map[*bake.Build]struct{}) {
	// Ignore if the build has already been attached.
	if _, ok := set[build]; ok {
		return
	}
	set[build] = struct{}{}

	// NOTE: goroutines are closed automatically when build is closed.
	go io.Copy(m.Stdout, build.Stdout())
	go io.Copy(m.Stderr, build.Stderr())

	// Recursively pipe dependencies.
	for _, subbuild := range build.Dependencies() {
		m.pipeReaders(subbuild, set)
	}
}