Skip to content

Commit 0bf4cbe

Browse files
committed
Lint fixes
Signed-off-by: Chris Koch <[email protected]>
1 parent 6080228 commit 0bf4cbe

File tree

5 files changed

+35
-41
lines changed

5 files changed

+35
-41
lines changed

Diff for: src/cmd/makebbmain/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
)
1717

1818
var (
19-
pkg = flag.String("template_pkg", "", "Go import package path")
2019
destDir = flag.String("dest_dir", "", "Destination directory")
2120
pkgFiles uflag.Strings
2221
commands uflag.Strings

Diff for: src/gobb2.bzl

-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ def _go_busybox_impl(ctx):
182182

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

187186
outputs = []
188187
inputs = []

Diff for: src/pkg/bb/bb.go

+9-23
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"os"
3131
"path"
3232
"path/filepath"
33-
"regexp"
3433
"strings"
3534

3635
"github.com/google/goterm/term"
@@ -255,11 +254,10 @@ func BuildBusybox(l ulog.Logger, opts *Opts) (nerr error) {
255254
GOPATH: tmpDir,
256255
Err: err,
257256
}
258-
} else {
259-
return &ErrModuleBuild{
260-
CmdDir: bbDir,
261-
Err: err,
262-
}
257+
}
258+
return &ErrModuleBuild{
259+
CmdDir: bbDir,
260+
Err: err,
263261
}
264262
}
265263
return nil
@@ -504,7 +502,7 @@ func findLocalModules(l ulog.Logger, mainPkgs []*bbinternal.Package) (map[string
504502

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

650-
mod.AddModuleStmt("bb.u-root.com/bb")
648+
if err := mod.AddModuleStmt("bb.u-root.com/bb"); err != nil {
649+
return fmt.Errorf("failed to add bb.u-root.com/bb to generated go.mod: %w", err)
650+
}
651651
for mpath, module := range localModules {
652652
v := module.Version
653653
if len(v) == 0 {
@@ -679,25 +679,11 @@ func copyLocalDeps(l ulog.Logger, env *golang.Environ, bbDir, tmpDir, pkgDir str
679679
// directives.
680680
//
681681
// Warn the user if they are potentially incompatible.
682-
if err := ioutil.WriteFile(filepath.Join(bbDir, "go.mod"), gomod, 0755); err != nil {
683-
return err
684-
}
685-
return nil
682+
return ioutil.WriteFile(filepath.Join(bbDir, "go.mod"), gomod, 0755)
686683
}
687684
return nil
688685
}
689686

690-
func versionNum(mpath string) string {
691-
last := path.Base(mpath)
692-
if len(last) == 0 {
693-
return "v0"
694-
}
695-
if matched, _ := regexp.Match("v[0-9]+", []byte(last)); matched {
696-
return last
697-
}
698-
return "v0"
699-
}
700-
701687
// deps recursively iterates through imports and returns the set of packages
702688
// for which filter returns true.
703689
func deps(p *packages.Package, filter func(p *packages.Package) bool) []*packages.Package {

Diff for: src/pkg/bb/findpkg/bb_test.go

+23-15
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,32 @@ var (
2323
urootSource = flag.String("uroot-source", "", "Directory path to u-root source location")
2424
)
2525

26-
func TestModules(t *testing.T) {
27-
dir, err := ioutil.TempDir("", "test-modules-")
28-
if err != nil {
26+
func mustMkdir(t *testing.T, path string, mode os.FileMode) {
27+
if err := os.MkdirAll(path, mode); err != nil {
2928
t.Fatal(err)
3029
}
31-
defer os.RemoveAll(dir)
30+
}
31+
32+
func mustWrite(t *testing.T, path string, contents []byte, mode os.FileMode) {
33+
if err := os.WriteFile(path, contents, mode); err != nil {
34+
t.Fatal(err)
35+
}
36+
}
37+
38+
func TestModules(t *testing.T) {
39+
dir := t.TempDir()
3240

33-
os.MkdirAll(filepath.Join(dir, "mod1/cmd/cmd1"), 0755)
34-
os.MkdirAll(filepath.Join(dir, "mod1/cmd/cmd2"), 0755)
35-
os.MkdirAll(filepath.Join(dir, "mod1/nestedmod1/cmd/cmd5"), 0755)
36-
os.MkdirAll(filepath.Join(dir, "mod1/nestedmod2/cmd/cmd6"), 0755)
37-
os.MkdirAll(filepath.Join(dir, "mod2/cmd/cmd3"), 0755)
38-
os.MkdirAll(filepath.Join(dir, "mod2/cmd/cmd4"), 0755)
39-
os.MkdirAll(filepath.Join(dir, "nomod/cmd/cmd7"), 0755)
40-
ioutil.WriteFile(filepath.Join(dir, "mod1/go.mod"), nil, 0644)
41-
ioutil.WriteFile(filepath.Join(dir, "mod1/nestedmod1/go.mod"), nil, 0644)
42-
ioutil.WriteFile(filepath.Join(dir, "mod1/nestedmod2/go.mod"), nil, 0644)
43-
ioutil.WriteFile(filepath.Join(dir, "mod2/go.mod"), nil, 0644)
41+
mustMkdir(t, filepath.Join(dir, "mod1/cmd/cmd1"), 0755)
42+
mustMkdir(t, filepath.Join(dir, "mod1/cmd/cmd2"), 0755)
43+
mustMkdir(t, filepath.Join(dir, "mod1/nestedmod1/cmd/cmd5"), 0755)
44+
mustMkdir(t, filepath.Join(dir, "mod1/nestedmod2/cmd/cmd6"), 0755)
45+
mustMkdir(t, filepath.Join(dir, "mod2/cmd/cmd3"), 0755)
46+
mustMkdir(t, filepath.Join(dir, "mod2/cmd/cmd4"), 0755)
47+
mustMkdir(t, filepath.Join(dir, "nomod/cmd/cmd7"), 0755)
48+
mustWrite(t, filepath.Join(dir, "mod1/go.mod"), nil, 0644)
49+
mustWrite(t, filepath.Join(dir, "mod1/nestedmod1/go.mod"), nil, 0644)
50+
mustWrite(t, filepath.Join(dir, "mod1/nestedmod2/go.mod"), nil, 0644)
51+
mustWrite(t, filepath.Join(dir, "mod2/go.mod"), nil, 0644)
4452

4553
paths := []string{
4654
filepath.Join(dir, "mod1/cmd/cmd1"),

Diff for: src/pkg/golang/build.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ func (c Environ) envCommon() []string {
175175
return env
176176
}
177177

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

203-
// Optional arguments to Environ.BuildDir.
205+
// BuildOpts are `go build` arguments.
204206
type BuildOpts struct {
205207
// NoStrip builds an unstripped binary.
206208
//

0 commit comments

Comments
 (0)