__init__.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import os.path
  2. import os.path as P
  3. import shutil
  4. from devtools.yamaker.arcpath import ArcPath
  5. from devtools.yamaker.fileutil import re_sub_dir
  6. from devtools.yamaker.modules import GLOBAL, Linkable, Switch
  7. from devtools.yamaker.project import CMakeNinjaNixProject
  8. def post_build(self):
  9. # Change std::string to TString
  10. re_sub_dir(self.dstdir, r"\bstd::string\b", "TString")
  11. re_sub_dir(self.dstdir, r"\bstd::to_string\b", "::ToString")
  12. re_sub_dir(
  13. self.dstdir,
  14. "#include <string>",
  15. """
  16. #include <util/generic/string.h>
  17. #include <util/string/cast.h>
  18. """.strip(),
  19. )
  20. # Change absl to y_absl
  21. re_sub_dir(self.dstdir, r"\babsl\b", "y_absl")
  22. re_sub_dir(self.dstdir, r"\bABSL_", "Y_ABSL_")
  23. def post_install(self):
  24. def fix_protos(m):
  25. srcs = getattr(m, "SRCS", None)
  26. if not srcs:
  27. return
  28. protos = set()
  29. for s in srcs:
  30. if s.endswith(".proto"):
  31. protos.add(s)
  32. m.PEERDIR.add(P.join("contrib/libs/grpc/src", P.dirname(s)))
  33. srcs -= protos
  34. def fix_ssl_certificates():
  35. with self.yamakes["."] as m:
  36. m.SRCS.add("src/core/lib/security/security_connector/add_arcadia_root_certs.cpp")
  37. m.PEERDIR |= {"certs", "library/cpp/resource"}
  38. # in the name of selective checkout
  39. # https://st.yandex-team.ru/DTCC-615
  40. def fix_selective_checkout():
  41. self.yamakes["."].PEERDIR |= {
  42. "contrib/restricted/abseil-cpp-tstring/y_absl/algorithm",
  43. "contrib/restricted/abseil-cpp-tstring/y_absl/functional",
  44. "contrib/restricted/abseil-cpp-tstring/y_absl/memory",
  45. "contrib/restricted/abseil-cpp-tstring/y_absl/meta",
  46. "contrib/restricted/abseil-cpp-tstring/y_absl/hash",
  47. "contrib/restricted/abseil-cpp-tstring/y_absl/utility",
  48. }
  49. for name, m in self.yamakes.items():
  50. with m:
  51. fix_protos(m)
  52. if hasattr(m, "CFLAGS"):
  53. m.before(
  54. "SRCS",
  55. Switch(
  56. {
  57. "OS_LINUX OR OS_DARWIN": Linkable(
  58. CFLAGS=[
  59. "-DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1",
  60. ]
  61. ),
  62. }
  63. ),
  64. )
  65. if hasattr(m, "NO_UTIL"):
  66. m.NO_UTIL = False
  67. fix_ssl_certificates()
  68. fix_selective_checkout()
  69. # remove unnecessary folder with protos duplicates
  70. shutil.rmtree(f"{self.dstdir}/protos")
  71. # Let grpc++_reflection register itself (r6449480).
  72. with self.yamakes["grpc++_reflection"] as m:
  73. m.SRCS.remove("src/cpp/ext/proto_server_reflection_plugin.cc")
  74. m.SRCS.add(GLOBAL("src/cpp/ext/proto_server_reflection_plugin.cc"))
  75. # fix path for protos
  76. with self.yamakes["grpc++_reflection"] as m:
  77. m.PEERDIR.remove("contrib/libs/grpc/src/protos/src/proto/grpc/reflection/v1alpha")
  78. m.PEERDIR.add("contrib/libs/grpc/src/proto/grpc/reflection/v1alpha")
  79. m.ADDINCL.remove("contrib/libs/grpc/protos")
  80. with self.yamakes["grpcpp_channelz"] as m:
  81. m.PEERDIR.remove("contrib/libs/grpc/src/protos/src/proto/grpc/channelz")
  82. m.PEERDIR.add("contrib/libs/grpc/src/proto/grpc/channelz")
  83. m.ADDINCL.remove("contrib/libs/grpc/protos")
  84. # fix induced deps
  85. for name, module in self.yamakes.items():
  86. addincls = getattr(module, "ADDINCL", None)
  87. source_addincl = ArcPath("contrib/libs/grpc", build=False)
  88. build_addincl = ArcPath("contrib/libs/grpc", build=True)
  89. if addincls and source_addincl in addincls:
  90. addincls.add(build_addincl)
  91. xxhash = os.path.join(self.dstdir, "third_party/xxhash")
  92. if os.path.exists(xxhash) and os.path.isdir(xxhash):
  93. shutil.rmtree(xxhash, ignore_errors=True)
  94. with self.yamakes["."] as m:
  95. # fmt: off
  96. m.RECURSE += [
  97. os.path.dirname(path)
  98. for path in self.keep_paths
  99. if path.endswith("/ya.make")
  100. ]
  101. # fmt: on
  102. grpc = CMakeNinjaNixProject(
  103. owners=["g:cpp-contrib"],
  104. arcdir="contrib/libs/grpc",
  105. nixattr="grpc",
  106. license="Apache-2.0",
  107. keep_paths=[
  108. "src/core/lib/security/security_connector/add_arcadia_root_certs.*",
  109. # Keep original ya.make for now
  110. "src/proto/grpc/core/ya.make",
  111. "src/proto/grpc/channelz/ya.make",
  112. "src/proto/grpc/health/v1/ya.make",
  113. "src/proto/grpc/reflection/v1alpha/ya.make",
  114. "src/proto/grpc/status/ya.make",
  115. ],
  116. ignore_targets=[
  117. "check_epollexclusive",
  118. "gen_hpack_tables",
  119. "grpc++_alts",
  120. "grpc++_error_details",
  121. "grpc++_unsecure",
  122. "grpc_unsecure",
  123. ],
  124. install_targets=[
  125. "gpr",
  126. "grpc",
  127. "grpc++",
  128. "grpc++_reflection",
  129. "grpc_cpp_plugin",
  130. "grpc_plugin_support",
  131. "grpc_python_plugin",
  132. "grpcpp_channelz",
  133. # third_party libraries
  134. "address_sorting",
  135. "upb",
  136. ],
  137. put={
  138. "grpc": ".",
  139. "grpc_cpp_plugin": "src/compiler/grpc_cpp_plugin",
  140. "grpc_plugin_support": "src/compiler/grpc_plugin_support",
  141. "grpc_python_plugin": "src/compiler/grpc_python_plugin",
  142. "grpcpp_channelz": "grpcpp_channelz",
  143. # third_party libraries
  144. "address_sorting": "third_party/address_sorting",
  145. "upb": "third_party/upb",
  146. },
  147. put_with={
  148. "grpc": ["grpc++", "gpr"],
  149. },
  150. unbundle_from={
  151. "xxhash": "third_party/xxhash",
  152. },
  153. copy_sources=[
  154. "include/**/*.h",
  155. "src/core/ext/transport/binder/utils/binder_auto_utils.h",
  156. "src/core/lib/gpr/string_windows.h",
  157. "src/core/lib/iomgr/ev_apple.h",
  158. "src/core/lib/iomgr/iocp_windows.h",
  159. "src/core/lib/iomgr/pollset_windows.h",
  160. "src/core/lib/iomgr/pollset_set_windows.h",
  161. "src/core/lib/iomgr/python_util.h",
  162. "src/core/lib/iomgr/resolve_address_windows.h",
  163. "src/core/lib/iomgr/socket_windows.h",
  164. "src/core/lib/iomgr/tcp_windows.h",
  165. "src/core/lib/event_engine/windows/windows_endpoint.h",
  166. "src/core/lib/event_engine/windows/windows_engine.h",
  167. "src/core/lib/event_engine/windows/windows_listener.h",
  168. "src/core/lib/event_engine/windows/win_socket.h",
  169. "src/core/lib/event_engine/windows/iocp.h",
  170. "src/core/lib/event_engine/socket_notifier.h",
  171. "src/core/lib/event_engine/poller.h",
  172. # Copy all .proto files except for grpc/testing
  173. "src/proto/grpc/channelz/**/*.proto",
  174. "src/proto/grpc/core/**/*.proto",
  175. "src/proto/grpc/gcp/**/*.proto",
  176. "src/proto/grpc/health/**/*.proto",
  177. "src/proto/grpc/lb/**/*.proto",
  178. "src/proto/grpc/lookup/**/*.proto",
  179. "src/proto/grpc/reflection/**/*.proto",
  180. "src/proto/grpc/status/**/*.proto",
  181. ],
  182. copy_sources_except=[
  183. # Proto library with testing services
  184. "src/proto/grpc/testing/",
  185. ],
  186. disable_includes=[
  187. "src/core/lib/profiling/stap_probes.h",
  188. # ifdef GRPC_UV
  189. "uv.h",
  190. # ifdef GRPC_USE_EVENT_ENGINE
  191. "src/core/lib/iomgr/resource_quota.h",
  192. # ifdef GRPC_CFSTREAM
  193. "src/core/lib/iomgr/cfstream_handle.h",
  194. "src/core/lib/iomgr/endpoint_cfstream.h",
  195. "src/core/lib/iomgr/error_cfstream.h",
  196. "src/core/lib/iomgr/event_engine/closure.h",
  197. "src/core/lib/iomgr/event_engine/endpoint.h",
  198. "src/core/lib/iomgr/event_engine/pollset.h",
  199. "src/core/lib/iomgr/event_engine/promise.h",
  200. "src/core/lib/iomgr/event_engine/resolver.h",
  201. "src/core/lib/iomgr/resolve_address_impl.h",
  202. "src/core/lib/gpr/string_windows.h",
  203. "systemd/sd-daemon.h",
  204. ],
  205. use_provides=[
  206. "contrib/restricted/abseil-cpp-tstring/.yandex_meta",
  207. ],
  208. post_build=post_build,
  209. post_install=post_install,
  210. )