lounge_lizard 0.1.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 (348) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +33 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +50 -0
  10. data/Rakefile +43 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/circle.yml +14 -0
  14. data/ext/drafter/CHANGELOG.md +278 -0
  15. data/ext/drafter/Dockerfile +17 -0
  16. data/ext/drafter/Makefile +62 -0
  17. data/ext/drafter/appveyor.yml +17 -0
  18. data/ext/drafter/bin/drafter +0 -0
  19. data/ext/drafter/build/Makefile +387 -0
  20. data/ext/drafter/build/drafter.Makefile +6 -0
  21. data/ext/drafter/build/drafter.target.mk +159 -0
  22. data/ext/drafter/build/ext/snowcrash/libmarkdownparser.target.mk +141 -0
  23. data/ext/drafter/build/ext/snowcrash/libsnowcrash.target.mk +154 -0
  24. data/ext/drafter/build/ext/snowcrash/libsundown.target.mk +149 -0
  25. data/ext/drafter/build/ext/snowcrash/perf-libsnowcrash.target.mk +147 -0
  26. data/ext/drafter/build/ext/snowcrash/snowcrash.Makefile +6 -0
  27. data/ext/drafter/build/gyp-mac-tool +606 -0
  28. data/ext/drafter/build/libdrafter.target.mk +186 -0
  29. data/ext/drafter/build/libsos.target.mk +137 -0
  30. data/ext/drafter/build/out/Release/drafter +0 -0
  31. data/ext/drafter/build/out/Release/libdrafter.dylib +0 -0
  32. data/ext/drafter/build/out/Release/libmarkdownparser.a +0 -0
  33. data/ext/drafter/build/out/Release/libsnowcrash.a +0 -0
  34. data/ext/drafter/build/out/Release/libsos.a +0 -0
  35. data/ext/drafter/build/out/Release/libsundown.a +0 -0
  36. data/ext/drafter/build/out/Release/obj.target/drafter/src/config.o +0 -0
  37. data/ext/drafter/build/out/Release/obj.target/drafter/src/main.o +0 -0
  38. data/ext/drafter/build/out/Release/obj.target/drafter/src/reporting.o +0 -0
  39. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/ConversionContext.o +0 -0
  40. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/NamedTypesRegistry.o +0 -0
  41. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/RefractAPI.o +0 -0
  42. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/RefractDataStructure.o +0 -0
  43. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/RefractElementFactory.o +0 -0
  44. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/RefractSourceMap.o +0 -0
  45. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/Render.o +0 -0
  46. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/Serialize.o +0 -0
  47. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/SerializeAST.o +0 -0
  48. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/SerializeResult.o +0 -0
  49. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/SerializeSourcemap.o +0 -0
  50. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/drafter.o +0 -0
  51. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/drafter_private.o +0 -0
  52. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/ComparableVisitor.o +0 -0
  53. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/Element.o +0 -0
  54. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/ExpandVisitor.o +0 -0
  55. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/IsExpandableVisitor.o +0 -0
  56. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/JSONSchemaVisitor.o +0 -0
  57. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/PrintVisitor.o +0 -0
  58. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/Query.o +0 -0
  59. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/Registry.o +0 -0
  60. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/RenderJSONVisitor.o +0 -0
  61. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/SerializeCompactVisitor.o +0 -0
  62. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/SerializeVisitor.o +0 -0
  63. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/TypeQueryVisitor.o +0 -0
  64. data/ext/drafter/build/out/Release/obj.target/libdrafter/src/refract/VisitorUtils.o +0 -0
  65. data/ext/drafter/build/out/Release/obj.target/libmarkdownparser/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.o +0 -0
  66. data/ext/drafter/build/out/Release/obj.target/libmarkdownparser/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.o +0 -0
  67. data/ext/drafter/build/out/Release/obj.target/libmarkdownparser/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.o +0 -0
  68. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/Blueprint.o +0 -0
  69. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/BlueprintSourcemap.o +0 -0
  70. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/HTTP.o +0 -0
  71. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/HeadersParser.o +0 -0
  72. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSON.o +0 -0
  73. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSONOneOfParser.o +0 -0
  74. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSONSourcemap.o +0 -0
  75. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSONTypeSectionParser.o +0 -0
  76. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/MSONValueMemberParser.o +0 -0
  77. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/Section.o +0 -0
  78. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/Signature.o +0 -0
  79. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/UriTemplateParser.o +0 -0
  80. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/posix/RegexMatch.o +0 -0
  81. data/ext/drafter/build/out/Release/obj.target/libsnowcrash/ext/snowcrash/src/snowcrash.o +0 -0
  82. data/ext/drafter/build/out/Release/obj.target/libsos/ext/sos/src/sos.o +0 -0
  83. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_href_e.o +0 -0
  84. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.o +0 -0
  85. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html.o +0 -0
  86. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html_smartypants.o +0 -0
  87. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/autolink.o +0 -0
  88. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/buffer.o +0 -0
  89. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.o +0 -0
  90. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/src_map.o +0 -0
  91. data/ext/drafter/build/out/Release/obj.target/libsundown/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.o +0 -0
  92. data/ext/drafter/circle.yml +32 -0
  93. data/ext/drafter/config.gypi +10 -0
  94. data/ext/drafter/config.mk +5 -0
  95. data/ext/drafter/configure +224 -0
  96. data/ext/drafter/drafter.gyp +189 -0
  97. data/ext/drafter/drafter.xcworkspace/contents.xcworkspacedata +13 -0
  98. data/ext/drafter/ext/snowcrash/Makefile +58 -0
  99. data/ext/drafter/ext/snowcrash/appveyor.yml +7 -0
  100. data/ext/drafter/ext/snowcrash/common.gypi +165 -0
  101. data/ext/drafter/ext/snowcrash/configure +197 -0
  102. data/ext/drafter/ext/snowcrash/ext/markdown-parser/Makefile +90 -0
  103. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/CONTRIBUTING.md +10 -0
  104. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/Makefile +84 -0
  105. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/Makefile.win +33 -0
  106. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/examples/smartypants.c +72 -0
  107. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/examples/sundown.c +80 -0
  108. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini.h +37 -0
  109. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_href_e.c +108 -0
  110. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/houdini_html_e.c +84 -0
  111. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html.c +647 -0
  112. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html.h +77 -0
  113. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html/html_smartypants.c +389 -0
  114. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/html_block_names.txt +25 -0
  115. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/autolink.c +297 -0
  116. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/autolink.h +51 -0
  117. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/buffer.c +225 -0
  118. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/buffer.h +96 -0
  119. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/html_blocks.h +206 -0
  120. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.c +2726 -0
  121. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/markdown.h +147 -0
  122. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/src_map.c +204 -0
  123. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/src_map.h +58 -0
  124. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.c +81 -0
  125. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/src/stack.h +29 -0
  126. data/ext/drafter/ext/snowcrash/ext/markdown-parser/ext/sundown/sundown.def +20 -0
  127. data/ext/drafter/ext/snowcrash/ext/markdown-parser/msvc/markdown/markdown.vcproj +188 -0
  128. data/ext/drafter/ext/snowcrash/ext/markdown-parser/msvc/msvc.sln +38 -0
  129. data/ext/drafter/ext/snowcrash/ext/markdown-parser/msvc/sundown/sundown.vcproj +206 -0
  130. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.cc +160 -0
  131. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/ByteBuffer.h +90 -0
  132. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.cc +152 -0
  133. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownNode.h +103 -0
  134. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.cc +388 -0
  135. data/ext/drafter/ext/snowcrash/ext/markdown-parser/src/MarkdownParser.h +106 -0
  136. data/ext/drafter/ext/snowcrash/snowcrash.gyp +196 -0
  137. data/ext/drafter/ext/snowcrash/src/ActionParser.h +560 -0
  138. data/ext/drafter/ext/snowcrash/src/AssetParser.h +123 -0
  139. data/ext/drafter/ext/snowcrash/src/AttributesParser.h +123 -0
  140. data/ext/drafter/ext/snowcrash/src/Blueprint.cc +90 -0
  141. data/ext/drafter/ext/snowcrash/src/Blueprint.h +489 -0
  142. data/ext/drafter/ext/snowcrash/src/BlueprintParser.h +845 -0
  143. data/ext/drafter/ext/snowcrash/src/BlueprintSourcemap.cc +81 -0
  144. data/ext/drafter/ext/snowcrash/src/BlueprintSourcemap.h +345 -0
  145. data/ext/drafter/ext/snowcrash/src/BlueprintUtility.h +111 -0
  146. data/ext/drafter/ext/snowcrash/src/CodeBlockUtility.h +276 -0
  147. data/ext/drafter/ext/snowcrash/src/DataStructureGroupParser.h +157 -0
  148. data/ext/drafter/ext/snowcrash/src/HTTP.cc +49 -0
  149. data/ext/drafter/ext/snowcrash/src/HTTP.h +108 -0
  150. data/ext/drafter/ext/snowcrash/src/HeadersParser.cc +117 -0
  151. data/ext/drafter/ext/snowcrash/src/HeadersParser.h +377 -0
  152. data/ext/drafter/ext/snowcrash/src/MSON.cc +272 -0
  153. data/ext/drafter/ext/snowcrash/src/MSON.h +405 -0
  154. data/ext/drafter/ext/snowcrash/src/MSONMixinParser.h +103 -0
  155. data/ext/drafter/ext/snowcrash/src/MSONNamedTypeParser.h +135 -0
  156. data/ext/drafter/ext/snowcrash/src/MSONOneOfParser.cc +132 -0
  157. data/ext/drafter/ext/snowcrash/src/MSONOneOfParser.h +80 -0
  158. data/ext/drafter/ext/snowcrash/src/MSONParameterParser.h +166 -0
  159. data/ext/drafter/ext/snowcrash/src/MSONPropertyMemberParser.h +106 -0
  160. data/ext/drafter/ext/snowcrash/src/MSONSourcemap.cc +141 -0
  161. data/ext/drafter/ext/snowcrash/src/MSONSourcemap.h +181 -0
  162. data/ext/drafter/ext/snowcrash/src/MSONTypeSectionParser.cc +209 -0
  163. data/ext/drafter/ext/snowcrash/src/MSONTypeSectionParser.h +213 -0
  164. data/ext/drafter/ext/snowcrash/src/MSONUtility.h +506 -0
  165. data/ext/drafter/ext/snowcrash/src/MSONValueMemberParser.cc +214 -0
  166. data/ext/drafter/ext/snowcrash/src/MSONValueMemberParser.h +390 -0
  167. data/ext/drafter/ext/snowcrash/src/ModelTable.h +87 -0
  168. data/ext/drafter/ext/snowcrash/src/ParameterParser.h +516 -0
  169. data/ext/drafter/ext/snowcrash/src/ParametersParser.h +222 -0
  170. data/ext/drafter/ext/snowcrash/src/PayloadParser.h +733 -0
  171. data/ext/drafter/ext/snowcrash/src/Platform.h +33 -0
  172. data/ext/drafter/ext/snowcrash/src/RegexMatch.h +32 -0
  173. data/ext/drafter/ext/snowcrash/src/RelationParser.h +87 -0
  174. data/ext/drafter/ext/snowcrash/src/ResourceGroupParser.h +297 -0
  175. data/ext/drafter/ext/snowcrash/src/ResourceParser.h +536 -0
  176. data/ext/drafter/ext/snowcrash/src/Section.cc +48 -0
  177. data/ext/drafter/ext/snowcrash/src/Section.h +60 -0
  178. data/ext/drafter/ext/snowcrash/src/SectionParser.h +246 -0
  179. data/ext/drafter/ext/snowcrash/src/SectionParserData.h +109 -0
  180. data/ext/drafter/ext/snowcrash/src/SectionProcessor.h +299 -0
  181. data/ext/drafter/ext/snowcrash/src/Signature.cc +75 -0
  182. data/ext/drafter/ext/snowcrash/src/Signature.h +103 -0
  183. data/ext/drafter/ext/snowcrash/src/SignatureSectionProcessor.h +442 -0
  184. data/ext/drafter/ext/snowcrash/src/SourceAnnotation.h +166 -0
  185. data/ext/drafter/ext/snowcrash/src/StringUtility.h +323 -0
  186. data/ext/drafter/ext/snowcrash/src/UriTemplateParser.cc +195 -0
  187. data/ext/drafter/ext/snowcrash/src/UriTemplateParser.h +240 -0
  188. data/ext/drafter/ext/snowcrash/src/ValuesParser.h +111 -0
  189. data/ext/drafter/ext/snowcrash/src/posix/RegexMatch.cc +99 -0
  190. data/ext/drafter/ext/snowcrash/src/snowcrash.cc +90 -0
  191. data/ext/drafter/ext/snowcrash/src/snowcrash.h +44 -0
  192. data/ext/drafter/ext/snowcrash/src/win/RegexMatch.cc +78 -0
  193. data/ext/drafter/ext/snowcrash/tools/gyp/AUTHORS +12 -0
  194. data/ext/drafter/ext/snowcrash/tools/gyp/DEPS +23 -0
  195. data/ext/drafter/ext/snowcrash/tools/gyp/OWNERS +1 -0
  196. data/ext/drafter/ext/snowcrash/tools/gyp/PRESUBMIT.py +137 -0
  197. data/ext/drafter/ext/snowcrash/tools/gyp/buildbot/buildbot_run.py +136 -0
  198. data/ext/drafter/ext/snowcrash/tools/gyp/buildbot/commit_queue/OWNERS +6 -0
  199. data/ext/drafter/ext/snowcrash/tools/gyp/buildbot/commit_queue/cq_config.json +15 -0
  200. data/ext/drafter/ext/snowcrash/tools/gyp/codereview.settings +10 -0
  201. data/ext/drafter/ext/snowcrash/tools/gyp/data/win/large-pdb-shim.cc +12 -0
  202. data/ext/drafter/ext/snowcrash/tools/gyp/gyp +8 -0
  203. data/ext/drafter/ext/snowcrash/tools/gyp/gyp.bat +5 -0
  204. data/ext/drafter/ext/snowcrash/tools/gyp/gyp_main.py +16 -0
  205. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSNew.py +340 -0
  206. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSProject.py +208 -0
  207. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSSettings.py +1096 -0
  208. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSToolFile.py +58 -0
  209. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUserFile.py +147 -0
  210. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.py +270 -0
  211. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.pyc +0 -0
  212. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.py +445 -0
  213. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.pyc +0 -0
  214. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/__init__.py +548 -0
  215. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
  216. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/common.py +608 -0
  217. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
  218. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/easy_xml.py +157 -0
  219. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/flock_tool.py +54 -0
  220. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.py +0 -0
  221. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
  222. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/analyzer.py +741 -0
  223. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/android.py +1069 -0
  224. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/cmake.py +1248 -0
  225. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/dump_dependency_json.py +99 -0
  226. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/eclipse.py +425 -0
  227. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypd.py +94 -0
  228. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypsh.py +56 -0
  229. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.py +2218 -0
  230. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
  231. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/msvs.py +3467 -0
  232. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.py +2427 -0
  233. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.pyc +0 -0
  234. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.py +1300 -0
  235. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
  236. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/input.py +2899 -0
  237. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
  238. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/mac_tool.py +605 -0
  239. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.py +1093 -0
  240. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.pyc +0 -0
  241. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.py +160 -0
  242. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.pyc +0 -0
  243. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/ordered_dict.py +289 -0
  244. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/simple_copy.py +46 -0
  245. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/simple_copy.pyc +0 -0
  246. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/win_tool.py +314 -0
  247. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.py +1664 -0
  248. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
  249. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcode_ninja.py +276 -0
  250. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcode_ninja.pyc +0 -0
  251. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.py +2927 -0
  252. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
  253. data/ext/drafter/ext/snowcrash/tools/gyp/pylib/gyp/xml_fix.py +69 -0
  254. data/ext/drafter/ext/snowcrash/tools/gyp/pylintrc +307 -0
  255. data/ext/drafter/ext/snowcrash/tools/gyp/samples/samples +81 -0
  256. data/ext/drafter/ext/snowcrash/tools/gyp/samples/samples.bat +5 -0
  257. data/ext/drafter/ext/snowcrash/tools/gyp/setup.py +19 -0
  258. data/ext/drafter/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.pbfilespec +27 -0
  259. data/ext/drafter/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.xclangspec +226 -0
  260. data/ext/drafter/ext/snowcrash/tools/gyp/tools/emacs/gyp.el +275 -0
  261. data/ext/drafter/ext/snowcrash/tools/gyp/tools/graphviz.py +100 -0
  262. data/ext/drafter/ext/snowcrash/tools/gyp/tools/pretty_gyp.py +155 -0
  263. data/ext/drafter/ext/snowcrash/tools/gyp/tools/pretty_sln.py +169 -0
  264. data/ext/drafter/ext/snowcrash/tools/gyp/tools/pretty_vcproj.py +329 -0
  265. data/ext/drafter/ext/snowcrash/vcbuild.bat +139 -0
  266. data/ext/drafter/ext/sos/Makefile +62 -0
  267. data/ext/drafter/ext/sos/src/sos.cc +235 -0
  268. data/ext/drafter/ext/sos/src/sos.h +188 -0
  269. data/ext/drafter/ext/sos/src/sosJSON.h +121 -0
  270. data/ext/drafter/ext/sos/src/sosYAML.h +105 -0
  271. data/ext/drafter/src/ConversionContext.cc +39 -0
  272. data/ext/drafter/src/ConversionContext.h +34 -0
  273. data/ext/drafter/src/NamedTypesRegistry.cc +405 -0
  274. data/ext/drafter/src/NamedTypesRegistry.h +28 -0
  275. data/ext/drafter/src/NodeInfo.h +143 -0
  276. data/ext/drafter/src/RefractAPI.cc +579 -0
  277. data/ext/drafter/src/RefractAPI.h +28 -0
  278. data/ext/drafter/src/RefractDataStructure.cc +1199 -0
  279. data/ext/drafter/src/RefractDataStructure.h +26 -0
  280. data/ext/drafter/src/RefractElementFactory.cc +107 -0
  281. data/ext/drafter/src/RefractElementFactory.h +67 -0
  282. data/ext/drafter/src/RefractSourceMap.cc +29 -0
  283. data/ext/drafter/src/RefractSourceMap.h +57 -0
  284. data/ext/drafter/src/Render.cc +157 -0
  285. data/ext/drafter/src/Render.h +40 -0
  286. data/ext/drafter/src/Serialize.cc +160 -0
  287. data/ext/drafter/src/Serialize.h +289 -0
  288. data/ext/drafter/src/SerializeAST.cc +507 -0
  289. data/ext/drafter/src/SerializeAST.h +29 -0
  290. data/ext/drafter/src/SerializeResult.cc +170 -0
  291. data/ext/drafter/src/SerializeResult.h +34 -0
  292. data/ext/drafter/src/SerializeSourcemap.cc +331 -0
  293. data/ext/drafter/src/SerializeSourcemap.h +21 -0
  294. data/ext/drafter/src/Version.h +40 -0
  295. data/ext/drafter/src/config.cc +91 -0
  296. data/ext/drafter/src/config.h +38 -0
  297. data/ext/drafter/src/drafter.cc +137 -0
  298. data/ext/drafter/src/drafter.h +102 -0
  299. data/ext/drafter/src/drafter_private.cc +85 -0
  300. data/ext/drafter/src/drafter_private.h +34 -0
  301. data/ext/drafter/src/main.cc +137 -0
  302. data/ext/drafter/src/refract/AppendDecorator.h +58 -0
  303. data/ext/drafter/src/refract/Build.h +67 -0
  304. data/ext/drafter/src/refract/ComparableVisitor.cc +43 -0
  305. data/ext/drafter/src/refract/ComparableVisitor.h +62 -0
  306. data/ext/drafter/src/refract/Element.cc +409 -0
  307. data/ext/drafter/src/refract/Element.h +656 -0
  308. data/ext/drafter/src/refract/ElementFwd.h +37 -0
  309. data/ext/drafter/src/refract/ElementInserter.h +59 -0
  310. data/ext/drafter/src/refract/Exception.h +31 -0
  311. data/ext/drafter/src/refract/ExpandVisitor.cc +359 -0
  312. data/ext/drafter/src/refract/ExpandVisitor.h +58 -0
  313. data/ext/drafter/src/refract/FilterVisitor.h +52 -0
  314. data/ext/drafter/src/refract/IsExpandableVisitor.cc +140 -0
  315. data/ext/drafter/src/refract/IsExpandableVisitor.h +31 -0
  316. data/ext/drafter/src/refract/Iterate.h +160 -0
  317. data/ext/drafter/src/refract/JSONSchemaVisitor.cc +675 -0
  318. data/ext/drafter/src/refract/JSONSchemaVisitor.h +73 -0
  319. data/ext/drafter/src/refract/PrintVisitor.cc +164 -0
  320. data/ext/drafter/src/refract/PrintVisitor.h +50 -0
  321. data/ext/drafter/src/refract/Query.cc +13 -0
  322. data/ext/drafter/src/refract/Query.h +38 -0
  323. data/ext/drafter/src/refract/Registry.cc +114 -0
  324. data/ext/drafter/src/refract/Registry.h +43 -0
  325. data/ext/drafter/src/refract/RenderJSONVisitor.cc +255 -0
  326. data/ext/drafter/src/refract/RenderJSONVisitor.h +51 -0
  327. data/ext/drafter/src/refract/SerializeCompactVisitor.cc +167 -0
  328. data/ext/drafter/src/refract/SerializeCompactVisitor.h +56 -0
  329. data/ext/drafter/src/refract/SerializeVisitor.cc +214 -0
  330. data/ext/drafter/src/refract/SerializeVisitor.h +55 -0
  331. data/ext/drafter/src/refract/TypeQueryVisitor.cc +46 -0
  332. data/ext/drafter/src/refract/TypeQueryVisitor.h +110 -0
  333. data/ext/drafter/src/refract/Visitor.h +126 -0
  334. data/ext/drafter/src/refract/VisitorUtils.cc +63 -0
  335. data/ext/drafter/src/refract/VisitorUtils.h +231 -0
  336. data/ext/drafter/src/reporting.cc +263 -0
  337. data/ext/drafter/src/reporting.h +39 -0
  338. data/ext/drafter/src/stream.h +148 -0
  339. data/ext/drafter/tools/homebrew/drafter.rb +18 -0
  340. data/ext/drafter/tools/make-tarball.sh +39 -0
  341. data/ext/drafter/tools/refract-filter.py +96 -0
  342. data/ext/drafter/tools/release.sh +17 -0
  343. data/ext/drafter/vcbuild.bat +203 -0
  344. data/lib/lounge_lizard/binding.rb +29 -0
  345. data/lib/lounge_lizard/version.rb +3 -0
  346. data/lib/lounge_lizard.rb +18 -0
  347. data/lounge_lizard.gemspec +37 -0
  348. metadata +547 -0
