nokogiri 1.5.0.beta.4-java → 1.5.0-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (87) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGELOG.ja.rdoc +34 -0
  3. data/CHANGELOG.rdoc +40 -1
  4. data/Manifest.txt +11 -2
  5. data/README.rdoc +1 -1
  6. data/Rakefile +96 -105
  7. data/bin/nokogiri +1 -2
  8. data/ext/java/nokogiri/HtmlDocument.java +1 -31
  9. data/ext/java/nokogiri/HtmlSaxParserContext.java +1 -1
  10. data/ext/java/nokogiri/NokogiriService.java +77 -22
  11. data/ext/java/nokogiri/XmlAttr.java +5 -16
  12. data/ext/java/nokogiri/XmlCdata.java +4 -11
  13. data/ext/java/nokogiri/XmlComment.java +5 -5
  14. data/ext/java/nokogiri/XmlDocument.java +49 -59
  15. data/ext/java/nokogiri/XmlDocumentFragment.java +14 -8
  16. data/ext/java/nokogiri/XmlDtd.java +45 -43
  17. data/ext/java/nokogiri/XmlElement.java +19 -46
  18. data/ext/java/nokogiri/XmlElementDecl.java +9 -5
  19. data/ext/java/nokogiri/XmlEntityReference.java +24 -2
  20. data/ext/java/nokogiri/XmlNamespace.java +89 -34
  21. data/ext/java/nokogiri/XmlNode.java +31 -52
  22. data/ext/java/nokogiri/XmlNodeSet.java +42 -86
  23. data/ext/java/nokogiri/XmlProcessingInstruction.java +15 -19
  24. data/ext/java/nokogiri/XmlReader.java +40 -43
  25. data/ext/java/nokogiri/XmlSaxParserContext.java +2 -2
  26. data/ext/java/nokogiri/XmlSchema.java +14 -9
  27. data/ext/java/nokogiri/XmlText.java +18 -35
  28. data/ext/java/nokogiri/XmlXpathContext.java +43 -23
  29. data/ext/java/nokogiri/XsltStylesheet.java +17 -3
  30. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +2 -4
  31. data/ext/java/nokogiri/internals/NokogiriHelpers.java +77 -20
  32. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +13 -17
  33. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +13 -1
  34. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +23 -8
  35. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +20 -3
  36. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +67 -0
  37. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +86 -0
  38. data/ext/java/nokogiri/internals/ParserContext.java +25 -27
  39. data/ext/java/nokogiri/internals/ReaderNode.java +58 -1
  40. data/ext/java/nokogiri/internals/SaveContextVisitor.java +567 -0
  41. data/ext/java/nokogiri/internals/XmlDomParser.java +1 -2
  42. data/ext/java/nokogiri/internals/XmlDomParserContext.java +6 -0
  43. data/ext/nokogiri/nokogiri.c +24 -1
  44. data/ext/nokogiri/xml_io.c +32 -7
  45. data/ext/nokogiri/xml_node.c +14 -13
  46. data/ext/nokogiri/xml_sax_parser.c +9 -4
  47. data/ext/nokogiri/xslt_stylesheet.c +7 -1
  48. data/lib/nokogiri.rb +3 -22
  49. data/lib/nokogiri/css.rb +4 -0
  50. data/lib/nokogiri/html/document.rb +10 -14
  51. data/lib/nokogiri/nokogiri.jar +0 -0
  52. data/lib/nokogiri/version.rb +76 -23
  53. data/lib/nokogiri/xml/builder.rb +7 -0
  54. data/lib/nokogiri/xml/document.rb +17 -1
  55. data/lib/nokogiri/xml/document_fragment.rb +14 -0
  56. data/lib/nokogiri/xml/node.rb +36 -28
  57. data/lib/nokogiri/xml/node/save_options.rb +17 -1
  58. data/lib/nokogiri/xml/node_set.rb +7 -0
  59. data/lib/nokogiri/xml/parse_options.rb +8 -0
  60. data/lib/nokogiri/xml/reader.rb +6 -6
  61. data/lib/nokogiri/xml/schema.rb +7 -1
  62. data/lib/xercesImpl.jar +0 -0
  63. data/nokogiri_help_responses.md +40 -0
  64. data/tasks/cross_compile.rb +134 -159
  65. data/tasks/nokogiri.org.rb +18 -0
  66. data/tasks/test.rb +1 -1
  67. data/test/files/encoding.html +82 -0
  68. data/test/files/encoding.xhtml +84 -0
  69. data/test/files/metacharset.html +10 -0
  70. data/test/files/noencoding.html +47 -0
  71. data/test/helper.rb +2 -0
  72. data/test/html/test_document.rb +15 -0
  73. data/test/html/test_document_encoding.rb +13 -0
  74. data/test/test_memory_leak.rb +20 -0
  75. data/test/test_reader.rb +22 -0
  76. data/test/test_xslt_transforms.rb +6 -2
  77. data/test/xml/node/test_save_options.rb +10 -2
  78. data/test/xml/test_builder.rb +17 -0
  79. data/test/xml/test_document.rb +22 -0
  80. data/test/xml/test_node.rb +19 -1
  81. data/test/xml/test_node_reparenting.rb +16 -3
  82. data/test/xml/test_node_set.rb +34 -0
  83. data/test/xml/test_schema.rb +5 -0
  84. data/test/xslt/test_exception_handling.rb +37 -0
  85. metadata +141 -107
  86. data/deps.rip +0 -5
  87. data/ext/java/nokogiri/internals/SaveContext.java +0 -288
@@ -327,6 +327,13 @@ module Nokogiri
327
327
  ###
328
328
  # Convert this Builder object to XML
329
329
  def to_xml(*args)
330
+ if Nokogiri.jruby?
331
+ options = args.first.is_a?(Hash) ? args.shift : {}
332
+ if !options[:save_with]
333
+ options[:save_with] = Node::SaveOptions::AS_BUILDER
334
+ end
335
+ args.insert(0, options)
336
+ end
330
337
  @doc.to_xml(*args)
331
338
  end
332
339
 
@@ -9,7 +9,7 @@ module Nokogiri
9
9
  # Nokogiri::XML::Node#xpath
10
10
  class Document < Nokogiri::XML::Node
11
11
  ##
12
- # Parse an XML file. +thing+ may be a String, or any object that
12
+ # Parse an XML file. +string_or_io+ may be a String, or any object that
13
13
  # responds to _read_ and _close_ such as an IO, or StringIO.
14
14
  # +url+ is resource where this document is located. +encoding+ is the
15
15
  # encoding that should be used when processing the document. +options+
@@ -205,6 +205,22 @@ module Nokogiri
205
205
  end
206
206
  alias :<< :add_child
207
207
 
208
+ ##
209
+ # +JRuby+
210
+ # Wraps Java's org.w3c.dom.document and returns Nokogiri::XML::Document
211
+ def self.wrap document
212
+ raise "JRuby only method" unless Nokogiri.jruby?
213
+ return wrapJavaDocument(document)
214
+ end
215
+
216
+ ##
217
+ # +JRuby+
218
+ # Returns Java's org.w3c.dom.document of this Document.
219
+ def to_java
220
+ raise "JRuby only method" unless Nokogiri.jruby?
221
+ return toJavaDocument()
222
+ end
223
+
208
224
  private
209
225
  def implied_xpath_context
210
226
  "/"
@@ -35,6 +35,13 @@ module Nokogiri
35
35
  # Convert this DocumentFragment to html
36
36
  # See Nokogiri::XML::NodeSet#to_html
37
37
  def to_html *args
38
+ if Nokogiri.jruby?
39
+ options = args.first.is_a?(Hash) ? args.shift : {}
40
+ if !options[:save_with]
41
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
42
+ end
43
+ args.insert(0, options)
44
+ end
38
45
  children.to_html(*args)
39
46
  end
40
47
 
@@ -42,6 +49,13 @@ module Nokogiri
42
49
  # Convert this DocumentFragment to xhtml
43
50
  # See Nokogiri::XML::NodeSet#to_xhtml
44
51
  def to_xhtml *args
52
+ if Nokogiri.jruby?
53
+ options = args.first.is_a?(Hash) ? args.shift : {}
54
+ if !options[:save_with]
55
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_XHTML
56
+ end
57
+ args.insert(0, options)
58
+ end
45
59
  children.to_xhtml(*args)
46
60
  end
47
61
 
@@ -103,7 +103,7 @@ module Nokogiri
103
103
 
104
104
  xpath(*(paths.map { |path|
105
105
  path = path.to_s
106
- path =~ /^(\.\/|\/)/ ? path : CSS.xpath_for(
106
+ path =~ /^(\.\/|\/|\.\.)/ ? path : CSS.xpath_for(
107
107
  path,
108
108
  :prefix => prefix,
109
109
  :ns => ns
@@ -260,6 +260,8 @@ module Nokogiri
260
260
  # +node_or_tags+ can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a string containing markup.
261
261
  #
262
262
  # Returns the reparented node (if +node_or_tags+ is a Node), or NodeSet (if +node_or_tags+ is a DocumentFragment, NodeSet, or string).
263
+ #
264
+ # Also see related method +<<+.
263
265
  def add_child node_or_tags
264
266
  node_or_tags = coerce(node_or_tags)
265
267
  if node_or_tags.is_a?(XML::NodeSet)
@@ -270,6 +272,17 @@ module Nokogiri
270
272
  node_or_tags
271
273
  end
272
274
 
275
+ ###
276
+ # Add +node_or_tags+ as a child of this Node.
277
+ # +node_or_tags+ can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a string containing markup.
278
+ #
279
+ # Returns self, to support chaining of calls (e.g., root << child1 << child2)
280
+ #
281
+ # Also see related method +add_child+.
282
+ def << node_or_tags
283
+ add_child node_or_tags
284
+ self
285
+ end
273
286
  ###
274
287
  # Insert +node_or_tags+ before this Node (as a sibling).
275
288
  # +node_or_tags+ can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a string containing markup.
@@ -310,7 +323,7 @@ module Nokogiri
310
323
  else
311
324
  pivot = self
312
325
  end
313
- node_or_tags.reverse.each { |n| pivot.send :add_next_sibling_node, n }
326
+ node_or_tags.reverse_each { |n| pivot.send :add_next_sibling_node, n }
314
327
  pivot.unlink if text?
315
328
  else
316
329
  add_next_sibling_node node_or_tags
@@ -425,7 +438,6 @@ module Nokogiri
425
438
  alias :text :content
426
439
  alias :inner_text :content
427
440
  alias :has_attribute? :key?
428
- alias :<< :add_child
429
441
  alias :name :node_name
430
442
  alias :name= :node_name=
431
443
  alias :type :node_type
@@ -716,7 +728,7 @@ module Nokogiri
716
728
  def serialize *args, &block
717
729
  options = args.first.is_a?(Hash) ? args.shift : {
718
730
  :encoding => args[0],
719
- :save_with => args[1] || SaveOptions::FORMAT
731
+ :save_with => args[1]
720
732
  }
721
733
 
722
734
  encoding = options[:encoding] || document.encoding
@@ -742,11 +754,8 @@ module Nokogiri
742
754
  # FIXME: this is a hack around broken libxml versions
743
755
  return dump_html if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
744
756
 
745
- options[:save_with] ||= SaveOptions::FORMAT |
746
- SaveOptions::NO_DECLARATION |
747
- SaveOptions::NO_EMPTY_TAGS |
748
- SaveOptions::AS_HTML
749
-
757
+ options[:save_with] |= SaveOptions::DEFAULT_HTML if options[:save_with]
758
+ options[:save_with] = SaveOptions::DEFAULT_HTML unless options[:save_with]
750
759
  serialize(options)
751
760
  end
752
761
 
@@ -757,8 +766,8 @@ module Nokogiri
757
766
  #
758
767
  # See Node#write_to for a list of +options+
759
768
  def to_xml options = {}
760
- options[:save_with] ||= SaveOptions::FORMAT | SaveOptions::AS_XML
761
-
769
+ options[:save_with] |= SaveOptions::DEFAULT_XML if options[:save_with]
770
+ options[:save_with] = SaveOptions::DEFAULT_XML unless options[:save_with]
762
771
  serialize(options)
763
772
  end
764
773
 
@@ -772,11 +781,8 @@ module Nokogiri
772
781
  # FIXME: this is a hack around broken libxml versions
773
782
  return dump_html if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
774
783
 
775
- options[:save_with] ||= SaveOptions::FORMAT |
776
- SaveOptions::NO_DECLARATION |
777
- SaveOptions::NO_EMPTY_TAGS |
778
- SaveOptions::AS_XHTML
779
-
784
+ options[:save_with] |= SaveOptions::DEFAULT_XHTML if options[:save_with]
785
+ options[:save_with] = SaveOptions::DEFAULT_XHTML unless options[:save_with]
780
786
  serialize(options)
781
787
  end
782
788
 
@@ -800,9 +806,14 @@ module Nokogiri
800
806
  def write_to io, *options
801
807
  options = options.first.is_a?(Hash) ? options.shift : {}
802
808
  encoding = options[:encoding] || options[0]
803
- save_options = options[:save_with] || options[1] || SaveOptions::FORMAT
809
+ if Nokogiri.jruby?
810
+ save_options = options[:save_with] || options[1]
811
+ indent_times = options[:indent] || 0
812
+ else
813
+ save_options = options[:save_with] || options[1] || SaveOptions::FORMAT
814
+ indent_times = options[:indent] || 2
815
+ end
804
816
  indent_text = options[:indent_text] || ' '
805
- indent_times = options[:indent] || 2
806
817
 
807
818
  config = SaveOptions.new(save_options.to_i)
808
819
  yield config if block_given?
@@ -818,10 +829,7 @@ module Nokogiri
818
829
  # FIXME: this is a hack around broken libxml versions
819
830
  return (io << dump_html) if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
820
831
 
821
- options[:save_with] ||= SaveOptions::FORMAT |
822
- SaveOptions::NO_DECLARATION |
823
- SaveOptions::NO_EMPTY_TAGS |
824
- SaveOptions::AS_HTML
832
+ options[:save_with] ||= SaveOptions::DEFAULT_HTML
825
833
  write_to io, options
826
834
  end
827
835
 
@@ -833,10 +841,7 @@ module Nokogiri
833
841
  # FIXME: this is a hack around broken libxml versions
834
842
  return (io << dump_html) if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
835
843
 
836
- options[:save_with] ||= SaveOptions::FORMAT |
837
- SaveOptions::NO_DECLARATION |
838
- SaveOptions::NO_EMPTY_TAGS |
839
- SaveOptions::AS_XHTML
844
+ options[:save_with] ||= SaveOptions::DEFAULT_XHTML
840
845
  write_to io, options
841
846
  end
842
847
 
@@ -847,7 +852,7 @@ module Nokogiri
847
852
  #
848
853
  # See Node#write_to for a list of options
849
854
  def write_xml_to io, options = {}
850
- options[:save_with] ||= SaveOptions::FORMAT | SaveOptions::AS_XML
855
+ options[:save_with] ||= SaveOptions::DEFAULT_XML
851
856
  write_to io, options
852
857
  end
853
858
 
@@ -871,7 +876,10 @@ module Nokogiri
871
876
  params -= [handler] if handler
872
877
 
873
878
  hashes = []
874
- hashes << params.pop while Hash === params.last || params.last.nil?
879
+ while Hash === params.last || params.last.nil?
880
+ hashes << params.pop
881
+ break if params.empty?
882
+ end
875
883
 
876
884
  ns, binds = hashes.reverse
877
885
 
@@ -6,7 +6,7 @@ module Nokogiri
6
6
  class SaveOptions
7
7
  # Format serialized xml
8
8
  FORMAT = 1
9
- # Do not include delcarations
9
+ # Do not include declarations
10
10
  NO_DECLARATION = 2
11
11
  # Do not include empty tags
12
12
  NO_EMPTY_TAGS = 4
@@ -19,6 +19,22 @@ module Nokogiri
19
19
  # Save as HTML
20
20
  AS_HTML = 64
21
21
 
22
+ if Nokogiri.jruby?
23
+ # Save builder created document
24
+ AS_BUILDER = 128
25
+ # the default for XML documents
26
+ DEFAULT_XML = AS_XML # https://github.com/tenderlove/nokogiri/issues/#issue/415
27
+ # the default for HTML document
28
+ DEFAULT_HTML = NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
29
+ else
30
+ # the default for XML documents
31
+ DEFAULT_XML = FORMAT | AS_XML
32
+ # the default for HTML document
33
+ DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
34
+ end
35
+ # the default for XHTML document
36
+ DEFAULT_XHTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_XHTML
37
+
22
38
  # Integer representation of the SaveOptions
23
39
  attr_reader :options
24
40
 
@@ -273,6 +273,13 @@ module Nokogiri
273
273
  ###
274
274
  # Convert this NodeSet to HTML
275
275
  def to_html *args
276
+ if Nokogiri.jruby?
277
+ options = args.first.is_a?(Hash) ? args.shift : {}
278
+ if !options[:save_with]
279
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
280
+ end
281
+ args.insert(0, options)
282
+ end
276
283
  map { |x| x.to_html(*args) }.join
277
284
  end
278
285
 
@@ -37,6 +37,14 @@ module Nokogiri
37
37
  NOCDATA = 1 << 14
38
38
  # do not generate XINCLUDE START/END nodes
39
39
  NOXINCNODE = 1 << 15
40
+ # compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree)
41
+ COMPACT = 1 << 16
42
+ # parse using XML-1.0 before update 5
43
+ OLD10 = 1 << 17
44
+ # do not fixup XINCLUDE xml:base uris
45
+ NOBASEFIX = 1 << 18
46
+ # relax any hardcoded limit from the parser
47
+ HUGE = 1 << 19
40
48
 
41
49
  # the default options used for parsing XML documents
42
50
  DEFAULT_XML = RECOVER
@@ -87,9 +87,9 @@ module Nokogiri
87
87
  ###
88
88
  # Get a list of attributes for the current node.
89
89
  def attributes
90
- Hash[*(attribute_nodes.map { |node|
90
+ Hash[attribute_nodes.map { |node|
91
91
  [node.name, node.to_s]
92
- }.flatten)].merge(namespaces || {})
92
+ }].merge(namespaces || {})
93
93
  end
94
94
 
95
95
  ###
@@ -101,10 +101,10 @@ module Nokogiri
101
101
  end
102
102
 
103
103
  ###
104
- # Move the cursor through the document yielding each node to the block
105
- def each(&block)
106
- while node = self.read
107
- block.call(node)
104
+ # Move the cursor through the document yielding the cursor to the block
105
+ def each
106
+ while cursor = self.read
107
+ yield cursor
108
108
  end
109
109
  end
110
110
  end
@@ -43,7 +43,13 @@ module Nokogiri
43
43
  # Nokogiri::XML::SyntaxError objects found while validating the
44
44
  # +thing+ is returned.
45
45
  def validate thing
46
- thing.is_a?(Nokogiri::XML::Document) ? validate_document(thing) : validate_file(thing)
46
+ if thing.is_a?(Nokogiri::XML::Document)
47
+ validate_document(thing)
48
+ elsif File.file?(thing)
49
+ validate_file(thing)
50
+ else
51
+ raise ArgumentError, "Must provide Nokogiri::Xml::Document or the name of an existing file"
52
+ end
47
53
  end
48
54
 
49
55
  ###
Binary file
@@ -0,0 +1,40 @@
1
+ # not-enough-information
2
+
3
+ Hello!
4
+
5
+ Thanks for asking this question! However, without more information,
6
+ Team Nokogiri cannot reproduce your issue, and so we cannot offer much
7
+ help.
8
+
9
+ Please provide us with:
10
+
11
+ * A self-contained script (one that we can run without modification,
12
+ and preferably without making external network connections).
13
+
14
+ * Please note that you need to include the XML/HTML that you are
15
+ operating on.
16
+
17
+ * The output of `nokogiri -v`, which will provide details about your
18
+ platform and versions of ruby, libxml2 and nokogiri.
19
+
20
+ For more information about requesting help or reporting bugs, please
21
+ take a look at http://bit.ly/nokohelp
22
+
23
+ Thank you so much!
24
+
25
+ # not-a-bug
26
+
27
+ Hello!
28
+
29
+ Thanks for asking this question! Your request for help will not go
30
+ unanswered!
31
+
32
+ However, Nokogiri's Github Issues is reserved for reporting bugs or
33
+ submitting patches. If you ask your question on the mailing list, Team
34
+ Nokogiri promises someone will provide you with an answer in a timely
35
+ manner.
36
+
37
+ If you'd like to read up on Team Nokogiri's rationale for this policy,
38
+ please go to http://bit.ly/nokohelp.
39
+
40
+ Thank you so much for understanding! And thank you for using Nokogiri.
@@ -1,177 +1,152 @@
1
1
  require 'rake/extensioncompiler'
2
2
  HOST = Rake::ExtensionCompiler.mingw_host
3
- TARGET = 'i386-pc-mingw32'
4
3
 
5
- ZLIB = 'zlib-1.2.5'
6
- ICONV = 'libiconv-1.13.1'
7
- LIBXML = 'libxml2-2.7.7'
8
- LIBXSLT = 'libxslt-1.1.26'
9
- RAKE_COMPILER_PKGCONFIG = File.expand_path(File.join(Dir.pwd, "tmp/cross/lib/pkgconfig/"))
4
+ require 'mini_portile'
5
+ $recipes = {}
6
+ $recipes[:zlib] = MiniPortile.new "zlib", "1.2.5"
7
+ $recipes[:libiconv] = MiniPortile.new "libiconv", "1.13.1"
8
+ $recipes[:libxml2] = MiniPortile.new "libxml2", "2.7.7"
9
+ $recipes[:libxslt] = MiniPortile.new "libxslt", "1.1.26"
10
+ $recipes.each { |_, recipe| recipe.host = HOST }
10
11
 
11
- ### Build zlib ###
12
- file "tmp/cross/download/#{ZLIB}" do |t|
13
- FileUtils.mkdir_p('tmp/cross/download')
14
-
15
- file = ZLIB
16
- url = "http://zlib.net/#{file}.tar.gz"
17
-
18
- Dir.chdir('tmp/cross/download') do
19
- sh "wget #{url} || curl -O #{url}"
20
- sh "tar zxvf #{file}.tar.gz"
21
- end
22
-
23
- Dir.chdir t.name do
24
- mk = File.read('win32/Makefile.gcc')
25
- File.open('win32/Makefile.gcc', 'wb') do |f|
26
- f.puts "BINARY_PATH = #{CROSS_DIR}/bin"
27
- f.puts "LIBRARY_PATH = #{CROSS_DIR}/lib"
28
- f.puts "INCLUDE_PATH = #{CROSS_DIR}/include"
29
-
30
- # FIXME: need to make the cross compiler dynamic
31
- f.puts mk.sub(/^PREFIX\s*=\s*$/, "PREFIX = #{HOST}-") #.
32
- #sub(/^SHARED_MODE=0$/, 'SHARED_MODE=1').
33
- #sub(/^IMPLIB\s*=.*$/, 'IMPLIB=libz.dll.a')
34
- end
35
- end
36
- end
37
-
38
- file 'tmp/cross/lib/libz.a' => "tmp/cross/download/#{ZLIB}" do |t|
39
- Dir.chdir t.prerequisites.first do
40
- sh 'make -f win32/Makefile.gcc'
41
- sh 'make -f win32/Makefile.gcc install'
42
- end
43
- end
44
- ### End build zlib ###
45
-
46
- ### Build iconv ###
47
- file "tmp/cross/download/#{ICONV}" do |t|
48
- FileUtils.mkdir_p('tmp/cross/download')
49
-
50
- file = ICONV
51
- url = "http://ftp.gnu.org/pub/gnu/libiconv/#{file}.tar.gz"
52
-
53
- Dir.chdir('tmp/cross/download') do
54
- sh "wget #{url} || curl -O #{url}"
55
- sh "tar zxvf #{file}.tar.gz"
56
- end
57
-
58
- Dir.chdir t.name do
59
- # FIXME: need to make the host dynamic
60
- sh "./configure --disable-shared --enable-static --host=#{HOST} --target=#{TARGET} --prefix=#{CROSS_DIR} CPPFLAGS='-mno-cygwin -Wall' CFLAGS='-mno-cygwin -O2 -g' CXXFLAGS='-mno-cygwin -O2 -g' LDFLAGS=-mno-cygwin"
61
- end
62
- end
63
-
64
- file 'tmp/cross/bin/iconv.exe' => "tmp/cross/download/#{ICONV}" do |t|
65
- Dir.chdir t.prerequisites.first do
66
- sh 'make'
67
- sh 'make install'
68
- end
69
- end
70
- ### End build iconv ###
71
-
72
- ### Build libxml2 ###
73
- file "tmp/cross/download/#{LIBXML}" do |t|
74
- FileUtils.mkdir_p('tmp/cross/download')
75
-
76
- file = LIBXML
77
- url = "ftp://ftp.xmlsoft.org/libxml2/#{file}.tar.gz"
78
-
79
- Dir.chdir('tmp/cross/download') do
80
- sh "wget #{url} || curl -O #{url}"
81
- sh "tar zxvf #{file}.tar.gz"
82
- end
83
-
84
- Dir.chdir t.name do
85
- # FIXME: need to make the host dynamic
86
- sh "CFLAGS='-DIN_LIBXML' ./configure --host=#{HOST} --target=#{TARGET} --enable-static --disable-shared --prefix=#{CROSS_DIR} --with-zlib=#{CROSS_DIR} --with-iconv=#{CROSS_DIR} --without-python --without-readline"
87
- end
88
- end
89
-
90
- file 'tmp/cross/bin/xml2-config' => "tmp/cross/download/#{LIBXML}" do |t|
91
- Dir.chdir t.prerequisites.first do
92
- sh 'make LDFLAGS="-avoid-version"'
93
- sh 'make install'
12
+ file "lib/nokogiri/nokogiri.rb" do
13
+ File.open("lib/nokogiri/nokogiri.rb", 'wb') do |f|
14
+ f.write %Q{require "nokogiri/\#{RUBY_VERSION.sub(/\\.\\d+$/, '')}/nokogiri"\n}
94
15
  end
95
16
  end
96
- ### End build libxml2 ###
97
-
98
- ### Build libxslt ###
99
- file "tmp/cross/download/#{LIBXSLT}" do |t|
100
- FileUtils.mkdir_p('tmp/cross/download')
101
17
 
102
- file = LIBXSLT
103
- url = "ftp://ftp.xmlsoft.org/libxml2/#{file}.tar.gz"
104
-
105
- Dir.chdir('tmp/cross/download') do
106
- sh "wget #{url} || curl -O #{url}"
107
- sh "tar zxvf #{file}.tar.gz"
108
- end
109
-
110
- Dir.chdir t.name do
111
- # FIXME: need to make the host dynamic
112
- sh "CFLAGS='-DIN_LIBXML' ./configure --host=#{HOST} --target=#{TARGET} --enable-static --disable-shared --prefix=#{CROSS_DIR} --with-libxml-prefix=#{CROSS_DIR} --without-python --without-crypto"
113
- end
114
- end
18
+ namespace :cross do
19
+ task :zlib do
20
+ recipe = $recipes[:zlib]
21
+ recipe.files = ["http://zlib.net/#{recipe.name}-#{recipe.version}.tar.gz"]
22
+ class << recipe
23
+ def configure
24
+ Dir.chdir work_path do
25
+ mk = File.read 'win32/Makefile.gcc'
26
+ File.open 'win32/Makefile.gcc', 'wb' do |f|
27
+ f.puts "BINARY_PATH = #{CROSS_DIR}/bin"
28
+ f.puts "LIBRARY_PATH = #{CROSS_DIR}/lib"
29
+ f.puts "INCLUDE_PATH = #{CROSS_DIR}/include"
30
+ f.puts mk.sub(/^PREFIX\s*=\s*$/, "PREFIX = #{HOST}-")
31
+ end
32
+ end
33
+ end
34
+
35
+ def configured?
36
+ Dir.chdir work_path do
37
+ !! (File.read('win32/Makefile.gcc') =~ /^BINARY_PATH/)
38
+ end
39
+ end
40
+
41
+ def compile
42
+ execute "compile", "make -f win32/Makefile.gcc"
43
+ end
44
+
45
+ def install
46
+ execute "install", "make -f win32/Makefile.gcc install"
47
+ end
48
+ end
115
49
 
116
- file 'tmp/cross/bin/xslt-config' => "tmp/cross/download/#{LIBXSLT}" do |t|
117
- Dir.chdir t.prerequisites.first do
118
- sh 'make LDFLAGS="-avoid-version"'
119
- sh 'make install'
120
- end
121
- end
122
- ### End build libxslt ###
50
+ checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}.installed"
51
+ unless File.exist?(checkpoint)
52
+ recipe.cook
53
+ touch checkpoint
54
+ end
55
+ recipe.activate
56
+ end
57
+
58
+ task :libiconv do
59
+ recipe = $recipes[:libiconv]
60
+ recipe.files = ["http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz"]
61
+ recipe.configure_options = [
62
+ "--host=#{HOST}",
63
+ "--enable-static",
64
+ "--disable-shared",
65
+ "CPPFLAGS='-mno-cygwin -Wall'",
66
+ "CFLAGS='-mno-cygwin -O2 -g'",
67
+ "CXXFLAGS='-mno-cygwin -O2 -g'",
68
+ "LDFLAGS=-mno-cygwin"
69
+ ]
70
+
71
+ checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}.installed"
72
+ unless File.exist?(checkpoint)
73
+ recipe.cook
74
+ touch checkpoint
75
+ end
76
+ recipe.activate
77
+ end
78
+
79
+ task :libxml2 => ["cross:zlib", "cross:libiconv"] do
80
+ recipe = $recipes[:libxml2]
81
+ recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
82
+ recipe.configure_options = [
83
+ "--host=#{HOST}",
84
+ "--enable-static",
85
+ "--disable-shared",
86
+ "--with-zlib=#{CROSS_DIR}",
87
+ "--with-iconv=#{$recipes[:libiconv].path}",
88
+ "--without-python",
89
+ "--without-readline",
90
+ "CFLAGS='-DIN_LIBXML'"
91
+ ]
92
+ class << recipe
93
+ def download
94
+ Dir.chdir archives_path do
95
+ @files.each do |url|
96
+ sh "wget #{url} || curl -O #{url}"
97
+ end
98
+ end
99
+ end
100
+ end
123
101
 
124
- file 'lib/nokogiri/nokogiri.rb' => 'cross:check' do
125
- File.open("lib/#{HOE.name}/#{HOE.name}.rb", 'wb') do |f|
126
- f.write <<-eoruby
127
- require "#{HOE.name}/\#{RUBY_VERSION.sub(/\\.\\d+$/, '')}/#{HOE.name}"
128
- eoruby
129
- end
130
- end
102
+ checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}.installed"
103
+ unless File.exist?(checkpoint)
104
+ recipe.cook
105
+ touch checkpoint
106
+ end
107
+ recipe.activate
108
+ end
109
+
110
+ task :libxslt => ['cross:libxml2'] do
111
+ recipe = $recipes[:libxslt]
112
+ recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
113
+ recipe.configure_options = [
114
+ "--host=#{HOST}",
115
+ "--enable-static",
116
+ "--disable-shared",
117
+ "--with-libxml-prefix=#{$recipes[:libxml2].path}",
118
+ "--without-python",
119
+ "--without-crypto",
120
+ "CFLAGS='-DIN_LIBXML'"
121
+ ]
122
+ class << recipe
123
+ def download
124
+ Dir.chdir archives_path do
125
+ @files.each do |url|
126
+ sh "wget #{url} || curl -O #{url}"
127
+ end
128
+ end
129
+ end
130
+ end
131
131
 
132
- namespace :cross do
133
- task :iconv => 'tmp/cross/bin/iconv.exe'
134
- task :zlib => 'tmp/cross/lib/libz.a'
135
- task :libxml2 => ['cross:zlib', 'cross:iconv', 'tmp/cross/bin/xml2-config']
136
- task :libxslt => ['cross:libxml2', 'tmp/cross/bin/xslt-config']
137
-
138
- task :check => ["cross:libxslt"] do
139
- unless File.directory?(RAKE_COMPILER_PKGCONFIG)
140
- raise RuntimeError.new("looks like rake-compiler changed where pkgconfig info is kept. (#{RAKE_COMPILER_PKGCONFIG})")
132
+ checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}.installed"
133
+ unless File.exist?(checkpoint)
134
+ recipe.cook
135
+ touch checkpoint
141
136
  end
137
+ recipe.activate
142
138
  end
143
139
 
144
140
  task :file_list do
145
- HOE.spec.extensions = []
146
- HOE.spec.files += Dir["lib/#{HOE.name}/#{HOE.name}.rb"]
147
- HOE.spec.files += Dir["lib/#{HOE.name}/1.{8,9}/#{HOE.name}.so"]
141
+ HOE.spec.files += Dir["lib/nokogiri/nokogiri.rb"]
142
+ HOE.spec.files += Dir["lib/nokogiri/1.{8,9}/nokogiri.so"]
148
143
  end
149
144
  end
150
145
 
151
- CLOBBER.include("lib/nokogiri/nokogiri.{so,dylib,rb,bundle}")
152
- CLOBBER.include("lib/nokogiri/1.{8,9}")
153
-
154
- if Rake::Task.task_defined?(:cross)
155
- Rake::Task[:cross].prerequisites << "lib/nokogiri/nokogiri.rb"
156
- Rake::Task[:cross].prerequisites << "cross:file_list"
157
- end
146
+ HOE.clean_globs += [
147
+ "#{CROSS_DIR}/*.installed",
148
+ "#{CROSS_DIR}/#{HOST}",
149
+ "tmp/#{HOST}",
150
+ ]
158
151
 
159
- desc "build a windows gem without all the ceremony."
160
- task "gem:windows" do
161
- rake_compiler_config = YAML.load_file("#{ENV['HOME']}/.rake-compiler/config.yml")
162
-
163
- # check that rake-compiler config contains the right patchlevels of 1.8.6 and 1.9.1. see #279.
164
- ["1.8.6-p383", "1.9.1-p243"].each do |version|
165
- majmin, patchlevel = version.split("-")
166
- rbconfig = "rbconfig-#{majmin}"
167
- unless rake_compiler_config.key?(rbconfig) && rake_compiler_config[rbconfig] =~ /-#{patchlevel}/
168
- raise "rake-compiler '#{rbconfig}' not #{patchlevel}. try running 'rake-compiler cross-ruby VERSION=#{version}'"
169
- end
170
- end
171
-
172
- # verify that --export-all is in the 1.9.1 rbconfig. see #279,#374,#375.
173
- rbconfig_191 = rake_compiler_config["rbconfig-1.9.1"]
174
- raise "rbconfig #{rbconfig_191} needs --export-all in its DLDFLAGS value" if File.read(rbconfig_191).grep(/CONFIG\["DLDFLAGS"\].*--export-all/).empty?
175
-
176
- system("env PKG_CONFIG_PATH=#{RAKE_COMPILER_PKGCONFIG} RUBY_CC_VERSION=1.8.6:1.9.1 rake cross native gem") || raise("build failed!")
177
- end
152
+ task :cross => ["cross:libxslt", "lib/nokogiri/nokogiri.rb", "cross:file_list"]