Add hook to add addition build tags

PiperOrigin-RevId: 404025736
This commit is contained in:
Michael Pratt
2021-10-18 12:16:53 -07:00
committed by gVisor bot
parent eafa3f19e4
commit c7e5b4bd67
4 changed files with 31 additions and 12 deletions
+5
View File
@@ -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
}
+8
View File
@@ -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!")
+2 -2
View File
@@ -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,
+16 -10
View File
@@ -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
}