From f9276e2442907c7a3d5a1eed64f4a8acc704f560 Mon Sep 17 00:00:00 2001 From: Alpha Lam Date: Fri, 1 Apr 2016 09:38:55 +0000 Subject: Fix issues with cc_configure Fixing a few issues with cc_configure that I encountered. * The argument for rpath should be -Wl,-rpath. * cc_configure should consider CPLUS_INCLUDE_PATH. I ran into this problem when using a crosstool gcc which needs -I/usr/include. * Check if -Wunused-but-set-parameter is available. -- Change-Id: I73198b5b17674ecbf1b511e23fcc9331ca96c8e0 Reviewed-on: https://bazel-review.googlesource.com/#/c/3210/ MOS_MIGRATED_REVID=118763218 --- tools/cpp/cc_configure.bzl | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl index d73a388b06..fc8a5d713f 100644 --- a/tools/cpp/cc_configure.bzl +++ b/tools/cpp/cc_configure.bzl @@ -75,13 +75,25 @@ def _ld_library_paths(repository_ctx): result = [] for p in repository_ctx.os.environ["LD_LIBRARY_PATH"].split(":"): p = str(repository_ctx.path(p)) # Normalize the path - result.append("-Wl,rpath," + p) + result.append("-Wl,-rpath," + p) result.append("-L" + p) return result else: return [] +def _cplus_include_paths(repository_ctx): + """Use ${CPLUS_INCLUDE_PATH} to compute the list of flags for cxxflag.""" + if "CPLUS_INCLUDE_PATH" in repository_ctx.os.environ: + result = [] + for p in repository_ctx.os.environ["CPLUS_INCLUDE_PATH"].split(":"): + p = str(repository_ctx.path(p)) # Normalize the path + result.append("-I" + p) + return result + else: + return [] + + def _get_cpu_value(repository_ctx): """Compute the cpu_value based on the OS name.""" os_name = repository_ctx.os.name.lower() @@ -143,7 +155,9 @@ def _crosstool_content(repository_ctx, cc, cpu_value, darwin): "target_libc": "macosx" if darwin else "local", "target_cpu": cpu_value, "target_system_name": "local", - "cxx_flag": "-std=c++0x", + "cxx_flag": [ + "-std=c++0x", + ] + _cplus_include_paths(repository_ctx), "linker_flag": [ "-lstdc++", # Anticipated future default. @@ -185,10 +199,10 @@ def _crosstool_content(repository_ctx, cc, cpu_value, darwin): "-Wall", # Enable a few more warnings that aren't part of -Wall. ] + (["-Wthread-safety", "-Wself-assign"] if darwin else [ - "-Wunused-but-set-parameter", # Disable some that are problematic. "-Wl,-z,-relro,-z,now" ]) + ( + _add_option_if_supported(repository_ctx, cc, "-Wunused-but-set-parameter") + # has false positives _add_option_if_supported(repository_ctx, cc, "-Wno-free-nonheap-object") + # Enable coloring even if there's no attached terminal. Bazel removes the -- cgit v1.2.3