@pnpm/exe 11.0.0-dev.1003 → 11.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (584) hide show
  1. package/dist/node-gyp-bin/node-gyp +6 -0
  2. package/dist/node-gyp-bin/node-gyp.cmd +5 -0
  3. package/dist/node_modules/@gar/promise-retry/LICENSE +20 -0
  4. package/dist/node_modules/@gar/promise-retry/lib/index.js +62 -0
  5. package/dist/node_modules/@gar/promise-retry/lib/retry.js +109 -0
  6. package/dist/node_modules/@gar/promise-retry/package.json +45 -0
  7. package/dist/node_modules/@isaacs/fs-minipass/LICENSE +15 -0
  8. package/dist/node_modules/@isaacs/fs-minipass/dist/commonjs/index.js +430 -0
  9. package/dist/node_modules/@isaacs/fs-minipass/dist/commonjs/package.json +3 -0
  10. package/dist/node_modules/@isaacs/fs-minipass/dist/esm/index.js +420 -0
  11. package/dist/node_modules/@isaacs/fs-minipass/dist/esm/package.json +3 -0
  12. package/dist/node_modules/@isaacs/fs-minipass/package.json +72 -0
  13. package/dist/node_modules/@npmcli/agent/lib/agents.js +206 -0
  14. package/dist/node_modules/@npmcli/agent/lib/dns.js +53 -0
  15. package/dist/node_modules/@npmcli/agent/lib/errors.js +61 -0
  16. package/dist/node_modules/@npmcli/agent/lib/index.js +56 -0
  17. package/dist/node_modules/@npmcli/agent/lib/options.js +86 -0
  18. package/dist/node_modules/@npmcli/agent/lib/proxy.js +88 -0
  19. package/dist/node_modules/@npmcli/agent/package.json +60 -0
  20. package/dist/node_modules/@npmcli/fs/lib/common/get-options.js +20 -0
  21. package/dist/node_modules/@npmcli/fs/lib/common/node.js +9 -0
  22. package/dist/node_modules/@npmcli/fs/lib/cp/LICENSE +15 -0
  23. package/dist/node_modules/@npmcli/fs/lib/cp/errors.js +129 -0
  24. package/dist/node_modules/@npmcli/fs/lib/cp/index.js +22 -0
  25. package/dist/node_modules/@npmcli/fs/lib/cp/polyfill.js +428 -0
  26. package/dist/node_modules/@npmcli/fs/lib/index.js +13 -0
  27. package/dist/node_modules/@npmcli/fs/lib/move-file.js +78 -0
  28. package/dist/node_modules/@npmcli/fs/lib/readdir-scoped.js +20 -0
  29. package/dist/node_modules/@npmcli/fs/lib/with-temp-dir.js +39 -0
  30. package/dist/node_modules/@npmcli/fs/package.json +54 -0
  31. package/dist/node_modules/@npmcli/redact/LICENSE +21 -0
  32. package/dist/node_modules/@npmcli/redact/lib/deep-map.js +71 -0
  33. package/dist/node_modules/@npmcli/redact/lib/error.js +28 -0
  34. package/dist/node_modules/@npmcli/redact/lib/index.js +44 -0
  35. package/dist/node_modules/@npmcli/redact/lib/matchers.js +88 -0
  36. package/dist/node_modules/@npmcli/redact/lib/server.js +59 -0
  37. package/dist/node_modules/@npmcli/redact/lib/utils.js +202 -0
  38. package/dist/node_modules/@npmcli/redact/package.json +52 -0
  39. package/dist/node_modules/abbrev/LICENSE +46 -0
  40. package/dist/node_modules/abbrev/lib/index.js +53 -0
  41. package/dist/node_modules/abbrev/package.json +41 -0
  42. package/dist/node_modules/agent-base/LICENSE +22 -0
  43. package/dist/node_modules/agent-base/dist/helpers.js +66 -0
  44. package/dist/node_modules/agent-base/dist/index.js +178 -0
  45. package/dist/node_modules/agent-base/package.json +46 -0
  46. package/dist/node_modules/balanced-match/dist/commonjs/index.js +59 -0
  47. package/dist/node_modules/balanced-match/dist/commonjs/package.json +3 -0
  48. package/dist/node_modules/balanced-match/dist/esm/index.js +54 -0
  49. package/dist/node_modules/balanced-match/dist/esm/package.json +3 -0
  50. package/dist/node_modules/balanced-match/package.json +68 -0
  51. package/dist/node_modules/brace-expansion/LICENSE +23 -0
  52. package/dist/node_modules/brace-expansion/dist/commonjs/index.js +201 -0
  53. package/dist/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
  54. package/dist/node_modules/brace-expansion/dist/esm/index.js +197 -0
  55. package/dist/node_modules/brace-expansion/dist/esm/package.json +3 -0
  56. package/dist/node_modules/brace-expansion/package.json +64 -0
  57. package/dist/node_modules/cacache/lib/content/path.js +29 -0
  58. package/dist/node_modules/cacache/lib/content/read.js +165 -0
  59. package/dist/node_modules/cacache/lib/content/rm.js +18 -0
  60. package/dist/node_modules/cacache/lib/content/write.js +206 -0
  61. package/dist/node_modules/cacache/lib/entry-index.js +336 -0
  62. package/dist/node_modules/cacache/lib/get.js +170 -0
  63. package/dist/node_modules/cacache/lib/index.js +42 -0
  64. package/dist/node_modules/cacache/lib/memoization.js +72 -0
  65. package/dist/node_modules/cacache/lib/put.js +80 -0
  66. package/dist/node_modules/cacache/lib/rm.js +31 -0
  67. package/dist/node_modules/cacache/lib/util/glob.js +7 -0
  68. package/dist/node_modules/cacache/lib/util/hash-to-segments.js +7 -0
  69. package/dist/node_modules/cacache/lib/util/tmp.js +32 -0
  70. package/dist/node_modules/cacache/lib/verify.js +258 -0
  71. package/dist/node_modules/cacache/package.json +81 -0
  72. package/dist/node_modules/chownr/dist/commonjs/index.js +93 -0
  73. package/dist/node_modules/chownr/dist/commonjs/package.json +3 -0
  74. package/dist/node_modules/chownr/dist/esm/index.js +85 -0
  75. package/dist/node_modules/chownr/dist/esm/package.json +3 -0
  76. package/dist/node_modules/chownr/package.json +69 -0
  77. package/dist/node_modules/debug/LICENSE +20 -0
  78. package/dist/node_modules/debug/package.json +64 -0
  79. package/dist/node_modules/debug/src/browser.js +272 -0
  80. package/dist/node_modules/debug/src/common.js +292 -0
  81. package/dist/node_modules/debug/src/index.js +10 -0
  82. package/dist/node_modules/debug/src/node.js +263 -0
  83. package/dist/node_modules/env-paths/index.js +74 -0
  84. package/dist/node_modules/env-paths/license +9 -0
  85. package/dist/node_modules/env-paths/package.json +45 -0
  86. package/dist/node_modules/exponential-backoff/LICENSE +202 -0
  87. package/dist/node_modules/exponential-backoff/dist/backoff.js +124 -0
  88. package/dist/node_modules/exponential-backoff/dist/delay/always/always.delay.js +25 -0
  89. package/dist/node_modules/exponential-backoff/dist/delay/delay.base.js +45 -0
  90. package/dist/node_modules/exponential-backoff/dist/delay/delay.factory.js +17 -0
  91. package/dist/node_modules/exponential-backoff/dist/delay/delay.interface.js +3 -0
  92. package/dist/node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js +82 -0
  93. package/dist/node_modules/exponential-backoff/dist/jitter/full/full.jitter.js +8 -0
  94. package/dist/node_modules/exponential-backoff/dist/jitter/jitter.factory.js +15 -0
  95. package/dist/node_modules/exponential-backoff/dist/jitter/no/no.jitter.js +7 -0
  96. package/dist/node_modules/exponential-backoff/dist/options.js +31 -0
  97. package/dist/node_modules/exponential-backoff/package.json +62 -0
  98. package/dist/node_modules/fdir/LICENSE +7 -0
  99. package/dist/node_modules/fdir/dist/index.cjs +588 -0
  100. package/dist/node_modules/fdir/dist/index.d.cts +155 -0
  101. package/dist/node_modules/fdir/dist/index.d.mts +155 -0
  102. package/dist/node_modules/fdir/dist/index.mjs +570 -0
  103. package/dist/node_modules/fdir/package.json +103 -0
  104. package/dist/node_modules/fs-minipass/LICENSE +15 -0
  105. package/dist/node_modules/fs-minipass/lib/index.js +443 -0
  106. package/dist/node_modules/fs-minipass/package.json +54 -0
  107. package/dist/node_modules/glob/dist/commonjs/glob.js +248 -0
  108. package/dist/node_modules/glob/dist/commonjs/has-magic.js +27 -0
  109. package/dist/node_modules/glob/dist/commonjs/ignore.js +119 -0
  110. package/dist/node_modules/glob/dist/commonjs/index.js +68 -0
  111. package/dist/node_modules/glob/dist/commonjs/index.min.js +4 -0
  112. package/dist/node_modules/glob/dist/commonjs/package.json +3 -0
  113. package/dist/node_modules/glob/dist/commonjs/pattern.js +223 -0
  114. package/dist/node_modules/glob/dist/commonjs/processor.js +301 -0
  115. package/dist/node_modules/glob/dist/commonjs/walker.js +387 -0
  116. package/dist/node_modules/glob/dist/esm/glob.js +244 -0
  117. package/dist/node_modules/glob/dist/esm/has-magic.js +23 -0
  118. package/dist/node_modules/glob/dist/esm/ignore.js +115 -0
  119. package/dist/node_modules/glob/dist/esm/index.js +55 -0
  120. package/dist/node_modules/glob/dist/esm/index.min.js +4 -0
  121. package/dist/node_modules/glob/dist/esm/package.json +3 -0
  122. package/dist/node_modules/glob/dist/esm/pattern.js +219 -0
  123. package/dist/node_modules/glob/dist/esm/processor.js +294 -0
  124. package/dist/node_modules/glob/dist/esm/walker.js +381 -0
  125. package/dist/node_modules/glob/package.json +98 -0
  126. package/dist/node_modules/graceful-fs/LICENSE +15 -0
  127. package/dist/node_modules/graceful-fs/clone.js +23 -0
  128. package/dist/node_modules/graceful-fs/graceful-fs.js +448 -0
  129. package/dist/node_modules/graceful-fs/legacy-streams.js +118 -0
  130. package/dist/node_modules/graceful-fs/package.json +53 -0
  131. package/dist/node_modules/graceful-fs/polyfills.js +355 -0
  132. package/dist/node_modules/http-cache-semantics/LICENSE +9 -0
  133. package/dist/node_modules/http-cache-semantics/index.js +928 -0
  134. package/dist/node_modules/http-cache-semantics/package.json +22 -0
  135. package/dist/node_modules/http-proxy-agent/LICENSE +22 -0
  136. package/dist/node_modules/http-proxy-agent/dist/index.js +148 -0
  137. package/dist/node_modules/http-proxy-agent/package.json +47 -0
  138. package/dist/node_modules/https-proxy-agent/LICENSE +22 -0
  139. package/dist/node_modules/https-proxy-agent/dist/index.js +180 -0
  140. package/dist/node_modules/https-proxy-agent/dist/parse-proxy-response.js +101 -0
  141. package/dist/node_modules/https-proxy-agent/package.json +50 -0
  142. package/dist/node_modules/iconv-lite/LICENSE +21 -0
  143. package/dist/node_modules/iconv-lite/encodings/dbcs-codec.js +532 -0
  144. package/dist/node_modules/iconv-lite/encodings/dbcs-data.js +185 -0
  145. package/dist/node_modules/iconv-lite/encodings/index.js +23 -0
  146. package/dist/node_modules/iconv-lite/encodings/internal.js +218 -0
  147. package/dist/node_modules/iconv-lite/encodings/sbcs-codec.js +75 -0
  148. package/dist/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
  149. package/dist/node_modules/iconv-lite/encodings/sbcs-data.js +178 -0
  150. package/dist/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
  151. package/dist/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
  152. package/dist/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
  153. package/dist/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
  154. package/dist/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
  155. package/dist/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
  156. package/dist/node_modules/iconv-lite/encodings/tables/gbk-added.json +56 -0
  157. package/dist/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
  158. package/dist/node_modules/iconv-lite/encodings/utf16.js +187 -0
  159. package/dist/node_modules/iconv-lite/encodings/utf32.js +307 -0
  160. package/dist/node_modules/iconv-lite/encodings/utf7.js +283 -0
  161. package/dist/node_modules/iconv-lite/lib/bom-handling.js +48 -0
  162. package/dist/node_modules/iconv-lite/lib/helpers/merge-exports.js +13 -0
  163. package/dist/node_modules/iconv-lite/lib/index.js +182 -0
  164. package/dist/node_modules/iconv-lite/lib/streams.js +105 -0
  165. package/dist/node_modules/iconv-lite/package.json +70 -0
  166. package/dist/node_modules/ip-address/LICENSE +19 -0
  167. package/dist/node_modules/ip-address/dist/address-error.js +12 -0
  168. package/dist/node_modules/ip-address/dist/common.js +46 -0
  169. package/dist/node_modules/ip-address/dist/ip-address.js +35 -0
  170. package/dist/node_modules/ip-address/dist/ipv4.js +360 -0
  171. package/dist/node_modules/ip-address/dist/ipv6.js +1003 -0
  172. package/dist/node_modules/ip-address/dist/v4/constants.js +8 -0
  173. package/dist/node_modules/ip-address/dist/v6/constants.js +76 -0
  174. package/dist/node_modules/ip-address/dist/v6/helpers.js +45 -0
  175. package/dist/node_modules/ip-address/dist/v6/regular-expressions.js +95 -0
  176. package/dist/node_modules/ip-address/package.json +78 -0
  177. package/dist/node_modules/isexe/dist/commonjs/index.js +56 -0
  178. package/dist/node_modules/isexe/dist/commonjs/index.min.js +2 -0
  179. package/dist/node_modules/isexe/dist/commonjs/options.js +3 -0
  180. package/dist/node_modules/isexe/dist/commonjs/package.json +3 -0
  181. package/dist/node_modules/isexe/dist/commonjs/posix.js +67 -0
  182. package/dist/node_modules/isexe/dist/commonjs/win32.js +63 -0
  183. package/dist/node_modules/isexe/dist/esm/index.js +16 -0
  184. package/dist/node_modules/isexe/dist/esm/index.min.js +2 -0
  185. package/dist/node_modules/isexe/dist/esm/options.js +2 -0
  186. package/dist/node_modules/isexe/dist/esm/package.json +3 -0
  187. package/dist/node_modules/isexe/dist/esm/posix.js +62 -0
  188. package/dist/node_modules/isexe/dist/esm/win32.js +58 -0
  189. package/dist/node_modules/isexe/package.json +78 -0
  190. package/dist/node_modules/lru-cache/dist/commonjs/index.js +1595 -0
  191. package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
  192. package/dist/node_modules/lru-cache/dist/commonjs/package.json +3 -0
  193. package/dist/node_modules/lru-cache/dist/esm/index.js +1591 -0
  194. package/dist/node_modules/lru-cache/dist/esm/index.min.js +2 -0
  195. package/dist/node_modules/lru-cache/dist/esm/package.json +3 -0
  196. package/dist/node_modules/lru-cache/package.json +93 -0
  197. package/dist/node_modules/make-fetch-happen/LICENSE +16 -0
  198. package/dist/node_modules/make-fetch-happen/lib/cache/entry.js +471 -0
  199. package/dist/node_modules/make-fetch-happen/lib/cache/errors.js +11 -0
  200. package/dist/node_modules/make-fetch-happen/lib/cache/index.js +49 -0
  201. package/dist/node_modules/make-fetch-happen/lib/cache/key.js +17 -0
  202. package/dist/node_modules/make-fetch-happen/lib/cache/policy.js +161 -0
  203. package/dist/node_modules/make-fetch-happen/lib/fetch.js +118 -0
  204. package/dist/node_modules/make-fetch-happen/lib/index.js +41 -0
  205. package/dist/node_modules/make-fetch-happen/lib/options.js +59 -0
  206. package/dist/node_modules/make-fetch-happen/lib/pipeline.js +41 -0
  207. package/dist/node_modules/make-fetch-happen/lib/remote.js +134 -0
  208. package/dist/node_modules/make-fetch-happen/package.json +75 -0
  209. package/dist/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
  210. package/dist/node_modules/minimatch/dist/commonjs/ast.js +846 -0
  211. package/dist/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
  212. package/dist/node_modules/minimatch/dist/commonjs/escape.js +30 -0
  213. package/dist/node_modules/minimatch/dist/commonjs/index.js +1121 -0
  214. package/dist/node_modules/minimatch/dist/commonjs/package.json +3 -0
  215. package/dist/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
  216. package/dist/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
  217. package/dist/node_modules/minimatch/dist/esm/ast.js +842 -0
  218. package/dist/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
  219. package/dist/node_modules/minimatch/dist/esm/escape.js +26 -0
  220. package/dist/node_modules/minimatch/dist/esm/index.js +1108 -0
  221. package/dist/node_modules/minimatch/dist/esm/package.json +3 -0
  222. package/dist/node_modules/minimatch/dist/esm/unescape.js +34 -0
  223. package/dist/node_modules/minimatch/package.json +67 -0
  224. package/dist/node_modules/minipass/dist/commonjs/index.js +1038 -0
  225. package/dist/node_modules/minipass/dist/commonjs/package.json +3 -0
  226. package/dist/node_modules/minipass/dist/esm/index.js +1020 -0
  227. package/dist/node_modules/minipass/dist/esm/package.json +3 -0
  228. package/dist/node_modules/minipass/package.json +77 -0
  229. package/dist/node_modules/minipass-collect/LICENSE +15 -0
  230. package/dist/node_modules/minipass-collect/index.js +71 -0
  231. package/dist/node_modules/minipass-collect/package.json +30 -0
  232. package/dist/node_modules/minipass-fetch/LICENSE +28 -0
  233. package/dist/node_modules/minipass-fetch/lib/abort-error.js +17 -0
  234. package/dist/node_modules/minipass-fetch/lib/blob.js +97 -0
  235. package/dist/node_modules/minipass-fetch/lib/body.js +360 -0
  236. package/dist/node_modules/minipass-fetch/lib/fetch-error.js +32 -0
  237. package/dist/node_modules/minipass-fetch/lib/headers.js +267 -0
  238. package/dist/node_modules/minipass-fetch/lib/index.js +376 -0
  239. package/dist/node_modules/minipass-fetch/lib/request.js +282 -0
  240. package/dist/node_modules/minipass-fetch/lib/response.js +90 -0
  241. package/dist/node_modules/minipass-fetch/package.json +70 -0
  242. package/dist/node_modules/minipass-flush/LICENSE +15 -0
  243. package/dist/node_modules/minipass-flush/index.js +39 -0
  244. package/dist/node_modules/minipass-flush/node_modules/minipass/LICENSE +15 -0
  245. package/dist/node_modules/minipass-flush/node_modules/minipass/index.js +649 -0
  246. package/dist/node_modules/minipass-flush/node_modules/minipass/package.json +56 -0
  247. package/dist/node_modules/minipass-flush/package.json +39 -0
  248. package/dist/node_modules/minipass-pipeline/LICENSE +15 -0
  249. package/dist/node_modules/minipass-pipeline/index.js +128 -0
  250. package/dist/node_modules/minipass-pipeline/node_modules/minipass/LICENSE +15 -0
  251. package/dist/node_modules/minipass-pipeline/node_modules/minipass/index.js +649 -0
  252. package/dist/node_modules/minipass-pipeline/node_modules/minipass/package.json +56 -0
  253. package/dist/node_modules/minipass-pipeline/package.json +29 -0
  254. package/dist/node_modules/minipass-sized/LICENSE +15 -0
  255. package/dist/node_modules/minipass-sized/dist/commonjs/index.js +69 -0
  256. package/dist/node_modules/minipass-sized/dist/commonjs/package.json +3 -0
  257. package/dist/node_modules/minipass-sized/dist/esm/index.js +64 -0
  258. package/dist/node_modules/minipass-sized/dist/esm/package.json +3 -0
  259. package/dist/node_modules/minipass-sized/package.json +69 -0
  260. package/dist/node_modules/minizlib/LICENSE +26 -0
  261. package/dist/node_modules/minizlib/dist/commonjs/constants.js +123 -0
  262. package/dist/node_modules/minizlib/dist/commonjs/index.js +416 -0
  263. package/dist/node_modules/minizlib/dist/commonjs/package.json +3 -0
  264. package/dist/node_modules/minizlib/dist/esm/constants.js +117 -0
  265. package/dist/node_modules/minizlib/dist/esm/index.js +363 -0
  266. package/dist/node_modules/minizlib/dist/esm/package.json +3 -0
  267. package/dist/node_modules/minizlib/package.json +80 -0
  268. package/dist/node_modules/ms/index.js +162 -0
  269. package/dist/node_modules/ms/package.json +38 -0
  270. package/dist/node_modules/negotiator/LICENSE +24 -0
  271. package/dist/node_modules/negotiator/index.js +83 -0
  272. package/dist/node_modules/negotiator/lib/charset.js +169 -0
  273. package/dist/node_modules/negotiator/lib/encoding.js +205 -0
  274. package/dist/node_modules/negotiator/lib/language.js +179 -0
  275. package/dist/node_modules/negotiator/lib/mediaType.js +294 -0
  276. package/dist/node_modules/negotiator/package.json +43 -0
  277. package/dist/node_modules/node-gyp/.release-please-manifest.json +3 -0
  278. package/dist/node_modules/node-gyp/LICENSE +24 -0
  279. package/dist/node_modules/node-gyp/addon.gypi +204 -0
  280. package/dist/node_modules/node-gyp/bin/node-gyp.js +145 -0
  281. package/dist/node_modules/node-gyp/eslint.config.js +3 -0
  282. package/dist/node_modules/node-gyp/gyp/.release-please-manifest.json +3 -0
  283. package/dist/node_modules/node-gyp/gyp/LICENSE +28 -0
  284. package/dist/node_modules/node-gyp/gyp/data/ninja/build.ninja +4 -0
  285. package/dist/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +12 -0
  286. package/dist/node_modules/node-gyp/gyp/gyp +8 -0
  287. package/dist/node_modules/node-gyp/gyp/gyp.bat +5 -0
  288. package/dist/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  289. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  290. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  291. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1283 -0
  292. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1545 -0
  293. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  294. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +152 -0
  295. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +270 -0
  296. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +599 -0
  297. package/dist/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +707 -0
  298. package/dist/node_modules/node-gyp/gyp/pylib/gyp/common.py +725 -0
  299. package/dist/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +186 -0
  300. package/dist/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +170 -0
  301. package/dist/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  302. package/dist/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  303. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  304. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +805 -0
  305. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1169 -0
  306. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1316 -0
  307. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +128 -0
  308. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +104 -0
  309. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +461 -0
  310. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +88 -0
  311. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +55 -0
  312. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2755 -0
  313. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3970 -0
  314. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  315. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2956 -0
  316. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
  317. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1389 -0
  318. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +26 -0
  319. package/dist/node_modules/node-gyp/gyp/pylib/gyp/input.py +3097 -0
  320. package/dist/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +99 -0
  321. package/dist/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +765 -0
  322. package/dist/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1255 -0
  323. package/dist/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  324. package/dist/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  325. package/dist/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +371 -0
  326. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1936 -0
  327. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +54 -0
  328. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +301 -0
  329. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3180 -0
  330. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +64 -0
  331. package/dist/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +3 -0
  332. package/dist/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +177 -0
  333. package/dist/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +23 -0
  334. package/dist/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  335. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +107 -0
  336. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  337. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  338. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  339. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  340. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  341. package/dist/node_modules/node-gyp/gyp/pylib/packaging/markers.py +251 -0
  342. package/dist/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +824 -0
  343. package/dist/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  344. package/dist/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  345. package/dist/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  346. package/dist/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
  347. package/dist/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  348. package/dist/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
  349. package/dist/node_modules/node-gyp/gyp/pyproject.toml +114 -0
  350. package/dist/node_modules/node-gyp/gyp/release-please-config.json +11 -0
  351. package/dist/node_modules/node-gyp/gyp/test_gyp.py +260 -0
  352. package/dist/node_modules/node-gyp/lib/Find-VisualStudio.cs +250 -0
  353. package/dist/node_modules/node-gyp/lib/build.js +230 -0
  354. package/dist/node_modules/node-gyp/lib/clean.js +15 -0
  355. package/dist/node_modules/node-gyp/lib/configure.js +328 -0
  356. package/dist/node_modules/node-gyp/lib/create-config-gypi.js +153 -0
  357. package/dist/node_modules/node-gyp/lib/download.js +39 -0
  358. package/dist/node_modules/node-gyp/lib/find-node-directory.js +63 -0
  359. package/dist/node_modules/node-gyp/lib/find-python.js +304 -0
  360. package/dist/node_modules/node-gyp/lib/find-visualstudio.js +606 -0
  361. package/dist/node_modules/node-gyp/lib/install.js +411 -0
  362. package/dist/node_modules/node-gyp/lib/list.js +26 -0
  363. package/dist/node_modules/node-gyp/lib/log.js +168 -0
  364. package/dist/node_modules/node-gyp/lib/node-gyp.js +199 -0
  365. package/dist/node_modules/node-gyp/lib/process-release.js +146 -0
  366. package/dist/node_modules/node-gyp/lib/rebuild.js +12 -0
  367. package/dist/node_modules/node-gyp/lib/remove.js +43 -0
  368. package/dist/node_modules/node-gyp/lib/util.js +81 -0
  369. package/dist/node_modules/node-gyp/macOS_Catalina_acid_test.sh +21 -0
  370. package/dist/node_modules/node-gyp/package.json +52 -0
  371. package/dist/node_modules/node-gyp/release-please-config.json +40 -0
  372. package/dist/node_modules/node-gyp/src/win_delay_load_hook.cc +41 -0
  373. package/dist/node_modules/nopt/LICENSE +15 -0
  374. package/dist/node_modules/nopt/bin/nopt.js +29 -0
  375. package/dist/node_modules/nopt/lib/debug.js +5 -0
  376. package/dist/node_modules/nopt/lib/nopt-lib.js +514 -0
  377. package/dist/node_modules/nopt/lib/nopt.js +34 -0
  378. package/dist/node_modules/nopt/lib/type-defs.js +91 -0
  379. package/dist/node_modules/nopt/package.json +52 -0
  380. package/dist/node_modules/p-map/index.js +283 -0
  381. package/dist/node_modules/p-map/license +9 -0
  382. package/dist/node_modules/p-map/package.json +57 -0
  383. package/dist/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
  384. package/dist/node_modules/path-scurry/dist/commonjs/package.json +3 -0
  385. package/dist/node_modules/path-scurry/dist/esm/index.js +1983 -0
  386. package/dist/node_modules/path-scurry/dist/esm/package.json +3 -0
  387. package/dist/node_modules/path-scurry/package.json +72 -0
  388. package/dist/node_modules/picomatch/LICENSE +21 -0
  389. package/dist/node_modules/picomatch/index.js +17 -0
  390. package/dist/node_modules/picomatch/lib/constants.js +184 -0
  391. package/dist/node_modules/picomatch/lib/parse.js +1386 -0
  392. package/dist/node_modules/picomatch/lib/picomatch.js +349 -0
  393. package/dist/node_modules/picomatch/lib/scan.js +391 -0
  394. package/dist/node_modules/picomatch/lib/utils.js +72 -0
  395. package/dist/node_modules/picomatch/package.json +82 -0
  396. package/dist/node_modules/picomatch/posix.js +3 -0
  397. package/dist/node_modules/proc-log/LICENSE +15 -0
  398. package/dist/node_modules/proc-log/lib/index.js +158 -0
  399. package/dist/node_modules/proc-log/package.json +46 -0
  400. package/dist/node_modules/safer-buffer/LICENSE +21 -0
  401. package/dist/node_modules/safer-buffer/dangerous.js +58 -0
  402. package/dist/node_modules/safer-buffer/package.json +34 -0
  403. package/dist/node_modules/safer-buffer/safer.js +77 -0
  404. package/dist/node_modules/safer-buffer/tests.js +406 -0
  405. package/dist/node_modules/semver/LICENSE +15 -0
  406. package/dist/node_modules/semver/bin/semver.js +191 -0
  407. package/dist/node_modules/semver/classes/comparator.js +143 -0
  408. package/dist/node_modules/semver/classes/index.js +7 -0
  409. package/dist/node_modules/semver/classes/range.js +557 -0
  410. package/dist/node_modules/semver/classes/semver.js +333 -0
  411. package/dist/node_modules/semver/functions/clean.js +8 -0
  412. package/dist/node_modules/semver/functions/cmp.js +54 -0
  413. package/dist/node_modules/semver/functions/coerce.js +62 -0
  414. package/dist/node_modules/semver/functions/compare-build.js +9 -0
  415. package/dist/node_modules/semver/functions/compare-loose.js +5 -0
  416. package/dist/node_modules/semver/functions/compare.js +7 -0
  417. package/dist/node_modules/semver/functions/diff.js +60 -0
  418. package/dist/node_modules/semver/functions/eq.js +5 -0
  419. package/dist/node_modules/semver/functions/gt.js +5 -0
  420. package/dist/node_modules/semver/functions/gte.js +5 -0
  421. package/dist/node_modules/semver/functions/inc.js +21 -0
  422. package/dist/node_modules/semver/functions/lt.js +5 -0
  423. package/dist/node_modules/semver/functions/lte.js +5 -0
  424. package/dist/node_modules/semver/functions/major.js +5 -0
  425. package/dist/node_modules/semver/functions/minor.js +5 -0
  426. package/dist/node_modules/semver/functions/neq.js +5 -0
  427. package/dist/node_modules/semver/functions/parse.js +18 -0
  428. package/dist/node_modules/semver/functions/patch.js +5 -0
  429. package/dist/node_modules/semver/functions/prerelease.js +8 -0
  430. package/dist/node_modules/semver/functions/rcompare.js +5 -0
  431. package/dist/node_modules/semver/functions/rsort.js +5 -0
  432. package/dist/node_modules/semver/functions/satisfies.js +12 -0
  433. package/dist/node_modules/semver/functions/sort.js +5 -0
  434. package/dist/node_modules/semver/functions/valid.js +8 -0
  435. package/dist/node_modules/semver/index.js +91 -0
  436. package/dist/node_modules/semver/internal/constants.js +37 -0
  437. package/dist/node_modules/semver/internal/debug.js +11 -0
  438. package/dist/node_modules/semver/internal/identifiers.js +29 -0
  439. package/dist/node_modules/semver/internal/lrucache.js +42 -0
  440. package/dist/node_modules/semver/internal/parse-options.js +17 -0
  441. package/dist/node_modules/semver/internal/re.js +223 -0
  442. package/dist/node_modules/semver/package.json +78 -0
  443. package/dist/node_modules/semver/preload.js +4 -0
  444. package/dist/node_modules/semver/range.bnf +16 -0
  445. package/dist/node_modules/semver/ranges/gtr.js +6 -0
  446. package/dist/node_modules/semver/ranges/intersects.js +9 -0
  447. package/dist/node_modules/semver/ranges/ltr.js +6 -0
  448. package/dist/node_modules/semver/ranges/max-satisfying.js +27 -0
  449. package/dist/node_modules/semver/ranges/min-satisfying.js +26 -0
  450. package/dist/node_modules/semver/ranges/min-version.js +63 -0
  451. package/dist/node_modules/semver/ranges/outside.js +82 -0
  452. package/dist/node_modules/semver/ranges/simplify.js +49 -0
  453. package/dist/node_modules/semver/ranges/subset.js +249 -0
  454. package/dist/node_modules/semver/ranges/to-comparators.js +10 -0
  455. package/dist/node_modules/semver/ranges/valid.js +13 -0
  456. package/dist/node_modules/smart-buffer/.prettierrc.yaml +5 -0
  457. package/dist/node_modules/smart-buffer/LICENSE +20 -0
  458. package/dist/node_modules/smart-buffer/build/smartbuffer.js +1233 -0
  459. package/dist/node_modules/smart-buffer/build/utils.js +108 -0
  460. package/dist/node_modules/smart-buffer/package.json +79 -0
  461. package/dist/node_modules/socks/.eslintrc.cjs +11 -0
  462. package/dist/node_modules/socks/.prettierrc.yaml +7 -0
  463. package/dist/node_modules/socks/LICENSE +20 -0
  464. package/dist/node_modules/socks/build/client/socksclient.js +793 -0
  465. package/dist/node_modules/socks/build/common/constants.js +108 -0
  466. package/dist/node_modules/socks/build/common/helpers.js +167 -0
  467. package/dist/node_modules/socks/build/common/receivebuffer.js +43 -0
  468. package/dist/node_modules/socks/build/common/util.js +25 -0
  469. package/dist/node_modules/socks/build/index.js +18 -0
  470. package/dist/node_modules/socks/package.json +58 -0
  471. package/dist/node_modules/socks-proxy-agent/LICENSE +22 -0
  472. package/dist/node_modules/socks-proxy-agent/dist/index.js +195 -0
  473. package/dist/node_modules/socks-proxy-agent/package.json +142 -0
  474. package/dist/node_modules/ssri/lib/index.js +550 -0
  475. package/dist/node_modules/ssri/package.json +66 -0
  476. package/dist/node_modules/tar/dist/commonjs/create.js +82 -0
  477. package/dist/node_modules/tar/dist/commonjs/cwd-error.js +18 -0
  478. package/dist/node_modules/tar/dist/commonjs/extract.js +88 -0
  479. package/dist/node_modules/tar/dist/commonjs/get-write-flag.js +32 -0
  480. package/dist/node_modules/tar/dist/commonjs/header.js +312 -0
  481. package/dist/node_modules/tar/dist/commonjs/index.js +64 -0
  482. package/dist/node_modules/tar/dist/commonjs/index.min.js +4 -0
  483. package/dist/node_modules/tar/dist/commonjs/large-numbers.js +99 -0
  484. package/dist/node_modules/tar/dist/commonjs/list.js +145 -0
  485. package/dist/node_modules/tar/dist/commonjs/make-command.js +52 -0
  486. package/dist/node_modules/tar/dist/commonjs/mkdir.js +187 -0
  487. package/dist/node_modules/tar/dist/commonjs/mode-fix.js +29 -0
  488. package/dist/node_modules/tar/dist/commonjs/normalize-unicode.js +38 -0
  489. package/dist/node_modules/tar/dist/commonjs/normalize-windows-path.js +12 -0
  490. package/dist/node_modules/tar/dist/commonjs/options.js +66 -0
  491. package/dist/node_modules/tar/dist/commonjs/pack.js +511 -0
  492. package/dist/node_modules/tar/dist/commonjs/package.json +3 -0
  493. package/dist/node_modules/tar/dist/commonjs/parse.js +610 -0
  494. package/dist/node_modules/tar/dist/commonjs/path-reservations.js +170 -0
  495. package/dist/node_modules/tar/dist/commonjs/pax.js +158 -0
  496. package/dist/node_modules/tar/dist/commonjs/process-umask.js +7 -0
  497. package/dist/node_modules/tar/dist/commonjs/read-entry.js +136 -0
  498. package/dist/node_modules/tar/dist/commonjs/replace.js +227 -0
  499. package/dist/node_modules/tar/dist/commonjs/strip-absolute-path.js +29 -0
  500. package/dist/node_modules/tar/dist/commonjs/strip-trailing-slashes.js +18 -0
  501. package/dist/node_modules/tar/dist/commonjs/symlink-error.js +19 -0
  502. package/dist/node_modules/tar/dist/commonjs/types.js +50 -0
  503. package/dist/node_modules/tar/dist/commonjs/unpack.js +932 -0
  504. package/dist/node_modules/tar/dist/commonjs/update.js +33 -0
  505. package/dist/node_modules/tar/dist/commonjs/warn-method.js +31 -0
  506. package/dist/node_modules/tar/dist/commonjs/winchars.js +14 -0
  507. package/dist/node_modules/tar/dist/commonjs/write-entry.js +698 -0
  508. package/dist/node_modules/tar/dist/esm/create.js +76 -0
  509. package/dist/node_modules/tar/dist/esm/cwd-error.js +14 -0
  510. package/dist/node_modules/tar/dist/esm/extract.js +49 -0
  511. package/dist/node_modules/tar/dist/esm/get-write-flag.js +26 -0
  512. package/dist/node_modules/tar/dist/esm/header.js +275 -0
  513. package/dist/node_modules/tar/dist/esm/index.js +20 -0
  514. package/dist/node_modules/tar/dist/esm/index.min.js +4 -0
  515. package/dist/node_modules/tar/dist/esm/large-numbers.js +94 -0
  516. package/dist/node_modules/tar/dist/esm/list.js +105 -0
  517. package/dist/node_modules/tar/dist/esm/make-command.js +48 -0
  518. package/dist/node_modules/tar/dist/esm/mkdir.js +179 -0
  519. package/dist/node_modules/tar/dist/esm/mode-fix.js +25 -0
  520. package/dist/node_modules/tar/dist/esm/normalize-unicode.js +34 -0
  521. package/dist/node_modules/tar/dist/esm/normalize-windows-path.js +9 -0
  522. package/dist/node_modules/tar/dist/esm/options.js +54 -0
  523. package/dist/node_modules/tar/dist/esm/pack.js +469 -0
  524. package/dist/node_modules/tar/dist/esm/package.json +3 -0
  525. package/dist/node_modules/tar/dist/esm/parse.js +606 -0
  526. package/dist/node_modules/tar/dist/esm/path-reservations.js +166 -0
  527. package/dist/node_modules/tar/dist/esm/pax.js +154 -0
  528. package/dist/node_modules/tar/dist/esm/process-umask.js +3 -0
  529. package/dist/node_modules/tar/dist/esm/read-entry.js +132 -0
  530. package/dist/node_modules/tar/dist/esm/replace.js +221 -0
  531. package/dist/node_modules/tar/dist/esm/strip-absolute-path.js +25 -0
  532. package/dist/node_modules/tar/dist/esm/strip-trailing-slashes.js +14 -0
  533. package/dist/node_modules/tar/dist/esm/symlink-error.js +15 -0
  534. package/dist/node_modules/tar/dist/esm/types.js +45 -0
  535. package/dist/node_modules/tar/dist/esm/unpack.js +891 -0
  536. package/dist/node_modules/tar/dist/esm/update.js +30 -0
  537. package/dist/node_modules/tar/dist/esm/warn-method.js +27 -0
  538. package/dist/node_modules/tar/dist/esm/winchars.js +9 -0
  539. package/dist/node_modules/tar/dist/esm/write-entry.js +656 -0
  540. package/dist/node_modules/tar/node_modules/yallist/dist/commonjs/index.js +384 -0
  541. package/dist/node_modules/tar/node_modules/yallist/dist/commonjs/package.json +3 -0
  542. package/dist/node_modules/tar/node_modules/yallist/dist/esm/index.js +379 -0
  543. package/dist/node_modules/tar/node_modules/yallist/dist/esm/package.json +3 -0
  544. package/dist/node_modules/tar/node_modules/yallist/package.json +68 -0
  545. package/dist/node_modules/tar/package.json +297 -0
  546. package/dist/node_modules/tinyglobby/LICENSE +21 -0
  547. package/dist/node_modules/tinyglobby/dist/index.cjs +350 -0
  548. package/dist/node_modules/tinyglobby/dist/index.d.cts +147 -0
  549. package/dist/node_modules/tinyglobby/dist/index.d.mts +147 -0
  550. package/dist/node_modules/tinyglobby/dist/index.mjs +318 -0
  551. package/dist/node_modules/tinyglobby/package.json +73 -0
  552. package/{LICENSE → dist/node_modules/v8-compile-cache/LICENSE} +1 -2
  553. package/dist/node_modules/v8-compile-cache/package.json +34 -0
  554. package/dist/node_modules/v8-compile-cache/v8-compile-cache.js +373 -0
  555. package/dist/node_modules/which/LICENSE +15 -0
  556. package/dist/node_modules/which/bin/which.js +52 -0
  557. package/dist/node_modules/which/lib/index.js +111 -0
  558. package/dist/node_modules/which/package.json +52 -0
  559. package/dist/node_modules/yallist/LICENSE +15 -0
  560. package/dist/node_modules/yallist/iterator.js +8 -0
  561. package/dist/node_modules/yallist/package.json +29 -0
  562. package/dist/node_modules/yallist/yallist.js +426 -0
  563. package/dist/pnpm.mjs +266382 -0
  564. package/dist/pnpmrc +2 -0
  565. package/dist/templates/completion.bash +31 -0
  566. package/dist/templates/completion.fish +22 -0
  567. package/dist/templates/completion.ps1 +193 -0
  568. package/dist/templates/completion.zsh +27 -0
  569. package/dist/vendor/fastlist-0.3.0-x64.exe +0 -0
  570. package/dist/vendor/fastlist-0.3.0-x86.exe +0 -0
  571. package/dist/worker.js +10958 -0
  572. package/package.json +34 -12
  573. package/pn +2 -0
  574. package/pn.cmd +2 -0
  575. package/pn.ps1 +1 -0
  576. package/pnpx +2 -0
  577. package/pnpx.cmd +2 -0
  578. package/pnpx.ps1 +1 -0
  579. package/pnx +2 -0
  580. package/pnx.cmd +2 -0
  581. package/pnx.ps1 +1 -0
  582. package/prepare.js +26 -3
  583. package/setup.js +22 -11
  584. package/CHANGELOG.md +0 -15
