nokogiri 1.11.1 → 1.11.2

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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +20 -15
  5. data/ext/nokogiri/depend +34 -474
  6. data/ext/nokogiri/extconf.rb +253 -183
  7. data/ext/nokogiri/html_document.c +10 -15
  8. data/ext/nokogiri/html_element_description.c +84 -71
  9. data/ext/nokogiri/html_entity_lookup.c +21 -16
  10. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  11. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  12. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  13. data/ext/nokogiri/nokogiri.c +171 -63
  14. data/ext/nokogiri/nokogiri.h +158 -75
  15. data/ext/nokogiri/test_global_handlers.c +3 -4
  16. data/ext/nokogiri/xml_attr.c +15 -15
  17. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  18. data/ext/nokogiri/xml_cdata.c +13 -18
  19. data/ext/nokogiri/xml_comment.c +19 -26
  20. data/ext/nokogiri/xml_document.c +221 -164
  21. data/ext/nokogiri/xml_document_fragment.c +13 -15
  22. data/ext/nokogiri/xml_dtd.c +54 -48
  23. data/ext/nokogiri/xml_element_content.c +30 -27
  24. data/ext/nokogiri/xml_element_decl.c +22 -22
  25. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  26. data/ext/nokogiri/xml_entity_decl.c +32 -30
  27. data/ext/nokogiri/xml_entity_reference.c +16 -18
  28. data/ext/nokogiri/xml_namespace.c +56 -49
  29. data/ext/nokogiri/xml_node.c +338 -286
  30. data/ext/nokogiri/xml_node_set.c +168 -156
  31. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  32. data/ext/nokogiri/xml_reader.c +191 -157
  33. data/ext/nokogiri/xml_relax_ng.c +29 -23
  34. data/ext/nokogiri/xml_sax_parser.c +117 -112
  35. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  36. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  37. data/ext/nokogiri/xml_schema.c +48 -42
  38. data/ext/nokogiri/xml_syntax_error.c +21 -23
  39. data/ext/nokogiri/xml_text.c +13 -17
  40. data/ext/nokogiri/xml_xpath_context.c +134 -127
  41. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  42. data/lib/nokogiri.rb +1 -22
  43. data/lib/nokogiri/css/parser.rb +1 -1
  44. data/lib/nokogiri/extension.rb +26 -0
  45. data/lib/nokogiri/html/document_fragment.rb +15 -15
  46. data/lib/nokogiri/version/constant.rb +1 -1
  47. data/lib/nokogiri/version/info.rb +31 -8
  48. data/lib/nokogiri/xml/document.rb +31 -11
  49. data/lib/nokogiri/xml/node.rb +38 -42
  50. data/lib/nokogiri/xml/reader.rb +2 -9
  51. data/lib/nokogiri/xml/xpath.rb +1 -3
  52. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  53. data/patches/libxml2/0010-parser.c-shrink-the-input-buffer-when-appropriate.patch +70 -0
  54. metadata +8 -41
  55. data/ext/nokogiri/html_document.h +0 -10
  56. data/ext/nokogiri/html_element_description.h +0 -10
  57. data/ext/nokogiri/html_entity_lookup.h +0 -8
  58. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  59. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  60. data/ext/nokogiri/xml_attr.h +0 -9
  61. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  62. data/ext/nokogiri/xml_cdata.h +0 -9
  63. data/ext/nokogiri/xml_comment.h +0 -9
  64. data/ext/nokogiri/xml_document.h +0 -23
  65. data/ext/nokogiri/xml_document_fragment.h +0 -10
  66. data/ext/nokogiri/xml_dtd.h +0 -10
  67. data/ext/nokogiri/xml_element_content.h +0 -10
  68. data/ext/nokogiri/xml_element_decl.h +0 -9
  69. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  70. data/ext/nokogiri/xml_entity_decl.h +0 -10
  71. data/ext/nokogiri/xml_entity_reference.h +0 -9
  72. data/ext/nokogiri/xml_io.c +0 -63
  73. data/ext/nokogiri/xml_io.h +0 -11
  74. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  75. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  76. data/ext/nokogiri/xml_namespace.h +0 -14
  77. data/ext/nokogiri/xml_node.h +0 -13
  78. data/ext/nokogiri/xml_node_set.h +0 -12
  79. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  80. data/ext/nokogiri/xml_reader.h +0 -10
  81. data/ext/nokogiri/xml_relax_ng.h +0 -9
  82. data/ext/nokogiri/xml_sax_parser.h +0 -39
  83. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  84. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  85. data/ext/nokogiri/xml_schema.h +0 -9
  86. data/ext/nokogiri/xml_syntax_error.h +0 -25
  87. data/ext/nokogiri/xml_text.h +0 -9
  88. data/ext/nokogiri/xml_xpath_context.h +0 -10
  89. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,4 +1,4 @@
1
- # :stopdoc:
1
+ # frozen_string_literal: true
2
2
  ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
3
3
 
4
4
  require "mkmf"
@@ -7,9 +7,7 @@ require "fileutils"
7
7
  require "shellwords"
8
8
  require "pathname"
9
9
 
10
- #
11
- # helpful constants
12
- #
10
+ # helpful constants
13
11
  PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
14
12
  REQUIRED_LIBXML_VERSION = "2.6.21"
15
13
  RECOMMENDED_LIBXML_VERSION = "2.9.3"
@@ -28,10 +26,16 @@ NOKOGIRI_HELP_MESSAGE = <<~HELP
28
26
  Flags that are always valid:
29
27
 
30
28
  --use-system-libraries
31
- Use system libraries instead of building and using the packaged libraries
29
+ --enable-system-libraries
30
+ Use system libraries instead of building and using the packaged libraries.
31
+
32
+ --disable-system-libraries
33
+ Use the packaged libraries, and ignore the system libraries. This is the default on most
34
+ platforms, and overrides `--use-system-libraries` and the environment variable
35
+ `NOKOGIRI_USE_SYSTEM_LIBRARIES`.
32
36
 
33
37
  --disable-clean
34
- Do not clean out intermediate files after successful build
38
+ Do not clean out intermediate files after successful build.
35
39
 
36
40
  --prevent-strip
37
41
  Take steps to prevent stripping the symbol table and debugging info from the shared
@@ -40,47 +44,82 @@ NOKOGIRI_HELP_MESSAGE = <<~HELP
40
44
 
41
45
  Flags only used when using system libraries:
42
46
 
43
- --with-opt-dir=DIRECTORY
44
- Look for headers and libraries in DIRECTORY
47
+ General:
48
+
49
+ --with-opt-dir=DIRECTORY
50
+ Look for headers and libraries in DIRECTORY.
51
+
52
+ --with-opt-lib=DIRECTORY
53
+ Look for libraries in DIRECTORY.
54
+
55
+ --with-opt-include=DIRECTORY
56
+ Look for headers in DIRECTORY.
57
+
58
+
59
+ Related to zlib:
60
+
61
+ --with-zlib-dir=DIRECTORY
62
+ Look for zlib headers and library in DIRECTORY.
63
+
64
+ --with-zlib-lib=DIRECTORY
65
+ Look for zlib library in DIRECTORY.
66
+
67
+ --with-zlib-include=DIRECTORY
68
+ Look for zlib headers in DIRECTORY.
69
+
70
+
71
+ Related to iconv:
72
+
73
+ --with-iconv-dir=DIRECTORY
74
+ Look for iconv headers and library in DIRECTORY.
75
+
76
+ --with-iconv-lib=DIRECTORY
77
+ Look for iconv library in DIRECTORY.
45
78
 
46
- --with-zlib-dir=DIR
47
- Look for zlib header and library in DIRECTORY
79
+ --with-iconv-include=DIRECTORY
80
+ Look for iconv headers in DIRECTORY.
48
81
 
49
- --with-iconv-dir=DIRECTORY
50
- Look for iconv header and library in DIRECTORY
51
82
 
52
- --with-xml2-dir=DIRECTORY
53
- Look for xml2 headers and library in DIRECTORY
83
+ Related to libxml2:
54
84
 
55
- --with-xml2-lib=DIRECTORY
56
- Look for xml2 library in DIRECTORY
85
+ --with-xml2-dir=DIRECTORY
86
+ Look for xml2 headers and library in DIRECTORY.
57
87
 
58
- --with-xslt-include=DIRECTORY
59
- Look for xslt headers in DIRECTORY
88
+ --with-xml2-lib=DIRECTORY
89
+ Look for xml2 library in DIRECTORY.
60
90
 
61
- --with-xslt-dir=DIRECTORY
62
- Look for xslt headers and library in DIRECTORY
91
+ --with-xml2-include=DIRECTORY
92
+ Look for xml2 headers in DIRECTORY.
63
93
 
64
- --with-xslt-lib=DIRECTORY
65
- Look for xslt library in DIRECTORY
66
94
 
67
- --with-xslt-include=DIRECTORY
68
- Look for xslt headers in DIRECTORY
95
+ Related to libxslt:
69
96
 
70
- --with-exslt-dir=DIRECTORY
71
- Look for exslt headers and library in DIRECTORY
97
+ --with-xslt-dir=DIRECTORY
98
+ Look for xslt headers and library in DIRECTORY.
72
99
 
73
- --with-exslt-lib=DIRECTORY
74
- Look for exslt library in DIRECTORY
100
+ --with-xslt-lib=DIRECTORY
101
+ Look for xslt library in DIRECTORY.
75
102
 
76
- --with-exslt-include=DIRECTORY
77
- Look for exslt headers in DIRECTORY
103
+ --with-xslt-include=DIRECTORY
104
+ Look for xslt headers in DIRECTORY.
105
+
106
+
107
+ Related to libexslt:
108
+
109
+ --with-exslt-dir=DIRECTORY
110
+ Look for exslt headers and library in DIRECTORY.
111
+
112
+ --with-exslt-lib=DIRECTORY
113
+ Look for exslt library in DIRECTORY.
114
+
115
+ --with-exslt-include=DIRECTORY
116
+ Look for exslt headers in DIRECTORY.
78
117
 
79
118
 
80
119
  Flags only used when building and using the packaged libraries:
81
120
 
82
121
  --disable-static
83
- Do not statically link packaged libraries, instead use shared libraries
122
+ Do not statically link packaged libraries, instead use shared libraries.
84
123
 
85
124
  --enable-cross-build
86
125
  Enable cross-build mode. (You probably do not want to set this manually.)
@@ -89,8 +128,7 @@ NOKOGIRI_HELP_MESSAGE = <<~HELP
89
128
  Environment variables used:
90
129
 
91
130
  NOKOGIRI_USE_SYSTEM_LIBRARIES
92
- When set, even if nil or blank, use system libraries instead of building and using the
93
- packaged libraries. Equivalent to `--use-system-libraries`.
131
+ Equivalent to `--enable-system-libraries` when set, even if nil or blank.
94
132
 
95
133
  CC
96
134
  Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
@@ -111,6 +149,25 @@ HELP
111
149
  #
112
150
  # utility functions
113
151
  #
152
+ def config_clean?
153
+ enable_config('clean', true)
154
+ end
155
+
156
+ def config_static?
157
+ default_static = !truffle?
158
+ enable_config("static", default_static)
159
+ end
160
+
161
+ def config_cross_build?
162
+ enable_config("cross-build")
163
+ end
164
+
165
+ def config_system_libraries?
166
+ enable_config("system-libraries", ENV.key?("NOKOGIRI_USE_SYSTEM_LIBRARIES")) do |_, default|
167
+ arg_config('--use-system-libraries', default)
168
+ end
169
+ end
170
+
114
171
  def windows?
115
172
  RbConfig::CONFIG['target_os'] =~ /mingw32|mswin/
116
173
  end
@@ -132,15 +189,19 @@ def aix?
132
189
  end
133
190
 
134
191
  def nix?
135
- ! (windows? || solaris? || darwin?)
192
+ !(windows? || solaris? || darwin?)
136
193
  end
137
194
 
138
- def concat_flags *args
195
+ def truffle?
196
+ ::RUBY_ENGINE == 'truffleruby'
197
+ end
198
+
199
+ def concat_flags(*args)
139
200
  args.compact.join(" ")
140
201
  end
141
202
 
142
- def local_have_library(lib, func=nil, headers=nil)
143
- have_library(lib, func, headers) or have_library("lib#{lib}", func, headers)
203
+ def local_have_library(lib, func = nil, headers = nil)
204
+ have_library(lib, func, headers) || have_library("lib#{lib}", func, headers)
144
205
  end
145
206
 
146
207
  LOCAL_PACKAGE_RESPONSE = Object.new
@@ -150,7 +211,7 @@ end
150
211
 
151
212
  # wrapper around MakeMakefil#pkg_config and the PKGConfig gem
152
213
  def try_package_configuration(pc)
153
- if !ENV.key?("NOKOGIRI_TEST_PKG_CONFIG_GEM")
214
+ unless ENV.key?("NOKOGIRI_TEST_PKG_CONFIG_GEM")
154
215
  # try MakeMakefile#pkg_config, which uses the system utility `pkg-config`.
155
216
  return if checking_for("#{pc} using `pkg_config`", LOCAL_PACKAGE_RESPONSE) do
156
217
  pkg_config(pc)
@@ -162,7 +223,7 @@ def try_package_configuration(pc)
162
223
  # same logic as MakeMakefile#pkg_config
163
224
  begin
164
225
  require 'rubygems'
165
- gem 'pkg-config', REQUIRED_PKG_CONFIG_VERSION
226
+ gem('pkg-config', REQUIRED_PKG_CONFIG_VERSION)
166
227
  require 'pkg-config'
167
228
 
168
229
  checking_for("#{pc} using pkg-config gem version #{PKGConfig::VERSION}", LOCAL_PACKAGE_RESPONSE) do
@@ -171,14 +232,14 @@ def try_package_configuration(pc)
171
232
  ldflags = PKGConfig.libs_only_L(pc)
172
233
  libs = PKGConfig.libs_only_l(pc)
173
234
 
174
- Logging::message "pkg-config gem found package configuration for %s\n", pc
175
- Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs
235
+ Logging.message("pkg-config gem found package configuration for %s\n", pc)
236
+ Logging.message("cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs)
176
237
 
177
238
  [cflags, ldflags, libs]
178
239
  end
179
240
  end
180
241
  rescue LoadError
181
- message "Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n"
242
+ message("Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n")
182
243
  end
183
244
  end
184
245
 
@@ -190,7 +251,7 @@ def have_package_configuration(opt: nil, pc: nil, lib:, func:, headers:)
190
251
  end
191
252
 
192
253
  # see if we have enough path info to do this without trying any harder
193
- if !ENV.key?("NOKOGIRI_TEST_PKG_CONFIG")
254
+ unless ENV.key?("NOKOGIRI_TEST_PKG_CONFIG")
194
255
  return true if local_have_library(lib, func, headers)
195
256
  end
196
257
 
@@ -201,12 +262,12 @@ def have_package_configuration(opt: nil, pc: nil, lib:, func:, headers:)
201
262
  end
202
263
 
203
264
  def ensure_package_configuration(opt: nil, pc: nil, lib:, func:, headers:)
204
- have_package_configuration(opt: opt, pc: pc, lib: lib, func: func, headers: headers) or
265
+ have_package_configuration(opt: opt, pc: pc, lib: lib, func: func, headers: headers) ||
205
266
  abort_could_not_find_library(lib)
206
267
  end
207
268
 
208
- def ensure_func(func, headers=nil)
209
- have_func(func, headers) or abort_could_not_find_library(lib)
269
+ def ensure_func(func, headers = nil)
270
+ have_func(func, headers) || abort_could_not_find_library(func)
210
271
  end
211
272
 
212
273
  def preserving_globals
@@ -217,7 +278,7 @@ ensure
217
278
  end
218
279
 
219
280
  def abort_could_not_find_library(lib)
220
- abort "-----\n#{caller[0]}\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----"
281
+ abort("-----\n#{caller[0]}\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----")
221
282
  end
222
283
 
223
284
  def chdir_for_build
@@ -230,7 +291,7 @@ def chdir_for_build
230
291
  end
231
292
  end
232
293
 
233
- def sh_export_path path
294
+ def sh_export_path(path)
234
295
  # because libxslt 1.1.29 configure.in uses AC_PATH_TOOL which treats ":"
235
296
  # as a $PATH separator, we need to convert windows paths from
236
297
  #
@@ -242,7 +303,7 @@ def sh_export_path path
242
303
  #
243
304
  # which is sh-compatible, in order to find things properly during
244
305
  # configuration
245
- return path if !windows?
306
+ return path unless windows?
246
307
 
247
308
  match = Regexp.new("^([A-Z]):(/.*)").match(path)
248
309
  if match && match.length == 3
@@ -255,31 +316,26 @@ end
255
316
  def libflag_to_filename(ldflag)
256
317
  case ldflag
257
318
  when /\A-l(.+)/
258
- "lib#{$1}.#{$LIBEXT}"
319
+ "lib#{Regexp.last_match(1)}.#{$LIBEXT}"
259
320
  end
260
321
  end
261
322
 
262
- def using_system_libraries?
263
- # NOTE: TruffleRuby uses this env var as it does not support using static libraries yet.
264
- arg_config('--use-system-libraries', ENV.key?("NOKOGIRI_USE_SYSTEM_LIBRARIES"))
265
- end
266
-
267
- def have_libxml_headers?(version=nil)
323
+ def have_libxml_headers?(version = nil)
268
324
  source = if version.nil?
269
- <<~SRC
270
- #include <libxml/xmlversion.h>
271
- SRC
272
- else
273
- version_int = sprintf "%d%2.2d%2.2d", *(version.split("."))
274
- <<~SRC
275
- #include <libxml/xmlversion.h>
276
- #if LIBXML_VERSION < #{version_int}
277
- # error libxml2 is older than #{version}
278
- #endif
279
- SRC
280
- end
281
-
282
- try_cpp source
325
+ <<~SRC
326
+ #include <libxml/xmlversion.h>
327
+ SRC
328
+ else
329
+ version_int = format("%d%2.2d%2.2d", *version.split("."))
330
+ <<~SRC
331
+ #include <libxml/xmlversion.h>
332
+ #if LIBXML_VERSION < #{version_int}
333
+ # error libxml2 is older than #{version}
334
+ #endif
335
+ SRC
336
+ end
337
+
338
+ try_cpp(source)
283
339
  end
284
340
 
285
341
  def try_link_iconv(using = nil)
@@ -307,19 +363,18 @@ def iconv_configure_flags
307
363
  # give --with-iconv-dir and --with-opt-dir first priority
308
364
  ["iconv", "opt"].each do |target|
309
365
  config = preserving_globals { dir_config(target) }
310
- if config.any? && try_link_iconv("--with-#{target}-* flags") { dir_config(target) }
311
- idirs, ldirs = config.map do |dirs|
312
- Array(dirs).flat_map do |dir|
313
- dir.split(File::PATH_SEPARATOR)
314
- end if dirs
315
- end
316
-
317
- return [
318
- '--with-iconv=yes',
319
- *("CPPFLAGS=#{idirs.map { |dir| '-I' + dir }.join(' ')}" if idirs),
320
- *("LDFLAGS=#{ldirs.map { |dir| '-L' + dir }.join(' ')}" if ldirs),
321
- ]
366
+ next unless config.any? && try_link_iconv("--with-#{target}-* flags") { dir_config(target) }
367
+ idirs, ldirs = config.map do |dirs|
368
+ Array(dirs).flat_map do |dir|
369
+ dir.split(File::PATH_SEPARATOR)
370
+ end if dirs
322
371
  end
372
+
373
+ return [
374
+ '--with-iconv=yes',
375
+ *("CPPFLAGS=#{idirs.map { |dir| '-I' + dir }.join(' ')}" if idirs),
376
+ *("LDFLAGS=#{ldirs.map { |dir| '-L' + dir }.join(' ')}" if ldirs),
377
+ ]
323
378
  end
324
379
 
325
380
  if try_link_iconv
@@ -338,14 +393,14 @@ def iconv_configure_flags
338
393
  ]
339
394
  end
340
395
 
341
- abort_could_not_find_library "libiconv"
396
+ abort_could_not_find_library("libiconv")
342
397
  end
343
398
 
344
399
  def process_recipe(name, version, static_p, cross_p)
345
400
  require 'rubygems'
346
- gem 'mini_portile2', REQUIRED_MINI_PORTILE_VERSION
401
+ gem('mini_portile2', REQUIRED_MINI_PORTILE_VERSION)
347
402
  require 'mini_portile2'
348
- message "Using mini_portile version #{MiniPortile::VERSION}\n"
403
+ message("Using mini_portile version #{MiniPortile::VERSION}\n")
349
404
 
350
405
  if name != "libxml2" && name != "libxslt"
351
406
  OTHER_LIBRARY_VERSIONS[name] = version
@@ -357,12 +412,12 @@ def process_recipe(name, version, static_p, cross_p)
357
412
  # correct compiler prefix for cross build, but use host if not set.
358
413
  recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
359
414
  recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", name, "*.patch")].sort
360
- recipe.configure_options << "--libdir=#{File.join(recipe.path, "lib")}"
415
+ recipe.configure_options << "--libdir=#{File.join(recipe.path, 'lib')}"
361
416
 
362
417
  yield recipe
363
418
 
364
419
  env = Hash.new do |hash, key|
365
- hash[key] = "#{ENV[key]}" # (ENV[key].dup rescue '')
420
+ hash[key] = (ENV[key]).to_s
366
421
  end
367
422
 
368
423
  recipe.configure_options.flatten!
@@ -370,10 +425,10 @@ def process_recipe(name, version, static_p, cross_p)
370
425
  recipe.configure_options.delete_if do |option|
371
426
  case option
372
427
  when /\A(\w+)=(.*)\z/
373
- if env.key?($1)
374
- env[$1] = concat_flags(env[$1], $2)
428
+ env[Regexp.last_match(1)] = if env.key?(Regexp.last_match(1))
429
+ concat_flags(env[Regexp.last_match(1)], Regexp.last_match(2))
375
430
  else
376
- env[$1] = $2
431
+ Regexp.last_match(2)
377
432
  end
378
433
  true
379
434
  else
@@ -415,34 +470,34 @@ def process_recipe(name, version, static_p, cross_p)
415
470
 
416
471
  checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
417
472
  if File.exist?(checkpoint)
418
- message "Building Nokogiri with a packaged version of #{name}-#{version}.\n"
473
+ message("Building Nokogiri with a packaged version of #{name}-#{version}.\n")
419
474
  else
420
- message <<~EOM
475
+ message(<<~EOM)
421
476
  ---------- IMPORTANT NOTICE ----------
422
477
  Building Nokogiri with a packaged version of #{name}-#{version}.
423
478
  Configuration options: #{recipe.configure_options.shelljoin}
424
479
  EOM
425
480
 
426
481
  unless recipe.patch_files.empty?
427
- message "The following patches are being applied:\n"
482
+ message("The following patches are being applied:\n")
428
483
 
429
484
  recipe.patch_files.each do |patch|
430
- message " - %s\n" % File.basename(patch)
485
+ message(" - %s\n" % File.basename(patch))
431
486
  end
432
487
  end
433
488
 
434
- message <<~EOM
489
+ message(<<~EOM)
435
490
 
436
491
  The Nokogiri maintainers intend to provide timely security updates, but if
437
492
  this is a concern for you and want to use your OS/distro system library
438
493
  instead, then abort this installation process and install nokogiri as
439
494
  instructed at:
440
495
 
441
- https://nokogiri.org/tutorials/installing_nokogiri.html#install-with-system-libraries
496
+ https://nokogiri.org/tutorials/installing_nokogiri.html#installing-using-standard-system-libraries
442
497
 
443
498
  EOM
444
499
 
445
- message <<~EOM if name == 'libxml2'
500
+ message(<<~EOM) if name == 'libxml2'
446
501
  Note, however, that nokogiri cannot guarantee compatiblity with every
447
502
  version of libxml2 that may be provided by OS/package vendors.
448
503
 
@@ -451,7 +506,7 @@ def process_recipe(name, version, static_p, cross_p)
451
506
  chdir_for_build do
452
507
  recipe.cook
453
508
  end
454
- FileUtils.touch checkpoint
509
+ FileUtils.touch(checkpoint)
455
510
  end
456
511
  recipe.activate
457
512
  end
@@ -466,8 +521,8 @@ def copy_packaged_libraries_headers(to_path:, from_recipes:)
466
521
  end
467
522
 
468
523
  def do_help
469
- print NOKOGIRI_HELP_MESSAGE
470
- exit! 0
524
+ print(NOKOGIRI_HELP_MESSAGE)
525
+ exit!(0)
471
526
  end
472
527
 
473
528
  def do_clean
@@ -476,7 +531,7 @@ def do_clean
476
531
 
477
532
  # Skip if this is a development work tree
478
533
  unless (root + '.git').exist?
479
- message "Cleaning files only used during build.\n"
534
+ message("Cleaning files only used during build.\n")
480
535
 
481
536
  # (root + 'tmp') cannot be removed at this stage because
482
537
  # nokogiri.so is yet to be copied to lib.
@@ -486,7 +541,7 @@ def do_clean
486
541
  FileUtils.rm_rf(dir, verbose: true)
487
542
  end
488
543
 
489
- if enable_config('static')
544
+ if config_static?
490
545
  # ports installation can be safely removed if statically linked.
491
546
  FileUtils.rm_rf(root + 'ports', verbose: true)
492
547
  else
@@ -494,7 +549,7 @@ def do_clean
494
549
  end
495
550
  end
496
551
 
497
- exit! 0
552
+ exit!(0)
498
553
  end
499
554
 
500
555
  #
@@ -503,10 +558,10 @@ end
503
558
  do_help if arg_config('--help')
504
559
  do_clean if arg_config('--clean')
505
560
 
506
- if openbsd? && !using_system_libraries?
507
- if `#{ENV['CC'] || '/usr/bin/cc'} -v 2>&1` !~ /clang/
508
- ENV['CC'] ||= find_executable('egcc') or
509
- abort "Please install gcc 4.9+ from ports using `pkg_add -v gcc`"
561
+ if openbsd? && !config_system_libraries?
562
+ if %x(#{ENV['CC'] || '/usr/bin/cc'} -v 2>&1) !~ /clang/
563
+ (ENV['CC'] ||= find_executable('egcc')) ||
564
+ abort("Please install gcc 4.9+ from ports using `pkg_add -v gcc`")
510
565
  end
511
566
  append_cppflags "-I/usr/local/include"
512
567
  end
@@ -531,20 +586,29 @@ if arg_config('--prevent-strip')
531
586
  end
532
587
 
533
588
  # adopt environment config
534
- append_cflags(ENV["CFLAGS"].split) if !ENV["CFLAGS"].nil?
535
- append_cppflags(ENV["CPPFLAGS"].split) if !ENV["CPPFLAGS"].nil?
536
- append_ldflags(ENV["LDFLAGS"].split) if !ENV["LDFLAGS"].nil?
589
+ append_cflags(ENV["CFLAGS"].split) unless ENV["CFLAGS"].nil?
590
+ append_cppflags(ENV["CPPFLAGS"].split) unless ENV["CPPFLAGS"].nil?
591
+ append_ldflags(ENV["LDFLAGS"].split) unless ENV["LDFLAGS"].nil?
537
592
  $LIBS = concat_flags($LIBS, ENV["LIBS"])
538
593
 
539
- append_cflags("-g") # always include debugging information
540
- append_cflags("-Winline") # we use at least one inline function in the C extension
541
- append_cflags("-Wmissing-noreturn") # good to have no matter what Ruby was compiled with
594
+ # always include debugging information
595
+ append_cflags("-g")
596
+
597
+ # we use at least one inline function in the C extension
598
+ append_cflags("-Winline")
599
+
600
+ # good to have no matter what Ruby was compiled with
601
+ append_cflags("-Wmissing-noreturn")
602
+
603
+ # handle clang variations, see #1101
542
604
  append_cflags("-Wno-error=unused-command-line-argument-hard-error-in-future") if darwin?
543
- # append_cflags(["-Wcast-qual", "-Wwrite-strings"]) # these tend to be noisy, but on occasion useful during development
605
+
606
+ # these tend to be noisy, but on occasion useful during development
607
+ # append_cflags(["-Wcast-qual", "-Wwrite-strings"])
544
608
 
545
609
  # Add SDK-specific include path for macOS and brew versions before v2.2.12 (2020-04-08) [#1851, #1801]
546
610
  macos_mojave_sdk_include_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2"
547
- if using_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path)
611
+ if config_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path)
548
612
  append_cppflags("-I#{macos_mojave_sdk_include_path}")
549
613
  end
550
614
 
@@ -552,26 +616,30 @@ end
552
616
  # See https://sourceforge.net/p/mingw/bugs/2142
553
617
  append_cppflags(' "-Idummypath"') if windows?
554
618
 
555
- if using_system_libraries?
619
+ if config_system_libraries?
556
620
  message "Building nokogiri using system libraries.\n"
557
- ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z", headers: "zlib.h", func: "gzdopen")
558
- ensure_package_configuration(opt: "xml2", pc: "libxml-2.0", lib: "xml2", headers: "libxml/parser.h", func: "xmlParseDoc")
559
- ensure_package_configuration(opt: "xslt", pc: "libxslt", lib: "xslt", headers: "libxslt/xslt.h", func: "xsltParseStylesheetDoc")
560
- ensure_package_configuration(opt: "exslt", pc: "libexslt", lib: "exslt", headers: "libexslt/exslt.h", func: "exsltFuncRegister")
561
-
562
- have_libxml_headers?(REQUIRED_LIBXML_VERSION) or
563
- abort "ERROR: libxml2 version #{REQUIRED_LIBXML_VERSION} or later is required!"
564
- have_libxml_headers?(RECOMMENDED_LIBXML_VERSION) or
565
- warn "WARNING: libxml2 version #{RECOMMENDED_LIBXML_VERSION} or later is highly recommended, but proceeding anyway."
621
+ ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z",
622
+ headers: "zlib.h", func: "gzdopen")
623
+ ensure_package_configuration(opt: "xml2", pc: "libxml-2.0", lib: "xml2",
624
+ headers: "libxml/parser.h", func: "xmlParseDoc")
625
+ ensure_package_configuration(opt: "xslt", pc: "libxslt", lib: "xslt",
626
+ headers: "libxslt/xslt.h", func: "xsltParseStylesheetDoc")
627
+ ensure_package_configuration(opt: "exslt", pc: "libexslt", lib: "exslt",
628
+ headers: "libexslt/exslt.h", func: "exsltFuncRegister")
629
+
630
+ have_libxml_headers?(REQUIRED_LIBXML_VERSION) ||
631
+ abort("ERROR: libxml2 version #{REQUIRED_LIBXML_VERSION} or later is required!")
632
+ have_libxml_headers?(RECOMMENDED_LIBXML_VERSION) ||
633
+ warn("WARNING: libxml2 version #{RECOMMENDED_LIBXML_VERSION} or later is highly recommended, but proceeding anyway.")
566
634
 
567
635
  else
568
636
  message "Building nokogiri using packaged libraries.\n"
569
637
 
570
- static_p = enable_config("static", true)
571
- message "Static linking is #{static_p ? "enabled" : "disabled"}.\n"
638
+ static_p = config_static?
639
+ message "Static linking is #{static_p ? 'enabled' : 'disabled'}.\n"
572
640
 
573
- cross_build_p = enable_config("cross-build")
574
- message "Cross build is #{cross_build_p ? "enabled" : "disabled"}.\n"
641
+ cross_build_p = config_cross_build?
642
+ message "Cross build is #{cross_build_p ? 'enabled' : 'disabled'}.\n"
575
643
 
576
644
  require 'yaml'
577
645
  dependencies = YAML.load_file(File.join(PACKAGE_ROOT_DIR, "dependencies.yml"))
@@ -581,17 +649,17 @@ else
581
649
  if cross_build_p || windows?
582
650
  zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
583
651
  recipe.files = [{
584
- url: "http://zlib.net/fossils/#{recipe.name}-#{recipe.version}.tar.gz",
585
- sha256: dependencies["zlib"]["sha256"]
586
- }]
652
+ url: "http://zlib.net/fossils/#{recipe.name}-#{recipe.version}.tar.gz",
653
+ sha256: dependencies["zlib"]["sha256"],
654
+ }]
587
655
  if windows?
588
656
  class << recipe
589
657
  attr_accessor :cross_build_p
590
658
 
591
659
  def configure
592
- Dir.chdir work_path do
593
- mk = File.read 'win32/Makefile.gcc'
594
- File.open 'win32/Makefile.gcc', 'wb' do |f|
660
+ Dir.chdir(work_path) do
661
+ mk = File.read('win32/Makefile.gcc')
662
+ File.open('win32/Makefile.gcc', 'wb') do |f|
595
663
  f.puts "BINARY_PATH = #{path}/bin"
596
664
  f.puts "LIBRARY_PATH = #{path}/lib"
597
665
  f.puts "INCLUDE_PATH = #{path}/include"
@@ -602,17 +670,17 @@ else
602
670
  end
603
671
 
604
672
  def configured?
605
- Dir.chdir work_path do
606
- !! (File.read('win32/Makefile.gcc') =~ /^BINARY_PATH/)
673
+ Dir.chdir(work_path) do
674
+ !!(File.read('win32/Makefile.gcc') =~ /^BINARY_PATH/)
607
675
  end
608
676
  end
609
677
 
610
678
  def compile
611
- execute "compile", "make -f win32/Makefile.gcc"
679
+ execute("compile", "make -f win32/Makefile.gcc")
612
680
  end
613
681
 
614
682
  def install
615
- execute "install", "make -f win32/Makefile.gcc install"
683
+ execute("install", "make -f win32/Makefile.gcc install")
616
684
  end
617
685
  end
618
686
  recipe.cross_build_p = cross_build_p
@@ -620,12 +688,13 @@ else
620
688
  class << recipe
621
689
  def configure
622
690
  cflags = concat_flags(ENV["CFLAGS"], "-fPIC", "-g")
623
- execute "configure", ["env", "CHOST=#{host}", "CFLAGS=#{cflags}", "./configure", "--static", configure_prefix]
691
+ execute("configure",
692
+ ["env", "CHOST=#{host}", "CFLAGS=#{cflags}", "./configure", "--static", configure_prefix])
624
693
  end
625
694
 
626
695
  def compile
627
- if host=~/darwin/
628
- execute "compile", "make AR=#{host}-libtool"
696
+ if host =~ /darwin/
697
+ execute("compile", "make AR=#{host}-libtool")
629
698
  else
630
699
  super
631
700
  end
@@ -635,11 +704,12 @@ else
635
704
  end
636
705
 
637
706
  unless nix?
638
- libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p, cross_build_p) do |recipe|
707
+ libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p,
708
+ cross_build_p) do |recipe|
639
709
  recipe.files = [{
640
- url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
641
- sha256: dependencies["libiconv"]["sha256"]
642
- }]
710
+ url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
711
+ sha256: dependencies["libiconv"]["sha256"],
712
+ }]
643
713
 
644
714
  cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
645
715
 
@@ -647,37 +717,35 @@ else
647
717
  "CPPFLAGS=-Wall",
648
718
  "CFLAGS=#{cflags}",
649
719
  "CXXFLAGS=#{cflags}",
650
- "LDFLAGS="
720
+ "LDFLAGS=",
651
721
  ]
652
722
  end
653
723
  end
654
- else
655
- if darwin? && !have_header('iconv.h')
656
- abort <<~EOM.chomp
657
- -----
658
- The file "iconv.h" is missing in your build environment,
659
- which means you haven't installed Xcode Command Line Tools properly.
660
-
661
- To install Command Line Tools, try running `xcode-select --install` on
662
- terminal and follow the instructions. If it fails, open Xcode.app,
663
- select from the menu "Xcode" - "Open Developer Tool" - "More Developer
664
- Tools" to open the developer site, download the installer for your OS
665
- version and run it.
666
- -----
724
+ elsif darwin? && !have_header('iconv.h')
725
+ abort(<<~EOM.chomp)
726
+ -----
727
+ The file "iconv.h" is missing in your build environment,
728
+ which means you haven't installed Xcode Command Line Tools properly.
729
+
730
+ To install Command Line Tools, try running `xcode-select --install` on
731
+ terminal and follow the instructions. If it fails, open Xcode.app,
732
+ select from the menu "Xcode" - "Open Developer Tool" - "More Developer
733
+ Tools" to open the developer site, download the installer for your OS
734
+ version and run it.
735
+ -----
667
736
  EOM
668
- end
669
737
  end
670
738
 
671
739
  unless windows?
672
- preserving_globals { local_have_library('z', 'gzdopen', 'zlib.h') } or
673
- abort 'zlib is missing; necessary for building libxml2'
740
+ preserving_globals { local_have_library('z', 'gzdopen', 'zlib.h') } ||
741
+ abort('zlib is missing; necessary for building libxml2')
674
742
  end
675
743
 
676
744
  libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
677
745
  recipe.files = [{
678
- url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
679
- sha256: dependencies["libxml2"]["sha256"]
680
- }]
746
+ url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
747
+ sha256: dependencies["libxml2"]["sha256"],
748
+ }]
681
749
 
682
750
  cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
683
751
 
@@ -696,6 +764,10 @@ else
696
764
  recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
697
765
  end
698
766
 
767
+ if windows?
768
+ cflags = concat_flags(cflags, "-ULIBXML_STATIC", "-DIN_LIBXML")
769
+ end
770
+
699
771
  recipe.configure_options += [
700
772
  "--without-python",
701
773
  "--without-readline",
@@ -708,9 +780,9 @@ else
708
780
 
709
781
  libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"]["version"], static_p, cross_build_p) do |recipe|
710
782
  recipe.files = [{
711
- url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
712
- sha256: dependencies["libxslt"]["sha256"]
713
- }]
783
+ url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
784
+ sha256: dependencies["libxslt"]["sha256"],
785
+ }]
714
786
 
715
787
  cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
716
788
 
@@ -738,15 +810,15 @@ else
738
810
  libname = recipe.name[/\Alib(.+)\z/, 1]
739
811
  File.join(recipe.path, "bin", "#{libname}-config").tap do |config|
740
812
  # call config scripts explicit with 'sh' for compat with Windows
741
- $CPPFLAGS = `sh #{config} --cflags`.strip << ' ' << $CPPFLAGS
742
- `sh #{config} --libs`.strip.shellsplit.each do |arg|
813
+ $CPPFLAGS = %x(sh #{config} --cflags).strip << ' ' << $CPPFLAGS
814
+ %x(sh #{config} --libs).strip.shellsplit.each do |arg|
743
815
  case arg
744
816
  when /\A-L(.+)\z/
745
817
  # Prioritize ports' directories
746
- if $1.start_with?(PACKAGE_ROOT_DIR + '/')
747
- $LIBPATH = [$1] | $LIBPATH
818
+ $LIBPATH = if Regexp.last_match(1).start_with?(PACKAGE_ROOT_DIR + '/')
819
+ [Regexp.last_match(1)] | $LIBPATH
748
820
  else
749
- $LIBPATH = $LIBPATH | [$1]
821
+ $LIBPATH | [Regexp.last_match(1)]
750
822
  end
751
823
  when /\A-l./
752
824
  libs.unshift(arg)
@@ -757,7 +829,7 @@ else
757
829
  end
758
830
 
759
831
  patches_string = recipe.patch_files.map { |path| File.basename(path) }.join(' ')
760
- append_cppflags(%Q[-DNOKOGIRI_#{recipe.name.upcase}_PATCHES="\\\"#{patches_string}\\\""])
832
+ append_cppflags(%[-DNOKOGIRI_#{recipe.name.upcase}_PATCHES="\\\"#{patches_string}\\\""])
761
833
 
762
834
  case libname
763
835
  when 'xml2'
@@ -793,7 +865,7 @@ else
793
865
  ensure_func("exsltFuncRegister", "libexslt/exslt.h")
794
866
  end
795
867
 
796
- have_func('xmlHasFeature') or abort("xmlHasFeature() is missing.") # introduced in libxml 2.6.21
868
+ have_func('xmlHasFeature') || abort("xmlHasFeature() is missing.") # introduced in libxml 2.6.21
797
869
  have_func('xmlFirstElementChild') # introduced in libxml 2.7.3
798
870
  have_func('xmlRelaxNGSetParserStructuredErrors') # introduced in libxml 2.6.24
799
871
  have_func('xmlRelaxNGSetValidStructuredErrors') # introduced in libxml 2.6.21
@@ -802,10 +874,10 @@ have_func('xmlSchemaSetParserStructuredErrors') # introduced in libxml 2.6.23
802
874
 
803
875
  have_func('vasprintf')
804
876
 
805
- other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k,v| [k,v].join(":") }.join(",")
806
- append_cppflags(%Q[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\\"#{other_library_versions_string}\\\""])
877
+ other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k, v| [k, v].join(":") }.join(",")
878
+ append_cppflags(%[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\\"#{other_library_versions_string}\\\""])
807
879
 
808
- unless using_system_libraries?
880
+ unless config_system_libraries?
809
881
  if cross_build_p
810
882
  # When precompiling native gems, copy packaged libraries' headers to ext/nokogiri/include
811
883
  # These are packaged up by the cross-compiling callback in the ExtensionTask
@@ -821,10 +893,10 @@ end
821
893
 
822
894
  create_makefile('nokogiri/nokogiri')
823
895
 
824
- if enable_config('clean', true)
896
+ if config_clean?
825
897
  # Do not clean if run in a development work tree.
826
898
  File.open('Makefile', 'at') do |mk|
827
- mk.print <<~EOF
899
+ mk.print(<<~EOF)
828
900
 
829
901
  all: clean-ports
830
902
  clean-ports: $(DLLIB)
@@ -832,5 +904,3 @@ if enable_config('clean', true)
832
904
  EOF
833
905
  end
834
906
  end
835
-
836
- # :startdoc: