diff --git a/sandboxed_api/bazel/sapi.bzl b/sandboxed_api/bazel/sapi.bzl index c6e2703..94c28b0 100644 --- a/sandboxed_api/bazel/sapi.bzl +++ b/sandboxed_api/bazel/sapi.bzl @@ -70,6 +70,34 @@ def sort_deps(deps): other_deps = [x for x in deps if not x.startswith(":")] return sorted(colon_deps) + sorted(other_deps) +def cc_library_virtual_includes(target): + """Checks a target for virtual includes. + + Those can be created by the deprecated `cc_inc_library` rule, or by using + a combination of `cc_library()`s `includes`, `include_prefix` and + `strip_include_prefix` attributes. + + Args: + target: The Target to analyze + Returns: + A depset with include paths generated by cc_inc_library targets. + """ + cc_ctx = target[CcInfo].compilation_context + + includes = [] + for f in cc_ctx.headers.to_list(): + p = f.path + if not p.startswith("blaze-out") and not p.startswith("bazel-out"): + continue + for path_marker in ["/_virtual_includes/", "/_/"]: + i = p.find(path_marker) + if i == -1: + continue + includes.append(p[:i] + path_marker + + p[i + len(path_marker):].split("/", 1)[0]) + + return depset(includes) + def _sapi_interface_impl(ctx): cpp_toolchain = find_cpp_toolchain(ctx) generator = select_generator(ctx) @@ -106,7 +134,9 @@ def _sapi_interface_impl(ctx): # Append all headers as dependencies input_files += cc_ctx.headers.to_list() - quote_includes = cc_ctx.quote_includes.to_list() + # Gather direct include paths as well as virtual ones + quote_includes = (cc_ctx.quote_includes.to_list() + + cc_library_virtual_includes(ctx.attr.lib).to_list()) if use_clang_generator: input_files += cpp_toolchain.all_files.to_list()