summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2021-10-18 12:14:22 -0700
committergVisor bot <gvisor-bot@google.com>2021-10-18 12:16:53 -0700
commitc7e5b4bd67e0a80c07bf051654e7d28fb592cc39 (patch)
tree7eebb8f638322768ac6616bfa96a39fa53fd60dd /tools
parenteafa3f19e4d2c0a490af78dbe77289c7b5edbb76 (diff)
Add hook to add addition build tags
PiperOrigin-RevId: 404025736
Diffstat (limited to 'tools')
-rw-r--r--tools/nogo/build.go5
-rw-r--r--tools/nogo/check/main.go8
-rw-r--r--tools/nogo/defs.bzl4
-rw-r--r--tools/nogo/nogo.go26
4 files changed, 31 insertions, 12 deletions
diff --git a/tools/nogo/build.go b/tools/nogo/build.go
index 4067bb480..003533c71 100644
--- a/tools/nogo/build.go
+++ b/tools/nogo/build.go
@@ -31,3 +31,8 @@ func findStdPkg(GOOS, GOARCH, path string) (io.ReadCloser, error) {
}
return os.Open(fmt.Sprintf("external/go_sdk/pkg/%s_%s/%s.a", GOOS, GOARCH, path))
}
+
+// ReleaseTags returns nil, indicating that the defaults should be used.
+func ReleaseTags() ([]string, error) {
+ return nil, nil
+}
diff --git a/tools/nogo/check/main.go b/tools/nogo/check/main.go
index 0e7e92965..17ca0d846 100644
--- a/tools/nogo/check/main.go
+++ b/tools/nogo/check/main.go
@@ -66,14 +66,22 @@ func run([]string) int {
return 1
}
+ releaseTags, err := nogo.ReleaseTags()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "error determining release tags: %v", err)
+ return 1
+ }
+
// Run the configuration.
if *stdlibFile != "" {
// Perform stdlib analysis.
c := loadConfig(*stdlibFile, new(nogo.StdlibConfig)).(*nogo.StdlibConfig)
+ c.ReleaseTags = releaseTags
findings, factData, err = nogo.CheckStdlib(c, nogo.AllAnalyzers)
} else if *packageFile != "" {
// Perform standard analysis.
c := loadConfig(*packageFile, new(nogo.PackageConfig)).(*nogo.PackageConfig)
+ c.ReleaseTags = releaseTags
findings, factData, err = nogo.CheckPackage(c, nogo.AllAnalyzers, nil)
} else {
fmt.Fprintf(os.Stderr, "please provide at least one of package or stdlib!")
diff --git a/tools/nogo/defs.bzl b/tools/nogo/defs.bzl
index dc9a8b24e..bc0d6874f 100644
--- a/tools/nogo/defs.bzl
+++ b/tools/nogo/defs.bzl
@@ -126,7 +126,7 @@ def _nogo_stdlib_impl(ctx):
Srcs = [f.path for f in go_ctx.stdlib_srcs],
GOOS = go_ctx.goos,
GOARCH = go_ctx.goarch,
- Tags = go_ctx.gotags,
+ BuildTags = go_ctx.gotags,
)
config_file = ctx.actions.declare_file(ctx.label.name + ".cfg")
ctx.actions.write(config_file, config.to_json())
@@ -321,7 +321,7 @@ def _nogo_aspect_impl(target, ctx):
NonGoFiles = [src.path for src in srcs if not src.path.endswith(".go")],
GOOS = go_ctx.goos,
GOARCH = go_ctx.goarch,
- Tags = go_ctx.gotags,
+ BuildTags = go_ctx.gotags,
FactMap = fact_map,
ImportMap = import_map,
StdlibFacts = stdlib_facts.path,
diff --git a/tools/nogo/nogo.go b/tools/nogo/nogo.go
index 2f88f84db..a96cb400a 100644
--- a/tools/nogo/nogo.go
+++ b/tools/nogo/nogo.go
@@ -52,10 +52,11 @@ import (
//
// This contains everything required for stdlib analysis.
type StdlibConfig struct {
- Srcs []string
- GOOS string
- GOARCH string
- Tags []string
+ Srcs []string
+ GOOS string
+ GOARCH string
+ BuildTags []string
+ ReleaseTags []string // Use build.Default if nil.
}
// PackageConfig is serialized as the configuration.
@@ -65,7 +66,8 @@ type PackageConfig struct {
ImportPath string
GoFiles []string
NonGoFiles []string
- Tags []string
+ BuildTags []string
+ ReleaseTags []string // Use build.Default if nil.
GOOS string
GOARCH string
ImportMap map[string]string
@@ -182,7 +184,10 @@ func (c *PackageConfig) shouldInclude(path string) (bool, error) {
ctx := build.Default
ctx.GOOS = c.GOOS
ctx.GOARCH = c.GOARCH
- ctx.BuildTags = c.Tags
+ ctx.BuildTags = c.BuildTags
+ if c.ReleaseTags != nil {
+ ctx.ReleaseTags = c.ReleaseTags
+ }
return ctx.MatchFile(filepath.Dir(path), filepath.Base(path))
}
@@ -333,10 +338,11 @@ func CheckStdlib(config *StdlibConfig, analyzers []*analysis.Analyzer) (allFindi
c, ok := packages[pkg]
if !ok {
c = &PackageConfig{
- ImportPath: pkg,
- GOOS: config.GOOS,
- GOARCH: config.GOARCH,
- Tags: config.Tags,
+ ImportPath: pkg,
+ GOOS: config.GOOS,
+ GOARCH: config.GOARCH,
+ BuildTags: config.BuildTags,
+ ReleaseTags: config.ReleaseTags,
}
packages[pkg] = c
}