This fixes broken _proto_cc_cc_proto build target suffixes.

These where inadvertently introduced in an internal cleanup change.

This change also removes a C++17-ism in var_proto.h. To make things easier for
downstream projects, we should stick to C++11 for the time being.

PiperOrigin-RevId: 271117700
Change-Id: I4eaacec88be16e1a561d3f77a61acce0a1af0b9d
This commit is contained in:
Christian Blichmann 2019-09-25 07:13:33 -07:00 committed by Copybara-Service
parent ce46cb3fef
commit c6b8e301e4
22 changed files with 91 additions and 79 deletions

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
exports_files(["LICENSE"])
@ -142,7 +142,7 @@ cc_library(
deps = [
":call",
":lenval_core",
":proto_arg_cc_cc_proto",
":proto_arg_cc_proto",
":var_type",
"//sandboxed_api/sandbox2:comms",
"//sandboxed_api/util:status",
@ -169,7 +169,7 @@ cc_library(
deps = [
":call",
":lenval_core",
":proto_arg_cc_cc_proto",
":proto_arg_cc_proto",
":vars",
"//sandboxed_api/sandbox2:client",
"//sandboxed_api/sandbox2:comms",
@ -190,7 +190,7 @@ cc_test(
deps = [
":sapi",
"//sandboxed_api/examples/stringop/lib:stringop-sapi",
"//sandboxed_api/examples/stringop/lib:stringop_params_proto_cc",
"//sandboxed_api/examples/stringop/lib:stringop_params_cc_proto",
"//sandboxed_api/examples/sum/lib:sum-sapi",
"//sandboxed_api/examples/sum/lib:sum-sapi_embed",
"//sandboxed_api/util:status",

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"]) # Apache v2.0
licenses(["notice"])
exports_files([
"proto.bzl",

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"]) # BSD/MIT-like license
licenses(["notice"])
cc_library(
name = "zlib",

View File

@ -14,11 +14,41 @@
"""Generates proto targets in various languages."""
load(
"@com_google_protobuf//:protobuf.bzl",
"cc_proto_library",
"py_proto_library",
)
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
def _cc_proto_library_name_from_proto_name(name):
"""Converts proto name to cc_proto_library name.
Several suffixes will be considered.
Args:
name: the proto name
Returns:
The cc_proto_library name.
"""
name = name.replace("-", "_")
if name == "proto":
# replace 'proto' with 'cc_proto'
return "cc_proto"
for suffix in [
".protolib",
"protolib",
"proto2lib",
"proto_lib",
"proto2",
"protos",
"proto2_lib",
"libproto",
"genproto",
"proto",
]:
# replace 'suffix' or '_suffix' with '_cc_proto'
if name.endswith("_" + suffix):
return name[:-len("_" + suffix)] + "_cc_proto"
elif name.endswith(suffix):
return name[:-len(suffix)] + "_cc_proto"
# no match; simply append '_cc_proto' to the end
return name + "_cc_proto"
def sapi_proto_library(
name,
@ -30,7 +60,7 @@ def sapi_proto_library(
Args:
name: Name for proto_library and base for the cc_proto_library name, name +
"_cc".
"_cc_proto".
srcs: Same as proto_library deps.
deps: Same as proto_library deps.
alwayslink: Same as cc_library.
@ -39,10 +69,6 @@ def sapi_proto_library(
if kwargs.get("has_services", False):
fail("Services are not currently supported.")
# TODO(cblichmann): For the time being, rely on the non-native rule
# provided by Protobuf. Once the Starlark C++ API has
# landed, it'll become possible to implement alwayslink
# natively.
cc_proto_library(
name = name,
srcs = srcs,
@ -51,25 +77,8 @@ def sapi_proto_library(
**kwargs
)
native.cc_library(
name = name + "_cc",
deps = [":" + name],
**kwargs
)
def sapi_py_proto_library(name, srcs = [], deps = [], **kwargs):
"""Generates proto targets for Python.
Args:
name: Name for proto_library.
srcs: Same as py_proto_library deps.
deps: Ignored, provided for compatibility only.
**kwargs: proto_library arguments.
"""
_ignore = [deps]
py_proto_library(
name = name,
srcs = srcs,
default_runtime = "@com_google_protobuf//:protobuf_python",
protoc = "@com_google_protobuf//:protoc",
name = _cc_proto_library_name_from_proto_name(name),
deps = [name],
alwayslink = alwayslink,
**kwargs
)

View File

@ -157,6 +157,8 @@ def sapi_library(
visibility = None):
"""BUILD rule providing implementation of a Sandboxed API library."""
repo_name = native.repository_name()
rprefix = "@com_google_sandboxed_api" if repo_name != "@" else ""
common = {
"tags": tags,
}
@ -180,7 +182,7 @@ def sapi_library(
else:
lib_hdrs += [generated_header]
default_deps = ["@com_google_sandboxed_api//sandboxed_api/sandbox2"]
default_deps = [rprefix + "//sandboxed_api/sandbox2"]
# Library that contains generated interface and sandboxed binary as a data
# dependency. Add this as a dependency instead of original library.
@ -191,8 +193,8 @@ def sapi_library(
data = [":" + name + ".bin"],
deps = sort_deps(
[
"@com_google_sandboxed_api//sandboxed_api:sapi",
"@com_google_sandboxed_api//sandboxed_api:vars",
rprefix + "//sandboxed_api:sapi",
rprefix + "//sandboxed_api:vars",
] + deps +
([":" + name + "_embed"] if embed else []) +
(default_deps if add_default_deps else []),
@ -208,7 +210,7 @@ def sapi_library(
] + exported_funcs, # must be both referenced, and exported
deps = [
":" + name + ".lib",
"@com_google_sandboxed_api//sandboxed_api:client",
rprefix + "//sandboxed_api:client",
],
**common
)

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Description: Examples using dynamic length structures for Sandboxed-API
# Description: Example using dynamic length structures for Sandboxed API
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
@ -27,7 +27,7 @@ cc_test(
"//sandboxed_api:sapi",
"//sandboxed_api:vars",
"//sandboxed_api/examples/stringop/lib:stringop-sapi",
"//sandboxed_api/examples/stringop/lib:stringop_params_proto_cc_cc_proto",
"//sandboxed_api/examples/stringop/lib:stringop_params_cc_proto",
"//sandboxed_api/util:flags",
"//sandboxed_api/util:status",
"//sandboxed_api/util:status_matchers",

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
load("//sandboxed_api/bazel:proto.bzl", "sapi_proto_library")
@ -30,7 +30,7 @@ cc_library(
copts = sapi_platform_copts(),
visibility = ["//visibility:public"],
deps = [
":stringop_params_proto_cc_cc_proto",
":stringop_params_cc_proto",
"//sandboxed_api:lenval_core",
],
alwayslink = 1, # All functions are linked into dependent binaries
@ -55,5 +55,5 @@ sapi_library(
lib_name = "Stringop",
namespace = "",
visibility = ["//visibility:public"],
deps = [":stringop_params_proto_cc"],
deps = [":stringop_params_cc_proto"],
)

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
@ -25,7 +25,7 @@ cc_binary(
"//sandboxed_api:sapi",
"//sandboxed_api:vars",
"//sandboxed_api/examples/sum/lib:sum-sapi",
"//sandboxed_api/examples/sum/lib:sum_params_proto_cc_cc_proto",
"//sandboxed_api/examples/sum/lib:sum_params_cc_proto",
"//sandboxed_api/util:flags",
"//sandboxed_api/util:status",
"@com_google_absl//absl/memory",

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
load("//sandboxed_api/bazel:proto.bzl", "sapi_proto_library")
@ -34,7 +34,7 @@ cc_library(
copts = sapi_platform_copts(),
visibility = ["//visibility:public"],
deps = [
":sum_params_proto_cc_cc_proto",
":sum_params_cc_proto",
"@com_google_glog//:glog",
],
alwayslink = 1, # All functions are linked into depending binaries
@ -68,5 +68,5 @@ sapi_library(
lib_name = "Sum",
namespace = "",
visibility = ["//visibility:public"],
deps = [":sum_params_proto_cc"],
deps = [":sum_params_cc_proto"],
)

View File

@ -14,7 +14,7 @@
# Description: Sandboxed API reimplementation of zlib's zpipe.c example.
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
load("//sandboxed_api/bazel:sapi.bzl", "sapi_library")

View File

@ -39,7 +39,7 @@ cc_library(
copts = sapi_platform_copts(),
deps = [
":syscall",
":violation_proto_cc_cc_proto",
":violation_cc_proto",
"//sandboxed_api/sandbox2/util:strerror",
"//sandboxed_api/util:status",
"@com_google_absl//absl/base:core_headers",
@ -105,7 +105,7 @@ cc_library(
copts = sapi_platform_copts(),
deps = [
":comms",
":logserver_proto_cc_cc_proto",
":logserver_cc_proto",
"@com_google_glog//:glog",
],
)
@ -118,7 +118,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":comms",
":logserver_proto_cc_cc_proto",
":logserver_cc_proto",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_glog//:glog",
@ -183,7 +183,7 @@ cc_library(
":namespace",
":regs",
":syscall",
":violation_proto_cc_cc_proto",
":violation_cc_proto",
"//sandboxed_api/sandbox2/util:bpf_helper",
"//sandboxed_api/util:flags",
"@com_google_absl//absl/base:core_headers",
@ -259,7 +259,7 @@ cc_library(
copts = sapi_platform_copts(),
deps = [
":forkserver",
":forkserver_proto_cc",
":forkserver_cc_proto",
":global_forkserver",
":ipc",
":limits",
@ -304,9 +304,9 @@ cc_library(
":client",
":executor",
":comms",
":violation_proto_cc_cc_proto",
":violation_cc_proto",
":forkserver",
":forkserver_proto_cc_cc_proto",
":forkserver_cc_proto",
":global_forkserver",
":ipc",
":limits",
@ -332,7 +332,7 @@ cc_library(
"@com_google_absl//absl/types:optional",
"@org_kernel_libcap//:libcap",
"//sandboxed_api/sandbox2/unwind",
"//sandboxed_api/sandbox2/unwind:unwind_proto_cc_cc_proto",
"//sandboxed_api/sandbox2/unwind:unwind_cc_proto",
"//sandboxed_api/sandbox2/util:bpf_helper",
"//sandboxed_api/sandbox2/util:file_base",
"//sandboxed_api/sandbox2/util:fileops",
@ -383,14 +383,14 @@ cc_library(
deps = [
":client",
":comms",
":forkserver_proto_cc_cc_proto",
":forkserver_cc_proto",
":namespace",
":policy",
":syscall",
":util",
"//sandboxed_api/sandbox2/unwind",
"//sandboxed_api/sandbox2/unwind:ptrace_hook",
"//sandboxed_api/sandbox2/unwind:unwind_proto_cc_cc_proto",
"//sandboxed_api/sandbox2/unwind:unwind_cc_proto",
"//sandboxed_api/sandbox2/util:bpf_helper",
"//sandboxed_api/sandbox2/util:fileops",
"//sandboxed_api/sandbox2/util:strerror",
@ -410,7 +410,7 @@ cc_library(
hdrs = ["mounts.h"],
copts = sapi_platform_copts(),
deps = [
":mounttree_proto_cc_cc_proto",
":mounttree_cc_proto",
"//sandboxed_api/sandbox2/util:file_base",
"//sandboxed_api/sandbox2/util:fileops",
"//sandboxed_api/sandbox2/util:minielf",
@ -449,9 +449,9 @@ cc_library(
copts = sapi_platform_copts(),
deps = [
":mounts",
":mounttree_proto_cc_cc_proto",
":mounttree_cc_proto",
":util",
":violation_proto_cc_cc_proto",
":violation_cc_proto",
"//sandboxed_api/sandbox2/util:file_base",
"//sandboxed_api/sandbox2/util:fileops",
"//sandboxed_api/sandbox2/util:strerror",
@ -597,7 +597,7 @@ cc_test(
copts = sapi_platform_copts(),
deps = [
":comms",
":comms_test_proto_cc_cc_proto",
":comms_test_cc_proto",
"//sandboxed_api/util:status_matchers",
"@com_google_absl//absl/container:fixed_array",
"@com_google_absl//absl/strings",
@ -618,7 +618,7 @@ cc_test(
deps = [
":comms",
":forkserver",
":forkserver_proto_cc_cc_proto",
":forkserver_cc_proto",
":sandbox2",
":testing",
"@com_google_absl//absl/strings",

View File

@ -19,7 +19,7 @@
# - Using sandbox2::Comms for data exchange (IPC)
# - Test to ensure sandbox executor runs sandboxee without issue
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")

View File

@ -16,7 +16,7 @@
# - create a custom fork-server, which will prepare and fork a sandboxee
# from the current process
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")

View File

@ -18,7 +18,7 @@
# - strict syscall policy
# - sandbox2::Comms for data exchange (IPC)
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")

View File

@ -14,7 +14,7 @@
# The 'network proxy' example demonstrates how to use network proxy server.
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")

View File

@ -19,7 +19,7 @@
# - communication with file descriptors and MapFd
# - test to ensure sandbox executor runs sandboxee without issue
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")

View File

@ -20,7 +20,7 @@
# - set limits, wall time, filesystem checks, asynchronous run
# - test to ensure sandbox executor runs sandboxee without issue
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")

View File

@ -50,7 +50,7 @@ cc_library(
]
]),
deps = [
":unwind_proto_cc_cc_proto",
":unwind_cc_proto",
"//sandboxed_api/sandbox2:comms",
"//sandboxed_api/sandbox2/util:maps_parser",
"//sandboxed_api/sandbox2/util:minielf",

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
load("//sandboxed_api/bazel:sapi.bzl", "sapi_library")

View File

@ -14,7 +14,7 @@
package(default_visibility = ["//sandboxed_api:__subpackages__"])
licenses(["notice"]) # Apache 2.0
licenses(["notice"])
load("//sandboxed_api/bazel:proto.bzl", "sapi_proto_library")
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
@ -41,7 +41,7 @@ cc_library(
copts = sapi_platform_copts(),
visibility = ["//visibility:public"],
deps = [
":status_proto_cc_cc_proto",
":status_cc_proto",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/meta:type_traits",
"@com_google_absl//absl/strings",

View File

@ -68,7 +68,8 @@ class Proto : public Pointable, public Var {
ABSL_DEPRECATED("Use GetMessage() instead")
std::unique_ptr<T> GetProtoCopy() const {
if (auto result_or = GetMessage(); result_or.ok()) {
auto result_or = GetMessage();
if (result_or.ok()) {
return absl::make_unique<T>(std::move(result_or).ValueOrDie());
}
return nullptr;