__init__.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import os
  2. import itertools
  3. from devtools.yamaker.modules import GLOBAL, Linkable, Switch
  4. from devtools.yamaker import pathutil
  5. from devtools.yamaker.project import NixProject
  6. WINDOWS_SRCS = [
  7. "alloca.h",
  8. "close.c",
  9. "dup2.c",
  10. "error.c",
  11. "fcntl.c",
  12. "fd-hook.c",
  13. "fd-hook.h",
  14. "float+.h",
  15. "fpending.c",
  16. "getdtablesize.c",
  17. "getopt.c",
  18. "getopt1.c",
  19. "getopt_int.h",
  20. "isnand-nolibm.h",
  21. "isnanf-nolibm.h",
  22. "isnanl-nolibm.h",
  23. "msvc-inval.c",
  24. "msvc-inval.h",
  25. "msvc-nothrow.c",
  26. "msvc-nothrow.h",
  27. "obstack.c",
  28. "obstack_printf.c",
  29. "open.c",
  30. "raise.c",
  31. "sigaction.c",
  32. "sigprocmask.c",
  33. "stpcpy.c",
  34. "stpncpy.c",
  35. "strndup.c",
  36. "strverscmp.c",
  37. "unitypes.h",
  38. "uniwisth.h",
  39. "w32spawn.h",
  40. "waitpid.c",
  41. "wcwidth.c",
  42. "windows-initguard.h",
  43. "windows-mutex.c",
  44. "windows-mutex.h",
  45. "windows-once.c",
  46. "windows-once.h",
  47. "windows-recmutex.c",
  48. "windows-recmutex.h",
  49. "windows-rwlock.c",
  50. "windows-rwlock.h",
  51. "windows-tls.c",
  52. "windows-tls.h",
  53. ]
  54. MUSL_SRCS = [
  55. "error.c",
  56. "obstack.c",
  57. "obstack_printf.c",
  58. ]
  59. DARWIN_SRCS = [
  60. "error.c",
  61. "fpending.c",
  62. "obstack.c",
  63. "obstack_printf.c",
  64. "strverscmp.c",
  65. ]
  66. EXCESSIVE_SRCS = [
  67. "alloca.h",
  68. "fcntl.h",
  69. "fprintf.c",
  70. "gettime.c",
  71. "iconv.h",
  72. "inttypes.h",
  73. "math.h",
  74. "limits.h",
  75. "locale.h",
  76. "printf.c",
  77. "sched.h",
  78. "signal.h",
  79. "snprintf.c",
  80. "spawn.h",
  81. "sprintf.c",
  82. "stdio.h",
  83. "stdlib.h",
  84. "string.h",
  85. "sys/ioctl.h",
  86. "sys/resource.h",
  87. "sys/time.h",
  88. "sys/times.h",
  89. "sys/types.h",
  90. "sys/wait.h",
  91. "termios.h",
  92. "time.h",
  93. "unistd.h",
  94. "vfprintf.c",
  95. "vsnprintf.c",
  96. "vsprintf.c",
  97. "wchar.h",
  98. "wctype.h",
  99. ]
  100. def post_install(self):
  101. with self.yamakes["lib"] as gnulib:
  102. # musl-libc has fseterr
  103. gnulib.SRCS.remove("fseterr.c")
  104. gnulib.after(
  105. "SRCS",
  106. """
  107. IF (NOT MUSL)
  108. SRCS(
  109. fseterr.c
  110. )
  111. ENDIF()
  112. """,
  113. )
  114. gnulib.after(
  115. "SRCS",
  116. Switch(
  117. MUSL=Linkable(
  118. SRCS=MUSL_SRCS,
  119. ),
  120. OS_DARWIN=Linkable(
  121. SRCS=DARWIN_SRCS,
  122. ),
  123. OS_WINDOWS=Linkable(
  124. SRCS=[src for src in WINDOWS_SRCS if pathutil.is_source(src)],
  125. ADDINCL=[GLOBAL(f"{self.arcdir}/lib/platform/win64")],
  126. ),
  127. ),
  128. )
  129. for src in WINDOWS_SRCS:
  130. if pathutil.is_source(src) and src in gnulib.SRCS:
  131. gnulib.SRCS.remove(src)
  132. for src in EXCESSIVE_SRCS:
  133. os.remove(f"{self.dstdir}/lib/{src}")
  134. if pathutil.is_source(src):
  135. gnulib.SRCS.remove(src)
  136. bison = NixProject(
  137. arcdir="contrib/tools/bison",
  138. owners=["g:cpp-contrib"],
  139. nixattr="bison",
  140. ignore_commands=[
  141. "bash",
  142. "cat",
  143. "sed",
  144. ],
  145. use_full_libnames=True,
  146. install_targets=[
  147. "bison",
  148. "libbison",
  149. ],
  150. put={
  151. "bison": ".",
  152. "libbison": "lib",
  153. },
  154. keep_paths=[
  155. "lib/platform/win64/*.h",
  156. "lib/platform/win64/sys/*.h",
  157. # Keep this for now as upstream code crashes on Windows
  158. "src/scan-skel.c",
  159. ],
  160. copy_sources=[
  161. "data/skeletons/*.c",
  162. "data/skeletons/*.cc",
  163. "data/skeletons/*.hh",
  164. "data/skeletons/*.m4",
  165. "data/m4sugar/*.m4",
  166. # These lex / bison sources will not be used
  167. # (how does one bootstrap bison without having bison?)
  168. #
  169. # Just copy them for informational purposes
  170. "src/scan-code.l",
  171. "src/scan-gram.l",
  172. "src/scan-skel.l",
  173. "src/parse-gram.y",
  174. ]
  175. + [f"lib/{src}" for src in itertools.chain(MUSL_SRCS, DARWIN_SRCS, WINDOWS_SRCS)],
  176. copy_sources_except=[
  177. # Don't need them for now, reduce import footprint
  178. "data/skeletons/d.m4",
  179. "data/skeletons/d-skel.m4",
  180. "data/skeletons/glr.c",
  181. "data/skeletons/java.m4",
  182. "data/skeletons/java-skel.m4",
  183. "data/skeletons/traceon.m4",
  184. ],
  185. platform_dispatchers=[
  186. "lib/config.h",
  187. "lib/configmake.h",
  188. ],
  189. disable_includes=[
  190. "InnoTekLIBC/backend.h",
  191. "bits/libc-lock.h",
  192. "libio/",
  193. "synch.h",
  194. "random.h",
  195. "OS.h",
  196. "os2.h",
  197. "sys/ps.h",
  198. "sys/ptem.h",
  199. "sys/single_threaded.h",
  200. "mbtowc-lock.h",
  201. "mbrtowc-impl.h",
  202. "lc-charset-dispatch.h",
  203. "unistring-notinline.h",
  204. "vasprintf.h",
  205. ],
  206. post_install=post_install,
  207. )
  208. bison.copy_top_sources_except |= {
  209. "ABOUT-NLS",
  210. "ChangeLog",
  211. "ChangeLog-2012",
  212. "ChangeLog-1998",
  213. "INSTALL",
  214. }