Skip to content

Commit

Permalink
makebb: add "generate code but do not build" switch
Browse files Browse the repository at this point in the history
-g will allow the package to generate code but not compile it.

Systems like tamago are not quite in reach for makebb to build just yet.

If the generate directory is empty an error will be returned.

Co-authored-by: Chris Koch <[email protected]>
Signed-off-by: Ronald G. Minnich <[email protected]>
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
rminnich and hugelgupf committed Dec 30, 2021
1 parent 8269634 commit c81ee86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cmd/makebb/makebb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
var (
outputPath = flag.String("o", "bb", "Path to compiled busybox binary")
genDir = flag.String("gen-dir", "", "Directory to generate source in")
genOnly = flag.Bool("g", false, "Generate but do not build binaries")
)

func main() {
Expand Down Expand Up @@ -59,6 +60,7 @@ func main() {
CommandPaths: flag.Args(),
BinaryPath: o,
GoBuildOpts: bopts,
GenerateOnly: *genOnly,
}
if err := bb.BuildBusybox(opts); err != nil {
l.Print(err)
Expand All @@ -71,9 +73,11 @@ func main() {
} else {
l.Fatalf("Preserving bb generated source directory at %s due to error.", tmpDir)
}
} else if opts.GenerateOnly {
l.Printf("Generated source can be found in %s. `cd %s && go build` to build.", tmpDir, filepath.Join(tmpDir, "src/bb.u-root.com/bb"))
}
// Only remove temp dir if there was no error.
if remove {
if remove && !opts.GenerateOnly {
os.RemoveAll(tmpDir)
}
}
11 changes: 11 additions & 0 deletions src/pkg/bb/bb.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ type Opts struct {
//
// If this is done with GO111MODULE=on,
AllowMixedMode bool

// Generate the tree but don't build it. This is useful for systems
// like Tamago which have their own way of building.
GenerateOnly bool
}

// BuildBusybox builds a busybox of many Go commands. opts contains both the
Expand Down Expand Up @@ -132,6 +136,9 @@ func BuildBusybox(opts *Opts) (nerr error) {
}
tmpDir = absDir
} else {
if opts.GenerateOnly {
return fmt.Errorf("GenerateOnly switch requires that the GenSrcDir directory be supplied")
}
var err error
tmpDir, err = ioutil.TempDir("", "bb-")
if err != nil {
Expand Down Expand Up @@ -218,6 +225,10 @@ func BuildBusybox(opts *Opts) (nerr error) {
}
}

if opts.GenerateOnly {
return nil
}

// Compile bb.
if err := opts.Env.BuildDir(bbDir, opts.BinaryPath, opts.GoBuildOpts); err != nil {
if opts.Env.GO111MODULE == "off" || numNoModule > 0 {
Expand Down

0 comments on commit c81ee86

Please sign in to comment.