Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Koch <[email protected]>
  • Loading branch information
hugelgupf committed Dec 24, 2023
1 parent 6080228 commit 0bf4cbe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/cmd/makebbmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

var (
pkg = flag.String("template_pkg", "", "Go import package path")
destDir = flag.String("dest_dir", "", "Destination directory")
pkgFiles uflag.Strings
commands uflag.Strings
Expand Down
1 change: 0 additions & 1 deletion src/gobb2.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def _go_busybox_impl(ctx):

args = ctx.actions.args()
template = ctx.attr._template[0] if type(ctx.attr._template) == "list" else ctx.attr._template
args.add("--template_pkg", "%s/main" % template.label.package)

outputs = []
inputs = []
Expand Down
32 changes: 9 additions & 23 deletions src/pkg/bb/bb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strings"

"github.com/google/goterm/term"
Expand Down Expand Up @@ -255,11 +254,10 @@ func BuildBusybox(l ulog.Logger, opts *Opts) (nerr error) {
GOPATH: tmpDir,
Err: err,
}
} else {
return &ErrModuleBuild{
CmdDir: bbDir,
Err: err,
}
}
return &ErrModuleBuild{
CmdDir: bbDir,
Err: err,
}
}
return nil
Expand Down Expand Up @@ -504,7 +502,7 @@ func findLocalModules(l ulog.Logger, mainPkgs []*bbinternal.Package) (map[string

if lm, ok := localModules[p.Module.Path]; ok && lm.m.Dir != p.Module.Dir {
gbbstrict, set := os.LookupEnv("GBB_STRICT")
if set == false {
if !set {
l.Printf("GBB_STRICT is not set.")
}
if gbbstrict != "1" {
Expand Down Expand Up @@ -647,7 +645,9 @@ func copyLocalDeps(l ulog.Logger, env *golang.Environ, bbDir, tmpDir, pkgDir str
// decides to go on the internet.
var mod modfile.File

mod.AddModuleStmt("bb.u-root.com/bb")
if err := mod.AddModuleStmt("bb.u-root.com/bb"); err != nil {
return fmt.Errorf("failed to add bb.u-root.com/bb to generated go.mod: %w", err)
}
for mpath, module := range localModules {
v := module.Version
if len(v) == 0 {
Expand Down Expand Up @@ -679,25 +679,11 @@ func copyLocalDeps(l ulog.Logger, env *golang.Environ, bbDir, tmpDir, pkgDir str
// directives.
//
// Warn the user if they are potentially incompatible.
if err := ioutil.WriteFile(filepath.Join(bbDir, "go.mod"), gomod, 0755); err != nil {
return err
}
return nil
return ioutil.WriteFile(filepath.Join(bbDir, "go.mod"), gomod, 0755)
}
return nil
}

func versionNum(mpath string) string {
last := path.Base(mpath)
if len(last) == 0 {
return "v0"
}
if matched, _ := regexp.Match("v[0-9]+", []byte(last)); matched {
return last
}
return "v0"
}

// deps recursively iterates through imports and returns the set of packages
// for which filter returns true.
func deps(p *packages.Package, filter func(p *packages.Package) bool) []*packages.Package {
Expand Down
38 changes: 23 additions & 15 deletions src/pkg/bb/findpkg/bb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,32 @@ var (
urootSource = flag.String("uroot-source", "", "Directory path to u-root source location")
)

func TestModules(t *testing.T) {
dir, err := ioutil.TempDir("", "test-modules-")
if err != nil {
func mustMkdir(t *testing.T, path string, mode os.FileMode) {
if err := os.MkdirAll(path, mode); err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
}

func mustWrite(t *testing.T, path string, contents []byte, mode os.FileMode) {
if err := os.WriteFile(path, contents, mode); err != nil {
t.Fatal(err)
}
}

func TestModules(t *testing.T) {
dir := t.TempDir()

os.MkdirAll(filepath.Join(dir, "mod1/cmd/cmd1"), 0755)
os.MkdirAll(filepath.Join(dir, "mod1/cmd/cmd2"), 0755)
os.MkdirAll(filepath.Join(dir, "mod1/nestedmod1/cmd/cmd5"), 0755)
os.MkdirAll(filepath.Join(dir, "mod1/nestedmod2/cmd/cmd6"), 0755)
os.MkdirAll(filepath.Join(dir, "mod2/cmd/cmd3"), 0755)
os.MkdirAll(filepath.Join(dir, "mod2/cmd/cmd4"), 0755)
os.MkdirAll(filepath.Join(dir, "nomod/cmd/cmd7"), 0755)
ioutil.WriteFile(filepath.Join(dir, "mod1/go.mod"), nil, 0644)
ioutil.WriteFile(filepath.Join(dir, "mod1/nestedmod1/go.mod"), nil, 0644)
ioutil.WriteFile(filepath.Join(dir, "mod1/nestedmod2/go.mod"), nil, 0644)
ioutil.WriteFile(filepath.Join(dir, "mod2/go.mod"), nil, 0644)
mustMkdir(t, filepath.Join(dir, "mod1/cmd/cmd1"), 0755)
mustMkdir(t, filepath.Join(dir, "mod1/cmd/cmd2"), 0755)
mustMkdir(t, filepath.Join(dir, "mod1/nestedmod1/cmd/cmd5"), 0755)
mustMkdir(t, filepath.Join(dir, "mod1/nestedmod2/cmd/cmd6"), 0755)
mustMkdir(t, filepath.Join(dir, "mod2/cmd/cmd3"), 0755)
mustMkdir(t, filepath.Join(dir, "mod2/cmd/cmd4"), 0755)
mustMkdir(t, filepath.Join(dir, "nomod/cmd/cmd7"), 0755)
mustWrite(t, filepath.Join(dir, "mod1/go.mod"), nil, 0644)
mustWrite(t, filepath.Join(dir, "mod1/nestedmod1/go.mod"), nil, 0644)
mustWrite(t, filepath.Join(dir, "mod1/nestedmod2/go.mod"), nil, 0644)
mustWrite(t, filepath.Join(dir, "mod2/go.mod"), nil, 0644)

paths := []string{
filepath.Join(dir, "mod1/cmd/cmd1"),
Expand Down
4 changes: 3 additions & 1 deletion src/pkg/golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (c Environ) envCommon() []string {
return env
}

// EnvHuman returns all env vars used by c, with an abbreviated
// PATH=$PATH:<added stuff> rather than displaying the full PATH.
func (c Environ) EnvHuman() []string {
env := c.envCommon()
if c.GOROOT != "" {
Expand All @@ -200,7 +202,7 @@ func (c Environ) String() string {
return strings.Join(c.EnvHuman(), " ")
}

// Optional arguments to Environ.BuildDir.
// BuildOpts are `go build` arguments.
type BuildOpts struct {
// NoStrip builds an unstripped binary.
//
Expand Down

0 comments on commit 0bf4cbe

Please sign in to comment.