nokogiri 1.11.0.rc3-x86-mingw32 → 1.11.0.rc4-x86-mingw32

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +1015 -947
  3. data/README.md +1 -1
  4. data/ext/nokogiri/depend +476 -357
  5. data/ext/nokogiri/extconf.rb +441 -321
  6. data/ext/nokogiri/html_document.c +79 -78
  7. data/ext/nokogiri/html_sax_parser_context.c +2 -2
  8. data/ext/nokogiri/include/libexslt/exslt.h +102 -0
  9. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  10. data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
  11. data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
  12. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  13. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  14. data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
  15. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
  16. data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
  17. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  18. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  19. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  20. data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
  21. data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
  22. data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
  23. data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
  24. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  25. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  26. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
  27. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  28. data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
  29. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
  30. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  31. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
  32. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  33. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  34. data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
  35. data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
  36. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  37. data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
  38. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  39. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  40. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
  41. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  42. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
  43. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
  44. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
  45. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  46. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  47. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  48. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  49. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
  58. data/ext/nokogiri/include/libxslt/attributes.h +38 -0
  59. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  60. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  61. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  62. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  63. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  64. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  65. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  66. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  67. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  68. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  69. data/ext/nokogiri/include/libxslt/security.h +104 -0
  70. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  71. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  72. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  73. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  74. data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
  75. data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
  76. data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
  77. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  78. data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
  79. data/ext/nokogiri/nokogiri.c +34 -46
  80. data/ext/nokogiri/nokogiri.h +22 -26
  81. data/ext/nokogiri/xml_document.c +2 -2
  82. data/ext/nokogiri/xml_node.c +1 -1
  83. data/ext/nokogiri/xml_node_set.c +1 -1
  84. data/ext/nokogiri/xml_relax_ng.c +29 -11
  85. data/ext/nokogiri/xml_sax_parser.c +2 -7
  86. data/ext/nokogiri/xml_sax_parser_context.c +2 -2
  87. data/ext/nokogiri/xml_schema.c +55 -13
  88. data/ext/nokogiri/xml_xpath_context.c +80 -4
  89. data/ext/nokogiri/xslt_stylesheet.c +1 -4
  90. data/lib/nokogiri.rb +1 -1
  91. data/lib/nokogiri/2.5/nokogiri.so +0 -0
  92. data/lib/nokogiri/2.6/nokogiri.so +0 -0
  93. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  94. data/lib/nokogiri/3.0/nokogiri.so +0 -0
  95. data/lib/nokogiri/css/parser.rb +3 -3
  96. data/lib/nokogiri/css/parser.y +2 -2
  97. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  98. data/lib/nokogiri/html/document.rb +12 -26
  99. data/lib/nokogiri/version.rb +2 -149
  100. data/lib/nokogiri/version/constant.rb +5 -0
  101. data/lib/nokogiri/version/info.rb +182 -0
  102. data/lib/nokogiri/xml/document.rb +17 -7
  103. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  104. data/lib/nokogiri/xml/node.rb +50 -27
  105. data/lib/nokogiri/xml/parse_options.rb +6 -0
  106. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  107. data/lib/nokogiri/xml/schema.rb +12 -4
  108. data/lib/nokogiri/xml/searchable.rb +3 -1
  109. metadata +105 -28
  110. data/lib/nokogiri/2.4/nokogiri.so +0 -0
@@ -1,12 +1,110 @@
1
1
  # :stopdoc:
2
2
  ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
3
3
 
4
- require 'mkmf'
4
+ require "mkmf"
5
+ require "rbconfig"
6
+ require "fileutils"
7
+ require "shellwords"
8
+ require "pathname"
5
9
 
6
- ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
+ #
11
+ # helpful constants
12
+ #
13
+ PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
14
+ REQUIRED_LIBXML_VERSION = "2.6.21"
15
+ RECOMMENDED_LIBXML_VERSION = "2.9.3"
16
+
17
+ # The gem version constraint in the Rakefile is not respected at install time.
18
+ # Keep this version in sync with the one in the Rakefile !
19
+ REQUIRED_MINI_PORTILE_VERSION = "~> 2.5.0"
20
+ REQUIRED_PKG_CONFIG_VERSION = "~> 1.1"
21
+
22
+ # Keep track of what versions of what libraries we build against
23
+ OTHER_LIBRARY_VERSIONS = {}
24
+
25
+ NOKOGIRI_HELP_MESSAGE = <<~HELP
26
+ USAGE: ruby #{$0} [options]
27
+
28
+ Flags that are always valid:
29
+
30
+ --use-system-libraries
31
+ Use system libraries instead of building and using the packaged libraries
32
+
33
+ --disable-clean
34
+ Do not clean out intermediate files after successful build
35
+
36
+
37
+ Flags only used when using system libraries:
38
+
39
+ --with-opt-dir=DIRECTORY
40
+ Look for headers and libraries in DIRECTORY
41
+
42
+ --with-zlib-dir=DIR
43
+ Look for zlib header and library in DIRECTORY
44
+
45
+ --with-iconv-dir=DIRECTORY
46
+ Look for iconv header and library in DIRECTORY
47
+
48
+ --with-xml2-dir=DIRECTORY
49
+ Look for xml2 headers and library in DIRECTORY
50
+
51
+ --with-xml2-lib=DIRECTORY
52
+ Look for xml2 library in DIRECTORY
53
+
54
+ --with-xslt-include=DIRECTORY
55
+ Look for xslt headers in DIRECTORY
56
+
57
+ --with-xslt-dir=DIRECTORY
58
+ Look for xslt headers and library in DIRECTORY
59
+
60
+ --with-xslt-lib=DIRECTORY
61
+ Look for xslt library in DIRECTORY
62
+
63
+ --with-xslt-include=DIRECTORY
64
+ Look for xslt headers in DIRECTORY
65
+
66
+ --with-exslt-dir=DIRECTORY
67
+ Look for exslt headers and library in DIRECTORY
68
+
69
+ --with-exslt-lib=DIRECTORY
70
+ Look for exslt library in DIRECTORY
71
+
72
+ --with-exslt-include=DIRECTORY
73
+ Look for exslt headers in DIRECTORY
74
+
75
+
76
+ Flags only used when building and using the packaged libraries:
77
+
78
+ --disable-static
79
+ Do not statically link packaged libraries, instead use shared libraries
80
+
81
+ --enable-cross-build
82
+ Enable cross-build mode. (You probably do not want to set this manually.)
83
+
84
+ Environment variables used:
85
+
86
+ NOKOGIRI_USE_SYSTEM_LIBRARIES
87
+ When set, even if nil or blank, use system libraries instead of building and using the
88
+ packaged libraries. Equivalent to `--use-system-libraries`.
89
+
90
+ CC
91
+ Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
92
+
93
+ CPPFLAGS
94
+ If this string is accepted by the C preprocessor, add it to the flags passed to the C preprocessor
95
+
96
+ CFLAGS
97
+ If this string is accepted by the compiler, add it to the flags passed to the compiler
98
+
99
+ LDFLAGS
100
+ If this string is accepted by the linker, add it to the flags passed to the linker
101
+
102
+ LIBS
103
+ Add this string to the flags passed to the linker
104
+ HELP
7
105
 
