diff options
author | Adin Scannell <ascannell@google.com> | 2020-02-05 22:45:44 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-02-05 22:46:35 -0800 |
commit | 1b6a12a768216a99a5e0428c42ea4faf79cf3b50 (patch) | |
tree | 995d1ae4ba930d3c6b8fde0f3d1651db472c0dba /tools/defs.bzl | |
parent | f3d95607036b8a502c65aa7b3e8145227274dbbc (diff) |
Add notes to relevant tests.
These were out-of-band notes that can help provide additional context
and simplify automated imports.
PiperOrigin-RevId: 293525915
Diffstat (limited to 'tools/defs.bzl')
-rw-r--r-- | tools/defs.bzl | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tools/defs.bzl b/tools/defs.bzl index 5d5fa134a..c03b557ae 100644 --- a/tools/defs.bzl +++ b/tools/defs.bzl @@ -73,6 +73,16 @@ def calculate_sets(srcs): result[target].append(file) return result +def go_imports(name, src, out): + """Simplify a single Go source file by eliminating unused imports.""" + native.genrule( + name = name, + srcs = [src], + outs = [out], + tools = ["@org_golang_x_tools//cmd/goimports:goimports"], + cmd = ("$(location @org_golang_x_tools//cmd/goimports:goimports) $(SRCS) > $@"), + ) + def go_library(name, srcs, deps = [], imports = [], stateify = True, marshal = False, **kwargs): """Wraps the standard go_library and does stateification and marshalling. @@ -107,10 +117,15 @@ def go_library(name, srcs, deps = [], imports = [], stateify = True, marshal = F state_sets = calculate_sets(srcs) for (suffix, srcs) in state_sets.items(): go_stateify( - name = name + suffix + "_state_autogen", + name = name + suffix + "_state_autogen_with_imports", srcs = srcs, imports = imports, package = name, + out = name + suffix + "_state_autogen_with_imports.go", + ) + go_imports( + name = name + suffix + "_state_autogen", + src = name + suffix + "_state_autogen_with_imports.go", out = name + suffix + "_state_autogen.go", ) all_srcs = all_srcs + [ |