nokogiri 1.6.1-java → 1.6.2-java

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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +17 -0
  3. data/.travis.yml +6 -6
  4. data/CHANGELOG.ja.rdoc +61 -8
  5. data/CHANGELOG.rdoc +58 -3
  6. data/Gemfile +3 -3
  7. data/Manifest.txt +57 -1
  8. data/README.ja.rdoc +22 -17
  9. data/README.rdoc +23 -18
  10. data/ROADMAP.md +1 -2
  11. data/Rakefile +162 -58
  12. data/build_all +56 -31
  13. data/dependencies.yml +3 -3
  14. data/ext/java/nokogiri/NokogiriService.java +9 -5
  15. data/ext/java/nokogiri/XmlDocument.java +95 -54
  16. data/ext/java/nokogiri/XmlNode.java +93 -42
  17. data/ext/java/nokogiri/XmlReader.java +1 -1
  18. data/ext/java/nokogiri/XmlSaxParserContext.java +33 -0
  19. data/ext/java/nokogiri/XmlSchema.java +4 -2
  20. data/ext/java/nokogiri/XmlXpathContext.java +118 -76
  21. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +20 -0
  22. data/ext/java/nokogiri/internals/NokogiriHandler.java +3 -10
  23. data/ext/java/nokogiri/internals/NokogiriHelpers.java +40 -23
  24. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +59 -54
  25. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +1 -1
  26. data/ext/java/nokogiri/internals/ParserContext.java +1 -4
  27. data/ext/java/nokogiri/internals/SaveContextVisitor.java +6 -2
  28. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +119 -0
  29. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +159 -0
  30. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +37 -0
  31. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +93 -0
  32. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +252 -0
  33. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +639 -0
  34. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +38 -0
  35. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +38 -0
  36. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +368 -0
  37. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +295 -0
  38. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +40 -0
  39. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +44 -0
  40. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +44 -0
  41. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +43 -0
  42. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +630 -0
  43. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +173 -0
  44. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +76 -0
  45. data/ext/java/nokogiri/internals/c14n/Constants.java +42 -0
  46. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +293 -0
  47. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +93 -0
  48. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +79 -0
  49. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +165 -0
  50. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +76 -0
  51. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +402 -0
  52. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +51 -0
  53. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +179 -0
  54. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +507 -0
  55. data/ext/nokogiri/extconf.rb +429 -128
  56. data/ext/nokogiri/html_document.c +2 -2
  57. data/ext/nokogiri/nokogiri.c +6 -1
  58. data/ext/nokogiri/xml_document.c +5 -4
  59. data/ext/nokogiri/xml_node.c +76 -7
  60. data/ext/nokogiri/xml_reader.c +1 -1
  61. data/ext/nokogiri/xml_sax_parser_context.c +40 -0
  62. data/ext/nokogiri/xml_syntax_error.c +10 -5
  63. data/ext/nokogiri/xml_syntax_error.h +1 -1
  64. data/ext/nokogiri/xml_xpath_context.c +2 -14
  65. data/ext/nokogiri/xslt_stylesheet.c +1 -1
  66. data/lib/nokogiri.rb +31 -22
  67. data/lib/nokogiri/css/node.rb +0 -50
  68. data/lib/nokogiri/css/parser.rb +213 -218
  69. data/lib/nokogiri/css/parser.y +21 -30
  70. data/lib/nokogiri/css/xpath_visitor.rb +62 -14
  71. data/lib/nokogiri/html/document.rb +97 -18
  72. data/lib/nokogiri/html/sax/parser.rb +2 -2
  73. data/lib/nokogiri/nokogiri.jar +0 -0
  74. data/lib/nokogiri/version.rb +1 -1
  75. data/lib/nokogiri/xml/builder.rb +1 -1
  76. data/lib/nokogiri/xml/document.rb +2 -2
  77. data/lib/nokogiri/xml/dtd.rb +10 -0
  78. data/lib/nokogiri/xml/node.rb +26 -1
  79. data/lib/nokogiri/xml/sax/parser.rb +1 -1
  80. data/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch +265 -0
  81. data/ports/patches/libxml2/0002-Fix-entities-local-buffers-size-problems.patch +102 -0
  82. data/ports/patches/libxml2/0003-Fix-an-error-in-previous-commit.patch +26 -0
  83. data/ports/patches/libxml2/0004-Fix-potential-out-of-bound-access.patch +26 -0
  84. data/ports/patches/libxml2/0005-Detect-excessive-entities-expansion-upon-replacement.patch +158 -0
  85. data/ports/patches/libxml2/0006-Do-not-fetch-external-parsed-entities.patch +78 -0
  86. data/ports/patches/libxml2/0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch +480 -0
  87. data/ports/patches/libxml2/0008-Improve-handling-of-xmlStopParser.patch +315 -0
  88. data/ports/patches/libxml2/0009-Fix-a-couple-of-return-without-value.patch +37 -0
  89. data/ports/patches/libxslt/0001-Adding-doc-update-related-to-1.1.28.patch +222 -0
  90. data/ports/patches/libxslt/0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch +53 -0
  91. data/ports/patches/libxslt/0003-Initialize-pseudo-random-number-generator-with-curre.patch +60 -0
  92. data/ports/patches/libxslt/0004-EXSLT-function-str-replace-is-broken-as-is.patch +42 -0
  93. data/ports/patches/libxslt/0006-Fix-str-padding-to-work-with-UTF-8-strings.patch +164 -0
  94. data/ports/patches/libxslt/0007-Separate-function-for-predicate-matching-in-patterns.patch +587 -0
  95. data/ports/patches/libxslt/0008-Fix-direct-pattern-matching.patch +80 -0
  96. data/ports/patches/libxslt/0009-Fix-certain-patterns-with-predicates.patch +185 -0
  97. data/ports/patches/libxslt/0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch +126 -0
  98. data/ports/patches/libxslt/0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch +25 -0
  99. data/ports/patches/libxslt/0014-Fix-for-bug-436589.patch +43 -0
  100. data/ports/patches/libxslt/0015-Fix-mkdir-for-mingw.patch +41 -0
  101. data/suppressions/README.txt +1 -0
  102. data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
  103. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  104. data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
  105. data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
  106. data/test/css/test_nthiness.rb +65 -2
  107. data/test/css/test_parser.rb +27 -10
  108. data/test/css/test_tokenizer.rb +1 -1
  109. data/test/css/test_xpath_visitor.rb +6 -1
  110. data/test/files/atom.xml +344 -0
  111. data/test/files/shift_jis_no_charset.html +9 -0
  112. data/test/helper.rb +10 -0
  113. data/test/html/test_document.rb +74 -7
  114. data/test/html/test_document_encoding.rb +10 -0
  115. data/test/html/test_document_fragment.rb +9 -3
  116. data/test/namespaces/test_namespaces_aliased_default.rb +24 -0
  117. data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
  118. data/test/namespaces/test_namespaces_preservation.rb +31 -0
  119. data/test/test_nokogiri.rb +6 -0
  120. data/test/test_reader.rb +7 -4
  121. data/test/test_xslt_transforms.rb +25 -0
  122. data/test/xml/sax/test_parser.rb +16 -0
  123. data/test/xml/sax/test_parser_context.rb +9 -0
  124. data/test/xml/test_builder.rb +9 -0
  125. data/test/xml/test_c14n.rb +12 -2
  126. data/test/xml/test_document.rb +66 -0
  127. data/test/xml/test_document_fragment.rb +5 -0
  128. data/test/xml/test_dtd.rb +84 -0
  129. data/test/xml/test_entity_reference.rb +3 -3
  130. data/test/xml/test_node.rb +21 -3
  131. data/test/xml/test_node_attributes.rb +17 -0
  132. data/test/xml/test_schema.rb +26 -0
  133. data/test/xml/test_text.rb +15 -0
  134. data/test/xml/test_xpath.rb +87 -0
  135. data/test_all +3 -3
  136. metadata +119 -68
  137. data/tasks/cross_compile.rb +0 -134
