nokogiri 1.0.0 → 1.6.8.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (309) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +26 -0
  3. data/.cross_rubies +9 -0
  4. data/.editorconfig +17 -0
  5. data/.gemtest +0 -0
  6. data/.travis.yml +51 -0
  7. data/CHANGELOG.rdoc +1160 -0
  8. data/CONTRIBUTING.md +42 -0
  9. data/C_CODING_STYLE.rdoc +33 -0
  10. data/Gemfile +22 -0
  11. data/LICENSE.txt +31 -0
  12. data/Manifest.txt +284 -40
  13. data/README.md +166 -0
  14. data/ROADMAP.md +111 -0
  15. data/Rakefile +310 -199
  16. data/STANDARD_RESPONSES.md +47 -0
  17. data/Y_U_NO_GEMSPEC.md +155 -0
  18. data/appveyor.yml +22 -0
  19. data/bin/nokogiri +118 -0
  20. data/build_all +45 -0
  21. data/dependencies.yml +29 -0
  22. data/ext/nokogiri/depend +358 -0
  23. data/ext/nokogiri/extconf.rb +664 -34
  24. data/ext/nokogiri/html_document.c +120 -33
  25. data/ext/nokogiri/html_document.h +1 -1
  26. data/ext/nokogiri/html_element_description.c +279 -0
  27. data/ext/nokogiri/html_element_description.h +10 -0
  28. data/ext/nokogiri/html_entity_lookup.c +32 -0
  29. data/ext/nokogiri/html_entity_lookup.h +8 -0
  30. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  31. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  32. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  33. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  34. data/ext/nokogiri/nokogiri.c +145 -0
  35. data/ext/nokogiri/nokogiri.h +131 -0
  36. data/ext/nokogiri/xml_attr.c +94 -0
  37. data/ext/nokogiri/xml_attr.h +9 -0
  38. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  39. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  40. data/ext/nokogiri/xml_cdata.c +23 -19
  41. data/ext/nokogiri/xml_cdata.h +1 -1
  42. data/ext/nokogiri/xml_comment.c +69 -0
  43. data/ext/nokogiri/xml_comment.h +9 -0
  44. data/ext/nokogiri/xml_document.c +501 -54
  45. data/ext/nokogiri/xml_document.h +14 -1
  46. data/ext/nokogiri/xml_document_fragment.c +48 -0
  47. data/ext/nokogiri/xml_document_fragment.h +10 -0
  48. data/ext/nokogiri/xml_dtd.c +109 -24
  49. data/ext/nokogiri/xml_dtd.h +3 -1
  50. data/ext/nokogiri/xml_element_content.c +123 -0
  51. data/ext/nokogiri/xml_element_content.h +10 -0
  52. data/ext/nokogiri/xml_element_decl.c +69 -0
  53. data/ext/nokogiri/xml_element_decl.h +9 -0
  54. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  55. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  56. data/ext/nokogiri/xml_entity_decl.c +110 -0
  57. data/ext/nokogiri/xml_entity_decl.h +10 -0
  58. data/ext/nokogiri/xml_entity_reference.c +52 -0
  59. data/ext/nokogiri/xml_entity_reference.h +9 -0
  60. data/ext/nokogiri/xml_io.c +60 -0
  61. data/ext/nokogiri/xml_io.h +11 -0
  62. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  63. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  64. data/ext/nokogiri/xml_namespace.c +117 -0
  65. data/ext/nokogiri/xml_namespace.h +13 -0
  66. data/ext/nokogiri/xml_node.c +1285 -315
  67. data/ext/nokogiri/xml_node.h +4 -6
  68. data/ext/nokogiri/xml_node_set.c +415 -54
  69. data/ext/nokogiri/xml_node_set.h +6 -2
  70. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  71. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  72. data/ext/nokogiri/xml_reader.c +316 -77
  73. data/ext/nokogiri/xml_reader.h +1 -1
  74. data/ext/nokogiri/xml_relax_ng.c +161 -0
  75. data/ext/nokogiri/xml_relax_ng.h +9 -0
  76. data/ext/nokogiri/xml_sax_parser.c +215 -80
  77. data/ext/nokogiri/xml_sax_parser.h +30 -1
  78. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  79. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  80. data/ext/nokogiri/xml_sax_push_parser.c +115 -0
  81. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  82. data/ext/nokogiri/xml_schema.c +205 -0
  83. data/ext/nokogiri/xml_schema.h +9 -0
  84. data/ext/nokogiri/xml_syntax_error.c +45 -175
  85. data/ext/nokogiri/xml_syntax_error.h +4 -2
  86. data/ext/nokogiri/xml_text.c +37 -14
  87. data/ext/nokogiri/xml_text.h +1 -1
  88. data/ext/nokogiri/xml_xpath_context.c +230 -13
  89. data/ext/nokogiri/xml_xpath_context.h +2 -1
  90. data/ext/nokogiri/xslt_stylesheet.c +196 -34
  91. data/ext/nokogiri/xslt_stylesheet.h +6 -1
  92. data/lib/nokogiri/css/node.rb +18 -61
  93. data/lib/nokogiri/css/parser.rb +725 -17
  94. data/lib/nokogiri/css/parser.y +126 -63
  95. data/lib/nokogiri/css/parser_extras.rb +91 -0
  96. data/lib/nokogiri/css/syntax_error.rb +7 -0
  97. data/lib/nokogiri/css/tokenizer.rb +148 -5
  98. data/lib/nokogiri/css/tokenizer.rex +31 -39
  99. data/lib/nokogiri/css/xpath_visitor.rb +109 -51
  100. data/lib/nokogiri/css.rb +24 -3
  101. data/lib/nokogiri/decorators/slop.rb +42 -0
  102. data/lib/nokogiri/html/builder.rb +27 -1
  103. data/lib/nokogiri/html/document.rb +329 -3
  104. data/lib/nokogiri/html/document_fragment.rb +39 -0
  105. data/lib/nokogiri/html/element_description.rb +23 -0
  106. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  107. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  108. data/lib/nokogiri/html/sax/parser.rb +35 -4
  109. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  110. data/lib/nokogiri/html/sax/push_parser.rb +36 -0
  111. data/lib/nokogiri/html.rb +18 -76
  112. data/lib/nokogiri/syntax_error.rb +4 -0
  113. data/lib/nokogiri/version.rb +106 -1
  114. data/lib/nokogiri/xml/attr.rb +14 -0
  115. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  116. data/lib/nokogiri/xml/builder.rb +395 -31
  117. data/lib/nokogiri/xml/cdata.rb +4 -2
  118. data/lib/nokogiri/xml/character_data.rb +7 -0
  119. data/lib/nokogiri/xml/document.rb +267 -12
  120. data/lib/nokogiri/xml/document_fragment.rb +149 -0
  121. data/lib/nokogiri/xml/dtd.rb +27 -1
  122. data/lib/nokogiri/xml/element_content.rb +36 -0
  123. data/lib/nokogiri/xml/element_decl.rb +13 -0
  124. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  125. data/lib/nokogiri/xml/namespace.rb +13 -0
  126. data/lib/nokogiri/xml/node/save_options.rb +61 -0
  127. data/lib/nokogiri/xml/node.rb +748 -109
  128. data/lib/nokogiri/xml/node_set.rb +200 -72
  129. data/lib/nokogiri/xml/parse_options.rb +120 -0
  130. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  131. data/lib/nokogiri/xml/pp/node.rb +56 -0
  132. data/lib/nokogiri/xml/pp.rb +2 -0
  133. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  134. data/lib/nokogiri/xml/reader.rb +102 -4
  135. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  136. data/lib/nokogiri/xml/sax/document.rb +114 -2
  137. data/lib/nokogiri/xml/sax/parser.rb +97 -7
  138. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  139. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  140. data/lib/nokogiri/xml/sax.rb +2 -7
  141. data/lib/nokogiri/xml/schema.rb +63 -0
  142. data/lib/nokogiri/xml/searchable.rb +221 -0
  143. data/lib/nokogiri/xml/syntax_error.rb +27 -1
  144. data/lib/nokogiri/xml/text.rb +4 -1
  145. data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
  146. data/lib/nokogiri/xml/xpath.rb +4 -0
  147. data/lib/nokogiri/xml/xpath_context.rb +3 -1
  148. data/lib/nokogiri/xml.rb +45 -38
  149. data/lib/nokogiri/xslt/stylesheet.rb +19 -0
  150. data/lib/nokogiri/xslt.rb +47 -2
  151. data/lib/nokogiri.rb +117 -24
  152. data/lib/xsd/xmlparser/nokogiri.rb +102 -0
  153. data/patches/sort-patches-by-date +25 -0
  154. data/ports/archives/libxml2-2.9.4.tar.gz +0 -0
  155. data/ports/archives/libxslt-1.1.29.tar.gz +0 -0
  156. data/suppressions/README.txt +1 -0
  157. data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
  158. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  159. data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
  160. data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
  161. data/tasks/test.rb +100 -0
  162. data/test/css/test_nthiness.rb +73 -6
  163. data/test/css/test_parser.rb +184 -39
  164. data/test/css/test_tokenizer.rb +72 -19
  165. data/test/css/test_xpath_visitor.rb +44 -2
  166. data/test/decorators/test_slop.rb +20 -0
  167. data/test/files/2ch.html +108 -0
  168. data/test/files/GH_1042.html +18 -0
  169. data/test/files/address_book.rlx +12 -0
  170. data/test/files/address_book.xml +10 -0
  171. data/test/files/atom.xml +344 -0
  172. data/test/files/bar/bar.xsd +4 -0
  173. data/test/files/bogus.xml +0 -0
  174. data/test/files/dont_hurt_em_why.xml +422 -0
  175. data/test/files/encoding.html +82 -0
  176. data/test/files/encoding.xhtml +84 -0
  177. data/test/files/exslt.xml +8 -0
  178. data/test/files/exslt.xslt +35 -0
  179. data/test/files/foo/foo.xsd +4 -0
  180. data/test/files/metacharset.html +10 -0
  181. data/test/files/namespace_pressure_test.xml +1684 -0
  182. data/test/files/noencoding.html +47 -0
  183. data/test/files/po.xml +32 -0
  184. data/test/files/po.xsd +66 -0
  185. data/test/files/saml/saml20assertion_schema.xsd +283 -0
  186. data/test/files/saml/saml20protocol_schema.xsd +302 -0
  187. data/test/files/saml/xenc_schema.xsd +146 -0
  188. data/test/files/saml/xmldsig_schema.xsd +318 -0
  189. data/test/files/shift_jis.html +10 -0
  190. data/test/files/shift_jis.xml +5 -0
  191. data/test/files/shift_jis_no_charset.html +9 -0
  192. data/test/files/slow-xpath.xml +25509 -0
  193. data/test/files/snuggles.xml +3 -0
  194. data/test/files/staff.dtd +10 -0
  195. data/test/files/test_document_url/bar.xml +2 -0
  196. data/test/files/test_document_url/document.dtd +4 -0
  197. data/test/files/test_document_url/document.xml +6 -0
  198. data/test/files/tlm.html +2 -1
  199. data/test/files/to_be_xincluded.xml +2 -0
  200. data/test/files/valid_bar.xml +2 -0
  201. data/test/files/xinclude.xml +4 -0
  202. data/test/helper.rb +124 -13
  203. data/test/html/sax/test_parser.rb +118 -4
  204. data/test/html/sax/test_parser_context.rb +46 -0
  205. data/test/html/sax/test_push_parser.rb +87 -0
  206. data/test/html/test_builder.rb +94 -8
  207. data/test/html/test_document.rb +626 -11
  208. data/test/html/test_document_encoding.rb +145 -0
  209. data/test/html/test_document_fragment.rb +301 -0
  210. data/test/html/test_element_description.rb +105 -0
  211. data/test/html/test_named_characters.rb +14 -0
  212. data/test/html/test_node.rb +212 -0
  213. data/test/html/test_node_encoding.rb +85 -0
  214. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +14 -0
  215. data/test/namespaces/test_namespaces_aliased_default.rb +24 -0
  216. data/test/namespaces/test_namespaces_in_builder_doc.rb +75 -0
  217. data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
  218. data/test/namespaces/test_namespaces_in_created_doc.rb +75 -0
  219. data/test/namespaces/test_namespaces_in_parsed_doc.rb +80 -0
  220. data/test/namespaces/test_namespaces_preservation.rb +31 -0
  221. data/test/test_convert_xpath.rb +2 -47
  222. data/test/test_css_cache.rb +45 -0
  223. data/test/test_encoding_handler.rb +48 -0
  224. data/test/test_memory_leak.rb +156 -0
  225. data/test/test_nokogiri.rb +103 -1
  226. data/test/test_soap4r_sax.rb +52 -0
  227. data/test/test_xslt_transforms.rb +293 -8
  228. data/test/xml/node/test_save_options.rb +28 -0
  229. data/test/xml/node/test_subclass.rb +44 -0
  230. data/test/xml/sax/test_parser.rb +309 -8
  231. data/test/xml/sax/test_parser_context.rb +115 -0
  232. data/test/xml/sax/test_push_parser.rb +157 -0
  233. data/test/xml/test_attr.rb +67 -0
  234. data/test/xml/test_attribute_decl.rb +86 -0
  235. data/test/xml/test_builder.rb +327 -2
  236. data/test/xml/test_c14n.rb +180 -0
  237. data/test/xml/test_cdata.rb +32 -2
  238. data/test/xml/test_comment.rb +40 -0
  239. data/test/xml/test_document.rb +846 -35
  240. data/test/xml/test_document_encoding.rb +31 -0
  241. data/test/xml/test_document_fragment.rb +271 -0
  242. data/test/xml/test_dtd.rb +153 -9
  243. data/test/xml/test_dtd_encoding.rb +31 -0
  244. data/test/xml/test_element_content.rb +56 -0
  245. data/test/xml/test_element_decl.rb +73 -0
  246. data/test/xml/test_entity_decl.rb +122 -0
  247. data/test/xml/test_entity_reference.rb +251 -0
  248. data/test/xml/test_namespace.rb +96 -0
  249. data/test/xml/test_node.rb +1126 -105
  250. data/test/xml/test_node_attributes.rb +115 -0
  251. data/test/xml/test_node_encoding.rb +69 -0
  252. data/test/xml/test_node_inheritance.rb +32 -0
  253. data/test/xml/test_node_reparenting.rb +549 -0
  254. data/test/xml/test_node_set.rb +668 -9
  255. data/test/xml/test_parse_options.rb +64 -0
  256. data/test/xml/test_processing_instruction.rb +30 -0
  257. data/test/xml/test_reader.rb +589 -0
  258. data/test/xml/test_reader_encoding.rb +134 -0
  259. data/test/xml/test_relax_ng.rb +60 -0
  260. data/test/xml/test_schema.rb +142 -0
  261. data/test/xml/test_syntax_error.rb +30 -0
  262. data/test/xml/test_text.rb +49 -2
  263. data/test/xml/test_unparented_node.rb +440 -0
  264. data/test/xml/test_xinclude.rb +83 -0
  265. data/test/xml/test_xpath.rb +445 -0
  266. data/test/xslt/test_custom_functions.rb +133 -0
  267. data/test/xslt/test_exception_handling.rb +37 -0
  268. data/test_all +107 -0
  269. metadata +459 -115
  270. data/History.txt +0 -6
  271. data/README.ja.txt +0 -86
  272. data/README.txt +0 -87
  273. data/ext/nokogiri/html_sax_parser.c +0 -32
  274. data/ext/nokogiri/html_sax_parser.h +0 -11
  275. data/ext/nokogiri/native.c +0 -40
  276. data/ext/nokogiri/native.h +0 -51
  277. data/ext/nokogiri/xml_xpath.c +0 -46
  278. data/ext/nokogiri/xml_xpath.h +0 -11
  279. data/lib/nokogiri/css/generated_parser.rb +0 -653
  280. data/lib/nokogiri/css/generated_tokenizer.rb +0 -159
  281. data/lib/nokogiri/decorators/hpricot/node.rb +0 -58
  282. data/lib/nokogiri/decorators/hpricot/node_set.rb +0 -14
  283. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +0 -17
  284. data/lib/nokogiri/decorators/hpricot.rb +0 -3
  285. data/lib/nokogiri/decorators.rb +0 -1
  286. data/lib/nokogiri/hpricot.rb +0 -47
  287. data/lib/nokogiri/xml/after_handler.rb +0 -18
  288. data/lib/nokogiri/xml/before_handler.rb +0 -32
  289. data/lib/nokogiri/xml/element.rb +0 -6
  290. data/lib/nokogiri/xml/entity_declaration.rb +0 -9
  291. data/nokogiri.gemspec +0 -34
  292. data/test/hpricot/files/basic.xhtml +0 -17
  293. data/test/hpricot/files/boingboing.html +0 -2266
  294. data/test/hpricot/files/cy0.html +0 -3653
  295. data/test/hpricot/files/immob.html +0 -400
  296. data/test/hpricot/files/pace_application.html +0 -1320
  297. data/test/hpricot/files/tenderlove.html +0 -16
  298. data/test/hpricot/files/uswebgen.html +0 -220
  299. data/test/hpricot/files/utf8.html +0 -1054
  300. data/test/hpricot/files/week9.html +0 -1723
  301. data/test/hpricot/files/why.xml +0 -19
  302. data/test/hpricot/load_files.rb +0 -7
  303. data/test/hpricot/test_alter.rb +0 -67
  304. data/test/hpricot/test_builder.rb +0 -27
  305. data/test/hpricot/test_parser.rb +0 -423
  306. data/test/hpricot/test_paths.rb +0 -15
  307. data/test/hpricot/test_preserved.rb +0 -78
  308. data/test/hpricot/test_xml.rb +0 -30
  309. data/test/test_reader.rb +0 -222
@@ -1,59 +1,689 @@
1
- ENV["ARCHFLAGS"] = "-arch #{`uname -p` =~ /powerpc/ ? 'ppc' : 'i386'}"
1
+ # :stopdoc:
2
+ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
2
3
 
3
4
  require 'mkmf'
4
5
 
5
6
  ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
6
7
 
7
- $CFLAGS << " #{ENV["CFLAGS"]}"
8
- if Config::CONFIG['target_os'] == 'mingw32'
9
- $CFLAGS << " -DXP_WIN -DXP_WIN32"
10
- else
11
- $CFLAGS << " -g -DXP_UNIX"
8
+ #
9
+ # functions
10
+ #
11
+ def windows?
12
+ RbConfig::CONFIG['target_os'] =~ /mingw32|mswin/
12
13
  end
13
14
 
14
- $CFLAGS << " -O3 -Wall -Wextra -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
15
+ def solaris?
16
+ RbConfig::CONFIG['target_os'] =~ /solaris/
17
+ end
15
18
 
16
- if Config::CONFIG['target_os'] == 'mingw32'
17
- find_library('xml2', 'xmlParseDoc',
18
- File.join(ROOT, 'cross', 'libxml2-2.7.2.win32', 'bin'))
19
- find_library('xslt', 'xsltParseStylesheetDoc',
20
- File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'bin'))
21
- else
22
- find_library('xml2', 'xmlParseDoc')
23
- find_library('xslt', 'xsltParseStylesheetDoc')
19
+ def darwin?
20
+ RbConfig::CONFIG['target_os'] =~ /darwin/
24
21
  end