@@ -0,0 +1,2956 @@
1
+ # Copyright (c) 2013 Google Inc. All rights reserved.
2
+ # Use of this source code is governed by a BSD-style license that can be
3
+ # found in the LICENSE file.
4
+
5
+
6
+ import collections
7
+ import copy
8
+ import ctypes
9
+ import hashlib
10
+ import json
11
+ import multiprocessing
12
+ import os.path
13
+ import re
14
+ import shutil
15
+ import signal
16
+ import subprocess
17
+ import sys
18
+ from io import StringIO
19
+
20
+ import gyp
21
+ import gyp.common
22
+ import gyp.msvs_emulation
23
+ import gyp.xcode_emulation
24
+ from gyp import MSVSUtil, ninja_syntax
25
+ from gyp.common import GetEnvironFallback
26
+
27
+ generator_default_variables = {
28
+ "EXECUTABLE_PREFIX": "",
29
+ "EXECUTABLE_SUFFIX": "",
30
+ "STATIC_LIB_PREFIX": "lib",
31
+ "STATIC_LIB_SUFFIX": ".a",
32
+ "SHARED_LIB_PREFIX": "lib",
33
+ # Gyp expects the following variables to be expandable by the build
34
+ # system to the appropriate locations. Ninja prefers paths to be
35
+ # known at gyp time. To resolve this, introduce special
36
+ # variables starting with $! and $| (which begin with a $ so gyp knows it
37
+ # should be treated specially, but is otherwise an invalid
38
+ # ninja/shell variable) that are passed to gyp here but expanded
39
+ # before writing out into the target .ninja files; see
40
+ # ExpandSpecial.
41
+ # $! is used for variables that represent a path and that can only appear at
42
+ # the start of a string, while $| is used for variables that can appear
43
+ # anywhere in a string.
44
+ "INTERMEDIATE_DIR": "$!INTERMEDIATE_DIR",
45
+ "SHARED_INTERMEDIATE_DIR": "$!PRODUCT_DIR/gen",
46
+ "PRODUCT_DIR": "$!PRODUCT_DIR",
47
+ "CONFIGURATION_NAME": "$|CONFIGURATION_NAME",
48
+ # Special variables that may be used by gyp 'rule' targets.
49
+ # We generate definitions for these variables on the fly when processing a
50
+ # rule.
51
+ "RULE_INPUT_ROOT": "${root}",
52
+ "RULE_INPUT_DIRNAME": "${dirname}",
53
+ "RULE_INPUT_PATH": "${source}",
54
+ "RULE_INPUT_EXT": "${ext}",
55
+ "RULE_INPUT_NAME": "${name}",
56
+ }
57
+
58
+ # Placates pylint.
59
+ generator_additional_non_configuration_keys = []
60
+ generator_additional_path_sections = []
61
+ generator_extra_sources_for_rules = []
62
+ generator_filelist_paths = None
63
+
64
+ generator_supports_multiple_toolsets = gyp.common.CrossCompileRequested()
65
+
66
+
67
+ def StripPrefix(arg, prefix):
68
+ if arg.startswith(prefix):
69
+ return arg[len(prefix) :]
70
+ return arg
71
+
72
+
73
+ def QuoteShellArgument(arg, flavor):
74
+ """Quote a string such that it will be interpreted as a single argument
75
+ by the shell."""
76
+ # Rather than attempting to enumerate the bad shell characters, just
77
+ # allow common OK ones and quote anything else.
78
+ if re.match(r"^[a-zA-Z0-9_=.\\/-]+$", arg):
79
+ return arg # No quoting necessary.
80
+ if flavor == "win":
81
+ return gyp.msvs_emulation.QuoteForRspFile(arg)
82
+ return "'" + arg.replace("'", "'" + '"\'"' + "'") + "'"
83
+
84
+
85
+ def Define(d, flavor):
86
+ """Takes a preprocessor define and returns a -D parameter that's ninja- and
87
+ shell-escaped."""
88
+ if flavor == "win":
89
+ # cl.exe replaces literal # characters with = in preprocessor definitions for
90
+ # some reason. Octal-encode to work around that.
91
+ d = d.replace("#", "\\%03o" % ord("#"))
92
+ return QuoteShellArgument(ninja_syntax.escape("-D" + d), flavor)
93
+
94
+
95
+ def AddArch(output, arch):
96
+ """Adds an arch string to an output path."""
97
+ output, extension = os.path.splitext(output)
98
+ return f"{output}.{arch}{extension}"
99
+
100
+
101
+ class Target:
102
+ """Target represents the paths used within a single gyp target.
103
+
104
+ Conceptually, building a single target A is a series of steps:
105
+
106
+ 1) actions/rules/copies generates source/resources/etc.
107
+ 2) compiles generates .o files
108
+ 3) link generates a binary (library/executable)
109
+ 4) bundle merges the above in a mac bundle
110
+
111
+ (Any of these steps can be optional.)
112
+
113
+ From a build ordering perspective, a dependent target B could just
114
+ depend on the last output of this series of steps.
115
+
116
+ But some dependent commands sometimes need to reach inside the box.
117
+ For example, when linking B it needs to get the path to the static
118
+ library generated by A.
119
+
120
+ This object stores those paths. To keep things simple, member
121
+ variables only store concrete paths to single files, while methods
122
+ compute derived values like "the last output of the target".
123
+ """
124
+
125
+ def __init__(self, type):
126
+ # Gyp type ("static_library", etc.) of this target.
127
+ self.type = type
128
+ # File representing whether any input dependencies necessary for
129
+ # dependent actions have completed.
130
+ self.preaction_stamp = None
131
+ # File representing whether any input dependencies necessary for
132
+ # dependent compiles have completed.
133
+ self.precompile_stamp = None
134
+ # File representing the completion of actions/rules/copies, if any.
135
+ self.actions_stamp = None
136
+ # Path to the output of the link step, if any.
137
+ self.binary = None
138
+ # Path to the file representing the completion of building the bundle,
139
+ # if any.
140
+ self.bundle = None
141
+ # On Windows, incremental linking requires linking against all the .objs
142
+ # that compose a .lib (rather than the .lib itself). That list is stored
143
+ # here. In this case, we also need to save the compile_deps for the target,
144
+ # so that the target that directly depends on the .objs can also depend
145
+ # on those.
146
+ self.component_objs = None
147
+ self.compile_deps = None
148
+ # Windows only. The import .lib is the output of a build step, but
149
+ # because dependents only link against the lib (not both the lib and the
150
+ # dll) we keep track of the import library here.
151
+ self.import_lib = None
152
+ # Track if this target contains any C++ files, to decide if gcc or g++
153
+ # should be used for linking.
154
+ self.uses_cpp = False
155
+
156
+ def Linkable(self):
157
+ """Return true if this is a target that can be linked against."""
158
+ return self.type in ("static_library", "shared_library")
159
+
160
+ def UsesToc(self, flavor):
161
+ """Return true if the target should produce a restat rule based on a TOC
162
+ file."""
163
+ # For bundles, the .TOC should be produced for the binary, not for
164
+ # FinalOutput(). But the naive approach would put the TOC file into the
165
+ # bundle, so don't do this for bundles for now.
166
+ if flavor == "win" or self.bundle:
167
+ return False
168
+ return self.type in ("shared_library", "loadable_module")
169
+
170
+ def PreActionInput(self, flavor):
171
+ """Return the path, if any, that should be used as a dependency of
172
+ any dependent action step."""
173
+ if self.UsesToc(flavor):
174
+ return self.FinalOutput() + ".TOC"
175
+ return self.FinalOutput() or self.preaction_stamp
176
+
177
+ def PreCompileInput(self):
178
+ """Return the path, if any, that should be used as a dependency of
179
+ any dependent compile step."""
180
+ return self.actions_stamp or self.precompile_stamp
181
+
182
+ def FinalOutput(self):
183
+ """Return the last output of the target, which depends on all prior
184
+ steps."""
185
+ return self.bundle or self.binary or self.actions_stamp
186
+
187
+
188
+ # A small discourse on paths as used within the Ninja build:
189
+ # All files we produce (both at gyp and at build time) appear in the
190
+ # build directory (e.g. out/Debug).
191
+ #
192
+ # Paths within a given .gyp file are always relative to the directory
193
+ # containing the .gyp file. Call these "gyp paths". This includes
194
+ # sources as well as the starting directory a given gyp rule/action
195
+ # expects to be run from. We call the path from the source root to
196
+ # the gyp file the "base directory" within the per-.gyp-file
197
+ # NinjaWriter code.
198
+ #
199
+ # All paths as written into the .ninja files are relative to the build
200
+ # directory. Call these paths "ninja paths".
201
+ #
202
+ # We translate between these two notions of paths with two helper
203
+ # functions:
204
+ #
205
+ # - GypPathToNinja translates a gyp path (i.e. relative to the .gyp file)
206
+ # into the equivalent ninja path.
207
+ #
208
+ # - GypPathToUniqueOutput translates a gyp path into a ninja path to write
209
+ # an output file; the result can be namespaced such that it is unique
210
+ # to the input file name as well as the output target name.
211
+
212
+
213
+ class NinjaWriter:
214
+ def __init__(
215
+ self,
216
+ hash_for_rules,
217
+ target_outputs,
218
+ base_dir,
219
+ build_dir,
220
+ output_file,
221
+ toplevel_build,
222
+ output_file_name,
223
+ flavor,
224
+ toplevel_dir=None,
225
+ ):
226
+ """
227
+ base_dir: path from source root to directory containing this gyp file,
228
+ by gyp semantics, all input paths are relative to this
229
+ build_dir: path from source root to build output
230
+ toplevel_dir: path to the toplevel directory
231
+ """
232
+
233
+ self.hash_for_rules = hash_for_rules
234
+ self.target_outputs = target_outputs
235
+ self.base_dir = base_dir
236
+ self.build_dir = build_dir
237
+ self.ninja = ninja_syntax.Writer(output_file)
238
+ self.toplevel_build = toplevel_build
239
+ self.output_file_name = output_file_name
240
+
241
+ self.flavor = flavor
242
+ self.abs_build_dir = None
243
+ if toplevel_dir is not None:
244
+ self.abs_build_dir = os.path.abspath(os.path.join(toplevel_dir, build_dir))
245
+ self.obj_ext = ".obj" if flavor == "win" else ".o"
246
+ if flavor == "win":
247
+ # See docstring of msvs_emulation.GenerateEnvironmentFiles().
248
+ self.win_env = {}
249
+ for arch in ("x86", "x64"):
250
+ self.win_env[arch] = "environment." + arch
251
+
252
+ # Relative path from build output dir to base dir.
253
+ build_to_top = gyp.common.InvertRelativePath(build_dir, toplevel_dir)
254
+ self.build_to_base = os.path.join(build_to_top, base_dir)
255
+ # Relative path from base dir to build dir.
256
+ base_to_top = gyp.common.InvertRelativePath(base_dir, toplevel_dir)
257
+ self.base_to_build = os.path.join(base_to_top, build_dir)
258
+
259
+ def ExpandSpecial(self, path, product_dir=None):
260
+ """Expand specials like $!PRODUCT_DIR in |path|.
261
+
262
+ If |product_dir| is None, assumes the cwd is already the product
263
+ dir. Otherwise, |product_dir| is the relative path to the product
264
+ dir.
265
+ """
266
+
267
+ if (PRODUCT_DIR := "$!PRODUCT_DIR") in path:
268
+ if product_dir:
269
+ path = path.replace(PRODUCT_DIR, product_dir)
270
+ else:
271
+ path = path.replace(PRODUCT_DIR + "/", "")
272
+ path = path.replace(PRODUCT_DIR + "\\", "")
273
+ path = path.replace(PRODUCT_DIR, ".")
274
+
275
+ if (INTERMEDIATE_DIR := "$!INTERMEDIATE_DIR") in path:
276
+ int_dir = self.GypPathToUniqueOutput("gen")
277
+ # GypPathToUniqueOutput generates a path relative to the product dir,
278
+ # so insert product_dir in front if it is provided.
279
+ path = path.replace(
280
+ INTERMEDIATE_DIR, os.path.join(product_dir or "", int_dir)
281
+ )
282
+
283
+ CONFIGURATION_NAME = "$|CONFIGURATION_NAME"
284
+ path = path.replace(CONFIGURATION_NAME, self.config_name)
285
+
286
+ return path
287
+
288
+ def ExpandRuleVariables(self, path, root, dirname, source, ext, name):
289
+ if self.flavor == "win":
290
+ path = self.msvs_settings.ConvertVSMacros(path, config=self.config_name)
291
+ path = path.replace(generator_default_variables["RULE_INPUT_ROOT"], root)
292
+ path = path.replace(generator_default_variables["RULE_INPUT_DIRNAME"], dirname)
293
+ path = path.replace(generator_default_variables["RULE_INPUT_PATH"], source)
294
+ path = path.replace(generator_default_variables["RULE_INPUT_EXT"], ext)
295
+ path = path.replace(generator_default_variables["RULE_INPUT_NAME"], name)
296
+ return path
297
+
298
+ def GypPathToNinja(self, path, env=None):
299
+ """Translate a gyp path to a ninja path, optionally expanding environment
300
+ variable references in |path| with |env|.
301
+
302
+ See the above discourse on path conversions."""
303
+ if env:
304
+ if self.flavor == "mac":
305
+ path = gyp.xcode_emulation.ExpandEnvVars(path, env)
306
+ elif self.flavor == "win":
307
+ path = gyp.msvs_emulation.ExpandMacros(path, env)
308
+ if path.startswith("$!"):
309
+ expanded = self.ExpandSpecial(path)
310
+ if self.flavor == "win":
311
+ expanded = os.path.normpath(expanded)
312
+ return expanded
313
+ if "$|" in path:
314
+ path = self.ExpandSpecial(path)
315
+ assert "$" not in path, path
316
+ return os.path.normpath(os.path.join(self.build_to_base, path))
317
+
318
+ def GypPathToUniqueOutput(self, path, qualified=True):
319
+ """Translate a gyp path to a ninja path for writing output.
320
+
321
+ If qualified is True, qualify the resulting filename with the name
322
+ of the target. This is necessary when e.g. compiling the same
323
+ path twice for two separate output targets.
324
+
325
+ See the above discourse on path conversions."""
326
+
327
+ path = self.ExpandSpecial(path)
328
+ assert not path.startswith("$"), path
329
+
330
+ # Translate the path following this scheme:
331
+ # Input: foo/bar.gyp, target targ, references baz/out.o
332
+ # Output: obj/foo/baz/targ.out.o (if qualified)
333
+ # obj/foo/baz/out.o (otherwise)
334
+ # (and obj.host instead of obj for cross-compiles)
335
+ #
336
+ # Why this scheme and not some other one?
337
+ # 1) for a given input, you can compute all derived outputs by matching
338
+ # its path, even if the input is brought via a gyp file with '..'.
339
+ # 2) simple files like libraries and stamps have a simple filename.
340
+
341
+ obj = "obj"
342
+ if self.toolset != "target":
343
+ obj += "." + self.toolset
344
+
345
+ path_dir, path_basename = os.path.split(path)
346
+ assert not os.path.isabs(path_dir), (
347
+ "'%s' can not be absolute path (see crbug.com/462153)." % path_dir
348
+ )
349
+
350
+ if qualified:
351
+ path_basename = self.name + "." + path_basename
352
+ return os.path.normpath(
353
+ os.path.join(obj, self.base_dir, path_dir, path_basename)
354
+ )
355
+
356
+ def WriteCollapsedDependencies(self, name, targets, order_only=None):
357
+ """Given a list of targets, return a path for a single file
358
+ representing the result of building all the targets or None.
359
+
360
+ Uses a stamp file if necessary."""
361
+
362
+ assert targets == [item for item in targets if item], targets
363
+ if len(targets) == 0:
364
+ assert not order_only
365
+ return None
366
+ if len(targets) > 1 or order_only:
367
+ stamp = self.GypPathToUniqueOutput(name + ".stamp")
368
+ targets = self.ninja.build(stamp, "stamp", targets, order_only=order_only)
369
+ self.ninja.newline()
370
+ return targets[0]
371
+
372
+ def _SubninjaNameForArch(self, arch):
373
+ output_file_base = os.path.splitext(self.output_file_name)[0]
374
+ return f"{output_file_base}.{arch}.ninja"
375
+
376
+ def WriteSpec(self, spec, config_name, generator_flags):
377
+ """The main entry point for NinjaWriter: write the build rules for a spec.
378
+
379
+ Returns a Target object, which represents the output paths for this spec.
380
+ Returns None if there are no outputs (e.g. a settings-only 'none' type
381
+ target)."""
382
+
383
+ self.config_name = config_name
384
+ self.name = spec["target_name"]
385
+ self.toolset = spec["toolset"]
386
+ config = spec["configurations"][config_name]
387
+ self.target = Target(spec["type"])
388
+ self.is_standalone_static_library = bool(
389
+ spec.get("standalone_static_library", 0)
390
+ )
391
+
392
+ self.target_rpath = generator_flags.get("target_rpath", r"\$$ORIGIN/lib/")
393
+
394
+ self.is_mac_bundle = gyp.xcode_emulation.IsMacBundle(self.flavor, spec)
395
+ self.xcode_settings = self.msvs_settings = None
396
+ if self.flavor == "mac":
397
+ self.xcode_settings = gyp.xcode_emulation.XcodeSettings(spec)
398
+ mac_toolchain_dir = generator_flags.get("mac_toolchain_dir", None)
399
+ if mac_toolchain_dir:
400
+ self.xcode_settings.mac_toolchain_dir = mac_toolchain_dir
401
+
402
+ if self.flavor == "win":
403
+ self.msvs_settings = gyp.msvs_emulation.MsvsSettings(spec, generator_flags)
404
+ arch = self.msvs_settings.GetArch(config_name)
405
+ self.ninja.variable("arch", self.win_env[arch])
406
+ self.ninja.variable("cc", "$cl_" + arch)
407
+ self.ninja.variable("cxx", "$cl_" + arch)
408
+ self.ninja.variable("cc_host", "$cl_" + arch)
409
+ self.ninja.variable("cxx_host", "$cl_" + arch)
410
+ self.ninja.variable("asm", "$ml_" + arch)
411
+
412
+ if self.flavor == "mac":
413
+ self.archs = self.xcode_settings.GetActiveArchs(config_name)
414
+ if len(self.archs) > 1:
415
+ self.arch_subninjas = {
416
+ arch: ninja_syntax.Writer(
417
+ OpenOutput(
418
+ os.path.join(
419
+ self.toplevel_build, self._SubninjaNameForArch(arch)
420
+ ),
421
+ "w",
422
+ )
423
+ )
424
+ for arch in self.archs
425
+ }
426
+
427
+ # Compute predepends for all rules.
428
+ # actions_depends is the dependencies this target depends on before running
429
+ # any of its action/rule/copy steps.
430
+ # compile_depends is the dependencies this target depends on before running
431
+ # any of its compile steps.
432
+ actions_depends = []
433
+ compile_depends = []
434
+ # TODO(evan): it is rather confusing which things are lists and which
435
+ # are strings. Fix these.
436
+ if "dependencies" in spec:
437
+ for dep in spec["dependencies"]:
438
+ if dep in self.target_outputs:
439
+ target = self.target_outputs[dep]
440
+ actions_depends.append(target.PreActionInput(self.flavor))
441
+ compile_depends.append(target.PreCompileInput())
442
+ if target.uses_cpp:
443
+ self.target.uses_cpp = True
444
+ actions_depends = [item for item in actions_depends if item]
445
+ compile_depends = [item for item in compile_depends if item]
446
+ actions_depends = self.WriteCollapsedDependencies(
447
+ "actions_depends", actions_depends
448
+ )
449
+ compile_depends = self.WriteCollapsedDependencies(
450
+ "compile_depends", compile_depends
451
+ )
452
+ self.target.preaction_stamp = actions_depends
453
+ self.target.precompile_stamp = compile_depends
454
+
455
+ # Write out actions, rules, and copies. These must happen before we
456
+ # compile any sources, so compute a list of predependencies for sources
457
+ # while we do it.
458
+ extra_sources = []
459
+ mac_bundle_depends = []
460
+ self.target.actions_stamp = self.WriteActionsRulesCopies(
461
+ spec, extra_sources, actions_depends, mac_bundle_depends
462
+ )
463
+
464
+ # If we have actions/rules/copies, we depend directly on those, but
465
+ # otherwise we depend on dependent target's actions/rules/copies etc.
466
+ # We never need to explicitly depend on previous target's link steps,
467
+ # because no compile ever depends on them.
468
+ compile_depends_stamp = self.target.actions_stamp or compile_depends
469
+
470
+ # Write out the compilation steps, if any.
471
+ link_deps = []
472
+ try:
473
+ sources = extra_sources + spec.get("sources", [])
474
+ except TypeError:
475
+ print("extra_sources: ", str(extra_sources))
476
+ print('spec.get("sources"): ', str(spec.get("sources")))
477
+ raise
478
+ if sources:
479
+ if self.flavor == "mac" and len(self.archs) > 1:
480
+ # Write subninja file containing compile and link commands scoped to
481
+ # a single arch if a fat binary is being built.
482
+ for arch in self.archs:
483
+ self.ninja.subninja(self._SubninjaNameForArch(arch))
484
+
485
+ pch = None
486
+ if self.flavor == "win":
487
+ gyp.msvs_emulation.VerifyMissingSources(
488
+ sources, self.abs_build_dir, generator_flags, self.GypPathToNinja
489
+ )
490
+ pch = gyp.msvs_emulation.PrecompiledHeader(
491
+ self.msvs_settings,
492
+ config_name,
493
+ self.GypPathToNinja,
494
+ self.GypPathToUniqueOutput,
495
+ self.obj_ext,
496
+ )
497
+ else:
498
+ pch = gyp.xcode_emulation.MacPrefixHeader(
499
+ self.xcode_settings,
500
+ self.GypPathToNinja,
501
+ lambda path, lang: self.GypPathToUniqueOutput(path + "-" + lang),
502
+ )
503
+ link_deps = self.WriteSources(
504
+ self.ninja,
505
+ config_name,
506
+ config,
507
+ sources,
508
+ compile_depends_stamp,
509
+ pch,
510
+ spec,
511
+ )
512
+ # Some actions/rules output 'sources' that are already object files.
513
+ obj_outputs = [f for f in sources if f.endswith(self.obj_ext)]
514
+ if obj_outputs:
515
+ if self.flavor != "mac" or len(self.archs) == 1:
516
+ link_deps += [self.GypPathToNinja(o) for o in obj_outputs]
517
+ else:
518
+ print(
519
+ "Warning: Actions/rules writing object files don't work with "
520
+ "multiarch targets, dropping. (target %s)" % spec["target_name"]
521
+ )
522
+ elif self.flavor == "mac" and len(self.archs) > 1:
523
+ link_deps = collections.defaultdict(list)
524
+
525
+ compile_deps = self.target.actions_stamp or actions_depends
526
+ if self.flavor == "win" and self.target.type == "static_library":
527
+ self.target.component_objs = link_deps
528
+ self.target.compile_deps = compile_deps
529
+
530
+ # Write out a link step, if needed.
531
+ output = None
532
+ is_empty_bundle = not link_deps and not mac_bundle_depends
533
+ if link_deps or self.target.actions_stamp or actions_depends:
534
+ output = self.WriteTarget(
535
+ spec, config_name, config, link_deps, compile_deps
536
+ )
537
+ if self.is_mac_bundle:
538
+ mac_bundle_depends.append(output)
539
+
540
+ # Bundle all of the above together, if needed.
541
+ if self.is_mac_bundle:
542
+ output = self.WriteMacBundle(spec, mac_bundle_depends, is_empty_bundle)
543
+
544
+ if not output:
545
+ return None
546
+
547
+ assert self.target.FinalOutput(), output
548
+ return self.target
549
+
550
+ def _WinIdlRule(self, source, prebuild, outputs):
551
+ """Handle the implicit VS .idl rule for one source file. Fills |outputs|
552
+ with files that are generated."""
553
+ outdir, output, vars, flags = self.msvs_settings.GetIdlBuildData(
554
+ source, self.config_name
555
+ )
556
+ outdir = self.GypPathToNinja(outdir)
557
+
558
+ def fix_path(path, rel=None):
559
+ path = os.path.join(outdir, path)
560
+ dirname, basename = os.path.split(source)
561
+ root, ext = os.path.splitext(basename)
562
+ path = self.ExpandRuleVariables(path, root, dirname, source, ext, basename)
563
+ if rel:
564
+ path = os.path.relpath(path, rel)
565
+ return path
566
+
567
+ vars = [(name, fix_path(value, outdir)) for name, value in vars]
568
+ output = [fix_path(p) for p in output]
569
+ vars.append(("outdir", outdir))
570
+ vars.append(("idlflags", flags))
571
+ input = self.GypPathToNinja(source)
572
+ self.ninja.build(output, "idl", input, variables=vars, order_only=prebuild)
573
+ outputs.extend(output)
574
+
575
+ def WriteWinIdlFiles(self, spec, prebuild):
576
+ """Writes rules to match MSVS's implicit idl handling."""
577
+ assert self.flavor == "win"
578
+ if self.msvs_settings.HasExplicitIdlRulesOrActions(spec):
579
+ return []
580
+ outputs = []
581
+ for source in filter(lambda x: x.endswith(".idl"), spec["sources"]):
582
+ self._WinIdlRule(source, prebuild, outputs)
583
+ return outputs
584
+
585
+ def WriteActionsRulesCopies(
586
+ self, spec, extra_sources, prebuild, mac_bundle_depends
587
+ ):
588
+ """Write out the Actions, Rules, and Copies steps. Return a path
589
+ representing the outputs of these steps."""
590
+ outputs = []
591
+ if self.is_mac_bundle:
592
+ mac_bundle_resources = spec.get("mac_bundle_resources", [])[:]
593
+ else:
594
+ mac_bundle_resources = []
595
+ extra_mac_bundle_resources = []
596
+
597
+ if "actions" in spec:
598
+ outputs += self.WriteActions(
599
+ spec["actions"], extra_sources, prebuild, extra_mac_bundle_resources
600
+ )
601
+ if "rules" in spec:
602
+ outputs += self.WriteRules(
603
+ spec["rules"],
604
+ extra_sources,
605
+ prebuild,
606
+ mac_bundle_resources,
607
+ extra_mac_bundle_resources,
608
+ )
609
+ if "copies" in spec:
610
+ outputs += self.WriteCopies(spec["copies"], prebuild, mac_bundle_depends)
611
+
612
+ if "sources" in spec and self.flavor == "win":
613
+ outputs += self.WriteWinIdlFiles(spec, prebuild)
614
+
615
+ if self.xcode_settings and self.xcode_settings.IsIosFramework():
616
+ self.WriteiOSFrameworkHeaders(spec, outputs, prebuild)
617
+
618
+ stamp = self.WriteCollapsedDependencies("actions_rules_copies", outputs)
619
+
620
+ if self.is_mac_bundle:
621
+ xcassets = self.WriteMacBundleResources(
622
+ extra_mac_bundle_resources + mac_bundle_resources, mac_bundle_depends
623
+ )
624
+ partial_info_plist = self.WriteMacXCassets(xcassets, mac_bundle_depends)
625
+ self.WriteMacInfoPlist(partial_info_plist, mac_bundle_depends)
626
+
627
+ return stamp
628
+
629
+ def GenerateDescription(self, verb, message, fallback):
630
+ """Generate and return a description of a build step.
631
+
632
+ |verb| is the short summary, e.g. ACTION or RULE.
633
+ |message| is a hand-written description, or None if not available.
634
+ |fallback| is the gyp-level name of the step, usable as a fallback.
635
+ """
636
+ if self.toolset != "target":
637
+ verb += "(%s)" % self.toolset
638
+ if message:
639
+ return f"{verb} {self.ExpandSpecial(message)}"
640
+ else:
641
+ return f"{verb} {self.name}: {fallback}"
642
+
643
+ def WriteActions(
644
+ self, actions, extra_sources, prebuild, extra_mac_bundle_resources
645
+ ):
646
+ # Actions cd into the base directory.
647
+ env = self.GetToolchainEnv()
648
+ all_outputs = []
649
+ for action in actions:
650
+ # First write out a rule for the action.
651
+ name = "{}_{}".format(action["action_name"], self.hash_for_rules)
652
+ description = self.GenerateDescription(
653
+ "ACTION", action.get("message", None), name
654
+ )
655
+ win_shell_flags = (
656
+ self.msvs_settings.GetRuleShellFlags(action)
657
+ if self.flavor == "win"
658
+ else None
659
+ )
660
+ args = action["action"]
661
+ depfile = action.get("depfile", None)
662
+ if depfile:
663
+ depfile = self.ExpandSpecial(depfile, self.base_to_build)
664
+ pool = "console" if int(action.get("ninja_use_console", 0)) else None
665
+ rule_name, _ = self.WriteNewNinjaRule(
666
+ name, args, description, win_shell_flags, env, pool, depfile=depfile
667
+ )
668
+
669
+ inputs = [self.GypPathToNinja(i, env) for i in action["inputs"]]
670
+ if int(action.get("process_outputs_as_sources", False)):
671
+ extra_sources += action["outputs"]
672
+ if int(action.get("process_outputs_as_mac_bundle_resources", False)):
673
+ extra_mac_bundle_resources += action["outputs"]
674
+ outputs = [self.GypPathToNinja(o, env) for o in action["outputs"]]
675
+
676
+ # Then write out an edge using the rule.
677
+ self.ninja.build(outputs, rule_name, inputs, order_only=prebuild)
678
+ all_outputs += outputs
679
+
680
+ self.ninja.newline()
681
+
682
+ return all_outputs
683
+
684
+ def WriteRules(
685
+ self,
686
+ rules,
687
+ extra_sources,
688
+ prebuild,
689
+ mac_bundle_resources,
690
+ extra_mac_bundle_resources,
691
+ ):
692
+ env = self.GetToolchainEnv()
693
+ all_outputs = []
694
+ for rule in rules:
695
+ # Skip a rule with no action and no inputs.
696
+ if "action" not in rule and not rule.get("rule_sources", []):
697
+ continue
698
+
699
+ # First write out a rule for the rule action.
700
+ name = "{}_{}".format(rule["rule_name"], self.hash_for_rules)
701
+
702
+ args = rule["action"]
703
+ description = self.GenerateDescription(
704
+ "RULE",
705
+ rule.get("message", None),
706
+ ("%s " + generator_default_variables["RULE_INPUT_PATH"]) % name,
707
+ )
708
+ win_shell_flags = (
709
+ self.msvs_settings.GetRuleShellFlags(rule)
710
+ if self.flavor == "win"
711
+ else None
712
+ )
713
+ pool = "console" if int(rule.get("ninja_use_console", 0)) else None
714
+ rule_name, args = self.WriteNewNinjaRule(
715
+ name, args, description, win_shell_flags, env, pool
716
+ )
717
+
718
+ # TODO: if the command references the outputs directly, we should
719
+ # simplify it to just use $out.
720
+
721
+ # Rules can potentially make use of some special variables which
722
+ # must vary per source file.
723
+ # Compute the list of variables we'll need to provide.
724
+ special_locals = ("source", "root", "dirname", "ext", "name")
725
+ needed_variables = {"source"}
726
+ for argument in args:
727
+ for var in special_locals:
728
+ if "${%s}" % var in argument:
729
+ needed_variables.add(var)
730
+ needed_variables = sorted(needed_variables)
731
+
732
+ def cygwin_munge(path):
733
+ # pylint: disable=cell-var-from-loop
734
+ if win_shell_flags and win_shell_flags.cygwin:
735
+ return path.replace("\\", "/")
736
+ return path
737
+
738
+ inputs = [self.GypPathToNinja(i, env) for i in rule.get("inputs", [])]
739
+
740
+ # If there are n source files matching the rule, and m additional rule
741
+ # inputs, then adding 'inputs' to each build edge written below will
742
+ # write m * n inputs. Collapsing reduces this to m + n.
743
+ sources = rule.get("rule_sources", [])
744
+ num_inputs = len(inputs)
745
+ if prebuild:
746
+ num_inputs += 1
747
+ if num_inputs > 2 and len(sources) > 2:
748
+ inputs = [
749
+ self.WriteCollapsedDependencies(
750
+ rule["rule_name"], inputs, order_only=prebuild
751
+ )
752
+ ]
753
+ prebuild = []
754
+
755
+ # For each source file, write an edge that generates all the outputs.
756
+ for source in sources:
757
+ source = os.path.normpath(source)
758
+ dirname, basename = os.path.split(source)
759
+ root, ext = os.path.splitext(basename)
760
+
761
+ # Gather the list of inputs and outputs, expanding $vars if possible.
762
+ outputs = [
763
+ self.ExpandRuleVariables(o, root, dirname, source, ext, basename)
764
+ for o in rule["outputs"]
765
+ ]
766
+
767
+ if int(rule.get("process_outputs_as_sources", False)):
768
+ extra_sources += outputs
769
+
770
+ was_mac_bundle_resource = source in mac_bundle_resources
771
+ if was_mac_bundle_resource or int(
772
+ rule.get("process_outputs_as_mac_bundle_resources", False)
773
+ ):
774
+ extra_mac_bundle_resources += outputs
775
+ # Note: This is n_resources * n_outputs_in_rule.
776
+ # Put to-be-removed items in a set and
777
+ # remove them all in a single pass
778
+ # if this becomes a performance issue.
779
+ if was_mac_bundle_resource:
780
+ mac_bundle_resources.remove(source)
781
+
782
+ extra_bindings = []
783
+ for var in needed_variables:
784
+ if var == "root":
785
+ extra_bindings.append(("root", cygwin_munge(root)))
786
+ elif var == "dirname":
787
+ # '$dirname' is a parameter to the rule action, which means
788
+ # it shouldn't be converted to a Ninja path. But we don't
789
+ # want $!PRODUCT_DIR in there either.
790
+ dirname_expanded = self.ExpandSpecial(
791
+ dirname, self.base_to_build
792
+ )
793
+ extra_bindings.append(
794
+ ("dirname", cygwin_munge(dirname_expanded))
795
+ )
796
+ elif var == "source":
797
+ # '$source' is a parameter to the rule action, which means
798
+ # it shouldn't be converted to a Ninja path. But we don't
799
+ # want $!PRODUCT_DIR in there either.
800
+ source_expanded = self.ExpandSpecial(source, self.base_to_build)
801
+ extra_bindings.append(("source", cygwin_munge(source_expanded)))
802
+ elif var == "ext":
803
+ extra_bindings.append(("ext", ext))
804
+ elif var == "name":
805
+ extra_bindings.append(("name", cygwin_munge(basename)))
806
+ else:
807
+ assert var is None, repr(var)
808
+
809
+ outputs = [self.GypPathToNinja(o, env) for o in outputs]
810
+ if self.flavor == "win":
811
+ # WriteNewNinjaRule uses unique_name to create a rsp file on win.
812
+ unique_name = hashlib.sha256(outputs[0].encode("utf-8")).hexdigest()
813
+ extra_bindings.append(("unique_name", unique_name))
814
+
815
+ self.ninja.build(
816
+ outputs,
817
+ rule_name,
818
+ self.GypPathToNinja(source),
819
+ implicit=inputs,
820
+ order_only=prebuild,
821
+ variables=extra_bindings,
822
+ )
823
+
824
+ all_outputs.extend(outputs)
825
+
826
+ return all_outputs
827
+
828
+ def WriteCopies(self, copies, prebuild, mac_bundle_depends):
829
+ outputs = []
830
+ if self.xcode_settings:
831
+ extra_env = self.xcode_settings.GetPerTargetSettings()
832
+ env = self.GetToolchainEnv(additional_settings=extra_env)
833
+ else:
834
+ env = self.GetToolchainEnv()
835
+ for to_copy in copies:
836
+ for path in to_copy["files"]:
837
+ # Normalize the path so trailing slashes don't confuse us.
838
+ path = os.path.normpath(path)
839
+ basename = os.path.split(path)[1]
840
+ src = self.GypPathToNinja(path, env)
841
+ dst = self.GypPathToNinja(
842
+ os.path.join(to_copy["destination"], basename), env
843
+ )
844
+ outputs += self.ninja.build(dst, "copy", src, order_only=prebuild)
845
+ if self.is_mac_bundle:
846
+ # gyp has mac_bundle_resources to copy things into a bundle's
847
+ # Resources folder, but there's no built-in way to copy files
848
+ # to other places in the bundle.
849
+ # Hence, some targets use copies for this.
850
+ # Check if this file is copied into the current bundle,
851
+ # and if so add it to the bundle depends so
852
+ # that dependent targets get rebuilt if the copy input changes.
853
+ if dst.startswith(
854
+ self.xcode_settings.GetBundleContentsFolderPath()
855
+ ):
856
+ mac_bundle_depends.append(dst)
857
+
858
+ return outputs
859
+
860
+ def WriteiOSFrameworkHeaders(self, spec, outputs, prebuild):
861
+ """Prebuild steps to generate hmap files and copy headers to destination."""
862
+ framework = self.ComputeMacBundleOutput()
863
+ all_sources = spec["sources"]
864
+ copy_headers = spec["mac_framework_headers"]
865
+ output = self.GypPathToUniqueOutput("headers.hmap")
866
+ self.xcode_settings.header_map_path = output
867
+ all_headers = map(
868
+ self.GypPathToNinja, filter(lambda x: x.endswith(".h"), all_sources)
869
+ )
870
+ variables = [
871
+ ("framework", framework),
872
+ ("copy_headers", map(self.GypPathToNinja, copy_headers)),
873
+ ]
874
+ outputs.extend(
875
+ self.ninja.build(
876
+ output,
877
+ "compile_ios_framework_headers",
878
+ all_headers,
879
+ variables=variables,
880
+ order_only=prebuild,
881
+ )
882
+ )
883
+
884
+ def WriteMacBundleResources(self, resources, bundle_depends):
885
+ """Writes ninja edges for 'mac_bundle_resources'."""
886
+ xcassets = []
887
+
888
+ extra_env = self.xcode_settings.GetPerTargetSettings()
889
+ env = self.GetSortedXcodeEnv(additional_settings=extra_env)
890
+ env = self.ComputeExportEnvString(env)
891
+ isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name)
892
+
893
+ for output, res in gyp.xcode_emulation.GetMacBundleResources(
894
+ generator_default_variables["PRODUCT_DIR"],
895
+ self.xcode_settings,
896
+ map(self.GypPathToNinja, resources),
897
+ ):
898
+ output = self.ExpandSpecial(output)
899
+ if os.path.splitext(output)[-1] != ".xcassets":
900
+ self.ninja.build(
901
+ output,
902
+ "mac_tool",
903
+ res,
904
+ variables=[
905
+ ("mactool_cmd", "copy-bundle-resource"),
906
+ ("env", env),
907
+ ("binary", isBinary),
908
+ ],
909
+ )
910
+ bundle_depends.append(output)
911
+ else:
912
+ xcassets.append(res)
913
+ return xcassets
914
+
915
+ def WriteMacXCassets(self, xcassets, bundle_depends):
916
+ """Writes ninja edges for 'mac_bundle_resources' .xcassets files.
917
+
918
+ This add an invocation of 'actool' via the 'mac_tool.py' helper script.
919
+ It assumes that the assets catalogs define at least one imageset and
920
+ thus an Assets.car file will be generated in the application resources
921
+ directory. If this is not the case, then the build will probably be done
922
+ at each invocation of ninja."""
923
+ if not xcassets:
924
+ return
925
+
926
+ extra_arguments = {}
927
+ settings_to_arg = {
928
+ "XCASSETS_APP_ICON": "app-icon",
929
+ "XCASSETS_LAUNCH_IMAGE": "launch-image",
930
+ }
931
+ settings = self.xcode_settings.xcode_settings[self.config_name]
932
+ for settings_key, arg_name in settings_to_arg.items():
933
+ value = settings.get(settings_key)
934
+ if value:
935
+ extra_arguments[arg_name] = value
936
+
937
+ partial_info_plist = None
938
+ if extra_arguments:
939
+ partial_info_plist = self.GypPathToUniqueOutput(
940
+ "assetcatalog_generated_info.plist"
941
+ )
942
+ extra_arguments["output-partial-info-plist"] = partial_info_plist
943
+
944
+ outputs = []
945
+ outputs.append(
946
+ os.path.join(self.xcode_settings.GetBundleResourceFolder(), "Assets.car")
947
+ )
948
+ if partial_info_plist:
949
+ outputs.append(partial_info_plist)
950
+
951
+ keys = QuoteShellArgument(json.dumps(extra_arguments), self.flavor)
952
+ extra_env = self.xcode_settings.GetPerTargetSettings()
953
+ env = self.GetSortedXcodeEnv(additional_settings=extra_env)
954
+ env = self.ComputeExportEnvString(env)
955
+
956
+ bundle_depends.extend(
957
+ self.ninja.build(
958
+ outputs,
959
+ "compile_xcassets",
960
+ xcassets,
961
+ variables=[("env", env), ("keys", keys)],
962
+ )
963
+ )
964
+ return partial_info_plist
965
+
966
+ def WriteMacInfoPlist(self, partial_info_plist, bundle_depends):
967
+ """Write build rules for bundle Info.plist files."""
968
+ info_plist, out, defines, extra_env = gyp.xcode_emulation.GetMacInfoPlist(
969
+ generator_default_variables["PRODUCT_DIR"],
970
+ self.xcode_settings,
971
+ self.GypPathToNinja,
972
+ )
973
+ if not info_plist:
974
+ return
975
+ out = self.ExpandSpecial(out)
976
+ if defines:
977
+ # Create an intermediate file to store preprocessed results.
978
+ intermediate_plist = self.GypPathToUniqueOutput(
979
+ os.path.basename(info_plist)
980
+ )
981
+ defines = " ".join([Define(d, self.flavor) for d in defines])
982
+ info_plist = self.ninja.build(
983
+ intermediate_plist,
984
+ "preprocess_infoplist",
985
+ info_plist,
986
+ variables=[("defines", defines)],
987
+ )
988
+
989
+ env = self.GetSortedXcodeEnv(additional_settings=extra_env)
990
+ env = self.ComputeExportEnvString(env)
991
+
992
+ if partial_info_plist:
993
+ intermediate_plist = self.GypPathToUniqueOutput("merged_info.plist")
994
+ info_plist = self.ninja.build(
995
+ intermediate_plist, "merge_infoplist", [partial_info_plist, info_plist]
996
+ )
997
+
998
+ keys = self.xcode_settings.GetExtraPlistItems(self.config_name)
999
+ keys = QuoteShellArgument(json.dumps(keys), self.flavor)
1000
+ isBinary = self.xcode_settings.IsBinaryOutputFormat(self.config_name)
1001
+ self.ninja.build(
1002
+ out,
1003
+ "copy_infoplist",
1004
+ info_plist,
1005
+ variables=[("env", env), ("keys", keys), ("binary", isBinary)],
1006
+ )
1007
+ bundle_depends.append(out)
1008
+
1009
+ def WriteSources(
1010
+ self,
1011
+ ninja_file,
1012
+ config_name,
1013
+ config,
1014
+ sources,
1015
+ predepends,
1016
+ precompiled_header,
1017
+ spec,
1018
+ ):
1019
+ """Write build rules to compile all of |sources|."""
1020
+ if self.toolset == "host":
1021
+ self.ninja.variable("ar", "$ar_host")
1022
+ self.ninja.variable("cc", "$cc_host")
1023
+ self.ninja.variable("cxx", "$cxx_host")
1024
+ self.ninja.variable("ld", "$ld_host")
1025
+ self.ninja.variable("ldxx", "$ldxx_host")
1026
+ self.ninja.variable("nm", "$nm_host")
1027
+ self.ninja.variable("readelf", "$readelf_host")
1028
+
1029
+ if self.flavor != "mac" or len(self.archs) == 1:
1030
+ return self.WriteSourcesForArch(
1031
+ self.ninja,
1032
+ config_name,
1033
+ config,
1034
+ sources,
1035
+ predepends,
1036
+ precompiled_header,
1037
+ spec,
1038
+ )
1039
+ else:
1040
+ return {
1041
+ arch: self.WriteSourcesForArch(
1042
+ self.arch_subninjas[arch],
1043
+ config_name,
1044
+ config,
1045
+ sources,
1046
+ predepends,
1047
+ precompiled_header,
1048
+ spec,
1049
+ arch=arch,
1050
+ )
1051
+ for arch in self.archs
1052
+ }
1053
+
1054
+ def WriteSourcesForArch(
1055
+ self,
1056
+ ninja_file,
1057
+ config_name,
1058
+ config,
1059
+ sources,
1060
+ predepends,
1061
+ precompiled_header,
1062
+ spec,
1063
+ arch=None,
1064
+ ):
1065
+ """Write build rules to compile all of |sources|."""
1066
+
1067
+ extra_defines = []
1068
+ if self.flavor == "mac":
1069
+ cflags = self.xcode_settings.GetCflags(config_name, arch=arch)
1070
+ cflags_c = self.xcode_settings.GetCflagsC(config_name)
1071
+ cflags_cc = self.xcode_settings.GetCflagsCC(config_name)
1072
+ cflags_objc = ["$cflags_c"] + self.xcode_settings.GetCflagsObjC(config_name)
1073
+ cflags_objcc = ["$cflags_cc"] + self.xcode_settings.GetCflagsObjCC(
1074
+ config_name
1075
+ )
1076
+ elif self.flavor == "win":
1077
+ asmflags = self.msvs_settings.GetAsmflags(config_name)
1078
+ cflags = self.msvs_settings.GetCflags(config_name)
1079
+ cflags_c = self.msvs_settings.GetCflagsC(config_name)
1080
+ cflags_cc = self.msvs_settings.GetCflagsCC(config_name)
1081
+ extra_defines = self.msvs_settings.GetComputedDefines(config_name)
1082
+ # See comment at cc_command for why there's two .pdb files.
1083
+ pdbpath_c = pdbpath_cc = self.msvs_settings.GetCompilerPdbName(
1084
+ config_name, self.ExpandSpecial
1085
+ )
1086
+ if not pdbpath_c:
1087
+ obj = "obj"
1088
+ if self.toolset != "target":
1089
+ obj += "." + self.toolset
1090
+ pdbpath = os.path.normpath(os.path.join(obj, self.base_dir, self.name))
1091
+ pdbpath_c = pdbpath + ".c.pdb"
1092
+ pdbpath_cc = pdbpath + ".cc.pdb"
1093
+ self.WriteVariableList(ninja_file, "pdbname_c", [pdbpath_c])
1094
+ self.WriteVariableList(ninja_file, "pdbname_cc", [pdbpath_cc])
1095
+ self.WriteVariableList(ninja_file, "pchprefix", [self.name])
1096
+ else:
1097
+ cflags = config.get("cflags", [])
1098
+ cflags_c = config.get("cflags_c", [])
1099
+ cflags_cc = config.get("cflags_cc", [])
1100
+
1101
+ # Respect environment variables related to build, but target-specific
1102
+ # flags can still override them.
1103
+ if self.toolset == "target":
1104
+ cflags_c = (
1105
+ os.environ.get("CPPFLAGS", "").split()
1106
+ + os.environ.get("CFLAGS", "").split()
1107
+ + cflags_c
1108
+ )
1109
+ cflags_cc = (
1110
+ os.environ.get("CPPFLAGS", "").split()
1111
+ + os.environ.get("CXXFLAGS", "").split()
1112
+ + cflags_cc
1113
+ )
1114
+ elif self.toolset == "host":
1115
+ cflags_c = (
1116
+ os.environ.get("CPPFLAGS_host", "").split()
1117
+ + os.environ.get("CFLAGS_host", "").split()
1118
+ + cflags_c
1119
+ )
1120
+ cflags_cc = (
1121
+ os.environ.get("CPPFLAGS_host", "").split()
1122
+ + os.environ.get("CXXFLAGS_host", "").split()
1123
+ + cflags_cc
1124
+ )
1125
+
1126
+ defines = config.get("defines", []) + extra_defines
1127
+ self.WriteVariableList(
1128
+ ninja_file, "defines", [Define(d, self.flavor) for d in defines]
1129
+ )
1130
+ if self.flavor == "win":
1131
+ self.WriteVariableList(
1132
+ ninja_file, "asmflags", map(self.ExpandSpecial, asmflags)
1133
+ )
1134
+ self.WriteVariableList(
1135
+ ninja_file,
1136
+ "rcflags",
1137
+ [
1138
+ QuoteShellArgument(self.ExpandSpecial(f), self.flavor)
1139
+ for f in self.msvs_settings.GetRcflags(
1140
+ config_name, self.GypPathToNinja
1141
+ )
1142
+ ],
1143
+ )
1144
+
1145
+ include_dirs = config.get("include_dirs", [])
1146
+
1147
+ env = self.GetToolchainEnv()
1148
+ if self.flavor == "win":
1149
+ include_dirs = self.msvs_settings.AdjustIncludeDirs(
1150
+ include_dirs, config_name
1151
+ )
1152
+ self.WriteVariableList(
1153
+ ninja_file,
1154
+ "includes",
1155
+ [
1156
+ QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
1157
+ for i in include_dirs
1158
+ ],
1159
+ )
1160
+
1161
+ if self.flavor == "win":
1162
+ midl_include_dirs = config.get("midl_include_dirs", [])
1163
+ midl_include_dirs = self.msvs_settings.AdjustMidlIncludeDirs(
1164
+ midl_include_dirs, config_name
1165
+ )
1166
+ self.WriteVariableList(
1167
+ ninja_file,
1168
+ "midl_includes",
1169
+ [
1170
+ QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
1171
+ for i in midl_include_dirs
1172
+ ],
1173
+ )
1174
+
1175
+ pch_commands = precompiled_header.GetPchBuildCommands(arch)
1176
+ if self.flavor == "mac":
1177
+ # Most targets use no precompiled headers, so only write these if needed.
1178
+ for ext, var in [
1179
+ ("c", "cflags_pch_c"),
1180
+ ("cc", "cflags_pch_cc"),
1181
+ ("m", "cflags_pch_objc"),
1182
+ ("mm", "cflags_pch_objcc"),
1183
+ ]:
1184
+ include = precompiled_header.GetInclude(ext, arch)
1185
+ if include:
1186
+ ninja_file.variable(var, include)
1187
+
1188
+ arflags = config.get("arflags", [])
1189
+
1190
+ self.WriteVariableList(ninja_file, "cflags", map(self.ExpandSpecial, cflags))
1191
+ self.WriteVariableList(
1192
+ ninja_file, "cflags_c", map(self.ExpandSpecial, cflags_c)
1193
+ )
1194
+ self.WriteVariableList(
1195
+ ninja_file, "cflags_cc", map(self.ExpandSpecial, cflags_cc)
1196
+ )
1197
+ if self.flavor == "mac":
1198
+ self.WriteVariableList(
1199
+ ninja_file, "cflags_objc", map(self.ExpandSpecial, cflags_objc)
1200
+ )
1201
+ self.WriteVariableList(
1202
+ ninja_file, "cflags_objcc", map(self.ExpandSpecial, cflags_objcc)
1203
+ )
1204
+ self.WriteVariableList(ninja_file, "arflags", map(self.ExpandSpecial, arflags))
1205
+ ninja_file.newline()
1206
+ outputs = []
1207
+ has_rc_source = False
1208
+ for source in sources:
1209
+ filename, ext = os.path.splitext(source)
1210
+ ext = ext[1:]
1211
+ obj_ext = self.obj_ext
1212
+ if ext in ("cc", "cpp", "cxx"):
1213
+ command = "cxx"
1214
+ self.target.uses_cpp = True
1215
+ elif ext == "c" or (ext == "S" and self.flavor != "win"):
1216
+ command = "cc"
1217
+ elif ext == "s" and self.flavor != "win": # Doesn't generate .o.d files.
1218
+ command = "cc_s"
1219
+ elif (
1220
+ self.flavor == "win"
1221
+ and ext in ("asm", "S")
1222
+ and not self.msvs_settings.HasExplicitAsmRules(spec)
1223
+ ):
1224
+ command = "asm"
1225
+ # Add the _asm suffix as msvs is capable of handling .cc and
1226
+ # .asm files of the same name without collision.
1227
+ obj_ext = "_asm.obj"
1228
+ elif self.flavor == "mac" and ext == "m":
1229
+ command = "objc"
1230
+ elif self.flavor == "mac" and ext == "mm":
1231
+ command = "objcxx"
1232
+ self.target.uses_cpp = True
1233
+ elif self.flavor == "win" and ext == "rc":
1234
+ command = "rc"
1235
+ obj_ext = ".res"
1236
+ has_rc_source = True
1237
+ else:
1238
+ # Ignore unhandled extensions.
1239
+ continue
1240
+ input = self.GypPathToNinja(source)
1241
+ output = self.GypPathToUniqueOutput(filename + obj_ext)
1242
+ if arch is not None:
1243
+ output = AddArch(output, arch)
1244
+ implicit = precompiled_header.GetObjDependencies([input], [output], arch)
1245
+ variables = []
1246
+ if self.flavor == "win":
1247
+ variables, output, implicit = precompiled_header.GetFlagsModifications(
1248
+ input,
1249
+ output,
1250
+ implicit,
1251
+ command,
1252
+ cflags_c,
1253
+ cflags_cc,
1254
+ self.ExpandSpecial,
1255
+ )
1256
+ ninja_file.build(
1257
+ output,
1258
+ command,
1259
+ input,
1260
+ implicit=[gch for _, _, gch in implicit],
1261
+ order_only=predepends,
1262
+ variables=variables,
1263
+ )
1264
+ outputs.append(output)
1265
+
1266
+ if has_rc_source:
1267
+ resource_include_dirs = config.get("resource_include_dirs", include_dirs)
1268
+ self.WriteVariableList(
1269
+ ninja_file,
1270
+ "resource_includes",
1271
+ [
1272
+ QuoteShellArgument("-I" + self.GypPathToNinja(i, env), self.flavor)
1273
+ for i in resource_include_dirs
1274
+ ],
1275
+ )
1276
+
1277
+ self.WritePchTargets(ninja_file, pch_commands)
1278
+
1279
+ ninja_file.newline()
1280
+ return outputs
1281
+
1282
+ def WritePchTargets(self, ninja_file, pch_commands):
1283
+ """Writes ninja rules to compile prefix headers."""
1284
+ if not pch_commands:
1285
+ return
1286
+
1287
+ for gch, lang_flag, lang, input in pch_commands:
1288
+ var_name = {
1289
+ "c": "cflags_pch_c",
1290
+ "cc": "cflags_pch_cc",
1291
+ "m": "cflags_pch_objc",
1292
+ "mm": "cflags_pch_objcc",
1293
+ }[lang]
1294
+
1295
+ map = {
1296
+ "c": "cc",
1297
+ "cc": "cxx",
1298
+ "m": "objc",
1299
+ "mm": "objcxx",
1300
+ }
1301
+ cmd = map.get(lang)
1302
+ ninja_file.build(gch, cmd, input, variables=[(var_name, lang_flag)])
1303
+
1304
+ def WriteLink(self, spec, config_name, config, link_deps, compile_deps):
1305
+ """Write out a link step. Fills out target.binary."""
1306
+ if self.flavor != "mac" or len(self.archs) == 1:
1307
+ return self.WriteLinkForArch(
1308
+ self.ninja, spec, config_name, config, link_deps, compile_deps
1309
+ )
1310
+ else:
1311
+ output = self.ComputeOutput(spec)
1312
+ inputs = [
1313
+ self.WriteLinkForArch(
1314
+ self.arch_subninjas[arch],
1315
+ spec,
1316
+ config_name,
1317
+ config,
1318
+ link_deps[arch],
1319
+ compile_deps,
1320
+ arch=arch,
1321
+ )
1322
+ for arch in self.archs
1323
+ ]
1324
+ extra_bindings = []
1325
+ build_output = output
1326
+ if not self.is_mac_bundle:
1327
+ self.AppendPostbuildVariable(extra_bindings, spec, output, output)
1328
+
1329
+ # TODO(yyanagisawa): more work needed to fix:
1330
+ # https://code.google.com/p/gyp/issues/detail?id=411
1331
+ if (
1332
+ spec["type"] in ("shared_library", "loadable_module")
1333
+ and not self.is_mac_bundle
1334
+ ):
1335
+ extra_bindings.append(("lib", output))
1336
+ self.ninja.build(
1337
+ [output, output + ".TOC"],
1338
+ "solipo",
1339
+ inputs,
1340
+ variables=extra_bindings,
1341
+ )
1342
+ else:
1343
+ self.ninja.build(build_output, "lipo", inputs, variables=extra_bindings)
1344
+ return output
1345
+
1346
+ def WriteLinkForArch(
1347
+ self, ninja_file, spec, config_name, config, link_deps, compile_deps, arch=None
1348
+ ):
1349
+ """Write out a link step. Fills out target.binary."""
1350
+ command = {
1351
+ "executable": "link",
1352
+ "loadable_module": "solink_module",
1353
+ "shared_library": "solink",
1354
+ }[spec["type"]]
1355
+ command_suffix = ""
1356
+
1357
+ implicit_deps = set()
1358
+ solibs = set()
1359
+ order_deps = set()
1360
+
1361
+ if compile_deps:
1362
+ # Normally, the compiles of the target already depend on compile_deps,
1363
+ # but a shared_library target might have no sources and only link together
1364
+ # a few static_library deps, so the link step also needs to depend
1365
+ # on compile_deps to make sure actions in the shared_library target
1366
+ # get run before the link.
1367
+ order_deps.add(compile_deps)
1368
+
1369
+ if "dependencies" in spec:
1370
+ # Two kinds of dependencies:
1371
+ # - Linkable dependencies (like a .a or a .so): add them to the link line.
1372
+ # - Non-linkable dependencies (like a rule that generates a file
1373
+ # and writes a stamp file): add them to implicit_deps
1374
+ extra_link_deps = set()
1375
+ for dep in spec["dependencies"]:
1376
+ target = self.target_outputs.get(dep)
1377
+ if not target:
1378
+ continue
1379
+ linkable = target.Linkable()
1380
+ if linkable:
1381
+ new_deps = []
1382
+ if (
1383
+ self.flavor == "win"
1384
+ and target.component_objs
1385
+ and self.msvs_settings.IsUseLibraryDependencyInputs(config_name)
1386
+ ):
1387
+ new_deps = target.component_objs
1388
+ if target.compile_deps:
1389
+ order_deps.add(target.compile_deps)
1390
+ elif self.flavor == "win" and target.import_lib:
1391
+ new_deps = [target.import_lib]
1392
+ elif target.UsesToc(self.flavor):
1393
+ solibs.add(target.binary)
1394
+ implicit_deps.add(target.binary + ".TOC")
1395
+ else:
1396
+ new_deps = [target.binary]
1397
+ for new_dep in new_deps:
1398
+ if new_dep not in extra_link_deps:
1399
+ extra_link_deps.add(new_dep)
1400
+ link_deps.append(new_dep)
1401
+
1402
+ final_output = target.FinalOutput()
1403
+ if not linkable or final_output != target.binary:
1404
+ implicit_deps.add(final_output)
1405
+
1406
+ extra_bindings = []
1407
+ if self.target.uses_cpp and self.flavor != "win":
1408
+ extra_bindings.append(("ld", "$ldxx"))
1409
+
1410
+ output = self.ComputeOutput(spec, arch)
1411
+ if arch is None and not self.is_mac_bundle:
1412
+ self.AppendPostbuildVariable(extra_bindings, spec, output, output)
1413
+
1414
+ is_executable = spec["type"] == "executable"
1415
+ # The ldflags config key is not used on mac or win. On those platforms
1416
+ # linker flags are set via xcode_settings and msvs_settings, respectively.
1417
+ if self.toolset == "target":
1418
+ env_ldflags = os.environ.get("LDFLAGS", "").split()
1419
+ elif self.toolset == "host":
1420
+ env_ldflags = os.environ.get("LDFLAGS_host", "").split()
1421
+
1422
+ if self.flavor == "mac":
1423
+ ldflags = self.xcode_settings.GetLdflags(
1424
+ config_name,
1425
+ self.ExpandSpecial(generator_default_variables["PRODUCT_DIR"]),
1426
+ self.GypPathToNinja,
1427
+ arch,
1428
+ )
1429
+ ldflags = env_ldflags + ldflags
1430
+ elif self.flavor == "win":
1431
+ manifest_base_name = self.GypPathToUniqueOutput(
1432
+ self.ComputeOutputFileName(spec)
1433
+ )
1434
+ (
1435
+ ldflags,
1436
+ intermediate_manifest,
1437
+ manifest_files,
1438
+ ) = self.msvs_settings.GetLdflags(
1439
+ config_name,
1440
+ self.GypPathToNinja,
1441
+ self.ExpandSpecial,
1442
+ manifest_base_name,
1443
+ output,
1444
+ is_executable,
1445
+ self.toplevel_build,
1446
+ )
1447
+ ldflags = env_ldflags + ldflags
1448
+ self.WriteVariableList(ninja_file, "manifests", manifest_files)
1449
+ implicit_deps = implicit_deps.union(manifest_files)
1450
+ if intermediate_manifest:
1451
+ self.WriteVariableList(
1452
+ ninja_file, "intermediatemanifest", [intermediate_manifest]
1453
+ )
1454
+ command_suffix = _GetWinLinkRuleNameSuffix(
1455
+ self.msvs_settings.IsEmbedManifest(config_name)
1456
+ )
1457
+ def_file = self.msvs_settings.GetDefFile(self.GypPathToNinja)
1458
+ if def_file:
1459
+ implicit_deps.add(def_file)
1460
+ else:
1461
+ # Respect environment variables related to build, but target-specific
1462
+ # flags can still override them.
1463
+ ldflags = env_ldflags + config.get("ldflags", [])
1464
+ if is_executable and solibs:
1465
+ rpath = "lib/"
1466
+ if self.toolset != "target":
1467
+ rpath += self.toolset
1468
+ ldflags.append(r"-Wl,-rpath=\$$ORIGIN/%s" % rpath)
1469
+ else:
1470
+ ldflags.append("-Wl,-rpath=%s" % self.target_rpath)
1471
+ ldflags.append("-Wl,-rpath-link=%s" % rpath)
1472
+ self.WriteVariableList(ninja_file, "ldflags", map(self.ExpandSpecial, ldflags))
1473
+
1474
+ library_dirs = config.get("library_dirs", [])
1475
+ if self.flavor == "win":
1476
+ library_dirs = [
1477
+ self.msvs_settings.ConvertVSMacros(library_dir, config_name)
1478
+ for library_dir in library_dirs
1479
+ ]
1480
+ library_dirs = [
1481
+ "/LIBPATH:"
1482
+ + QuoteShellArgument(self.GypPathToNinja(library_dir), self.flavor)
1483
+ for library_dir in library_dirs
1484
+ ]
1485
+ else:
1486
+ library_dirs = [
1487
+ QuoteShellArgument("-L" + self.GypPathToNinja(library_dir), self.flavor)
1488
+ for library_dir in library_dirs
1489
+ ]
1490
+
1491
+ libraries = gyp.common.uniquer(
1492
+ map(self.ExpandSpecial, spec.get("libraries", []))
1493
+ )
1494
+ if self.flavor == "mac":
1495
+ libraries = self.xcode_settings.AdjustLibraries(libraries, config_name)
1496
+ elif self.flavor == "win":
1497
+ libraries = self.msvs_settings.AdjustLibraries(libraries)
1498
+
1499
+ self.WriteVariableList(ninja_file, "libs", library_dirs + libraries)
1500
+
1501
+ linked_binary = output
1502
+
1503
+ if command in ("solink", "solink_module"):
1504
+ extra_bindings.append(("soname", os.path.split(output)[1]))
1505
+ extra_bindings.append(("lib", gyp.common.EncodePOSIXShellArgument(output)))
1506
+ if self.flavor != "win":
1507
+ link_file_list = output
1508
+ if self.is_mac_bundle:
1509
+ # 'Dependency Framework.framework/Versions/A/Dependency Framework'
1510
+ # -> 'Dependency Framework.framework.rsp'
1511
+ link_file_list = self.xcode_settings.GetWrapperName()
1512
+ if arch:
1513
+ link_file_list += "." + arch
1514
+ link_file_list += ".rsp"
1515
+ # If an rspfile contains spaces, ninja surrounds the filename with
1516
+ # quotes around it and then passes it to open(), creating a file with
1517
+ # quotes in its name (and when looking for the rsp file, the name
1518
+ # makes it through bash which strips the quotes) :-/
1519
+ link_file_list = link_file_list.replace(" ", "_")
1520
+ extra_bindings.append(
1521
+ (
1522
+ "link_file_list",
1523
+ gyp.common.EncodePOSIXShellArgument(link_file_list),
1524
+ )
1525
+ )
1526
+ if self.flavor == "win":
1527
+ extra_bindings.append(("binary", output))
1528
+ if (
1529
+ "/NOENTRY" not in ldflags
1530
+ and not self.msvs_settings.GetNoImportLibrary(config_name)
1531
+ ):
1532
+ self.target.import_lib = output + ".lib"
1533
+ extra_bindings.append(
1534
+ ("implibflag", "/IMPLIB:%s" % self.target.import_lib)
1535
+ )
1536
+ pdbname = self.msvs_settings.GetPDBName(
1537
+ config_name, self.ExpandSpecial, output + ".pdb"
1538
+ )
1539
+ output = [output, self.target.import_lib]
1540
+ if pdbname:
1541
+ output.append(pdbname)
1542
+ elif not self.is_mac_bundle:
1543
+ output = [output, output + ".TOC"]
1544
+ else:
1545
+ command = command + "_notoc"
1546
+ elif self.flavor == "win":
1547
+ extra_bindings.append(("binary", output))
1548
+ pdbname = self.msvs_settings.GetPDBName(
1549
+ config_name, self.ExpandSpecial, output + ".pdb"
1550
+ )
1551
+ if pdbname:
1552
+ output = [output, pdbname]
1553
+
1554
+ if solibs:
1555
+ extra_bindings.append(
1556
+ ("solibs", gyp.common.EncodePOSIXShellList(sorted(solibs)))
1557
+ )
1558
+
1559
+ ninja_file.build(
1560
+ output,
1561
+ command + command_suffix,
1562
+ link_deps,
1563
+ implicit=sorted(implicit_deps),
1564
+ order_only=list(order_deps),
1565
+ variables=extra_bindings,
1566
+ )
1567
+ return linked_binary
1568
+
1569
+ def WriteTarget(self, spec, config_name, config, link_deps, compile_deps):
1570
+ extra_link_deps = any(
1571
+ self.target_outputs.get(dep).Linkable()
1572
+ for dep in spec.get("dependencies", [])
1573
+ if dep in self.target_outputs
1574
+ )
1575
+ if spec["type"] == "none" or (not link_deps and not extra_link_deps):
1576
+ # TODO(evan): don't call this function for 'none' target types, as
1577
+ # it doesn't do anything, and we fake out a 'binary' with a stamp file.
1578
+ self.target.binary = compile_deps
1579
+ self.target.type = "none"
1580
+ elif spec["type"] == "static_library":
1581
+ self.target.binary = self.ComputeOutput(spec)
1582
+ if (
1583
+ self.flavor not in ("ios", "mac", "netbsd", "openbsd", "win")
1584
+ and not self.is_standalone_static_library
1585
+ ):
1586
+ self.ninja.build(
1587
+ self.target.binary, "alink_thin", link_deps, order_only=compile_deps
1588
+ )
1589
+ else:
1590
+ variables = []
1591
+ if self.xcode_settings:
1592
+ libtool_flags = self.xcode_settings.GetLibtoolflags(config_name)
1593
+ if libtool_flags:
1594
+ variables.append(("libtool_flags", libtool_flags))
1595
+ if self.msvs_settings:
1596
+ libflags = self.msvs_settings.GetLibFlags(
1597
+ config_name, self.GypPathToNinja
1598
+ )
1599
+ variables.append(("libflags", libflags))
1600
+
1601
+ if self.flavor != "mac" or len(self.archs) == 1:
1602
+ self.AppendPostbuildVariable(
1603
+ variables, spec, self.target.binary, self.target.binary
1604
+ )
1605
+ self.ninja.build(
1606
+ self.target.binary,
1607
+ "alink",
1608
+ link_deps,
1609
+ order_only=compile_deps,
1610
+ variables=variables,
1611
+ )
1612
+ else:
1613
+ inputs = []
1614
+ for arch in self.archs:
1615
+ output = self.ComputeOutput(spec, arch)
1616
+ self.arch_subninjas[arch].build(
1617
+ output,
1618
+ "alink",
1619
+ link_deps[arch],
1620
+ order_only=compile_deps,
1621
+ variables=variables,
1622
+ )
1623
+ inputs.append(output)
1624
+ # TODO: It's not clear if
1625
+ # libtool_flags should be passed to the alink
1626
+ # call that combines single-arch .a files into a fat .a file.
1627
+ self.AppendPostbuildVariable(
1628
+ variables, spec, self.target.binary, self.target.binary
1629
+ )
1630
+ self.ninja.build(
1631
+ self.target.binary,
1632
+ "alink",
1633
+ inputs,
1634
+ # FIXME: test proving order_only=compile_deps isn't
1635
+ # needed.
1636
+ variables=variables,
1637
+ )
1638
+ else:
1639
+ self.target.binary = self.WriteLink(
1640
+ spec, config_name, config, link_deps, compile_deps
1641
+ )
1642
+ return self.target.binary
1643
+
1644
+ def WriteMacBundle(self, spec, mac_bundle_depends, is_empty):
1645
+ assert self.is_mac_bundle
1646
+ package_framework = spec["type"] in ("shared_library", "loadable_module")
1647
+ output = self.ComputeMacBundleOutput()
1648
+ if is_empty:
1649
+ output += ".stamp"
1650
+ variables = []
1651
+ self.AppendPostbuildVariable(
1652
+ variables,
1653
+ spec,
1654
+ output,
1655
+ self.target.binary,
1656
+ is_command_start=not package_framework,
1657
+ )
1658
+ if package_framework and not is_empty:
1659
+ if spec["type"] == "shared_library" and self.xcode_settings.isIOS:
1660
+ self.ninja.build(
1661
+ output,
1662
+ "package_ios_framework",
1663
+ mac_bundle_depends,
1664
+ variables=variables,
1665
+ )
1666
+ else:
1667
+ variables.append(("version", self.xcode_settings.GetFrameworkVersion()))
1668
+ self.ninja.build(
1669
+ output, "package_framework", mac_bundle_depends, variables=variables
1670
+ )
1671
+ else:
1672
+ self.ninja.build(output, "stamp", mac_bundle_depends, variables=variables)
1673
+ self.target.bundle = output
1674
+ return output
1675
+
1676
+ def GetToolchainEnv(self, additional_settings=None):
1677
+ """Returns the variables toolchain would set for build steps."""
1678
+ env = self.GetSortedXcodeEnv(additional_settings=additional_settings)
1679
+ if self.flavor == "win":
1680
+ env = self.GetMsvsToolchainEnv(additional_settings=additional_settings)
1681
+ return env
1682
+
1683
+ def GetMsvsToolchainEnv(self, additional_settings=None):
1684
+ """Returns the variables Visual Studio would set for build steps."""
1685
+ return self.msvs_settings.GetVSMacroEnv(
1686
+ "$!PRODUCT_DIR", config=self.config_name
1687
+ )
1688
+
1689
+ def GetSortedXcodeEnv(self, additional_settings=None):
1690
+ """Returns the variables Xcode would set for build steps."""
1691
+ assert self.abs_build_dir
1692
+ abs_build_dir = self.abs_build_dir
1693
+ return gyp.xcode_emulation.GetSortedXcodeEnv(
1694
+ self.xcode_settings,
1695
+ abs_build_dir,
1696
+ os.path.join(abs_build_dir, self.build_to_base),
1697
+ self.config_name,
1698
+ additional_settings,
1699
+ )
1700
+
1701
+ def GetSortedXcodePostbuildEnv(self):
1702
+ """Returns the variables Xcode would set for postbuild steps."""
1703
+ postbuild_settings = {}
1704
+ # CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack.
1705
+ # TODO(thakis): It would be nice to have some general mechanism instead.
1706
+ strip_save_file = self.xcode_settings.GetPerTargetSetting(
1707
+ "CHROMIUM_STRIP_SAVE_FILE"
1708
+ )
1709
+ if strip_save_file:
1710
+ postbuild_settings["CHROMIUM_STRIP_SAVE_FILE"] = strip_save_file
1711
+ return self.GetSortedXcodeEnv(additional_settings=postbuild_settings)
1712
+
1713
+ def AppendPostbuildVariable(
1714
+ self, variables, spec, output, binary, is_command_start=False
1715
+ ):
1716
+ """Adds a 'postbuild' variable if there is a postbuild for |output|."""
1717
+ postbuild = self.GetPostbuildCommand(spec, output, binary, is_command_start)
1718
+ if postbuild:
1719
+ variables.append(("postbuilds", postbuild))
1720
+
1721
+ def GetPostbuildCommand(self, spec, output, output_binary, is_command_start):
1722
+ """Returns a shell command that runs all the postbuilds, and removes
1723
+ |output| if any of them fails. If |is_command_start| is False, then the
1724
+ returned string will start with ' && '."""
1725
+ if not self.xcode_settings or spec["type"] == "none" or not output:
1726
+ return ""
1727
+ output = QuoteShellArgument(output, self.flavor)
1728
+ postbuilds = gyp.xcode_emulation.GetSpecPostbuildCommands(spec, quiet=True)
1729
+ if output_binary is not None:
1730
+ postbuilds = self.xcode_settings.AddImplicitPostbuilds(
1731
+ self.config_name,
1732
+ os.path.normpath(os.path.join(self.base_to_build, output)),
1733
+ QuoteShellArgument(
1734
+ os.path.normpath(os.path.join(self.base_to_build, output_binary)),
1735
+ self.flavor,
1736
+ ),
1737
+ postbuilds,
1738
+ quiet=True,
1739
+ )
1740
+
1741
+ if not postbuilds:
1742
+ return ""
1743
+ # Postbuilds expect to be run in the gyp file's directory, so insert an
1744
+ # implicit postbuild to cd to there.
1745
+ postbuilds.insert(
1746
+ 0, gyp.common.EncodePOSIXShellList(["cd", self.build_to_base])
1747
+ )
1748
+ env = self.ComputeExportEnvString(self.GetSortedXcodePostbuildEnv())
1749
+ # G will be non-null if any postbuild fails. Run all postbuilds in a
1750
+ # subshell.
1751
+ commands = (
1752
+ env
1753
+ + " ("
1754
+ + " && ".join([ninja_syntax.escape(command) for command in postbuilds])
1755
+ )
1756
+ command_string = (
1757
+ commands + "); G=$$?; "
1758
+ # Remove the final output if any postbuild failed.
1759
+ "((exit $$G) || rm -rf %s) " % output + "&& exit $$G)"
1760
+ )
1761
+ if is_command_start:
1762
+ return "(" + command_string + " && "
1763
+ else:
1764
+ return "$ && (" + command_string
1765
+
1766
+ def ComputeExportEnvString(self, env):
1767
+ """Given an environment, returns a string looking like
1768
+ 'export FOO=foo; export BAR="${FOO} bar;'
1769
+ that exports |env| to the shell."""
1770
+ export_str = []
1771
+ for k, v in env:
1772
+ export_str.append(
1773
+ "export %s=%s;"
1774
+ % (k, ninja_syntax.escape(gyp.common.EncodePOSIXShellArgument(v)))
1775
+ )
1776
+ return " ".join(export_str)
1777
+
1778
+ def ComputeMacBundleOutput(self):
1779
+ """Return the 'output' (full output path) to a bundle output directory."""
1780
+ assert self.is_mac_bundle
1781
+ path = generator_default_variables["PRODUCT_DIR"]
1782
+ return self.ExpandSpecial(
1783
+ os.path.join(path, self.xcode_settings.GetWrapperName())
1784
+ )
1785
+
1786
+ def ComputeOutputFileName(self, spec, type=None):
1787
+ """Compute the filename of the final output for the current target."""
1788
+ if not type:
1789
+ type = spec["type"]
1790
+
1791
+ default_variables = copy.copy(generator_default_variables)
1792
+ CalculateVariables(default_variables, {"flavor": self.flavor})
1793
+
1794
+ # Compute filename prefix: the product prefix, or a default for
1795
+ # the product type.
1796
+ DEFAULT_PREFIX = {
1797
+ "loadable_module": default_variables["SHARED_LIB_PREFIX"],
1798
+ "shared_library": default_variables["SHARED_LIB_PREFIX"],
1799
+ "static_library": default_variables["STATIC_LIB_PREFIX"],
1800
+ "executable": default_variables["EXECUTABLE_PREFIX"],
1801
+ }
1802
+ prefix = spec.get("product_prefix", DEFAULT_PREFIX.get(type, ""))
1803
+
1804
+ # Compute filename extension: the product extension, or a default
1805
+ # for the product type.
1806
+ DEFAULT_EXTENSION = {
1807
+ "loadable_module": default_variables["SHARED_LIB_SUFFIX"],
1808
+ "shared_library": default_variables["SHARED_LIB_SUFFIX"],
1809
+ "static_library": default_variables["STATIC_LIB_SUFFIX"],
1810
+ "executable": default_variables["EXECUTABLE_SUFFIX"],
1811
+ }
1812
+ extension = spec.get("product_extension")
1813
+ extension = "." + extension if extension else DEFAULT_EXTENSION.get(type, "")
1814
+
1815
+ if "product_name" in spec:
1816
+ # If we were given an explicit name, use that.
1817
+ target = spec["product_name"]
1818
+ else:
1819
+ # Otherwise, derive a name from the target name.
1820
+ target = spec["target_name"]
1821
+ if prefix == "lib":
1822
+ # Snip out an extra 'lib' from libs if appropriate.
1823
+ target = StripPrefix(target, "lib")
1824
+
1825
+ if type in (
1826
+ "static_library",
1827
+ "loadable_module",
1828
+ "shared_library",
1829
+ "executable",
1830
+ ):
1831
+ return f"{prefix}{target}{extension}"
1832
+ elif type == "none":
1833
+ return "%s.stamp" % target
1834
+ else:
1835
+ raise Exception("Unhandled output type %s" % type)
1836
+
1837
+ def ComputeOutput(self, spec, arch=None):
1838
+ """Compute the path for the final output of the spec."""
1839
+ type = spec["type"]
1840
+
1841
+ if self.flavor == "win":
1842
+ override = self.msvs_settings.GetOutputName(
1843
+ self.config_name, self.ExpandSpecial
1844
+ )
1845
+ if override:
1846
+ return override
1847
+
1848
+ if (
1849
+ arch is None
1850
+ and self.flavor == "mac"
1851
+ and type
1852
+ in ("static_library", "executable", "shared_library", "loadable_module")
1853
+ ):
1854
+ filename = self.xcode_settings.GetExecutablePath()
1855
+ else:
1856
+ filename = self.ComputeOutputFileName(spec, type)
1857
+
1858
+ if arch is None and "product_dir" in spec:
1859
+ path = os.path.join(spec["product_dir"], filename)
1860
+ return self.ExpandSpecial(path)
1861
+
1862
+ # Some products go into the output root, libraries go into shared library
1863
+ # dir, and everything else goes into the normal place.
1864
+ type_in_output_root = ["executable", "loadable_module"]
1865
+ if self.flavor == "mac" and self.toolset == "target":
1866
+ type_in_output_root += ["shared_library", "static_library"]
1867
+ elif self.flavor == "win" and self.toolset == "target":
1868
+ type_in_output_root += ["shared_library"]
1869
+
1870
+ if arch is not None:
1871
+ # Make sure partial executables don't end up in a bundle or the regular
1872
+ # output directory.
1873
+ archdir = "arch"
1874
+ if self.toolset != "target":
1875
+ archdir = os.path.join("arch", "%s" % self.toolset)
1876
+ return os.path.join(archdir, AddArch(filename, arch))
1877
+ elif type in type_in_output_root or self.is_standalone_static_library:
1878
+ return filename
1879
+ elif type == "shared_library":
1880
+ libdir = "lib"
1881
+ if self.toolset != "target":
1882
+ libdir = os.path.join("lib", "%s" % self.toolset)
1883
+ return os.path.join(libdir, filename)
1884
+ else:
1885
+ return self.GypPathToUniqueOutput(filename, qualified=False)
1886
+
1887
+ def WriteVariableList(self, ninja_file, var, values):
1888
+ assert not isinstance(values, str)
1889
+ if values is None:
1890
+ values = []
1891
+ ninja_file.variable(var, " ".join(values))
1892
+
1893
+ def WriteNewNinjaRule(
1894
+ self, name, args, description, win_shell_flags, env, pool, depfile=None
1895
+ ):
1896
+ """Write out a new ninja "rule" statement for a given command.
1897
+
1898
+ Returns the name of the new rule, and a copy of |args| with variables
1899
+ expanded."""
1900
+
1901
+ if self.flavor == "win":
1902
+ args = [
1903
+ self.msvs_settings.ConvertVSMacros(
1904
+ arg, self.base_to_build, config=self.config_name
1905
+ )
1906
+ for arg in args
1907
+ ]
1908
+ description = self.msvs_settings.ConvertVSMacros(
1909
+ description, config=self.config_name
1910
+ )
1911
+ elif self.flavor == "mac":
1912
+ # |env| is an empty list on non-mac.
1913
+ args = [gyp.xcode_emulation.ExpandEnvVars(arg, env) for arg in args]
1914
+ description = gyp.xcode_emulation.ExpandEnvVars(description, env)
1915
+
1916
+ # TODO: we shouldn't need to qualify names; we do it because
1917
+ # currently the ninja rule namespace is global, but it really
1918
+ # should be scoped to the subninja.
1919
+ rule_name = self.name
1920
+ if self.toolset == "target":
1921
+ rule_name += "." + self.toolset
1922
+ rule_name += "." + name
1923
+ rule_name = re.sub("[^a-zA-Z0-9_]", "_", rule_name)
1924
+
1925
+ # Remove variable references, but not if they refer to the magic rule
1926
+ # variables. This is not quite right, as it also protects these for
1927
+ # actions, not just for rules where they are valid. Good enough.
1928
+ protect = ["${root}", "${dirname}", "${source}", "${ext}", "${name}"]
1929
+ protect = "(?!" + "|".join(map(re.escape, protect)) + ")"
1930
+ description = re.sub(protect + r"\$", "_", description)
1931
+
1932
+ # gyp dictates that commands are run from the base directory.
1933
+ # cd into the directory before running, and adjust paths in
1934
+ # the arguments to point to the proper locations.
1935
+ rspfile = None
1936
+ rspfile_content = None
1937
+ args = [self.ExpandSpecial(arg, self.base_to_build) for arg in args]
1938
+ if self.flavor == "win":
1939
+ rspfile = rule_name + ".$unique_name.rsp"
1940
+ # The cygwin case handles this inside the bash sub-shell.
1941
+ run_in = "" if win_shell_flags.cygwin else " " + self.build_to_base
1942
+ if win_shell_flags.cygwin:
1943
+ rspfile_content = self.msvs_settings.BuildCygwinBashCommandLine(
1944
+ args, self.build_to_base
1945
+ )
1946
+ else:
1947
+ rspfile_content = gyp.msvs_emulation.EncodeRspFileList(
1948
+ args, win_shell_flags.quote
1949
+ )
1950
+ command = (
1951
+ "%s gyp-win-tool action-wrapper $arch " % sys.executable
1952
+ + rspfile
1953
+ + run_in
1954
+ )
1955
+ else:
1956
+ env = self.ComputeExportEnvString(env)
1957
+ command = gyp.common.EncodePOSIXShellList(args)
1958
+ command = "cd %s; " % self.build_to_base + env + command
1959
+
1960
+ # GYP rules/actions express being no-ops by not touching their outputs.
1961
+ # Avoid executing downstream dependencies in this case by specifying
1962
+ # restat=1 to ninja.
1963
+ self.ninja.rule(
1964
+ rule_name,
1965
+ command,
1966
+ description,
1967
+ depfile=depfile,
1968
+ restat=True,
1969
+ pool=pool,
1970
+ rspfile=rspfile,
1971
+ rspfile_content=rspfile_content,
1972
+ )
1973
+ self.ninja.newline()
1974
+
1975
+ return rule_name, args
1976
+
1977
+
1978
+ def CalculateVariables(default_variables, params):
1979
+ """Calculate additional variables for use in the build (called by gyp)."""
1980
+ global generator_additional_non_configuration_keys
1981
+ global generator_additional_path_sections
1982
+ flavor = gyp.common.GetFlavor(params)
1983
+ if flavor == "mac":
1984
+ default_variables.setdefault("OS", "mac")
1985
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".dylib")
1986
+ default_variables.setdefault(
1987
+ "SHARED_LIB_DIR", generator_default_variables["PRODUCT_DIR"]
1988
+ )
1989
+ default_variables.setdefault(
1990
+ "LIB_DIR", generator_default_variables["PRODUCT_DIR"]
1991
+ )
1992
+
1993
+ # Copy additional generator configuration data from Xcode, which is shared
1994
+ # by the Mac Ninja generator.
1995
+ import gyp.generator.xcode as xcode_generator # noqa: PLC0415
1996
+
1997
+ generator_additional_non_configuration_keys = getattr(
1998
+ xcode_generator, "generator_additional_non_configuration_keys", []
1999
+ )
2000
+ generator_additional_path_sections = getattr(
2001
+ xcode_generator, "generator_additional_path_sections", []
2002
+ )
2003
+ global generator_extra_sources_for_rules
2004
+ generator_extra_sources_for_rules = getattr(
2005
+ xcode_generator, "generator_extra_sources_for_rules", []
2006
+ )
2007
+ elif flavor == "win":
2008
+ exts = gyp.MSVSUtil.TARGET_TYPE_EXT
2009
+ default_variables.setdefault("OS", "win")
2010
+ default_variables["EXECUTABLE_SUFFIX"] = "." + exts["executable"]
2011
+ default_variables["STATIC_LIB_PREFIX"] = ""
2012
+ default_variables["STATIC_LIB_SUFFIX"] = "." + exts["static_library"]
2013
+ default_variables["SHARED_LIB_PREFIX"] = ""
2014
+ default_variables["SHARED_LIB_SUFFIX"] = "." + exts["shared_library"]
2015
+
2016
+ # Copy additional generator configuration data from VS, which is shared
2017
+ # by the Windows Ninja generator.
2018
+ import gyp.generator.msvs as msvs_generator # noqa: PLC0415
2019
+
2020
+ generator_additional_non_configuration_keys = getattr(
2021
+ msvs_generator, "generator_additional_non_configuration_keys", []
2022
+ )
2023
+ generator_additional_path_sections = getattr(
2024
+ msvs_generator, "generator_additional_path_sections", []
2025
+ )
2026
+
2027
+ gyp.msvs_emulation.CalculateCommonVariables(default_variables, params)
2028
+ else:
2029
+ operating_system = flavor
2030
+ if flavor == "android":
2031
+ operating_system = "linux" # Keep this legacy behavior for now.
2032
+ default_variables.setdefault("OS", operating_system)
2033
+ default_variables.setdefault("SHARED_LIB_SUFFIX", ".so")
2034
+ default_variables.setdefault(
2035
+ "SHARED_LIB_DIR", os.path.join("$!PRODUCT_DIR", "lib")
2036
+ )
2037
+ default_variables.setdefault("LIB_DIR", os.path.join("$!PRODUCT_DIR", "obj"))
2038
+
2039
+
2040
+ def ComputeOutputDir(params):
2041
+ """Returns the path from the toplevel_dir to the build output directory."""
2042
+ # generator_dir: relative path from pwd to where make puts build files.
2043
+ # Makes migrating from make to ninja easier, ninja doesn't put anything here.
2044
+ generator_dir = os.path.relpath(params["options"].generator_output or ".")
2045
+
2046
+ # output_dir: relative path from generator_dir to the build directory.
2047
+ output_dir = params.get("generator_flags", {}).get("output_dir", "out")
2048
+
2049
+ # Relative path from source root to our output files. e.g. "out"
2050
+ return os.path.normpath(os.path.join(generator_dir, output_dir))
2051
+
2052
+
2053
+ def CalculateGeneratorInputInfo(params):
2054
+ """Called by __init__ to initialize generator values based on params."""
2055
+ # E.g. "out/gypfiles"
2056
+ toplevel = params["options"].toplevel_dir
2057
+ qualified_out_dir = os.path.normpath(
2058
+ os.path.join(toplevel, ComputeOutputDir(params), "gypfiles")
2059
+ )
2060
+
2061
+ global generator_filelist_paths
2062
+ generator_filelist_paths = {
2063
+ "toplevel": toplevel,
2064
+ "qualified_out_dir": qualified_out_dir,
2065
+ }
2066
+
2067
+
2068
+ def OpenOutput(path, mode="w"):
2069
+ """Open |path| for writing, creating directories if necessary."""
2070
+ gyp.common.EnsureDirExists(path)
2071
+ return open(path, mode)
2072
+
2073
+
2074
+ def CommandWithWrapper(cmd, wrappers, prog):
2075
+ if wrapper := wrappers.get(cmd, ""):
2076
+ return wrapper + " " + prog
2077
+ return prog
2078
+
2079
+
2080
+ def GetDefaultConcurrentLinks():
2081
+ """Returns a best-guess for a number of concurrent links."""
2082
+ if pool_size := int(os.environ.get("GYP_LINK_CONCURRENCY") or 0):
2083
+ return pool_size
2084
+
2085
+ if sys.platform in ("win32", "cygwin"):
2086
+
2087
+ class MEMORYSTATUSEX(ctypes.Structure):
2088
+ _fields_ = [
2089
+ ("dwLength", ctypes.c_ulong),
2090
+ ("dwMemoryLoad", ctypes.c_ulong),
2091
+ ("ullTotalPhys", ctypes.c_ulonglong),
2092
+ ("ullAvailPhys", ctypes.c_ulonglong),
2093
+ ("ullTotalPageFile", ctypes.c_ulonglong),
2094
+ ("ullAvailPageFile", ctypes.c_ulonglong),
2095
+ ("ullTotalVirtual", ctypes.c_ulonglong),
2096
+ ("ullAvailVirtual", ctypes.c_ulonglong),
2097
+ ("sullAvailExtendedVirtual", ctypes.c_ulonglong),
2098
+ ]
2099
+
2100
+ stat = MEMORYSTATUSEX()
2101
+ stat.dwLength = ctypes.sizeof(stat)
2102
+ ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat))
2103
+
2104
+ # VS 2015 uses 20% more working set than VS 2013 and can consume all RAM
2105
+ # on a 64 GiB machine.
2106
+ mem_limit = max(1, stat.ullTotalPhys // (5 * (2**30))) # total / 5GiB
2107
+ hard_cap = max(1, int(os.environ.get("GYP_LINK_CONCURRENCY_MAX") or 2**32))
2108
+ return min(mem_limit, hard_cap)
2109
+ elif sys.platform.startswith("linux"):
2110
+ if os.path.exists("/proc/meminfo"):
2111
+ with open("/proc/meminfo") as meminfo:
2112
+ memtotal_re = re.compile(r"^MemTotal:\s*(\d*)\s*kB")
2113
+ for line in meminfo:
2114
+ match = memtotal_re.match(line)
2115
+ if not match:
2116
+ continue
2117
+ # Allow 8Gb per link on Linux because Gold is quite memory hungry
2118
+ return max(1, int(match.group(1)) // (8 * (2**20)))
2119
+ return 1
2120
+ elif sys.platform == "darwin":
2121
+ try:
2122
+ avail_bytes = int(subprocess.check_output(["sysctl", "-n", "hw.memsize"]))
2123
+ # A static library debug build of Chromium's unit_tests takes ~2.7GB, so
2124
+ # 4GB per ld process allows for some more bloat.
2125
+ return max(1, avail_bytes // (4 * (2**30))) # total / 4GB
2126
+ except subprocess.CalledProcessError:
2127
+ return 1
2128
+ else:
2129
+ # TODO(scottmg): Implement this for other platforms.
2130
+ return 1
2131
+
2132
+
2133
+ def _GetWinLinkRuleNameSuffix(embed_manifest):
2134
+ """Returns the suffix used to select an appropriate linking rule depending on
2135
+ whether the manifest embedding is enabled."""
2136
+ return "_embed" if embed_manifest else ""
2137
+
2138
+
2139
+ def _AddWinLinkRules(master_ninja, embed_manifest):
2140
+ """Adds link rules for Windows platform to |master_ninja|."""
2141
+
2142
+ def FullLinkCommand(ldcmd, out, binary_type):
2143
+ resource_name = {"exe": "1", "dll": "2"}[binary_type]
2144
+ return (
2145
+ "%(python)s gyp-win-tool link-with-manifests $arch %(embed)s "
2146
+ '%(out)s "%(ldcmd)s" %(resname)s $mt $rc "$intermediatemanifest" '
2147
+ "$manifests"
2148
+ % {
2149
+ "python": sys.executable,
2150
+ "out": out,
2151
+ "ldcmd": ldcmd,
2152
+ "resname": resource_name,
2153
+ "embed": embed_manifest,
2154
+ }
2155
+ )
2156
+
2157
+ rule_name_suffix = _GetWinLinkRuleNameSuffix(embed_manifest)
2158
+ use_separate_mspdbsrv = int(os.environ.get("GYP_USE_SEPARATE_MSPDBSRV", "0")) != 0
2159
+ dlldesc = "LINK%s(DLL) $binary" % rule_name_suffix.upper()
2160
+ dllcmd = (
2161
+ "%s gyp-win-tool link-wrapper $arch %s "
2162
+ "$ld /nologo $implibflag /DLL /OUT:$binary "
2163
+ "@$binary.rsp" % (sys.executable, use_separate_mspdbsrv)
2164
+ )
2165
+ dllcmd = FullLinkCommand(dllcmd, "$binary", "dll")
2166
+ master_ninja.rule(
2167
+ "solink" + rule_name_suffix,
2168
+ description=dlldesc,
2169
+ command=dllcmd,
2170
+ rspfile="$binary.rsp",
2171
+ rspfile_content="$libs $in_newline $ldflags",
2172
+ restat=True,
2173
+ pool="link_pool",
2174
+ )
2175
+ master_ninja.rule(
2176
+ "solink_module" + rule_name_suffix,
2177
+ description=dlldesc,
2178
+ command=dllcmd,
2179
+ rspfile="$binary.rsp",
2180
+ rspfile_content="$libs $in_newline $ldflags",
2181
+ restat=True,
2182
+ pool="link_pool",
2183
+ )
2184
+ # Note that ldflags goes at the end so that it has the option of
2185
+ # overriding default settings earlier in the command line.
2186
+ exe_cmd = (
2187
+ "%s gyp-win-tool link-wrapper $arch %s "
2188
+ "$ld /nologo /OUT:$binary @$binary.rsp"
2189
+ % (sys.executable, use_separate_mspdbsrv)
2190
+ )
2191
+ exe_cmd = FullLinkCommand(exe_cmd, "$binary", "exe")
2192
+ master_ninja.rule(
2193
+ "link" + rule_name_suffix,
2194
+ description="LINK%s $binary" % rule_name_suffix.upper(),
2195
+ command=exe_cmd,
2196
+ rspfile="$binary.rsp",
2197
+ rspfile_content="$in_newline $libs $ldflags",
2198
+ pool="link_pool",
2199
+ )
2200
+
2201
+
2202
+ def GenerateOutputForConfig(target_list, target_dicts, data, params, config_name):
2203
+ options = params["options"]
2204
+ flavor = gyp.common.GetFlavor(params)
2205
+ generator_flags = params.get("generator_flags", {})
2206
+ generate_compile_commands = generator_flags.get("compile_commands", False)
2207
+
2208
+ # build_dir: relative path from source root to our output files.
2209
+ # e.g. "out/Debug"
2210
+ build_dir = os.path.normpath(os.path.join(ComputeOutputDir(params), config_name))
2211
+
2212
+ toplevel_build = os.path.join(options.toplevel_dir, build_dir)
2213
+
2214
+ master_ninja_file = OpenOutput(os.path.join(toplevel_build, "build.ninja"))
2215
+ master_ninja = ninja_syntax.Writer(master_ninja_file, width=120)
2216
+
2217
+ # Put build-time support tools in out/{config_name}.
2218
+ gyp.common.CopyTool(flavor, toplevel_build, generator_flags)
2219
+
2220
+ # Grab make settings for CC/CXX.
2221
+ # The rules are
2222
+ # - The priority from low to high is gcc/g++, the 'make_global_settings' in
2223
+ # gyp, the environment variable.
2224
+ # - If there is no 'make_global_settings' for CC.host/CXX.host or
2225
+ # 'CC_host'/'CXX_host' environment variable, cc_host/cxx_host should be set
2226
+ # to cc/cxx.
2227
+ if flavor == "win":
2228
+ ar = "lib.exe"
2229
+ # cc and cxx must be set to the correct architecture by overriding with one
2230
+ # of cl_x86 or cl_x64 below.
2231
+ cc = "UNSET"
2232
+ cxx = "UNSET"
2233
+ ld = "link.exe"
2234
+ ld_host = "$ld"
2235
+ else:
2236
+ ar = "ar"
2237
+ cc = "cc"
2238
+ cxx = "c++"
2239
+ ld = "$cc"
2240
+ ldxx = "$cxx"
2241
+ ld_host = "$cc_host"
2242
+ ldxx_host = "$cxx_host"
2243
+
2244
+ ar_host = ar
2245
+ cc_host = None
2246
+ cxx_host = None
2247
+ cc_host_global_setting = None
2248
+ cxx_host_global_setting = None
2249
+ clang_cl = None
2250
+ nm = "nm"
2251
+ nm_host = "nm"
2252
+ readelf = "readelf"
2253
+ readelf_host = "readelf"
2254
+
2255
+ build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
2256
+ make_global_settings = data[build_file].get("make_global_settings", [])
2257
+ build_to_root = gyp.common.InvertRelativePath(build_dir, options.toplevel_dir)
2258
+ wrappers = {}
2259
+ for key, value in make_global_settings:
2260
+ if key == "AR":
2261
+ ar = os.path.join(build_to_root, value)
2262
+ if key == "AR.host":
2263
+ ar_host = os.path.join(build_to_root, value)
2264
+ if key == "CC":
2265
+ cc = os.path.join(build_to_root, value)
2266
+ if cc.endswith("clang-cl"):
2267
+ clang_cl = cc
2268
+ if key == "CXX":
2269
+ cxx = os.path.join(build_to_root, value)
2270
+ if key == "CC.host":
2271
+ cc_host = os.path.join(build_to_root, value)
2272
+ cc_host_global_setting = value
2273
+ if key == "CXX.host":
2274
+ cxx_host = os.path.join(build_to_root, value)
2275
+ cxx_host_global_setting = value
2276
+ if key == "LD":
2277
+ ld = os.path.join(build_to_root, value)
2278
+ if key == "LD.host":
2279
+ ld_host = os.path.join(build_to_root, value)
2280
+ if key == "LDXX":
2281
+ ldxx = os.path.join(build_to_root, value)
2282
+ if key == "LDXX.host":
2283
+ ldxx_host = os.path.join(build_to_root, value)
2284
+ if key == "NM":
2285
+ nm = os.path.join(build_to_root, value)
2286
+ if key == "NM.host":
2287
+ nm_host = os.path.join(build_to_root, value)
2288
+ if key == "READELF":
2289
+ readelf = os.path.join(build_to_root, value)
2290
+ if key == "READELF.host":
2291
+ readelf_host = os.path.join(build_to_root, value)
2292
+ if key.endswith("_wrapper"):
2293
+ wrappers[key[: -len("_wrapper")]] = os.path.join(build_to_root, value)
2294
+
2295
+ # Support wrappers from environment variables too.
2296
+ for key, value in os.environ.items():
2297
+ if key.lower().endswith("_wrapper"):
2298
+ key_prefix = key[: -len("_wrapper")]
2299
+ key_prefix = re.sub(r"\.HOST$", ".host", key_prefix)
2300
+ wrappers[key_prefix] = os.path.join(build_to_root, value)
2301
+
2302
+ if mac_toolchain_dir := generator_flags.get("mac_toolchain_dir", None):
2303
+ wrappers["LINK"] = "export DEVELOPER_DIR='%s' &&" % mac_toolchain_dir
2304
+
2305
+ if flavor == "win":
2306
+ configs = [
2307
+ target_dicts[qualified_target]["configurations"][config_name]
2308
+ for qualified_target in target_list
2309
+ ]
2310
+ shared_system_includes = None
2311
+ if not generator_flags.get("ninja_use_custom_environment_files", 0):
2312
+ shared_system_includes = gyp.msvs_emulation.ExtractSharedMSVSSystemIncludes(
2313
+ configs, generator_flags
2314
+ )
2315
+ cl_paths = gyp.msvs_emulation.GenerateEnvironmentFiles(
2316
+ toplevel_build, generator_flags, shared_system_includes, OpenOutput
2317
+ )
2318
+ for arch, path in sorted(cl_paths.items()):
2319
+ if clang_cl:
2320
+ # If we have selected clang-cl, use that instead.
2321
+ path = clang_cl
2322
+ command = CommandWithWrapper(
2323
+ "CC", wrappers, QuoteShellArgument(path, "win")
2324
+ )
2325
+ if clang_cl:
2326
+ # Use clang-cl to cross-compile for x86 or x86_64.
2327
+ command += " -m32" if arch == "x86" else " -m64"
2328
+ master_ninja.variable("cl_" + arch, command)
2329
+
2330
+ cc = GetEnvironFallback(["CC_target", "CC"], cc)
2331
+ master_ninja.variable("cc", CommandWithWrapper("CC", wrappers, cc))
2332
+ cxx = GetEnvironFallback(["CXX_target", "CXX"], cxx)
2333
+ master_ninja.variable("cxx", CommandWithWrapper("CXX", wrappers, cxx))
2334
+
2335
+ if flavor == "win":
2336
+ master_ninja.variable("ld", ld)
2337
+ master_ninja.variable("idl", "midl.exe")
2338
+ master_ninja.variable("ar", ar)
2339
+ master_ninja.variable("rc", "rc.exe")
2340
+ master_ninja.variable("ml_x86", "ml.exe")
2341
+ master_ninja.variable("ml_x64", "ml64.exe")
2342
+ master_ninja.variable("mt", "mt.exe")
2343
+ else:
2344
+ master_ninja.variable("ld", CommandWithWrapper("LINK", wrappers, ld))
2345
+ master_ninja.variable("ldxx", CommandWithWrapper("LINK", wrappers, ldxx))
2346
+ master_ninja.variable("ar", GetEnvironFallback(["AR_target", "AR"], ar))
2347
+ if flavor != "mac":
2348
+ # Mac does not use readelf/nm for .TOC generation, so avoiding polluting
2349
+ # the master ninja with extra unused variables.
2350
+ master_ninja.variable("nm", GetEnvironFallback(["NM_target", "NM"], nm))
2351
+ master_ninja.variable(
2352
+ "readelf", GetEnvironFallback(["READELF_target", "READELF"], readelf)
2353
+ )
2354
+
2355
+ if generator_supports_multiple_toolsets:
2356
+ if not cc_host:
2357
+ cc_host = cc
2358
+ if not cxx_host:
2359
+ cxx_host = cxx
2360
+
2361
+ master_ninja.variable("ar_host", GetEnvironFallback(["AR_host"], ar_host))
2362
+ master_ninja.variable("nm_host", GetEnvironFallback(["NM_host"], nm_host))
2363
+ master_ninja.variable(
2364
+ "readelf_host", GetEnvironFallback(["READELF_host"], readelf_host)
2365
+ )
2366
+ cc_host = GetEnvironFallback(["CC_host"], cc_host)
2367
+ cxx_host = GetEnvironFallback(["CXX_host"], cxx_host)
2368
+
2369
+ # The environment variable could be used in 'make_global_settings', like
2370
+ # ['CC.host', '$(CC)'] or ['CXX.host', '$(CXX)'], transform them here.
2371
+ if "$(CC)" in cc_host and cc_host_global_setting:
2372
+ cc_host = cc_host_global_setting.replace("$(CC)", cc)
2373
+ if "$(CXX)" in cxx_host and cxx_host_global_setting:
2374
+ cxx_host = cxx_host_global_setting.replace("$(CXX)", cxx)
2375
+ master_ninja.variable(
2376
+ "cc_host", CommandWithWrapper("CC.host", wrappers, cc_host)
2377
+ )
2378
+ master_ninja.variable(
2379
+ "cxx_host", CommandWithWrapper("CXX.host", wrappers, cxx_host)
2380
+ )
2381
+ if flavor == "win":
2382
+ master_ninja.variable("ld_host", ld_host)
2383
+ else:
2384
+ master_ninja.variable(
2385
+ "ld_host", CommandWithWrapper("LINK", wrappers, ld_host)
2386
+ )
2387
+ master_ninja.variable(
2388
+ "ldxx_host", CommandWithWrapper("LINK", wrappers, ldxx_host)
2389
+ )
2390
+
2391
+ master_ninja.newline()
2392
+
2393
+ master_ninja.pool("link_pool", depth=GetDefaultConcurrentLinks())
2394
+ master_ninja.newline()
2395
+
2396
+ deps = "msvc" if flavor == "win" else "gcc"
2397
+
2398
+ if flavor != "win":
2399
+ master_ninja.rule(
2400
+ "cc",
2401
+ description="CC $out",
2402
+ command=(
2403
+ "$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c "
2404
+ "$cflags_pch_c -c $in -o $out"
2405
+ ),
2406
+ depfile="$out.d",
2407
+ deps=deps,
2408
+ )
2409
+ master_ninja.rule(
2410
+ "cc_s",
2411
+ description="CC $out",
2412
+ command=(
2413
+ "$cc $defines $includes $cflags $cflags_c $cflags_pch_c -c $in -o $out"
2414
+ ),
2415
+ )
2416
+ master_ninja.rule(
2417
+ "cxx",
2418
+ description="CXX $out",
2419
+ command=(
2420
+ "$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_cc "
2421
+ "$cflags_pch_cc -c $in -o $out"
2422
+ ),
2423
+ depfile="$out.d",
2424
+ deps=deps,
2425
+ )
2426
+ else:
2427
+ # TODO(scottmg) Separate pdb names is a test to see if it works around
2428
+ # http://crbug.com/142362. It seems there's a race between the creation of
2429
+ # the .pdb by the precompiled header step for .cc and the compilation of
2430
+ # .c files. This should be handled by mspdbsrv, but rarely errors out with
2431
+ # c1xx : fatal error C1033: cannot open program database
2432
+ # By making the rules target separate pdb files this might be avoided.
2433
+ cc_command = (
2434
+ "ninja -t msvc -e $arch " + "-- "
2435
+ "$cc /nologo /showIncludes /FC "
2436
+ "@$out.rsp /c $in /Fo$out /Fd$pdbname_c "
2437
+ )
2438
+ cxx_command = (
2439
+ "ninja -t msvc -e $arch " + "-- "
2440
+ "$cxx /nologo /showIncludes /FC "
2441
+ "@$out.rsp /c $in /Fo$out /Fd$pdbname_cc "
2442
+ )
2443
+ master_ninja.rule(
2444
+ "cc",
2445
+ description="CC $out",
2446
+ command=cc_command,
2447
+ rspfile="$out.rsp",
2448
+ rspfile_content="$defines $includes $cflags $cflags_c",
2449
+ deps=deps,
2450
+ )
2451
+ master_ninja.rule(
2452
+ "cxx",
2453
+ description="CXX $out",
2454
+ command=cxx_command,
2455
+ rspfile="$out.rsp",
2456
+ rspfile_content="$defines $includes $cflags $cflags_cc",
2457
+ deps=deps,
2458
+ )
2459
+ master_ninja.rule(
2460
+ "idl",
2461
+ description="IDL $in",
2462
+ command=(
2463
+ "%s gyp-win-tool midl-wrapper $arch $outdir "
2464
+ "$tlb $h $dlldata $iid $proxy $in "
2465
+ "$midl_includes $idlflags" % sys.executable
2466
+ ),
2467
+ )
2468
+ master_ninja.rule(
2469
+ "rc",
2470
+ description="RC $in",
2471
+ # Note: $in must be last otherwise rc.exe complains.
2472
+ command=(
2473
+ "%s gyp-win-tool rc-wrapper "
2474
+ "$arch $rc $defines $resource_includes $rcflags /fo$out $in"
2475
+ % sys.executable
2476
+ ),
2477
+ )
2478
+ master_ninja.rule(
2479
+ "asm",
2480
+ description="ASM $out",
2481
+ command=(
2482
+ "%s gyp-win-tool asm-wrapper "
2483
+ "$arch $asm $defines $includes $asmflags /c /Fo $out $in"
2484
+ % sys.executable
2485
+ ),
2486
+ )
2487
+
2488
+ if flavor not in ("ios", "mac", "win"):
2489
+ master_ninja.rule(
2490
+ "alink",
2491
+ description="AR $out",
2492
+ command="rm -f $out && $ar rcs $arflags $out $in",
2493
+ )
2494
+ master_ninja.rule(
2495
+ "alink_thin",
2496
+ description="AR $out",
2497
+ command="rm -f $out && $ar rcsT $arflags $out $in",
2498
+ )
2499
+
2500
+ # This allows targets that only need to depend on $lib's API to declare an
2501
+ # order-only dependency on $lib.TOC and avoid relinking such downstream
2502
+ # dependencies when $lib changes only in non-public ways.
2503
+ # The resulting string leaves an uninterpolated %{suffix} which
2504
+ # is used in the final substitution below.
2505
+ mtime_preserving_solink_base = (
2506
+ "if [ ! -e $lib -o ! -e $lib.TOC ]; then "
2507
+ "%(solink)s && %(extract_toc)s > $lib.TOC; else "
2508
+ "%(solink)s && %(extract_toc)s > $lib.tmp && "
2509
+ "if ! cmp -s $lib.tmp $lib.TOC; then mv $lib.tmp $lib.TOC ; "
2510
+ "fi; fi"
2511
+ % {
2512
+ "solink": "$ld -shared $ldflags -o $lib -Wl,-soname=$soname %(suffix)s",
2513
+ "extract_toc": (
2514
+ "{ $readelf -d $lib | grep SONAME ; "
2515
+ "$nm -gD -f p $lib | cut -f1-2 -d' '; }"
2516
+ ),
2517
+ }
2518
+ )
2519
+
2520
+ master_ninja.rule(
2521
+ "solink",
2522
+ description="SOLINK $lib",
2523
+ restat=True,
2524
+ command=mtime_preserving_solink_base % {"suffix": "@$link_file_list"},
2525
+ rspfile="$link_file_list",
2526
+ rspfile_content=(
2527
+ "-Wl,--whole-archive $in $solibs -Wl,--no-whole-archive $libs"
2528
+ ),
2529
+ pool="link_pool",
2530
+ )
2531
+ master_ninja.rule(
2532
+ "solink_module",
2533
+ description="SOLINK(module) $lib",
2534
+ restat=True,
2535
+ command=mtime_preserving_solink_base % {"suffix": "@$link_file_list"},
2536
+ rspfile="$link_file_list",
2537
+ rspfile_content="-Wl,--start-group $in $solibs $libs -Wl,--end-group",
2538
+ pool="link_pool",
2539
+ )
2540
+ master_ninja.rule(
2541
+ "link",
2542
+ description="LINK $out",
2543
+ command=(
2544
+ "$ld $ldflags -o $out "
2545
+ "-Wl,--start-group $in $solibs $libs -Wl,--end-group"
2546
+ ),
2547
+ pool="link_pool",
2548
+ )
2549
+ elif flavor == "win":
2550
+ master_ninja.rule(
2551
+ "alink",
2552
+ description="LIB $out",
2553
+ command=(
2554
+ "%s gyp-win-tool link-wrapper $arch False "
2555
+ "$ar /nologo /ignore:4221 /OUT:$out @$out.rsp" % sys.executable
2556
+ ),
2557
+ rspfile="$out.rsp",
2558
+ rspfile_content="$in_newline $libflags",
2559
+ )
2560
+ _AddWinLinkRules(master_ninja, embed_manifest=True)
2561
+ _AddWinLinkRules(master_ninja, embed_manifest=False)
2562
+ else:
2563
+ master_ninja.rule(
2564
+ "objc",
2565
+ description="OBJC $out",
2566
+ command=(
2567
+ "$cc -MMD -MF $out.d $defines $includes $cflags $cflags_objc "
2568
+ "$cflags_pch_objc -c $in -o $out"
2569
+ ),
2570
+ depfile="$out.d",
2571
+ deps=deps,
2572
+ )
2573
+ master_ninja.rule(
2574
+ "objcxx",
2575
+ description="OBJCXX $out",
2576
+ command=(
2577
+ "$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_objcc "
2578
+ "$cflags_pch_objcc -c $in -o $out"
2579
+ ),
2580
+ depfile="$out.d",
2581
+ deps=deps,
2582
+ )
2583
+ master_ninja.rule(
2584
+ "alink",
2585
+ description="LIBTOOL-STATIC $out, POSTBUILDS",
2586
+ command="rm -f $out && "
2587
+ "%s gyp-mac-tool filter-libtool libtool $libtool_flags "
2588
+ "-static -o $out $in"
2589
+ "$postbuilds" % sys.executable,
2590
+ )
2591
+ master_ninja.rule(
2592
+ "lipo",
2593
+ description="LIPO $out, POSTBUILDS",
2594
+ command="rm -f $out && lipo -create $in -output $out$postbuilds",
2595
+ )
2596
+ master_ninja.rule(
2597
+ "solipo",
2598
+ description="SOLIPO $out, POSTBUILDS",
2599
+ command=(
2600
+ "rm -f $lib $lib.TOC && lipo -create $in -output $lib$postbuilds &&"
2601
+ "%(extract_toc)s > $lib.TOC"
2602
+ % {
2603
+ "extract_toc": "{ otool -l $lib | grep LC_ID_DYLIB -A 5; "
2604
+ "nm -gP $lib | cut -f1-2 -d' ' | grep -v U$$; true; }"
2605
+ }
2606
+ ),
2607
+ )
2608
+
2609
+ # Record the public interface of $lib in $lib.TOC. See the corresponding
2610
+ # comment in the posix section above for details.
2611
+ solink_base = "$ld %(type)s $ldflags -o $lib %(suffix)s"
2612
+ mtime_preserving_solink_base = (
2613
+ "if [ ! -e $lib -o ! -e $lib.TOC ] || "
2614
+ # Always force dependent targets to relink if this library
2615
+ # reexports something. Handling this correctly would require
2616
+ # recursive TOC dumping but this is rare in practice, so punt.
2617
+ "otool -l $lib | grep -q LC_REEXPORT_DYLIB ; then "
2618
+ "%(solink)s && %(extract_toc)s > $lib.TOC; "
2619
+ "else "
2620
+ "%(solink)s && %(extract_toc)s > $lib.tmp && "
2621
+ "if ! cmp -s $lib.tmp $lib.TOC; then "
2622
+ "mv $lib.tmp $lib.TOC ; "
2623
+ "fi; "
2624
+ "fi"
2625
+ % {
2626
+ "solink": solink_base,
2627
+ "extract_toc": "{ otool -l $lib | grep LC_ID_DYLIB -A 5; "
2628
+ "nm -gP $lib | cut -f1-2 -d' ' | grep -v U$$; true; }",
2629
+ }
2630
+ )
2631
+
2632
+ solink_suffix = "@$link_file_list$postbuilds"
2633
+ master_ninja.rule(
2634
+ "solink",
2635
+ description="SOLINK $lib, POSTBUILDS",
2636
+ restat=True,
2637
+ command=mtime_preserving_solink_base
2638
+ % {"suffix": solink_suffix, "type": "-shared"},
2639
+ rspfile="$link_file_list",
2640
+ rspfile_content="$in $solibs $libs",
2641
+ pool="link_pool",
2642
+ )
2643
+ master_ninja.rule(
2644
+ "solink_notoc",
2645
+ description="SOLINK $lib, POSTBUILDS",
2646
+ restat=True,
2647
+ command=solink_base % {"suffix": solink_suffix, "type": "-shared"},
2648
+ rspfile="$link_file_list",
2649
+ rspfile_content="$in $solibs $libs",
2650
+ pool="link_pool",
2651
+ )
2652
+
2653
+ master_ninja.rule(
2654
+ "solink_module",
2655
+ description="SOLINK(module) $lib, POSTBUILDS",
2656
+ restat=True,
2657
+ command=mtime_preserving_solink_base
2658
+ % {"suffix": solink_suffix, "type": "-bundle"},
2659
+ rspfile="$link_file_list",
2660
+ rspfile_content="$in $solibs $libs",
2661
+ pool="link_pool",
2662
+ )
2663
+ master_ninja.rule(
2664
+ "solink_module_notoc",
2665
+ description="SOLINK(module) $lib, POSTBUILDS",
2666
+ restat=True,
2667
+ command=solink_base % {"suffix": solink_suffix, "type": "-bundle"},
2668
+ rspfile="$link_file_list",
2669
+ rspfile_content="$in $solibs $libs",
2670
+ pool="link_pool",
2671
+ )
2672
+
2673
+ master_ninja.rule(
2674
+ "link",
2675
+ description="LINK $out, POSTBUILDS",
2676
+ command=("$ld $ldflags -o $out $in $solibs $libs$postbuilds"),
2677
+ pool="link_pool",
2678
+ )
2679
+ master_ninja.rule(
2680
+ "preprocess_infoplist",
2681
+ description="PREPROCESS INFOPLIST $out",
2682
+ command=(
2683
+ "$cc -E -P -Wno-trigraphs -x c $defines $in -o $out && "
2684
+ "plutil -convert xml1 $out $out"
2685
+ ),
2686
+ )
2687
+ master_ninja.rule(
2688
+ "copy_infoplist",
2689
+ description="COPY INFOPLIST $in",
2690
+ command="$env %s gyp-mac-tool copy-info-plist $in $out $binary $keys"
2691
+ % sys.executable,
2692
+ )
2693
+ master_ninja.rule(
2694
+ "merge_infoplist",
2695
+ description="MERGE INFOPLISTS $in",
2696
+ command="$env %s gyp-mac-tool merge-info-plist $out $in" % sys.executable,
2697
+ )
2698
+ master_ninja.rule(
2699
+ "compile_xcassets",
2700
+ description="COMPILE XCASSETS $in",
2701
+ command="$env %s gyp-mac-tool compile-xcassets $keys $in" % sys.executable,
2702
+ )
2703
+ master_ninja.rule(
2704
+ "compile_ios_framework_headers",
2705
+ description="COMPILE HEADER MAPS AND COPY FRAMEWORK HEADERS $in",
2706
+ command="$env %(python)s gyp-mac-tool compile-ios-framework-header-map "
2707
+ "$out $framework $in && $env %(python)s gyp-mac-tool "
2708
+ "copy-ios-framework-headers $framework $copy_headers"
2709
+ % {"python": sys.executable},
2710
+ )
2711
+ master_ninja.rule(
2712
+ "mac_tool",
2713
+ description="MACTOOL $mactool_cmd $in",
2714
+ command="$env %s gyp-mac-tool $mactool_cmd $in $out $binary"
2715
+ % sys.executable,
2716
+ )
2717
+ master_ninja.rule(
2718
+ "package_framework",
2719
+ description="PACKAGE FRAMEWORK $out, POSTBUILDS",
2720
+ command="%s gyp-mac-tool package-framework $out $version$postbuilds "
2721
+ "&& touch $out" % sys.executable,
2722
+ )
2723
+ master_ninja.rule(
2724
+ "package_ios_framework",
2725
+ description="PACKAGE IOS FRAMEWORK $out, POSTBUILDS",
2726
+ command="%s gyp-mac-tool package-ios-framework $out $postbuilds "
2727
+ "&& touch $out" % sys.executable,
2728
+ )
2729
+ if flavor == "win":
2730
+ master_ninja.rule(
2731
+ "stamp",
2732
+ description="STAMP $out",
2733
+ command="%s gyp-win-tool stamp $out" % sys.executable,
2734
+ )
2735
+ else:
2736
+ master_ninja.rule(
2737
+ "stamp", description="STAMP $out", command="${postbuilds}touch $out"
2738
+ )
2739
+ if flavor == "win":
2740
+ master_ninja.rule(
2741
+ "copy",
2742
+ description="COPY $in $out",
2743
+ command="%s gyp-win-tool recursive-mirror $in $out" % sys.executable,
2744
+ )
2745
+ elif flavor == "zos":
2746
+ master_ninja.rule(
2747
+ "copy",
2748
+ description="COPY $in $out",
2749
+ command="rm -rf $out && cp -fRP $in $out",
2750
+ )
2751
+ else:
2752
+ master_ninja.rule(
2753
+ "copy",
2754
+ description="COPY $in $out",
2755
+ command="ln -f $in $out 2>/dev/null || (rm -rf $out && cp -af $in $out)",
2756
+ )
2757
+ master_ninja.newline()
2758
+
2759
+ all_targets = set()
2760
+ for build_file in params["build_files"]:
2761
+ for target in gyp.common.AllTargets(
2762
+ target_list, target_dicts, os.path.normpath(build_file)
2763
+ ):
2764
+ all_targets.add(target)
2765
+ all_outputs = set()
2766
+
2767
+ # target_outputs is a map from qualified target name to a Target object.
2768
+ target_outputs = {}
2769
+ # target_short_names is a map from target short name to a list of Target
2770
+ # objects.
2771
+ target_short_names = {}
2772
+
2773
+ # short name of targets that were skipped because they didn't contain anything
2774
+ # interesting.
2775
+ # NOTE: there may be overlap between this an non_empty_target_names.
2776
+ empty_target_names = set()
2777
+
2778
+ # Set of non-empty short target names.
2779
+ # NOTE: there may be overlap between this an empty_target_names.
2780
+ non_empty_target_names = set()
2781
+
2782
+ for qualified_target in target_list:
2783
+ # qualified_target is like: third_party/icu/icu.gyp:icui18n#target
2784
+ build_file, name, toolset = gyp.common.ParseQualifiedTarget(qualified_target)
2785
+
2786
+ this_make_global_settings = data[build_file].get("make_global_settings", [])
2787
+ assert make_global_settings == this_make_global_settings, (
2788
+ "make_global_settings needs to be the same for all targets. "
2789
+ f"{this_make_global_settings} vs. {make_global_settings}"
2790
+ )
2791
+
2792
+ spec = target_dicts[qualified_target]
2793
+ if flavor == "mac":
2794
+ gyp.xcode_emulation.MergeGlobalXcodeSettingsToSpec(data[build_file], spec)
2795
+
2796
+ # If build_file is a symlink, we must not follow it because there's a chance
2797
+ # it could point to a path above toplevel_dir, and we cannot correctly deal
2798
+ # with that case at the moment.
2799
+ build_file = gyp.common.RelativePath(build_file, options.toplevel_dir, False)
2800
+
2801
+ qualified_target_for_hash = gyp.common.QualifiedTarget(
2802
+ build_file, name, toolset
2803
+ )
2804
+ qualified_target_for_hash = qualified_target_for_hash.encode("utf-8")
2805
+ hash_for_rules = hashlib.sha256(qualified_target_for_hash).hexdigest()
2806
+
2807
+ base_path = os.path.dirname(build_file)
2808
+ obj = "obj"
2809
+ if toolset != "target":
2810
+ obj += "." + toolset
2811
+ output_file = os.path.join(obj, base_path, name + ".ninja")
2812
+
2813
+ ninja_output = StringIO()
2814
+ writer = NinjaWriter(
2815
+ hash_for_rules,
2816
+ target_outputs,
2817
+ base_path,
2818
+ build_dir,
2819
+ ninja_output,
2820
+ toplevel_build,
2821
+ output_file,
2822
+ flavor,
2823
+ toplevel_dir=options.toplevel_dir,
2824
+ )
2825
+
2826
+ target = writer.WriteSpec(spec, config_name, generator_flags)
2827
+
2828
+ if ninja_output.tell() > 0:
2829
+ # Only create files for ninja files that actually have contents.
2830
+ with OpenOutput(os.path.join(toplevel_build, output_file)) as ninja_file:
2831
+ ninja_file.write(ninja_output.getvalue())
2832
+ ninja_output.close()
2833
+ master_ninja.subninja(output_file)
2834
+
2835
+ if target:
2836
+ if name != target.FinalOutput() and spec["toolset"] == "target":
2837
+ target_short_names.setdefault(name, []).append(target)
2838
+ target_outputs[qualified_target] = target
2839
+ if qualified_target in all_targets:
2840
+ all_outputs.add(target.FinalOutput())
2841
+ non_empty_target_names.add(name)
2842
+ else:
2843
+ empty_target_names.add(name)
2844
+
2845
+ if target_short_names:
2846
+ # Write a short name to build this target. This benefits both the
2847
+ # "build chrome" case as well as the gyp tests, which expect to be
2848
+ # able to run actions and build libraries by their short name.
2849
+ master_ninja.newline()
2850
+ master_ninja.comment("Short names for targets.")
2851
+ for short_name in sorted(target_short_names):
2852
+ master_ninja.build(
2853
+ short_name,
2854
+ "phony",
2855
+ [x.FinalOutput() for x in target_short_names[short_name]],
2856
+ )
2857
+
2858
+ # Write phony targets for any empty targets that weren't written yet. As
2859
+ # short names are not necessarily unique only do this for short names that
2860
+ # haven't already been output for another target.
2861
+ empty_target_names = empty_target_names - non_empty_target_names
2862
+ if empty_target_names:
2863
+ master_ninja.newline()
2864
+ master_ninja.comment("Empty targets (output for completeness).")
2865
+ for name in sorted(empty_target_names):
2866
+ master_ninja.build(name, "phony")
2867
+
2868
+ if all_outputs:
2869
+ master_ninja.newline()
2870
+ master_ninja.build("all", "phony", sorted(all_outputs))
2871
+ master_ninja.default(generator_flags.get("default_target", "all"))
2872
+
2873
+ master_ninja_file.close()
2874
+
2875
+ if generate_compile_commands:
2876
+ compile_db = GenerateCompileDBWithNinja(toplevel_build)
2877
+ compile_db_file = OpenOutput(
2878
+ os.path.join(toplevel_build, "compile_commands.json")
2879
+ )
2880
+ compile_db_file.write(json.dumps(compile_db, indent=2))
2881
+ compile_db_file.close()
2882
+
2883
+
2884
+ def GenerateCompileDBWithNinja(path, targets=["all"]):
2885
+ """Generates a compile database using ninja.
2886
+
2887
+ Args:
2888
+ path: The build directory to generate a compile database for.
2889
+ targets: Additional targets to pass to ninja.
2890
+
2891
+ Returns:
2892
+ List of the contents of the compile database.
2893
+ """
2894
+ ninja_path = shutil.which("ninja")
2895
+ if ninja_path is None:
2896
+ raise Exception("ninja not found in PATH")
2897
+ json_compile_db = subprocess.check_output(
2898
+ [ninja_path, "-C", path]
2899
+ + targets
2900
+ + ["-t", "compdb", "cc", "cxx", "objc", "objcxx"]
2901
+ )
2902
+ return json.loads(json_compile_db)
2903
+
2904
+
2905
+ def PerformBuild(data, configurations, params):
2906
+ options = params["options"]
2907
+ for config in configurations:
2908
+ builddir = os.path.join(options.toplevel_dir, "out", config)
2909
+ arguments = ["ninja", "-C", builddir]
2910
+ print(f"Building [{config}]: {arguments}")
2911
+ subprocess.check_call(arguments)
2912
+
2913
+
2914
+ def CallGenerateOutputForConfig(arglist):
2915
+ # Ignore the interrupt signal so that the parent process catches it and
2916
+ # kills all multiprocessing children.
2917
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
2918
+
2919
+ (target_list, target_dicts, data, params, config_name) = arglist
2920
+ GenerateOutputForConfig(target_list, target_dicts, data, params, config_name)
2921
+
2922
+
2923
+ def GenerateOutput(target_list, target_dicts, data, params):
2924
+ # Update target_dicts for iOS device builds.
2925
+ target_dicts = gyp.xcode_emulation.CloneConfigurationForDeviceAndEmulator(
2926
+ target_dicts
2927
+ )
2928
+
2929
+ user_config = params.get("generator_flags", {}).get("config", None)
2930
+ if gyp.common.GetFlavor(params) == "win":
2931
+ target_list, target_dicts = MSVSUtil.ShardTargets(target_list, target_dicts)
2932
+ target_list, target_dicts = MSVSUtil.InsertLargePdbShims(
2933
+ target_list, target_dicts, generator_default_variables
2934
+ )
2935
+
2936
+ if user_config:
2937
+ GenerateOutputForConfig(target_list, target_dicts, data, params, user_config)
2938
+ else:
2939
+ config_names = target_dicts[target_list[0]]["configurations"]
2940
+ if params["parallel"]:
2941
+ try:
2942
+ pool = multiprocessing.Pool(len(config_names))
2943
+ arglists = []
2944
+ for config_name in config_names:
2945
+ arglists.append(
2946
+ (target_list, target_dicts, data, params, config_name)
2947
+ )
2948
+ pool.map(CallGenerateOutputForConfig, arglists)
2949
+ except KeyboardInterrupt as e:
2950
+ pool.terminate()
2951
+ raise e
2952
+ else:
2953
+ for config_name in config_names:
2954
+ GenerateOutputForConfig(
2955
+ target_list, target_dicts, data, params, config_name
2956
+ )