__init__.py 8.1 KB

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