25
22
 
23
+ def nix?
24
+ ! (windows? || solaris? || darwin?)
25
+ end
26
26
 
27
- if Config::CONFIG['target_os'] == 'mingw32'
28
- header = File.join(ROOT, 'cross', 'libxml2-2.7.2.win32', 'include')
29
- unless find_header('libxml/xmlversion.h', header)
30
- abort "need libxml"
27
+ def sh_export_path path
28
+ # because libxslt 1.1.29 configure.in uses AC_PATH_TOOL which treats ":"
29
+ # as a $PATH separator, we need to convert windows paths from
30
+ #
31
+ # C:/path/to/foo
32
+ #
33
+ # to
34
+ #
35
+ # /C/path/to/foo
36
+ #
37
+ # which is sh-compatible, in order to find things properly during
38
+ # configuration
39
+ if windows?
40
+ match = Regexp.new("^([A-Z]):(/.*)").match(path)
41
+ if match && match.length == 3
42
+ return File.join("/", match[1], match[2])
43
+ end
31
44
  end
45
+ path
46
+ end
47
+
48
+ def do_help
49
+ print <<HELP
50
+ usage: ruby #{$0} [options]
51
+
52
+ --disable-clean
53
+ Do not clean out intermediate files after successful build.
54
+
55
+ --disable-static
56
+ Do not statically link bundled libraries.
57
+
58
+ --with-iconv-dir=DIR
59
+ Use the iconv library placed under DIR.
60
+
61
+ --with-zlib-dir=DIR
62
+ Use the zlib library placed under DIR.
63
+
64
+ --use-system-libraries
65
+ Use system libraries intead of building and using the bundled
66
+ libraries.
67
+
68
+ --with-xml2-dir=DIR / --with-xml2-config=CONFIG
69
+ --with-xslt-dir=DIR / --with-xslt-config=CONFIG
70
+ --with-exslt-dir=DIR / --with-exslt-config=CONFIG
71
+ Use libxml2/libxslt/libexslt as specified.
72
+
73
+ --enable-cross-build
74
+ Do cross-build.
75
+ HELP
76
+ exit! 0
77
+ end
78
+
79
+ def do_clean
80
+ require 'pathname'
81
+ require 'fileutils'
82
+
83
+ root = Pathname(ROOT)
84
+ pwd = Pathname(Dir.pwd)
85
+
86
+ # Skip if this is a development work tree
87
+ unless (root + '.git').exist?
88
+ message "Cleaning files only used during build.\n"
89
+
90
+ # (root + 'tmp') cannot be removed at this stage because
91
+ # nokogiri.so is yet to be copied to lib.
92
+
93
+ # clean the ports build directory
94
+ Pathname.glob(pwd.join('tmp', '*', 'ports')) do |dir|
95
+ FileUtils.rm_rf(dir, verbose: true)
96
+ end
97
+
98
+ if enable_config('static')
99
+ # ports installation can be safely removed if statically linked.
100
+ FileUtils.rm_rf(root + 'ports', verbose: true)
101
+ else
102
+ FileUtils.rm_rf(root + 'ports' + 'archives', verbose: true)
103
+ end
104
+ end
105
+
106
+ exit! 0
107
+ end
108
+
109
+ def package_config pkg, options={}
110
+ package = pkg_config(pkg)
111
+ return package if package
112
+
113
+ begin
114
+ require 'rubygems'
115
+ gem 'pkg-config', (gem_ver='~> 1.1.7')
116
+ require 'pkg-config' and message("Using pkg-config gem version #{PKGConfig::VERSION}\n")
117
+ rescue LoadError
118
+ message "pkg-config could not be used to find #{pkg}\nPlease install either `pkg-config` or the pkg-config gem per\n\n gem install pkg-config -v #{gem_ver.inspect}\n\n"
119
+ else
120
+ return nil unless PKGConfig.have_package(pkg)
121
+
122
+ cflags = PKGConfig.cflags(pkg)
123
+ ldflags = PKGConfig.libs_only_L(pkg)
124
+ libs = PKGConfig.libs_only_l(pkg)
125
+
126
+ Logging::message "PKGConfig package configuration for %s\n", pkg
127
+ Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs
128
+
129
+ [cflags, ldflags, libs]
130
+ end
131
+ end
132
+
133
+ def nokogiri_try_compile
134
+ args = if defined?(RUBY_VERSION) && RUBY_VERSION <= "1.9.2"
135
+ ["int main() {return 0;}"]
136
+ else
137
+ ["int main() {return 0;}", "", {werror: true}]
138
+ end
139
+ try_compile(*args)
140
+ end
141
+
142
+ def check_libxml_version version=nil
143
+ source = if version.nil?
144
+ <<-SRC
145
+ #include <libxml/xmlversion.h>
146
+ SRC
147
+ else
148
+ version_int = sprintf "%d%2.2d%2.2d", *(version.split("."))
149
+ <<-SRC
150
+ #include <libxml/xmlversion.h>
151
+ #if LIBXML_VERSION < #{version_int}
152
+ #error libxml2 is older than #{version}
153
+ #endif
154
+ SRC
155
+ end
156
+
157
+ try_cpp source
158
+ end
159
+
160
+ def add_cflags(flags)
161
+ print "checking if the C compiler accepts #{flags}... "
162
+ with_cflags("#{$CFLAGS} #{flags}") do
163
+ if nokogiri_try_compile
164
+ puts 'yes'
165
+ true
166
+ else
167
+ puts 'no'
168
+ false
169
+ end
170
+ end
171
+ end
172
+
173
+ def preserving_globals
174
+ values = [
175
+ $arg_config,
176
+ $CFLAGS, $CPPFLAGS,
177
+ $LDFLAGS, $LIBPATH, $libs
178
+ ].map(&:dup)
179
+ yield
180
+ ensure
181
+ $arg_config,
182
+ $CFLAGS, $CPPFLAGS,
183
+ $LDFLAGS, $LIBPATH, $libs =
184
+ values
185
+ end
186
+
187
+ def asplode(lib)
188
+ abort "-----\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----"
189
+ end
190
+
191
+ def have_iconv?(using = nil)
192
+ checking_for(using ? "iconv using #{using}" : 'iconv') do
193
+ ['', '-liconv'].any? do |opt|
194
+ preserving_globals do
195
+ yield if block_given?
196
+
197
+ try_link(<<-'SRC', opt)
198
+ #include <stdlib.h>
199
+ #include <iconv.h>
200
+
201
+ int main(void)
202
+ {
203
+ iconv_t cd = iconv_open("", "");
204
+ iconv(cd, NULL, NULL, NULL, NULL);
205
+ return EXIT_SUCCESS;
206
+ }
207
+ SRC
208
+ end
209
+ end
210
+ end
211
+ end
212
+
213
+ def iconv_configure_flags
214
+ # If --with-iconv-dir or --with-opt-dir is given, it should be
215
+ # the first priority
216
+ %w[iconv opt].each do |name|
217
+ if (config = preserving_globals { dir_config(name) }).any? &&
218
+ have_iconv?("--with-#{name}-* flags") { dir_config(name) }
219
+ idirs, ldirs = config.map do |dirs|
220
+ Array(dirs).flat_map do |dir|
221
+ dir.split(File::PATH_SEPARATOR)
222
+ end if dirs
223
+ end
224
+
225
+ return [
226
+ '--with-iconv=yes',
227
+ *("CPPFLAGS=#{idirs.map { |dir| '-I' << dir }.join(' ')}" if idirs),
228
+ *("LDFLAGS=#{ldirs.map { |dir| '-L' << dir }.join(' ')}" if ldirs),
229
+ ]
230
+ end
231
+ end
232
+
233
+ if have_iconv?
234
+ return ['--with-iconv=yes']
235
+ end
236
+
237
+ if (config = preserving_globals { package_config('libiconv') }) &&
238
+ have_iconv?('pkg-config libiconv') { package_config('libiconv') }
239
+ cflags, ldflags, libs = config
240
+
241
+ return [
242
+ '--with-iconv=yes',
243
+ "CPPFLAGS=#{cflags}",
244
+ "LDFLAGS=#{ldflags}",
245
+ "LIBS=#{libs}",
246
+ ]
247
+ end
248
+
249
+ asplode "libiconv"
250
+ end
251
+
252
+ # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
253
+ # folders don't support symlinks, but libiconv expects it for a build on
254
+ # Linux. We work around this limitation by using the temp dir for cooking.
255
+ def chdir_for_build
256
+ build_dir = ENV['RCD_HOST_RUBY_PLATFORM'].to_s =~ /mingw|mswin|cygwin/ ? '/tmp' : '.'
257
+ Dir.chdir(build_dir) do
258
+ yield
259
+ end
260
+ end
261
+
262
+ def process_recipe(name, version, static_p, cross_p)
263
+ MiniPortile.new(name, version).tap do |recipe|
264
+ recipe.target = portsdir = File.join(ROOT, "ports")
265
+ # Prefer host_alias over host in order to use i586-mingw32msvc as
266
+ # correct compiler prefix for cross build, but use host if not set.
267
+ recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
268
+ recipe.patch_files = Dir[File.join(ROOT, "patches", name, "*.patch")].sort
269
+
270
+ yield recipe
271
+
272
+ env = Hash.new do |hash, key|
273
+ hash[key] = "#{ENV[key]}" # (ENV[key].dup rescue '')
274
+ end
275
+
276
+ recipe.configure_options.flatten!
277
+
278
+ recipe.configure_options.delete_if do |option|
279
+ case option
280
+ when /\A(\w+)=(.*)\z/
281
+ env[$1] = $2
282
+ true
283
+ else
284
+ false
285
+ end
286
+ end
287
+
288
+ if static_p
289
+ recipe.configure_options += [
290
+ "--disable-shared",
291
+ "--enable-static",
292
+ ]
293
+ env['CFLAGS'] = "-fPIC #{env['CFLAGS']}"
294
+ else
295
+ recipe.configure_options += [
296
+ "--enable-shared",
297
+ "--disable-static",
298
+ ]
299
+ end
300
+
301
+ if cross_p
302
+ recipe.configure_options += [
303
+ "--target=#{recipe.host}",
304
+ "--host=#{recipe.host}",
305
+ ]
306
+ end
307
+
308
+ if RbConfig::CONFIG['target_cpu'] == 'universal'
309
+ %w[CFLAGS LDFLAGS].each do |key|
310
+ unless env[key].include?('-arch')
311
+ env[key] << ' ' << RbConfig::CONFIG['ARCH_FLAG']
312
+ end
313
+ end
314
+ end
315
+
316
+ recipe.configure_options += env.map do |key, value|
317
+ "#{key}=#{value}"
318
+ end
319
+
320
+ message <<-"EOS"
321
+ ************************************************************************
322
+ IMPORTANT NOTICE:
323
+
324
+ Building Nokogiri with a packaged version of #{name}-#{version}#{'.' if recipe.patch_files.empty?}
325
+ EOS
326
+
327
+ unless recipe.patch_files.empty?
328
+ message "with the following patches applied:\n"
32
329
 
