bazel: use expand_template instead of genrules
This lets us drop the dependency on the preprocessed headers in src/windows/glog/. For some reason, this lets Bazel realize we've failed to declare a dependency on dirent.h, so I added that too.
This commit is contained in:
parent
d66e593188
commit
30bb9086d2
137
bazel/glog.bzl
137
bazel/glog.bzl
@ -9,6 +9,28 @@
|
|||||||
#
|
#
|
||||||
# Known issue: the namespace parameter is not supported on Win32.
|
# Known issue: the namespace parameter is not supported on Win32.
|
||||||
|
|
||||||
|
def expand_template_impl(ctx):
|
||||||
|
ctx.actions.expand_template(
|
||||||
|
template = ctx.file.template,
|
||||||
|
output = ctx.outputs.out,
|
||||||
|
substitutions = ctx.attr.substitutions,
|
||||||
|
)
|
||||||
|
|
||||||
|
expand_template = rule(
|
||||||
|
implementation = expand_template_impl,
|
||||||
|
attrs = {
|
||||||
|
"template": attr.label(mandatory = True, allow_single_file = True),
|
||||||
|
"substitutions": attr.string_dict(mandatory = True),
|
||||||
|
"out": attr.output(mandatory = True),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def dict_union(x, y):
|
||||||
|
z = {}
|
||||||
|
z.update(x)
|
||||||
|
z.update(y)
|
||||||
|
return z
|
||||||
|
|
||||||
def glog_library(namespace = "google", with_gflags = 1, **kwargs):
|
def glog_library(namespace = "google", with_gflags = 1, **kwargs):
|
||||||
if native.repository_name() != "@":
|
if native.repository_name() != "@":
|
||||||
repo_name = native.repository_name().lstrip("@")
|
repo_name = native.repository_name().lstrip("@")
|
||||||
@ -78,6 +100,7 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
|
|||||||
windows_only_srcs = [
|
windows_only_srcs = [
|
||||||
"src/glog/log_severity.h",
|
"src/glog/log_severity.h",
|
||||||
"src/windows/config.h",
|
"src/windows/config.h",
|
||||||
|
"src/windows/dirent.h",
|
||||||
"src/windows/port.cc",
|
"src/windows/port.cc",
|
||||||
"src/windows/port.h",
|
"src/windows/port.h",
|
||||||
]
|
]
|
||||||
@ -112,29 +135,17 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
|
|||||||
"@bazel_tools//src/conditions:windows": windows_only_srcs,
|
"@bazel_tools//src/conditions:windows": windows_only_srcs,
|
||||||
"//conditions:default": [":config_h"],
|
"//conditions:default": [":config_h"],
|
||||||
}),
|
}),
|
||||||
hdrs = select({
|
hdrs = [
|
||||||
"@bazel_tools//src/conditions:windows": [
|
|
||||||
"src/windows/glog/logging.h",
|
|
||||||
"src/windows/glog/log_severity.h",
|
|
||||||
"src/windows/glog/raw_logging.h",
|
|
||||||
"src/windows/glog/stl_logging.h",
|
|
||||||
"src/windows/glog/vlog_is_on.h",
|
|
||||||
],
|
|
||||||
"//conditions:default": [
|
|
||||||
"src/glog/log_severity.h",
|
"src/glog/log_severity.h",
|
||||||
":logging_h",
|
":logging_h",
|
||||||
":raw_logging_h",
|
":raw_logging_h",
|
||||||
":stl_logging_h",
|
":stl_logging_h",
|
||||||
":vlog_is_on_h",
|
":vlog_is_on_h",
|
||||||
],
|
],
|
||||||
}),
|
strip_include_prefix = "src",
|
||||||
strip_include_prefix = select({
|
|
||||||
"@bazel_tools//src/conditions:windows": "/src/windows",
|
|
||||||
"//conditions:default": "src",
|
|
||||||
}),
|
|
||||||
defines = select({
|
defines = select({
|
||||||
# We need to override the default GOOGLE_GLOG_DLL_DECL from
|
# We need to override the default GOOGLE_GLOG_DLL_DECL from
|
||||||
# src/windows/glog/*.h to match src/windows/config.h.
|
# src/glog/*.h to match src/windows/config.h.
|
||||||
"@bazel_tools//src/conditions:windows": ["GOOGLE_GLOG_DLL_DECL=__declspec(dllexport)"],
|
"@bazel_tools//src/conditions:windows": ["GOOGLE_GLOG_DLL_DECL=__declspec(dllexport)"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
@ -157,57 +168,67 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
|
|||||||
# the dependencies without strip_include_prefix.
|
# the dependencies without strip_include_prefix.
|
||||||
native.cc_library(
|
native.cc_library(
|
||||||
name = "strip_include_prefix_hack",
|
name = "strip_include_prefix_hack",
|
||||||
hdrs = native.glob(["src/windows/*.h"]),
|
hdrs = [
|
||||||
|
"src/glog/log_severity.h",
|
||||||
|
":logging_h",
|
||||||
|
":raw_logging_h",
|
||||||
|
":stl_logging_h",
|
||||||
|
":vlog_is_on_h",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
native.genrule(
|
expand_template(
|
||||||
name = "config_h",
|
name = "config_h",
|
||||||
srcs = [
|
template = "src/config.h.cmake.in",
|
||||||
"src/config.h.cmake.in",
|
out = "glog_internal/config.h",
|
||||||
],
|
substitutions = {"#cmakedefine": "//cmakedefine"},
|
||||||
outs = [
|
|
||||||
"glog_internal/config.h",
|
|
||||||
],
|
|
||||||
cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $< > $@",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
native.genrule(
|
common_config = {
|
||||||
name = "gen_sh",
|
"@ac_cv_cxx_using_operator@": "1",
|
||||||
outs = [
|
"@ac_cv_have_inttypes_h@": "0",
|
||||||
"gen.sh",
|
"@ac_cv_have_u_int16_t@": "0",
|
||||||
],
|
"@ac_cv_have_glog_export@": "0",
|
||||||
cmd = r'''\
|
"@ac_google_start_namespace@": "namespace google {",
|
||||||
#!/bin/sh
|
"@ac_google_end_namespace@": "}",
|
||||||
cat > $@ <<"EOF"
|
"@ac_google_namespace@": "google",
|
||||||
sed -e 's/@ac_cv_cxx_using_operator@/1/g' \
|
}
|
||||||
-e 's/@ac_cv_have_unistd_h@/1/g' \
|
|
||||||
-e 's/@ac_cv_have_stdint_h@/1/g' \
|
posix_config = dict_union(common_config, {
|
||||||
-e 's/@ac_cv_have_systypes_h@/1/g' \
|
"@ac_cv_have_unistd_h@": "1",
|
||||||
-e 's/@ac_cv_have_libgflags@/{}/g' \
|
"@ac_cv_have_stdint_h@": "1",
|
||||||
-e 's/@ac_cv_have_uint16_t@/1/g' \
|
"@ac_cv_have_systypes_h@": "1",
|
||||||
-e 's/@ac_cv_have___builtin_expect@/1/g' \
|
"@ac_cv_have_uint16_t@": "1",
|
||||||
-e 's/@ac_cv_have_.*@/0/g' \
|
"@ac_cv_have___uint16@": "0",
|
||||||
-e 's/@ac_google_start_namespace@/namespace google {{/g' \
|
"@ac_cv_have___builtin_expect@": "1",
|
||||||
-e 's/@ac_google_end_namespace@/}}/g' \
|
"@ac_cv_have_libgflags@": "1" if with_gflags else "0",
|
||||||
-e 's/@ac_google_namespace@/google/g' \
|
"@ac_cv___attribute___noinline@": "__attribute__((noinline))",
|
||||||
-e 's/@ac_cv___attribute___noinline@/__attribute__((noinline))/g' \
|
"@ac_cv___attribute___noreturn@": "__attribute__((noreturn))",
|
||||||
-e 's/@ac_cv___attribute___noreturn@/__attribute__((noreturn))/g' \
|
"@ac_cv___attribute___printf_4_5@": "__attribute__((__format__(__printf__, 4, 5)))",
|
||||||
-e 's/@ac_cv___attribute___printf_4_5@/__attribute__((__format__(__printf__, 4, 5)))/g'
|
})
|
||||||
EOF
|
|
||||||
'''.format(int(with_gflags)),
|
windows_config = dict_union(common_config, {
|
||||||
)
|
"@ac_cv_have_unistd_h@": "0",
|
||||||
|
"@ac_cv_have_stdint_h@": "0",
|
||||||
|
"@ac_cv_have_systypes_h@": "0",
|
||||||
|
"@ac_cv_have_uint16_t@": "0",
|
||||||
|
"@ac_cv_have___uint16@": "1",
|
||||||
|
"@ac_cv_have___builtin_expect@": "0",
|
||||||
|
"@ac_cv_have_libgflags@": "0",
|
||||||
|
"@ac_cv___attribute___noinline@": "",
|
||||||
|
"@ac_cv___attribute___noreturn@": "__declspec(noreturn)",
|
||||||
|
"@ac_cv___attribute___printf_4_5@": "",
|
||||||
|
})
|
||||||
|
|
||||||
[
|
[
|
||||||
native.genrule(
|
expand_template(
|
||||||
name = "%s_h" % f,
|
name = "%s_h" % f,
|
||||||
srcs = [
|
template = "src/glog/%s.h.in" % f,
|
||||||
"src/glog/%s.h.in" % f,
|
out = "src/glog/%s.h" % f,
|
||||||
],
|
substitutions = select({
|
||||||
outs = [
|
"@bazel_tools//src/conditions:windows": windows_config,
|
||||||
"src/glog/%s.h" % f,
|
"//conditions:default": posix_config,
|
||||||
],
|
}),
|
||||||
cmd = "$(location :gen_sh) < $< > $@",
|
|
||||||
tools = [":gen_sh"],
|
|
||||||
)
|
)
|
||||||
for f in [
|
for f in [
|
||||||
"vlog_is_on",
|
"vlog_is_on",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user