Skip to content

Commit 1495aba

Browse files
authored
Add support for parse_headers (#524)
Fixes #522
1 parent 59d2cff commit 1495aba

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

tests/scripts/bazel.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ common_test_args=(
5050
"--keep_going"
5151
"--test_output=errors"
5252
"--features=layering_check"
53+
"--process_headers_in_dependencies"
5354
)
5455

5556
# Do not run autoconf to configure local CC toolchains.

toolchain/cc_toolchain_config.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ def cc_toolchain_config(
348348
# https://cs.opensource.google/bazel/bazel/+/master:src/main/starlark/builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl;l=75;drc=f0150efd1cca473640269caaf92b5a23c288089d
349349
# https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java;l=1257;drc=6743d76f9ecde726d592e88d8914b9db007b1c43
350350
# https://cs.opensource.google/bazel/bazel/+/refs/tags/7.0.0:tools/cpp/unix_cc_toolchain_config.bzl;l=192,201;drc=044a14cca2747aeff258fc71eaeb153c08cb34d5
351+
# https://github.com/bazelbuild/rules_cc/blob/fe41fc4ea219c9d3680ee536bba6681f3baf838e/cc/private/toolchain/unix_cc_toolchain_config.bzl#L1887
351352
# NOTE: Ensure these are listed in toolchain_tools in toolchain/internal/common.bzl.
352353
tool_paths = {
353354
"ar": tools_path_prefix + ("llvm-ar" if not use_libtool else "libtool"),
@@ -362,6 +363,7 @@ def cc_toolchain_config(
362363
"objcopy": tools_path_prefix + "llvm-objcopy",
363364
"objdump": tools_path_prefix + "llvm-objdump",
364365
"strip": tools_path_prefix + "llvm-strip",
366+
"parse_headers": wrapper_bin_prefix + "cc_wrapper.sh",
365367
}
366368

367369
# Start-end group linker support:

toolchain/cc_wrapper.sh.tpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ if [[ ! -f ${toolchain_path_prefix}bin/clang ]]; then
8282
exit 5
8383
fi
8484

85+
OUTPUT=
86+
87+
function parse_option() {
88+
local -r opt="$1"
89+
if [[ "${OUTPUT}" = "1" ]]; then
90+
OUTPUT=${opt}
91+
elif [[ "${opt}" = "-o" ]]; then
92+
# output is coming
93+
OUTPUT=1
94+
fi
95+
}
96+
8597
function sanitize_option() {
8698
local -r opt=$1
8799
if [[ ${opt} == */cc_wrapper.sh ]]; then
@@ -106,6 +118,7 @@ for ((i = 0; i <= $#; i++)); do
106118
set -e
107119
sanitize_option "${opt}"
108120
)"
121+
parse_option "${opt}"
109122
echo "${opt}" >>"${tmpfile}"
110123
done <"${!i:1}"
111124
cmd+=("@${tmpfile}")
@@ -114,9 +127,15 @@ for ((i = 0; i <= $#; i++)); do
114127
set -e
115128
sanitize_option "${!i}"
116129
)"
130+
parse_option "${opt}"
117131
cmd+=("${opt}")
118132
fi
119133
done
120134

121135
# Call the C++ compiler.
122136
"${cmd[@]}"
137+
138+
# Generate an empty file if header processing succeeded.
139+
if [[ "${OUTPUT}" == *.h.processed ]]; then
140+
echo -n >"${OUTPUT}"
141+
fi

toolchain/internal/configure.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ cc_toolchain(
531531
strip_files = "strip-files-{suffix}",
532532
toolchain_config = "local-{suffix}",
533533
module_map = "module-{suffix}",
534+
supports_header_parsing = True,
534535
)
535536
"""
536537

toolchain/osx_cc_wrapper.sh.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ fi
183183
# Call the C++ compiler.
184184
"${cmd[@]}"
185185

186+
# Generate an empty file if header processing succeeded.
187+
if [[ "${OUTPUT}" == *.h.processed ]]; then
188+
echo -n >"${OUTPUT}"
189+
fi
190+
186191
function get_library_path() {
187192
for libdir in ${LIB_DIRS}; do
188193
if [[ -f "${libdir}/lib$1".so ]]; then

0 commit comments

Comments
 (0)