From 4e20e0702ab6329d59947a7599f7947535c08b9d Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Mon, 1 Jul 2019 02:53:20 -0700 Subject: [PATCH] Use full workspace name to access Bazel packages in generator Since the interface generator is invoked via a Bazel macro, it will be expanded in the embedding context of the project using SAPI, so package access needs to go through the full workspace root @com_google_sandboxed_api. This change also modifies the CMakeLists.txt accordingly, as the "external" subdirectory is no longer needed/wanted. PiperOrigin-RevId: 255918784 Change-Id: I052c687509f65fef7f011a9d1a074a171595330f --- CMakeLists.txt | 4 +-- cmake/FindLibunwind.cmake | 34 -------------------- sandboxed_api/bazel/external/libunwind.BUILD | 1 + sandboxed_api/bazel/sapi.bzl | 12 +++---- sandboxed_api/bazel/sapi_deps.bzl | 8 ++--- sandboxed_api/sandbox2/executor.cc | 2 +- sandboxed_api/sandbox2/policy.cc | 2 +- sandboxed_api/sandbox2/stack-trace.cc | 2 +- sandboxed_api/sandbox2/unwind/unwind.cc | 2 +- 9 files changed, 17 insertions(+), 50 deletions(-) delete mode 100644 cmake/FindLibunwind.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 019d16b..9e80079 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,12 +69,12 @@ find_package(ZLIB REQUIRED) # Make Bazel-like includes work configure_file(cmake/libcap_capability.h.in - external/org_kernel_libcap/libcap/include/sys/capability.h + libcap/include/sys/capability.h @ONLY) set(libunwind_INCLUDE_DIR ${PROJECT_BINARY_DIR}/Dependencies/Source/libunwind/include) configure_file(cmake/libunwind_ptrace.h.in - external/org_gnu_libunwind/include/libunwind-ptrace.h + libunwind-ptrace.h @ONLY) # Library with basic project settings. The empty file is there to be able to diff --git a/cmake/FindLibunwind.cmake b/cmake/FindLibunwind.cmake deleted file mode 100644 index 069740c..0000000 --- a/cmake/FindLibunwind.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2019 Google LLC. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# On Debian, install libunwind-dev to use this module. - -find_path(libunwind_INCLUDE_DIR sys/capability.h) -# Look for static library only. -find_library(libunwind_LIBRARY libcap.a) -mark_as_advanced(libunwind_INCLUDE_DIR libcap_LIBRARY) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(libunwind - REQUIRED_VARS libunwind_LIBRARY libcap_INCLUDE_DIR -) - -if(libunwind_FOUND AND NOT TARGET libcap::libcap) - add_library(libunwind::libcap UNKNOWN IMPORTED) - set_target_properties(libunwind::libcap PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - IMPORTED_LOCATION "${libunwind_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${libunwind_INCLUDE_DIR}" - ) -endif() diff --git a/sandboxed_api/bazel/external/libunwind.BUILD b/sandboxed_api/bazel/external/libunwind.BUILD index 47f2ee8..bf07e8e 100644 --- a/sandboxed_api/bazel/external/libunwind.BUILD +++ b/sandboxed_api/bazel/external/libunwind.BUILD @@ -131,6 +131,7 @@ filegroup( hdrs = [ "include/config.h", "include/libunwind.h", + "include/libunwind-ptrace.h", ], copts = LIBUNWIND_COPTS + [ # Assume our inferior doesn't have frame pointers, regardless of diff --git a/sandboxed_api/bazel/sapi.bzl b/sandboxed_api/bazel/sapi.bzl index c4d225c..b74f201 100644 --- a/sandboxed_api/bazel/sapi.bzl +++ b/sandboxed_api/bazel/sapi.bzl @@ -72,7 +72,7 @@ def sapi_interface_impl(ctx): # Append system headers as dependencies input_files += cc_ctx.headers.to_list() - append_all(extra_flags, "-D", cc_ctx.defines) + append_all(extra_flags, "-D", cc_ctx.defines.to_list()) append_all(extra_flags, "-isystem", cc_ctx.system_includes.to_list()) append_all(extra_flags, "-iquote", cc_ctx.quote_includes.to_list()) @@ -133,7 +133,7 @@ sapi_interface = rule( executable = True, cfg = "host", allow_files = True, - default = Label("//sandboxed_api/" + + default = Label("@com_google_sandboxed_api//sandboxed_api/" + "tools/generator2:sapi_generator"), ), }, @@ -180,7 +180,7 @@ def sapi_library( else: lib_hdrs += [generated_header] - default_deps = ["//sandboxed_api/sandbox2"] + default_deps = ["@com_google_sandboxed_api//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 +191,8 @@ def sapi_library( data = [":" + name + ".bin"], deps = sort_deps( [ - "//sandboxed_api:sapi", - "//sandboxed_api:vars", + "@com_google_sandboxed_api//sandboxed_api:sapi", + "@com_google_sandboxed_api//sandboxed_api:vars", ] + deps + ([":" + name + "_embed"] if embed else []) + (default_deps if add_default_deps else []), @@ -208,7 +208,7 @@ def sapi_library( ] + exported_funcs, # must be both referenced, and exported deps = [ ":" + name + ".lib", - "//sandboxed_api:client", + "@com_google_sandboxed_api//sandboxed_api:client", ], **common ) diff --git a/sandboxed_api/bazel/sapi_deps.bzl b/sandboxed_api/bazel/sapi_deps.bzl index 60c5ad5..0e782d6 100644 --- a/sandboxed_api/bazel/sapi_deps.bzl +++ b/sandboxed_api/bazel/sapi_deps.bzl @@ -49,7 +49,7 @@ def sapi_deps(): if "six_archive" not in native.existing_rules(): http_archive( name = "six_archive", - build_file = "//sandboxed_api:bazel/external/six.BUILD", + build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/six.BUILD", sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a", strip_prefix = "six-1.10.0", urls = [ @@ -88,7 +88,7 @@ def sapi_deps(): # libcap http_archive( name = "org_kernel_libcap", - build_file = "//sandboxed_api:bazel/external/libcap.BUILD", + build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libcap.BUILD", sha256 = "ef83108f77314e50bae926ae473f9b130b15240d17cbae05089e19c36a8676d6", strip_prefix = "libcap-2.13", urls = ["https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.13.tar.gz"], @@ -97,7 +97,7 @@ def sapi_deps(): # libffi autotools_repository( name = "org_sourceware_libffi", - build_file = "//sandboxed_api:bazel/external/libffi.BUILD", + build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libffi.BUILD", sha256 = "403d67aabf1c05157855ea2b1d9950263fb6316536c8c333f5b9ab1eb2f20ecf", strip_prefix = "libffi-3.3-rc0", urls = ["https://github.com/libffi/libffi/releases/download/v3.3-rc0/libffi-3.3-rc0.tar.gz"], @@ -106,7 +106,7 @@ def sapi_deps(): # libunwind autotools_repository( name = "org_gnu_libunwind", - build_file = "//sandboxed_api:bazel/external/libunwind.BUILD", + build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libunwind.BUILD", configure_args = [ "--disable-documentation", "--disable-minidebuginfo", diff --git a/sandboxed_api/sandbox2/executor.cc b/sandboxed_api/sandbox2/executor.cc index d4c8873..6e19a19 100644 --- a/sandboxed_api/sandbox2/executor.cc +++ b/sandboxed_api/sandbox2/executor.cc @@ -26,7 +26,7 @@ #include "absl/memory/memory.h" #include "absl/strings/str_cat.h" -#include "external/org_kernel_libcap/libcap/include/sys/capability.h" +#include "libcap/include/sys/capability.h" #include "sandboxed_api/sandbox2/forkserver.h" #include "sandboxed_api/sandbox2/forkserver.pb.h" #include "sandboxed_api/sandbox2/global_forkclient.h" diff --git a/sandboxed_api/sandbox2/policy.cc b/sandboxed_api/sandbox2/policy.cc index d1394e9..21f83d2 100644 --- a/sandboxed_api/sandbox2/policy.cc +++ b/sandboxed_api/sandbox2/policy.cc @@ -28,7 +28,7 @@ #include #include "sandboxed_api/util/flag.h" -#include "external/org_kernel_libcap/libcap/include/sys/capability.h" +#include "libcap/include/sys/capability.h" #include "sandboxed_api/sandbox2/bpfdisassembler.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/regs.h" diff --git a/sandboxed_api/sandbox2/stack-trace.cc b/sandboxed_api/sandbox2/stack-trace.cc index 5a795b1..20605e2 100644 --- a/sandboxed_api/sandbox2/stack-trace.cc +++ b/sandboxed_api/sandbox2/stack-trace.cc @@ -29,7 +29,7 @@ #include "absl/strings/numbers.h" #include "absl/strings/str_cat.h" #include "absl/strings/strip.h" -#include "external/org_kernel_libcap/libcap/include/sys/capability.h" +#include "libcap/include/sys/capability.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/executor.h" #include "sandboxed_api/sandbox2/ipc.h" diff --git a/sandboxed_api/sandbox2/unwind/unwind.cc b/sandboxed_api/sandbox2/unwind/unwind.cc index 0913d44..7852d5f 100644 --- a/sandboxed_api/sandbox2/unwind/unwind.cc +++ b/sandboxed_api/sandbox2/unwind/unwind.cc @@ -25,7 +25,7 @@ #include #include "absl/strings/str_cat.h" -#include "external/org_gnu_libunwind/include/libunwind-ptrace.h" +#include "libunwind-ptrace.h" #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/unwind/unwind.pb.h" #include "sandboxed_api/sandbox2/util/maps_parser.h"