glog.BUILD 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # Licensed to the Apache Software Foundation (ASF) under one or more
  2. # contributor license agreements. See the NOTICE file distributed with
  3. # this work for additional information regarding copyright ownership.
  4. # The ASF licenses this file to You under the Apache License, Version 2.0
  5. # (the "License"); you may not use this file except in compliance with
  6. # the License. You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. licenses(["notice"])
  16. cc_library(
  17. name = "glog",
  18. srcs = [
  19. "src/base/commandlineflags.h",
  20. "src/base/googleinit.h",
  21. "src/demangle.cc",
  22. "src/logging.cc",
  23. "src/raw_logging.cc",
  24. "src/symbolize.cc",
  25. "src/utilities.cc",
  26. "src/vlog_is_on.cc",
  27. ],
  28. hdrs = [
  29. "raw_logging_h",
  30. "src/base/mutex.h",
  31. "src/demangle.h",
  32. "src/symbolize.h",
  33. "src/utilities.h",
  34. "src/glog/log_severity.h",
  35. ":config_h",
  36. ":logging_h",
  37. ":stl_logging_h",
  38. ":vlog_is_on_h",
  39. ],
  40. copts = [
  41. # Disable warnings that exists in glog
  42. "-Wno-sign-compare",
  43. "-Wno-unused-local-typedefs",
  44. # Inject google namespace as "google"
  45. "-D_START_GOOGLE_NAMESPACE_='namespace google {'",
  46. "-D_END_GOOGLE_NAMESPACE_='}'",
  47. "-DGOOGLE_NAMESPACE='google'",
  48. # Allows src/base/mutex.h to include pthread.h.
  49. "-DHAVE_PTHREAD",
  50. # Allows src/logging.cc to determine the host name.
  51. "-DHAVE_SYS_UTSNAME_H",
  52. # System header files enabler for src/utilities.cc
  53. # Enable system calls from syscall.h
  54. "-DHAVE_SYS_SYSCALL_H",
  55. # Enable system calls from sys/time.h
  56. "-DHAVE_SYS_TIME_H",
  57. "-DHAVE_STDINT_H",
  58. "-DHAVE_STRING_H",
  59. # For logging.cc
  60. "-DHAVE_PREAD",
  61. "-DHAVE_FCNTL",
  62. "-DHAVE_SYS_TYPES_H",
  63. # Allows syslog support
  64. "-DHAVE_SYSLOG_H",
  65. # GFlags
  66. "-isystem $(GENDIR)/external/com_github_gflags_gflags/",
  67. "-DHAVE_LIB_GFLAGS",
  68. # Necessary for creating soft links of log files
  69. "-DHAVE_UNISTD_H",
  70. ],
  71. includes = [
  72. ".",
  73. "src",
  74. ],
  75. visibility = ["//visibility:public"],
  76. deps = [
  77. "//external:gflags",
  78. ],
  79. )
  80. # Below are the generation rules that generates the necessary header
  81. # files for glog. Originally they are generated by CMAKE
  82. # configure_file() command, which replaces certain template
  83. # placeholders in the .in files with provided values.
  84. # gen_sh is a bash script that provides the values for generated
  85. # header files. Under the hood it is just a wrapper over sed.
  86. genrule(
  87. name = "gen_sh",
  88. outs = [
  89. "gen.sh",
  90. ],
  91. cmd = """
  92. cat > $@ <<"EOF"
  93. #! /bin/sh
  94. sed -e 's/@ac_cv_have_unistd_h@/1/g' \
  95. -e 's/@ac_cv_have_stdint_h@/1/g' \
  96. -e 's/@ac_cv_have_systypes_h@/1/g' \
  97. -e 's/@ac_cv_have_libgflags_h@/1/g' \
  98. -e 's/@ac_cv_have_uint16_t@/1/g' \
  99. -e 's/@ac_cv_have___builtin_expect@/1/g' \
  100. -e 's/@ac_cv_have_.*@/0/g' \
  101. -e 's/@ac_google_start_namespace@/namespace google {/g' \
  102. -e 's/@ac_google_end_namespace@/}/g' \
  103. -e 's/@ac_google_namespace@/google/g' \
  104. -e 's/@ac_cv___attribute___noinline@/__attribute__((noinline))/g' \
  105. -e 's/@ac_cv___attribute___noreturn@/__attribute__((noreturn))/g' \
  106. -e 's/@ac_cv___attribute___printf_4_5@/__attribute__((__format__ (__printf__, 4, 5)))/g'
  107. EOF""",
  108. )
  109. genrule(
  110. name = "config_h",
  111. srcs = [
  112. "src/config.h.cmake.in",
  113. ],
  114. outs = [
  115. "config.h",
  116. ],
  117. cmd = "awk '{ gsub(/^#cmakedefine/, \"//cmakedefine\"); print; }' $(<) > $(@)",
  118. )
  119. genrule(
  120. name = "logging_h",
  121. srcs = [
  122. "src/glog/logging.h.in",
  123. ],
  124. outs = [
  125. "glog/logging.h",
  126. ],
  127. cmd = "$(location :gen_sh) < $(<) > $(@)",
  128. tools = [":gen_sh"],
  129. )
  130. genrule(
  131. name = "raw_logging_h",
  132. srcs = [
  133. "src/glog/raw_logging.h.in",
  134. ],
  135. outs = [
  136. "glog/raw_logging.h",
  137. ],
  138. cmd = "$(location :gen_sh) < $(<) > $(@)",
  139. tools = [":gen_sh"],
  140. )
  141. genrule(
  142. name = "stl_logging_h",
  143. srcs = [
  144. "src/glog/stl_logging.h.in",
  145. ],
  146. outs = [
  147. "glog/stl_logging.h",
  148. ],
  149. cmd = "$(location :gen_sh) < $(<) > $(@)",
  150. tools = [":gen_sh"],
  151. )
  152. genrule(
  153. name = "vlog_is_on_h",
  154. srcs = [
  155. "src/glog/vlog_is_on.h.in",
  156. ],
  157. outs = [
  158. "glog/vlog_is_on.h",
  159. ],
  160. cmd = "$(location :gen_sh) < $(<) > $(@)",
  161. tools = [":gen_sh"],
  162. )