33
- header = File.join(ROOT, 'cross', 'libxslt-1.1.24.win32', 'include')
34
- unless find_header('libxslt/libxslt.h', header)
35
- abort "need libxslt"
330
+ recipe.patch_files.each do |patch|
331
+ message "\t- %s\n" % File.basename(patch)
332
+ end
333
+ end
334
+
335
+ message <<-"EOS"
336
+
337
+ Team Nokogiri will keep on doing their best to provide security
338
+ updates in a timely manner, but if this is a concern for you and want
339
+ to use the system library instead; abort this installation process and
340
+ reinstall nokogiri as follows:
341
+
342
+ gem install nokogiri -- --use-system-libraries
343
+ [--with-xml2-config=/path/to/xml2-config]
344
+ [--with-xslt-config=/path/to/xslt-config]
345
+
346
+ If you are using Bundler, tell it to use the option:
347
+
348
+ bundle config build.nokogiri --use-system-libraries
349
+ bundle install
350
+ EOS
351
+
352
+ message <<-"EOS" if name == 'libxml2'
353
+
354
+ Note, however, that nokogiri is not fully compatible with arbitrary
355
+ versions of libxml2 provided by OS/package vendors.
356
+ EOS
357
+
358
+ message <<-"EOS"
359
+ ************************************************************************
360
+ EOS
361
+
362
+ checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
363
+ unless File.exist?(checkpoint)
364
+ chdir_for_build do
365
+ recipe.cook
366
+ end
367
+ FileUtils.touch checkpoint
368
+ end
369
+ recipe.activate
36
370
  end
371
+ end
37
372
 
38
- header = File.join(ROOT, 'cross', 'iconv-1.9.2.win32', 'include')
39
- unless find_header('iconv.h', header)
40
- abort "need iconv"
373
+ def lib_a(ldflag)
374
+ case ldflag
375
+ when /\A-l(.+)/
376
+ "lib#{$1}.#{$LIBEXT}"
41
377
  end
378
+ end
379
+
380
+ def using_system_libraries?
381
+ arg_config('--use-system-libraries', !!ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'])
382
+ end
383
+
384
+ #
385
+ # monkey patches
386
+ #
387
+
388
+ # Workaround for Ruby bug #8074, introduced in Ruby 2.0.0, fixed in Ruby 2.1.0
389
+ # https://bugs.ruby-lang.org/issues/8074
390
+ @libdir_basename = "lib" if RUBY_VERSION < '2.1.0'
391
+
392
+ #
393
+ # main
394
+ #
395
+
396
+ case
397
+ when arg_config('--help')
398
+ do_help
399
+ when arg_config('--clean')
400
+ do_clean
401
+ end
402
+
403
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
404
+ # use same c compiler for libxml and libxslt
405
+ ENV['CC'] = RbConfig::MAKEFILE_CONFIG['CC']
406
+
407
+ # TODO: deprecate MacRuby: https://github.com/sparklemotion/nokogiri/issues/1474
408
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
409
+ $LIBRUBYARG_STATIC.gsub!(/-static/, '')
410
+ end
411
+
412
+ $LIBS << " #{ENV["LIBS"]}"
413
+
414
+ # Read CFLAGS from ENV and make sure compiling works.
415
+ add_cflags(ENV["CFLAGS"])
416
+
417
+ if windows?
418
+ $CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
419
+ end
420
+
421
+ if solaris?
422
+ $CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
423
+ end
424
+
425
+ if darwin?
426
+ # Let Apple LLVM/clang 5.1 ignore unknown compiler flags
427
+ add_cflags("-Wno-error=unused-command-line-argument-hard-error-in-future")
428
+ end
429
+
430
+ if nix?
431
+ $CFLAGS << " -g -DXP_UNIX"
432
+ end
433
+
434
+ if RUBY_PLATFORM =~ /mingw/i
435
+ # Work around a character escaping bug in MSYS by passing an arbitrary
436
+ # double quoted parameter to gcc. See https://sourceforge.net/p/mingw/bugs/2142
437
+ $CPPFLAGS << ' "-Idummypath"'
438
+ end
439
+
440
+ if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
441
+ $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
442
+ $CFLAGS << " -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
443
+ end
444
+
445
+ case
446
+ when using_system_libraries?
447
+ message "Building nokogiri using system libraries.\n"
448
+
449
+ dir_config('zlib')
450
+
451
+ # Using system libraries means we rely on the system libxml2 with
452
+ # regard to the iconv support.
453
+
454
+ dir_config('xml2').any? or package_config('libxml-2.0')
455
+ dir_config('xslt').any? or package_config('libxslt')
456
+ dir_config('exslt').any? or package_config('libexslt')
457
+
458
+ check_libxml_version or abort "ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed."
459
+ check_libxml_version("2.6.21") or abort "ERROR: libxml2 version 2.6.21 or later is required!"
460
+ check_libxml_version("2.9.3") or warn "WARNING: libxml2 version 2.9.3 or later is highly recommended, but proceeding anyway."
461
+
42
462
  else
43
- unless find_header('libxml/xmlversion.h', '/usr/include/libxml2')
44
- abort "need libxml"
463
+ message "Building nokogiri using packaged libraries.\n"
464
+
465
+ # The gem version constraint in the Rakefile is not respected at install time.
466
+ # Keep this version in sync with the one in the Rakefile !
467
+ require 'rubygems'
468
+ gem 'mini_portile2', '~> 2.1.0'
469
+ require 'mini_portile2'
470
+ message "Using mini_portile version #{MiniPortile::VERSION}\n"
471
+
472
+ require 'yaml'
473
+
474
+ static_p = enable_config('static', true) or
475
+ message "Static linking is disabled.\n"
476
+
477
+ dir_config('zlib')
478
+
479
+ dependencies = YAML.load_file(File.join(ROOT, "dependencies.yml"))
480
+
481
+ cross_build_p = enable_config("cross-build")
482
+ if cross_build_p || windows?
483
+ zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
484
+ recipe.files = [{
485
+ url: "http://zlib.net/#{recipe.name}-#{recipe.version}.tar.gz",
486
+ md5: dependencies["zlib"]["md5"]
487
+ }]
488
+ class << recipe
489
+ attr_accessor :cross_build_p
490
+
491
+ def configure
492
+ Dir.chdir work_path do
493
+ mk = File.read 'win32/Makefile.gcc'
494
+ File.open 'win32/Makefile.gcc', 'wb' do |f|
495
+ f.puts "BINARY_PATH = #{path}/bin"
496
+ f.puts "LIBRARY_PATH = #{path}/lib"
497
+ f.puts "INCLUDE_PATH = #{path}/include"
498
+ mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
499
+ f.puts mk
500
+ end
501
+ end
502
+ end
503
+
504
+ def configured?
505
+ Dir.chdir work_path do
506
+ !! (File.read('win32/Makefile.gcc') =~ /^BINARY_PATH/)
507
+ end
508
+ end
509
+
510
+ def compile
511
+ execute "compile", "make -f win32/Makefile.gcc"
512
+ end
513
+
514
+ def install
515
+ execute "install", "make -f win32/Makefile.gcc install"
516
+ end
517
+ end
518
+ recipe.cross_build_p = cross_build_p
519
+ end
520
+
521
+ libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p, cross_build_p) do |recipe|
522
+ recipe.files = [{
523
+ url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
524
+ md5: dependencies["libiconv"]["md5"]
525
+ }]
526
+ recipe.configure_options += [
527
+ "CPPFLAGS=-Wall",
528
+ "CFLAGS=-O2 -g",
529
+ "CXXFLAGS=-O2 -g",
530
+ "LDFLAGS="
531
+ ]
532
+ end
533
+ else
534
+ if darwin? && !have_header('iconv.h')
535
+ abort <<'EOM'.chomp
536
+ -----
537
+ The file "iconv.h" is missing in your build environment,
538
+ which means you haven't installed Xcode Command Line Tools properly.
539
+
540
+ To install Command Line Tools, try running `xcode-select --install` on
541
+ terminal and follow the instructions. If it fails, open Xcode.app,
542
+ select from the menu "Xcode" - "Open Developer Tool" - "More Developer
543
+ Tools" to open the developer site, download the installer for your OS
544
+ version and run it.
545
+ -----
546
+ EOM
547
+ end
548
+ end
549
+
550
+ unless windows?
551
+ preserving_globals {
552
+ have_library('z', 'gzdopen', 'zlib.h')
553
+ } or abort 'zlib is missing; necessary for building libxml2'
554
+ end
555
+
556
+ libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
557
+ recipe.files = [{
558
+ url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
559
+ md5: dependencies["libxml2"]["md5"]
560
+ }]
561
+ recipe.configure_options += [
562
+ "--without-python",
563
+ "--without-readline",
564
+ *(zlib_recipe ? ["--with-zlib=#{zlib_recipe.path}", "CFLAGS=-I#{zlib_recipe.path}/include"] : []),
565
+ *(libiconv_recipe ? "--with-iconv=#{libiconv_recipe.path}" : iconv_configure_flags),
566
+ "--with-c14n",
567
+ "--with-debug",
568
+ "--with-threads"
569
+ ]
570
+ end
571
+
572
+ libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"]["version"], static_p, cross_build_p) do |recipe|
573
+ recipe.files = [{
574
+ url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
575
+ md5: dependencies["libxslt"]["md5"]
576
+ }]
577
+ recipe.configure_options += [
578
+ "--without-python",
579
+ "--without-crypto",
580
+ "--with-debug",
581
+ "--with-libxml-prefix=#{sh_export_path(libxml2_recipe.path)}"
582
+ ]
45
583
  end
