diff options
author | Marco Poletti <poletti.marco@gmail.com> | 2020-08-09 21:10:16 -0700 |
---|---|---|
committer | Marco Poletti <poletti.marco@gmail.com> | 2020-08-09 21:10:16 -0700 |
commit | c6d389dab4bcdb61ed1a3d9d0500f8d6feca1ecf (patch) | |
tree | 2f65fc3e2f83d33cc18f6fe5cb960dcd46680be3 | |
parent | 6f3760672a0d2c772306e737d894a2ae2d8c5f58 (diff) | |
download | google-fruit-c6d389dab4bcdb61ed1a3d9d0500f8d6feca1ecf.tar.gz |
Fix bazel build errors introduced by 94cefefb42f3685c1d64664e6aa9cbaf834b25ee when the Fruit headers are not also installed on the system where bazel runs.
-rw-r--r-- | BUILD | 5 | ||||
-rw-r--r-- | configuration/bazel/BUILD | 2 | ||||
-rw-r--r-- | configuration/bazel/build_defs.bzl | 28 | ||||
-rw-r--r-- | tests/BUILD | 5 |
4 files changed, 29 insertions, 11 deletions
@@ -7,7 +7,7 @@ filegroup( srcs = glob([ "include/**/*.h", ]) + [ - "//third_party/fruit/configuration/bazel:fruit_config", + "//third_party/fruit/configuration/bazel:fruit-config-base", ], ) @@ -16,11 +16,12 @@ cc_library( srcs = glob([ "src/*.cpp", "include/fruit/impl/**/*.h", - ]) + ["//third_party/fruit/configuration/bazel:fruit_config"], + ]), hdrs = glob(["include/fruit/*.h"]), includes = ["include", "configuration/bazel"], deps = [ "@boost//:unordered", + "//third_party/fruit/configuration/bazel:fruit-config-base", ], linkopts = ["-lm"], ) diff --git a/configuration/bazel/BUILD b/configuration/bazel/BUILD index 112b732..a207462 100644 --- a/configuration/bazel/BUILD +++ b/configuration/bazel/BUILD @@ -3,6 +3,6 @@ load("//third_party/fruit/configuration/bazel:build_defs.bzl", "generate_fruit_c package(default_visibility = ["//third_party/fruit:__subpackages__"]) generate_fruit_config( - name = "fruit_config", + name = "fruit-config-base", check_sources = glob(["*.cpp"]) ) diff --git a/configuration/bazel/build_defs.bzl b/configuration/bazel/build_defs.bzl index 8d683c4..28c3b17 100644 --- a/configuration/bazel/build_defs.bzl +++ b/configuration/bazel/build_defs.bzl @@ -17,7 +17,9 @@ def _generate_fruit_config_impl(ctx): check_output_files = [] for check_source in ctx.files.check_sources: - output_file = ctx.actions.declare_file(check_source.path + ".o") + check_name = check_source.path[:-len(".cpp")].split('/')[-1].split('\\')[-1] + + output_file = ctx.actions.declare_file(check_name + ".o") c_compile_variables = cc_common.create_compile_variables( feature_configuration = feature_configuration, @@ -37,9 +39,8 @@ def _generate_fruit_config_impl(ctx): variables = c_compile_variables, ) - check_name = check_source.path.split('/')[-1].split('\\')[-1] check_define = 'FRUIT_HAS_%s' % check_name.upper() - check_output_file = ctx.actions.declare_file(check_source.path + ".h") + check_output_file = ctx.actions.declare_file(check_name + ".h") ctx.actions.run_shell( command = '"$@" &>/dev/null && echo "#define %s 1" >"%s" || echo "#define %s 0" >"%s"; touch "%s"' % ( @@ -55,7 +56,7 @@ def _generate_fruit_config_impl(ctx): ) check_output_files.append(check_output_file) - merged_output_file = ctx.actions.declare_file(ctx.label.name + ".h") + merged_output_file = ctx.actions.declare_file("fruit/impl/fruit-config-base.h") ctx.actions.run_shell( command = '\n'.join([ '(', @@ -70,8 +71,25 @@ def _generate_fruit_config_impl(ctx): outputs = [merged_output_file], ) + compilation_context, compilation_outputs = cc_common.compile( + actions = ctx.actions, + feature_configuration = feature_configuration, + cc_toolchain = cc_toolchain, + public_hdrs = [merged_output_file], + name = "%s_link" % ctx.label.name, + ) + + linking_context, linking_outputs = cc_common.create_linking_context_from_compilation_outputs( + actions = ctx.actions, + feature_configuration = feature_configuration, + compilation_outputs = compilation_outputs, + cc_toolchain = cc_toolchain, + name = "%s_link" % ctx.label.name, + ) + return [ - DefaultInfo(files = depset([merged_output_file])), + DefaultInfo(files = depset([merged_output_file]), runfiles = ctx.runfiles(files = [merged_output_file])), + CcInfo(compilation_context=compilation_context, linking_context=linking_context), ] generate_fruit_config = rule( diff --git a/tests/BUILD b/tests/BUILD index b7ff089..e89f144 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -69,7 +69,6 @@ genrule( ], visibility = ["//third_party/fruit/tests:__subpackages__"], cmd = "" - + "FRUIT_HEADERS_LOCATION=`for f in $(locations //third_party/fruit:fruit_headers); do echo \"$$f\"; done | fgrep configuration/bazel/ | head -n 1 | sed 's|configuration/bazel/.*|./|'`;" + "TEST_HEADERS_LOCATION=`for f in $(locations :test_headers_filegroup); do echo \"$$f\"; done | fgrep test_macros.h | sed 's|test_macros.h|./|'`;" + "LIBFRUIT_LOCATION=`for f in $(locations //third_party/fruit); do echo \"$$f\"; done | fgrep libfruit.so | head -n 1 | sed 's|libfruit.so|./|'`;" + "LIBTEST_HEADERS_LOCATION=`for f in $(locations //third_party/fruit/tests:test_headers); do echo \"$$f\"; done | fgrep libtest_headers.so | head -n 1 | sed 's|libtest_headers.so|./|'`;" @@ -86,8 +85,8 @@ genrule( + "PATH_TO_COMPILED_FRUIT_LIB='third_party/fruit/tests'\n" + "PATH_TO_COMPILED_TEST_HEADERS='third_party/fruit/tests/test_headers'\n" + "PATH_TO_COMPILED_TEST_HEADERS_LIB='third_party/fruit/tests/test_headers'\n" - + "PATH_TO_FRUIT_STATIC_HEADERS='$${FRUIT_HEADERS_LOCATION}/include'\n" - + "PATH_TO_FRUIT_GENERATED_HEADERS='$${FRUIT_HEADERS_LOCATION}/configuration/bazel'\n" + + "PATH_TO_FRUIT_STATIC_HEADERS='third_party/fruit/include'\n" + + "PATH_TO_FRUIT_GENERATED_HEADERS='third_party/fruit/configuration/bazel'\n" + "PATH_TO_FRUIT_TEST_HEADERS='$${TEST_HEADERS_LOCATION}'\n" + "ADDITIONAL_LINKER_FLAGS='-lstdc++ -lm'\n" + "RUN_TESTS_UNDER_VALGRIND='0'\n" |