Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 218 lines (198 sloc) 6.219 kb
c3431a1 Jeremy Hinegardner core library in extension working
authored
1 #-----------------------------------------------------------------------
2 # Extensions
3 #-----------------------------------------------------------------------
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
4 require 'pathname'
5 namespace :ext do
6 def current_sqlite_version
7 ext = Util.platform_gemspec.extensions.first
8 path = Pathname.new( ext )
9 h_path = path.dirname.realpath + "sqlite3.h"
10 File.open( h_path ) do |f|
11 f.each_line do |line|
12 if line =~ /\A#define SQLITE_VERSION\s+/ then
13 define ,constant ,value = line.split
14 return value
429df0d Jeremy Hinegardner update to sqlite 3.6.6.2
authored
15 end
16 end
17 end
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
18 end
429df0d Jeremy Hinegardner update to sqlite 3.6.6.2
authored
19
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
20 desc "Build the SQLite extension version #{current_sqlite_version}"
21 task :build => :clean do
22 with_each_extension do |extension|
23 path = Pathname.new(extension)
24 parts = path.split
25 conf = parts.last
26 Dir.chdir(path.dirname) do |d|
27 ruby conf.to_s
28 sh "make"
29
30 # install into requireable location so specs will run
9a92f42 Jeremy Hinegardner Back to green.
authored
31 mkdir_p ext_dest_dir, :verbose => true
d62ad1a Jeremy Hinegardner Config -> RbConfig. Closes #23
authored
32 cp "amalgalite3.#{RbConfig::CONFIG['DLEXT']}", ext_dest_dir, :verbose => true
c3431a1 Jeremy Hinegardner core library in extension working
authored
33 end
34 end
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
35 end
32791aa Jeremy Hinegardner initial import
authored
36
9a92f42 Jeremy Hinegardner Back to green.
authored
37 def ext_dest_dir
38 version_sub = RUBY_VERSION.sub(/\.\d$/,'')
39 dest_dir = Util.proj_path( 'lib', 'amalgalite', version_sub)
40 end
41
42
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
43 def with_each_extension
44 Util.platform_gemspec.extensions.each do |ext|
45 yield ext
2ea23cc Jeremy Hinegardner Fix cross compilation issues
authored
46 end
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
47 end
2ea23cc Jeremy Hinegardner Fix cross compilation issues
authored
48
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
49 def myruby
50 require 'rbconfig'
51 x = File.join(
52 RbConfig::CONFIG['bindir'],
53 RbConfig::CONFIG['ruby_install_name']
54 )
55 #puts "myruby = #{x}"
56 return x
57 end
26f46d8 Jeremy Hinegardner adding support for windows
authored
58
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
59 # FIXME: building on windows is broken
60 def build_win( version = "1.8.7" )
61 ext_config = Util.platform_gemspec.extensions.first
62 rbconfig = ext_config.cross_rbconfig["rbconfig-#{version}"]
63 raise ArgumentError, "No cross compiler for version #{version}, we have #{ext_config.cross_rbconfig.keys.join(",")}" unless rbconfig
64 with_each_extension do |extension|
65 path = Pathname.new(extension)
66 parts = path.split
67 conf = parts.last
68 rvm = File.expand_path( "~/.rvm/bin/rvm" )
69 Dir.chdir(path.dirname) do |d|
70 if File.exist?( "Makefile" ) then
71 sh "make clean distclean"
72 end
73 cp "#{rbconfig}", "rbconfig.rb"
74 rubylib = ENV['RUBYLIB']
75 ENV['RUBYLIB'] = "."
76 sh %[ #{rvm} #{version} -S extconf.rb #{myruby} ]
77 ENV['RUBYLIB'] = rubylib
78 sh "make"
e66cebc Jeremy Hinegardner ruby 1.9 compatibility
authored
79 end
80 end
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
81 end
e66cebc Jeremy Hinegardner ruby 1.9 compatibility
authored
82
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
83 win_builds = []
84 # ext_config.cross_rbconfig.keys.each do |v|
85 # s = v.split("-").last
86 # desc "Build the extension for windows version #{s}"
87 # win_bname = "build_win-#{s}"
88 # win_builds << win_bname
89 # task win_bname => :clean do
90 # build_win( s )
91 # end
92 # end
93
94 task :clean do
95 with_each_extension do |extension|
96 path = Pathname.new(extension)
97 parts = path.split
98 conf = parts.last
99 Dir.chdir(path.dirname) do |d|
100 if File.exist?( "Makefile" ) then
101 sh "make clean"
c3431a1 Jeremy Hinegardner core library in extension working
authored
102 end
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
103 rm_f "rbconfig.rb"
c3431a1 Jeremy Hinegardner core library in extension working
authored
104 end
105 end
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
106 end
c3431a1 Jeremy Hinegardner core library in extension working
authored
107
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
108 desc "List the sqlite api calls that are not implemented"
109 task :todo do
110
111 not_implementing = %w[
112 sqlite3_exec
113 sqlite3_open
114 sqlite3_os_end
115 sqlite3_os_init
116 sqlite3_malloc
117 sqlite3_realloc
118 sqlite3_free
119 sqlite3_get_table
120 sqlite3_free_table
121 sqlite3_key
122 sqlite3_rekey
123 sqlite3_next_stmt
124 sqlite3_release_memory
125 sqlite3_sleep
126 sqlite3_snprintf
127 sqlite3_vmprintf
128 sqlite3_strnicmp
129 sqlite3_test_control
130 sqlite3_unlock_notify
131 sqlite3_vfs_find
132 sqlite3_vfs_register
133 sqlite3_vfs_unregister
134 ]
135
136 sqlite_h = File.join( *%w[ ext amalgalite sqlite3.h ] )
137 api_todo = {}
138 IO.readlines( sqlite_h ).each do |line|
139 if line =~ /\ASQLITE_API/ then
140 if line !~ /SQLITE_DEPRECATED/ and line !~ /SQLITE_EXPERIMENTAL/ then
141 if md = line.match( /(sqlite3_[^(\s]+)\(/ ) then
142 next if not_implementing.include?(md.captures[0])
143 api_todo[md.captures[0]] = true
4004ba5 Jeremy Hinegardner added ext:todo task
authored
144 end
145 end
146 end
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
147 end
4004ba5 Jeremy Hinegardner added ext:todo task
authored
148
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
149 Dir.glob("ext/amalgalite/amalgalite*.c").each do |am_file|
150 IO.readlines( am_file ).each do |am_line|
151 if md = am_line.match( /(sqlite3_[^(\s]+)\(/ ) then
152 api_todo.delete( md.captures[0] )
4004ba5 Jeremy Hinegardner added ext:todo task
authored
153 end
154 end
155 end
156
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
157 puts "#{api_todo.keys.size} functions to still implement"
158 puts api_todo.keys.sort.join("\n")
159 end
160
161 task :clobber do
162 with_each_extension do |extension|
163 path = Pathname.new(extension)
164 parts = path.split
165 conf = parts.last
166 Dir.chdir(path.dirname) do |d|
167 if File.exist?( "Makefile") then
168 sh "make distclean"
c3431a1 Jeremy Hinegardner core library in extension working
authored
169 end
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
170 rm_f "rbconfig.rb"
c3431a1 Jeremy Hinegardner core library in extension working
authored
171 end
172 end
9a92f42 Jeremy Hinegardner Back to green.
authored
173 FileUtils.rm_rf ext_dest_dir, :verbose => true
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
174 end
f16060b Jeremy Hinegardner update to upstream SQLite v3.6.3
authored
175
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
176 desc "Download and integrate the next version of sqlite (use VERSION=x.y.z)"
177 task :update_sqlite do
178 require 'uri'
179 require 'net/http'
180 parts = ENV['VERSION'].split(".")
181 next_version = [ parts.shift.to_s ]
182 parts.each do |p|
183 next_version << "#{"%02d" % p }"
184 end
185 next_version << "00" if next_version.size == 3
186
187 next_version = next_version.join('')
188
189 raise "VERSION env variable must be set" unless next_version
190 url = ::URI.parse("http://sqlite.org/sqlite-amalgamation-#{next_version}.zip")
191 puts "downloading #{url.to_s} ..."
192 file = "tmp/#{File.basename( url.path ) }"
193 FileUtils.mkdir "tmp" unless File.directory?( "tmp" )
194 File.open( file, "wb+") do |f|
195 res = Net::HTTP.get_response( url )
196 f.write( res.body )
197 end
f16060b Jeremy Hinegardner update to upstream SQLite v3.6.3
authored
198
a9b8414 Jeremy Hinegardner Switch to "fixme" style project structure
authored
199 puts "extracting..."
200 upstream_files = %w[ sqlite3.h sqlite3.c sqlite3ext.h ]
201 Zip::ZipInputStream.open( file ) do |io|
202 loop do
203 entry = io.get_next_entry
204 break unless entry
205 bname = File.basename( entry.name )
206 if upstream_files.include?( bname ) then
207 dest_file = File.join( "ext", "amalgalite", bname )
208 puts "updating #{dest_file}"
209 entry.extract( dest_file ) { true }
f16060b Jeremy Hinegardner update to upstream SQLite v3.6.3
authored
210 end
211 end
212 end
c3431a1 Jeremy Hinegardner core library in extension working
authored
213 end
214 end
9a92f42 Jeremy Hinegardner Back to green.
authored
215 task :clobber => 'ext:clobber'
216 task :clean => 'ext:clean'
217 task :test => 'ext:build'
Something went wrong with that request. Please try again.