@@ -0,0 +1,3467 @@
1
+ # Copyright (c) 2012 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
+ import copy
6
+ import ntpath
7
+ import os
8
+ import posixpath
9
+ import re
10
+ import subprocess
11
+ import sys
12
+
13
+ import gyp.common
14
+ import gyp.easy_xml as easy_xml
15
+ import gyp.generator.ninja as ninja_generator
16
+ import gyp.MSVSNew as MSVSNew
17
+ import gyp.MSVSProject as MSVSProject
18
+ import gyp.MSVSSettings as MSVSSettings
19
+ import gyp.MSVSToolFile as MSVSToolFile
20
+ import gyp.MSVSUserFile as MSVSUserFile
21
+ import gyp.MSVSUtil as MSVSUtil
22
+ import gyp.MSVSVersion as MSVSVersion
23
+ from gyp.common import GypError
24
+ from gyp.common import OrderedSet
25
+
26
+ # TODO: Remove once bots are on 2.7, http://crbug.com/241769
27
+ def _import_OrderedDict():
28
+ import collections
29
+ try:
30
+ return collections.OrderedDict
31
+ except AttributeError:
32
+ import gyp.ordered_dict
33
+ return gyp.ordered_dict.OrderedDict
34
+ OrderedDict = _import_OrderedDict()
35
+
36
+
37
+ # Regular expression for validating Visual Studio GUIDs. If the GUID
38
+ # contains lowercase hex letters, MSVS will be fine. However,
39
+ # IncrediBuild BuildConsole will parse the solution file, but then
40
+ # silently skip building the target causing hard to track down errors.
41
+ # Note that this only happens with the BuildConsole, and does not occur
42
+ # if IncrediBuild is executed from inside Visual Studio. This regex
43
+ # validates that the string looks like a GUID with all uppercase hex
44
+ # letters.
45
+ VALID_MSVS_GUID_CHARS = re.compile(r'^[A-F0-9\-]+$')
46
+
47
+
48
+ generator_default_variables = {
49
+ 'EXECUTABLE_PREFIX': '',
50
+ 'EXECUTABLE_SUFFIX': '.exe',
51
+ 'STATIC_LIB_PREFIX': '',
52
+ 'SHARED_LIB_PREFIX': '',
53
+ 'STATIC_LIB_SUFFIX': '.lib',
54
+ 'SHARED_LIB_SUFFIX': '.dll',
55
+ 'INTERMEDIATE_DIR': '$(IntDir)',
56
+ 'SHARED_INTERMEDIATE_DIR': '$(OutDir)obj/global_intermediate',
57
+ 'OS': 'win',
58
+ 'PRODUCT_DIR': '$(OutDir)',
59
+ 'LIB_DIR': '$(OutDir)lib',
60
+ 'RULE_INPUT_ROOT': '$(InputName)',
61
+ 'RULE_INPUT_DIRNAME': '$(InputDir)',
62
+ 'RULE_INPUT_EXT': '$(InputExt)',
63
+ 'RULE_INPUT_NAME': '$(InputFileName)',
64
+ 'RULE_INPUT_PATH': '$(InputPath)',
65
+ 'CONFIGURATION_NAME': '$(ConfigurationName)',
66
+ }
67
+
68
+
69
+ # The msvs specific sections that hold paths
70
+ generator_additional_path_sections = [
71
+ 'msvs_cygwin_dirs',
72
+ 'msvs_props',
73
+ ]
74
+
75
+
76
+ generator_additional_non_configuration_keys = [
77
+ 'msvs_cygwin_dirs',
78
+ 'msvs_cygwin_shell',
79
+ 'msvs_large_pdb',
80
+ 'msvs_shard',
81
+ 'msvs_external_builder',
82
+ 'msvs_external_builder_out_dir',
83
+ 'msvs_external_builder_build_cmd',
84
+ 'msvs_external_builder_clean_cmd',
85
+ 'msvs_external_builder_clcompile_cmd',
86
+ 'msvs_enable_winrt',
87
+ 'msvs_requires_importlibrary',
88
+ 'msvs_enable_winphone',
89
+ 'msvs_application_type_revision',
90
+ 'msvs_target_platform_version',
91
+ 'msvs_target_platform_minversion',
92
+ ]
93
+
94
+ generator_filelist_paths = None
95
+
96
+ # List of precompiled header related keys.
97
+ precomp_keys = [
98
+ 'msvs_precompiled_header',
99
+ 'msvs_precompiled_source',
100
+ ]
101
+
102
+
103
+ cached_username = None
104
+
105
+
106
+ cached_domain = None
107
+
108
+
109
+ # TODO(gspencer): Switch the os.environ calls to be
110
+ # win32api.GetDomainName() and win32api.GetUserName() once the
111
+ # python version in depot_tools has been updated to work on Vista
112
+ # 64-bit.
113
+ def _GetDomainAndUserName():
114
+ if sys.platform not in ('win32', 'cygwin'):
115
+ return ('DOMAIN', 'USERNAME')
116
+ global cached_username
117
+ global cached_domain
118
+ if not cached_domain or not cached_username:
119
+ domain = os.environ.get('USERDOMAIN')
120
+ username = os.environ.get('USERNAME')
121
+ if not domain or not username:
122
+ call = subprocess.Popen(['net', 'config', 'Workstation'],
123
+ stdout=subprocess.PIPE)
124
+ config = call.communicate()[0]
125
+ username_re = re.compile(r'^User name\s+(\S+)', re.MULTILINE)
126
+ username_match = username_re.search(config)
127
+ if username_match:
128
+ username = username_match.group(1)
129
+ domain_re = re.compile(r'^Logon domain\s+(\S+)', re.MULTILINE)
130
+ domain_match = domain_re.search(config)
131
+ if domain_match:
132
+ domain = domain_match.group(1)
133
+ cached_domain = domain
134
+ cached_username = username
135
+ return (cached_domain, cached_username)
136
+
137
+ fixpath_prefix = None
138
+
139
+
140
+ def _NormalizedSource(source):
141
+ """Normalize the path.
142
+
143
+ But not if that gets rid of a variable, as this may expand to something
144
+ larger than one directory.
145
+
146
+ Arguments:
147
+ source: The path to be normalize.d
148
+
149
+ Returns:
150
+ The normalized path.
151
+ """
152
+ normalized = os.path.normpath(source)
153
+ if source.count('$') == normalized.count('$'):
154
+ source = normalized
155
+ return source
156
+
157
+
158
+ def _FixPath(path):
159
+ """Convert paths to a form that will make sense in a vcproj file.
160
+
161
+ Arguments:
162
+ path: The path to convert, may contain / etc.
163
+ Returns:
164
+ The path with all slashes made into backslashes.
165
+ """
166
+ if fixpath_prefix and path and not os.path.isabs(path) and not path[0] == '$':
167
+ path = os.path.join(fixpath_prefix, path)
168
+ path = path.replace('/', '\\')
169
+ path = _NormalizedSource(path)
170
+ if path and path[-1] == '\\':
171
+ path = path[:-1]
172
+ return path
173
+
174
+
175
+ def _FixPaths(paths):
176
+ """Fix each of the paths of the list."""
177
+ return [_FixPath(i) for i in paths]
178
+
179
+
180
+ def _ConvertSourcesToFilterHierarchy(sources, prefix=None, excluded=None,
181
+ list_excluded=True, msvs_version=None):
182
+ """Converts a list split source file paths into a vcproj folder hierarchy.
183
+
184
+ Arguments:
185
+ sources: A list of source file paths split.
186
+ prefix: A list of source file path layers meant to apply to each of sources.
187
+ excluded: A set of excluded files.
188
+ msvs_version: A MSVSVersion object.
189
+
190
+ Returns:
191
+ A hierarchy of filenames and MSVSProject.Filter objects that matches the
192
+ layout of the source tree.
193
+ For example:
194
+ _ConvertSourcesToFilterHierarchy([['a', 'bob1.c'], ['b', 'bob2.c']],
195
+ prefix=['joe'])
196
+ -->
197
+ [MSVSProject.Filter('a', contents=['joe\\a\\bob1.c']),
198
+ MSVSProject.Filter('b', contents=['joe\\b\\bob2.c'])]
199
+ """
200
+ if not prefix: prefix = []
201
+ result = []
202
+ excluded_result = []
203
+ folders = OrderedDict()
204
+ # Gather files into the final result, excluded, or folders.
205
+ for s in sources:
206
+ if len(s) == 1:
207
+ filename = _NormalizedSource('\\'.join(prefix + s))
208
+ if filename in excluded:
209
+ excluded_result.append(filename)
210
+ else:
211
+ result.append(filename)
212
+ elif msvs_version and not msvs_version.UsesVcxproj():
213
+ # For MSVS 2008 and earlier, we need to process all files before walking
214
+ # the sub folders.
215
+ if not folders.get(s[0]):
216
+ folders[s[0]] = []
217
+ folders[s[0]].append(s[1:])
218
+ else:
219
+ contents = _ConvertSourcesToFilterHierarchy([s[1:]], prefix + [s[0]],
220
+ excluded=excluded,
221
+ list_excluded=list_excluded,
222
+ msvs_version=msvs_version)
223
+ contents = MSVSProject.Filter(s[0], contents=contents)
224
+ result.append(contents)
225
+ # Add a folder for excluded files.
226
+ if excluded_result and list_excluded:
227
+ excluded_folder = MSVSProject.Filter('_excluded_files',
228
+ contents=excluded_result)
229
+ result.append(excluded_folder)
230
+
231
+ if msvs_version and msvs_version.UsesVcxproj():
232
+ return result
233
+
234
+ # Populate all the folders.
235
+ for f in folders:
236
+ contents = _ConvertSourcesToFilterHierarchy(folders[f], prefix=prefix + [f],
237
+ excluded=excluded,
238
+ list_excluded=list_excluded,
239
+ msvs_version=msvs_version)
240
+ contents = MSVSProject.Filter(f, contents=contents)
241
+ result.append(contents)
242
+ return result
243
+
244
+
245
+ def _ToolAppend(tools, tool_name, setting, value, only_if_unset=False):
246
+ if not value: return
247
+ _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset)
248
+
249
+
250
+ def _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset=False):
251
+ # TODO(bradnelson): ugly hack, fix this more generally!!!
252
+ if 'Directories' in setting or 'Dependencies' in setting:
253
+ if type(value) == str:
254
+ value = value.replace('/', '\\')
255
+ else:
256
+ value = [i.replace('/', '\\') for i in value]
257
+ if not tools.get(tool_name):
258
+ tools[tool_name] = dict()
259
+ tool = tools[tool_name]
260
+ if tool.get(setting):
261
+ if only_if_unset: return
262
+ if type(tool[setting]) == list and type(value) == list:
263
+ tool[setting] += value
264
+ else:
265
+ raise TypeError(
266
+ 'Appending "%s" to a non-list setting "%s" for tool "%s" is '
267
+ 'not allowed, previous value: %s' % (
268
+ value, setting, tool_name, str(tool[setting])))
269
+ else:
270
+ tool[setting] = value
271
+
272
+
273
+ def _ConfigPlatform(config_data):
274
+ return config_data.get('msvs_configuration_platform', 'Win32')
275
+
276
+
277
+ def _ConfigBaseName(config_name, platform_name):
278
+ if config_name.endswith('_' + platform_name):
279
+ return config_name[0:-len(platform_name) - 1]
280
+ else:
281
+ return config_name
282
+
283
+
284
+ def _ConfigFullName(config_name, config_data):
285
+ platform_name = _ConfigPlatform(config_data)
286
+ return '%s|%s' % (_ConfigBaseName(config_name, platform_name), platform_name)
287
+
288
+
289
+ def _BuildCommandLineForRuleRaw(spec, cmd, cygwin_shell, has_input_path,
290
+ quote_cmd, do_setup_env):
291
+
292
+ if [x for x in cmd if '$(InputDir)' in x]:
293
+ input_dir_preamble = (
294
+ 'set INPUTDIR=$(InputDir)\n'
295
+ 'if NOT DEFINED INPUTDIR set INPUTDIR=.\\\n'
296
+ 'set INPUTDIR=%INPUTDIR:~0,-1%\n'
297
+ )
298
+ else:
299
+ input_dir_preamble = ''
300
+
301
+ if cygwin_shell:
302
+ # Find path to cygwin.
303
+ cygwin_dir = _FixPath(spec.get('msvs_cygwin_dirs', ['.'])[0])
304
+ # Prepare command.
305
+ direct_cmd = cmd
306
+ direct_cmd = [i.replace('$(IntDir)',
307
+ '`cygpath -m "${INTDIR}"`') for i in direct_cmd]
308
+ direct_cmd = [i.replace('$(OutDir)',
309
+ '`cygpath -m "${OUTDIR}"`') for i in direct_cmd]
310
+ direct_cmd = [i.replace('$(InputDir)',
311
+ '`cygpath -m "${INPUTDIR}"`') for i in direct_cmd]
312
+ if has_input_path:
313
+ direct_cmd = [i.replace('$(InputPath)',
314
+ '`cygpath -m "${INPUTPATH}"`')
315
+ for i in direct_cmd]
316
+ direct_cmd = ['\\"%s\\"' % i.replace('"', '\\\\\\"') for i in direct_cmd]
317
+ # direct_cmd = gyp.common.EncodePOSIXShellList(direct_cmd)
318
+ direct_cmd = ' '.join(direct_cmd)
319
+ # TODO(quote): regularize quoting path names throughout the module
320
+ cmd = ''
321
+ if do_setup_env:
322
+ cmd += 'call "$(ProjectDir)%(cygwin_dir)s\\setup_env.bat" && '
323
+ cmd += 'set CYGWIN=nontsec&& '
324
+ if direct_cmd.find('NUMBER_OF_PROCESSORS') >= 0:
325
+ cmd += 'set /a NUMBER_OF_PROCESSORS_PLUS_1=%%NUMBER_OF_PROCESSORS%%+1&& '
326
+ if direct_cmd.find('INTDIR') >= 0:
327
+ cmd += 'set INTDIR=$(IntDir)&& '
328
+ if direct_cmd.find('OUTDIR') >= 0:
329
+ cmd += 'set OUTDIR=$(OutDir)&& '
330
+ if has_input_path and direct_cmd.find('INPUTPATH') >= 0:
331
+ cmd += 'set INPUTPATH=$(InputPath) && '
332
+ cmd += 'bash -c "%(cmd)s"'
333
+ cmd = cmd % {'cygwin_dir': cygwin_dir,
334
+ 'cmd': direct_cmd}
335
+ return input_dir_preamble + cmd
336
+ else:
337
+ # Convert cat --> type to mimic unix.
338
+ if cmd[0] == 'cat':
339
+ command = ['type']
340
+ else:
341
+ command = [cmd[0].replace('/', '\\')]
342
+ # Add call before command to ensure that commands can be tied together one
343
+ # after the other without aborting in Incredibuild, since IB makes a bat
344
+ # file out of the raw command string, and some commands (like python) are
345
+ # actually batch files themselves.
346
+ command.insert(0, 'call')
347
+ # Fix the paths
348
+ # TODO(quote): This is a really ugly heuristic, and will miss path fixing
349
+ # for arguments like "--arg=path" or "/opt:path".
350
+ # If the argument starts with a slash or dash, it's probably a command line
351
+ # switch
352
+ arguments = [i if (i[:1] in "/-") else _FixPath(i) for i in cmd[1:]]
353
+ arguments = [i.replace('$(InputDir)', '%INPUTDIR%') for i in arguments]
354
+ arguments = [MSVSSettings.FixVCMacroSlashes(i) for i in arguments]
355
+ if quote_cmd:
356
+ # Support a mode for using cmd directly.
357
+ # Convert any paths to native form (first element is used directly).
358
+ # TODO(quote): regularize quoting path names throughout the module
359
+ arguments = ['"%s"' % i for i in arguments]
360
+ # Collapse into a single command.
361
+ return input_dir_preamble + ' '.join(command + arguments)
362
+
363
+
364
+ def _BuildCommandLineForRule(spec, rule, has_input_path, do_setup_env):
365
+ # Currently this weird argument munging is used to duplicate the way a
366
+ # python script would need to be run as part of the chrome tree.
367
+ # Eventually we should add some sort of rule_default option to set this
368
+ # per project. For now the behavior chrome needs is the default.
369
+ mcs = rule.get('msvs_cygwin_shell')
370
+ if mcs is None:
371
+ mcs = int(spec.get('msvs_cygwin_shell', 1))
372
+ elif isinstance(mcs, str):
373
+ mcs = int(mcs)
374
+ quote_cmd = int(rule.get('msvs_quote_cmd', 1))
375
+ return _BuildCommandLineForRuleRaw(spec, rule['action'], mcs, has_input_path,
376
+ quote_cmd, do_setup_env=do_setup_env)
377
+
378
+
379
+ def _AddActionStep(actions_dict, inputs, outputs, description, command):
380
+ """Merge action into an existing list of actions.
381
+
382
+ Care must be taken so that actions which have overlapping inputs either don't
383
+ get assigned to the same input, or get collapsed into one.
384
+
385
+ Arguments:
386
+ actions_dict: dictionary keyed on input name, which maps to a list of
387
+ dicts describing the actions attached to that input file.
388
+ inputs: list of inputs
389
+ outputs: list of outputs
390
+ description: description of the action
391
+ command: command line to execute
392
+ """
393
+ # Require there to be at least one input (call sites will ensure this).
394
+ assert inputs
395
+
396
+ action = {
397
+ 'inputs': inputs,
398
+ 'outputs': outputs,
399
+ 'description': description,
400
+ 'command': command,
401
+ }
402
+
403
+ # Pick where to stick this action.
404
+ # While less than optimal in terms of build time, attach them to the first
405
+ # input for now.
406
+ chosen_input = inputs[0]
407
+
408
+ # Add it there.
409
+ if chosen_input not in actions_dict:
410
+ actions_dict[chosen_input] = []
411
+ actions_dict[chosen_input].append(action)
412
+
413
+
414
+ def _AddCustomBuildToolForMSVS(p, spec, primary_input,
415
+ inputs, outputs, description, cmd):
416
+ """Add a custom build tool to execute something.
417
+
418
+ Arguments:
419
+ p: the target project
420
+ spec: the target project dict
421
+ primary_input: input file to attach the build tool to
422
+ inputs: list of inputs
423
+ outputs: list of outputs
424
+ description: description of the action
425
+ cmd: command line to execute
426
+ """
427
+ inputs = _FixPaths(inputs)
428
+ outputs = _FixPaths(outputs)
429
+ tool = MSVSProject.Tool(
430
+ 'VCCustomBuildTool',
431
+ {'Description': description,
432
+ 'AdditionalDependencies': ';'.join(inputs),
433
+ 'Outputs': ';'.join(outputs),
434
+ 'CommandLine': cmd,
435
+ })
436
+ # Add to the properties of primary input for each config.
437
+ for config_name, c_data in spec['configurations'].iteritems():
438
+ p.AddFileConfig(_FixPath(primary_input),
439
+ _ConfigFullName(config_name, c_data), tools=[tool])
440
+
441
+
442
+ def _AddAccumulatedActionsToMSVS(p, spec, actions_dict):
443
+ """Add actions accumulated into an actions_dict, merging as needed.
444
+
445
+ Arguments:
446
+ p: the target project
447
+ spec: the target project dict
448
+ actions_dict: dictionary keyed on input name, which maps to a list of
449
+ dicts describing the actions attached to that input file.
450
+ """
451
+ for primary_input in actions_dict:
452
+ inputs = OrderedSet()
453
+ outputs = OrderedSet()
454
+ descriptions = []
455
+ commands = []
456
+ for action in actions_dict[primary_input]:
457
+ inputs.update(OrderedSet(action['inputs']))
458
+ outputs.update(OrderedSet(action['outputs']))
459
+ descriptions.append(action['description'])
460
+ commands.append(action['command'])
461
+ # Add the custom build step for one input file.
462
+ description = ', and also '.join(descriptions)
463
+ command = '\r\n'.join(commands)
464
+ _AddCustomBuildToolForMSVS(p, spec,
465
+ primary_input=primary_input,
466
+ inputs=inputs,
467
+ outputs=outputs,
468
+ description=description,
469
+ cmd=command)
470
+
471
+
472
+ def _RuleExpandPath(path, input_file):
473
+ """Given the input file to which a rule applied, string substitute a path.
474
+
475
+ Arguments:
476
+ path: a path to string expand
477
+ input_file: the file to which the rule applied.
478
+ Returns:
479
+ The string substituted path.
480
+ """
481
+ path = path.replace('$(InputName)',
482
+ os.path.splitext(os.path.split(input_file)[1])[0])
483
+ path = path.replace('$(InputDir)', os.path.dirname(input_file))
484
+ path = path.replace('$(InputExt)',
485
+ os.path.splitext(os.path.split(input_file)[1])[1])
486
+ path = path.replace('$(InputFileName)', os.path.split(input_file)[1])
487
+ path = path.replace('$(InputPath)', input_file)
488
+ return path
489
+
490
+
491
+ def _FindRuleTriggerFiles(rule, sources):
492
+ """Find the list of files which a particular rule applies to.
493
+
494
+ Arguments:
495
+ rule: the rule in question
496
+ sources: the set of all known source files for this project
497
+ Returns:
498
+ The list of sources that trigger a particular rule.
499
+ """
500
+ return rule.get('rule_sources', [])
501
+
502
+
503
+ def _RuleInputsAndOutputs(rule, trigger_file):
504
+ """Find the inputs and outputs generated by a rule.
505
+
506
+ Arguments:
507
+ rule: the rule in question.
508
+ trigger_file: the main trigger for this rule.
509
+ Returns:
510
+ The pair of (inputs, outputs) involved in this rule.
511
+ """
512
+ raw_inputs = _FixPaths(rule.get('inputs', []))
513
+ raw_outputs = _FixPaths(rule.get('outputs', []))
514
+ inputs = OrderedSet()
515
+ outputs = OrderedSet()
516
+ inputs.add(trigger_file)
517
+ for i in raw_inputs:
518
+ inputs.add(_RuleExpandPath(i, trigger_file))
519
+ for o in raw_outputs:
520
+ outputs.add(_RuleExpandPath(o, trigger_file))
521
+ return (inputs, outputs)
522
+
523
+
524
+ def _GenerateNativeRulesForMSVS(p, rules, output_dir, spec, options):
525
+ """Generate a native rules file.
526
+
527
+ Arguments:
528
+ p: the target project
529
+ rules: the set of rules to include
530
+ output_dir: the directory in which the project/gyp resides
531
+ spec: the project dict
532
+ options: global generator options
533
+ """
534
+ rules_filename = '%s%s.rules' % (spec['target_name'],
535
+ options.suffix)
536
+ rules_file = MSVSToolFile.Writer(os.path.join(output_dir, rules_filename),
537
+ spec['target_name'])
538
+ # Add each rule.
539
+ for r in rules:
540
+ rule_name = r['rule_name']
541
+ rule_ext = r['extension']
542
+ inputs = _FixPaths(r.get('inputs', []))
543
+ outputs = _FixPaths(r.get('outputs', []))
544
+ # Skip a rule with no action and no inputs.
545
+ if 'action' not in r and not r.get('rule_sources', []):
546
+ continue
547
+ cmd = _BuildCommandLineForRule(spec, r, has_input_path=True,
548
+ do_setup_env=True)
549
+ rules_file.AddCustomBuildRule(name=rule_name,
550
+ description=r.get('message', rule_name),
551
+ extensions=[rule_ext],
552
+ additional_dependencies=inputs,
553
+ outputs=outputs,
554
+ cmd=cmd)
555
+ # Write out rules file.
556
+ rules_file.WriteIfChanged()
557
+
558
+ # Add rules file to project.
559
+ p.AddToolFile(rules_filename)
560
+
561
+
562
+ def _Cygwinify(path):
563
+ path = path.replace('$(OutDir)', '$(OutDirCygwin)')
564
+ path = path.replace('$(IntDir)', '$(IntDirCygwin)')
565
+ return path
566
+
567
+
568
+ def _GenerateExternalRules(rules, output_dir, spec,
569
+ sources, options, actions_to_add):
570
+ """Generate an external makefile to do a set of rules.
571
+
572
+ Arguments:
573
+ rules: the list of rules to include
574
+ output_dir: path containing project and gyp files
575
+ spec: project specification data
576
+ sources: set of sources known
577
+ options: global generator options
578
+ actions_to_add: The list of actions we will add to.
579
+ """
580
+ filename = '%s_rules%s.mk' % (spec['target_name'], options.suffix)
581
+ mk_file = gyp.common.WriteOnDiff(os.path.join(output_dir, filename))
582
+ # Find cygwin style versions of some paths.
583
+ mk_file.write('OutDirCygwin:=$(shell cygpath -u "$(OutDir)")\n')
584
+ mk_file.write('IntDirCygwin:=$(shell cygpath -u "$(IntDir)")\n')
585
+ # Gather stuff needed to emit all: target.
586
+ all_inputs = OrderedSet()
587
+ all_outputs = OrderedSet()
588
+ all_output_dirs = OrderedSet()
589
+ first_outputs = []
590
+ for rule in rules:
591
+ trigger_files = _FindRuleTriggerFiles(rule, sources)
592
+ for tf in trigger_files:
593
+ inputs, outputs = _RuleInputsAndOutputs(rule, tf)
594
+ all_inputs.update(OrderedSet(inputs))
595
+ all_outputs.update(OrderedSet(outputs))
596
+ # Only use one target from each rule as the dependency for
597
+ # 'all' so we don't try to build each rule multiple times.
598
+ first_outputs.append(list(outputs)[0])
599
+ # Get the unique output directories for this rule.
600
+ output_dirs = [os.path.split(i)[0] for i in outputs]
601
+ for od in output_dirs:
602
+ all_output_dirs.add(od)
603
+ first_outputs_cyg = [_Cygwinify(i) for i in first_outputs]
604
+ # Write out all: target, including mkdir for each output directory.
605
+ mk_file.write('all: %s\n' % ' '.join(first_outputs_cyg))
606
+ for od in all_output_dirs:
607
+ if od:
608
+ mk_file.write('\tmkdir -p `cygpath -u "%s"`\n' % od)
609
+ mk_file.write('\n')
610
+ # Define how each output is generated.
611
+ for rule in rules:
612
+ trigger_files = _FindRuleTriggerFiles(rule, sources)
613
+ for tf in trigger_files:
614
+ # Get all the inputs and outputs for this rule for this trigger file.
615
+ inputs, outputs = _RuleInputsAndOutputs(rule, tf)
616
+ inputs = [_Cygwinify(i) for i in inputs]
617
+ outputs = [_Cygwinify(i) for i in outputs]
618
+ # Prepare the command line for this rule.
619
+ cmd = [_RuleExpandPath(c, tf) for c in rule['action']]
620
+ cmd = ['"%s"' % i for i in cmd]
621
+ cmd = ' '.join(cmd)
622
+ # Add it to the makefile.
623
+ mk_file.write('%s: %s\n' % (' '.join(outputs), ' '.join(inputs)))
624
+ mk_file.write('\t%s\n\n' % cmd)
625
+ # Close up the file.
626
+ mk_file.close()
627
+
628
+ # Add makefile to list of sources.
629
+ sources.add(filename)
630
+ # Add a build action to call makefile.
631
+ cmd = ['make',
632
+ 'OutDir=$(OutDir)',
633
+ 'IntDir=$(IntDir)',
634
+ '-j', '${NUMBER_OF_PROCESSORS_PLUS_1}',
635
+ '-f', filename]
636
+ cmd = _BuildCommandLineForRuleRaw(spec, cmd, True, False, True, True)
637
+ # Insert makefile as 0'th input, so it gets the action attached there,
638
+ # as this is easier to understand from in the IDE.
639
+ all_inputs = list(all_inputs)
640
+ all_inputs.insert(0, filename)
641
+ _AddActionStep(actions_to_add,
642
+ inputs=_FixPaths(all_inputs),
643
+ outputs=_FixPaths(all_outputs),
644
+ description='Running external rules for %s' %
645
+ spec['target_name'],
646
+ command=cmd)
647
+
648
+
649
+ def _EscapeEnvironmentVariableExpansion(s):
650
+ """Escapes % characters.
651
+
652
+ Escapes any % characters so that Windows-style environment variable
653
+ expansions will leave them alone.
654
+ See http://connect.microsoft.com/VisualStudio/feedback/details/106127/cl-d-name-text-containing-percentage-characters-doesnt-compile
655
+ to understand why we have to do this.
656
+
657
+ Args:
658
+ s: The string to be escaped.
659
+
660
+ Returns:
661
+ The escaped string.
662
+ """
663
+ s = s.replace('%', '%%')
664
+ return s
665
+
666
+
667
+ quote_replacer_regex = re.compile(r'(\\*)"')
668
+
669
+
670
+ def _EscapeCommandLineArgumentForMSVS(s):
671
+ """Escapes a Windows command-line argument.
672
+
673
+ So that the Win32 CommandLineToArgv function will turn the escaped result back
674
+ into the original string.
675
+ See http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
676
+ ("Parsing C++ Command-Line Arguments") to understand why we have to do
677
+ this.
678
+
679
+ Args:
680
+ s: the string to be escaped.
681
+ Returns:
682
+ the escaped string.
683
+ """
684
+
685
+ def _Replace(match):
686
+ # For a literal quote, CommandLineToArgv requires an odd number of
687
+ # backslashes preceding it, and it produces half as many literal backslashes
688
+ # (rounded down). So we need to produce 2n+1 backslashes.
689
+ return 2 * match.group(1) + '\\"'
690
+
691
+ # Escape all quotes so that they are interpreted literally.
692
+ s = quote_replacer_regex.sub(_Replace, s)
693
+ # Now add unescaped quotes so that any whitespace is interpreted literally.
694
+ s = '"' + s + '"'
695
+ return s
696
+
697
+
698
+ delimiters_replacer_regex = re.compile(r'(\\*)([,;]+)')
699
+
700
+
701
+ def _EscapeVCProjCommandLineArgListItem(s):
702
+ """Escapes command line arguments for MSVS.
703
+
704
+ The VCProj format stores string lists in a single string using commas and
705
+ semi-colons as separators, which must be quoted if they are to be
706
+ interpreted literally. However, command-line arguments may already have
707
+ quotes, and the VCProj parser is ignorant of the backslash escaping
708
+ convention used by CommandLineToArgv, so the command-line quotes and the
709
+ VCProj quotes may not be the same quotes. So to store a general
710
+ command-line argument in a VCProj list, we need to parse the existing
711
+ quoting according to VCProj's convention and quote any delimiters that are
712
+ not already quoted by that convention. The quotes that we add will also be
713
+ seen by CommandLineToArgv, so if backslashes precede them then we also have
714
+ to escape those backslashes according to the CommandLineToArgv
715
+ convention.
716
+
717
+ Args:
718
+ s: the string to be escaped.
719
+ Returns:
720
+ the escaped string.
721
+ """
722
+
723
+ def _Replace(match):
724
+ # For a non-literal quote, CommandLineToArgv requires an even number of
725
+ # backslashes preceding it, and it produces half as many literal
726
+ # backslashes. So we need to produce 2n backslashes.
727
+ return 2 * match.group(1) + '"' + match.group(2) + '"'
728
+
729
+ segments = s.split('"')
730
+ # The unquoted segments are at the even-numbered indices.
731
+ for i in range(0, len(segments), 2):
732
+ segments[i] = delimiters_replacer_regex.sub(_Replace, segments[i])
733
+ # Concatenate back into a single string
734
+ s = '"'.join(segments)
735
+ if len(segments) % 2 == 0:
736
+ # String ends while still quoted according to VCProj's convention. This
737
+ # means the delimiter and the next list item that follow this one in the
738
+ # .vcproj file will be misinterpreted as part of this item. There is nothing
739
+ # we can do about this. Adding an extra quote would correct the problem in
740
+ # the VCProj but cause the same problem on the final command-line. Moving
741
+ # the item to the end of the list does works, but that's only possible if
742
+ # there's only one such item. Let's just warn the user.
743
+ print >> sys.stderr, ('Warning: MSVS may misinterpret the odd number of ' +
744
+ 'quotes in ' + s)
745
+ return s
746
+
747
+
748
+ def _EscapeCppDefineForMSVS(s):
749
+ """Escapes a CPP define so that it will reach the compiler unaltered."""
750
+ s = _EscapeEnvironmentVariableExpansion(s)
751
+ s = _EscapeCommandLineArgumentForMSVS(s)
752
+ s = _EscapeVCProjCommandLineArgListItem(s)
753
+ # cl.exe replaces literal # characters with = in preprocesor definitions for
754
+ # some reason. Octal-encode to work around that.
755
+ s = s.replace('#', '\\%03o' % ord('#'))
756
+ return s
757
+
758
+
759
+ quote_replacer_regex2 = re.compile(r'(\\+)"')
760
+
761
+
762
+ def _EscapeCommandLineArgumentForMSBuild(s):
763
+ """Escapes a Windows command-line argument for use by MSBuild."""
764
+
765
+ def _Replace(match):
766
+ return (len(match.group(1)) / 2 * 4) * '\\' + '\\"'
767
+
768
+ # Escape all quotes so that they are interpreted literally.
769
+ s = quote_replacer_regex2.sub(_Replace, s)
770
+ return s
771
+
772
+
773
+ def _EscapeMSBuildSpecialCharacters(s):
774
+ escape_dictionary = {
775
+ '%': '%25',
776
+ '$': '%24',
777
+ '@': '%40',
778
+ "'": '%27',
779
+ ';': '%3B',
780
+ '?': '%3F',
781
+ '*': '%2A'
782
+ }
783
+ result = ''.join([escape_dictionary.get(c, c) for c in s])
784
+ return result
785
+
786
+
787
+ def _EscapeCppDefineForMSBuild(s):
788
+ """Escapes a CPP define so that it will reach the compiler unaltered."""
789
+ s = _EscapeEnvironmentVariableExpansion(s)
790
+ s = _EscapeCommandLineArgumentForMSBuild(s)
791
+ s = _EscapeMSBuildSpecialCharacters(s)
792
+ # cl.exe replaces literal # characters with = in preprocesor definitions for
793
+ # some reason. Octal-encode to work around that.
794
+ s = s.replace('#', '\\%03o' % ord('#'))
795
+ return s
796
+
797
+
798
+ def _GenerateRulesForMSVS(p, output_dir, options, spec,
799
+ sources, excluded_sources,
800
+ actions_to_add):
801
+ """Generate all the rules for a particular project.
802
+
803
+ Arguments:
804
+ p: the project
805
+ output_dir: directory to emit rules to
806
+ options: global options passed to the generator
807
+ spec: the specification for this project
808
+ sources: the set of all known source files in this project
809
+ excluded_sources: the set of sources excluded from normal processing
810
+ actions_to_add: deferred list of actions to add in
811
+ """
812
+ rules = spec.get('rules', [])
813
+ rules_native = [r for r in rules if not int(r.get('msvs_external_rule', 0))]
814
+ rules_external = [r for r in rules if int(r.get('msvs_external_rule', 0))]
815
+
816
+ # Handle rules that use a native rules file.
817
+ if rules_native:
818
+ _GenerateNativeRulesForMSVS(p, rules_native, output_dir, spec, options)
819
+
820
+ # Handle external rules (non-native rules).
821
+ if rules_external:
822
+ _GenerateExternalRules(rules_external, output_dir, spec,
823
+ sources, options, actions_to_add)
824
+ _AdjustSourcesForRules(rules, sources, excluded_sources, False)
825
+
826
+
827
+ def _AdjustSourcesForRules(rules, sources, excluded_sources, is_msbuild):
828
+ # Add outputs generated by each rule (if applicable).
829
+ for rule in rules:
830
+ # Add in the outputs from this rule.
831
+ trigger_files = _FindRuleTriggerFiles(rule, sources)
832
+ for trigger_file in trigger_files:
833
+ # Remove trigger_file from excluded_sources to let the rule be triggered
834
+ # (e.g. rule trigger ax_enums.idl is added to excluded_sources
835
+ # because it's also in an action's inputs in the same project)
836
+ excluded_sources.discard(_FixPath(trigger_file))
837
+ # Done if not processing outputs as sources.
838
+ if int(rule.get('process_outputs_as_sources', False)):
839
+ inputs, outputs = _RuleInputsAndOutputs(rule, trigger_file)
840
+ inputs = OrderedSet(_FixPaths(inputs))
841
+ outputs = OrderedSet(_FixPaths(outputs))
842
+ inputs.remove(_FixPath(trigger_file))
843
+ sources.update(inputs)
844
+ if not is_msbuild:
845
+ excluded_sources.update(inputs)
846
+ sources.update(outputs)
847
+
848
+
849
+ def _FilterActionsFromExcluded(excluded_sources, actions_to_add):
850
+ """Take inputs with actions attached out of the list of exclusions.
851
+
852
+ Arguments:
853
+ excluded_sources: list of source files not to be built.
854
+ actions_to_add: dict of actions keyed on source file they're attached to.
855
+ Returns:
856
+ excluded_sources with files that have actions attached removed.
857
+ """
858
+ must_keep = OrderedSet(_FixPaths(actions_to_add.keys()))
859
+ return [s for s in excluded_sources if s not in must_keep]
860
+
861
+
862
+ def _GetDefaultConfiguration(spec):
863
+ return spec['configurations'][spec['default_configuration']]
864
+
865
+
866
+ def _GetGuidOfProject(proj_path, spec):
867
+ """Get the guid for the project.
868
+
869
+ Arguments:
870
+ proj_path: Path of the vcproj or vcxproj file to generate.
871
+ spec: The target dictionary containing the properties of the target.
872
+ Returns:
873
+ the guid.
874
+ Raises:
875
+ ValueError: if the specified GUID is invalid.
876
+ """
877
+ # Pluck out the default configuration.
878
+ default_config = _GetDefaultConfiguration(spec)
879
+ # Decide the guid of the project.
880
+ guid = default_config.get('msvs_guid')
881
+ if guid:
882
+ if VALID_MSVS_GUID_CHARS.match(guid) is None:
883
+ raise ValueError('Invalid MSVS guid: "%s". Must match regex: "%s".' %
884
+ (guid, VALID_MSVS_GUID_CHARS.pattern))
885
+ guid = '{%s}' % guid
886
+ guid = guid or MSVSNew.MakeGuid(proj_path)
887
+ return guid
888
+
889
+
890
+ def _GetMsbuildToolsetOfProject(proj_path, spec, version):
891
+ """Get the platform toolset for the project.
892
+
893
+ Arguments:
894
+ proj_path: Path of the vcproj or vcxproj file to generate.
895
+ spec: The target dictionary containing the properties of the target.
896
+ version: The MSVSVersion object.
897
+ Returns:
898
+ the platform toolset string or None.
899
+ """
900
+ # Pluck out the default configuration.
901
+ default_config = _GetDefaultConfiguration(spec)
902
+ toolset = default_config.get('msbuild_toolset')
903
+ if not toolset and version.DefaultToolset():
904
+ toolset = version.DefaultToolset()
905
+ return toolset
906
+
907
+
908
+ def _GenerateProject(project, options, version, generator_flags):
909
+ """Generates a vcproj file.
910
+
911
+ Arguments:
912
+ project: the MSVSProject object.
913
+ options: global generator options.
914
+ version: the MSVSVersion object.
915
+ generator_flags: dict of generator-specific flags.
916
+ Returns:
917
+ A list of source files that cannot be found on disk.
918
+ """
919
+ default_config = _GetDefaultConfiguration(project.spec)
920
+
921
+ # Skip emitting anything if told to with msvs_existing_vcproj option.
922
+ if default_config.get('msvs_existing_vcproj'):
923
+ return []
924
+
925
+ if version.UsesVcxproj():
926
+ return _GenerateMSBuildProject(project, options, version, generator_flags)
927
+ else:
928
+ return _GenerateMSVSProject(project, options, version, generator_flags)
929
+
930
+
931
+ # TODO: Avoid code duplication with _ValidateSourcesForOSX in make.py.
932
+ def _ValidateSourcesForMSVSProject(spec, version):
933
+ """Makes sure if duplicate basenames are not specified in the source list.
934
+
935
+ Arguments:
936
+ spec: The target dictionary containing the properties of the target.
937
+ version: The VisualStudioVersion object.
938
+ """
939
+ # This validation should not be applied to MSVC2010 and later.
940
+ assert not version.UsesVcxproj()
941
+
942
+ # TODO: Check if MSVC allows this for loadable_module targets.
943
+ if spec.get('type', None) not in ('static_library', 'shared_library'):
944
+ return
945
+ sources = spec.get('sources', [])
946
+ basenames = {}
947
+ for source in sources:
948
+ name, ext = os.path.splitext(source)
949
+ is_compiled_file = ext in [
950
+ '.c', '.cc', '.cpp', '.cxx', '.m', '.mm', '.s', '.S']
951
+ if not is_compiled_file:
952
+ continue
953
+ basename = os.path.basename(name) # Don't include extension.
954
+ basenames.setdefault(basename, []).append(source)
955
+
956
+ error = ''
957
+ for basename, files in basenames.iteritems():
958
+ if len(files) > 1:
959
+ error += ' %s: %s\n' % (basename, ' '.join(files))
960
+
961
+ if error:
962
+ print('static library %s has several files with the same basename:\n' %
963
+ spec['target_name'] + error + 'MSVC08 cannot handle that.')
964
+ raise GypError('Duplicate basenames in sources section, see list above')
965
+
966
+
967
+ def _GenerateMSVSProject(project, options, version, generator_flags):
968
+ """Generates a .vcproj file. It may create .rules and .user files too.
969
+
970
+ Arguments:
971
+ project: The project object we will generate the file for.
972
+ options: Global options passed to the generator.
973
+ version: The VisualStudioVersion object.
974
+ generator_flags: dict of generator-specific flags.
975
+ """
976
+ spec = project.spec
977
+ gyp.common.EnsureDirExists(project.path)
978
+
979
+ platforms = _GetUniquePlatforms(spec)
980
+ p = MSVSProject.Writer(project.path, version, spec['target_name'],
981
+ project.guid, platforms)
982
+
983
+ # Get directory project file is in.
984
+ project_dir = os.path.split(project.path)[0]
985
+ gyp_path = _NormalizedSource(project.build_file)
986
+ relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
987
+
988
+ config_type = _GetMSVSConfigurationType(spec, project.build_file)
989
+ for config_name, config in spec['configurations'].iteritems():
990
+ _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config)
991
+
992
+ # MSVC08 and prior version cannot handle duplicate basenames in the same
993
+ # target.
994
+ # TODO: Take excluded sources into consideration if possible.
995
+ _ValidateSourcesForMSVSProject(spec, version)
996
+
997
+ # Prepare list of sources and excluded sources.
998
+ gyp_file = os.path.split(project.build_file)[1]
999
+ sources, excluded_sources = _PrepareListOfSources(spec, generator_flags,
1000
+ gyp_file)
1001
+
1002
+ # Add rules.
1003
+ actions_to_add = {}
1004
+ _GenerateRulesForMSVS(p, project_dir, options, spec,
1005
+ sources, excluded_sources,
1006
+ actions_to_add)
1007
+ list_excluded = generator_flags.get('msvs_list_excluded_files', True)
1008
+ sources, excluded_sources, excluded_idl = (
1009
+ _AdjustSourcesAndConvertToFilterHierarchy(spec, options, project_dir,
1010
+ sources, excluded_sources,
1011
+ list_excluded, version))
1012
+
1013
+ # Add in files.
1014
+ missing_sources = _VerifySourcesExist(sources, project_dir)
1015
+ p.AddFiles(sources)
1016
+
1017
+ _AddToolFilesToMSVS(p, spec)
1018
+ _HandlePreCompiledHeaders(p, sources, spec)
1019
+ _AddActions(actions_to_add, spec, relative_path_of_gyp_file)
1020
+ _AddCopies(actions_to_add, spec)
1021
+ _WriteMSVSUserFile(project.path, version, spec)
1022
+
1023
+ # NOTE: this stanza must appear after all actions have been decided.
1024
+ # Don't excluded sources with actions attached, or they won't run.
1025
+ excluded_sources = _FilterActionsFromExcluded(
1026
+ excluded_sources, actions_to_add)
1027
+ _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl,
1028
+ list_excluded)
1029
+ _AddAccumulatedActionsToMSVS(p, spec, actions_to_add)
1030
+
1031
+ # Write it out.
1032
+ p.WriteIfChanged()
1033
+
1034
+ return missing_sources
1035
+
1036
+
1037
+ def _GetUniquePlatforms(spec):
1038
+ """Returns the list of unique platforms for this spec, e.g ['win32', ...].
1039
+
1040
+ Arguments:
1041
+ spec: The target dictionary containing the properties of the target.
1042
+ Returns:
1043
+ The MSVSUserFile object created.
1044
+ """
1045
+ # Gather list of unique platforms.
1046
+ platforms = OrderedSet()
1047
+ for configuration in spec['configurations']:
1048
+ platforms.add(_ConfigPlatform(spec['configurations'][configuration]))
1049
+ platforms = list(platforms)
1050
+ return platforms
1051
+
1052
+
1053
+ def _CreateMSVSUserFile(proj_path, version, spec):
1054
+ """Generates a .user file for the user running this Gyp program.
1055
+
1056
+ Arguments:
1057
+ proj_path: The path of the project file being created. The .user file
1058
+ shares the same path (with an appropriate suffix).
1059
+ version: The VisualStudioVersion object.
1060
+ spec: The target dictionary containing the properties of the target.
1061
+ Returns:
1062
+ The MSVSUserFile object created.
1063
+ """
1064
+ (domain, username) = _GetDomainAndUserName()
1065
+ vcuser_filename = '.'.join([proj_path, domain, username, 'user'])
1066
+ user_file = MSVSUserFile.Writer(vcuser_filename, version,
1067
+ spec['target_name'])
1068
+ return user_file
1069
+
1070
+
1071
+ def _GetMSVSConfigurationType(spec, build_file):
1072
+ """Returns the configuration type for this project.
1073
+
1074
+ It's a number defined by Microsoft. May raise an exception.
1075
+
1076
+ Args:
1077
+ spec: The target dictionary containing the properties of the target.
1078
+ build_file: The path of the gyp file.
1079
+ Returns:
1080
+ An integer, the configuration type.
1081
+ """
1082
+ try:
1083
+ config_type = {
1084
+ 'executable': '1', # .exe
1085
+ 'shared_library': '2', # .dll
1086
+ 'loadable_module': '2', # .dll
1087
+ 'static_library': '4', # .lib
1088
+ 'none': '10', # Utility type
1089
+ }[spec['type']]
1090
+ except KeyError:
1091
+ if spec.get('type'):
1092
+ raise GypError('Target type %s is not a valid target type for '
1093
+ 'target %s in %s.' %
1094
+ (spec['type'], spec['target_name'], build_file))
1095
+ else:
1096
+ raise GypError('Missing type field for target %s in %s.' %
1097
+ (spec['target_name'], build_file))
1098
+ return config_type
1099
+
1100
+
1101
+ def _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config):
1102
+ """Adds a configuration to the MSVS project.
1103
+
1104
+ Many settings in a vcproj file are specific to a configuration. This
1105
+ function the main part of the vcproj file that's configuration specific.
1106
+
1107
+ Arguments:
1108
+ p: The target project being generated.
1109
+ spec: The target dictionary containing the properties of the target.
1110
+ config_type: The configuration type, a number as defined by Microsoft.
1111
+ config_name: The name of the configuration.
1112
+ config: The dictionary that defines the special processing to be done
1113
+ for this configuration.
1114
+ """
1115
+ # Get the information for this configuration
1116
+ include_dirs, midl_include_dirs, resource_include_dirs = \
1117
+ _GetIncludeDirs(config)
1118
+ libraries = _GetLibraries(spec)
1119
+ library_dirs = _GetLibraryDirs(config)
1120
+ out_file, vc_tool, _ = _GetOutputFilePathAndTool(spec, msbuild=False)
1121
+ defines = _GetDefines(config)
1122
+ defines = [_EscapeCppDefineForMSVS(d) for d in defines]
1123
+ disabled_warnings = _GetDisabledWarnings(config)
1124
+ prebuild = config.get('msvs_prebuild')
1125
+ postbuild = config.get('msvs_postbuild')
1126
+ def_file = _GetModuleDefinition(spec)
1127
+ precompiled_header = config.get('msvs_precompiled_header')
1128
+
1129
+ # Prepare the list of tools as a dictionary.
1130
+ tools = dict()
1131
+ # Add in user specified msvs_settings.
1132
+ msvs_settings = config.get('msvs_settings', {})
1133
+ MSVSSettings.ValidateMSVSSettings(msvs_settings)
1134
+
1135
+ # Prevent default library inheritance from the environment.
1136
+ _ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', ['$(NOINHERIT)'])
1137
+
1138
+ for tool in msvs_settings:
1139
+ settings = config['msvs_settings'][tool]
1140
+ for setting in settings:
1141
+ _ToolAppend(tools, tool, setting, settings[setting])
1142
+ # Add the information to the appropriate tool
1143
+ _ToolAppend(tools, 'VCCLCompilerTool',
1144
+ 'AdditionalIncludeDirectories', include_dirs)
1145
+ _ToolAppend(tools, 'VCMIDLTool',
1146
+ 'AdditionalIncludeDirectories', midl_include_dirs)
1147
+ _ToolAppend(tools, 'VCResourceCompilerTool',
1148
+ 'AdditionalIncludeDirectories', resource_include_dirs)
1149
+ # Add in libraries.
1150
+ _ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', libraries)
1151
+ _ToolAppend(tools, 'VCLinkerTool', 'AdditionalLibraryDirectories',
1152
+ library_dirs)
1153
+ if out_file:
1154
+ _ToolAppend(tools, vc_tool, 'OutputFile', out_file, only_if_unset=True)
1155
+ # Add defines.
1156
+ _ToolAppend(tools, 'VCCLCompilerTool', 'PreprocessorDefinitions', defines)
1157
+ _ToolAppend(tools, 'VCResourceCompilerTool', 'PreprocessorDefinitions',
1158
+ defines)
1159
+ # Change program database directory to prevent collisions.
1160
+ _ToolAppend(tools, 'VCCLCompilerTool', 'ProgramDataBaseFileName',
1161
+ '$(IntDir)$(ProjectName)\\vc80.pdb', only_if_unset=True)
1162
+ # Add disabled warnings.
1163
+ _ToolAppend(tools, 'VCCLCompilerTool',
1164
+ 'DisableSpecificWarnings', disabled_warnings)
1165
+ # Add Pre-build.
1166
+ _ToolAppend(tools, 'VCPreBuildEventTool', 'CommandLine', prebuild)
1167
+ # Add Post-build.
1168
+ _ToolAppend(tools, 'VCPostBuildEventTool', 'CommandLine', postbuild)
1169
+ # Turn on precompiled headers if appropriate.
1170
+ if precompiled_header:
1171
+ precompiled_header = os.path.split(precompiled_header)[1]
1172
+ _ToolAppend(tools, 'VCCLCompilerTool', 'UsePrecompiledHeader', '2')
1173
+ _ToolAppend(tools, 'VCCLCompilerTool',
1174
+ 'PrecompiledHeaderThrough', precompiled_header)
1175
+ _ToolAppend(tools, 'VCCLCompilerTool',
1176
+ 'ForcedIncludeFiles', precompiled_header)
1177
+ # Loadable modules don't generate import libraries;
1178
+ # tell dependent projects to not expect one.
1179
+ if spec['type'] == 'loadable_module':
1180
+ _ToolAppend(tools, 'VCLinkerTool', 'IgnoreImportLibrary', 'true')
1181
+ # Set the module definition file if any.
1182
+ if def_file:
1183
+ _ToolAppend(tools, 'VCLinkerTool', 'ModuleDefinitionFile', def_file)
1184
+
1185
+ _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name)
1186
+
1187
+
1188
+ def _GetIncludeDirs(config):
1189
+ """Returns the list of directories to be used for #include directives.
1190
+
1191
+ Arguments:
1192
+ config: The dictionary that defines the special processing to be done
1193
+ for this configuration.
1194
+ Returns:
1195
+ The list of directory paths.
1196
+ """
1197
+ # TODO(bradnelson): include_dirs should really be flexible enough not to
1198
+ # require this sort of thing.
1199
+ include_dirs = (
1200
+ config.get('include_dirs', []) +
1201
+ config.get('msvs_system_include_dirs', []))
1202
+ midl_include_dirs = (
1203
+ config.get('midl_include_dirs', []) +
1204
+ config.get('msvs_system_include_dirs', []))
1205
+ resource_include_dirs = config.get('resource_include_dirs', include_dirs)
1206
+ include_dirs = _FixPaths(include_dirs)
1207
+ midl_include_dirs = _FixPaths(midl_include_dirs)
1208
+ resource_include_dirs = _FixPaths(resource_include_dirs)
1209
+ return include_dirs, midl_include_dirs, resource_include_dirs
1210
+
1211
+
1212
+ def _GetLibraryDirs(config):
1213
+ """Returns the list of directories to be used for library search paths.
1214
+
1215
+ Arguments:
1216
+ config: The dictionary that defines the special processing to be done
1217
+ for this configuration.
1218
+ Returns:
1219
+ The list of directory paths.
1220
+ """
1221
+
1222
+ library_dirs = config.get('library_dirs', [])
1223
+ library_dirs = _FixPaths(library_dirs)
1224
+ return library_dirs
1225
+
1226
+
1227
+ def _GetLibraries(spec):
1228
+ """Returns the list of libraries for this configuration.
1229
+
1230
+ Arguments:
1231
+ spec: The target dictionary containing the properties of the target.
1232
+ Returns:
1233
+ The list of directory paths.
1234
+ """
1235
+ libraries = spec.get('libraries', [])
1236
+ # Strip out -l, as it is not used on windows (but is needed so we can pass
1237
+ # in libraries that are assumed to be in the default library path).
1238
+ # Also remove duplicate entries, leaving only the last duplicate, while
1239
+ # preserving order.
1240
+ found = OrderedSet()
1241
+ unique_libraries_list = []
1242
+ for entry in reversed(libraries):
1243
+ library = re.sub(r'^\-l', '', entry)
1244
+ if not os.path.splitext(library)[1]:
1245
+ library += '.lib'
1246
+ if library not in found:
1247
+ found.add(library)
1248
+ unique_libraries_list.append(library)
1249
+ unique_libraries_list.reverse()
1250
+ return unique_libraries_list
1251
+
1252
+
1253
+ def _GetOutputFilePathAndTool(spec, msbuild):
1254
+ """Returns the path and tool to use for this target.
1255
+
1256
+ Figures out the path of the file this spec will create and the name of
1257
+ the VC tool that will create it.
1258
+
1259
+ Arguments:
1260
+ spec: The target dictionary containing the properties of the target.
1261
+ Returns:
1262
+ A triple of (file path, name of the vc tool, name of the msbuild tool)
1263
+ """
1264
+ # Select a name for the output file.
1265
+ out_file = ''
1266
+ vc_tool = ''
1267
+ msbuild_tool = ''
1268
+ output_file_map = {
1269
+ 'executable': ('VCLinkerTool', 'Link', '$(OutDir)', '.exe'),
1270
+ 'shared_library': ('VCLinkerTool', 'Link', '$(OutDir)', '.dll'),
1271
+ 'loadable_module': ('VCLinkerTool', 'Link', '$(OutDir)', '.dll'),
1272
+ 'static_library': ('VCLibrarianTool', 'Lib', '$(OutDir)lib\\', '.lib'),
1273
+ }
1274
+ output_file_props = output_file_map.get(spec['type'])
1275
+ if output_file_props and int(spec.get('msvs_auto_output_file', 1)):
1276
+ vc_tool, msbuild_tool, out_dir, suffix = output_file_props
1277
+ if spec.get('standalone_static_library', 0):
1278
+ out_dir = '$(OutDir)'
1279
+ out_dir = spec.get('product_dir', out_dir)
1280
+ product_extension = spec.get('product_extension')
1281
+ if product_extension:
1282
+ suffix = '.' + product_extension
1283
+ elif msbuild:
1284
+ suffix = '$(TargetExt)'
1285
+ prefix = spec.get('product_prefix', '')
1286
+ product_name = spec.get('product_name', '$(ProjectName)')
1287
+ out_file = ntpath.join(out_dir, prefix + product_name + suffix)
1288
+ return out_file, vc_tool, msbuild_tool
1289
+
1290
+
1291
+ def _GetOutputTargetExt(spec):
1292
+ """Returns the extension for this target, including the dot
1293
+
1294
+ If product_extension is specified, set target_extension to this to avoid
1295
+ MSB8012, returns None otherwise. Ignores any target_extension settings in
1296
+ the input files.
1297
+
1298
+ Arguments:
1299
+ spec: The target dictionary containing the properties of the target.
1300
+ Returns:
1301
+ A string with the extension, or None
1302
+ """
1303
+ target_extension = spec.get('product_extension')
1304
+ if target_extension:
1305
+ return '.' + target_extension
1306
+ return None
1307
+
1308
+
1309
+ def _GetDefines(config):
1310
+ """Returns the list of preprocessor definitions for this configuation.
1311
+
1312
+ Arguments:
1313
+ config: The dictionary that defines the special processing to be done
1314
+ for this configuration.
1315
+ Returns:
1316
+ The list of preprocessor definitions.
1317
+ """
1318
+ defines = []
1319
+ for d in config.get('defines', []):
1320
+ if type(d) == list:
1321
+ fd = '='.join([str(dpart) for dpart in d])
1322
+ else:
1323
+ fd = str(d)
1324
+ defines.append(fd)
1325
+ return defines
1326
+
1327
+
1328
+ def _GetDisabledWarnings(config):
1329
+ return [str(i) for i in config.get('msvs_disabled_warnings', [])]
1330
+
1331
+
1332
+ def _GetModuleDefinition(spec):
1333
+ def_file = ''
1334
+ if spec['type'] in ['shared_library', 'loadable_module', 'executable']:
1335
+ def_files = [s for s in spec.get('sources', []) if s.endswith('.def')]
1336
+ if len(def_files) == 1:
1337
+ def_file = _FixPath(def_files[0])
1338
+ elif def_files:
1339
+ raise ValueError(
1340
+ 'Multiple module definition files in one target, target %s lists '
1341
+ 'multiple .def files: %s' % (
1342
+ spec['target_name'], ' '.join(def_files)))
1343
+ return def_file
1344
+
1345
+
1346
+ def _ConvertToolsToExpectedForm(tools):
1347
+ """Convert tools to a form expected by Visual Studio.
1348
+
1349
+ Arguments:
1350
+ tools: A dictionary of settings; the tool name is the key.
1351
+ Returns:
1352
+ A list of Tool objects.
1353
+ """
1354
+ tool_list = []
1355
+ for tool, settings in tools.iteritems():
1356
+ # Collapse settings with lists.
1357
+ settings_fixed = {}
1358
+ for setting, value in settings.iteritems():
1359
+ if type(value) == list:
1360
+ if ((tool == 'VCLinkerTool' and
1361
+ setting == 'AdditionalDependencies') or
1362
+ setting == 'AdditionalOptions'):
1363
+ settings_fixed[setting] = ' '.join(value)
1364
+ else:
1365
+ settings_fixed[setting] = ';'.join(value)
1366
+ else:
1367
+ settings_fixed[setting] = value
1368
+ # Add in this tool.
1369
+ tool_list.append(MSVSProject.Tool(tool, settings_fixed))
1370
+ return tool_list
1371
+
1372
+
1373
+ def _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name):
1374
+ """Add to the project file the configuration specified by config.
1375
+
1376
+ Arguments:
1377
+ p: The target project being generated.
1378
+ spec: the target project dict.
1379
+ tools: A dictionary of settings; the tool name is the key.
1380
+ config: The dictionary that defines the special processing to be done
1381
+ for this configuration.
1382
+ config_type: The configuration type, a number as defined by Microsoft.
1383
+ config_name: The name of the configuration.
1384
+ """
1385
+ attributes = _GetMSVSAttributes(spec, config, config_type)
1386
+ # Add in this configuration.
1387
+ tool_list = _ConvertToolsToExpectedForm(tools)
1388
+ p.AddConfig(_ConfigFullName(config_name, config),
1389
+ attrs=attributes, tools=tool_list)
1390
+
1391
+
1392
+ def _GetMSVSAttributes(spec, config, config_type):
1393
+ # Prepare configuration attributes.
1394
+ prepared_attrs = {}
1395
+ source_attrs = config.get('msvs_configuration_attributes', {})
1396
+ for a in source_attrs:
1397
+ prepared_attrs[a] = source_attrs[a]
1398
+ # Add props files.
1399
+ vsprops_dirs = config.get('msvs_props', [])
1400
+ vsprops_dirs = _FixPaths(vsprops_dirs)
1401
+ if vsprops_dirs:
1402
+ prepared_attrs['InheritedPropertySheets'] = ';'.join(vsprops_dirs)
1403
+ # Set configuration type.
1404
+ prepared_attrs['ConfigurationType'] = config_type
1405
+ output_dir = prepared_attrs.get('OutputDirectory',
1406
+ '$(SolutionDir)$(ConfigurationName)')
1407
+ prepared_attrs['OutputDirectory'] = _FixPath(output_dir) + '\\'
1408
+ if 'IntermediateDirectory' not in prepared_attrs:
1409
+ intermediate = '$(ConfigurationName)\\obj\\$(ProjectName)'
1410
+ prepared_attrs['IntermediateDirectory'] = _FixPath(intermediate) + '\\'
1411
+ else:
1412
+ intermediate = _FixPath(prepared_attrs['IntermediateDirectory']) + '\\'
1413
+ intermediate = MSVSSettings.FixVCMacroSlashes(intermediate)
1414
+ prepared_attrs['IntermediateDirectory'] = intermediate
1415
+ return prepared_attrs
1416
+
1417
+
1418
+ def _AddNormalizedSources(sources_set, sources_array):
1419
+ sources_set.update(_NormalizedSource(s) for s in sources_array)
1420
+
1421
+
1422
+ def _PrepareListOfSources(spec, generator_flags, gyp_file):
1423
+ """Prepare list of sources and excluded sources.
1424
+
1425
+ Besides the sources specified directly in the spec, adds the gyp file so
1426
+ that a change to it will cause a re-compile. Also adds appropriate sources
1427
+ for actions and copies. Assumes later stage will un-exclude files which
1428
+ have custom build steps attached.
1429
+
1430
+ Arguments:
1431
+ spec: The target dictionary containing the properties of the target.
1432
+ gyp_file: The name of the gyp file.
1433
+ Returns:
1434
+ A pair of (list of sources, list of excluded sources).
1435
+ The sources will be relative to the gyp file.
1436
+ """
1437
+ sources = OrderedSet()
1438
+ _AddNormalizedSources(sources, spec.get('sources', []))
1439
+ excluded_sources = OrderedSet()
1440
+ # Add in the gyp file.
1441
+ if not generator_flags.get('standalone'):
1442
+ sources.add(gyp_file)
1443
+
1444
+ # Add in 'action' inputs and outputs.
1445
+ for a in spec.get('actions', []):
1446
+ inputs = a['inputs']
1447
+ inputs = [_NormalizedSource(i) for i in inputs]
1448
+ # Add all inputs to sources and excluded sources.
1449
+ inputs = OrderedSet(inputs)
1450
+ sources.update(inputs)
1451
+ if not spec.get('msvs_external_builder'):
1452
+ excluded_sources.update(inputs)
1453
+ if int(a.get('process_outputs_as_sources', False)):
1454
+ _AddNormalizedSources(sources, a.get('outputs', []))
1455
+ # Add in 'copies' inputs and outputs.
1456
+ for cpy in spec.get('copies', []):
1457
+ _AddNormalizedSources(sources, cpy.get('files', []))
1458
+ return (sources, excluded_sources)
1459
+
1460
+
1461
+ def _AdjustSourcesAndConvertToFilterHierarchy(
1462
+ spec, options, gyp_dir, sources, excluded_sources, list_excluded, version):
1463
+ """Adjusts the list of sources and excluded sources.
1464
+
1465
+ Also converts the sets to lists.
1466
+
1467
+ Arguments:
1468
+ spec: The target dictionary containing the properties of the target.
1469
+ options: Global generator options.
1470
+ gyp_dir: The path to the gyp file being processed.
1471
+ sources: A set of sources to be included for this project.
1472
+ excluded_sources: A set of sources to be excluded for this project.
1473
+ version: A MSVSVersion object.
1474
+ Returns:
1475
+ A trio of (list of sources, list of excluded sources,
1476
+ path of excluded IDL file)
1477
+ """
1478
+ # Exclude excluded sources coming into the generator.
1479
+ excluded_sources.update(OrderedSet(spec.get('sources_excluded', [])))
1480
+ # Add excluded sources into sources for good measure.
1481
+ sources.update(excluded_sources)
1482
+ # Convert to proper windows form.
1483
+ # NOTE: sources goes from being a set to a list here.
1484
+ # NOTE: excluded_sources goes from being a set to a list here.
1485
+ sources = _FixPaths(sources)
1486
+ # Convert to proper windows form.
1487
+ excluded_sources = _FixPaths(excluded_sources)
1488
+
1489
+ excluded_idl = _IdlFilesHandledNonNatively(spec, sources)
1490
+
1491
+ precompiled_related = _GetPrecompileRelatedFiles(spec)
1492
+ # Find the excluded ones, minus the precompiled header related ones.
1493
+ fully_excluded = [i for i in excluded_sources if i not in precompiled_related]
1494
+
1495
+ # Convert to folders and the right slashes.
1496
+ sources = [i.split('\\') for i in sources]
1497
+ sources = _ConvertSourcesToFilterHierarchy(sources, excluded=fully_excluded,
1498
+ list_excluded=list_excluded,
1499
+ msvs_version=version)
1500
+
1501
+ # Prune filters with a single child to flatten ugly directory structures
1502
+ # such as ../../src/modules/module1 etc.
1503
+ if version.UsesVcxproj():
1504
+ while all([isinstance(s, MSVSProject.Filter) for s in sources]) \
1505
+ and len(set([s.name for s in sources])) == 1:
1506
+ assert all([len(s.contents) == 1 for s in sources])
1507
+ sources = [s.contents[0] for s in sources]
1508
+ else:
1509
+ while len(sources) == 1 and isinstance(sources[0], MSVSProject.Filter):
1510
+ sources = sources[0].contents
1511
+
1512
+ return sources, excluded_sources, excluded_idl
1513
+
1514
+
1515
+ def _IdlFilesHandledNonNatively(spec, sources):
1516
+ # If any non-native rules use 'idl' as an extension exclude idl files.
1517
+ # Gather a list here to use later.
1518
+ using_idl = False
1519
+ for rule in spec.get('rules', []):
1520
+ if rule['extension'] == 'idl' and int(rule.get('msvs_external_rule', 0)):
1521
+ using_idl = True
1522
+ break
1523
+ if using_idl:
1524
+ excluded_idl = [i for i in sources if i.endswith('.idl')]
1525
+ else:
1526
+ excluded_idl = []
1527
+ return excluded_idl
1528
+
1529
+
1530
+ def _GetPrecompileRelatedFiles(spec):
1531
+ # Gather a list of precompiled header related sources.
1532
+ precompiled_related = []
1533
+ for _, config in spec['configurations'].iteritems():
1534
+ for k in precomp_keys:
1535
+ f = config.get(k)
1536
+ if f:
1537
+ precompiled_related.append(_FixPath(f))
1538
+ return precompiled_related
1539
+
1540
+
1541
+ def _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl,
1542
+ list_excluded):
1543
+ exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
1544
+ for file_name, excluded_configs in exclusions.iteritems():
1545
+ if (not list_excluded and
1546
+ len(excluded_configs) == len(spec['configurations'])):
1547
+ # If we're not listing excluded files, then they won't appear in the
1548
+ # project, so don't try to configure them to be excluded.
1549
+ pass
1550
+ else:
1551
+ for config_name, config in excluded_configs:
1552
+ p.AddFileConfig(file_name, _ConfigFullName(config_name, config),
1553
+ {'ExcludedFromBuild': 'true'})
1554
+
1555
+
1556
+ def _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl):
1557
+ exclusions = {}
1558
+ # Exclude excluded sources from being built.
1559
+ for f in excluded_sources:
1560
+ excluded_configs = []
1561
+ for config_name, config in spec['configurations'].iteritems():
1562
+ precomped = [_FixPath(config.get(i, '')) for i in precomp_keys]
1563
+ # Don't do this for ones that are precompiled header related.
1564
+ if f not in precomped:
1565
+ excluded_configs.append((config_name, config))
1566
+ exclusions[f] = excluded_configs
1567
+ # If any non-native rules use 'idl' as an extension exclude idl files.
1568
+ # Exclude them now.
1569
+ for f in excluded_idl:
1570
+ excluded_configs = []
1571
+ for config_name, config in spec['configurations'].iteritems():
1572
+ excluded_configs.append((config_name, config))
1573
+ exclusions[f] = excluded_configs
1574
+ return exclusions
1575
+
1576
+
1577
+ def _AddToolFilesToMSVS(p, spec):
1578
+ # Add in tool files (rules).
1579
+ tool_files = OrderedSet()
1580
+ for _, config in spec['configurations'].iteritems():
1581
+ for f in config.get('msvs_tool_files', []):
1582
+ tool_files.add(f)
1583
+ for f in tool_files:
1584
+ p.AddToolFile(f)
1585
+
1586
+
1587
+ def _HandlePreCompiledHeaders(p, sources, spec):
1588
+ # Pre-compiled header source stubs need a different compiler flag
1589
+ # (generate precompiled header) and any source file not of the same
1590
+ # kind (i.e. C vs. C++) as the precompiled header source stub needs
1591
+ # to have use of precompiled headers disabled.
1592
+ extensions_excluded_from_precompile = []
1593
+ for config_name, config in spec['configurations'].iteritems():
1594
+ source = config.get('msvs_precompiled_source')
1595
+ if source:
1596
+ source = _FixPath(source)
1597
+ # UsePrecompiledHeader=1 for if using precompiled headers.
1598
+ tool = MSVSProject.Tool('VCCLCompilerTool',
1599
+ {'UsePrecompiledHeader': '1'})
1600
+ p.AddFileConfig(source, _ConfigFullName(config_name, config),
1601
+ {}, tools=[tool])
1602
+ basename, extension = os.path.splitext(source)
1603
+ if extension == '.c':
1604
+ extensions_excluded_from_precompile = ['.cc', '.cpp', '.cxx']
1605
+ else:
1606
+ extensions_excluded_from_precompile = ['.c']
1607
+ def DisableForSourceTree(source_tree):
1608
+ for source in source_tree:
1609
+ if isinstance(source, MSVSProject.Filter):
1610
+ DisableForSourceTree(source.contents)
1611
+ else:
1612
+ basename, extension = os.path.splitext(source)
1613
+ if extension in extensions_excluded_from_precompile:
1614
+ for config_name, config in spec['configurations'].iteritems():
1615
+ tool = MSVSProject.Tool('VCCLCompilerTool',
1616
+ {'UsePrecompiledHeader': '0',
1617
+ 'ForcedIncludeFiles': '$(NOINHERIT)'})
1618
+ p.AddFileConfig(_FixPath(source),
1619
+ _ConfigFullName(config_name, config),
1620
+ {}, tools=[tool])
1621
+ # Do nothing if there was no precompiled source.
1622
+ if extensions_excluded_from_precompile:
1623
+ DisableForSourceTree(sources)
1624
+
1625
+
1626
+ def _AddActions(actions_to_add, spec, relative_path_of_gyp_file):
1627
+ # Add actions.
1628
+ actions = spec.get('actions', [])
1629
+ # Don't setup_env every time. When all the actions are run together in one
1630
+ # batch file in VS, the PATH will grow too long.
1631
+ # Membership in this set means that the cygwin environment has been set up,
1632
+ # and does not need to be set up again.
1633
+ have_setup_env = set()
1634
+ for a in actions:
1635
+ # Attach actions to the gyp file if nothing else is there.
1636
+ inputs = a.get('inputs') or [relative_path_of_gyp_file]
1637
+ attached_to = inputs[0]
1638
+ need_setup_env = attached_to not in have_setup_env
1639
+ cmd = _BuildCommandLineForRule(spec, a, has_input_path=False,
1640
+ do_setup_env=need_setup_env)
1641
+ have_setup_env.add(attached_to)
1642
+ # Add the action.
1643
+ _AddActionStep(actions_to_add,
1644
+ inputs=inputs,
1645
+ outputs=a.get('outputs', []),
1646
+ description=a.get('message', a['action_name']),
1647
+ command=cmd)
1648
+
1649
+
1650
+ def _WriteMSVSUserFile(project_path, version, spec):
1651
+ # Add run_as and test targets.
1652
+ if 'run_as' in spec:
1653
+ run_as = spec['run_as']
1654
+ action = run_as.get('action', [])
1655
+ environment = run_as.get('environment', [])
1656
+ working_directory = run_as.get('working_directory', '.')
1657
+ elif int(spec.get('test', 0)):
1658
+ action = ['$(TargetPath)', '--gtest_print_time']
1659
+ environment = []
1660
+ working_directory = '.'
1661
+ else:
1662
+ return # Nothing to add
1663
+ # Write out the user file.
1664
+ user_file = _CreateMSVSUserFile(project_path, version, spec)
1665
+ for config_name, c_data in spec['configurations'].iteritems():
1666
+ user_file.AddDebugSettings(_ConfigFullName(config_name, c_data),
1667
+ action, environment, working_directory)
1668
+ user_file.WriteIfChanged()
1669
+
1670
+
1671
+ def _AddCopies(actions_to_add, spec):
1672
+ copies = _GetCopies(spec)
1673
+ for inputs, outputs, cmd, description in copies:
1674
+ _AddActionStep(actions_to_add, inputs=inputs, outputs=outputs,
1675
+ description=description, command=cmd)
1676
+
1677
+
1678
+ def _GetCopies(spec):
1679
+ copies = []
1680
+ # Add copies.
1681
+ for cpy in spec.get('copies', []):
1682
+ for src in cpy.get('files', []):
1683
+ dst = os.path.join(cpy['destination'], os.path.basename(src))
1684
+ # _AddCustomBuildToolForMSVS() will call _FixPath() on the inputs and
1685
+ # outputs, so do the same for our generated command line.
1686
+ if src.endswith('/'):
1687
+ src_bare = src[:-1]
1688
+ base_dir = posixpath.split(src_bare)[0]
1689
+ outer_dir = posixpath.split(src_bare)[1]
1690
+ cmd = 'cd "%s" && xcopy /e /f /y "%s" "%s\\%s\\"' % (
1691
+ _FixPath(base_dir), outer_dir, _FixPath(dst), outer_dir)
1692
+ copies.append(([src], ['dummy_copies', dst], cmd,
1693
+ 'Copying %s to %s' % (src, dst)))
1694
+ else:
1695
+ cmd = 'mkdir "%s" 2>nul & set ERRORLEVEL=0 & copy /Y "%s" "%s"' % (
1696
+ _FixPath(cpy['destination']), _FixPath(src), _FixPath(dst))
1697
+ copies.append(([src], [dst], cmd, 'Copying %s to %s' % (src, dst)))
1698
+ return copies
1699
+
1700
+
1701
+ def _GetPathDict(root, path):
1702
+ # |path| will eventually be empty (in the recursive calls) if it was initially
1703
+ # relative; otherwise it will eventually end up as '\', 'D:\', etc.
1704
+ if not path or path.endswith(os.sep):
1705
+ return root
1706
+ parent, folder = os.path.split(path)
1707
+ parent_dict = _GetPathDict(root, parent)
1708
+ if folder not in parent_dict:
1709
+ parent_dict[folder] = dict()
1710
+ return parent_dict[folder]
1711
+
1712
+
1713
+ def _DictsToFolders(base_path, bucket, flat):
1714
+ # Convert to folders recursively.
1715
+ children = []
1716
+ for folder, contents in bucket.iteritems():
1717
+ if type(contents) == dict:
1718
+ folder_children = _DictsToFolders(os.path.join(base_path, folder),
1719
+ contents, flat)
1720
+ if flat:
1721
+ children += folder_children
1722
+ else:
1723
+ folder_children = MSVSNew.MSVSFolder(os.path.join(base_path, folder),
1724
+ name='(' + folder + ')',
1725
+ entries=folder_children)
1726
+ children.append(folder_children)
1727
+ else:
1728
+ children.append(contents)
1729
+ return children
1730
+
1731
+
1732
+ def _CollapseSingles(parent, node):
1733
+ # Recursively explorer the tree of dicts looking for projects which are
1734
+ # the sole item in a folder which has the same name as the project. Bring
1735
+ # such projects up one level.
1736
+ if (type(node) == dict and
1737
+ len(node) == 1 and
1738
+ node.keys()[0] == parent + '.vcproj'):
1739
+ return node[node.keys()[0]]
1740
+ if type(node) != dict:
1741
+ return node
1742
+ for child in node:
1743
+ node[child] = _CollapseSingles(child, node[child])
1744
+ return node
1745
+
1746
+
1747
+ def _GatherSolutionFolders(sln_projects, project_objects, flat):
1748
+ root = {}
1749
+ # Convert into a tree of dicts on path.
1750
+ for p in sln_projects:
1751
+ gyp_file, target = gyp.common.ParseQualifiedTarget(p)[0:2]
1752
+ gyp_dir = os.path.dirname(gyp_file)
1753
+ path_dict = _GetPathDict(root, gyp_dir)
1754
+ path_dict[target + '.vcproj'] = project_objects[p]
1755
+ # Walk down from the top until we hit a folder that has more than one entry.
1756
+ # In practice, this strips the top-level "src/" dir from the hierarchy in
1757
+ # the solution.
1758
+ while len(root) == 1 and type(root[root.keys()[0]]) == dict:
1759
+ root = root[root.keys()[0]]
1760
+ # Collapse singles.
1761
+ root = _CollapseSingles('', root)
1762
+ # Merge buckets until everything is a root entry.
1763
+ return _DictsToFolders('', root, flat)
1764
+
1765
+
1766
+ def _GetPathOfProject(qualified_target, spec, options, msvs_version):
1767
+ default_config = _GetDefaultConfiguration(spec)
1768
+ proj_filename = default_config.get('msvs_existing_vcproj')
1769
+ if not proj_filename:
1770
+ proj_filename = (spec['target_name'] + options.suffix +
1771
+ msvs_version.ProjectExtension())
1772
+
1773
+ build_file = gyp.common.BuildFile(qualified_target)
1774
+ proj_path = os.path.join(os.path.dirname(build_file), proj_filename)
1775
+ fix_prefix = None
1776
+ if options.generator_output:
1777
+ project_dir_path = os.path.dirname(os.path.abspath(proj_path))
1778
+ proj_path = os.path.join(options.generator_output, proj_path)
1779
+ fix_prefix = gyp.common.RelativePath(project_dir_path,
1780
+ os.path.dirname(proj_path))
1781
+ return proj_path, fix_prefix
1782
+
1783
+
1784
+ def _GetPlatformOverridesOfProject(spec):
1785
+ # Prepare a dict indicating which project configurations are used for which
1786
+ # solution configurations for this target.
1787
+ config_platform_overrides = {}
1788
+ for config_name, c in spec['configurations'].iteritems():
1789
+ config_fullname = _ConfigFullName(config_name, c)
1790
+ platform = c.get('msvs_target_platform', _ConfigPlatform(c))
1791
+ fixed_config_fullname = '%s|%s' % (
1792
+ _ConfigBaseName(config_name, _ConfigPlatform(c)), platform)
1793
+ config_platform_overrides[config_fullname] = fixed_config_fullname
1794
+ return config_platform_overrides
1795
+
1796
+
1797
+ def _CreateProjectObjects(target_list, target_dicts, options, msvs_version):
1798
+ """Create a MSVSProject object for the targets found in target list.
1799
+
1800
+ Arguments:
1801
+ target_list: the list of targets to generate project objects for.
1802
+ target_dicts: the dictionary of specifications.
1803
+ options: global generator options.
1804
+ msvs_version: the MSVSVersion object.
1805
+ Returns:
1806
+ A set of created projects, keyed by target.
1807
+ """
1808
+ global fixpath_prefix
1809
+ # Generate each project.
1810
+ projects = {}
1811
+ for qualified_target in target_list:
1812
+ spec = target_dicts[qualified_target]
1813
+ if spec['toolset'] != 'target':
1814
+ raise GypError(
1815
+ 'Multiple toolsets not supported in msvs build (target %s)' %
1816
+ qualified_target)
1817
+ proj_path, fixpath_prefix = _GetPathOfProject(qualified_target, spec,
1818
+ options, msvs_version)
1819
+ guid = _GetGuidOfProject(proj_path, spec)
1820
+ overrides = _GetPlatformOverridesOfProject(spec)
1821
+ build_file = gyp.common.BuildFile(qualified_target)
1822
+ # Create object for this project.
1823
+ obj = MSVSNew.MSVSProject(
1824
+ proj_path,
1825
+ name=spec['target_name'],
1826
+ guid=guid,
1827
+ spec=spec,
1828
+ build_file=build_file,
1829
+ config_platform_overrides=overrides,
1830
+ fixpath_prefix=fixpath_prefix)
1831
+ # Set project toolset if any (MS build only)
1832
+ if msvs_version.UsesVcxproj():
1833
+ obj.set_msbuild_toolset(
1834
+ _GetMsbuildToolsetOfProject(proj_path, spec, msvs_version))
1835
+ projects[qualified_target] = obj
1836
+ # Set all the dependencies, but not if we are using an external builder like
1837
+ # ninja
1838
+ for project in projects.values():
1839
+ if not project.spec.get('msvs_external_builder'):
1840
+ deps = project.spec.get('dependencies', [])
1841
+ deps = [projects[d] for d in deps]
1842
+ project.set_dependencies(deps)
1843
+ return projects
1844
+
1845
+
1846
+ def _InitNinjaFlavor(params, target_list, target_dicts):
1847
+ """Initialize targets for the ninja flavor.
1848
+
1849
+ This sets up the necessary variables in the targets to generate msvs projects
1850
+ that use ninja as an external builder. The variables in the spec are only set
1851
+ if they have not been set. This allows individual specs to override the
1852
+ default values initialized here.
1853
+ Arguments:
1854
+ params: Params provided to the generator.
1855
+ target_list: List of target pairs: 'base/base.gyp:base'.
1856
+ target_dicts: Dict of target properties keyed on target pair.
1857
+ """
1858
+ for qualified_target in target_list:
1859
+ spec = target_dicts[qualified_target]
1860
+ if spec.get('msvs_external_builder'):
1861
+ # The spec explicitly defined an external builder, so don't change it.
1862
+ continue
1863
+
1864
+ path_to_ninja = spec.get('msvs_path_to_ninja', 'ninja.exe')
1865
+
1866
+ spec['msvs_external_builder'] = 'ninja'
1867
+ if not spec.get('msvs_external_builder_out_dir'):
1868
+ gyp_file, _, _ = gyp.common.ParseQualifiedTarget(qualified_target)
1869
+ gyp_dir = os.path.dirname(gyp_file)
1870
+ configuration = '$(Configuration)'
1871
+ if params.get('target_arch') == 'x64':
1872
+ configuration += '_x64'
1873
+ spec['msvs_external_builder_out_dir'] = os.path.join(
1874
+ gyp.common.RelativePath(params['options'].toplevel_dir, gyp_dir),
1875
+ ninja_generator.ComputeOutputDir(params),
1876
+ configuration)
1877
+ if not spec.get('msvs_external_builder_build_cmd'):
1878
+ spec['msvs_external_builder_build_cmd'] = [
1879
+ path_to_ninja,
1880
+ '-C',
1881
+ '$(OutDir)',
1882
+ '$(ProjectName)',
1883
+ ]
1884
+ if not spec.get('msvs_external_builder_clean_cmd'):
1885
+ spec['msvs_external_builder_clean_cmd'] = [
1886
+ path_to_ninja,
1887
+ '-C',
1888
+ '$(OutDir)',
1889
+ '-tclean',
1890
+ '$(ProjectName)',
1891
+ ]
1892
+
1893
+
1894
+ def CalculateVariables(default_variables, params):
1895
+ """Generated variables that require params to be known."""
1896
+
1897
+ generator_flags = params.get('generator_flags', {})
1898
+
1899
+ # Select project file format version (if unset, default to auto detecting).
1900
+ msvs_version = MSVSVersion.SelectVisualStudioVersion(
1901
+ generator_flags.get('msvs_version', 'auto'))
1902
+ # Stash msvs_version for later (so we don't have to probe the system twice).
1903
+ params['msvs_version'] = msvs_version
1904
+
1905
+ # Set a variable so conditions can be based on msvs_version.
1906
+ default_variables['MSVS_VERSION'] = msvs_version.ShortName()
1907
+
1908
+ # To determine processor word size on Windows, in addition to checking
1909
+ # PROCESSOR_ARCHITECTURE (which reflects the word size of the current
1910
+ # process), it is also necessary to check PROCESSOR_ARCITEW6432 (which
1911
+ # contains the actual word size of the system when running thru WOW64).
1912
+ if (os.environ.get('PROCESSOR_ARCHITECTURE', '').find('64') >= 0 or
1913
+ os.environ.get('PROCESSOR_ARCHITEW6432', '').find('64') >= 0):
1914
+ default_variables['MSVS_OS_BITS'] = 64
1915
+ else:
1916
+ default_variables['MSVS_OS_BITS'] = 32
1917
+
1918
+ if gyp.common.GetFlavor(params) == 'ninja':
1919
+ default_variables['SHARED_INTERMEDIATE_DIR'] = '$(OutDir)gen'
1920
+
1921
+
1922
+ def PerformBuild(data, configurations, params):
1923
+ options = params['options']
1924
+ msvs_version = params['msvs_version']
1925
+ devenv = os.path.join(msvs_version.path, 'Common7', 'IDE', 'devenv.com')
1926
+
1927
+ for build_file, build_file_dict in data.iteritems():
1928
+ (build_file_root, build_file_ext) = os.path.splitext(build_file)
1929
+ if build_file_ext != '.gyp':
1930
+ continue
1931
+ sln_path = build_file_root + options.suffix + '.sln'
1932
+ if options.generator_output:
1933
+ sln_path = os.path.join(options.generator_output, sln_path)
1934
+
1935
+ for config in configurations:
1936
+ arguments = [devenv, sln_path, '/Build', config]
1937
+ print 'Building [%s]: %s' % (config, arguments)
1938
+ rtn = subprocess.check_call(arguments)
1939
+
1940
+
1941
+ def CalculateGeneratorInputInfo(params):
1942
+ if params.get('flavor') == 'ninja':
1943
+ toplevel = params['options'].toplevel_dir
1944
+ qualified_out_dir = os.path.normpath(os.path.join(
1945
+ toplevel, ninja_generator.ComputeOutputDir(params),
1946
+ 'gypfiles-msvs-ninja'))
1947
+
1948
+ global generator_filelist_paths
1949
+ generator_filelist_paths = {
1950
+ 'toplevel': toplevel,
1951
+ 'qualified_out_dir': qualified_out_dir,
1952
+ }
1953
+
1954
+ def GenerateOutput(target_list, target_dicts, data, params):
1955
+ """Generate .sln and .vcproj files.
1956
+
1957
+ This is the entry point for this generator.
1958
+ Arguments:
1959
+ target_list: List of target pairs: 'base/base.gyp:base'.
1960
+ target_dicts: Dict of target properties keyed on target pair.
1961
+ data: Dictionary containing per .gyp data.
1962
+ """
1963
+ global fixpath_prefix
1964
+
1965
+ options = params['options']
1966
+
1967
+ # Get the project file format version back out of where we stashed it in
1968
+ # GeneratorCalculatedVariables.
1969
+ msvs_version = params['msvs_version']
1970
+
1971
+ generator_flags = params.get('generator_flags', {})
1972
+
1973
+ # Optionally shard targets marked with 'msvs_shard': SHARD_COUNT.
1974
+ (target_list, target_dicts) = MSVSUtil.ShardTargets(target_list, target_dicts)
1975
+
1976
+ # Optionally use the large PDB workaround for targets marked with
1977
+ # 'msvs_large_pdb': 1.
1978
+ (target_list, target_dicts) = MSVSUtil.InsertLargePdbShims(
1979
+ target_list, target_dicts, generator_default_variables)
1980
+
1981
+ # Optionally configure each spec to use ninja as the external builder.
1982
+ if params.get('flavor') == 'ninja':
1983
+ _InitNinjaFlavor(params, target_list, target_dicts)
1984
+
1985
+ # Prepare the set of configurations.
1986
+ configs = set()
1987
+ for qualified_target in target_list:
1988
+ spec = target_dicts[qualified_target]
1989
+ for config_name, config in spec['configurations'].iteritems():
1990
+ configs.add(_ConfigFullName(config_name, config))
1991
+ configs = list(configs)
1992
+
1993
+ # Figure out all the projects that will be generated and their guids
1994
+ project_objects = _CreateProjectObjects(target_list, target_dicts, options,
1995
+ msvs_version)
1996
+
1997
+ # Generate each project.
1998
+ missing_sources = []
1999
+ for project in project_objects.values():
2000
+ fixpath_prefix = project.fixpath_prefix
2001
+ missing_sources.extend(_GenerateProject(project, options, msvs_version,
2002
+ generator_flags))
2003
+ fixpath_prefix = None
2004
+
2005
+ for build_file in data:
2006
+ # Validate build_file extension
2007
+ if not build_file.endswith('.gyp'):
2008
+ continue
2009
+ sln_path = os.path.splitext(build_file)[0] + options.suffix + '.sln'
2010
+ if options.generator_output:
2011
+ sln_path = os.path.join(options.generator_output, sln_path)
2012
+ # Get projects in the solution, and their dependents.
2013
+ sln_projects = gyp.common.BuildFileTargets(target_list, build_file)
2014
+ sln_projects += gyp.common.DeepDependencyTargets(target_dicts, sln_projects)
2015
+ # Create folder hierarchy.
2016
+ root_entries = _GatherSolutionFolders(
2017
+ sln_projects, project_objects, flat=msvs_version.FlatSolution())
2018
+ # Create solution.
2019
+ sln = MSVSNew.MSVSSolution(sln_path,
2020
+ entries=root_entries,
2021
+ variants=configs,
2022
+ websiteProperties=False,
2023
+ version=msvs_version)
2024
+ sln.Write()
2025
+
2026
+ if missing_sources:
2027
+ error_message = "Missing input files:\n" + \
2028
+ '\n'.join(set(missing_sources))
2029
+ if generator_flags.get('msvs_error_on_missing_sources', False):
2030
+ raise GypError(error_message)
2031
+ else:
2032
+ print >> sys.stdout, "Warning: " + error_message
2033
+
2034
+
2035
+ def _GenerateMSBuildFiltersFile(filters_path, source_files,
2036
+ rule_dependencies, extension_to_rule_name):
2037
+ """Generate the filters file.
2038
+
2039
+ This file is used by Visual Studio to organize the presentation of source
2040
+ files into folders.
2041
+
2042
+ Arguments:
2043
+ filters_path: The path of the file to be created.
2044
+ source_files: The hierarchical structure of all the sources.
2045
+ extension_to_rule_name: A dictionary mapping file extensions to rules.
2046
+ """
2047
+ filter_group = []
2048
+ source_group = []
2049
+ _AppendFiltersForMSBuild('', source_files, rule_dependencies,
2050
+ extension_to_rule_name, filter_group, source_group)
2051
+ if filter_group:
2052
+ content = ['Project',
2053
+ {'ToolsVersion': '4.0',
2054
+ 'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'
2055
+ },
2056
+ ['ItemGroup'] + filter_group,
2057
+ ['ItemGroup'] + source_group
2058
+ ]
2059
+ easy_xml.WriteXmlIfChanged(content, filters_path, pretty=True, win32=True)
2060
+ elif os.path.exists(filters_path):
2061
+ # We don't need this filter anymore. Delete the old filter file.
2062
+ os.unlink(filters_path)
2063
+
2064
+
2065
+ def _AppendFiltersForMSBuild(parent_filter_name, sources, rule_dependencies,
2066
+ extension_to_rule_name,
2067
+ filter_group, source_group):
2068
+ """Creates the list of filters and sources to be added in the filter file.
2069
+
2070
+ Args:
2071
+ parent_filter_name: The name of the filter under which the sources are
2072
+ found.
2073
+ sources: The hierarchy of filters and sources to process.
2074
+ extension_to_rule_name: A dictionary mapping file extensions to rules.
2075
+ filter_group: The list to which filter entries will be appended.
2076
+ source_group: The list to which source entries will be appeneded.
2077
+ """
2078
+ for source in sources:
2079
+ if isinstance(source, MSVSProject.Filter):
2080
+ # We have a sub-filter. Create the name of that sub-filter.
2081
+ if not parent_filter_name:
2082
+ filter_name = source.name
2083
+ else:
2084
+ filter_name = '%s\\%s' % (parent_filter_name, source.name)
2085
+ # Add the filter to the group.
2086
+ filter_group.append(
2087
+ ['Filter', {'Include': filter_name},
2088
+ ['UniqueIdentifier', MSVSNew.MakeGuid(source.name)]])
2089
+ # Recurse and add its dependents.
2090
+ _AppendFiltersForMSBuild(filter_name, source.contents,
2091
+ rule_dependencies, extension_to_rule_name,
2092
+ filter_group, source_group)
2093
+ else:
2094
+ # It's a source. Create a source entry.
2095
+ _, element = _MapFileToMsBuildSourceType(source, rule_dependencies,
2096
+ extension_to_rule_name)
2097
+ source_entry = [element, {'Include': source}]
2098
+ # Specify the filter it is part of, if any.
2099
+ if parent_filter_name:
2100
+ source_entry.append(['Filter', parent_filter_name])
2101
+ source_group.append(source_entry)
2102
+
2103
+
2104
+ def _MapFileToMsBuildSourceType(source, rule_dependencies,
2105
+ extension_to_rule_name):
2106
+ """Returns the group and element type of the source file.
2107
+
2108
+ Arguments:
2109
+ source: The source file name.
2110
+ extension_to_rule_name: A dictionary mapping file extensions to rules.
2111
+
2112
+ Returns:
2113
+ A pair of (group this file should be part of, the label of element)
2114
+ """
2115
+ _, ext = os.path.splitext(source)
2116
+ if ext in extension_to_rule_name:
2117
+ group = 'rule'
2118
+ element = extension_to_rule_name[ext]
2119
+ elif ext in ['.cc', '.cpp', '.c', '.cxx']:
2120
+ group = 'compile'
2121
+ element = 'ClCompile'
2122
+ elif ext in ['.h', '.hxx']:
2123
+ group = 'include'
2124
+ element = 'ClInclude'
2125
+ elif ext == '.rc':
2126
+ group = 'resource'
2127
+ element = 'ResourceCompile'
2128
+ elif ext == '.asm':
2129
+ group = 'masm'
2130
+ element = 'MASM'
2131
+ elif ext == '.idl':
2132
+ group = 'midl'
2133
+ element = 'Midl'
2134
+ elif source in rule_dependencies:
2135
+ group = 'rule_dependency'
2136
+ element = 'CustomBuild'
2137
+ else:
2138
+ group = 'none'
2139
+ element = 'None'
2140
+ return (group, element)
2141
+
2142
+
2143
+ def _GenerateRulesForMSBuild(output_dir, options, spec,
2144
+ sources, excluded_sources,
2145
+ props_files_of_rules, targets_files_of_rules,
2146
+ actions_to_add, rule_dependencies,
2147
+ extension_to_rule_name):
2148
+ # MSBuild rules are implemented using three files: an XML file, a .targets
2149
+ # file and a .props file.
2150
+ # See http://blogs.msdn.com/b/vcblog/archive/2010/04/21/quick-help-on-vs2010-custom-build-rule.aspx
2151
+ # for more details.
2152
+ rules = spec.get('rules', [])
2153
+ rules_native = [r for r in rules if not int(r.get('msvs_external_rule', 0))]
2154
+ rules_external = [r for r in rules if int(r.get('msvs_external_rule', 0))]
2155
+
2156
+ msbuild_rules = []
2157
+ for rule in rules_native:
2158
+ # Skip a rule with no action and no inputs.
2159
+ if 'action' not in rule and not rule.get('rule_sources', []):
2160
+ continue
2161
+ msbuild_rule = MSBuildRule(rule, spec)
2162
+ msbuild_rules.append(msbuild_rule)
2163
+ rule_dependencies.update(msbuild_rule.additional_dependencies.split(';'))
2164
+ extension_to_rule_name[msbuild_rule.extension] = msbuild_rule.rule_name
2165
+ if msbuild_rules:
2166
+ base = spec['target_name'] + options.suffix
2167
+ props_name = base + '.props'
2168
+ targets_name = base + '.targets'
2169
+ xml_name = base + '.xml'
2170
+
2171
+ props_files_of_rules.add(props_name)
2172
+ targets_files_of_rules.add(targets_name)
2173
+
2174
+ props_path = os.path.join(output_dir, props_name)
2175
+ targets_path = os.path.join(output_dir, targets_name)
2176
+ xml_path = os.path.join(output_dir, xml_name)
2177
+
2178
+ _GenerateMSBuildRulePropsFile(props_path, msbuild_rules)
2179
+ _GenerateMSBuildRuleTargetsFile(targets_path, msbuild_rules)
2180
+ _GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules)
2181
+
2182
+ if rules_external:
2183
+ _GenerateExternalRules(rules_external, output_dir, spec,
2184
+ sources, options, actions_to_add)
2185
+ _AdjustSourcesForRules(rules, sources, excluded_sources, True)
2186
+
2187
+
2188
+ class MSBuildRule(object):
2189
+ """Used to store information used to generate an MSBuild rule.
2190
+
2191
+ Attributes:
2192
+ rule_name: The rule name, sanitized to use in XML.
2193
+ target_name: The name of the target.
2194
+ after_targets: The name of the AfterTargets element.
2195
+ before_targets: The name of the BeforeTargets element.
2196
+ depends_on: The name of the DependsOn element.
2197
+ compute_output: The name of the ComputeOutput element.
2198
+ dirs_to_make: The name of the DirsToMake element.
2199
+ inputs: The name of the _inputs element.
2200
+ tlog: The name of the _tlog element.
2201
+ extension: The extension this rule applies to.
2202
+ description: The message displayed when this rule is invoked.
2203
+ additional_dependencies: A string listing additional dependencies.
2204
+ outputs: The outputs of this rule.
2205
+ command: The command used to run the rule.
2206
+ """
2207
+
2208
+ def __init__(self, rule, spec):
2209
+ self.display_name = rule['rule_name']
2210
+ # Assure that the rule name is only characters and numbers
2211
+ self.rule_name = re.sub(r'\W', '_', self.display_name)
2212
+ # Create the various element names, following the example set by the
2213
+ # Visual Studio 2008 to 2010 conversion. I don't know if VS2010
2214
+ # is sensitive to the exact names.
2215
+ self.target_name = '_' + self.rule_name
2216
+ self.after_targets = self.rule_name + 'AfterTargets'
2217
+ self.before_targets = self.rule_name + 'BeforeTargets'
2218
+ self.depends_on = self.rule_name + 'DependsOn'
2219
+ self.compute_output = 'Compute%sOutput' % self.rule_name
2220
+ self.dirs_to_make = self.rule_name + 'DirsToMake'
2221
+ self.inputs = self.rule_name + '_inputs'
2222
+ self.tlog = self.rule_name + '_tlog'
2223
+ self.extension = rule['extension']
2224
+ if not self.extension.startswith('.'):
2225
+ self.extension = '.' + self.extension
2226
+
2227
+ self.description = MSVSSettings.ConvertVCMacrosToMSBuild(
2228
+ rule.get('message', self.rule_name))
2229
+ old_additional_dependencies = _FixPaths(rule.get('inputs', []))
2230
+ self.additional_dependencies = (
2231
+ ';'.join([MSVSSettings.ConvertVCMacrosToMSBuild(i)
2232
+ for i in old_additional_dependencies]))
2233
+ old_outputs = _FixPaths(rule.get('outputs', []))
2234
+ self.outputs = ';'.join([MSVSSettings.ConvertVCMacrosToMSBuild(i)
2235
+ for i in old_outputs])
2236
+ old_command = _BuildCommandLineForRule(spec, rule, has_input_path=True,
2237
+ do_setup_env=True)
2238
+ self.command = MSVSSettings.ConvertVCMacrosToMSBuild(old_command)
2239
+
2240
+
2241
+ def _GenerateMSBuildRulePropsFile(props_path, msbuild_rules):
2242
+ """Generate the .props file."""
2243
+ content = ['Project',
2244
+ {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'}]
2245
+ for rule in msbuild_rules:
2246
+ content.extend([
2247
+ ['PropertyGroup',
2248
+ {'Condition': "'$(%s)' == '' and '$(%s)' == '' and "
2249
+ "'$(ConfigurationType)' != 'Makefile'" % (rule.before_targets,
2250
+ rule.after_targets)
2251
+ },
2252
+ [rule.before_targets, 'Midl'],
2253
+ [rule.after_targets, 'CustomBuild'],
2254
+ ],
2255
+ ['PropertyGroup',
2256
+ [rule.depends_on,
2257
+ {'Condition': "'$(ConfigurationType)' != 'Makefile'"},
2258
+ '_SelectedFiles;$(%s)' % rule.depends_on
2259
+ ],
2260
+ ],
2261
+ ['ItemDefinitionGroup',
2262
+ [rule.rule_name,
2263
+ ['CommandLineTemplate', rule.command],
2264
+ ['Outputs', rule.outputs],
2265
+ ['ExecutionDescription', rule.description],
2266
+ ['AdditionalDependencies', rule.additional_dependencies],
2267
+ ],
2268
+ ]
2269
+ ])
2270
+ easy_xml.WriteXmlIfChanged(content, props_path, pretty=True, win32=True)
2271
+
2272
+
2273
+ def _GenerateMSBuildRuleTargetsFile(targets_path, msbuild_rules):
2274
+ """Generate the .targets file."""
2275
+ content = ['Project',
2276
+ {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'
2277
+ }
2278
+ ]
2279
+ item_group = [
2280
+ 'ItemGroup',
2281
+ ['PropertyPageSchema',
2282
+ {'Include': '$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml'}
2283
+ ]
2284
+ ]
2285
+ for rule in msbuild_rules:
2286
+ item_group.append(
2287
+ ['AvailableItemName',
2288
+ {'Include': rule.rule_name},
2289
+ ['Targets', rule.target_name],
2290
+ ])
2291
+ content.append(item_group)
2292
+
2293
+ for rule in msbuild_rules:
2294
+ content.append(
2295
+ ['UsingTask',
2296
+ {'TaskName': rule.rule_name,
2297
+ 'TaskFactory': 'XamlTaskFactory',
2298
+ 'AssemblyName': 'Microsoft.Build.Tasks.v4.0'
2299
+ },
2300
+ ['Task', '$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml'],
2301
+ ])
2302
+ for rule in msbuild_rules:
2303
+ rule_name = rule.rule_name
2304
+ target_outputs = '%%(%s.Outputs)' % rule_name
2305
+ target_inputs = ('%%(%s.Identity);%%(%s.AdditionalDependencies);'
2306
+ '$(MSBuildProjectFile)') % (rule_name, rule_name)
2307
+ rule_inputs = '%%(%s.Identity)' % rule_name
2308
+ extension_condition = ("'%(Extension)'=='.obj' or "
2309
+ "'%(Extension)'=='.res' or "
2310
+ "'%(Extension)'=='.rsc' or "
2311
+ "'%(Extension)'=='.lib'")
2312
+ remove_section = [
2313
+ 'ItemGroup',
2314
+ {'Condition': "'@(SelectedFiles)' != ''"},
2315
+ [rule_name,
2316
+ {'Remove': '@(%s)' % rule_name,
2317
+ 'Condition': "'%(Identity)' != '@(SelectedFiles)'"
2318
+ }
2319
+ ]
2320
+ ]
2321
+ inputs_section = [
2322
+ 'ItemGroup',
2323
+ [rule.inputs, {'Include': '%%(%s.AdditionalDependencies)' % rule_name}]
2324
+ ]
2325
+ logging_section = [
2326
+ 'ItemGroup',
2327
+ [rule.tlog,
2328
+ {'Include': '%%(%s.Outputs)' % rule_name,
2329
+ 'Condition': ("'%%(%s.Outputs)' != '' and "
2330
+ "'%%(%s.ExcludedFromBuild)' != 'true'" %
2331
+ (rule_name, rule_name))
2332
+ },
2333
+ ['Source', "@(%s, '|')" % rule_name],
2334
+ ['Inputs', "@(%s -> '%%(Fullpath)', ';')" % rule.inputs],
2335
+ ],
2336
+ ]
2337
+ message_section = [
2338
+ 'Message',
2339
+ {'Importance': 'High',
2340
+ 'Text': '%%(%s.ExecutionDescription)' % rule_name
2341
+ }
2342
+ ]
2343
+ write_tlog_section = [
2344
+ 'WriteLinesToFile',
2345
+ {'Condition': "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
2346
+ "'true'" % (rule.tlog, rule.tlog),
2347
+ 'File': '$(IntDir)$(ProjectName).write.1.tlog',
2348
+ 'Lines': "^%%(%s.Source);@(%s->'%%(Fullpath)')" % (rule.tlog,
2349
+ rule.tlog)
2350
+ }
2351
+ ]
2352
+ read_tlog_section = [
2353
+ 'WriteLinesToFile',
2354
+ {'Condition': "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
2355
+ "'true'" % (rule.tlog, rule.tlog),
2356
+ 'File': '$(IntDir)$(ProjectName).read.1.tlog',
2357
+ 'Lines': "^%%(%s.Source);%%(%s.Inputs)" % (rule.tlog, rule.tlog)
2358
+ }
2359
+ ]
2360
+ command_and_input_section = [
2361
+ rule_name,
2362
+ {'Condition': "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
2363
+ "'true'" % (rule_name, rule_name),
2364
+ 'EchoOff': 'true',
2365
+ 'StandardOutputImportance': 'High',
2366
+ 'StandardErrorImportance': 'High',
2367
+ 'CommandLineTemplate': '%%(%s.CommandLineTemplate)' % rule_name,
2368
+ 'AdditionalOptions': '%%(%s.AdditionalOptions)' % rule_name,
2369
+ 'Inputs': rule_inputs
2370
+ }
2371
+ ]
2372
+ content.extend([
2373
+ ['Target',
2374
+ {'Name': rule.target_name,
2375
+ 'BeforeTargets': '$(%s)' % rule.before_targets,
2376
+ 'AfterTargets': '$(%s)' % rule.after_targets,
2377
+ 'Condition': "'@(%s)' != ''" % rule_name,
2378
+ 'DependsOnTargets': '$(%s);%s' % (rule.depends_on,
2379
+ rule.compute_output),
2380
+ 'Outputs': target_outputs,
2381
+ 'Inputs': target_inputs
2382
+ },
2383
+ remove_section,
2384
+ inputs_section,
2385
+ logging_section,
2386
+ message_section,
2387
+ write_tlog_section,
2388
+ read_tlog_section,
2389
+ command_and_input_section,
2390
+ ],
2391
+ ['PropertyGroup',
2392
+ ['ComputeLinkInputsTargets',
2393
+ '$(ComputeLinkInputsTargets);',
2394
+ '%s;' % rule.compute_output
2395
+ ],
2396
+ ['ComputeLibInputsTargets',
2397
+ '$(ComputeLibInputsTargets);',
2398
+ '%s;' % rule.compute_output
2399
+ ],
2400
+ ],
2401
+ ['Target',
2402
+ {'Name': rule.compute_output,
2403
+ 'Condition': "'@(%s)' != ''" % rule_name
2404
+ },
2405
+ ['ItemGroup',
2406
+ [rule.dirs_to_make,
2407
+ {'Condition': "'@(%s)' != '' and "
2408
+ "'%%(%s.ExcludedFromBuild)' != 'true'" % (rule_name, rule_name),
2409
+ 'Include': '%%(%s.Outputs)' % rule_name
2410
+ }
2411
+ ],
2412
+ ['Link',
2413
+ {'Include': '%%(%s.Identity)' % rule.dirs_to_make,
2414
+ 'Condition': extension_condition
2415
+ }
2416
+ ],
2417
+ ['Lib',
2418
+ {'Include': '%%(%s.Identity)' % rule.dirs_to_make,
2419
+ 'Condition': extension_condition
2420
+ }
2421
+ ],
2422
+ ['ImpLib',
2423
+ {'Include': '%%(%s.Identity)' % rule.dirs_to_make,
2424
+ 'Condition': extension_condition
2425
+ }
2426
+ ],
2427
+ ],
2428
+ ['MakeDir',
2429
+ {'Directories': ("@(%s->'%%(RootDir)%%(Directory)')" %
2430
+ rule.dirs_to_make)
2431
+ }
2432
+ ]
2433
+ ],
2434
+ ])
2435
+ easy_xml.WriteXmlIfChanged(content, targets_path, pretty=True, win32=True)
2436
+
2437
+
2438
+ def _GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules):
2439
+ # Generate the .xml file
2440
+ content = [
2441
+ 'ProjectSchemaDefinitions',
2442
+ {'xmlns': ('clr-namespace:Microsoft.Build.Framework.XamlTypes;'
2443
+ 'assembly=Microsoft.Build.Framework'),
2444
+ 'xmlns:x': 'http://schemas.microsoft.com/winfx/2006/xaml',
2445
+ 'xmlns:sys': 'clr-namespace:System;assembly=mscorlib',
2446
+ 'xmlns:transformCallback':
2447
+ 'Microsoft.Cpp.Dev10.ConvertPropertyCallback'
2448
+ }
2449
+ ]
2450
+ for rule in msbuild_rules:
2451
+ content.extend([
2452
+ ['Rule',
2453
+ {'Name': rule.rule_name,
2454
+ 'PageTemplate': 'tool',
2455
+ 'DisplayName': rule.display_name,
2456
+ 'Order': '200'
2457
+ },
2458
+ ['Rule.DataSource',
2459
+ ['DataSource',
2460
+ {'Persistence': 'ProjectFile',
2461
+ 'ItemType': rule.rule_name
2462
+ }
2463
+ ]
2464
+ ],
2465
+ ['Rule.Categories',
2466
+ ['Category',
2467
+ {'Name': 'General'},
2468
+ ['Category.DisplayName',
2469
+ ['sys:String', 'General'],
2470
+ ],
2471
+ ],
2472
+ ['Category',
2473
+ {'Name': 'Command Line',
2474
+ 'Subtype': 'CommandLine'
2475
+ },
2476
+ ['Category.DisplayName',
2477
+ ['sys:String', 'Command Line'],
2478
+ ],
2479
+ ],
2480
+ ],
2481
+ ['StringListProperty',
2482
+ {'Name': 'Inputs',
2483
+ 'Category': 'Command Line',
2484
+ 'IsRequired': 'true',
2485
+ 'Switch': ' '
2486
+ },
2487
+ ['StringListProperty.DataSource',
2488
+ ['DataSource',
2489
+ {'Persistence': 'ProjectFile',
2490
+ 'ItemType': rule.rule_name,
2491
+ 'SourceType': 'Item'
2492
+ }
2493
+ ]
2494
+ ],
2495
+ ],
2496
+ ['StringProperty',
2497
+ {'Name': 'CommandLineTemplate',
2498
+ 'DisplayName': 'Command Line',
2499
+ 'Visible': 'False',
2500
+ 'IncludeInCommandLine': 'False'
2501
+ }
2502
+ ],
2503
+ ['DynamicEnumProperty',
2504
+ {'Name': rule.before_targets,
2505
+ 'Category': 'General',
2506
+ 'EnumProvider': 'Targets',
2507
+ 'IncludeInCommandLine': 'False'
2508
+ },
2509
+ ['DynamicEnumProperty.DisplayName',
2510
+ ['sys:String', 'Execute Before'],
2511
+ ],
2512
+ ['DynamicEnumProperty.Description',
2513
+ ['sys:String', 'Specifies the targets for the build customization'
2514
+ ' to run before.'
2515
+ ],
2516
+ ],
2517
+ ['DynamicEnumProperty.ProviderSettings',
2518
+ ['NameValuePair',
2519
+ {'Name': 'Exclude',
2520
+ 'Value': '^%s|^Compute' % rule.before_targets
2521
+ }
2522
+ ]
2523
+ ],
2524
+ ['DynamicEnumProperty.DataSource',
2525
+ ['DataSource',
2526
+ {'Persistence': 'ProjectFile',
2527
+ 'HasConfigurationCondition': 'true'
2528
+ }
2529
+ ]
2530
+ ],
2531
+ ],
2532
+ ['DynamicEnumProperty',
2533
+ {'Name': rule.after_targets,
2534
+ 'Category': 'General',
2535
+ 'EnumProvider': 'Targets',
2536
+ 'IncludeInCommandLine': 'False'
2537
+ },
2538
+ ['DynamicEnumProperty.DisplayName',
2539
+ ['sys:String', 'Execute After'],
2540
+ ],
2541
+ ['DynamicEnumProperty.Description',
2542
+ ['sys:String', ('Specifies the targets for the build customization'
2543
+ ' to run after.')
2544
+ ],
2545
+ ],
2546
+ ['DynamicEnumProperty.ProviderSettings',
2547
+ ['NameValuePair',
2548
+ {'Name': 'Exclude',
2549
+ 'Value': '^%s|^Compute' % rule.after_targets
2550
+ }
2551
+ ]
2552
+ ],
2553
+ ['DynamicEnumProperty.DataSource',
2554
+ ['DataSource',
2555
+ {'Persistence': 'ProjectFile',
2556
+ 'ItemType': '',
2557
+ 'HasConfigurationCondition': 'true'
2558
+ }
2559
+ ]
2560
+ ],
2561
+ ],
2562
+ ['StringListProperty',
2563
+ {'Name': 'Outputs',
2564
+ 'DisplayName': 'Outputs',
2565
+ 'Visible': 'False',
2566
+ 'IncludeInCommandLine': 'False'
2567
+ }
2568
+ ],
2569
+ ['StringProperty',
2570
+ {'Name': 'ExecutionDescription',
2571
+ 'DisplayName': 'Execution Description',
2572
+ 'Visible': 'False',
2573
+ 'IncludeInCommandLine': 'False'
2574
+ }
2575
+ ],
2576
+ ['StringListProperty',
2577
+ {'Name': 'AdditionalDependencies',
2578
+ 'DisplayName': 'Additional Dependencies',
2579
+ 'IncludeInCommandLine': 'False',
2580
+ 'Visible': 'false'
2581
+ }
2582
+ ],
2583
+ ['StringProperty',
2584
+ {'Subtype': 'AdditionalOptions',
2585
+ 'Name': 'AdditionalOptions',
2586
+ 'Category': 'Command Line'
2587
+ },
2588
+ ['StringProperty.DisplayName',
2589
+ ['sys:String', 'Additional Options'],
2590
+ ],
2591
+ ['StringProperty.Description',
2592
+ ['sys:String', 'Additional Options'],
2593
+ ],
2594
+ ],
2595
+ ],
2596
+ ['ItemType',
2597
+ {'Name': rule.rule_name,
2598
+ 'DisplayName': rule.display_name
2599
+ }
2600
+ ],
2601
+ ['FileExtension',
2602
+ {'Name': '*' + rule.extension,
2603
+ 'ContentType': rule.rule_name
2604
+ }
2605
+ ],
2606
+ ['ContentType',
2607
+ {'Name': rule.rule_name,
2608
+ 'DisplayName': '',
2609
+ 'ItemType': rule.rule_name
2610
+ }
2611
+ ]
2612
+ ])
2613
+ easy_xml.WriteXmlIfChanged(content, xml_path, pretty=True, win32=True)
2614
+
2615
+
2616
+ def _GetConfigurationAndPlatform(name, settings):
2617
+ configuration = name.rsplit('_', 1)[0]
2618
+ platform = settings.get('msvs_configuration_platform', 'Win32')
2619
+ return (configuration, platform)
2620
+
2621
+
2622
+ def _GetConfigurationCondition(name, settings):
2623
+ return (r"'$(Configuration)|$(Platform)'=='%s|%s'" %
2624
+ _GetConfigurationAndPlatform(name, settings))
2625
+
2626
+
2627
+ def _GetMSBuildProjectConfigurations(configurations):
2628
+ group = ['ItemGroup', {'Label': 'ProjectConfigurations'}]
2629
+ for (name, settings) in sorted(configurations.iteritems()):
2630
+ configuration, platform = _GetConfigurationAndPlatform(name, settings)
2631
+ designation = '%s|%s' % (configuration, platform)
2632
+ group.append(
2633
+ ['ProjectConfiguration', {'Include': designation},
2634
+ ['Configuration', configuration],
2635
+ ['Platform', platform]])
2636
+ return [group]
2637
+
2638
+
2639
+ def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
2640
+ namespace = os.path.splitext(gyp_file_name)[0]
2641
+ properties = [
2642
+ ['PropertyGroup', {'Label': 'Globals'},
2643
+ ['ProjectGuid', guid],
2644
+ ['Keyword', 'Win32Proj'],
2645
+ ['RootNamespace', namespace],
2646
+ ['IgnoreWarnCompileDuplicatedFilename', 'true'],
2647
+ ]
2648
+ ]
2649
+
2650
+ if os.environ.get('PROCESSOR_ARCHITECTURE') == 'AMD64' or \
2651
+ os.environ.get('PROCESSOR_ARCHITEW6432') == 'AMD64':
2652
+ properties[0].append(['PreferredToolArchitecture', 'x64'])
2653
+
2654
+ if spec.get('msvs_enable_winrt'):
2655
+ properties[0].append(['DefaultLanguage', 'en-US'])
2656
+ properties[0].append(['AppContainerApplication', 'true'])
2657
+ if spec.get('msvs_application_type_revision'):
2658
+ app_type_revision = spec.get('msvs_application_type_revision')
2659
+ properties[0].append(['ApplicationTypeRevision', app_type_revision])
2660
+ else:
2661
+ properties[0].append(['ApplicationTypeRevision', '8.1'])
2662
+
2663
+ if spec.get('msvs_target_platform_version'):
2664
+ target_platform_version = spec.get('msvs_target_platform_version')
2665
+ properties[0].append(['WindowsTargetPlatformVersion',
2666
+ target_platform_version])
2667
+ if spec.get('msvs_target_platform_minversion'):
2668
+ target_platform_minversion = spec.get('msvs_target_platform_minversion')
2669
+ properties[0].append(['WindowsTargetPlatformMinVersion',
2670
+ target_platform_minversion])
2671
+ else:
2672
+ properties[0].append(['WindowsTargetPlatformMinVersion',
2673
+ target_platform_version])
2674
+ if spec.get('msvs_enable_winphone'):
2675
+ properties[0].append(['ApplicationType', 'Windows Phone'])
2676
+ else:
2677
+ properties[0].append(['ApplicationType', 'Windows Store'])
2678
+
2679
+ return properties
2680
+
2681
+ def _GetMSBuildConfigurationDetails(spec, build_file):
2682
+ properties = {}
2683
+ for name, settings in spec['configurations'].iteritems():
2684
+ msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file)
2685
+ condition = _GetConfigurationCondition(name, settings)
2686
+ character_set = msbuild_attributes.get('CharacterSet')
2687
+ _AddConditionalProperty(properties, condition, 'ConfigurationType',
2688
+ msbuild_attributes['ConfigurationType'])
2689
+ if character_set:
2690
+ if 'msvs_enable_winrt' not in spec :
2691
+ _AddConditionalProperty(properties, condition, 'CharacterSet',
2692
+ character_set)
2693
+ return _GetMSBuildPropertyGroup(spec, 'Configuration', properties)
2694
+
2695
+
2696
+ def _GetMSBuildLocalProperties(msbuild_toolset):
2697
+ # Currently the only local property we support is PlatformToolset
2698
+ properties = {}
2699
+ if msbuild_toolset:
2700
+ properties = [
2701
+ ['PropertyGroup', {'Label': 'Locals'},
2702
+ ['PlatformToolset', msbuild_toolset],
2703
+ ]
2704
+ ]
2705
+ return properties
2706
+
2707
+
2708
+ def _GetMSBuildPropertySheets(configurations):
2709
+ user_props = r'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props'
2710
+ additional_props = {}
2711
+ props_specified = False
2712
+ for name, settings in sorted(configurations.iteritems()):
2713
+ configuration = _GetConfigurationCondition(name, settings)
2714
+ if settings.has_key('msbuild_props'):
2715
+ additional_props[configuration] = _FixPaths(settings['msbuild_props'])
2716
+ props_specified = True
2717
+ else:
2718
+ additional_props[configuration] = ''
2719
+
2720
+ if not props_specified:
2721
+ return [
2722
+ ['ImportGroup',
2723
+ {'Label': 'PropertySheets'},
2724
+ ['Import',
2725
+ {'Project': user_props,
2726
+ 'Condition': "exists('%s')" % user_props,
2727
+ 'Label': 'LocalAppDataPlatform'
2728
+ }
2729
+ ]
2730
+ ]
2731
+ ]
2732
+ else:
2733
+ sheets = []
2734
+ for condition, props in additional_props.iteritems():
2735
+ import_group = [
2736
+ 'ImportGroup',
2737
+ {'Label': 'PropertySheets',
2738
+ 'Condition': condition
2739
+ },
2740
+ ['Import',
2741
+ {'Project': user_props,
2742
+ 'Condition': "exists('%s')" % user_props,
2743
+ 'Label': 'LocalAppDataPlatform'
2744
+ }
2745
+ ]
2746
+ ]
2747
+ for props_file in props:
2748
+ import_group.append(['Import', {'Project':props_file}])
2749
+ sheets.append(import_group)
2750
+ return sheets
2751
+
2752
+ def _ConvertMSVSBuildAttributes(spec, config, build_file):
2753
+ config_type = _GetMSVSConfigurationType(spec, build_file)
2754
+ msvs_attributes = _GetMSVSAttributes(spec, config, config_type)
2755
+ msbuild_attributes = {}
2756
+ for a in msvs_attributes:
2757
+ if a in ['IntermediateDirectory', 'OutputDirectory']:
2758
+ directory = MSVSSettings.ConvertVCMacrosToMSBuild(msvs_attributes[a])
2759
+ if not directory.endswith('\\'):
2760
+ directory += '\\'
2761
+ msbuild_attributes[a] = directory
2762
+ elif a == 'CharacterSet':
2763
+ msbuild_attributes[a] = _ConvertMSVSCharacterSet(msvs_attributes[a])
2764
+ elif a == 'ConfigurationType':
2765
+ msbuild_attributes[a] = _ConvertMSVSConfigurationType(msvs_attributes[a])
2766
+ else:
2767
+ print 'Warning: Do not know how to convert MSVS attribute ' + a
2768
+ return msbuild_attributes
2769
+
2770
+
2771
+ def _ConvertMSVSCharacterSet(char_set):
2772
+ if char_set.isdigit():
2773
+ char_set = {
2774
+ '0': 'MultiByte',
2775
+ '1': 'Unicode',
2776
+ '2': 'MultiByte',
2777
+ }[char_set]
2778
+ return char_set
2779
+
2780
+
2781
+ def _ConvertMSVSConfigurationType(config_type):
2782
+ if config_type.isdigit():
2783
+ config_type = {
2784
+ '1': 'Application',
2785
+ '2': 'DynamicLibrary',
2786
+ '4': 'StaticLibrary',
2787
+ '10': 'Utility'
2788
+ }[config_type]
2789
+ return config_type
2790
+
2791
+
2792
+ def _GetMSBuildAttributes(spec, config, build_file):
2793
+ if 'msbuild_configuration_attributes' not in config:
2794
+ msbuild_attributes = _ConvertMSVSBuildAttributes(spec, config, build_file)
2795
+
2796
+ else:
2797
+ config_type = _GetMSVSConfigurationType(spec, build_file)
2798
+ config_type = _ConvertMSVSConfigurationType(config_type)
2799
+ msbuild_attributes = config.get('msbuild_configuration_attributes', {})
2800
+ msbuild_attributes.setdefault('ConfigurationType', config_type)
2801
+ output_dir = msbuild_attributes.get('OutputDirectory',
2802
+ '$(SolutionDir)$(Configuration)')
2803
+ msbuild_attributes['OutputDirectory'] = _FixPath(output_dir) + '\\'
2804
+ if 'IntermediateDirectory' not in msbuild_attributes:
2805
+ intermediate = _FixPath('$(Configuration)') + '\\'
2806
+ msbuild_attributes['IntermediateDirectory'] = intermediate
2807
+ if 'CharacterSet' in msbuild_attributes:
2808
+ msbuild_attributes['CharacterSet'] = _ConvertMSVSCharacterSet(
2809
+ msbuild_attributes['CharacterSet'])
2810
+ if 'TargetName' not in msbuild_attributes:
2811
+ prefix = spec.get('product_prefix', '')
2812
+ product_name = spec.get('product_name', '$(ProjectName)')
2813
+ target_name = prefix + product_name
2814
+ msbuild_attributes['TargetName'] = target_name
2815
+
2816
+ if spec.get('msvs_external_builder'):
2817
+ external_out_dir = spec.get('msvs_external_builder_out_dir', '.')
2818
+ msbuild_attributes['OutputDirectory'] = _FixPath(external_out_dir) + '\\'
2819
+
2820
+ # Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile'
2821
+ # (depending on the tool used) to avoid MSB8012 warning.
2822
+ msbuild_tool_map = {
2823
+ 'executable': 'Link',
2824
+ 'shared_library': 'Link',
2825
+ 'loadable_module': 'Link',
2826
+ 'static_library': 'Lib',
2827
+ }
2828
+ msbuild_tool = msbuild_tool_map.get(spec['type'])
2829
+ if msbuild_tool:
2830
+ msbuild_settings = config['finalized_msbuild_settings']
2831
+ out_file = msbuild_settings[msbuild_tool].get('OutputFile')
2832
+ if out_file:
2833
+ msbuild_attributes['TargetPath'] = _FixPath(out_file)
2834
+ target_ext = msbuild_settings[msbuild_tool].get('TargetExt')
2835
+ if target_ext:
2836
+ msbuild_attributes['TargetExt'] = target_ext
2837
+
2838
+ return msbuild_attributes
2839
+
2840
+
2841
+ def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
2842
+ # TODO(jeanluc) We could optimize out the following and do it only if
2843
+ # there are actions.
2844
+ # TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'.
2845
+ new_paths = []
2846
+ cygwin_dirs = spec.get('msvs_cygwin_dirs', ['.'])[0]
2847
+ if cygwin_dirs:
2848
+ cyg_path = '$(MSBuildProjectDirectory)\\%s\\bin\\' % _FixPath(cygwin_dirs)
2849
+ new_paths.append(cyg_path)
2850
+ # TODO(jeanluc) Change the convention to have both a cygwin_dir and a
2851
+ # python_dir.
2852
+ python_path = cyg_path.replace('cygwin\\bin', 'python_26')
2853
+ new_paths.append(python_path)
2854
+ if new_paths:
2855
+ new_paths = '$(ExecutablePath);' + ';'.join(new_paths)
2856
+
2857
+ properties = {}
2858
+ for (name, configuration) in sorted(configurations.iteritems()):
2859
+ condition = _GetConfigurationCondition(name, configuration)
2860
+ attributes = _GetMSBuildAttributes(spec, configuration, build_file)
2861
+ msbuild_settings = configuration['finalized_msbuild_settings']
2862
+ _AddConditionalProperty(properties, condition, 'IntDir',
2863
+ attributes['IntermediateDirectory'])
2864
+ _AddConditionalProperty(properties, condition, 'OutDir',
2865
+ attributes['OutputDirectory'])
2866
+ _AddConditionalProperty(properties, condition, 'TargetName',
2867
+ attributes['TargetName'])
2868
+
2869
+ if attributes.get('TargetPath'):
2870
+ _AddConditionalProperty(properties, condition, 'TargetPath',
2871
+ attributes['TargetPath'])
2872
+ if attributes.get('TargetExt'):
2873
+ _AddConditionalProperty(properties, condition, 'TargetExt',
2874
+ attributes['TargetExt'])
2875
+
2876
+ if new_paths:
2877
+ _AddConditionalProperty(properties, condition, 'ExecutablePath',
2878
+ new_paths)
2879
+ tool_settings = msbuild_settings.get('', {})
2880
+ for name, value in sorted(tool_settings.iteritems()):
2881
+ formatted_value = _GetValueFormattedForMSBuild('', name, value)
2882
+ _AddConditionalProperty(properties, condition, name, formatted_value)
2883
+ return _GetMSBuildPropertyGroup(spec, None, properties)
2884
+
2885
+
2886
+ def _AddConditionalProperty(properties, condition, name, value):
2887
+ """Adds a property / conditional value pair to a dictionary.
2888
+
2889
+ Arguments:
2890
+ properties: The dictionary to be modified. The key is the name of the
2891
+ property. The value is itself a dictionary; its key is the value and
2892
+ the value a list of condition for which this value is true.
2893
+ condition: The condition under which the named property has the value.
2894
+ name: The name of the property.
2895
+ value: The value of the property.
2896
+ """
2897
+ if name not in properties:
2898
+ properties[name] = {}
2899
+ values = properties[name]
2900
+ if value not in values:
2901
+ values[value] = []
2902
+ conditions = values[value]
2903
+ conditions.append(condition)
2904
+
2905
+
2906
+ # Regex for msvs variable references ( i.e. $(FOO) ).
2907
+ MSVS_VARIABLE_REFERENCE = re.compile(r'\$\(([a-zA-Z_][a-zA-Z0-9_]*)\)')
2908
+
2909
+
2910
+ def _GetMSBuildPropertyGroup(spec, label, properties):
2911
+ """Returns a PropertyGroup definition for the specified properties.
2912
+
2913
+ Arguments:
2914
+ spec: The target project dict.
2915
+ label: An optional label for the PropertyGroup.
2916
+ properties: The dictionary to be converted. The key is the name of the
2917
+ property. The value is itself a dictionary; its key is the value and
2918
+ the value a list of condition for which this value is true.
2919
+ """
2920
+ group = ['PropertyGroup']
2921
+ if label:
2922
+ group.append({'Label': label})
2923
+ num_configurations = len(spec['configurations'])
2924
+ def GetEdges(node):
2925
+ # Use a definition of edges such that user_of_variable -> used_varible.
2926
+ # This happens to be easier in this case, since a variable's
2927
+ # definition contains all variables it references in a single string.
2928
+ edges = set()
2929
+ for value in sorted(properties[node].keys()):
2930
+ # Add to edges all $(...) references to variables.
2931
+ #
2932
+ # Variable references that refer to names not in properties are excluded
2933
+ # These can exist for instance to refer built in definitions like
2934
+ # $(SolutionDir).
2935
+ #
2936
+ # Self references are ignored. Self reference is used in a few places to
2937
+ # append to the default value. I.e. PATH=$(PATH);other_path
2938
+ edges.update(set([v for v in MSVS_VARIABLE_REFERENCE.findall(value)
2939
+ if v in properties and v != node]))
2940
+ return edges
2941
+ properties_ordered = gyp.common.TopologicallySorted(
2942
+ properties.keys(), GetEdges)
2943
+ # Walk properties in the reverse of a topological sort on
2944
+ # user_of_variable -> used_variable as this ensures variables are
2945
+ # defined before they are used.
2946
+ # NOTE: reverse(topsort(DAG)) = topsort(reverse_edges(DAG))
2947
+ for name in reversed(properties_ordered):
2948
+ values = properties[name]
2949
+ for value, conditions in sorted(values.iteritems()):
2950
+ if len(conditions) == num_configurations:
2951
+ # If the value is the same all configurations,
2952
+ # just add one unconditional entry.
2953
+ group.append([name, value])
2954
+ else:
2955
+ for condition in conditions:
2956
+ group.append([name, {'Condition': condition}, value])
2957
+ return [group]
2958
+
2959
+
2960
+ def _GetMSBuildToolSettingsSections(spec, configurations):
2961
+ groups = []
2962
+ for (name, configuration) in sorted(configurations.iteritems()):
2963
+ msbuild_settings = configuration['finalized_msbuild_settings']
2964
+ group = ['ItemDefinitionGroup',
2965
+ {'Condition': _GetConfigurationCondition(name, configuration)}
2966
+ ]
2967
+ for tool_name, tool_settings in sorted(msbuild_settings.iteritems()):
2968
+ # Skip the tool named '' which is a holder of global settings handled
2969
+ # by _GetMSBuildConfigurationGlobalProperties.
2970
+ if tool_name:
2971
+ if tool_settings:
2972
+ tool = [tool_name]
2973
+ for name, value in sorted(tool_settings.iteritems()):
2974
+ formatted_value = _GetValueFormattedForMSBuild(tool_name, name,
2975
+ value)
2976
+ tool.append([name, formatted_value])
2977
+ group.append(tool)
2978
+ groups.append(group)
2979
+ return groups
2980
+
2981
+
2982
+ def _FinalizeMSBuildSettings(spec, configuration):
2983
+ if 'msbuild_settings' in configuration:
2984
+ converted = False
2985
+ msbuild_settings = configuration['msbuild_settings']
2986
+ MSVSSettings.ValidateMSBuildSettings(msbuild_settings)
2987
+ else:
2988
+ converted = True
2989
+ msvs_settings = configuration.get('msvs_settings', {})
2990
+ msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(msvs_settings)
2991
+ include_dirs, midl_include_dirs, resource_include_dirs = \
2992
+ _GetIncludeDirs(configuration)
2993
+ libraries = _GetLibraries(spec)
2994
+ library_dirs = _GetLibraryDirs(configuration)
2995
+ out_file, _, msbuild_tool = _GetOutputFilePathAndTool(spec, msbuild=True)
2996
+ target_ext = _GetOutputTargetExt(spec)
2997
+ defines = _GetDefines(configuration)
2998
+ if converted:
2999
+ # Visual Studio 2010 has TR1
3000
+ defines = [d for d in defines if d != '_HAS_TR1=0']
3001
+ # Warn of ignored settings
3002
+ ignored_settings = ['msvs_tool_files']
3003
+ for ignored_setting in ignored_settings:
3004
+ value = configuration.get(ignored_setting)
3005
+ if value:
3006
+ print ('Warning: The automatic conversion to MSBuild does not handle '
3007
+ '%s. Ignoring setting of %s' % (ignored_setting, str(value)))
3008
+
3009
+ defines = [_EscapeCppDefineForMSBuild(d) for d in defines]
3010
+ disabled_warnings = _GetDisabledWarnings(configuration)
3011
+ prebuild = configuration.get('msvs_prebuild')
3012
+ postbuild = configuration.get('msvs_postbuild')
3013
+ def_file = _GetModuleDefinition(spec)
3014
+ precompiled_header = configuration.get('msvs_precompiled_header')
3015
+
3016
+ # Add the information to the appropriate tool
3017
+ # TODO(jeanluc) We could optimize and generate these settings only if
3018
+ # the corresponding files are found, e.g. don't generate ResourceCompile
3019
+ # if you don't have any resources.
3020
+ _ToolAppend(msbuild_settings, 'ClCompile',
3021
+ 'AdditionalIncludeDirectories', include_dirs)
3022
+ _ToolAppend(msbuild_settings, 'Midl',
3023
+ 'AdditionalIncludeDirectories', midl_include_dirs)
3024
+ _ToolAppend(msbuild_settings, 'ResourceCompile',
3025
+ 'AdditionalIncludeDirectories', resource_include_dirs)
3026
+ # Add in libraries, note that even for empty libraries, we want this
3027
+ # set, to prevent inheriting default libraries from the enviroment.
3028
+ _ToolSetOrAppend(msbuild_settings, 'Link', 'AdditionalDependencies',
3029
+ libraries)
3030
+ _ToolAppend(msbuild_settings, 'Link', 'AdditionalLibraryDirectories',
3031
+ library_dirs)
3032
+ if out_file:
3033
+ _ToolAppend(msbuild_settings, msbuild_tool, 'OutputFile', out_file,
3034
+ only_if_unset=True)
3035
+ if target_ext:
3036
+ _ToolAppend(msbuild_settings, msbuild_tool, 'TargetExt', target_ext,
3037
+ only_if_unset=True)
3038
+ # Add defines.
3039
+ _ToolAppend(msbuild_settings, 'ClCompile',
3040
+ 'PreprocessorDefinitions', defines)
3041
+ _ToolAppend(msbuild_settings, 'ResourceCompile',
3042
+ 'PreprocessorDefinitions', defines)
3043
+ # Add disabled warnings.
3044
+ _ToolAppend(msbuild_settings, 'ClCompile',
3045
+ 'DisableSpecificWarnings', disabled_warnings)
3046
+ # Turn on precompiled headers if appropriate.
3047
+ if precompiled_header:
3048
+ precompiled_header = os.path.split(precompiled_header)[1]
3049
+ _ToolAppend(msbuild_settings, 'ClCompile', 'PrecompiledHeader', 'Use')
3050
+ _ToolAppend(msbuild_settings, 'ClCompile',
3051
+ 'PrecompiledHeaderFile', precompiled_header)
3052
+ _ToolAppend(msbuild_settings, 'ClCompile',
3053
+ 'ForcedIncludeFiles', [precompiled_header])
3054
+ else:
3055
+ _ToolAppend(msbuild_settings, 'ClCompile', 'PrecompiledHeader', 'NotUsing')
3056
+ # Turn off WinRT compilation
3057
+ _ToolAppend(msbuild_settings, 'ClCompile', 'CompileAsWinRT', 'false')
3058
+ # Turn on import libraries if appropriate
3059
+ if spec.get('msvs_requires_importlibrary'):
3060
+ _ToolAppend(msbuild_settings, '', 'IgnoreImportLibrary', 'false')
3061
+ # Loadable modules don't generate import libraries;
3062
+ # tell dependent projects to not expect one.
3063
+ if spec['type'] == 'loadable_module':
3064
+ _ToolAppend(msbuild_settings, '', 'IgnoreImportLibrary', 'true')
3065
+ # Set the module definition file if any.
3066
+ if def_file:
3067
+ _ToolAppend(msbuild_settings, 'Link', 'ModuleDefinitionFile', def_file)
3068
+ configuration['finalized_msbuild_settings'] = msbuild_settings
3069
+ if prebuild:
3070
+ _ToolAppend(msbuild_settings, 'PreBuildEvent', 'Command', prebuild)
3071
+ if postbuild:
3072
+ _ToolAppend(msbuild_settings, 'PostBuildEvent', 'Command', postbuild)
3073
+
3074
+
3075
+ def _GetValueFormattedForMSBuild(tool_name, name, value):
3076
+ if type(value) == list:
3077
+ # For some settings, VS2010 does not automatically extends the settings
3078
+ # TODO(jeanluc) Is this what we want?
3079
+ if name in ['AdditionalIncludeDirectories',
3080
+ 'AdditionalLibraryDirectories',
3081
+ 'AdditionalOptions',
3082
+ 'DelayLoadDLLs',
3083
+ 'DisableSpecificWarnings',
3084
+ 'PreprocessorDefinitions']:
3085
+ value.append('%%(%s)' % name)
3086
+ # For most tools, entries in a list should be separated with ';' but some
3087
+ # settings use a space. Check for those first.
3088
+ exceptions = {
3089
+ 'ClCompile': ['AdditionalOptions'],
3090
+ 'Link': ['AdditionalOptions'],
3091
+ 'Lib': ['AdditionalOptions']}
3092
+ if tool_name in exceptions and name in exceptions[tool_name]:
3093
+ char = ' '
3094
+ else:
3095
+ char = ';'
3096
+ formatted_value = char.join(
3097
+ [MSVSSettings.ConvertVCMacrosToMSBuild(i) for i in value])
3098
+ else:
3099
+ formatted_value = MSVSSettings.ConvertVCMacrosToMSBuild(value)
3100
+ return formatted_value
3101
+
3102
+
3103
+ def _VerifySourcesExist(sources, root_dir):
3104
+ """Verifies that all source files exist on disk.
3105
+
3106
+ Checks that all regular source files, i.e. not created at run time,
3107
+ exist on disk. Missing files cause needless recompilation but no otherwise
3108
+ visible errors.
3109
+
3110
+ Arguments:
3111
+ sources: A recursive list of Filter/file names.
3112
+ root_dir: The root directory for the relative path names.
3113
+ Returns:
3114
+ A list of source files that cannot be found on disk.
3115
+ """
3116
+ missing_sources = []
3117
+ for source in sources:
3118
+ if isinstance(source, MSVSProject.Filter):
3119
+ missing_sources.extend(_VerifySourcesExist(source.contents, root_dir))
3120
+ else:
3121
+ if '$' not in source:
3122
+ full_path = os.path.join(root_dir, source)
3123
+ if not os.path.exists(full_path):
3124
+ missing_sources.append(full_path)
3125
+ return missing_sources
3126
+
3127
+
3128
+ def _GetMSBuildSources(spec, sources, exclusions, rule_dependencies,
3129
+ extension_to_rule_name, actions_spec,
3130
+ sources_handled_by_action, list_excluded):
3131
+ groups = ['none', 'masm', 'midl', 'include', 'compile', 'resource', 'rule',
3132
+ 'rule_dependency']
3133
+ grouped_sources = {}
3134
+ for g in groups:
3135
+ grouped_sources[g] = []
3136
+
3137
+ _AddSources2(spec, sources, exclusions, grouped_sources,
3138
+ rule_dependencies, extension_to_rule_name,
3139
+ sources_handled_by_action, list_excluded)
3140
+ sources = []
3141
+ for g in groups:
3142
+ if grouped_sources[g]:
3143
+ sources.append(['ItemGroup'] + grouped_sources[g])
3144
+ if actions_spec:
3145
+ sources.append(['ItemGroup'] + actions_spec)
3146
+ return sources
3147
+
3148
+
3149
+ def _AddSources2(spec, sources, exclusions, grouped_sources,
3150
+ rule_dependencies, extension_to_rule_name,
3151
+ sources_handled_by_action,
3152
+ list_excluded):
3153
+ extensions_excluded_from_precompile = []
3154
+ for source in sources:
3155
+ if isinstance(source, MSVSProject.Filter):
3156
+ _AddSources2(spec, source.contents, exclusions, grouped_sources,
3157
+ rule_dependencies, extension_to_rule_name,
3158
+ sources_handled_by_action,
3159
+ list_excluded)
3160
+ else:
3161
+ if not source in sources_handled_by_action:
3162
+ detail = []
3163
+ excluded_configurations = exclusions.get(source, [])
3164
+ if len(excluded_configurations) == len(spec['configurations']):
3165
+ detail.append(['ExcludedFromBuild', 'true'])
3166
+ else:
3167
+ for config_name, configuration in sorted(excluded_configurations):
3168
+ condition = _GetConfigurationCondition(config_name, configuration)
3169
+ detail.append(['ExcludedFromBuild',
3170
+ {'Condition': condition},
3171
+ 'true'])
3172
+ # Add precompile if needed
3173
+ for config_name, configuration in spec['configurations'].iteritems():
3174
+ precompiled_source = configuration.get('msvs_precompiled_source', '')
3175
+ if precompiled_source != '':
3176
+ precompiled_source = _FixPath(precompiled_source)
3177
+ if not extensions_excluded_from_precompile:
3178
+ # If the precompiled header is generated by a C source, we must
3179
+ # not try to use it for C++ sources, and vice versa.
3180
+ basename, extension = os.path.splitext(precompiled_source)
3181
+ if extension == '.c':
3182
+ extensions_excluded_from_precompile = ['.cc', '.cpp', '.cxx']
3183
+ else:
3184
+ extensions_excluded_from_precompile = ['.c']
3185
+
3186
+ if precompiled_source == source:
3187
+ condition = _GetConfigurationCondition(config_name, configuration)
3188
+ detail.append(['PrecompiledHeader',
3189
+ {'Condition': condition},
3190
+ 'Create'
3191
+ ])
3192
+ else:
3193
+ # Turn off precompiled header usage for source files of a
3194
+ # different type than the file that generated the
3195
+ # precompiled header.
3196
+ for extension in extensions_excluded_from_precompile:
3197
+ if source.endswith(extension):
3198
+ detail.append(['PrecompiledHeader', ''])
3199
+ detail.append(['ForcedIncludeFiles', ''])
3200
+
3201
+ group, element = _MapFileToMsBuildSourceType(source, rule_dependencies,
3202
+ extension_to_rule_name)
3203
+ grouped_sources[group].append([element, {'Include': source}] + detail)
3204
+
3205
+
3206
+ def _GetMSBuildProjectReferences(project):
3207
+ references = []
3208
+ if project.dependencies:
3209
+ group = ['ItemGroup']
3210
+ for dependency in project.dependencies:
3211
+ guid = dependency.guid
3212
+ project_dir = os.path.split(project.path)[0]
3213
+ relative_path = gyp.common.RelativePath(dependency.path, project_dir)
3214
+ project_ref = ['ProjectReference',
3215
+ {'Include': relative_path},
3216
+ ['Project', guid],
3217
+ ['ReferenceOutputAssembly', 'false']
3218
+ ]
3219
+ for config in dependency.spec.get('configurations', {}).itervalues():
3220
+ # If it's disabled in any config, turn it off in the reference.
3221
+ if config.get('msvs_2010_disable_uldi_when_referenced', 0):
3222
+ project_ref.append(['UseLibraryDependencyInputs', 'false'])
3223
+ break
3224
+ group.append(project_ref)
3225
+ references.append(group)
3226
+ return references
3227
+
3228
+
3229
+ def _GenerateMSBuildProject(project, options, version, generator_flags):
3230
+ spec = project.spec
3231
+ configurations = spec['configurations']
3232
+ project_dir, project_file_name = os.path.split(project.path)
3233
+ gyp.common.EnsureDirExists(project.path)
3234
+ # Prepare list of sources and excluded sources.
3235
+ gyp_path = _NormalizedSource(project.build_file)
3236
+ relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
3237
+
3238
+ gyp_file = os.path.split(project.build_file)[1]
3239
+ sources, excluded_sources = _PrepareListOfSources(spec, generator_flags,
3240
+ gyp_file)
3241
+ # Add rules.
3242
+ actions_to_add = {}
3243
+ props_files_of_rules = set()
3244
+ targets_files_of_rules = set()
3245
+ rule_dependencies = set()
3246
+ extension_to_rule_name = {}
3247
+ list_excluded = generator_flags.get('msvs_list_excluded_files', True)
3248
+
3249
+ # Don't generate rules if we are using an external builder like ninja.
3250
+ if not spec.get('msvs_external_builder'):
3251
+ _GenerateRulesForMSBuild(project_dir, options, spec,
3252
+ sources, excluded_sources,
3253
+ props_files_of_rules, targets_files_of_rules,
3254
+ actions_to_add, rule_dependencies,
3255
+ extension_to_rule_name)
3256
+ else:
3257
+ rules = spec.get('rules', [])
3258
+ _AdjustSourcesForRules(rules, sources, excluded_sources, True)
3259
+
3260
+ sources, excluded_sources, excluded_idl = (
3261
+ _AdjustSourcesAndConvertToFilterHierarchy(spec, options,
3262
+ project_dir, sources,
3263
+ excluded_sources,
3264
+ list_excluded, version))
3265
+
3266
+ # Don't add actions if we are using an external builder like ninja.
3267
+ if not spec.get('msvs_external_builder'):
3268
+ _AddActions(actions_to_add, spec, project.build_file)
3269
+ _AddCopies(actions_to_add, spec)
3270
+
3271
+ # NOTE: this stanza must appear after all actions have been decided.
3272
+ # Don't excluded sources with actions attached, or they won't run.
3273
+ excluded_sources = _FilterActionsFromExcluded(
3274
+ excluded_sources, actions_to_add)
3275
+
3276
+ exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
3277
+ actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild(
3278
+ spec, actions_to_add)
3279
+
3280
+ _GenerateMSBuildFiltersFile(project.path + '.filters', sources,
3281
+ rule_dependencies,
3282
+ extension_to_rule_name)
3283
+ missing_sources = _VerifySourcesExist(sources, project_dir)
3284
+
3285
+ for configuration in configurations.itervalues():
3286
+ _FinalizeMSBuildSettings(spec, configuration)
3287
+
3288
+ # Add attributes to root element
3289
+
3290
+ import_default_section = [
3291
+ ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.Default.props'}]]
3292
+ import_cpp_props_section = [
3293
+ ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.props'}]]
3294
+ import_cpp_targets_section = [
3295
+ ['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.targets'}]]
3296
+ import_masm_props_section = [
3297
+ ['Import',
3298
+ {'Project': r'$(VCTargetsPath)\BuildCustomizations\masm.props'}]]
3299
+ import_masm_targets_section = [
3300
+ ['Import',
3301
+ {'Project': r'$(VCTargetsPath)\BuildCustomizations\masm.targets'}]]
3302
+ macro_section = [['PropertyGroup', {'Label': 'UserMacros'}]]
3303
+
3304
+ content = [
3305
+ 'Project',
3306
+ {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003',
3307
+ 'ToolsVersion': version.ProjectVersion(),
3308
+ 'DefaultTargets': 'Build'
3309
+ }]
3310
+
3311
+ content += _GetMSBuildProjectConfigurations(configurations)
3312
+ content += _GetMSBuildGlobalProperties(spec, project.guid, project_file_name)
3313
+ content += import_default_section
3314
+ content += _GetMSBuildConfigurationDetails(spec, project.build_file)
3315
+ if spec.get('msvs_enable_winphone'):
3316
+ content += _GetMSBuildLocalProperties('v120_wp81')
3317
+ else:
3318
+ content += _GetMSBuildLocalProperties(project.msbuild_toolset)
3319
+ content += import_cpp_props_section
3320
+ content += import_masm_props_section
3321
+ content += _GetMSBuildExtensions(props_files_of_rules)
3322
+ content += _GetMSBuildPropertySheets(configurations)
3323
+ content += macro_section
3324
+ content += _GetMSBuildConfigurationGlobalProperties(spec, configurations,
3325
+ project.build_file)
3326
+ content += _GetMSBuildToolSettingsSections(spec, configurations)
3327
+ content += _GetMSBuildSources(
3328
+ spec, sources, exclusions, rule_dependencies, extension_to_rule_name,
3329
+ actions_spec, sources_handled_by_action, list_excluded)
3330
+ content += _GetMSBuildProjectReferences(project)
3331
+ content += import_cpp_targets_section
3332
+ content += import_masm_targets_section
3333
+ content += _GetMSBuildExtensionTargets(targets_files_of_rules)
3334
+
3335
+ if spec.get('msvs_external_builder'):
3336
+ content += _GetMSBuildExternalBuilderTargets(spec)
3337
+
3338
+ # TODO(jeanluc) File a bug to get rid of runas. We had in MSVS:
3339
+ # has_run_as = _WriteMSVSUserFile(project.path, version, spec)
3340
+
3341
+ easy_xml.WriteXmlIfChanged(content, project.path, pretty=True, win32=True)
3342
+
3343
+ return missing_sources
3344
+
3345
+
3346
+ def _GetMSBuildExternalBuilderTargets(spec):
3347
+ """Return a list of MSBuild targets for external builders.
3348
+
3349
+ The "Build" and "Clean" targets are always generated. If the spec contains
3350
+ 'msvs_external_builder_clcompile_cmd', then the "ClCompile" target will also
3351
+ be generated, to support building selected C/C++ files.
3352
+
3353
+ Arguments:
3354
+ spec: The gyp target spec.
3355
+ Returns:
3356
+ List of MSBuild 'Target' specs.
3357
+ """
3358
+ build_cmd = _BuildCommandLineForRuleRaw(
3359
+ spec, spec['msvs_external_builder_build_cmd'],
3360
+ False, False, False, False)
3361
+ build_target = ['Target', {'Name': 'Build'}]
3362
+ build_target.append(['Exec', {'Command': build_cmd}])
3363
+
3364
+ clean_cmd = _BuildCommandLineForRuleRaw(
3365
+ spec, spec['msvs_external_builder_clean_cmd'],
3366
+ False, False, False, False)
3367
+ clean_target = ['Target', {'Name': 'Clean'}]
3368
+ clean_target.append(['Exec', {'Command': clean_cmd}])
3369
+
3370
+ targets = [build_target, clean_target]
3371
+
3372
+ if spec.get('msvs_external_builder_clcompile_cmd'):
3373
+ clcompile_cmd = _BuildCommandLineForRuleRaw(
3374
+ spec, spec['msvs_external_builder_clcompile_cmd'],
3375
+ False, False, False, False)
3376
+ clcompile_target = ['Target', {'Name': 'ClCompile'}]
3377
+ clcompile_target.append(['Exec', {'Command': clcompile_cmd}])
3378
+ targets.append(clcompile_target)
3379
+
3380
+ return targets
3381
+
3382
+
3383
+ def _GetMSBuildExtensions(props_files_of_rules):
3384
+ extensions = ['ImportGroup', {'Label': 'ExtensionSettings'}]
3385
+ for props_file in props_files_of_rules:
3386
+ extensions.append(['Import', {'Project': props_file}])
3387
+ return [extensions]
3388
+
3389
+
3390
+ def _GetMSBuildExtensionTargets(targets_files_of_rules):
3391
+ targets_node = ['ImportGroup', {'Label': 'ExtensionTargets'}]
3392
+ for targets_file in sorted(targets_files_of_rules):
3393
+ targets_node.append(['Import', {'Project': targets_file}])
3394
+ return [targets_node]
3395
+
3396
+
3397
+ def _GenerateActionsForMSBuild(spec, actions_to_add):
3398
+ """Add actions accumulated into an actions_to_add, merging as needed.
3399
+
3400
+ Arguments:
3401
+ spec: the target project dict
3402
+ actions_to_add: dictionary keyed on input name, which maps to a list of
3403
+ dicts describing the actions attached to that input file.
3404
+
3405
+ Returns:
3406
+ A pair of (action specification, the sources handled by this action).
3407
+ """
3408
+ sources_handled_by_action = OrderedSet()
3409
+ actions_spec = []
3410
+ for primary_input, actions in actions_to_add.iteritems():
3411
+ inputs = OrderedSet()
3412
+ outputs = OrderedSet()
3413
+ descriptions = []
3414
+ commands = []
3415
+ for action in actions:
3416
+ inputs.update(OrderedSet(action['inputs']))
3417
+ outputs.update(OrderedSet(action['outputs']))
3418
+ descriptions.append(action['description'])
3419
+ cmd = action['command']
3420
+ # For most actions, add 'call' so that actions that invoke batch files
3421
+ # return and continue executing. msbuild_use_call provides a way to
3422
+ # disable this but I have not seen any adverse effect from doing that
3423
+ # for everything.
3424
+ if action.get('msbuild_use_call', True):
3425
+ cmd = 'call ' + cmd
3426
+ commands.append(cmd)
3427
+ # Add the custom build action for one input file.
3428
+ description = ', and also '.join(descriptions)
3429
+
3430
+ # We can't join the commands simply with && because the command line will
3431
+ # get too long. See also _AddActions: cygwin's setup_env mustn't be called
3432
+ # for every invocation or the command that sets the PATH will grow too
3433
+ # long.
3434
+ command = '\r\n'.join([c + '\r\nif %errorlevel% neq 0 exit /b %errorlevel%'
3435
+ for c in commands])
3436
+ _AddMSBuildAction(spec,
3437
+ primary_input,
3438
+ inputs,
3439
+ outputs,
3440
+ command,
3441
+ description,
3442
+ sources_handled_by_action,
3443
+ actions_spec)
3444
+ return actions_spec, sources_handled_by_action
3445
+
3446
+
3447
+ def _AddMSBuildAction(spec, primary_input, inputs, outputs, cmd, description,
3448
+ sources_handled_by_action, actions_spec):
3449
+ command = MSVSSettings.ConvertVCMacrosToMSBuild(cmd)
3450
+ primary_input = _FixPath(primary_input)
3451
+ inputs_array = _FixPaths(inputs)
3452
+ outputs_array = _FixPaths(outputs)
3453
+ additional_inputs = ';'.join([i for i in inputs_array
3454
+ if i != primary_input])
3455
+ outputs = ';'.join(outputs_array)
3456
+ sources_handled_by_action.add(primary_input)
3457
+ action_spec = ['CustomBuild', {'Include': primary_input}]
3458
+ action_spec.extend(
3459
+ # TODO(jeanluc) 'Document' for all or just if as_sources?
3460
+ [['FileType', 'Document'],
3461
+ ['Command', command],
3462
+ ['Message', description],
3463
+ ['Outputs', outputs]
3464
+ ])
3465
+ if additional_inputs:
3466
+ action_spec.append(['AdditionalInputs', additional_inputs])
3467
+ actions_spec.append(action_spec)