Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 292 lines (252 sloc) 8.045 kB
e7f98b6 @tenderlove initial checkin
tenderlove authored
1 # -*- ruby -*-
2
cde87f2 @tenderlove Revert "fixing segfaults. no more weakrefs"
tenderlove authored
3 require 'rubygems'
66fea0e @tenderlove adding a java platform
tenderlove authored
4 require 'rake'
5
cde87f2 @tenderlove Revert "fixing segfaults. no more weakrefs"
tenderlove authored
6
9246422 @tenderlove adding tokenizer and parser
tenderlove authored
7 kind = Config::CONFIG['DLEXT']
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
8 windows = RUBY_PLATFORM =~ /mswin/i ? true : false
9246422 @tenderlove adding tokenizer and parser
tenderlove authored
9
08450f3 @tenderlove auto generating the IDL interface
tenderlove authored
10 LIB_DIR = File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
11 $LOAD_PATH << LIB_DIR
12
06f7a60 @tenderlove vendoring hoe
tenderlove authored
13 $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'vendor'))
14
15 require 'hoe'
16
9246422 @tenderlove adding tokenizer and parser
tenderlove authored
17 GENERATED_PARSER = "lib/nokogiri/css/generated_parser.rb"
18 GENERATED_TOKENIZER = "lib/nokogiri/css/generated_tokenizer.rb"
e7f98b6 @tenderlove initial checkin
tenderlove authored
19
9246422 @tenderlove adding tokenizer and parser
tenderlove authored
20 EXT = "ext/nokogiri/native.#{kind}"
21
22 require 'nokogiri/version'
85b1f6d @tenderlove starting the move to C
tenderlove authored
23
06f7a60 @tenderlove vendoring hoe
tenderlove authored
24 HOE = Hoe.new('nokogiri', Nokogiri::VERSION) do |p|
25 p.developer('Aaron Patterson', 'aaronp@rubyforge.org')
26 p.clean_globs = [
27 'ext/nokogiri/Makefile',
28 'ext/nokogiri/*.{o,so,bundle,a,log,dll}',
29 'ext/nokogiri/conftest.dSYM',
30 GENERATED_PARSER,
31 GENERATED_TOKENIZER,
32 'cross',
33 ]
34 p.spec_extras = { :extensions => ["Rakefile"] }
08450f3 @tenderlove auto generating the IDL interface
tenderlove authored
35 end
36
c40736a @tenderlove bumping version and adding a gem spec task
tenderlove authored
37 namespace :gem do
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
38 namespace :dev do
39 task :spec do
40 File.open("#{HOE.name}.gemspec", 'w') do |f|
41 HOE.spec.version = "#{HOE.version}.#{Time.now.strftime("%Y%m%d%H%M%S")}"
42 f.write(HOE.spec.to_ruby)
43 end
44 end
45 end
46
47 namespace :win32 do
cf6fc79 @tenderlove making sure the win32 spec task depends on build:win32
tenderlove authored
48 task :spec => ['build:win32'] do
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
49 File.open("#{HOE.name}.gemspec", 'w') do |f|
50 HOE.spec.files += Dir['ext/nokogiri/**.{dll,so}']
51 if windows
52 HOE.spec.platform = Gem::Platform::CURRENT
53 else
54 HOE.spec.platform = 'x86-mswin32-60'
55 end
56 HOE.spec.extensions = []
57 f.write(HOE.spec.to_ruby)
58 end
c40736a @tenderlove bumping version and adding a gem spec task
tenderlove authored
59 end
60 end
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
61
66fea0e @tenderlove adding a java platform
tenderlove authored
62 namespace :jruby do
63 task :spec => ['build'] do
64 File.open("#{HOE.name}.gemspec", 'w') do |f|
65 HOE.spec.platform = 'jruby'
66 HOE.spec.extensions = []
67 f.write(HOE.spec.to_ruby)
68 end
69 end
70 end
71
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
72 namespace :unix do
73 task :spec do
74 File.open("#{HOE.name}.gemspec", 'w') do |f|
75 f.write(HOE.spec.to_ruby)
76 end
77 end
78 end
79
80 task :spec => ['gem:dev:spec']
c40736a @tenderlove bumping version and adding a gem spec task
tenderlove authored
81 end
08450f3 @tenderlove auto generating the IDL interface
tenderlove authored
82
0799dd7 @flavorjones added rcov task
flavorjones authored
83 desc "Run code-coverage analysis"
84 task :coverage do
85 rm_rf "coverage"
86 sh "rcov -x Library -I lib:test #{Dir[*HOE.test_globs].join(' ')}"
87 end
85b1f6d @tenderlove starting the move to C
tenderlove authored
88
9246422 @tenderlove adding tokenizer and parser
tenderlove authored
89 file GENERATED_PARSER => "lib/nokogiri/css/parser.y" do |t|
66fea0e @tenderlove adding a java platform
tenderlove authored
90 begin
91 sh "racc -o #{t.name} #{t.prerequisites.first}"
92 rescue
e1e9751 @tenderlove extconf should not check for frex and racc
tenderlove authored
93 abort "need racc, get the tarball from http://i.loveruby.net/archive/racc/racc-1.4.5-all.tar.gz"
94 end
9246422 @tenderlove adding tokenizer and parser
tenderlove authored
95 end
96
97 file GENERATED_TOKENIZER => "lib/nokogiri/css/tokenizer.rex" do |t|
66fea0e @tenderlove adding a java platform
tenderlove authored
98 begin
99 sh "frex -i --independent -o #{t.name} #{t.prerequisites.first}"
100 rescue
e1e9751 @tenderlove extconf should not check for frex and racc
tenderlove authored
101 abort "need frex, sudo gem install aaronp-frex -s http://gems.github.com"
102 end
9246422 @tenderlove adding tokenizer and parser
tenderlove authored
103 end
85b1f6d @tenderlove starting the move to C
tenderlove authored
104
105 task 'ext/nokogiri/Makefile' do
106 Dir.chdir('ext/nokogiri') do
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
107 ruby "extconf.rb"
85b1f6d @tenderlove starting the move to C
tenderlove authored
108 end
109 end
110
111 task EXT => 'ext/nokogiri/Makefile' do
112 Dir.chdir('ext/nokogiri') do
113 sh 'make'
114 end
115 end
116
66fea0e @tenderlove adding a java platform
tenderlove authored
117 if RUBY_PLATFORM == 'java'
118 task :build => [GENERATED_PARSER, GENERATED_TOKENIZER]
119 else
120 task :build => [EXT, GENERATED_PARSER, GENERATED_TOKENIZER]
121 end
85b1f6d @tenderlove starting the move to C
tenderlove authored
122
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
123 namespace :build do
124 namespace :win32 do
125 file 'cross/bin/ruby.exe' => ['cross/ruby-1.8.6-p287'] do
126 Dir.chdir('cross/ruby-1.8.6-p287') do
127 str = ''
128 File.open('Makefile.in', 'rb') do |f|
129 f.each_line do |line|
130 if line =~ /^\s*ALT_SEPARATOR =/
131 str += "\t\t " + 'ALT_SEPARATOR = "\\\\\"; \\'
132 str += "\n"
133 else
134 str += line
135 end
136 end
137 end
138 File.open('Makefile.in', 'wb') { |f| f.write str }
9e456a1 @flavorjones added build options for cross-compiling on linux for mingw32
flavorjones authored
139 buildopts = if File.exists?('/usr/bin/i586-mingw32msvc-gcc')
140 "--host=i586-mingw32msvc --target=i386-mingw32 --build=i686-linux"
141 else
142 "--host=i386-mingw32 --target=i386-mingw32"
143 end
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
144 sh(<<-eocommand)
145 env ac_cv_func_getpgrp_void=no \
146 ac_cv_func_setpgrp_void=yes \
147 rb_cv_negative_time_t=no \
148 ac_cv_func_memcmp_working=yes \
149 rb_cv_binary_elf=no \
150 ./configure \
9e456a1 @flavorjones added build options for cross-compiling on linux for mingw32
flavorjones authored
151 #{buildopts} \
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
152 --prefix=#{File.expand_path(File.join(Dir.pwd, '..'))}
153 eocommand
154 sh 'make'
155 sh 'make install'
156 end
157 end
158
159 desc 'build cross compiled ruby'
160 task :ruby => 'cross/bin/ruby.exe'
161 end
162
163 desc 'build nokogiri for win32'
164 task :win32 => [GENERATED_PARSER, GENERATED_TOKENIZER, 'build:externals', 'build:win32:ruby'] do
165 dash_i = File.expand_path(
166 File.join(File.dirname(__FILE__), 'cross/lib/ruby/1.8/i386-mingw32/')
167 )
168 Dir.chdir('ext/nokogiri') do
169 ruby " -I #{dash_i} extconf.rb"
170 sh 'make'
171 end
172 dlls = Dir[File.join(File.dirname(__FILE__), 'cross', '**/*.dll')]
173 dlls.each do |dll|
174 next if dll =~ /ruby/
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
175 cp dll, 'ext/nokogiri'
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
176 end
177 end
178
179 libs = %w{
180 iconv-1.9.2.win32
181 zlib-1.2.3.win32
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
182 libxml2-2.7.2.win32
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
183 libxslt-1.1.24.win32
184 }
185
186 libs.each do |lib|
94cd698 @flavorjones using a separate 'stash' directory for storing .zip and .tar.gz files…
flavorjones authored
187 file "stash/#{lib}.zip" do |t|
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
188 puts "downloading #{lib}"
94cd698 @flavorjones using a separate 'stash' directory for storing .zip and .tar.gz files…
flavorjones authored
189 FileUtils.mkdir_p('stash')
190 Dir.chdir('stash') do
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
191 url = "http://www.zlatkovic.com/pub/libxml/#{lib}.zip"
192 system("wget #{url} || curl -O #{url}")
94cd698 @flavorjones using a separate 'stash' directory for storing .zip and .tar.gz files…
flavorjones authored
193 end
194 end
195 file "cross/#{lib}" => ["stash/#{lib}.zip"] do |t|
196 puts "unzipping #{lib}.zip"
197 FileUtils.mkdir_p('cross')
198 Dir.chdir('cross') do
199 sh "unzip ../stash/#{lib}.zip"
200 sh "touch #{lib}"
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
201 end
202 end
203 end
204
94cd698 @flavorjones using a separate 'stash' directory for storing .zip and .tar.gz files…
flavorjones authored
205 file "stash/ruby-1.8.6-p287.tar.gz" do |t|
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
206 puts "downloading ruby"
94cd698 @flavorjones using a separate 'stash' directory for storing .zip and .tar.gz files…
flavorjones authored
207 FileUtils.mkdir_p('stash')
208 Dir.chdir('stash') do
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
209 url = ("ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p287.tar.gz")
210 system("wget #{url} || curl -O #{url}")
94cd698 @flavorjones using a separate 'stash' directory for storing .zip and .tar.gz files…
flavorjones authored
211 end
212 end
213 file 'cross/ruby-1.8.6-p287' => ["stash/ruby-1.8.6-p287.tar.gz"] do |t|
214 puts "unzipping ruby"
215 FileUtils.mkdir_p('cross')
216 Dir.chdir('cross') do
217 sh "tar zxvf ../stash/ruby-1.8.6-p287.tar.gz"
131df0d @tenderlove adding tasks to build cross compiled nokogiri
tenderlove authored
218 end
219 end
220
221 task :externals => libs.map { |x| "cross/#{x}" } + ['cross/ruby-1.8.6-p287']
222 end
223
4f61ace @flavorjones putting gdb and valgrind rake tasks under 'test' namespace
flavorjones authored
224 desc "set environment variables to build and/or test with debug options"
225 task :debug do
226 ENV['NOKOGIRI_DEBUG'] = "true"
227 ENV['CFLAGS'] ||= ""
228 ENV['CFLAGS'] += " -DDEBUG"
229 end
230
10b09f8 @flavorjones added rake task to run test suite in gdb
flavorjones authored
231 def test_suite_cmdline
e95a348 @flavorjones rake tasks for running the test suite under valgrind.
flavorjones authored
232 require 'find'
233 files = []
234 Find.find("test") do |f|
235 files << f if File.basename(f) =~ /.*test.*\.rb$/
236 end
237 cmdline = "ruby -w -I.:lib:ext:test -rtest/unit -e '%w[#{files.join(' ')}].each {|f| require f}'"
238 end
239
4f61ace @flavorjones putting gdb and valgrind rake tasks under 'test' namespace
flavorjones authored
240 namespace :test do
e95a348 @flavorjones rake tasks for running the test suite under valgrind.
flavorjones authored
241 # partial-loads-ok and undef-value-errors necessary to ignore
242 # spurious (and eminently ignorable) warnings from the ruby
243 # interpreter
244 VALGRIND_BASIC_OPTS = "--num-callers=50 --error-limit=no --partial-loads-ok=yes --undef-value-errors=no"
245
f46df50 @flavorjones tweaked rake task descriptions
flavorjones authored
246 desc "run test suite under valgrind with basic ruby options"
4f61ace @flavorjones putting gdb and valgrind rake tasks under 'test' namespace
flavorjones authored
247 task :valgrind => :build do
10b09f8 @flavorjones added rake task to run test suite in gdb
flavorjones authored
248 cmdline = "valgrind #{VALGRIND_BASIC_OPTS} #{test_suite_cmdline}"
e95a348 @flavorjones rake tasks for running the test suite under valgrind.
flavorjones authored
249 puts cmdline
250 system cmdline
251 end
252
f46df50 @flavorjones tweaked rake task descriptions
flavorjones authored
253 desc "run test suite under valgrind with memory-fill ruby options"
4f61ace @flavorjones putting gdb and valgrind rake tasks under 'test' namespace
flavorjones authored
254 task :valgrind_mem => :build do
e95a348 @flavorjones rake tasks for running the test suite under valgrind.
flavorjones authored
255 # fill malloced memory with "m" and freed memory with "f"
10b09f8 @flavorjones added rake task to run test suite in gdb
flavorjones authored
256 cmdline = "valgrind #{VALGRIND_BASIC_OPTS} --freelist-vol=100000000 --malloc-fill=6D --free-fill=66 #{test_suite_cmdline}"
e95a348 @flavorjones rake tasks for running the test suite under valgrind.
flavorjones authored
257 puts cmdline
258 system cmdline
259 end
260
f46df50 @flavorjones tweaked rake task descriptions
flavorjones authored
261 desc "run test suite under valgrind with memory-zero ruby options"
4f61ace @flavorjones putting gdb and valgrind rake tasks under 'test' namespace
flavorjones authored
262 task :valgrind_mem0 => :build do
e95a348 @flavorjones rake tasks for running the test suite under valgrind.
flavorjones authored
263 # fill malloced and freed memory with 0
10b09f8 @flavorjones added rake task to run test suite in gdb
flavorjones authored
264 cmdline = "valgrind #{VALGRIND_BASIC_OPTS} --freelist-vol=100000000 --malloc-fill=00 --free-fill=00 #{test_suite_cmdline}"
e95a348 @flavorjones rake tasks for running the test suite under valgrind.
flavorjones authored
265 puts cmdline
266 system cmdline
267 end
268
4f61ace @flavorjones putting gdb and valgrind rake tasks under 'test' namespace
flavorjones authored
269 desc "run test suite under gdb"
270 task :gdb => :build do
271 cmdline = "gdb --args #{test_suite_cmdline}"
272 puts cmdline
273 system cmdline
274 end
1e32e9e @flavorjones rake task to run tests with aggressive garbage collection
flavorjones authored
275
276 desc "run test suite with aggressive GC"
277 task :gc => :build do
278 ENV['NOKOGIRI_GC'] = "true"
279 Rake::Task["test"].invoke
280 end
10b09f8 @flavorjones added rake task to run test suite in gdb
flavorjones authored
281 end
282
283
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
284 # Only do this on unix, since we can't build on windows
285 unless windows
06f7a60 @tenderlove vendoring hoe
tenderlove authored
286 Rake::Task[:test].prerequisites << :build
287 Rake::Task[:check_manifest].prerequisites << GENERATED_PARSER
288 Rake::Task[:check_manifest].prerequisites << GENERATED_TOKENIZER
35cace6 @tenderlove fixing up win32 build, adding a few methods to dtd
tenderlove authored
289 end
43686d6 @tenderlove updating rakefile to build before testing
tenderlove authored
290
e7f98b6 @tenderlove initial checkin
tenderlove authored
291 # vim: syntax=Ruby
Something went wrong with that request. Please try again.