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.

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
  • Loading branch information
rminnich committed Aug 24, 2021
1 parent adc854e commit 8988031
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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 Down
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("generate switch requires that generate directory be supplied")
}
var err error
tmpDir, err = ioutil.TempDir("", "bb-")
if err != nil {
Expand Down Expand Up @@ -200,6 +207,10 @@ func BuildBusybox(opts *Opts) (nerr error) {
return fmt.Errorf("failed to write main.go: %v", err)
}

if opts.GenerateOnly {
return nil
}

// Compile bb.
if opts.Env.GO111MODULE == "off" || numNoModule > 0 {
opts.Env.GOPATH = tmpDir
Expand Down

0 comments on commit 8988031

Please sign in to comment.