glog.BUILD 4.8 KB

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