From 8dc1068ee0572894961443dc5f00b9d66277580d Mon Sep 17 00:00:00 2001 From: Chris Koch Date: Sun, 28 Jan 2024 21:28:38 +0000 Subject: [PATCH] Move BuildOpts -- allow specifying different BuildOpts for different commands Signed-off-by: Chris Koch --- cmd/mkuimage/main.go | 6 +++--- uroot/uroot.go | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/mkuimage/main.go b/cmd/mkuimage/main.go index 31b91e4..cdab1f8 100644 --- a/cmd/mkuimage/main.go +++ b/cmd/mkuimage/main.go @@ -350,8 +350,9 @@ func Main(l ulog.Logger, env *golang.Environ, buildOpts *golang.BuildOpts) error // The command-line tool only allows specifying one build mode // right now. c = append(c, uroot.Commands{ - Builder: b, - Packages: pkgs, + Builder: b, + Packages: pkgs, + BuildOpts: buildOpts, }) } @@ -366,7 +367,6 @@ func Main(l ulog.Logger, env *golang.Environ, buildOpts *golang.BuildOpts) error UseExistingInit: *useExistingInit, InitCmd: initCommand, DefaultShell: *defaultShell, - BuildOpts: buildOpts, } uinitArgs := shlex.Split(*uinitCmd) if len(uinitArgs) > 0 { diff --git a/uroot/uroot.go b/uroot/uroot.go index 5e528c7..6f0768c 100644 --- a/uroot/uroot.go +++ b/uroot/uroot.go @@ -103,6 +103,10 @@ type Commands struct { // BinaryDir may be empty, in which case Builder.DefaultBinaryDir() // will be used. BinaryDir string + + // Build options for building go binaries. Ultimate this holds all the + // args that end up being passed to `go build`. + BuildOpts *golang.BuildOpts } // TargetDir returns the initramfs binary directory for these Commands. @@ -224,10 +228,6 @@ type Opts struct { // // This must be specified to have a default shell. DefaultShell string - - // Build options for building go binaries. Ultimate this holds all the - // args that end up being passed to `go build`. - BuildOpts *golang.BuildOpts } // CreateInitramfs creates an initramfs built to opts' specifications. @@ -243,10 +243,6 @@ func CreateInitramfs(logger ulog.Logger, opts Opts) error { if opts.Env != nil { env = opts.Env } - if opts.BuildOpts == nil { - opts.BuildOpts = &golang.BuildOpts{} - } - files := initramfs.NewFiles() lookupEnv := findpkg.DefaultEnv() @@ -269,11 +265,15 @@ func CreateInitramfs(logger ulog.Logger, opts Opts) error { if err != nil { return err } + buildOpts := cmds.BuildOpts + if buildOpts == nil { + buildOpts = &golang.BuildOpts{} + } // Build packages. bOpts := builder.Opts{ Env: env, - BuildOpts: opts.BuildOpts, + BuildOpts: buildOpts, Packages: cmds.Packages, TempDir: builderTmpDir, BinaryDir: cmds.TargetDir(),