Skip to content

Commit

Permalink
Avoid leaking config.h
Browse files Browse the repository at this point in the history
This uses strip_include_prefix to avoid leaking private headers
(config.h, port.h). This needs a workaround to prevent a "missing
dependency declarations" error.
  • Loading branch information
drigz committed Nov 20, 2019
1 parent 925858d commit 1bb0133
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions bazel/glog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

def glog_library(namespace = "google", with_gflags = 1, **kwargs):
if native.repository_name() != "@":
gendir = "$(GENDIR)/external/" + native.repository_name().lstrip("@")
repo_name = native.repository_name().lstrip("@")
gendir = "$(GENDIR)/external/" + repo_name
src_windows = "external/%s/src/windows" % repo_name
else:
gendir = "$(GENDIR)"
src_windows = "src/windows"

common_copts = [
"-DGLOG_BAZEL_BUILD",
Expand Down Expand Up @@ -50,6 +53,14 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):

windows_only_copts = [
"-DHAVE_SNPRINTF",
"-I" + src_windows,
]

windows_only_srcs = [
"src/glog/log_severity.h",
"src/windows/config.h",
"src/windows/port.cc",
"src/windows/port.h",
]

gflags_deps = ["@com_github_gflags_gflags//:gflags"] if with_gflags else []
Expand Down Expand Up @@ -79,7 +90,7 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
"src/utilities.h",
"src/vlog_is_on.cc",
] + select({
"@bazel_tools//src/conditions:windows": ["src/windows/port.cc", "src/windows/port.h"],
"@bazel_tools//src/conditions:windows": windows_only_srcs,
"//conditions:default": [":config_h"],
}),
copts =
Expand All @@ -105,8 +116,9 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):

native.cc_library(
name = "windows_glog_headers",
hdrs = ["src/glog/log_severity.h", "src/windows/config.h",] + native.glob(["src/windows/glog/*.h"]),
includes = ["src/windows"],
hdrs = native.glob(["src/windows/glog/*.h"]),
strip_include_prefix = "src/windows",
# TODO(rodrigoq): are these necessary?
# config.h for windows seem hardcoded that way,
# and we need to propagate those defines to binaries/libraries linking
# against glog.
Expand All @@ -115,6 +127,14 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
"GOOGLE_GLOG_DLL_DECL=__declspec(dllexport)",
"GOOGLE_GLOG_DLL_DECL_FOR_UNITTEST=__declspec(dllimport)",
],
deps = [":strip_include_prefix_hack"],
)

# Workaround https://github.com/bazelbuild/bazel/issues/6337 by declaring
# the dependencies without strip_include_prefix.
native.cc_library(
name = "strip_include_prefix_hack",
hdrs = native.glob(["src/windows/*.h"]),
)

native.cc_library(
Expand Down

0 comments on commit 1bb0133

Please sign in to comment.