nokogiri 1.15.7 → 1.18.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +12 -17
  3. data/LICENSE-DEPENDENCIES.md +6 -6
  4. data/README.md +11 -5
  5. data/dependencies.yml +9 -8
  6. data/ext/nokogiri/extconf.rb +191 -154
  7. data/ext/nokogiri/gumbo.c +69 -53
  8. data/ext/nokogiri/html4_document.c +10 -4
  9. data/ext/nokogiri/html4_element_description.c +18 -18
  10. data/ext/nokogiri/html4_sax_parser.c +40 -0
  11. data/ext/nokogiri/html4_sax_parser_context.c +48 -58
  12. data/ext/nokogiri/html4_sax_push_parser.c +26 -25
  13. data/ext/nokogiri/libxml2_polyfill.c +114 -0
  14. data/ext/nokogiri/nokogiri.c +9 -2
  15. data/ext/nokogiri/nokogiri.h +25 -33
  16. data/ext/nokogiri/test_global_handlers.c +1 -1
  17. data/ext/nokogiri/xml_attr.c +1 -1
  18. data/ext/nokogiri/xml_cdata.c +3 -12
  19. data/ext/nokogiri/xml_comment.c +3 -8
  20. data/ext/nokogiri/xml_document.c +167 -156
  21. data/ext/nokogiri/xml_document_fragment.c +10 -25
  22. data/ext/nokogiri/xml_dtd.c +1 -1
  23. data/ext/nokogiri/xml_element_content.c +9 -9
  24. data/ext/nokogiri/xml_encoding_handler.c +4 -4
  25. data/ext/nokogiri/xml_namespace.c +6 -10
  26. data/ext/nokogiri/xml_node.c +135 -107
  27. data/ext/nokogiri/xml_node_set.c +46 -44
  28. data/ext/nokogiri/xml_reader.c +74 -100
  29. data/ext/nokogiri/xml_relax_ng.c +35 -56
  30. data/ext/nokogiri/xml_sax_parser.c +156 -88
  31. data/ext/nokogiri/xml_sax_parser_context.c +220 -128
  32. data/ext/nokogiri/xml_sax_push_parser.c +69 -50
  33. data/ext/nokogiri/xml_schema.c +51 -87
  34. data/ext/nokogiri/xml_syntax_error.c +19 -11
  35. data/ext/nokogiri/xml_text.c +3 -6
  36. data/ext/nokogiri/xml_xpath_context.c +104 -104
  37. data/ext/nokogiri/xslt_stylesheet.c +16 -11
  38. data/gumbo-parser/Makefile +18 -0
  39. data/gumbo-parser/src/ascii.c +2 -2
  40. data/gumbo-parser/src/error.c +76 -48
  41. data/gumbo-parser/src/error.h +5 -1
  42. data/gumbo-parser/src/nokogiri_gumbo.h +11 -2
  43. data/gumbo-parser/src/parser.c +66 -25
  44. data/gumbo-parser/src/tokenizer.c +7 -6
  45. data/lib/nokogiri/class_resolver.rb +1 -1
  46. data/lib/nokogiri/css/node.rb +6 -2
  47. data/lib/nokogiri/css/parser.rb +6 -4
  48. data/lib/nokogiri/css/parser.y +2 -2
  49. data/lib/nokogiri/css/parser_extras.rb +6 -66
  50. data/lib/nokogiri/css/selector_cache.rb +38 -0
  51. data/lib/nokogiri/css/tokenizer.rb +4 -4
  52. data/lib/nokogiri/css/tokenizer.rex +9 -8
  53. data/lib/nokogiri/css/xpath_visitor.rb +44 -27
  54. data/lib/nokogiri/css.rb +86 -20
  55. data/lib/nokogiri/decorators/slop.rb +3 -5
  56. data/lib/nokogiri/encoding_handler.rb +2 -2
  57. data/lib/nokogiri/html4/document.rb +45 -24
  58. data/lib/nokogiri/html4/document_fragment.rb +124 -12
  59. data/lib/nokogiri/html4/encoding_reader.rb +2 -2
  60. data/lib/nokogiri/html4/sax/parser.rb +23 -38
  61. data/lib/nokogiri/html4/sax/parser_context.rb +4 -9
  62. data/lib/nokogiri/html4.rb +9 -14
  63. data/lib/nokogiri/html5/builder.rb +40 -0
  64. data/lib/nokogiri/html5/document.rb +61 -30
  65. data/lib/nokogiri/html5/document_fragment.rb +130 -20
  66. data/lib/nokogiri/html5/node.rb +4 -4
  67. data/lib/nokogiri/html5.rb +114 -138
  68. data/lib/nokogiri/version/constant.rb +1 -1
  69. data/lib/nokogiri/version/info.rb +6 -5
  70. data/lib/nokogiri/xml/attr.rb +2 -2
  71. data/lib/nokogiri/xml/builder.rb +8 -1
  72. data/lib/nokogiri/xml/document.rb +73 -29
  73. data/lib/nokogiri/xml/document_fragment.rb +86 -15
  74. data/lib/nokogiri/xml/namespace.rb +1 -2
  75. data/lib/nokogiri/xml/node.rb +113 -35
  76. data/lib/nokogiri/xml/node_set.rb +12 -10
  77. data/lib/nokogiri/xml/parse_options.rb +1 -1
  78. data/lib/nokogiri/xml/pp/node.rb +6 -1
  79. data/lib/nokogiri/xml/reader.rb +51 -17
  80. data/lib/nokogiri/xml/relax_ng.rb +57 -20
  81. data/lib/nokogiri/xml/sax/document.rb +174 -83
  82. data/lib/nokogiri/xml/sax/parser.rb +115 -41
  83. data/lib/nokogiri/xml/sax/parser_context.rb +116 -8
  84. data/lib/nokogiri/xml/sax/push_parser.rb +3 -0
  85. data/lib/nokogiri/xml/sax.rb +48 -0
  86. data/lib/nokogiri/xml/schema.rb +112 -45
  87. data/lib/nokogiri/xml/searchable.rb +39 -43
  88. data/lib/nokogiri/xml/syntax_error.rb +23 -1
  89. data/lib/nokogiri/xml/xpath_context.rb +14 -3
  90. data/lib/nokogiri/xml.rb +14 -25
  91. data/lib/nokogiri/xslt/stylesheet.rb +29 -7
  92. data/lib/nokogiri/xslt.rb +4 -10
  93. data/lib/nokogiri.rb +1 -1
  94. data/lib/xsd/xmlparser/nokogiri.rb +3 -4
  95. data/patches/libxml2/0019-xpath-Use-separate-static-hash-table-for-standard-fu.patch +244 -0
  96. data/ports/archives/libxml2-2.13.7.tar.xz +0 -0
  97. data/ports/archives/libxslt-1.1.43.tar.xz +0 -0
  98. metadata +13 -12
  99. data/ext/nokogiri/libxml2_backwards_compat.c +0 -121
  100. data/patches/libxml2/0003-libxml2.la-is-in-top_builddir.patch +0 -25
  101. data/ports/archives/libxml2-2.11.7.tar.xz +0 -0
  102. data/ports/archives/libxslt-1.1.39.tar.xz +0 -0
@@ -12,8 +12,8 @@ require "pathname"
12
12
 
13
13
  # helpful constants
14
14
  PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
15
- REQUIRED_LIBXML_VERSION = "2.6.21"
16
- RECOMMENDED_LIBXML_VERSION = "2.9.3"
15
+ REQUIRED_LIBXML_VERSION = "2.9.2"
16
+ RECOMMENDED_LIBXML_VERSION = "2.12.0"
17
17
 
18
18
  REQUIRED_MINI_PORTILE_VERSION = "~> 2.8.2" # keep this version in sync with the one in the gemspec
19
19
  REQUIRED_PKG_CONFIG_VERSION = "~> 1.1"
@@ -57,30 +57,6 @@ NOKOGIRI_HELP_MESSAGE = <<~HELP
57
57
  Look for headers in DIRECTORY.
58
58
 
59
59
 
60
- Related to zlib:
61
-
62
- --with-zlib-dir=DIRECTORY
63
- Look for zlib headers and library in DIRECTORY.
64
-
65
- --with-zlib-lib=DIRECTORY
66
- Look for zlib library in DIRECTORY.
67
-
68
- --with-zlib-include=DIRECTORY
69
- Look for zlib headers in DIRECTORY.
70
-
71
-
72
- Related to iconv:
73
-
74
- --with-iconv-dir=DIRECTORY
75
- Look for iconv headers and library in DIRECTORY.
76
-
77
- --with-iconv-lib=DIRECTORY
78
- Look for iconv library in DIRECTORY.
79
-
80
- --with-iconv-include=DIRECTORY
81
- Look for iconv headers in DIRECTORY.
82
-
83
-
84
60
  Related to libxml2:
85
61
 
86
62
  --with-xml2-dir=DIRECTORY
@@ -95,6 +71,10 @@ NOKOGIRI_HELP_MESSAGE = <<~HELP
95
71
  --with-xml2-source-dir=DIRECTORY
96
72
  (dev only) Build libxml2 from the source code in DIRECTORY
97
73
 
74
+ --disable-xml2-legacy
75
+ Do not build libxml2 with zlib, liblzma, or HTTP support. This will become the default
76
+ in a future version of Nokogiri.
77
+
98
78
 
99
79
  Related to libxslt:
100
80
 
@@ -123,6 +103,30 @@ NOKOGIRI_HELP_MESSAGE = <<~HELP
123
103
  Look for exslt headers in DIRECTORY.
124
104
 
125
105
 
106
+ Related to iconv:
107
+
108
+ --with-iconv-dir=DIRECTORY
109
+ Look for iconv headers and library in DIRECTORY.
110
+
111
+ --with-iconv-lib=DIRECTORY
112
+ Look for iconv library in DIRECTORY.
113
+
114
+ --with-iconv-include=DIRECTORY
115
+ Look for iconv headers in DIRECTORY.
116
+
117
+
118
+ Related to zlib (ignored if `--disable-xml2-legacy` is used):
119
+
120
+ --with-zlib-dir=DIRECTORY
121
+ Look for zlib headers and library in DIRECTORY.
122
+
123
+ --with-zlib-lib=DIRECTORY
124
+ Look for zlib library in DIRECTORY.
125
+
126
+ --with-zlib-include=DIRECTORY
127
+ Look for zlib headers in DIRECTORY.
128
+
129
+
126
130
  Flags only used when building and using the packaged libraries:
127
131
 
128
132
  --disable-static
@@ -137,6 +141,9 @@ NOKOGIRI_HELP_MESSAGE = <<~HELP
137
141
  NOKOGIRI_USE_SYSTEM_LIBRARIES
138
142
  Equivalent to `--enable-system-libraries` when set, even if nil or blank.
139
143
 
144
+ AR
145
+ Use this path to invoke the library archiver instead of `RbConfig::CONFIG['AR']`
146
+
140
147
  CC
141
148
  Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
142
149
 
@@ -146,6 +153,9 @@ NOKOGIRI_HELP_MESSAGE = <<~HELP
146
153
  CFLAGS
147
154
  If this string is accepted by the compiler, add it to the flags passed to the compiler
148
155
 
156
+ LD
157
+ Use this path to invoke the linker instead of `RbConfig::CONFIG['LD']`
158
+
149
159
  LDFLAGS
150
160
  If this string is accepted by the linker, add it to the flags passed to the linker
151
161
 
@@ -175,6 +185,10 @@ def config_system_libraries?
175
185
  end
176
186
  end
177
187
 
188
+ def config_with_xml2_legacy?
189
+ enable_config("xml2-legacy", true)
190
+ end
191
+
178
192
  def windows?
179
193
  RbConfig::CONFIG["target_os"].match?(/mingw|mswin/)
180
194
  end
@@ -195,10 +209,14 @@ def aix?
195
209
  RbConfig::CONFIG["target_os"].include?("aix")
196
210
  end
197
211
 
198
- def nix?
212
+ def unix?
199
213
  !(windows? || solaris? || darwin?)
200
214
  end
201
215
 
216
+ def nix?
217
+ ENV.key?("NIX_CC")
218
+ end
219
+
202
220
  def truffle?
203
221
  RUBY_ENGINE == "truffleruby"
204
222
  end
@@ -222,15 +240,7 @@ def zlib_source(version_string)
222
240
  end
223
241
 
224
242
  def gnome_source
225
- # As of 2022-02-20, some mirrors have expired SSL certificates. I'm able to retrieve from my home,
226
- # but whatever host is resolved on the github actions workers see an expired cert.
227
- #
228
- # See https://github.com/sparklemotion/nokogiri/runs/5266206403?check_suite_focus=true
229
- if ENV["NOKOGIRI_USE_CANONICAL_GNOME_SOURCE"]
230
- "https://download.gnome.org"
231
- else
232
- "https://muug.ca/mirror/gnome" # old reliable
233
- end
243
+ "https://download.gnome.org"
234
244
  end
235
245
 
236
246
  LOCAL_PACKAGE_RESPONSE = Object.new
@@ -443,7 +453,7 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p = true)
443
453
  # We use 'host' to set compiler prefix for cross-compiling. Prefer host_alias over host. And
444
454
  # prefer i686 (what external dev tools use) to i386 (what ruby's configure.ac emits).
445
455
  recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
446
- recipe.host = recipe.host.gsub(/i386/, "i686")
456
+ recipe.host = recipe.host.gsub("i386", "i686")
447
457
 
448
458
  recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") if cacheable_p
449
459
  recipe.configure_options << "--libdir=#{File.join(recipe.path, "lib")}"
@@ -626,12 +636,22 @@ if openbsd? && !config_system_libraries?
626
636
  append_cppflags "-I/usr/local/include"
627
637
  end
628
638
 
639
+ if ENV["AR"]
640
+ RbConfig::CONFIG["AR"] = RbConfig::MAKEFILE_CONFIG["AR"] = ENV["AR"]
641
+ end
642
+
629
643
  if ENV["CC"]
630
644
  RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"]
631
645
  end
632
646
 
633
- # use same c compiler for libxml and libxslt
647
+ if ENV["LD"]
648
+ RbConfig::CONFIG["LD"] = RbConfig::MAKEFILE_CONFIG["LD"] = ENV["LD"]
649
+ end
650
+
651
+ # use same toolchain for libxml and libxslt
652
+ ENV["AR"] = RbConfig::CONFIG["AR"]
634
653
  ENV["CC"] = RbConfig::CONFIG["CC"]
654
+ ENV["LD"] = RbConfig::CONFIG["LD"]
635
655
 
636
656
  if arg_config("--prevent-strip")
637
657
  old_cflags = $CFLAGS.split.join(" ")
@@ -646,13 +666,12 @@ if arg_config("--prevent-strip")
646
666
  end
647
667
 
648
668
  # adopt environment config
649
- append_cflags(ENV["CFLAGS"].split) unless ENV["CFLAGS"].nil?
650
- append_cppflags(ENV["CPPFLAGS"].split) unless ENV["CPPFLAGS"].nil?
651
- append_ldflags(ENV["LDFLAGS"].split) unless ENV["LDFLAGS"].nil?
669
+ append_cflags(ENV["CFLAGS"]) unless ENV["CFLAGS"].nil?
670
+ append_cppflags(ENV["CPPFLAGS"]) unless ENV["CPPFLAGS"].nil?
671
+ append_ldflags(ENV["LDFLAGS"]) unless ENV["LDFLAGS"].nil?
652
672
  $LIBS = concat_flags($LIBS, ENV["LIBS"])
653
673
 
654
- # nokogumbo code uses C90/C99 features, let's make sure older compilers won't give
655
- # errors/warnings. see #2302
674
+ # libgumbo uses C90/C99 features, see #2302
656
675
  append_cflags(["-std=c99", "-Wno-declaration-after-statement"])
657
676
 
658
677
  # gumbo html5 serialization is slower with O3, let's make sure we use O2
@@ -667,12 +686,9 @@ append_cflags("-Winline")
667
686
  # good to have no matter what Ruby was compiled with
668
687
  append_cflags("-Wmissing-noreturn")
669
688
 
670
- # check integer loss of precision
671
- if darwin?
672
- append_cflags("-Wshorten-64-to-32")
673
- else
674
- append_cflags("-Wconversion -Wno-sign-conversion")
675
- end
689
+ # check integer loss of precision. this flag won't generally work until Ruby 3.4.
690
+ # see https://bugs.ruby-lang.org/issues/20507
691
+ append_cflags("-Wconversion")
676
692
 
677
693
  # handle clang variations, see #1101
678
694
  if darwin?
@@ -685,7 +701,7 @@ end
685
701
 
686
702
  # Add SDK-specific include path for macOS and brew versions before v2.2.12 (2020-04-08) [#1851, #1801]
687
703
  macos_mojave_sdk_include_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2"
688
- if config_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path)
704
+ if config_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path) && !nix?
689
705
  append_cppflags("-I#{macos_mojave_sdk_include_path}")
690
706
  end
691
707
 
@@ -695,13 +711,15 @@ append_cppflags(' "-Idummypath"') if windows?
695
711
 
696
712
  if config_system_libraries?
697
713
  message "Building nokogiri using system libraries.\n"
698
- ensure_package_configuration(
699
- opt: "zlib",
700
- pc: "zlib",
701
- lib: "z",
702
- headers: "zlib.h",
703
- func: "gzdopen",
704
- )
714
+ if config_with_xml2_legacy?
715
+ ensure_package_configuration(
716
+ opt: "zlib",
717
+ pc: "zlib",
718
+ lib: "z",
719
+ headers: "zlib.h",
720
+ func: "gzdopen",
721
+ )
722
+ end
705
723
  ensure_package_configuration(
706
724
  opt: "xml2",
707
725
  pc: "libxml-2.0",
@@ -745,58 +763,60 @@ else
745
763
  require "yaml"
746
764
  dependencies = YAML.load_file(File.join(PACKAGE_ROOT_DIR, "dependencies.yml"))
747
765
 
748
- dir_config("zlib")
766
+ dir_config("zlib") if config_with_xml2_legacy?
749
767
 
750
768
  if cross_build_p || windows?
751
- zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
752
- recipe.files = [{
753
- url: zlib_source(recipe.version),
754
- sha256: dependencies["zlib"]["sha256"],
755
- }]
756
- if windows?
757
- class << recipe
758
- attr_accessor :cross_build_p
759
-
760
- def configure
761
- Dir.chdir(work_path) do
762
- mk = File.read("win32/Makefile.gcc")
763
- File.open("win32/Makefile.gcc", "wb") do |f|
764
- f.puts "BINARY_PATH = #{path}/bin"
765
- f.puts "LIBRARY_PATH = #{path}/lib"
766
- f.puts "INCLUDE_PATH = #{path}/include"
767
- mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
768
- f.puts mk
769
+ if config_with_xml2_legacy?
770
+ zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
771
+ recipe.files = [{
772
+ url: zlib_source(recipe.version),
773
+ sha256: dependencies["zlib"]["sha256"],
774
+ }]
775
+ if windows?
776
+ class << recipe
777
+ attr_accessor :cross_build_p
778
+
779
+ def configure
780
+ Dir.chdir(work_path) do
781
+ mk = File.read("win32/Makefile.gcc")
782
+ File.open("win32/Makefile.gcc", "wb") do |f|
783
+ f.puts "BINARY_PATH = #{path}/bin"
784
+ f.puts "LIBRARY_PATH = #{path}/lib"
785
+ f.puts "INCLUDE_PATH = #{path}/include"
786
+ mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
787
+ f.puts mk
788
+ end
769
789
  end
770
790
  end
771
- end
772
791
 
773
- def configured?
774
- Dir.chdir(work_path) do
775
- !!(File.read("win32/Makefile.gcc") =~ /^BINARY_PATH/)
792
+ def configured?
793
+ Dir.chdir(work_path) do
794
+ !!(File.read("win32/Makefile.gcc") =~ /^BINARY_PATH/)
795
+ end
776
796
  end
777
- end
778
797
 
779
- def compile
780
- execute("compile", "make -f win32/Makefile.gcc")
781
- end
798
+ def compile
799
+ execute("compile", "make -f win32/Makefile.gcc")
800
+ end
782
801
 
783
- def install
784
- execute("install", "make -f win32/Makefile.gcc install")
802
+ def install
803
+ execute("install", "make -f win32/Makefile.gcc install")
804
+ end
785
805
  end
786
- end
787
- recipe.cross_build_p = cross_build_p
788
- else
789
- class << recipe
790
- def configure
791
- env = {}
792
- env["CFLAGS"] = concat_flags(ENV["CFLAGS"], "-fPIC", "-g")
793
- env["CHOST"] = host
794
- execute("configure", ["./configure", "--static", configure_prefix], { env: env })
795
- if darwin?
796
- # needed as of zlib 1.2.13
797
- Dir.chdir(work_path) do
798
- makefile = File.read("Makefile").gsub(/^AR=.*$/, "AR=#{host}-libtool")
799
- File.open("Makefile", "w") { |m| m.write(makefile) }
806
+ recipe.cross_build_p = cross_build_p
807
+ else
808
+ class << recipe
809
+ def configure
810
+ env = {}
811
+ env["CFLAGS"] = concat_flags(ENV["CFLAGS"], "-fPIC", "-g")
812
+ env["CHOST"] = host
813
+ execute("configure", ["./configure", "--static", configure_prefix], { env: env })
814
+ if darwin?
815
+ # needed as of zlib 1.2.13
816
+ Dir.chdir(work_path) do
817
+ makefile = File.read("Makefile").gsub(/^AR=.*$/, "AR=#{host}-libtool")
818
+ File.open("Makefile", "w") { |m| m.write(makefile) }
819
+ end
800
820
  end
801
821
  end
802
822
  end
@@ -804,7 +824,7 @@ else
804
824
  end
805
825
  end
806
826
 
807
- unless nix?
827
+ unless unix?
808
828
  libiconv_recipe = process_recipe(
809
829
  "libiconv",
810
830
  dependencies["libiconv"]["version"],
@@ -819,7 +839,7 @@ else
819
839
  # The libiconv configure script doesn't accept "arm64" host string but "aarch64"
820
840
  recipe.host = recipe.host.gsub("arm64-apple-darwin", "aarch64-apple-darwin")
821
841
 
822
- cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
842
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-g")
823
843
 
824
844
  recipe.configure_options += [
825
845
  "--disable-dependency-tracking",
@@ -883,12 +903,16 @@ else
883
903
  end
884
904
 
885
905
  cppflags = concat_flags(ENV["CPPFLAGS"])
886
- cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
906
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-g")
887
907
 
888
908
  if cross_build_p
889
909
  cppflags = concat_flags(cppflags, "-DNOKOGIRI_PRECOMPILED_LIBRARIES")
890
910
  end
891
911
 
912
+ if config_with_xml2_legacy?
913
+ recipe.configure_options << "--with-legacy"
914
+ end
915
+
892
916
  if zlib_recipe
893
917
  recipe.configure_options << "--with-zlib=#{zlib_recipe.path}"
894
918
  end
@@ -900,7 +924,8 @@ else
900
924
  end
901
925
 
902
926
  if darwin? && !cross_build_p
903
- recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
927
+ recipe.configure_options << "RANLIB=/usr/bin/ranlib" unless ENV.key?("RANLIB")
928
+ recipe.configure_options << "AR=/usr/bin/ar" unless ENV.key?("AR")
904
929
  end
905
930
 
906
931
  if windows?
@@ -937,10 +962,11 @@ else
937
962
  recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", "libxslt", "*.patch")].sort
938
963
  end
939
964
 
940
- cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
965
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-g")
941
966
 
942
967
  if darwin? && !cross_build_p
943
- recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
968
+ recipe.configure_options << "RANLIB=/usr/bin/ranlib" unless ENV.key?("RANLIB")
969
+ recipe.configure_options << "AR=/usr/bin/ar" unless ENV.key?("AR")
944
970
  end
945
971
 
946
972
  if windows?
@@ -1031,64 +1057,75 @@ else
1031
1057
  ensure_func("exsltFuncRegister", "libexslt/exslt.h")
1032
1058
  end
1033
1059
 
1034
- libgumbo_recipe = process_recipe("libgumbo", "1.0.0-nokogiri", static_p, cross_build_p, false) do |recipe|
1035
- recipe.configure_options = []
1060
+ if arg_config("--gumbo-dev")
1061
+ message("DEV MODE ENABLED: build libgumbo as packaged source")
1062
+ ext_dir = File.dirname(__FILE__)
1063
+ Dir.chdir(ext_dir) do
1064
+ $srcs = Dir["*.c", "../../gumbo-parser/src/*.c"]
1065
+ $hdrs = Dir["*.h", "../../gumbo-parser/src/*.h"]
1066
+ end
1067
+ $INCFLAGS << " -I$(srcdir)/../../gumbo-parser/src"
1068
+ $VPATH << "$(srcdir)/../../gumbo-parser/src"
1069
+ find_header("nokogiri_gumbo.h") || abort("nokogiri_gumbo.h not found")
1070
+ else
1071
+ libgumbo_recipe = process_recipe("libgumbo", "1.0.0-nokogiri", static_p, cross_build_p, false) do |recipe|
1072
+ recipe.configure_options = []
1036
1073
 
1037
- class << recipe
1038
- def downloaded?
1039
- true
1040
- end
1074
+ class << recipe
1075
+ def downloaded?
1076
+ true
1077
+ end
1041
1078
 
1042
- def extract
1043
- target = File.join(tmp_path, "gumbo-parser")
1044
- output("Copying gumbo-parser files into #{target}...")
1045
- FileUtils.mkdir_p(target)
1046
- FileUtils.cp(Dir.glob(File.join(PACKAGE_ROOT_DIR, "gumbo-parser/src/*")), target)
1047
- end
1079
+ def extract
1080
+ target = File.join(tmp_path, "gumbo-parser")
1081
+ output("Copying gumbo-parser files into #{target}...")
1082
+ FileUtils.mkdir_p(target)
1083
+ FileUtils.cp(Dir.glob(File.join(PACKAGE_ROOT_DIR, "gumbo-parser/src/*")), target)
1084
+ end
1048
1085
 
1049
- def configured?
1050
- true
1051
- end
1086
+ def configured?
1087
+ true
1088
+ end
1052
1089
 
1053
- def install
1054
- lib_dir = File.join(port_path, "lib")
1055
- inc_dir = File.join(port_path, "include")
1056
- FileUtils.mkdir_p([lib_dir, inc_dir])
1057
- FileUtils.cp(File.join(work_path, "libgumbo.a"), lib_dir)
1058
- FileUtils.cp(Dir.glob(File.join(work_path, "*.h")), inc_dir)
1059
- end
1090
+ def install
1091
+ lib_dir = File.join(port_path, "lib")
1092
+ inc_dir = File.join(port_path, "include")
1093
+ FileUtils.mkdir_p([lib_dir, inc_dir])
1094
+ FileUtils.cp(File.join(work_path, "libgumbo.a"), lib_dir)
1095
+ FileUtils.cp(Dir.glob(File.join(work_path, "*.h")), inc_dir)
1096
+ end
1060
1097
 
1061
- def compile
1062
- cflags = concat_flags(ENV["CFLAGS"], "-fPIC", "-O2", "-g")
1098
+ def compile
1099
+ cflags = concat_flags(ENV["CFLAGS"], "-fPIC", "-O2", "-g")
1063
1100
 
1064
- env = { "CC" => gcc_cmd, "CFLAGS" => cflags }
1065
- if config_cross_build?
1066
- if host.include?("darwin")
1067
- env["AR"] = "#{host}-libtool"
1068
- env["ARFLAGS"] = "-o"
1069
- else
1070
- env["AR"] = "#{host}-ar"
1101
+ env = { "CC" => gcc_cmd, "CFLAGS" => cflags }
1102
+ if config_cross_build?
1103
+ if host.include?("darwin")
1104
+ env["AR"] = "#{host}-libtool"
1105
+ env["ARFLAGS"] = "-o"
1106
+ else
1107
+ env["AR"] = "#{host}-ar"
1108
+ end
1109
+ env["RANLIB"] = "#{host}-ranlib"
1110
+ if windows?
1111
+ concat_flags(env["CFLAGS"], "-D_RUBY_UCRT")
1112
+ end
1071
1113
  end
1072
- env["RANLIB"] = "#{host}-ranlib"
1073
- end
1074
1114
 
1075
- execute("compile", make_cmd, { env: env })
1115
+ execute("compile", make_cmd, { env: env })
1116
+ end
1076
1117
  end
1077
1118
  end
1119
+ append_cppflags("-I#{File.join(libgumbo_recipe.path, "include")}")
1120
+ $libs = $libs + " " + File.join(libgumbo_recipe.path, "lib", "libgumbo.a")
1121
+ $LIBPATH = $LIBPATH | [File.join(libgumbo_recipe.path, "lib")]
1122
+ ensure_func("gumbo_parse_with_options", "nokogiri_gumbo.h")
1078
1123
  end
1079
- append_cppflags("-I#{File.join(libgumbo_recipe.path, "include")}")
1080
- $libs = $libs + " " + File.join(libgumbo_recipe.path, "lib", "libgumbo.a")
1081
- $LIBPATH = $LIBPATH | [File.join(libgumbo_recipe.path, "lib")]
1082
- ensure_func("gumbo_parse_with_options", "nokogiri_gumbo.h")
1083
-
1084
- have_func("xmlHasFeature") || abort("xmlHasFeature() is missing.") # introduced in libxml 2.6.21
1085
- have_func("xmlFirstElementChild") # introduced in libxml 2.7.3
1086
- have_func("xmlRelaxNGSetParserStructuredErrors") # introduced in libxml 2.6.24
1087
- have_func("xmlRelaxNGSetValidStructuredErrors") # introduced in libxml 2.6.21
1088
- have_func("xmlSchemaSetValidStructuredErrors") # introduced in libxml 2.6.23
1089
- have_func("xmlSchemaSetParserStructuredErrors") # introduced in libxml 2.6.23
1090
- have_func("rb_gc_location") # introduced in Ruby 2.7
1091
- have_func("rb_category_warning") # introduced in Ruby 3.0
1124
+
1125
+ have_func("xmlCtxtSetOptions") # introduced in libxml2 2.13.0
1126
+ have_func("xmlCtxtGetOptions") # introduced in libxml2 2.14.0
1127
+ have_func("xmlSwitchEncodingName") # introduced in libxml2 2.13.0
1128
+ have_func("rb_category_warning") # introduced in Ruby 3.0 but had trouble resolving this symbol in truffleruby
1092
1129
 
1093
1130
  other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k, v| [k, v].join(":") }.join(",")
1094
1131
  append_cppflags(%[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\"#{other_library_versions_string}\\""])
@@ -1119,7 +1156,7 @@ if config_clean?
1119
1156
  mk.print(<<~EOF)
1120
1157
 
1121
1158
  all: clean-ports
1122
- clean-ports: $(DLLIB)
1159
+ clean-ports: $(TARGET_SO)
1123
1160
  \t-$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? "enable" : "disable"}-static
1124
1161
  EOF
1125
1162
  end