@@ -1,183 +1,472 @@
1
- ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
2
-
3
1
  # :stopdoc:
2
+ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
4
3
 
5
4
  require 'mkmf'
6
5
 
7
- RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
6
+ if arg_config('--help')
7
+ print <<HELP
8
+ usage: ruby #{$0} [options]
8
9
 
9
- ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
- LIBDIR = RbConfig::CONFIG['libdir']
11
- @libdir_basename = "lib" # shrug, ruby 2.0 won't work for me.
12
- INCLUDEDIR = RbConfig::CONFIG['includedir']
10
+ --disable-clean
11
+ Do not clean out intermediate files after successful build.
13
12
 
14
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
15
- $LIBRUBYARG_STATIC.gsub!(/-static/, '')
16
- end
13
+ --disable-static
14
+ Do not statically link bundled libraries.
17
15
 
18
- $CFLAGS << " #{ENV["CFLAGS"]}"
19
- $LIBS << " #{ENV["LIBS"]}"
16
+ --with-iconv-dir=DIR
17
+ Use the iconv library placed under DIR.
20
18
 
21
- windows_p = RbConfig::CONFIG['target_os'] == 'mingw32' || RbConfig::CONFIG['target_os'] =~ /mswin/
19
+ --with-zlib-dir=DIR
20
+ Use the zlib library placed under DIR.
22
21
 
23
- if windows_p
24
- $CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
25
- elsif RbConfig::CONFIG['target_os'] =~ /solaris/
26
- $CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
27
- else
28
- $CFLAGS << " -g -DXP_UNIX"
29
- end
22
+ --use-system-libraries
23
+ Use system libraries intead of building and using the bundled
24
+ libraries.
25
+
26
+ --with-xml2-dir=DIR / --with-xml2-config=CONFIG
27
+ --with-xslt-dir=DIR / --with-xslt-config=CONFIG
28
+ --with-exslt-dir=DIR / --with-exslt-config=CONFIG
29
+ Use libxml2/libxslt/libexslt as specified.
30
30
 
31
- if RbConfig::MAKEFILE_CONFIG['CC'] =~ /mingw/
32
- $CFLAGS << " -DIN_LIBXML"
33
- $LIBS << " -lz" # TODO why is this necessary?
31
+ --enable-cross-build
32
+ Do cross-build.
33
+ HELP
34
+ exit! 0
34
35
  end
35
36
 
36
- if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
37
- $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
38
- $CFLAGS << " -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
37
+ def message!(important_message)
38
+ message important_message
39
+ if !$stdout.tty? && File.chardev?('/dev/tty')
40
+ File.open('/dev/tty', 'w') { |tty|
41
+ tty.print important_message
42
+ }
43
+ end
44
+ rescue Errno::ENXIO
39
45
  end
40
46
 
41
- if windows_p
42
- # I'm cross compiling!
43
- HEADER_DIRS = [INCLUDEDIR]
44
- LIB_DIRS = [LIBDIR]
45
- XML2_HEADER_DIRS = [File.join(INCLUDEDIR, "libxml2"), INCLUDEDIR]
47
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
46
48
 
47
- else
48
- if ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES']
49
- HEADER_DIRS = [
50
- # First search /opt/local for macports
51
- '/opt/local/include',
49
+ ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
50
+ # Workaround for Ruby bug #8074, introduced in Ruby 2.0.0, fixed in Ruby 2.1.0
51
+ # https://bugs.ruby-lang.org/issues/8074
52
+ @libdir_basename = "lib" if RUBY_VERSION < '2.1.0'
53
+
54
+ # Workaround for Ruby bug #9760, will be fixed in Ruby 2.2
55
+ class Array
56
+ alias orig_or |
57
+
58
+ def | other
59
+ if self.equal?($DEFLIBPATH) && other.equal?($LIBPATH)
60
+ # Make sure library directories we set take precedence over $(libdir)
61
+ other.orig_or(self)
62
+ else
63
+ self.orig_or(other)
64
+ end
65
+ end
66
+ end if RUBY_VERSION < '2.2.0'
52
67
 
53
- # Then search /usr/local for people that installed from source
54
- '/usr/local/include',
68
+ if arg_config('--clean')
69
+ require 'pathname'
70
+ require 'fileutils'
55
71
 
56
- # Check the ruby install locations
57
- INCLUDEDIR,
72
+ root = Pathname(ROOT)
73
+ pwd = Pathname(Dir.pwd)
58
74
 
59
- # Finally fall back to /usr
60
- '/usr/include',
61
- '/usr/include/libxml2',
62
- ]
75
+ # Skip if this is a development work tree
76
+ unless (root + '.git').exist?
77
+ message "Cleaning files only used during build.\n"
63
78
 
64
- LIB_DIRS = [
65
- # First search /opt/local for macports
66
- '/opt/local/lib',
79
+ # (root + 'tmp') cannot be removed at this stage because
80
+ # nokogiri.so is yet to be copied to lib.
67
81
 
68
- # Then search /usr/local for people that installed from source
69
- '/usr/local/lib',
82
+ # clean the ports build directory
83
+ Pathname.glob(pwd.join('tmp', '*', 'ports')) { |dir|
84
+ FileUtils.rm_rf(dir, verbose: true)
85
+ FileUtils.rmdir(dir.parent, parents: true, verbose: true)
86
+ }
70
87
 
71
- # Check the ruby install locations
72
- LIBDIR,
88
+ if enable_config('static')
89
+ # ports installation can be safely removed if statically linked.
90
+ FileUtils.rm_rf(root + 'ports', verbose: true)
91
+ else
92
+ FileUtils.rm_rf(root + 'ports' + 'archives', verbose: true)
93
+ end
94
+ end
73
95
 
74
- # Finally fall back to /usr
75
- '/usr/lib',
76
- ]
96
+ exit
97
+ end
77
98
 
78
- XML2_HEADER_DIRS = [
79
- '/opt/local/include/libxml2',
80
- '/usr/local/include/libxml2',
81
- File.join(INCLUDEDIR, "libxml2")
82
- ] + HEADER_DIRS
83
-
84
- # If the user has homebrew installed, use the libxml2 inside homebrew
85
- brew_prefix = `brew --prefix libxml2 2> /dev/null`.chomp
86
- unless brew_prefix.empty?
87
- LIB_DIRS.unshift File.join(brew_prefix, 'lib')
88
- XML2_HEADER_DIRS.unshift File.join(brew_prefix, 'include/libxml2')
89
- end
99
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
100
+ $LIBRUBYARG_STATIC.gsub!(/-static/, '')
101
+ end
90
102
 
91
- else
92
- require 'mini_portile'
93
- require 'yaml'
103
+ $CFLAGS << " #{ENV["CFLAGS"]}"
104
+ $LIBS << " #{ENV["LIBS"]}"
94
105
 
95
- common_recipe = lambda do |recipe|
96
- recipe.target = File.join(ROOT, "ports")
97
- recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
106
+ def preserving_globals
107
+ values = [
108
+ $arg_config,
109
+ $CFLAGS, $CPPFLAGS,
110
+ $LDFLAGS, $LIBPATH, $libs
111
+ ].map(&:dup)
112
+ yield
113
+ ensure
114
+ $arg_config,
115
+ $CFLAGS, $CPPFLAGS,
116
+ $LDFLAGS, $LIBPATH, $libs =
117
+ values
118
+ end
98
119
 
99
- checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
100
- unless File.exist?(checkpoint)
101
- recipe.cook
102
- FileUtils.touch checkpoint
103
- end
104
- recipe.activate
105
- end
120
+ def asplode(lib)
121
+ abort "-----\n#{lib} is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.\n-----"
122
+ end
106
123
 
107
- dependencies = YAML.load_file(File.join(ROOT, "dependencies.yml"))
124
+ def have_iconv?
125
+ have_header('iconv.h') or return false
126
+ %w{ iconv_open libiconv_open }.any? do |method|
127
+ have_func(method, 'iconv.h') or
128
+ have_library('iconv', method, 'iconv.h')
129
+ end
130
+ end
131
+
132
+ def each_iconv_idir
133
+ # If --with-iconv-dir or --with-opt-dir is given, it should be
134
+ # the first priority
135
+ %w[iconv opt].each { |config|
136
+ idir = preserving_globals {
137
+ dir_config(config)
138
+ }.first and yield idir
139
+ }
140
+
141
+ # Try the system default
142
+ yield "/usr/include"
143
+
144
+ cflags, = preserving_globals {
145
+ pkg_config('libiconv')
146
+ }
147
+ if cflags
148
+ cflags.shellsplit.each { |arg|
149
+ arg.sub!(/\A-I/, '') and
150
+ yield arg
151
+ }
152
+ end
108
153
 
109
- libxml2_recipe = MiniPortile.new("libxml2", dependencies["libxml2"]).tap do |recipe|
154
+ nil
155
+ end
156
+
157
+ def iconv_prefix
158
+ # Make sure libxml2 is built with iconv
159
+ each_iconv_idir { |idir|
160
+ next unless File.file?(File.join(idir, 'iconv.h'))
161
+
162
+ prefix, dir = File.split(idir)
163
+ next unless dir == 'include'
164
+
165
+ preserving_globals {
166
+ # Follow the way libxml2's configure uses a value given with
167
+ # --with-iconv[=DIR]
168
+ $CPPFLAGS = "-I#{idir}".quote << ' ' << $CPPFLAGS
169
+ $LIBPATH.unshift(File.join(prefix, "lib"))
170
+ have_iconv?
171
+ } and break prefix
172
+ } or asplode "libiconv"
173
+ end
174
+
175
+ def process_recipe(name, version, static_p, cross_p)
176
+ MiniPortile.new(name, version).tap do |recipe|
177
+ recipe.target = portsdir = File.join(ROOT, "ports")
178
+ # Prefer host_alias over host in order to use i586-mingw32msvc as
179
+ # correct compiler prefix for cross build, but use host if not set.
180
+ recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
181
+ recipe.patch_files = Dir[File.join(portsdir, "patches", name, "*.patch")].sort
182
+
183
+ if static_p
184
+ recipe.configure_options = [
185
+ "--disable-shared",
186
+ "--enable-static",
187
+ "CFLAGS='-fPIC #{ENV["CFLAGS"]}'",
188
+ ]
189
+ else
110
190
  recipe.configure_options = [
111
191
  "--enable-shared",
112
192
  "--disable-static",
113
- "--without-python",
114
- "--without-readline",
115
- "--with-c14n",
116
- "--with-debug",
117
- "--with-threads"
118
193
  ]
119
- common_recipe.call recipe
120
194
  end
121
195
 
122
- libxslt_recipe = MiniPortile.new("libxslt", dependencies["libxslt"]).tap do |recipe|
123
- recipe.configure_options = [
124
- "--enable-shared",
125
- "--disable-static",
126
- "--without-python",
127
- "--without-crypto",
128
- "--with-debug",
129
- "--with-libxml-prefix=#{libxml2_recipe.path}"
196
+ if cross_p
197
+ recipe.configure_options += [
198
+ "--target=#{recipe.host}",
199
+ "--host=#{recipe.host}",
130
200
  ]
131
- common_recipe.call recipe
132
201
  end
133
202
 
134
- $LDFLAGS << " -Wl,-rpath,#{libxml2_recipe.path}/lib"
135
- $LDFLAGS << " -Wl,-rpath,#{libxslt_recipe.path}/lib"
203
+ yield recipe
204
+
205
+ if recipe.patch_files.empty?
206
+ message! "Building #{name}-#{version} for nokogiri.\n"
207
+ else
208
+ message! "Building #{name}-#{version} for nokogiri with the following patches applied:\n"
209
+
210
+ recipe.patch_files.each { |patch|
211
+ message! "\t- %s\n" % File.basename(patch)
212
+ }
213
+ end
214
+
215
+ message! <<-"EOS"
216
+ ************************************************************************
217
+ IMPORTANT! Nokogiri builds and uses a packaged version of #{name}.
218
+
219
+ If this is a concern for you and you want to use the system library
220
+ instead, abort this installation process and reinstall nokogiri as
221
+ follows:
222
+
223
+ gem install nokogiri -- --use-system-libraries
224
+
225
+ If you are using Bundler, tell it to use the option:
226
+
227
+ bundle config build.nokogiri --use-system-libraries
228
+ bundle install
229
+ EOS
230
+
231
+ message! <<-"EOS" if name == 'libxml2'
232
+
233
+ However, note that nokogiri does not necessarily support all versions
234
+ of libxml2.
136
235
 
137
- $CFLAGS << " -DNOKOGIRI_USE_PACKAGED_LIBRARIES -DNOKOGIRI_LIBXML2_PATH='\"#{libxml2_recipe.path}\"' -DNOKOGIRI_LIBXSLT_PATH='\"#{libxslt_recipe.path}\"'"
236
+ For example, libxml2-2.9.0 and higher are currently known to be broken
237
+ and thus unsupported by nokogiri, due to compatibility problems and
238
+ XPath optimization bugs.
239
+ EOS
138
240
 
139
- HEADER_DIRS = [libxml2_recipe, libxslt_recipe].map { |f| File.join(f.path, "include") }
140
- LIB_DIRS = [libxml2_recipe, libxslt_recipe].map { |f| File.join(f.path, "lib") }
141
- XML2_HEADER_DIRS = HEADER_DIRS + [File.join(libxml2_recipe.path, "include", "libxml2")]
241
+ message! <<-"EOS"
242
+ ************************************************************************
243
+ EOS
244
+
245
+ checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
246
+ unless File.exist?(checkpoint)
247
+ recipe.cook
248
+ FileUtils.touch checkpoint
249
+ end
250
+ recipe.activate
142
251
  end
143
252
  end
144
253
 
145
- dir_config('zlib', HEADER_DIRS, LIB_DIRS)
146
- dir_config('iconv', HEADER_DIRS, LIB_DIRS)
147
- dir_config('xml2', XML2_HEADER_DIRS, LIB_DIRS)
148
- dir_config('xslt', HEADER_DIRS, LIB_DIRS)
254
+ case RbConfig::CONFIG['target_os']
255
+ when 'mingw32', /mswin/
256
+ windows_p = true
257
+ $CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
258
+ when /solaris/
259
+ $CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
260
+ else
261
+ $CFLAGS << " -g -DXP_UNIX"
262
+ end
149
263
 
150
- def asplode(lib)
151
- abort "-----\n#{lib} is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.\n-----"
264
+ if RUBY_PLATFORM =~ /mingw/i
265
+ # Work around a character escaping bug in MSYS by passing an arbitrary
266
+ # double quoted parameter to gcc. See https://sourceforge.net/p/mingw/bugs/2142
267
+ $CPPFLAGS << ' "-Idummypath"'
268
+ end
269
+
270
+ if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
271
+ $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
272
+ $CFLAGS << " -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline"
152
273
  end
153
274
 
154
- pkg_config('libxslt')
155
- pkg_config('libxml-2.0')
156
- pkg_config('libiconv')
275
+ case
276
+ when arg_config('--use-system-libraries', !!ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'])
277
+ message! "Building nokogiri using system libraries.\n"
157
278
 
158
- def have_iconv?
159
- %w{ iconv_open libiconv_open }.any? do |method|
160
- have_func(method, 'iconv.h') or
161
- have_library('iconv', method, 'iconv.h') or
162
- find_library('iconv', method, 'iconv.h')
279
+ dir_config('zlib')
280
+
281
+ # Using system libraries means we rely on the system libxml2 with
282
+ # regard to the iconv support.
283
+
284
+ dir_config('xml2').any? or pkg_config('libxml-2.0')
285
+ dir_config('xslt').any? or pkg_config('libxslt')
286
+ dir_config('exslt').any? or pkg_config('libexslt')
287
+
288
+ try_cpp(<<-SRC) or abort "libxml2 version 2.6.21 or later is required!"
289
+ #include <libxml/xmlversion.h>
290
+
291
+ #if LIBXML_VERSION < 20621
292
+ #error libxml2 is too old
293
+ #endif
294
+ SRC
295
+
296
+ try_cpp(<<-SRC) or warn "libxml2 version 2.9.0 and later is not yet supported, but proceeding anyway."
297
+ #include <libxml/xmlversion.h>
298
+
299
+ #if LIBXML_VERSION >= 20900
300
+ #error libxml2 is too new
301
+ #endif
302
+ SRC
303
+ else
304
+ message! "Building nokogiri using packaged libraries.\n"
305
+
306
+ require 'mini_portile'
307
+ require 'yaml'
308
+
309
+ static_p = enable_config('static', true) or
310
+ message! "Static linking is disabled.\n"
311
+
312
+ dir_config('zlib')
313
+
314
+ dependencies = YAML.load_file(File.join(ROOT, "dependencies.yml"))
315
+
316
+ cross_build_p = enable_config("cross-build")
317
+ if cross_build_p || windows_p
318
+ zlib_recipe = process_recipe("zlib", dependencies["zlib"], static_p, cross_build_p) do |recipe|
319
+ recipe.files = ["http://zlib.net/#{recipe.name}-#{recipe.version}.tar.gz"]
320
+ class << recipe
321
+ attr_accessor :cross_build_p
322
+
323
+ def configure
324
+ Dir.chdir work_path do
325
+ mk = File.read 'win32/Makefile.gcc'
326
+ File.open 'win32/Makefile.gcc', 'wb' do |f|
327
+ f.puts "BINARY_PATH = #{path}/bin"
328
+ f.puts "LIBRARY_PATH = #{path}/lib"
329
+ f.puts "INCLUDE_PATH = #{path}/include"
330
+ mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
331
+ f.puts mk
332
+ end
333
+ end
334
+ end
335
+
336
+ def configured?
337
+ Dir.chdir work_path do
338
+ !! (File.read('win32/Makefile.gcc') =~ /^BINARY_PATH/)
339
+ end
340
+ end
341
+
342
+ def compile
343
+ execute "compile", "make -f win32/Makefile.gcc"
344
+ end
345
+
346
+ def install
347
+ execute "install", "make -f win32/Makefile.gcc install"
348
+ end
349
+ end
350
+ recipe.cross_build_p = cross_build_p
351
+ end
352
+
353
+ libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"], static_p, cross_build_p) do |recipe|
354
+ recipe.files = ["http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz"]
355
+ recipe.configure_options += [
356
+ "CPPFLAGS='-Wall'",
357
+ "CFLAGS='-O2 -g'",
358
+ "CXXFLAGS='-O2 -g'",
359
+ "LDFLAGS="
360
+ ]
361
+ end
163
362
  end
164
- end
165
363
 
166
- asplode "libxml2" unless find_header('libxml/parser.h')
167
- asplode "libxslt" unless find_header('libxslt/xslt.h')
168
- asplode "libexslt" unless find_header('libexslt/exslt.h')
169
- asplode "libiconv" unless have_iconv?
170
- asplode "libxml2" unless find_library("xml2", 'xmlParseDoc')
171
- asplode "libxslt" unless find_library("xslt", 'xsltParseStylesheetDoc')
172
- asplode "libexslt" unless find_library("exslt", 'exsltFuncRegister')
364
+ libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"], static_p, cross_build_p) do |recipe|
365
+ recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
366
+ recipe.configure_options += [
367
+ "--without-python",
368
+ "--without-readline",
369
+ "--with-iconv=#{libiconv_recipe ? libiconv_recipe.path : iconv_prefix}",
370
+ "--with-c14n",
371
+ "--with-debug",
372
+ "--with-threads"
373
+ ]
374
+ end
173
375
 
174
- unless have_func('xmlHasFeature')
175
- abort "-----\nThe function 'xmlHasFeature' is missing from your installation of libxml2. Likely this means that your installed version of libxml2 is old enough that nokogiri will not work well. To get around this problem, please upgrade your installation of libxml2.
376
+ libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"], static_p, cross_build_p) do |recipe|
377
+ recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
378
+ recipe.configure_options += [
379
+ "--without-python",
380
+ "--without-crypto",
381
+ "--with-debug",
382
+ "--with-libxml-prefix=#{libxml2_recipe.path}"
383
+ ]
384
+ end
176
385
 
177
- Please visit http://nokogiri.org/tutorials/installing_nokogiri.html for more help!"
386
+ $CFLAGS << ' ' << '-DNOKOGIRI_USE_PACKAGED_LIBRARIES'
387
+ $LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH if zlib_recipe
388
+ $LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH if libiconv_recipe
389
+
390
+ have_lzma = preserving_globals {
391
+ have_library('lzma')
392
+ }
393
+
394
+ $libs = $libs.shellsplit.tap { |libs|
395
+ [libxml2_recipe, libxslt_recipe].each { |recipe|
396
+ libname = recipe.name[/\Alib(.+)\z/, 1]
397
+ File.join(recipe.path, "bin", "#{libname}-config").tap { |config|
398
+ # call config scripts explicit with 'sh' for compat with Windows
399
+ $CPPFLAGS = `sh #{config} --cflags`.strip << ' ' << $CPPFLAGS
400
+ `sh #{config} --libs`.strip.shellsplit.each { |arg|
401
+ case arg
402
+ when /\A-L(.+)\z/
403
+ # Prioritize ports' directories
404
+ if $1.start_with?(ROOT + '/')
405
+ $LIBPATH = [$1] | $LIBPATH
406
+ else
407
+ $LIBPATH = $LIBPATH | [$1]
408
+ end
409
+ when /\A-l./
410
+ libs.unshift(arg)
411
+ else
412
+ $LDFLAGS << ' ' << arg.shellescape
413
+ end
414
+ }
415
+ }
416
+
417
+ $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATH=\"#{recipe.path}\"".shellescape
418
+
419
+ case libname
420
+ when 'xml2'
421
+ # xslt-config --libs or pkg-config libxslt --libs does not include
422
+ # -llzma, so we need to add it manually when linking statically.
423
+ if static_p && have_lzma
424
+ # Add it at the end; GH #988
425
+ libs << '-llzma'
426
+ end
427
+ when 'xslt'
428
+ # xslt-config does not have a flag to emit options including
429
+ # -lexslt, so add it manually.
430
+ libs.unshift('-lexslt')
431
+ end
432
+ }
433
+ }.shelljoin
434
+
435
+ if static_p
436
+ message 'checking for linker flags for static linking... '
437
+
438
+ case
439
+ when try_link('int main(void) { return 0; }',
440
+ ['-Wl,-Bstatic', '-lxml2', '-Wl,-Bdynamic'].shelljoin)
441
+ message "-Wl,-Bstatic\n"
442
+
443
+ $libs = $libs.shellsplit.flat_map { |arg|
444
+ case arg
445
+ when '-lxml2', '-lxslt', '-lexslt'
446
+ ['-Wl,-Bstatic', arg, '-Wl,-Bdynamic']
447
+ else
448
+ arg
449
+ end
450
+ }.shelljoin
451
+ else
452
+ message "NONE\n"
453
+ end
454
+ end
178
455
  end
179
456
 
180
- have_func 'xmlFirstElementChild'
457
+ {
458
+ "xml2" => ['xmlParseDoc', 'libxml/parser.h'],
459
+ "xslt" => ['xsltParseStylesheetDoc', 'libxslt/xslt.h'],
460
+ "exslt" => ['exsltFuncRegister', 'libexslt/exslt.h'],
461
+ }.each { |lib, (func, header)|
462
+ have_func(func, header) ||
463
+ have_library(lib, func, header) ||
464
+ have_library("lib#{lib}", func, header) or
465
+ asplode("lib#{lib}")
466
+ }
467
+
468
+ have_func('xmlHasFeature') or abort "xmlHasFeature() is missing."
469
+ have_func('xmlFirstElementChild')
181
470
  have_func('xmlRelaxNGSetParserStructuredErrors')
182
471
  have_func('xmlRelaxNGSetParserStructuredErrors')
183
472
  have_func('xmlRelaxNGSetValidStructuredErrors')
@@ -192,4 +481,16 @@ end
192
481
 
193
482
  create_makefile('nokogiri/nokogiri')
194
483
 
484
+ if enable_config('clean', true)
485
+ # Do not clean if run in a development work tree.
486
+ File.open('Makefile', 'at') { |mk|
487
+ mk.print <<EOF
488
+ all: clean-ports
489
+
490
+ clean-ports: $(DLLIB)
491
+ -$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? 'enable' : 'disable'}-static
492
+ EOF
493
+ }
494
+ end
495
+
195
496
  # :startdoc: