Minor nogo cleanup.

PiperOrigin-RevId: 336126583
This commit is contained in:
Adin Scannell
2020-10-08 11:24:21 -07:00
committed by gVisor bot
parent 06200cb5cf
commit 5124ce579d
4 changed files with 24 additions and 25 deletions
+3 -3
View File
@@ -102,8 +102,8 @@ var (
// This may be set instead of Binary.
Reader io.Reader
// Tool is the tool used to dump a binary.
tool = flag.String("dump_tool", "", "tool used to dump a binary")
// objdumpTool is the tool used to dump a binary.
objdumpTool = flag.String("objdump_tool", "", "tool used to dump a binary")
)
// EscapeReason is an escape reason.
@@ -387,7 +387,7 @@ func loadObjdump() (map[string][]string, error) {
}
// Construct our command.
cmd := exec.Command(*tool, args...)
cmd := exec.Command(*objdumpTool, args...)
cmd.Stdin = stdin
cmd.Stderr = os.Stderr
out, err := cmd.StdoutPipe()
+3 -3
View File
@@ -72,7 +72,7 @@ def go_binary(name, nogo = True, pure = False, static = False, x_defs = None, **
)
nogo_test(
name = name + "_nogo",
deps = [":" + name + "_nogo_library"],
library = ":" + name + "_nogo_library",
)
def calculate_sets(srcs):
@@ -203,7 +203,7 @@ def go_library(name, srcs, deps = [], imports = [], stateify = True, marshal = F
if nogo:
nogo_test(
name = name + "_nogo",
deps = [":" + name],
library = ":" + name,
)
if marshal:
@@ -239,7 +239,7 @@ def go_test(name, nogo = True, **kwargs):
if nogo:
nogo_test(
name = name + "_nogo",
deps = [":" + name],
library = ":" + name,
)
def proto_library(name, srcs, deps = None, has_services = 0, **kwargs):
+3 -3
View File
@@ -1,10 +1,10 @@
load("//tools:defs.bzl", "bzl_library", "go_library")
load("//tools/nogo:defs.bzl", "nogo_dump_tool", "nogo_stdlib")
load("//tools/nogo:defs.bzl", "nogo_objdump_tool", "nogo_stdlib")
package(licenses = ["notice"])
nogo_dump_tool(
name = "dump_tool",
nogo_objdump_tool(
name = "objdump_tool",
visibility = ["//visibility:public"],
)
+15 -16
View File
@@ -2,8 +2,7 @@
load("//tools/bazeldefs:defs.bzl", "go_context", "go_importpath", "go_rule", "go_test_library")
def _nogo_dump_tool_impl(ctx):
# Extract the Go context.
def _nogo_objdump_tool_impl(ctx):
go_ctx = go_context(ctx)
# Construct the magic dump command.
@@ -40,9 +39,9 @@ def _nogo_dump_tool_impl(ctx):
executable = dumper,
)]
nogo_dump_tool = go_rule(
nogo_objdump_tool = go_rule(
rule,
implementation = _nogo_dump_tool_impl,
implementation = _nogo_objdump_tool_impl,
)
# NogoStdlibInfo is the set of standard library facts.
@@ -55,7 +54,6 @@ NogoStdlibInfo = provider(
)
def _nogo_stdlib_impl(ctx):
# Extract the Go context.
go_ctx = go_context(ctx)
# Build the standard library facts.
@@ -72,12 +70,12 @@ def _nogo_stdlib_impl(ctx):
ctx.actions.run(
inputs = [config_file] + go_ctx.stdlib_srcs,
outputs = [facts, findings],
tools = depset(go_ctx.runfiles.to_list() + ctx.files._dump_tool),
tools = depset(go_ctx.runfiles.to_list() + ctx.files._objdump_tool),
executable = ctx.files._nogo[0],
mnemonic = "GoStandardLibraryAnalysis",
progress_message = "Analyzing Go Standard Library",
arguments = go_ctx.nogo_args + [
"-dump_tool=%s" % ctx.files._dump_tool[0].path,
"-objdump_tool=%s" % ctx.files._objdump_tool[0].path,
"-stdlib=%s" % config_file.path,
"-findings=%s" % findings.path,
"-facts=%s" % facts.path,
@@ -97,8 +95,8 @@ nogo_stdlib = go_rule(
"_nogo": attr.label(
default = "//tools/nogo/check:check",
),
"_dump_tool": attr.label(
default = "//tools/nogo:dump_tool",
"_objdump_tool": attr.label(
default = "//tools/nogo:objdump_tool",
),
},
)
@@ -121,6 +119,8 @@ NogoInfo = provider(
)
def _nogo_aspect_impl(target, ctx):
go_ctx = go_context(ctx)
# If this is a nogo rule itself (and not the shadow of a go_library or
# go_binary rule created by such a rule), then we simply return nothing.
# All work is done in the shadow properties for go rules. For a proto
@@ -135,9 +135,6 @@ def _nogo_aspect_impl(target, ctx):
else:
return [NogoInfo()]
# Extract the Go context.
go_ctx = go_context(ctx)
# If we're using the "library" attribute, then we need to aggregate the
# original library sources and dependencies into this target to perform
# proper type analysis.
@@ -227,13 +224,13 @@ def _nogo_aspect_impl(target, ctx):
ctx.actions.run(
inputs = inputs,
outputs = [facts, findings, escapes],
tools = depset(go_ctx.runfiles.to_list() + ctx.files._dump_tool),
tools = depset(go_ctx.runfiles.to_list() + ctx.files._objdump_tool),
executable = ctx.files._nogo[0],
mnemonic = "GoStaticAnalysis",
progress_message = "Analyzing %s" % target.label,
arguments = go_ctx.nogo_args + [
"-binary=%s" % target_objfile.path,
"-dump_tool=%s" % ctx.files._dump_tool[0].path,
"-objdump_tool=%s" % ctx.files._objdump_tool[0].path,
"-package=%s" % config_file.path,
"-findings=%s" % findings.path,
"-facts=%s" % facts.path,
@@ -271,7 +268,7 @@ nogo_aspect = go_rule(
attrs = {
"_nogo": attr.label(default = "//tools/nogo/check:check"),
"_nogo_stdlib": attr.label(default = "//tools/nogo:stdlib"),
"_dump_tool": attr.label(default = "//tools/nogo:dump_tool"),
"_objdump_tool": attr.label(default = "//tools/nogo:objdump_tool"),
},
)
@@ -314,15 +311,17 @@ def _nogo_test_impl(ctx):
_nogo_test = rule(
implementation = _nogo_test_impl,
attrs = {
# deps should have only a single element.
"deps": attr.label_list(aspects = [nogo_aspect]),
},
test = True,
)
def nogo_test(name, **kwargs):
def nogo_test(name, library, **kwargs):
tags = kwargs.pop("tags", []) + ["nogo"]
_nogo_test(
name = name,
deps = [library],
tags = tags,
**kwargs
)