Skip to content

HTTPS clone URL

Subversion checkout URL

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