From fe79c95a50bcf25269808d3333ff347f99855970 Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Tue, 5 Jan 2021 07:18:13 -0800 Subject: [PATCH] IWYU in sapi code generator PiperOrigin-RevId: 350134692 Change-Id: I5389df8a02f6679a3881b20b599ff5d9fc81650e --- sandboxed_api/bazel/sapi.bzl | 4 ++++ sandboxed_api/tools/generator2/BUILD | 7 +++++-- sandboxed_api/tools/generator2/code.py | 3 +++ sandboxed_api/tools/generator2/code_test_util.py | 9 +++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sandboxed_api/bazel/sapi.bzl b/sandboxed_api/bazel/sapi.bzl index 211d5a6..d1c49ea 100644 --- a/sandboxed_api/bazel/sapi.bzl +++ b/sandboxed_api/bazel/sapi.bzl @@ -31,6 +31,7 @@ def get_embed_dir(): return native.package_name() def sort_deps(deps): + deps = depset(deps).to_list() colon_deps = [x for x in deps if x.startswith(":")] other_deps = [x for x in deps if not x.startswith(":")] return sorted(colon_deps) + sorted(other_deps) @@ -192,7 +193,10 @@ def sapi_library( data = [":" + name + ".bin"], deps = sort_deps( [ + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", rprefix + "//sandboxed_api:sapi", + rprefix + "//sandboxed_api/util:status", rprefix + "//sandboxed_api:vars", ] + deps + ([":" + name + "_embed"] if embed else []) + diff --git a/sandboxed_api/tools/generator2/BUILD b/sandboxed_api/tools/generator2/BUILD index 7bee859..d901370 100644 --- a/sandboxed_api/tools/generator2/BUILD +++ b/sandboxed_api/tools/generator2/BUILD @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -licenses(["notice"]) - load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts") load("//sandboxed_api/bazel:sapi.bzl", "sapi_library") +licenses(["notice"]) + py_library( name = "code", srcs = ["code.py"], @@ -81,6 +81,9 @@ cc_binary( "//sandboxed_api:sapi", "//sandboxed_api:vars", "//sandboxed_api/sandbox2", + "//sandboxed_api/util:status", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", ], ) diff --git a/sandboxed_api/tools/generator2/code.py b/sandboxed_api/tools/generator2/code.py index ec1e4fc..a393459 100644 --- a/sandboxed_api/tools/generator2/code.py +++ b/sandboxed_api/tools/generator2/code.py @@ -906,7 +906,10 @@ class Generator(object): result.append(Generator.GUARD_START.format(header_guard)) # Copybara transform results in the paths below. + result.append('#include "absl/status/status.h"') + result.append('#include "absl/status/statusor.h"') result.append('#include "sandboxed_api/sandbox.h"') + result.append('#include "sandboxed_api/util/status_macros.h"') result.append('#include "sandboxed_api/vars.h"') if embed_name: diff --git a/sandboxed_api/tools/generator2/code_test_util.py b/sandboxed_api/tools/generator2/code_test_util.py index 82ee3a6..50b51ac 100644 --- a/sandboxed_api/tools/generator2/code_test_util.py +++ b/sandboxed_api/tools/generator2/code_test_util.py @@ -18,7 +18,10 @@ CODE_GOLD = """// AUTO-GENERATED by the Sandboxed API generator. // Edits will be discarded when regenerating this file. +#include "absl/status/status.h" +#include "absl/status/statusor.h" #include "sandboxed_api/sandbox.h" +#include "sandboxed_api/util/status_macros.h" #include "sandboxed_api/vars.h" namespace sapi { @@ -119,7 +122,10 @@ class TestApi { CODE_GOLD_MAPPED = """// AUTO-GENERATED by the Sandboxed API generator. // Edits will be discarded when regenerating this file. +#include "absl/status/status.h" +#include "absl/status/statusor.h" #include "sandboxed_api/sandbox.h" +#include "sandboxed_api/util/status_macros.h" #include "sandboxed_api/vars.h" namespace sapi { @@ -154,7 +160,10 @@ class TestApi { CODE_ENUM_GOLD = """// AUTO-GENERATED by the Sandboxed API generator. // Edits will be discarded when regenerating this file. +#include "absl/status/status.h" +#include "absl/status/statusor.h" #include "sandboxed_api/sandbox.h" +#include "sandboxed_api/util/status_macros.h" #include "sandboxed_api/vars.h" namespace sapi {