8
106
  #
9
- # functions
107
+ # utility functions
10
108
  #
11
109
  def windows?
12
110
  RbConfig::CONFIG['target_os'] =~ /mingw32|mswin/
@@ -32,181 +130,168 @@ def nix?
32
130
  ! (windows? || solaris? || darwin?)
33
131
  end
34
132
 
35
- def sh_export_path path
36
- # because libxslt 1.1.29 configure.in uses AC_PATH_TOOL which treats ":"
37
- # as a $PATH separator, we need to convert windows paths from
38
- #
39
- # C:/path/to/foo
40
- #
41
- # to
42
- #
43
- # /C/path/to/foo
44
- #
45
- # which is sh-compatible, in order to find things properly during
46
- # configuration
47
- if windows?
48
- match = Regexp.new("^([A-Z]):(/.*)").match(path)
49
- if match && match.length == 3
50
- return File.join("/", match[1], match[2])
51
- end
52
- end
53
- path
133
+ def concat_flags *args
134
+ args.compact.join(" ")
54
135
  end
55
136
 
56
- def do_help
57
- print <<HELP
58
- usage: ruby #{$0} [options]
59
-
60
- --disable-clean
61
- Do not clean out intermediate files after successful build.
137
+ def local_have_library(lib, func=nil, headers=nil)
138
+ have_library(lib, func, headers) or have_library("lib#{lib}", func, headers)
139
+ end
62
140
 
63
- --disable-static
64
- Do not statically link bundled libraries.
141
+ LOCAL_PACKAGE_RESPONSE = Object.new
142
+ def LOCAL_PACKAGE_RESPONSE.%(package)
143
+ package ? "yes: #{package}" : "no"
144
+ end
65
145
 
66
- --with-iconv-dir=DIR
67
- Use the iconv library placed under DIR.
146
+ # wrapper around MakeMakefil#pkg_config and the PKGConfig gem
147
+ def try_package_configuration(pc)
148
+ if !ENV.key?("NOKOGIRI_TEST_PKG_CONFIG_GEM")
149
+ # try MakeMakefile#pkg_config, which uses the system utility `pkg-config`.
150
+ return if checking_for("#{pc} using `pkg_config`", LOCAL_PACKAGE_RESPONSE) do
151
+ pkg_config(pc)
152
+ end
153
+ end
68
154
 
69
- --with-zlib-dir=DIR
70
- Use the zlib library placed under DIR.
155
+ # `pkg-config` probably isn't installed, which appears to be the case for lots of freebsd systems.
156
+ # let's fall back to the pkg-config gem, which knows how to parse .pc files, and wrap it with the
157
+ # same logic as MakeMakefile#pkg_config
158
+ begin
159
+ require 'rubygems'
160
+ gem 'pkg-config', REQUIRED_PKG_CONFIG_VERSION
161
+ require 'pkg-config'
71
162
 
72
- --use-system-libraries
73
- Use system libraries instead of building and using the bundled
74
- libraries.
163
+ checking_for("#{pc} using pkg-config gem version #{PKGConfig::VERSION}", LOCAL_PACKAGE_RESPONSE) do
164
+ if PKGConfig.have_package(pc)
165
+ cflags = PKGConfig.cflags(pc)
166
+ ldflags = PKGConfig.libs_only_L(pc)
167
+ libs = PKGConfig.libs_only_l(pc)
75
168
 
76
- --with-xml2-dir=DIR / --with-xml2-config=CONFIG
77
- --with-xslt-dir=DIR / --with-xslt-config=CONFIG
78
- --with-exslt-dir=DIR / --with-exslt-config=CONFIG
79
- Use libxml2/libxslt/libexslt as specified.
169
+ Logging::message "pkg-config gem found package configuration for %s\n", pc
170
+ Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs
80
171
 
81
- --enable-cross-build
82
- Do cross-build.
83
- HELP
84
- exit! 0
172
+ [cflags, ldflags, libs]
173
+ end
174
+ end
175
+ rescue LoadError
176
+ message "Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n"
177
+ end
85
178
  end
86
179
 
87
- def do_clean
88
- require 'pathname'
89
- require 'fileutils'
180
+ # set up mkmf to link against the library if we can find it
181
+ def have_package_configuration(opt: nil, pc: nil, lib:, func:, headers:)
182
+ if opt
183
+ dir_config(opt)
184
+ dir_config("opt")
185
+ end
90
186
 
91
- root = Pathname(ROOT)
92
- pwd = Pathname(Dir.pwd)
187
+ # see if we have enough path info to do this without trying any harder
188
+ if !ENV.key?("NOKOGIRI_TEST_PKG_CONFIG")
189
+ return true if local_have_library(lib, func, headers)
190
+ end
93
191
 
94
- # Skip if this is a development work tree
95
- unless (root + '.git').exist?
96
- message "Cleaning files only used during build.\n"
192
+ try_package_configuration(pc) if pc
97
193
 
98
- # (root + 'tmp') cannot be removed at this stage because
99
- # nokogiri.so is yet to be copied to lib.
194
+ # verify that we can compile and link against the library
195
+ local_have_library(lib, func, headers)
196
+ end
100
197
 
101
- # clean the ports build directory
102
- Pathname.glob(pwd.join('tmp', '*', 'ports')) do |dir|
103
- FileUtils.rm_rf(dir, verbose: true)
104
- end
198
+ def ensure_package_configuration(opt: nil, pc: nil, lib:, func:, headers:)
199
+ have_package_configuration(opt: opt, pc: pc, lib: lib, func: func, headers: headers) or
200
+ abort_could_not_find_library(lib)
201
+ end
105
202
 
106
- if enable_config('static')
107
- # ports installation can be safely removed if statically linked.
108
- FileUtils.rm_rf(root + 'ports', verbose: true)
109
- else
110
- FileUtils.rm_rf(root + 'ports' + 'archives', verbose: true)
111
- end
112
- end
203
+ def ensure_func(func, headers=nil)
204
+ have_func(func, headers) or abort_could_not_find_library(lib)
205
+ end
113
206
 
114
- exit! 0
207
+ def preserving_globals
208
+ values = [$arg_config, $INCFLAGS, $CFLAGS, $CPPFLAGS, $LDFLAGS, $DLDFLAGS, $LIBPATH, $libs].map(&:dup)
209
+ yield
210
+ ensure
211
+ $arg_config, $INCFLAGS, $CFLAGS, $CPPFLAGS, $LDFLAGS, $DLDFLAGS, $LIBPATH, $libs = values
115
212
  end
116
213
 
117
- def package_config pkg, options={}
118
- package = pkg_config(pkg)
119
- return package if package
214
+ def abort_could_not_find_library(lib)
215
+ abort "-----\n#{caller[0]}\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----"
216
+ end
120
217
 
121
- begin
122
- require 'rubygems'
123
- gem 'pkg-config', (gem_ver='~> 1.1')
124
- require 'pkg-config' and message("Using pkg-config gem version #{PKGConfig::VERSION}\n")
125
- rescue LoadError
126
- 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"
127
- else
128
- return nil unless PKGConfig.have_package(pkg)
218
+ def chdir_for_build
219
+ # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
220
+ # folders don't support symlinks, but libiconv expects it for a build on
221
+ # Linux. We work around this limitation by using the temp dir for cooking.
222
+ build_dir = ENV['RCD_HOST_RUBY_PLATFORM'].to_s =~ /mingw|mswin|cygwin/ ? '/tmp' : '.'
223
+ Dir.chdir(build_dir) do
224
+ yield
225
+ end
226
+ end
227
+
228
+ def sh_export_path path
229
+ # because libxslt 1.1.29 configure.in uses AC_PATH_TOOL which treats ":"
230
+ # as a $PATH separator, we need to convert windows paths from
231
+ #
232
+ # C:/path/to/foo
233
+ #
234
+ # to
235
+ #
236
+ # /C/path/to/foo
237
+ #
238
+ # which is sh-compatible, in order to find things properly during
239
+ # configuration
240
+ return path if !windows?
129
241
 
130
- cflags = PKGConfig.cflags(pkg)
131
- ldflags = PKGConfig.libs_only_L(pkg)
132
- libs = PKGConfig.libs_only_l(pkg)
242
+ match = Regexp.new("^([A-Z]):(/.*)").match(path)
243
+ if match && match.length == 3
244
+ return File.join("/", match[1], match[2])
245
+ end
133
246
 
134
- Logging::message "PKGConfig package configuration for %s\n", pkg
135
- Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs
247
+ path
248
+ end
136
249
 
137
- [cflags, ldflags, libs]
250
+ def libflag_to_filename(ldflag)
251
+ case ldflag
252
+ when /\A-l(.+)/
253
+ "lib#{$1}.#{$LIBEXT}"
138
254
  end
139
255
  end
140
256
 
141
- def nokogiri_try_compile
142
- try_compile "int main() {return 0;}", "", {werror: true}
257
+ def using_system_libraries?
258
+ # NOTE: TruffleRuby uses this env var as it does not support using static libraries yet.
259
+ arg_config('--use-system-libraries', ENV.key?("NOKOGIRI_USE_SYSTEM_LIBRARIES"))
143
260
  end
144
261
 
145
- def check_libxml_version version=nil
262
+ def have_libxml_headers?(version=nil)
146
263
  source = if version.nil?
147
- <<-SRC
148
- #include <libxml/xmlversion.h>
264
+ <<~SRC
265
+ #include <libxml/xmlversion.h>
149
266
  SRC
150
267
  else
151
268
  version_int = sprintf "%d%2.2d%2.2d", *(version.split("."))
152
- <<-SRC
153
- #include <libxml/xmlversion.h>
154
- #if LIBXML_VERSION < #{version_int}
155
- #error libxml2 is older than #{version}
156
- #endif
269
+ <<~SRC
270
+ #include <libxml/xmlversion.h>
271
+ #if LIBXML_VERSION < #{version_int}
272
+ # error libxml2 is older than #{version}
273
+ #endif
157
274
  SRC
158
275
  end
159
276
 
160
277
  try_cpp source
161
278
  end
162
279
 
163
- def add_cflags(flags)
164
- print "checking if the C compiler accepts #{flags}... "
165
- with_cflags("#{$CFLAGS} #{flags}") do
166
- if nokogiri_try_compile
167
- puts 'yes'
168
- true
169
- else
170
- puts 'no'
171
- false
172
- end
173
- end
174
- end
175
-
176
- def preserving_globals
177
- values = [
178
- $arg_config,
179
- $CFLAGS, $CPPFLAGS,
180
- $LDFLAGS, $LIBPATH, $libs
181
- ].map(&:dup)
182
- yield
183
- ensure
184
- $arg_config,
185
- $CFLAGS, $CPPFLAGS,
186
- $LDFLAGS, $LIBPATH, $libs =
187
- values
188
- end
189
-
190
- def asplode(lib)
191
- abort "-----\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----"
192
- end
193
-
194
- def have_iconv?(using = nil)
280
+ def try_link_iconv(using = nil)
195
281
  checking_for(using ? "iconv using #{using}" : 'iconv') do
196
282
  ['', '-liconv'].any? do |opt|
197
283
  preserving_globals do
198
284
  yield if block_given?
199
285
 
200
- try_link(<<-'SRC', opt)
201
- #include <stdlib.h>
202
- #include <iconv.h>
203
-
204
- int main(void)
205
- {
206
- iconv_t cd = iconv_open("", "");
207
- iconv(cd, NULL, NULL, NULL, NULL);
208
- return EXIT_SUCCESS;
209
- }
286
+ try_link(<<~'SRC', opt)
287
+ #include <stdlib.h>
288
+ #include <iconv.h>
289
+ int main(void)
290
+ {
291
+ iconv_t cd = iconv_open("", "");
292
+ iconv(cd, NULL, NULL, NULL, NULL);
293
+ return EXIT_SUCCESS;
294
+ }
210
295
  SRC
211
296
  end
212
297
  end
@@ -214,11 +299,10 @@ int main(void)
214
299
  end
215
300
 
216
301
  def iconv_configure_flags
217
- # If --with-iconv-dir or --with-opt-dir is given, it should be
218
- # the first priority
219
- %w[iconv opt].each do |name|
220
- if (config = preserving_globals { dir_config(name) }).any? &&
221
- have_iconv?("--with-#{name}-* flags") { dir_config(name) }
302
+ # give --with-iconv-dir and --with-opt-dir first priority
303
+ ["iconv", "opt"].each do |target|
304
+ config = preserving_globals { dir_config(target) }
305
+ if config.any? && try_link_iconv("--with-#{target}-* flags") { dir_config(target) }
222
306
  idirs, ldirs = config.map do |dirs|
223
307
  Array(dirs).flat_map do |dir|
224
308
  dir.split(File::PATH_SEPARATOR)
@@ -233,12 +317,12 @@ def iconv_configure_flags
233
317
  end
234
318
  end
235
319
 
236
- if have_iconv?
320
+ if try_link_iconv
237
321
  return ['--with-iconv=yes']
238
322
  end
239
323
 
240
- if (config = preserving_globals { package_config('libiconv') }) &&
241
- have_iconv?('pkg-config libiconv') { package_config('libiconv') }
324
+ config = preserving_globals { have_package_configuration('libiconv') }
325
+ if config && try_link_iconv('pkg-config libiconv') { have_package_configuration('libiconv') }
242
326
  cflags, ldflags, libs = config
243
327
 
244
328
  return [
@@ -249,26 +333,25 @@ def iconv_configure_flags
249
333
  ]
250
334
  end
251
335
 
252
- asplode "libiconv"
336
+ abort_could_not_find_library "libiconv"
253
337
  end
254
338
 
255
- # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
256
- # folders don't support symlinks, but libiconv expects it for a build on
257
- # Linux. We work around this limitation by using the temp dir for cooking.
258
- def chdir_for_build
259
- build_dir = ENV['RCD_HOST_RUBY_PLATFORM'].to_s =~ /mingw|mswin|cygwin/ ? '/tmp' : '.'
260
- Dir.chdir(build_dir) do
261
- yield
339
+ def process_recipe(name, version, static_p, cross_p)
340
+ require 'rubygems'
341
+ gem 'mini_portile2', REQUIRED_MINI_PORTILE_VERSION
342
+ require 'mini_portile2'
343
+ message "Using mini_portile version #{MiniPortile::VERSION}\n"
344
+
345
+ if name != "libxml2" && name != "libxslt"
346
+ OTHER_LIBRARY_VERSIONS[name] = version
262
347
  end
263
- end
264
348
 
265
- def process_recipe(name, version, static_p, cross_p)
266
349
  MiniPortile.new(name, version).tap do |recipe|
267
- recipe.target = File.join(ROOT, "ports")
350
+ recipe.target = File.join(PACKAGE_ROOT_DIR, "ports")
268
351
  # Prefer host_alias over host in order to use i586-mingw32msvc as
269
352
  # correct compiler prefix for cross build, but use host if not set.
270
353
  recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
271
- recipe.patch_files = Dir[File.join(ROOT, "patches", name, "*.patch")].sort
354
+ recipe.patch_files = Dir[File.join(PACKAGE_ROOT_DIR, "patches", name, "*.patch")].sort
272
355
  recipe.configure_options << "--libdir=#{File.join(recipe.path, "lib")}"
273
356
 
274
357
  yield recipe
@@ -282,7 +365,11 @@ def process_recipe(name, version, static_p, cross_p)
282
365
  recipe.configure_options.delete_if do |option|
283
366
  case option
284
367
  when /\A(\w+)=(.*)\z/
285
- env[$1] = $2
368
+ if env.key?($1)
369
+ env[$1] = concat_flags(env[$1], $2)
370
+ else
371
+ env[$1] = $2
372
+ end
286
373
  true
287
374
  else
288
375
  false
@@ -294,7 +381,7 @@ def process_recipe(name, version, static_p, cross_p)
294
381
  "--disable-shared",
295
382
  "--enable-static",
296
383
  ]
297
- env['CFLAGS'] = "-fPIC #{env['CFLAGS']}"
384
+ env["CFLAGS"] = concat_flags(env["CFLAGS"], "-fPIC")
298
385
  else
299
386
  recipe.configure_options += [
300
387
  "--enable-shared",
@@ -312,59 +399,50 @@ def process_recipe(name, version, static_p, cross_p)
312
399
  if RbConfig::CONFIG['target_cpu'] == 'universal'
313
400
  %w[CFLAGS LDFLAGS].each do |key|
314
401
  unless env[key].include?('-arch')
315
- env[key] += ' ' + RbConfig::CONFIG['ARCH_FLAG']
402
+ env[key] = concat_flags(env[key], RbConfig::CONFIG['ARCH_FLAG'])
316
403
  end
317
404
  end
318
405
  end
319
406
 
320
407
  recipe.configure_options += env.map do |key, value|
321
- "#{key}=#{value}"
408
+ "#{key}=#{value.strip}"
322
409
  end
323
410
 
324
- message <<-"EOS"
325
- ************************************************************************
326
- IMPORTANT NOTICE:
327
-
328
- Building Nokogiri with a packaged version of #{name}-#{version}#{'.' if recipe.patch_files.empty?}
329
- EOS
411
+ checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
412
+ if File.exist?(checkpoint)
413
+ message "Building Nokogiri with a packaged version of #{name}-#{version}.\n"
414
+ else
415
+ message <<~EOM
416
+ ---------- IMPORTANT NOTICE ----------
417
+ Building Nokogiri with a packaged version of #{name}-#{version}.
418
+ Configuration options: #{recipe.configure_options.shelljoin}
419
+ EOM
330
420
 
331
- unless recipe.patch_files.empty?
332
- message "with the following patches applied:\n"
421
+ unless recipe.patch_files.empty?
422
+ message "The following patches are being applied:\n"
333
423
 
334
- recipe.patch_files.each do |patch|
335
- message "\t- %s\n" % File.basename(patch)
424
+ recipe.patch_files.each do |patch|
425
+ message " - %s\n" % File.basename(patch)
426
+ end
336
427
  end
337
- end
338
-
339
- message <<-"EOS"
340
428
 
341
- Team Nokogiri will keep on doing their best to provide security
342
- updates in a timely manner, but if this is a concern for you and want
343
- to use the system library instead; abort this installation process and
344
- reinstall nokogiri as follows:
429
+ message <<~EOM
345
430
 
346
- gem install nokogiri -- --use-system-libraries
347
- [--with-xml2-config=/path/to/xml2-config]
348
- [--with-xslt-config=/path/to/xslt-config]
431
+ The Nokogiri maintainers intend to provide timely security updates, but if
432
+ this is a concern for you and want to use your OS/distro system library
433
+ instead, then abort this installation process and install nokogiri as
434
+ instructed at:
349
435
 
350
- If you are using Bundler, tell it to use the option:
436
+ https://nokogiri.org/tutorials/installing_nokogiri.html#install-with-system-libraries
351
437
 
352
- bundle config build.nokogiri --use-system-libraries
353
- bundle install
354
- EOS
438
+ EOM
355
439
 
356
- message <<-"EOS" if name == 'libxml2'
440
+ message <<~EOM if name == 'libxml2'
441
+ Note, however, that nokogiri cannot guarantee compatiblity with every
442
+ version of libxml2 that may be provided by OS/package vendors.
357
443
 
358
- Note, however, that nokogiri is not fully compatible with arbitrary
359
- versions of libxml2 provided by OS/package vendors.
360
- EOS
444
+ EOM
361
445
 
362
- message <<-"EOS"
363
- ************************************************************************
364
- EOS
365
-
366
- checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
367
- unless File.exist?(checkpoint)
368
446
  chdir_for_build do
369
447
  recipe.cook
370
448
  end
@@ -374,116 +452,115 @@ versions of libxml2 provided by OS/package vendors.
374
452
  end
375
453
  end
376
454
 
377
- def lib_a(ldflag)
378
- case ldflag
379
- when /\A-l(.+)/
380
- "lib#{$1}.#{$LIBEXT}"
455
+ def copy_packaged_libraries_headers(to_path:, from_recipes:)
456
+ FileUtils.rm_rf(to_path, secure: true)
457
+ FileUtils.mkdir(to_path)
458
+ from_recipes.each do |recipe|
459
+ FileUtils.cp_r(Dir[File.join(recipe.path, 'include/*')], to_path)
381
460
  end
382
461
  end
383
462
 
384
- def using_system_libraries?
385
- arg_config('--use-system-libraries', !!ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'])
463
+ def do_help
464
+ print NOKOGIRI_HELP_MESSAGE
465
+ exit! 0
386
466
  end
387
467
 
388
- #
389
- # main
390
- #
468
+ def do_clean
469
+ root = Pathname(PACKAGE_ROOT_DIR)
470
+ pwd = Pathname(Dir.pwd)
391
471
 
392
- case
393
- when arg_config('--help')
394
- do_help
395
- when arg_config('--clean')
396
- do_clean
397
- end
472
+ # Skip if this is a development work tree
473
+ unless (root + '.git').exist?
474
+ message "Cleaning files only used during build.\n"
475
+
476
+ # (root + 'tmp') cannot be removed at this stage because
477
+ # nokogiri.so is yet to be copied to lib.
398
478
 
399
- if darwin?
400
- ENV['CFLAGS'] = "#{ENV['CFLAGS']} -I /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2"
479
+ # clean the ports build directory
480
+ Pathname.glob(pwd.join('tmp', '*', 'ports')) do |dir|
481
+ FileUtils.rm_rf(dir, verbose: true)
482
+ end
483
+
484
+ if enable_config('static')
485
+ # ports installation can be safely removed if statically linked.
486
+ FileUtils.rm_rf(root + 'ports', verbose: true)
487
+ else
488
+ FileUtils.rm_rf(root + 'ports' + 'archives', verbose: true)
489
+ end
490
+ end
491
+
492
+ exit! 0
401
493
  end
402
494
 
495
+ #
496
+ # main
497
+ #
498
+ do_help if arg_config('--help')
499
+ do_clean if arg_config('--clean')
500
+
403
501
  if openbsd? && !using_system_libraries?
404
502
  if `#{ENV['CC'] || '/usr/bin/cc'} -v 2>&1` !~ /clang/
405
503
  ENV['CC'] ||= find_executable('egcc') or
406
504
  abort "Please install gcc 4.9+ from ports using `pkg_add -v gcc`"
407
505
  end
408
- ENV['CFLAGS'] = "#{ENV['CFLAGS']} -I /usr/local/include"
506
+ append_cppflags "-I/usr/local/include"
409
507
  end
410
508
 
411
509
  if ENV['CC']
412
510
  RbConfig::CONFIG['CC'] = RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC']
413
511
  end
512
+
414
513
  # use same c compiler for libxml and libxslt
415
514
  ENV['CC'] = RbConfig::CONFIG['CC']
416
515
 
417
- $LIBS << " #{ENV["LIBS"]}"
418
-
419
- # Read CFLAGS from ENV and make sure compiling works.
420
- add_cflags(ENV["CFLAGS"])
421
-
422
- if windows?
423
- $CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
424
- end
425
-
426
- if solaris? || aix?
427
- $CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
428
- end
429
-
430
- if darwin?
431
- # Let Apple LLVM/clang 5.1 ignore unknown compiler flags
432
- add_cflags("-Wno-error=unused-command-line-argument-hard-error-in-future")
433
- end
516
+ # adopt environment config
517
+ append_cflags(ENV["CFLAGS"].split(/\s+/)) if !ENV["CFLAGS"].nil?
518
+ append_cppflags(ENV["CPPFLAGS"].split(/\s+/)) if !ENV["CPPFLAGS"].nil?
519
+ append_ldflags(ENV["LDFLAGS"].split(/\s+/)) if !ENV["LDFLAGS"].nil?
520
+ $LIBS = concat_flags($LIBS, ENV["LIBS"])
434
521
 
435
- if nix?
436
- $CFLAGS << " -g -DXP_UNIX"
437
- end
522
+ append_cflags("-g") # always include debugging information
523
+ append_cflags("-Winline") # we use at least one inline function in the C extension
524
+ append_cflags("-Wmissing-noreturn") # good to have no matter what Ruby was compiled with
525
+ append_cflags("-Wno-error=unused-command-line-argument-hard-error-in-future") if darwin?
526
+ # append_cflags(["-Wcast-qual", "-Wwrite-strings"]) # these tend to be noisy, but on occasion useful during development
438
527
 
439
- if RUBY_PLATFORM =~ /mingw/i
440
- # Work around a character escaping bug in MSYS by passing an arbitrary
441
- # double quoted parameter to gcc. See https://sourceforge.net/p/mingw/bugs/2142
442
- $CPPFLAGS << ' "-Idummypath"'
528
+ # Add SDK-specific include path for macOS and brew versions before v2.2.12 (2020-04-08) [#1851, #1801]
529
+ macos_mojave_sdk_include_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2"
530
+ if using_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path)
531
+ append_cppflags("-I#{macos_mojave_sdk_include_path}")
443
532
  end
444
533
 
445
- if RbConfig::CONFIG['CC'] =~ /gcc/
446
- $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
447
- $CFLAGS << " -Wall -Wcast-qual -Wwrite-strings -Wmissing-noreturn -Winline"
448
- end
534
+ # Work around a character escaping bug in MSYS by passing an arbitrary double-quoted parameter to gcc.
535
+ # See https://sourceforge.net/p/mingw/bugs/2142
536
+ append_cppflags(' "-Idummypath"') if windows?
449
537
 
450
- case
451
- when using_system_libraries?
538
+ if using_system_libraries?
452
539
  message "Building nokogiri using system libraries.\n"
540
+ ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z", headers: "zlib.h", func: "gzdopen")
541
+ ensure_package_configuration(opt: "xml2", pc: "libxml-2.0", lib: "xml2", headers: "libxml/parser.h", func: "xmlParseDoc")
542
+ ensure_package_configuration(opt: "xslt", pc: "libxslt", lib: "xslt", headers: "libxslt/xslt.h", func: "xsltParseStylesheetDoc")
543
+ ensure_package_configuration(opt: "exslt", pc: "libexslt", lib: "exslt", headers: "libexslt/exslt.h", func: "exsltFuncRegister")
453
544
 
454
- dir_config('zlib')
455
-
456
- # Using system libraries means we rely on the system libxml2 with
457
- # regard to the iconv support.
458
-
459
- dir_config('xml2').any? or package_config('libxml-2.0')
460
- dir_config('xslt').any? or package_config('libxslt')
461
- dir_config('exslt').any? or package_config('libexslt')
462
-
463
- check_libxml_version or abort "ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed."
464
- check_libxml_version("2.6.21") or abort "ERROR: libxml2 version 2.6.21 or later is required!"
465
- check_libxml_version("2.9.3") or warn "WARNING: libxml2 version 2.9.3 or later is highly recommended, but proceeding anyway."
545
+ have_libxml_headers?(REQUIRED_LIBXML_VERSION) or
546
+ abort "ERROR: libxml2 version #{REQUIRED_LIBXML_VERSION} or later is required!"
547
+ have_libxml_headers?(RECOMMENDED_LIBXML_VERSION) or
548
+ warn "WARNING: libxml2 version #{RECOMMENDED_LIBXML_VERSION} or later is highly recommended, but proceeding anyway."
466
549
 
467
550
  else
468
551
  message "Building nokogiri using packaged libraries.\n"
469
552
 
470
- # The gem version constraint in the Rakefile is not respected at install time.
471
- # Keep this version in sync with the one in the Rakefile !
472
- require 'rubygems'
473
- gem 'mini_portile2', '~> 2.5.0'
474
- require 'mini_portile2'
475
- message "Using mini_portile version #{MiniPortile::VERSION}\n"
553
+ static_p = enable_config("static", true)
554
+ message "Static linking is #{static_p ? "enabled" : "disabled"}.\n"
476
555
 
477
- require 'yaml'
556
+ cross_build_p = enable_config("cross-build")
557
+ message "Cross build is #{cross_build_p ? "enabled" : "disabled"}.\n"
478
558
 
479
- static_p = enable_config('static', true) or
480
- message "Static linking is disabled.\n"
559
+ require 'yaml'
560
+ dependencies = YAML.load_file(File.join(PACKAGE_ROOT_DIR, "dependencies.yml"))
481
561
 
482
562
  dir_config('zlib')
483
563
 
484
- dependencies = YAML.load_file(File.join(ROOT, "dependencies.yml"))
485
-
486
- cross_build_p = enable_config("cross-build")
487
564
  if cross_build_p || windows?
488
565
  zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
489
566
  recipe.files = [{
@@ -525,7 +602,16 @@ else
525
602
  else
526
603
  class << recipe
527
604
  def configure
528
- execute "configure", ["env", "CHOST=#{host}", "CFLAGS=-fPIC #{ENV['CFLAGS']}", "./configure", "--static", configure_prefix]
605
+ cflags = concat_flags(ENV["CFLAGS"], "-fPIC", "-g")
606
+ execute "configure", ["env", "CHOST=#{host}", "CFLAGS=#{cflags}", "./configure", "--static", configure_prefix]
607
+ end
608
+
609
+ def compile
610
+ if host=~/darwin/
611
+ execute "compile", "make AR=#{host}-libtool"
612
+ else
613
+ super
614
+ end
529
615
  end
530
616
  end
531
617
  end
@@ -537,35 +623,37 @@ else
537
623
  url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
538
624
  sha256: dependencies["libiconv"]["sha256"]
539
625
  }]
626
+
627
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
628
+
540
629
  recipe.configure_options += [
541
630
  "CPPFLAGS=-Wall",
542
- "CFLAGS=-O2 -g",
543
- "CXXFLAGS=-O2 -g",
631
+ "CFLAGS=#{cflags}",
632
+ "CXXFLAGS=#{cflags}",
544
633
  "LDFLAGS="
545
634
  ]
546
635
  end
547
636
  end
548
637
  else
549
638
  if darwin? && !have_header('iconv.h')
550
- abort <<'EOM'.chomp
551
- -----
552
- The file "iconv.h" is missing in your build environment,
553
- which means you haven't installed Xcode Command Line Tools properly.
554
-
555
- To install Command Line Tools, try running `xcode-select --install` on
556
- terminal and follow the instructions. If it fails, open Xcode.app,
557
- select from the menu "Xcode" - "Open Developer Tool" - "More Developer
558
- Tools" to open the developer site, download the installer for your OS
559
- version and run it.
560
- -----
561
- EOM
639
+ abort <<~EOM.chomp
640
+ -----
641
+ The file "iconv.h" is missing in your build environment,
642
+ which means you haven't installed Xcode Command Line Tools properly.
643
+
644
+ To install Command Line Tools, try running `xcode-select --install` on
645
+ terminal and follow the instructions. If it fails, open Xcode.app,
646
+ select from the menu "Xcode" - "Open Developer Tool" - "More Developer
647
+ Tools" to open the developer site, download the installer for your OS
648
+ version and run it.
649
+ -----
650
+ EOM
562
651
  end
563
652
  end
564
653
 
565
654
  unless windows?
566
- preserving_globals {
567
- have_library('z', 'gzdopen', 'zlib.h')
568
- } or abort 'zlib is missing; necessary for building libxml2'
655
+ preserving_globals { local_have_library('z', 'gzdopen', 'zlib.h') } or
656
+ abort 'zlib is missing; necessary for building libxml2'
569
657
  end
570
658
 
571
659
  libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
@@ -573,15 +661,31 @@ EOM
573
661
  url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
574
662
  sha256: dependencies["libxml2"]["sha256"]
575
663
  }]
664
+
665
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
666
+
667
+ if zlib_recipe
668
+ recipe.configure_options << "--with-zlib=#{zlib_recipe.path}"
669
+ cflags = concat_flags(cflags, "-I#{zlib_recipe.path}/include")
670
+ end
671
+
672
+ if libiconv_recipe
673
+ recipe.configure_options << "--with-iconv=#{libiconv_recipe.path}"
674
+ else
675
+ recipe.configure_options += iconv_configure_flags
676
+ end
677
+
678
+ if darwin? && !cross_build_p
679
+ recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
680
+ end
681
+
576
682
  recipe.configure_options += [
577
683
  "--without-python",
578
684
  "--without-readline",
579
- *(zlib_recipe ? ["--with-zlib=#{zlib_recipe.path}", "CFLAGS=-I#{zlib_recipe.path}/include"] : []),
580
- *(libiconv_recipe ? "--with-iconv=#{libiconv_recipe.path}" : iconv_configure_flags),
581
685
  "--with-c14n",
582
686
  "--with-debug",
583
687
  "--with-threads",
584
- *(darwin? ? ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"] : "")
688
+ "CFLAGS=#{cflags}",
585
689
  ]
586
690
  end
587
691
 
@@ -590,23 +694,28 @@ EOM
590
694
  url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
591
695
  sha256: dependencies["libxslt"]["sha256"]
592
696
  }]
697
+
698
+ cflags = concat_flags(ENV["CFLAGS"], "-O2", "-U_FORTIFY_SOURCE", "-g")
699
+
700
+ if darwin? && !cross_build_p
701
+ recipe.configure_options += ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"]
702
+ end
703
+
593
704
  recipe.configure_options += [
594
705
  "--without-python",
595
706
  "--without-crypto",
596
707
  "--with-debug",
597
708
  "--with-libxml-prefix=#{sh_export_path(libxml2_recipe.path)}",
598
- *(darwin? ? ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"] : "")
709
+ "CFLAGS=#{cflags}",
599
710
  ]
600
711
  end
601
712
 
602
- $CFLAGS << ' ' << '-DNOKOGIRI_USE_PACKAGED_LIBRARIES'
713
+ append_cppflags("-DNOKOGIRI_PACKAGED_LIBRARIES")
714
+ append_cppflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p
715
+
603
716
  $LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH if zlib_recipe
604
717
  $LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH if libiconv_recipe
605
718
 
606
- have_lzma = preserving_globals {
607
- have_library('lzma')
608
- }
609
-
610
719
  $libs = $libs.shellsplit.tap do |libs|
611
720
  [libxml2_recipe, libxslt_recipe].each do |recipe|
612
721
  libname = recipe.name[/\Alib(.+)\z/, 1]
@@ -617,7 +726,7 @@ EOM
617
726
  case arg
618
727
  when /\A-L(.+)\z/
619
728
  # Prioritize ports' directories
620
- if $1.start_with?(ROOT + '/')
729
+ if $1.start_with?(PACKAGE_ROOT_DIR + '/')
621
730
  $LIBPATH = [$1] | $LIBPATH
622
731
  else
623
732
  $LIBPATH = $LIBPATH | [$1]
@@ -630,14 +739,14 @@ EOM
630
739
  end
631
740
  end
632
741
 
633
- # Defining a macro that expands to a C string; double quotes are significant.
634
- $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATCHES=\"#{recipe.patch_files.map { |path| File.basename(path) }.join(' ')}\"".inspect
742
+ patches_string = recipe.patch_files.map { |path| File.basename(path) }.join(' ')
743
+ append_cppflags(%Q[-DNOKOGIRI_#{recipe.name.upcase}_PATCHES="\\\"#{patches_string}\\\""])
635
744
 
636
745
  case libname
637
746
  when 'xml2'
638
747
  # xslt-config --libs or pkg-config libxslt --libs does not include
639
748
  # -llzma, so we need to add it manually when linking statically.
640
- if static_p && have_lzma
749
+ if static_p && preserving_globals { local_have_library('lzma') }
641
750
  # Add it at the end; GH #988
642
751
  libs << '-llzma'
643
752
  end
@@ -653,46 +762,57 @@ EOM
653
762
  $libs = $libs.shellsplit.map do |arg|
654
763
  case arg
655
764
  when '-lxml2'
656
- File.join(libxml2_recipe.path, 'lib', lib_a(arg))
765
+ File.join(libxml2_recipe.path, 'lib', libflag_to_filename(arg))
657
766
  when '-lxslt', '-lexslt'
658
- File.join(libxslt_recipe.path, 'lib', lib_a(arg))
767
+ File.join(libxslt_recipe.path, 'lib', libflag_to_filename(arg))
659
768
  else
660
769
  arg
661
770
  end
662
771
  end.shelljoin
663
772
  end
664
- end
665
773
 
666
- {
667
- "xml2" => ['xmlParseDoc', 'libxml/parser.h'],
668
- "xslt" => ['xsltParseStylesheetDoc', 'libxslt/xslt.h'],
669
- "exslt" => ['exsltFuncRegister', 'libexslt/exslt.h'],
670
- }.each do |lib, (func, header)|
671
- have_func(func, header) ||
672
- have_library(lib, func, header) ||
673
- have_library("lib#{lib}", func, header) or
674
- asplode("lib#{lib}")
774
+ ensure_func("xmlParseDoc", "libxml/parser.h")
775
+ ensure_func("xsltParseStylesheetDoc", "libxslt/xslt.h")
776
+ ensure_func("exsltFuncRegister", "libexslt/exslt.h")
675
777
  end
676
778
 
677
- have_func('xmlHasFeature') or abort "xmlHasFeature() is missing."
678
- have_func('xmlFirstElementChild')
679
- have_func('xmlRelaxNGSetParserStructuredErrors')
680
- have_func('xmlRelaxNGSetParserStructuredErrors')
681
- have_func('xmlRelaxNGSetValidStructuredErrors')
682
- have_func('xmlSchemaSetValidStructuredErrors')
683
- have_func('xmlSchemaSetParserStructuredErrors')
779
+ have_func('xmlHasFeature') or abort("xmlHasFeature() is missing.") # introduced in libxml 2.6.21
780
+ have_func('xmlFirstElementChild') # introduced in libxml 2.7.3
781
+ have_func('xmlRelaxNGSetParserStructuredErrors') # introduced in libxml 2.6.24
782
+ have_func('xmlRelaxNGSetValidStructuredErrors') # introduced in libxml 2.6.21
783
+ have_func('xmlSchemaSetValidStructuredErrors') # introduced in libxml 2.6.23
784
+ have_func('xmlSchemaSetParserStructuredErrors') # introduced in libxml 2.6.23
785
+
786
+ have_func('vasprintf')
787
+
788
+ other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k,v| [k,v].join(":") }.join(",")
789
+ append_cppflags(%Q[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\\"#{other_library_versions_string}\\\""])
790
+
791
+ unless using_system_libraries?
792
+ if cross_build_p
793
+ # When precompiling native gems, copy packaged libraries' headers to ext/nokogiri/include
794
+ # These are packaged up by the cross-compiling callback in the ExtensionTask
795
+ copy_packaged_libraries_headers(to_path: File.join(PACKAGE_ROOT_DIR, "ext/nokogiri/include"),
796
+ from_recipes: [libxml2_recipe, libxslt_recipe])
797
+ else
798
+ # When compiling during installation, install packaged libraries' header files into ext/nokogiri/include
799
+ copy_packaged_libraries_headers(to_path: "include",
800
+ from_recipes: [libxml2_recipe, libxslt_recipe])
801
+ $INSTALLFILES << ["include/**/*.h", "$(rubylibdir)"]
802
+ end
803
+ end
684
804
 
685
805
  create_makefile('nokogiri/nokogiri')
686
806
 
687
807
  if enable_config('clean', true)
688
808
  # Do not clean if run in a development work tree.
689
809
  File.open('Makefile', 'at') do |mk|
690
- mk.print <<EOF
691
- all: clean-ports
810
+ mk.print <<~EOF
692
811
 
693
- clean-ports: $(DLLIB)
694
- -$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? 'enable' : 'disable'}-static
695
- EOF
812
+ all: clean-ports
813
+ clean-ports: $(DLLIB)
814
+ \t-$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? 'enable' : 'disable'}-static
815
+ EOF
696
816
  end
697
817
  end
698
818