nokogiri 1.6.7.2-java → 1.6.8-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.cross_rubies +2 -0
- data/.travis.yml +19 -9
- data/CHANGELOG.rdoc +73 -5
- data/CONTRIBUTING.md +42 -0
- data/Gemfile +10 -9
- data/LICENSE.txt +1 -1
- data/Manifest.txt +7 -2
- data/README.md +23 -27
- data/ROADMAP.md +11 -1
- data/Rakefile +36 -17
- data/bin/nokogiri +2 -2
- data/dependencies.yml +29 -4
- data/ext/java/nokogiri/HtmlElementDescription.java +5 -2
- data/ext/java/nokogiri/NokogiriService.java +19 -0
- data/ext/java/nokogiri/XmlAttr.java +3 -1
- data/ext/java/nokogiri/XmlDocumentFragment.java +0 -14
- data/ext/java/nokogiri/XmlNode.java +106 -63
- data/ext/java/nokogiri/XmlXpathContext.java +12 -12
- data/ext/java/nokogiri/XsltStylesheet.java +11 -4
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +8 -1
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +1 -2
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +7 -7
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +1 -1
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +0 -1
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +3 -3
- data/ext/java/nokogiri/internals/ParserContext.java +4 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +18 -13
- data/ext/nokogiri/extconf.rb +163 -79
- data/ext/nokogiri/html_document.c +6 -6
- data/ext/nokogiri/html_element_description.c +1 -1
- data/ext/nokogiri/html_entity_lookup.c +1 -1
- data/ext/nokogiri/html_sax_parser_context.c +4 -4
- data/ext/nokogiri/html_sax_push_parser.c +2 -2
- data/ext/nokogiri/nokogiri.c +0 -7
- data/ext/nokogiri/nokogiri.h +1 -34
- data/ext/nokogiri/xml_attr.c +2 -2
- data/ext/nokogiri/xml_comment.c +1 -1
- data/ext/nokogiri/xml_document.c +20 -22
- data/ext/nokogiri/xml_encoding_handler.c +3 -3
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_namespace.c +56 -17
- data/ext/nokogiri/xml_node.c +73 -67
- data/ext/nokogiri/xml_node_set.c +164 -146
- data/ext/nokogiri/xml_node_set.h +3 -4
- data/ext/nokogiri/xml_processing_instruction.c +2 -2
- data/ext/nokogiri/xml_reader.c +5 -18
- data/ext/nokogiri/xml_sax_parser.c +9 -12
- data/ext/nokogiri/xml_sax_parser_context.c +1 -1
- data/ext/nokogiri/xml_sax_push_parser.c +1 -1
- data/ext/nokogiri/xml_schema.c +1 -1
- data/ext/nokogiri/xml_syntax_error.c +0 -4
- data/ext/nokogiri/xml_syntax_error.h +0 -1
- data/ext/nokogiri/xml_text.c +1 -1
- data/ext/nokogiri/xml_xpath_context.c +15 -24
- data/ext/nokogiri/xslt_stylesheet.c +6 -6
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri.rb +14 -7
- data/lib/nokogiri/css/parser.rb +8 -2
- data/lib/nokogiri/css/parser.y +7 -2
- data/lib/nokogiri/html/document.rb +4 -2
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml/document.rb +7 -1
- data/lib/nokogiri/xml/dtd.rb +4 -4
- data/lib/nokogiri/xml/node.rb +6 -10
- data/lib/nokogiri/xml/node_set.rb +3 -3
- data/lib/nokogiri/xml/parse_options.rb +22 -0
- data/lib/serializer.jar +0 -0
- data/lib/xalan.jar +0 -0
- data/lib/xercesImpl.jar +0 -0
- data/lib/xml-apis.jar +0 -0
- data/tasks/test.rb +5 -0
- data/test/css/test_parser.rb +7 -1
- data/test/files/GH_1042.html +18 -0
- data/test/files/namespace_pressure_test.xml +1684 -0
- data/test/files/tlm.html +2 -1
- data/test/helper.rb +4 -0
- data/test/html/sax/test_parser.rb +2 -2
- data/test/html/test_document.rb +47 -11
- data/test/html/test_document_encoding.rb +55 -58
- data/test/html/test_document_fragment.rb +27 -23
- data/test/html/test_node.rb +16 -0
- data/test/html/test_node_encoding.rb +71 -13
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +14 -0
- data/test/test_css_cache.rb +1 -1
- data/test/test_encoding_handler.rb +2 -0
- data/test/test_xslt_transforms.rb +38 -3
- data/test/xml/sax/test_parser.rb +54 -53
- data/test/xml/test_document.rb +7 -2
- data/test/xml/test_document_encoding.rb +19 -16
- data/test/xml/test_document_fragment.rb +12 -0
- data/test/xml/test_dtd_encoding.rb +0 -2
- data/test/xml/test_namespace.rb +2 -2
- data/test/xml/test_node.rb +15 -4
- data/test/xml/test_node_attributes.rb +6 -0
- data/test/xml/test_node_encoding.rb +49 -87
- data/test/xml/test_node_reparenting.rb +193 -18
- data/test/xml/test_node_set.rb +1 -1
- data/test/xml/test_reader.rb +589 -0
- data/test/xml/test_reader_encoding.rb +100 -102
- data/test/xml/test_unparented_node.rb +14 -1
- data/test/xslt/test_exception_handling.rb +1 -1
- data/test_all +47 -33
- metadata +38 -36
- data/CHANGELOG.ja.rdoc +0 -1057
- data/test/test_reader.rb +0 -558
@@ -35,6 +35,7 @@ package nokogiri;
|
|
35
35
|
import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
36
36
|
import static nokogiri.internals.NokogiriHelpers.stringOrBlank;
|
37
37
|
|
38
|
+
import java.io.ByteArrayOutputStream;
|
38
39
|
import java.io.IOException;
|
39
40
|
import java.io.PipedReader;
|
40
41
|
import java.io.PipedWriter;
|
@@ -58,6 +59,8 @@ import javax.xml.transform.stream.StreamSource;
|
|
58
59
|
|
59
60
|
import nokogiri.internals.NokogiriXsltErrorListener;
|
60
61
|
|
62
|
+
import org.apache.xalan.transformer.TransformerImpl;
|
63
|
+
import org.apache.xml.serializer.SerializationHandler;
|
61
64
|
import org.jruby.Ruby;
|
62
65
|
import org.jruby.RubyArray;
|
63
66
|
import org.jruby.RubyClass;
|
@@ -194,10 +197,14 @@ public class XsltStylesheet extends RubyObject {
|
|
194
197
|
}
|
195
198
|
|
196
199
|
@JRubyMethod
|
197
|
-
public IRubyObject serialize(ThreadContext context, IRubyObject doc) {
|
198
|
-
|
199
|
-
|
200
|
-
|
200
|
+
public IRubyObject serialize(ThreadContext context, IRubyObject doc) throws IOException, TransformerException {
|
201
|
+
XmlDocument xmlDoc = (XmlDocument) doc;
|
202
|
+
TransformerImpl transformer = (TransformerImpl) this.sheet.newTransformer();
|
203
|
+
ByteArrayOutputStream writer = new ByteArrayOutputStream();
|
204
|
+
StreamResult streamResult = new StreamResult(writer);
|
205
|
+
SerializationHandler serializationHandler = transformer.createSerializationHandler(streamResult);
|
206
|
+
serializationHandler.serialize(xmlDoc.getNode());
|
207
|
+
return context.getRuntime().newString(writer.toString());
|
201
208
|
}
|
202
209
|
|
203
210
|
@JRubyMethod(rest = true, required=1, optional=2)
|
@@ -65,7 +65,9 @@ import org.w3c.dom.NodeList;
|
|
65
65
|
*/
|
66
66
|
public class HtmlDomParserContext extends XmlDomParserContext {
|
67
67
|
|
68
|
-
|
68
|
+
private String encoding;
|
69
|
+
|
70
|
+
public HtmlDomParserContext(Ruby runtime, IRubyObject options) {
|
69
71
|
super(runtime, options);
|
70
72
|
}
|
71
73
|
|
@@ -102,6 +104,11 @@ public class HtmlDomParserContext extends XmlDomParserContext {
|
|
102
104
|
setFeature("http://cyberneko.org/html/features/report-errors", true);
|
103
105
|
setFeature("http://xml.org/sax/features/namespaces", false);
|
104
106
|
}
|
107
|
+
|
108
|
+
@Override
|
109
|
+
public void setEncoding(String encoding) {
|
110
|
+
super.setEncoding(encoding);
|
111
|
+
}
|
105
112
|
|
106
113
|
/**
|
107
114
|
* Enable NekoHTML feature for balancing tags in a document fragment.
|
@@ -80,7 +80,6 @@ public abstract class NokogiriErrorHandler implements ErrorHandler, XMLErrorHand
|
|
80
80
|
}
|
81
81
|
|
82
82
|
protected boolean usesNekoHtml(String domain) {
|
83
|
-
|
84
|
-
else return false;
|
83
|
+
return "http://cyberneko.org/html".equals(domain);
|
85
84
|
}
|
86
85
|
}
|
@@ -119,12 +119,12 @@ public class NokogiriHelpers {
|
|
119
119
|
if (node.getNodeType() == Node.ATTRIBUTE_NODE && isNamespace(node.getNodeName())) {
|
120
120
|
XmlDocument xmlDocument = (XmlDocument)node.getOwnerDocument().getUserData(CACHED_NODE);
|
121
121
|
if (!(xmlDocument instanceof HtmlDocument)) {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
122
|
+
String prefix = getLocalNameForNamespace(((Attr)node).getName());
|
123
|
+
prefix = prefix != null ? prefix : "";
|
124
|
+
String href = ((Attr)node).getValue();
|
125
|
+
XmlNamespace xmlNamespace = xmlDocument.getNamespaceCache().get(prefix, href);
|
126
|
+
if (xmlNamespace != null) return xmlNamespace;
|
127
|
+
else return XmlNamespace.createFromAttr(ruby, (Attr)node);
|
128
128
|
}
|
129
129
|
}
|
130
130
|
XmlNode xmlNode = getCachedNode(node);
|
@@ -134,7 +134,7 @@ public class NokogiriHelpers {
|
|
134
134
|
}
|
135
135
|
return xmlNode;
|
136
136
|
}
|
137
|
-
|
137
|
+
|
138
138
|
/**
|
139
139
|
* Construct a new XmlNode wrapping <code>node</code>. The proper
|
140
140
|
* subclass of XmlNode is chosen based on the type of
|
@@ -115,7 +115,7 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
|
|
115
115
|
* @param e Exception.
|
116
116
|
*/
|
117
117
|
public void warning(String domain, String key, XMLParseException e) {
|
118
|
-
|
118
|
+
errors.add(e);
|
119
119
|
}
|
120
120
|
|
121
121
|
}
|
@@ -52,17 +52,17 @@ public class NokogiriXsltErrorListener implements ErrorListener {
|
|
52
52
|
private String errorMessage = null;
|
53
53
|
private Exception exception = null;
|
54
54
|
|
55
|
-
public void warning(TransformerException ex)
|
55
|
+
public void warning(TransformerException ex) {
|
56
56
|
type = ErrorType.WARNING;
|
57
57
|
setError(ex);
|
58
58
|
}
|
59
59
|
|
60
|
-
public void error(TransformerException ex)
|
60
|
+
public void error(TransformerException ex) {
|
61
61
|
type = ErrorType.ERROR;
|
62
62
|
setError(ex);
|
63
63
|
}
|
64
64
|
|
65
|
-
public void fatalError(TransformerException ex)
|
65
|
+
public void fatalError(TransformerException ex) {
|
66
66
|
type = ErrorType.FATAL;
|
67
67
|
setError(ex);
|
68
68
|
}
|
@@ -190,6 +190,10 @@ public class ParserContext extends RubyObject {
|
|
190
190
|
}
|
191
191
|
return false;
|
192
192
|
}
|
193
|
+
|
194
|
+
protected void setEncoding(String encoding) {
|
195
|
+
source.setEncoding(encoding);
|
196
|
+
}
|
193
197
|
|
194
198
|
/**
|
195
199
|
* Set the InputSource to read from <code>file</code>, a String filename.
|
@@ -741,6 +741,10 @@ public class SaveContextVisitor {
|
|
741
741
|
return htmlDoc && text.getParentNode().getNodeName().equals("script");
|
742
742
|
}
|
743
743
|
|
744
|
+
private boolean isHtmlStyle(Text text) {
|
745
|
+
return htmlDoc && text.getParentNode().getNodeName().equals("style");
|
746
|
+
}
|
747
|
+
|
744
748
|
private static char lineSeparator = '\n'; // System.getProperty("line.separator"); ?
|
745
749
|
public boolean enter(Text text) {
|
746
750
|
String textContent = text.getNodeValue();
|
@@ -752,7 +756,7 @@ public class SaveContextVisitor {
|
|
752
756
|
}
|
753
757
|
}
|
754
758
|
|
755
|
-
if (NokogiriHelpers.shouldEncode(text) && !isHtmlScript(text)) {
|
759
|
+
if (NokogiriHelpers.shouldEncode(text) && !isHtmlScript(text) && !isHtmlStyle(text)) {
|
756
760
|
textContent = encodeJavaString(textContent);
|
757
761
|
}
|
758
762
|
|
@@ -761,24 +765,25 @@ public class SaveContextVisitor {
|
|
761
765
|
return true;
|
762
766
|
}
|
763
767
|
|
764
|
-
private String getEncoding(Text text) {
|
765
|
-
if (encoding != null) return encoding;
|
766
|
-
encoding = text.getOwnerDocument().getInputEncoding();
|
767
|
-
return encoding;
|
768
|
-
}
|
769
|
-
|
770
768
|
private String encodeStringToHtmlEntity(String text) {
|
771
769
|
if (encoding == null)
|
772
770
|
return text;
|
773
771
|
CharsetEncoder encoder = Charset.forName(encoding).newEncoder();
|
774
|
-
int last = 126; // = U+007E. No need to encode under U+007E.
|
775
772
|
StringBuffer sb = new StringBuffer();
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
773
|
+
// make sure we can handle code points that are higher than 2 bytes
|
774
|
+
for (int i = 0; i < text.length();) {
|
775
|
+
int code = text.codePointAt(i);
|
776
|
+
// TODO not sure about bigger offset then 2 ?!
|
777
|
+
int offset = code > 65535 ? 2 : 1;
|
778
|
+
boolean canEncode = encoder.canEncode(text.substring(i, i + offset));
|
779
|
+
if (canEncode) {
|
780
|
+
sb.append(text.substring(i, i + offset));
|
781
|
+
}
|
782
|
+
else {
|
783
|
+
sb.append("&#x" + Integer.toHexString(code) + ";");
|
784
|
+
}
|
785
|
+
i += offset;
|
780
786
|
}
|
781
787
|
return new String(sb);
|
782
788
|
}
|
783
|
-
|
784
789
|
}
|
data/ext/nokogiri/extconf.rb
CHANGED
@@ -8,6 +8,42 @@ ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
|
8
8
|
#
|
9
9
|
# functions
|
10
10
|
#
|
11
|
+
def windows?
|
12
|
+
RbConfig::CONFIG['target_os'] =~ /mingw32|mswin/
|
13
|
+
end
|
14
|
+
|
15
|
+
def solaris?
|
16
|
+
RbConfig::CONFIG['target_os'] =~ /solaris/
|
17
|
+
end
|
18
|
+
|
19
|
+
def darwin?
|
20
|
+
RbConfig::CONFIG['target_os'] =~ /darwin/
|
21
|
+
end
|
22
|
+
|
23
|
+
def nix?
|
24
|
+
! (windows? || solaris? || darwin?)
|
25
|
+
end
|
26
|
+
|
27
|
+
def sh_export_path path
|
28
|
+
# because libxslt 1.1.29 configure.in uses AC_PATH_TOOL which treats ":"
|
29
|
+
# as a $PATH separator, we need to convert windows paths from
|
30
|
+
#
|
31
|
+
# C:/path/to/foo
|
32
|
+
#
|
33
|
+
# to
|
34
|
+
#
|
35
|
+
# /C/path/to/foo
|
36
|
+
#
|
37
|
+
# which is sh-compatible, in order to find things properly during
|
38
|
+
# configuration
|
39
|
+
if windows?
|
40
|
+
match = Regexp.new("^([A-Z]):(/.*)").match(path)
|
41
|
+
if match && match.length == 3
|
42
|
+
return File.join("/", match[1], match[2])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
path
|
46
|
+
end
|
11
47
|
|
12
48
|
def do_help
|
13
49
|
print <<HELP
|
@@ -55,10 +91,9 @@ def do_clean
|
|
55
91
|
# nokogiri.so is yet to be copied to lib.
|
56
92
|
|
57
93
|
# clean the ports build directory
|
58
|
-
Pathname.glob(pwd.join('tmp', '*', 'ports'))
|
94
|
+
Pathname.glob(pwd.join('tmp', '*', 'ports')) do |dir|
|
59
95
|
FileUtils.rm_rf(dir, verbose: true)
|
60
|
-
|
61
|
-
}
|
96
|
+
end
|
62
97
|
|
63
98
|
if enable_config('static')
|
64
99
|
# ports installation can be safely removed if statically linked.
|
@@ -71,6 +106,29 @@ def do_clean
|
|
71
106
|
exit! 0
|
72
107
|
end
|
73
108
|
|
109
|
+
# The gem version constraint in the Rakefile is not respected at install time.
|
110
|
+
# Keep this version in sync with the one in the Rakefile !
|
111
|
+
require 'rubygems'
|
112
|
+
gem 'pkg-config', '~> 1.1.7'
|
113
|
+
require 'pkg-config'
|
114
|
+
message "Using pkg-config version #{PKGConfig::VERSION}\n"
|
115
|
+
|
116
|
+
def package_config pkg, options={}
|
117
|
+
package = pkg_config(pkg)
|
118
|
+
return package if package
|
119
|
+
|
120
|
+
return nil unless PKGConfig.have_package(pkg)
|
121
|
+
|
122
|
+
cflags = PKGConfig.cflags(pkg)
|
123
|
+
ldflags = PKGConfig.libs_only_L(pkg)
|
124
|
+
libs = PKGConfig.libs_only_l(pkg)
|
125
|
+
|
126
|
+
Logging::message "PKGConfig package configuration for %s\n", pkg
|
127
|
+
Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs
|
128
|
+
|
129
|
+
[cflags, ldflags, libs]
|
130
|
+
end
|
131
|
+
|
74
132
|
def nokogiri_try_compile
|
75
133
|
args = if defined?(RUBY_VERSION) && RUBY_VERSION <= "1.9.2"
|
76
134
|
["int main() {return 0;}"]
|
@@ -80,6 +138,23 @@ def nokogiri_try_compile
|
|
80
138
|
try_compile(*args)
|
81
139
|
end
|
82
140
|
|
141
|
+
def check_libxml_version version=nil
|
142
|
+
source = if version.nil?
|
143
|
+
<<-SRC
|
144
|
+
#include <libxml/xmlversion.h>
|
145
|
+
SRC
|
146
|
+
else
|
147
|
+
version_int = sprintf "%d%2.2d%2.2d", *(version.split("."))
|
148
|
+
<<-SRC
|
149
|
+
#include <libxml/xmlversion.h>
|
150
|
+
#if LIBXML_VERSION < #{version_int}
|
151
|
+
#error libxml2 is older than #{version}
|
152
|
+
#endif
|
153
|
+
SRC
|
154
|
+
end
|
155
|
+
|
156
|
+
try_cpp source
|
157
|
+
end
|
83
158
|
|
84
159
|
def add_cflags(flags)
|
85
160
|
print "checking if the C compiler accepts #{flags}... "
|
@@ -113,9 +188,9 @@ def asplode(lib)
|
|
113
188
|
end
|
114
189
|
|
115
190
|
def have_iconv?(using = nil)
|
116
|
-
checking_for(using ? "iconv using #{using}" : 'iconv')
|
117
|
-
['', '-liconv'].any?
|
118
|
-
preserving_globals
|
191
|
+
checking_for(using ? "iconv using #{using}" : 'iconv') do
|
192
|
+
['', '-liconv'].any? do |opt|
|
193
|
+
preserving_globals do
|
119
194
|
yield if block_given?
|
120
195
|
|
121
196
|
try_link(<<-'SRC', opt)
|
@@ -129,22 +204,22 @@ int main(void)
|
|
129
204
|
return EXIT_SUCCESS;
|
130
205
|
}
|
131
206
|
SRC
|
132
|
-
|
133
|
-
|
134
|
-
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
135
210
|
end
|
136
211
|
|
137
212
|
def iconv_configure_flags
|
138
213
|
# If --with-iconv-dir or --with-opt-dir is given, it should be
|
139
214
|
# the first priority
|
140
|
-
%w[iconv opt].each
|
215
|
+
%w[iconv opt].each do |name|
|
141
216
|
if (config = preserving_globals { dir_config(name) }).any? &&
|
142
|
-
|
143
|
-
idirs, ldirs = config.map
|
144
|
-
Array(dirs).flat_map
|
217
|
+
have_iconv?("--with-#{name}-* flags") { dir_config(name) }
|
218
|
+
idirs, ldirs = config.map do |dirs|
|
219
|
+
Array(dirs).flat_map do |dir|
|
145
220
|
dir.split(File::PATH_SEPARATOR)
|
146
|
-
|
147
|
-
|
221
|
+
end if dirs
|
222
|
+
end
|
148
223
|
|
149
224
|
return [
|
150
225
|
'--with-iconv=yes',
|
@@ -152,14 +227,14 @@ def iconv_configure_flags
|
|
152
227
|
*("LDFLAGS=#{ldirs.map { |dir| '-L' << dir }.join(' ')}" if ldirs),
|
153
228
|
]
|
154
229
|
end
|
155
|
-
|
230
|
+
end
|
156
231
|
|
157
232
|
if have_iconv?
|
158
233
|
return ['--with-iconv=yes']
|
159
234
|
end
|
160
235
|
|
161
|
-
if (config = preserving_globals {
|
162
|
-
have_iconv?('pkg-config libiconv') {
|
236
|
+
if (config = preserving_globals { package_config('libiconv') }) &&
|
237
|
+
have_iconv?('pkg-config libiconv') { package_config('libiconv') }
|
163
238
|
cflags, ldflags, libs = config
|
164
239
|
|
165
240
|
return [
|
@@ -193,13 +268,13 @@ def process_recipe(name, version, static_p, cross_p)
|
|
193
268
|
|
194
269
|
yield recipe
|
195
270
|
|
196
|
-
env = Hash.new
|
271
|
+
env = Hash.new do |hash, key|
|
197
272
|
hash[key] = "#{ENV[key]}" # (ENV[key].dup rescue '')
|
198
|
-
|
273
|
+
end
|
199
274
|
|
200
275
|
recipe.configure_options.flatten!
|
201
276
|
|
202
|
-
recipe.configure_options.delete_if
|
277
|
+
recipe.configure_options.delete_if do |option|
|
203
278
|
case option
|
204
279
|
when /\A(\w+)=(.*)\z/
|
205
280
|
env[$1] = $2
|
@@ -207,7 +282,7 @@ def process_recipe(name, version, static_p, cross_p)
|
|
207
282
|
else
|
208
283
|
false
|
209
284
|
end
|
210
|
-
|
285
|
+
end
|
211
286
|
|
212
287
|
if static_p
|
213
288
|
recipe.configure_options += [
|
@@ -230,16 +305,16 @@ def process_recipe(name, version, static_p, cross_p)
|
|
230
305
|
end
|
231
306
|
|
232
307
|
if RbConfig::CONFIG['target_cpu'] == 'universal'
|
233
|
-
%w[CFLAGS LDFLAGS].each
|
308
|
+
%w[CFLAGS LDFLAGS].each do |key|
|
234
309
|
unless env[key].include?('-arch')
|
235
310
|
env[key] << ' ' << RbConfig::CONFIG['ARCH_FLAG']
|
236
311
|
end
|
237
|
-
|
312
|
+
end
|
238
313
|
end
|
239
314
|
|
240
|
-
recipe.configure_options += env.map
|
315
|
+
recipe.configure_options += env.map do |key, value|
|
241
316
|
"#{key}=#{value}"
|
242
|
-
|
317
|
+
end
|
243
318
|
|
244
319
|
message <<-"EOS"
|
245
320
|
************************************************************************
|
@@ -251,9 +326,9 @@ Building Nokogiri with a packaged version of #{name}-#{version}#{'.' if recipe.p
|
|
251
326
|
unless recipe.patch_files.empty?
|
252
327
|
message "with the following patches applied:\n"
|
253
328
|
|
254
|
-
recipe.patch_files.each
|
329
|
+
recipe.patch_files.each do |patch|
|
255
330
|
message "\t- %s\n" % File.basename(patch)
|
256
|
-
|
331
|
+
end
|
257
332
|
end
|
258
333
|
|
259
334
|
message <<-"EOS"
|
@@ -325,7 +400,10 @@ when arg_config('--clean')
|
|
325
400
|
end
|
326
401
|
|
327
402
|
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
|
403
|
+
# use same c compiler for libxml and libxslt
|
404
|
+
ENV['CC'] = RbConfig::MAKEFILE_CONFIG['CC']
|
328
405
|
|
406
|
+
# TODO: deprecate MacRuby: https://github.com/sparklemotion/nokogiri/issues/1474
|
329
407
|
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
|
330
408
|
$LIBRUBYARG_STATIC.gsub!(/-static/, '')
|
331
409
|
end
|
@@ -335,17 +413,20 @@ $LIBS << " #{ENV["LIBS"]}"
|
|
335
413
|
# Read CFLAGS from ENV and make sure compiling works.
|
336
414
|
add_cflags(ENV["CFLAGS"])
|
337
415
|
|
338
|
-
|
339
|
-
when 'mingw32', /mswin/
|
340
|
-
windows_p = true
|
416
|
+
if windows?
|
341
417
|
$CFLAGS << " -DXP_WIN -DXP_WIN32 -DUSE_INCLUDED_VASPRINTF"
|
342
|
-
|
418
|
+
end
|
419
|
+
|
420
|
+
if solaris?
|
343
421
|
$CFLAGS << " -DUSE_INCLUDED_VASPRINTF"
|
344
|
-
|
345
|
-
|
422
|
+
end
|
423
|
+
|
424
|
+
if darwin?
|
346
425
|
# Let Apple LLVM/clang 5.1 ignore unknown compiler flags
|
347
426
|
add_cflags("-Wno-error=unused-command-line-argument-hard-error-in-future")
|
348
|
-
|
427
|
+
end
|
428
|
+
|
429
|
+
if nix?
|
349
430
|
$CFLAGS << " -g -DXP_UNIX"
|
350
431
|
end
|
351
432
|
|
@@ -369,31 +450,21 @@ when using_system_libraries?
|
|
369
450
|
# Using system libraries means we rely on the system libxml2 with
|
370
451
|
# regard to the iconv support.
|
371
452
|
|
372
|
-
dir_config('xml2').any? or
|
373
|
-
dir_config('xslt').any? or
|
374
|
-
dir_config('exslt').any? or
|
375
|
-
|
376
|
-
try_cpp(<<-SRC) or abort "libxml2 version 2.6.21 or later is required!"
|
377
|
-
#include <libxml/xmlversion.h>
|
453
|
+
dir_config('xml2').any? or package_config('libxml-2.0')
|
454
|
+
dir_config('xslt').any? or package_config('libxslt')
|
455
|
+
dir_config('exslt').any? or package_config('libexslt')
|
378
456
|
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
SRC
|
457
|
+
check_libxml_version or abort "ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed."
|
458
|
+
check_libxml_version("2.6.21") or abort "ERROR: libxml2 version 2.6.21 or later is required!"
|
459
|
+
check_libxml_version("2.9.3") or warn "WARNING: libxml2 version 2.9.3 or later is highly recommended, but proceeding anyway."
|
383
460
|
|
384
|
-
try_cpp(<<-SRC) or warn "libxml2 version 2.9.2 or later is highly recommended, but proceeding anyway."
|
385
|
-
#include <libxml/xmlversion.h>
|
386
|
-
|
387
|
-
#if LIBXML_VERSION < 20902
|
388
|
-
#error libxml2 is too old
|
389
|
-
#endif
|
390
|
-
SRC
|
391
461
|
else
|
392
462
|
message "Building nokogiri using packaged libraries.\n"
|
393
463
|
|
394
464
|
# The gem version constraint in the Rakefile is not respected at install time.
|
395
465
|
# Keep this version in sync with the one in the Rakefile !
|
396
|
-
|
466
|
+
require 'rubygems'
|
467
|
+
gem 'mini_portile2', '~> 2.1.0'
|
397
468
|
require 'mini_portile2'
|
398
469
|
message "Using mini_portile version #{MiniPortile::VERSION}\n"
|
399
470
|
|
@@ -407,9 +478,12 @@ else
|
|
407
478
|
dependencies = YAML.load_file(File.join(ROOT, "dependencies.yml"))
|
408
479
|
|
409
480
|
cross_build_p = enable_config("cross-build")
|
410
|
-
if cross_build_p ||
|
411
|
-
zlib_recipe = process_recipe("zlib", dependencies["zlib"], static_p, cross_build_p) do |recipe|
|
412
|
-
recipe.files = [
|
481
|
+
if cross_build_p || windows?
|
482
|
+
zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
|
483
|
+
recipe.files = [{
|
484
|
+
url: "http://zlib.net/#{recipe.name}-#{recipe.version}.tar.gz",
|
485
|
+
md5: dependencies["zlib"]["md5"]
|
486
|
+
}]
|
413
487
|
class << recipe
|
414
488
|
attr_accessor :cross_build_p
|
415
489
|
|
@@ -443,8 +517,11 @@ else
|
|
443
517
|
recipe.cross_build_p = cross_build_p
|
444
518
|
end
|
445
519
|
|
446
|
-
libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"], static_p, cross_build_p) do |recipe|
|
447
|
-
recipe.files = [
|
520
|
+
libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p, cross_build_p) do |recipe|
|
521
|
+
recipe.files = [{
|
522
|
+
url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
|
523
|
+
md5: dependencies["libiconv"]["md5"]
|
524
|
+
}]
|
448
525
|
recipe.configure_options += [
|
449
526
|
"CPPFLAGS=-Wall",
|
450
527
|
"CFLAGS=-O2 -g",
|
@@ -453,7 +530,7 @@ else
|
|
453
530
|
]
|
454
531
|
end
|
455
532
|
else
|
456
|
-
if
|
533
|
+
if darwin? && !have_header('iconv.h')
|
457
534
|
abort <<'EOM'.chomp
|
458
535
|
-----
|
459
536
|
The file "iconv.h" is missing in your build environment,
|
@@ -469,17 +546,21 @@ EOM
|
|
469
546
|
end
|
470
547
|
end
|
471
548
|
|
472
|
-
unless
|
549
|
+
unless windows?
|
473
550
|
preserving_globals {
|
474
551
|
have_library('z', 'gzdopen', 'zlib.h')
|
475
552
|
} or abort 'zlib is missing; necessary for building libxml2'
|
476
553
|
end
|
477
554
|
|
478
|
-
libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"], static_p, cross_build_p) do |recipe|
|
479
|
-
recipe.files = [
|
555
|
+
libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
|
556
|
+
recipe.files = [{
|
557
|
+
url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
|
558
|
+
md5: dependencies["libxml2"]["md5"]
|
559
|
+
}]
|
480
560
|
recipe.configure_options += [
|
481
561
|
"--without-python",
|
482
562
|
"--without-readline",
|
563
|
+
*(zlib_recipe ? ["--with-zlib=#{zlib_recipe.path}", "CFLAGS=-I#{zlib_recipe.path}/include"] : []),
|
483
564
|
*(libiconv_recipe ? "--with-iconv=#{libiconv_recipe.path}" : iconv_configure_flags),
|
484
565
|
"--with-c14n",
|
485
566
|
"--with-debug",
|
@@ -487,13 +568,16 @@ EOM
|
|
487
568
|
]
|
488
569
|
end
|
489
570
|
|
490
|
-
libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"], static_p, cross_build_p) do |recipe|
|
491
|
-
recipe.files = [
|
571
|
+
libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"]["version"], static_p, cross_build_p) do |recipe|
|
572
|
+
recipe.files = [{
|
573
|
+
url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
|
574
|
+
md5: dependencies["libxslt"]["md5"]
|
575
|
+
}]
|
492
576
|
recipe.configure_options += [
|
493
577
|
"--without-python",
|
494
578
|
"--without-crypto",
|
495
579
|
"--with-debug",
|
496
|
-
"--with-libxml-prefix=#{libxml2_recipe.path}"
|
580
|
+
"--with-libxml-prefix=#{sh_export_path(libxml2_recipe.path)}"
|
497
581
|
]
|
498
582
|
end
|
499
583
|
|
@@ -505,13 +589,13 @@ EOM
|
|
505
589
|
have_library('lzma')
|
506
590
|
}
|
507
591
|
|
508
|
-
$libs = $libs.shellsplit.tap
|
509
|
-
[libxml2_recipe, libxslt_recipe].each
|
592
|
+
$libs = $libs.shellsplit.tap do |libs|
|
593
|
+
[libxml2_recipe, libxslt_recipe].each do |recipe|
|
510
594
|
libname = recipe.name[/\Alib(.+)\z/, 1]
|
511
|
-
File.join(recipe.path, "bin", "#{libname}-config").tap
|
595
|
+
File.join(recipe.path, "bin", "#{libname}-config").tap do |config|
|
512
596
|
# call config scripts explicit with 'sh' for compat with Windows
|
513
597
|
$CPPFLAGS = `sh #{config} --cflags`.strip << ' ' << $CPPFLAGS
|
514
|
-
`sh #{config} --libs`.strip.shellsplit.each
|
598
|
+
`sh #{config} --libs`.strip.shellsplit.each do |arg|
|
515
599
|
case arg
|
516
600
|
when /\A-L(.+)\z/
|
517
601
|
# Prioritize ports' directories
|
@@ -525,8 +609,8 @@ EOM
|
|
525
609
|
else
|
526
610
|
$LDFLAGS << ' ' << arg.shellescape
|
527
611
|
end
|
528
|
-
|
529
|
-
|
612
|
+
end
|
613
|
+
end
|
530
614
|
|
531
615
|
# Defining a macro that expands to a C string; double quotes are significant.
|
532
616
|
$CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATH=\"#{recipe.path}\"".inspect
|
@@ -545,11 +629,11 @@ EOM
|
|
545
629
|
# -lexslt, so add it manually.
|
546
630
|
libs.unshift('-lexslt')
|
547
631
|
end
|
548
|
-
|
549
|
-
|
632
|
+
end
|
633
|
+
end.shelljoin
|
550
634
|
|
551
635
|
if static_p
|
552
|
-
$libs = $libs.shellsplit.map
|
636
|
+
$libs = $libs.shellsplit.map do |arg|
|
553
637
|
case arg
|
554
638
|
when '-lxml2'
|
555
639
|
File.join(libxml2_recipe.path, 'lib', lib_a(arg))
|
@@ -558,7 +642,7 @@ EOM
|
|
558
642
|
else
|
559
643
|
arg
|
560
644
|
end
|
561
|
-
|
645
|
+
end.shelljoin
|
562
646
|
end
|
563
647
|
end
|
564
648
|
|
@@ -566,12 +650,12 @@ end
|
|
566
650
|
"xml2" => ['xmlParseDoc', 'libxml/parser.h'],
|
567
651
|
"xslt" => ['xsltParseStylesheetDoc', 'libxslt/xslt.h'],
|
568
652
|
"exslt" => ['exsltFuncRegister', 'libexslt/exslt.h'],
|
569
|
-
}.each
|
653
|
+
}.each do |lib, (func, header)|
|
570
654
|
have_func(func, header) ||
|
571
655
|
have_library(lib, func, header) ||
|
572
656
|
have_library("lib#{lib}", func, header) or
|
573
657
|
asplode("lib#{lib}")
|
574
|
-
|
658
|
+
end
|
575
659
|
|
576
660
|
have_func('xmlHasFeature') or abort "xmlHasFeature() is missing."
|
577
661
|
have_func('xmlFirstElementChild')
|
@@ -591,14 +675,14 @@ create_makefile('nokogiri/nokogiri')
|
|
591
675
|
|
592
676
|
if enable_config('clean', true)
|
593
677
|
# Do not clean if run in a development work tree.
|
594
|
-
File.open('Makefile', 'at')
|
678
|
+
File.open('Makefile', 'at') do |mk|
|
595
679
|
mk.print <<EOF
|
596
680
|
all: clean-ports
|
597
681
|
|
598
682
|
clean-ports: $(DLLIB)
|
599
683
|
-$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? 'enable' : 'disable'}-static
|
600
684
|
EOF
|
601
|
-
|
685
|
+
end
|
602
686
|
end
|
603
687
|
|
604
688
|
# :startdoc:
|