46
- unless find_header('libxslt/xslt.h', '/usr/include')
47
- abort "need libxslt"
584
+
585
+ $CFLAGS << ' ' << '-DNOKOGIRI_USE_PACKAGED_LIBRARIES'
586
+ $LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH if zlib_recipe
587
+ $LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH if libiconv_recipe
588
+
589
+ have_lzma = preserving_globals {
590
+ have_library('lzma')
591
+ }
592
+
593
+ $libs = $libs.shellsplit.tap do |libs|
594
+ [libxml2_recipe, libxslt_recipe].each do |recipe|
595
+ libname = recipe.name[/\Alib(.+)\z/, 1]
596
+ File.join(recipe.path, "bin", "#{libname}-config").tap do |config|
597
+ # call config scripts explicit with 'sh' for compat with Windows
598
+ $CPPFLAGS = `sh #{config} --cflags`.strip << ' ' << $CPPFLAGS
599
+ `sh #{config} --libs`.strip.shellsplit.each do |arg|
600
+ case arg
601
+ when /\A-L(.+)\z/
602
+ # Prioritize ports' directories
603
+ if $1.start_with?(ROOT + '/')
604
+ $LIBPATH = [$1] | $LIBPATH
605
+ else
606
+ $LIBPATH = $LIBPATH | [$1]
607
+ end
608
+ when /\A-l./
609
+ libs.unshift(arg)
610
+ else
611
+ $LDFLAGS << ' ' << arg.shellescape
612
+ end
613
+ end
614
+ end
615
+
616
+ # Defining a macro that expands to a C string; double quotes are significant.
617
+ $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATH=\"#{recipe.path}\"".inspect
618
+ $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATCHES=\"#{recipe.patch_files.map { |path| File.basename(path) }.join(' ')}\"".inspect
619
+
620
+ case libname
621
+ when 'xml2'
622
+ # xslt-config --libs or pkg-config libxslt --libs does not include
623
+ # -llzma, so we need to add it manually when linking statically.
624
+ if static_p && have_lzma
625
+ # Add it at the end; GH #988
626
+ libs << '-llzma'
627
+ end
628
+ when 'xslt'
629
+ # xslt-config does not have a flag to emit options including
630
+ # -lexslt, so add it manually.
631
+ libs.unshift('-lexslt')
632
+ end
633
+ end
634
+ end.shelljoin
635
+
636
+ if static_p
637
+ $libs = $libs.shellsplit.map do |arg|
638
+ case arg
639
+ when '-lxml2'
640
+ File.join(libxml2_recipe.path, 'lib', lib_a(arg))
641
+ when '-lxslt', '-lexslt'
642
+ File.join(libxslt_recipe.path, 'lib', lib_a(arg))
643
+ else
644
+ arg
645
+ end
646
+ end.shelljoin
48
647
  end
49
648
  end
50
649
 
51
- unless find_executable("racc")
52
- abort "need racc, get the tarball from http://i.loveruby.net/archive/racc/racc-1.4.5-all.tar.gz"
650
+ {
651
+ "xml2" => ['xmlParseDoc', 'libxml/parser.h'],
652
+ "xslt" => ['xsltParseStylesheetDoc', 'libxslt/xslt.h'],
653
+ "exslt" => ['exsltFuncRegister', 'libexslt/exslt.h'],
654
+ }.each do |lib, (func, header)|
655
+ have_func(func, header) ||
656
+ have_library(lib, func, header) ||
657
+ have_library("lib#{lib}", func, header) or
658
+ asplode("lib#{lib}")
53
659
  end
54
660
 
55
- unless find_executable("frex")
56
- abort "need frex, sudo gem install aaronp-frex -s http://gems.github.com"
661
+ have_func('xmlHasFeature') or abort "xmlHasFeature() is missing."
662
+ have_func('xmlFirstElementChild')
663
+ have_func('xmlRelaxNGSetParserStructuredErrors')
664
+ have_func('xmlRelaxNGSetParserStructuredErrors')
665
+ have_func('xmlRelaxNGSetValidStructuredErrors')
666
+ have_func('xmlSchemaSetValidStructuredErrors')
667
+ have_func('xmlSchemaSetParserStructuredErrors')
668
+
669
+ if ENV['CPUPROFILE']
670
+ unless find_library('profiler', 'ProfilerEnable', *LIB_DIRS)
671
+ abort "google performance tools are not installed"
672
+ end
673
+ end
674
+
675
+ create_makefile('nokogiri/nokogiri')
676
+
677
+ if enable_config('clean', true)
678
+ # Do not clean if run in a development work tree.
679
+ File.open('Makefile', 'at') do |mk|
680
+ mk.print <<EOF
681
+ all: clean-ports
682
+
683
+ clean-ports: $(DLLIB)
684
+ -$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? 'enable' : 'disable'}-static
685
+ EOF
686
+ end
57
687
  end
58
688
 
59
- create_makefile('nokogiri/native')
689
+ # :startdoc: