Skip to content

HTTPS clone URL

Subversion checkout URL

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