amalgalite 0.10.1-x86-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. data/HISTORY +201 -0
  2. data/LICENSE +29 -0
  3. data/README +51 -0
  4. data/bin/amalgalite-pack +126 -0
  5. data/examples/a.rb +9 -0
  6. data/examples/blob.rb +88 -0
  7. data/examples/bootstrap.rb +36 -0
  8. data/examples/define_aggregate.rb +75 -0
  9. data/examples/define_function.rb +104 -0
  10. data/examples/gem-db.rb +94 -0
  11. data/examples/gems.db +0 -0
  12. data/examples/require_me.rb +11 -0
  13. data/examples/requires.rb +42 -0
  14. data/examples/schema-info.rb +34 -0
  15. data/ext/amalgalite/amalgalite3.c +290 -0
  16. data/ext/amalgalite/amalgalite3.h +151 -0
  17. data/ext/amalgalite/amalgalite3_blob.c +240 -0
  18. data/ext/amalgalite/amalgalite3_constants.c +221 -0
  19. data/ext/amalgalite/amalgalite3_database.c +1148 -0
  20. data/ext/amalgalite/amalgalite3_requires_bootstrap.c +210 -0
  21. data/ext/amalgalite/amalgalite3_statement.c +639 -0
  22. data/ext/amalgalite/extconf.rb +36 -0
  23. data/ext/amalgalite/gen_constants.rb +130 -0
  24. data/ext/amalgalite/sqlite3.c +106729 -0
  25. data/ext/amalgalite/sqlite3.h +5626 -0
  26. data/ext/amalgalite/sqlite3_options.h +4 -0
  27. data/ext/amalgalite/sqlite3ext.h +380 -0
  28. data/gemspec.rb +60 -0
  29. data/lib/amalgalite.rb +43 -0
  30. data/lib/amalgalite/1.8/amalgalite3.so +0 -0
  31. data/lib/amalgalite/1.9/amalgalite3.so +0 -0
  32. data/lib/amalgalite/aggregate.rb +67 -0
  33. data/lib/amalgalite/blob.rb +186 -0
  34. data/lib/amalgalite/boolean.rb +42 -0
  35. data/lib/amalgalite/busy_timeout.rb +47 -0
  36. data/lib/amalgalite/column.rb +97 -0
  37. data/lib/amalgalite/core_ext/kernel/require.rb +21 -0
  38. data/lib/amalgalite/database.rb +947 -0
  39. data/lib/amalgalite/function.rb +61 -0
  40. data/lib/amalgalite/index.rb +43 -0
  41. data/lib/amalgalite/packer.rb +226 -0
  42. data/lib/amalgalite/paths.rb +70 -0
  43. data/lib/amalgalite/profile_tap.rb +131 -0
  44. data/lib/amalgalite/progress_handler.rb +21 -0
  45. data/lib/amalgalite/requires.rb +120 -0
  46. data/lib/amalgalite/schema.rb +191 -0
  47. data/lib/amalgalite/sqlite3.rb +6 -0
  48. data/lib/amalgalite/sqlite3/constants.rb +80 -0
  49. data/lib/amalgalite/sqlite3/database/function.rb +48 -0
  50. data/lib/amalgalite/sqlite3/database/status.rb +68 -0
  51. data/lib/amalgalite/sqlite3/status.rb +60 -0
  52. data/lib/amalgalite/sqlite3/version.rb +37 -0
  53. data/lib/amalgalite/statement.rb +414 -0
  54. data/lib/amalgalite/table.rb +90 -0
  55. data/lib/amalgalite/taps.rb +2 -0
  56. data/lib/amalgalite/taps/console.rb +27 -0
  57. data/lib/amalgalite/taps/io.rb +71 -0
  58. data/lib/amalgalite/trace_tap.rb +35 -0
  59. data/lib/amalgalite/type_map.rb +63 -0
  60. data/lib/amalgalite/type_maps/default_map.rb +167 -0
  61. data/lib/amalgalite/type_maps/storage_map.rb +40 -0
  62. data/lib/amalgalite/type_maps/text_map.rb +22 -0
  63. data/lib/amalgalite/version.rb +37 -0
  64. data/lib/amalgalite/view.rb +26 -0
  65. data/spec/aggregate_spec.rb +169 -0
  66. data/spec/amalgalite_spec.rb +4 -0
  67. data/spec/blob_spec.rb +81 -0
  68. data/spec/boolean_spec.rb +23 -0
  69. data/spec/busy_handler.rb +165 -0
  70. data/spec/database_spec.rb +494 -0
  71. data/spec/default_map_spec.rb +87 -0
  72. data/spec/function_spec.rb +94 -0
  73. data/spec/integeration_spec.rb +111 -0
  74. data/spec/packer_spec.rb +60 -0
  75. data/spec/paths_spec.rb +28 -0
  76. data/spec/progress_handler_spec.rb +105 -0
  77. data/spec/requires_spec.rb +23 -0
  78. data/spec/rtree_spec.rb +71 -0
  79. data/spec/schema_spec.rb +120 -0
  80. data/spec/spec_helper.rb +27 -0
  81. data/spec/sqlite3/constants_spec.rb +65 -0
  82. data/spec/sqlite3/database_status_spec.rb +36 -0
  83. data/spec/sqlite3/status_spec.rb +18 -0
  84. data/spec/sqlite3/version_spec.rb +14 -0
  85. data/spec/sqlite3_spec.rb +53 -0
  86. data/spec/statement_spec.rb +161 -0
  87. data/spec/storage_map_spec.rb +41 -0
  88. data/spec/tap_spec.rb +59 -0
  89. data/spec/text_map_spec.rb +23 -0
  90. data/spec/type_map_spec.rb +17 -0
  91. data/spec/version_spec.rb +15 -0
  92. data/tasks/announce.rake +43 -0
  93. data/tasks/config.rb +107 -0
  94. data/tasks/distribution.rake +77 -0
  95. data/tasks/documentation.rake +32 -0
  96. data/tasks/extension.rake +141 -0
  97. data/tasks/rspec.rake +33 -0
  98. data/tasks/rubyforge.rake +59 -0
  99. data/tasks/utils.rb +80 -0
  100. metadata +237 -0
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
5
+ require 'amalgalite/type_maps/storage_map'
6
+
7
+ describe Amalgalite::TypeMaps::StorageMap do
8
+ before(:each) do
9
+ @map = Amalgalite::TypeMaps::StorageMap.new
10
+ end
11
+
12
+ describe "#bind_type_of" do
13
+
14
+ it "Float is bound to DataType::FLOAT" do
15
+ @map.bind_type_of( 3.14 ).should == ::Amalgalite::SQLite3::Constants::DataType::FLOAT
16
+ end
17
+
18
+ it "Fixnum is bound to DataType::INTGER" do
19
+ @map.bind_type_of( 42 ).should == ::Amalgalite::SQLite3::Constants::DataType::INTEGER
20
+ end
21
+
22
+ it "nil is bound to DataType::NULL" do
23
+ @map.bind_type_of( nil ).should == ::Amalgalite::SQLite3::Constants::DataType::NULL
24
+ end
25
+
26
+ it "::Amalgalite::Blob is bound to DataType::BLOB" do
27
+ @map.bind_type_of( ::Amalgalite::Blob.new( :string => "testing mapping", :column => true ) ).should == ::Amalgalite::SQLite3::Constants::DataType::BLOB
28
+ end
29
+
30
+ it "everything else is bound to DataType::TEXT" do
31
+ @map.bind_type_of( "everything else" ).should == ::Amalgalite::SQLite3::Constants::DataType::TEXT
32
+ end
33
+
34
+ end
35
+
36
+ describe "#result_value_of" do
37
+ it "returns the original object for everything passed in" do
38
+ @map.result_value_of( "doesn't matter", 42 ).should == 42
39
+ end
40
+ end
41
+ end
data/spec/tap_spec.rb ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
5
+ require 'amalgalite'
6
+ require 'amalgalite/trace_tap'
7
+ require 'amalgalite/profile_tap'
8
+ require 'amalgalite/taps/console'
9
+ require 'stringio'
10
+
11
+ describe Amalgalite::TraceTap do
12
+ it "wraps up an object and delegates the 'trace' method to a method on that object" do
13
+ s = StringIO.new
14
+ tt = ::Amalgalite::TraceTap.new( s, 'puts' )
15
+ tt.trace('test trace')
16
+ s.string.should eql("test trace\n")
17
+ end
18
+
19
+ it "raises an error if an the wrapped object does not respond to the indicated method" do
20
+ lambda{ ::Amalgalite::TraceTap.new( Object.new ) }.should raise_error( Amalgalite::Error )
21
+ end
22
+ end
23
+
24
+ describe Amalgalite::ProfileTap do
25
+ it "raises an error if an the wrapped object does not respond to the indicated method" do
26
+ lambda{ ::Amalgalite::ProfileTap.new( Object.new ) }.should raise_error( Amalgalite::Error )
27
+ end
28
+ end
29
+
30
+ describe Amalgalite::Taps::StringIO do
31
+ it "dumps profile information" do
32
+ s = ::Amalgalite::Taps::StringIO.new
33
+ s.profile( 'test', 42 )
34
+ s.dump_profile
35
+ s.string.should eql("42 : test\n[test] => sum: 42, sumsq: 1764, n: 1, mean: 42.000000, stddev: 0.000000, min: 42, max: 42\n")
36
+ end
37
+
38
+ it "has a stdout tap" do
39
+ s = ::Amalgalite::Taps::Stdout.new
40
+ end
41
+
42
+ it "has a stderr tap" do
43
+ s = ::Amalgalite::Taps::Stderr.new
44
+ end
45
+ end
46
+
47
+ describe Amalgalite::ProfileSampler do
48
+ it "aggregates samples" do
49
+ s = Amalgalite::ProfileSampler.new( 'test1' )
50
+ s.sample( 42 )
51
+ s.sample( 84 )
52
+ s.sample( 21 )
53
+ h = s.to_h
54
+ h['min'].should eql(21)
55
+ h['max'].should eql(84)
56
+ h['mean'].should eql(49.0)
57
+ h['n'].should eql(3)
58
+ end
59
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
5
+ require 'amalgalite/type_maps/text_map'
6
+
7
+ describe Amalgalite::TypeMaps::TextMap do
8
+ before(:each) do
9
+ @map = Amalgalite::TypeMaps::TextMap.new
10
+ end
11
+
12
+ describe "#bind_type_of" do
13
+ it "returnes text for everything" do
14
+ @map.bind_type_of( 3.14 ).should == ::Amalgalite::SQLite3::Constants::DataType::TEXT
15
+ end
16
+ end
17
+
18
+ describe "#result_value_of" do
19
+ it "returns the string value of the object for everything passed in" do
20
+ @map.result_value_of( "doesn't matter", 42 ).should == "42"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
5
+ require 'amalgalite/type_map'
6
+
7
+ describe Amalgalite::TypeMap do
8
+ it "#bind_type_of raises NotImplemented error" do
9
+ tm = Amalgalite::TypeMap.new
10
+ lambda { tm.bind_type_of( Object.new ) }.should raise_error( NotImplementedError )
11
+ end
12
+
13
+ it "#result_value_of raises NotImplemented error" do
14
+ tm = Amalgalite::TypeMap.new
15
+ lambda { tm.result_value_of( "foo", Object.new ) }.should raise_error( NotImplementedError )
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),"spec_helper.rb"))
2
+ require 'amalgalite/version'
3
+
4
+ describe "Amalgalite::Version" do
5
+ it "should have a version string" do
6
+ Amalgalite::Version.to_s.should =~ /\d+\.\d+\.\d+/
7
+ Amalgalite::VERSION.should =~ /\d+\.\d+\.\d+/
8
+ end
9
+ it "should have a version hash" do
10
+ h = Amalgalite::Version.to_hash
11
+ [ :major, :minor, :build ].each do |k|
12
+ h[k].should_not be_nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ require 'tasks/config'
2
+ #-------------------------------------------------------------------------------
3
+ # announcement methods
4
+ #-------------------------------------------------------------------------------
5
+
6
+ proj_config = Configuration.for('project')
7
+ namespace :announce do
8
+ desc "create email for ruby-talk"
9
+ task :email do
10
+ info = Utils.announcement
11
+
12
+ File.open("email.txt", "w") do |mail|
13
+ mail.puts "From: #{proj_config.author} <#{proj_config.email}>"
14
+ mail.puts "To: ruby-talk@ruby-lang.org"
15
+ mail.puts "Date: #{Time.now.rfc2822}"
16
+ mail.puts "Subject: [ANN] #{info[:subject]}"
17
+ mail.puts
18
+ mail.puts info[:title]
19
+ mail.puts
20
+ mail.puts "{{ Release notes for Version #{Amalgalite::VERSION} }}"
21
+ mail.puts
22
+ mail.puts info[:release_notes]
23
+ mail.puts
24
+ mail.puts " #{info[:urls]}"
25
+ mail.puts
26
+ mail.puts "=== Installation"
27
+ mail.puts
28
+ mail.puts " gem install #{Amalgalite::GEM_SPEC.name}"
29
+ mail.puts
30
+ mail.puts "=== Description"
31
+ mail.puts
32
+ mail.puts info[:description]
33
+ mail.puts
34
+ end
35
+ puts "Created the following as email.txt:"
36
+ puts "-" * 72
37
+ puts File.read("email.txt")
38
+ puts "-" * 72
39
+ end
40
+
41
+ CLOBBER << "email.txt"
42
+ end
43
+
data/tasks/config.rb ADDED
@@ -0,0 +1,107 @@
1
+ require 'configuration'
2
+
3
+ require 'rake'
4
+ require 'tasks/utils'
5
+
6
+ #-----------------------------------------------------------------------
7
+ # General project configuration
8
+ #-----------------------------------------------------------------------
9
+ Configuration.for('project') {
10
+ name "amalgalite"
11
+ version Amalgalite::Version.to_s
12
+ author "Jeremy Hinegardner"
13
+ email "jeremy at copiousfreetime dot org"
14
+ homepage "http://copiousfreetime.rubyforge.org/amalgalite/"
15
+ description Utils.section_of("README", "description")
16
+ summary description.split(".").first
17
+ history "HISTORY"
18
+ license FileList["LICENSE"]
19
+ readme "README"
20
+ }
21
+
22
+ #-----------------------------------------------------------------------
23
+ # Packaging
24
+ #-----------------------------------------------------------------------
25
+ Configuration.for('packaging') {
26
+ # files in the project
27
+ proj_conf = Configuration.for('project')
28
+ files {
29
+ bin FileList["bin/*"]
30
+ ext FileList["ext/amalgalite/*.{c,h,rb}"]
31
+ examples FileList["examples/*"]
32
+ lib FileList["lib/**/*.rb"]
33
+ test FileList["spec/**/*.rb", "test/**/*.rb"]
34
+ data FileList["data/**/*"]
35
+ tasks FileList["tasks/**/*.r{ake,b}"]
36
+ rdoc FileList[proj_conf.readme, proj_conf.history,
37
+ proj_conf.license] + lib + FileList["ext/amalgalite3*.c"]
38
+ all bin + ext + examples + lib + test + data + rdoc + tasks
39
+ }
40
+
41
+ # ways to package the results
42
+ formats {
43
+ tgz true
44
+ zip true
45
+ rubygem Configuration::Table.has_key?('rubygem')
46
+ }
47
+ }
48
+
49
+ #-----------------------------------------------------------------------
50
+ # Gem packaging
51
+ #-----------------------------------------------------------------------
52
+ Configuration.for("rubygem") {
53
+ spec "gemspec.rb"
54
+ Configuration.for('packaging').files.all << spec
55
+ }
56
+
57
+ #-----------------------------------------------------------------------
58
+ # Testing
59
+ # - change mode to 'testunit' to use unit testing
60
+ #-----------------------------------------------------------------------
61
+ Configuration.for('test') {
62
+ mode "spec"
63
+ files Configuration.for("packaging").files.test
64
+ options %w[ --format profile --color ]
65
+ ruby_opts %w[ ]
66
+ }
67
+
68
+ #-----------------------------------------------------------------------
69
+ # Rcov
70
+ #-----------------------------------------------------------------------
71
+ Configuration.for('rcov') {
72
+ output_dir "coverage"
73
+ libs %w[ lib ]
74
+ rcov_opts %w[ --html ]
75
+ ruby_opts %w[ ]
76
+ test_files Configuration.for('packaging').files.test
77
+ }
78
+ #
79
+ #-----------------------------------------------------------------------
80
+ # Rdoc
81
+ #-----------------------------------------------------------------------
82
+ Configuration.for('rdoc') {
83
+ files Configuration.for('packaging').files.rdoc
84
+ main_page files.first
85
+ title Configuration.for('project').name
86
+ options %w[ ]
87
+ output_dir "doc"
88
+ }
89
+
90
+ #-----------------------------------------------------------------------
91
+ # Extensions
92
+ #-----------------------------------------------------------------------
93
+ Configuration.for('extension') {
94
+ configs Configuration.for('packaging').files.ext.find_all { |x| %w[ extconf.rb ].include?(File.basename(x)) }
95
+ cross_rbconfig YAML.load_file( File.expand_path("~/.rake-compiler/config.yml"))
96
+ }
97
+
98
+ #-----------------------------------------------------------------------
99
+ # Rubyforge
100
+ #-----------------------------------------------------------------------
101
+ Configuration.for('rubyforge') {
102
+ project "copiousfreetime"
103
+ user "jjh"
104
+ host "rubyforge.org"
105
+ rdoc_location "#{user}@#{host}:/var/www/gforge-projects/#{project}/amalgalite/"
106
+ }
107
+
@@ -0,0 +1,77 @@
1
+ require 'tasks/config'
2
+
3
+ #-------------------------------------------------------------------------------
4
+ # Distribution and Packaging
5
+ #-------------------------------------------------------------------------------
6
+ if pkg_config = Configuration.for_if_exist?("packaging") then
7
+
8
+ require 'gemspec'
9
+ require 'rake/gempackagetask'
10
+ require 'rake/contrib/sshpublisher'
11
+
12
+ namespace :dist do
13
+
14
+ Rake::GemPackageTask.new(Amalgalite::GEM_SPEC) do |pkg|
15
+ pkg.need_tar = pkg_config.formats.tgz
16
+ pkg.need_zip = pkg_config.formats.zip
17
+ end
18
+
19
+ desc "Install as a gem"
20
+ task :install => [:clobber, :package] do
21
+ sh "sudo gem install --local pkg/#{Amalgalite::GEM_SPEC.full_name}.gem --no-rdoc --no-ri"
22
+ end
23
+
24
+ desc "Uninstall gem"
25
+ task :uninstall do
26
+ sh "sudo gem uninstall -i #{Amalgalite::GEM_SPEC.name} -x"
27
+ end
28
+
29
+ desc "dump gemspec"
30
+ task :gemspec do
31
+ puts Amalgalite::GEM_SPEC.to_ruby
32
+ end
33
+
34
+ desc "dump gemspec for win"
35
+ task :gemspec_win do
36
+ puts Amalgalite::GEM_SPEC_MINGW32.to_ruby
37
+ end
38
+
39
+ desc "reinstall gem"
40
+ task :reinstall => [:uninstall, :repackage, :install]
41
+
42
+ desc "package up a windows gem"
43
+ task :package_win => :clean do
44
+ Configuration.for("extension").cross_rbconfig.keys.each do |rbconfig|
45
+ v = rbconfig.split("-").last
46
+ s = v.sub(/\.\d$/,'')
47
+ sh "rake ext:build_win-#{v}"
48
+ mkdir_p "lib/amalgalite/#{s}", :verbose => true
49
+ cp "ext/amalgalite/amalgalite3.so", "lib/amalgalite/#{s}/", :verbose => true
50
+ end
51
+
52
+ Amalgalite::SPECS.each do |spec|
53
+ next if spec.platform == "ruby"
54
+ spec.files += FileList["lib/amalgalite/{1.8,1.9}/**.{dll,so}"]
55
+ Gem::Builder.new( spec ).build
56
+ mkdir "pkg" unless File.directory?( 'pkg' )
57
+ mv Dir["*.gem"].first, "pkg"
58
+ end
59
+ end
60
+
61
+ task :clobber do
62
+ rm_rf 'lib/amalgalite/1.8'
63
+ rm_rf 'lib/amalgalite/1.9'
64
+ end
65
+
66
+ task :prep => [:clobber, :package, :package_win ]
67
+
68
+ desc "distribute copiously"
69
+ task :copious => :prep do
70
+ gems = Amalgalite::SPECS.collect { |s| "#{s.full_name}.gem" }
71
+ Rake::SshFilePublisher.new('jeremy@copiousfreetime.org',
72
+ '/var/www/vhosts/www.copiousfreetime.org/htdocs/gems/gems',
73
+ 'pkg', *gems).upload
74
+ sh "ssh jeremy@copiousfreetime.org rake -f /var/www/vhosts/www.copiousfreetime.org/htdocs/gems/Rakefile"
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,32 @@
1
+ require 'tasks/config'
2
+
3
+ #-----------------------------------------------------------------------
4
+ # Documentation
5
+ #-----------------------------------------------------------------------
6
+
7
+ if rdoc_config = Configuration.for_if_exist?('rdoc') then
8
+
9
+ namespace :doc do
10
+
11
+ require 'rdoc'
12
+ require 'rake/rdoctask'
13
+
14
+ # generating documentation locally
15
+ Rake::RDocTask.new do |rdoc|
16
+ rdoc.rdoc_dir = rdoc_config.output_dir
17
+ rdoc.options = rdoc_config.options
18
+ rdoc.rdoc_files = rdoc_config.files
19
+ rdoc.title = rdoc_config.title
20
+ rdoc.main = rdoc_config.main_page
21
+ end
22
+
23
+ if rubyforge_config = Configuration.for_if_exist?('rubyforge') then
24
+ desc "Deploy the RDoc documentation to #{rubyforge_config.rdoc_location}"
25
+ task :deploy => :rerdoc do
26
+ sh "rsync -zav --delete #{rdoc_config.output_dir}/ #{rubyforge_config.rdoc_location}"
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+
@@ -0,0 +1,141 @@
1
+ require 'tasks/config'
2
+ require 'pathname'
3
+ require 'zlib'
4
+ require 'archive/tar/minitar'
5
+
6
+ #-----------------------------------------------------------------------
7
+ # Extensions
8
+ #-----------------------------------------------------------------------
9
+
10
+ if ext_config = Configuration.for_if_exist?('extension') then
11
+ namespace :ext do
12
+ def current_sqlite_version
13
+ ext = Configuration.for('extension').configs.first
14
+ path = Pathname.new( ext )
15
+ h_path = path.dirname.realpath + "sqlite3.h"
16
+ File.open( h_path ) do |f|
17
+ f.each_line do |line|
18
+ if line =~ /\A#define SQLITE_VERSION\s+/ then
19
+ define ,constant ,value = line.split
20
+ return value
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ desc "Build the SQLite extension version #{current_sqlite_version}"
27
+ task :build => :clean do
28
+ ext_config.configs.each do |extension|
29
+ path = Pathname.new(extension)
30
+ parts = path.split
31
+ conf = parts.last
32
+ Dir.chdir(path.dirname) do |d|
33
+ ruby conf.to_s
34
+ sh "make"
35
+
36
+ # install into requireable location so specs will run
37
+ subdir = "amalgalite/#{RUBY_VERSION.sub(/\.\d$/,'')}"
38
+ dest_dir = Amalgalite::Paths.lib_path( subdir )
39
+ mkdir_p dest_dir, :verbose => true
40
+ cp "amalgalite3.#{Config::CONFIG['DLEXT']}", dest_dir, :verbose => true
41
+ end
42
+ end
43
+ end
44
+
45
+ def build_win( version = "1.8.6" )
46
+ ext_config = Configuration.for("extension")
47
+ rbconfig = ext_config.cross_rbconfig["rbconfig-#{version}"]
48
+ raise ArgumentError, "No cross compiler for version #{version}, we have #{ext_config.cross_rbconfig.keys.join(",")}" unless rbconfig
49
+ ruby_exe = if version =~ /1\.8/ then
50
+ "ruby"
51
+ else
52
+ "ruby1.9"
53
+ end
54
+ Amalgalite::GEM_SPEC.extensions.each do |extension|
55
+ path = Pathname.new(extension)
56
+ parts = path.split
57
+ conf = parts.last
58
+ Dir.chdir(path.dirname) do |d|
59
+ if File.exist?( "Makefile" ) then
60
+ sh "make clean distclean"
61
+ end
62
+ cp "#{rbconfig}", "rbconfig.rb"
63
+ sh "#{ruby_exe} -I. extconf.rb"
64
+ sh "make"
65
+ end
66
+ end
67
+ end
68
+
69
+ win_builds = []
70
+ ext_config.cross_rbconfig.keys.each do |v|
71
+ s = v.split("-").last
72
+ desc "Build the extension for windows version #{s}"
73
+ win_bname = "build_win-#{s}"
74
+ win_builds << win_bname
75
+ task win_bname => :clean do
76
+ build_win( s )
77
+ end
78
+ end
79
+
80
+ task :clean do
81
+ ext_config.configs.each do |extension|
82
+ path = Pathname.new(extension)
83
+ parts = path.split
84
+ conf = parts.last
85
+ Dir.chdir(path.dirname) do |d|
86
+ if File.exist?( "Makefile" ) then
87
+ sh "make clean"
88
+ end
89
+ rm_f "rbconfig.rb"
90
+ end
91
+ end
92
+ end
93
+
94
+ task :clobber do
95
+ ext_config.configs.each 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 distclean"
102
+ end
103
+ rm_f "rbconfig.rb"
104
+ end
105
+ end
106
+ end
107
+
108
+ desc "Download and integrate the next version of sqlite (use VERSION=x.y.z)"
109
+ task :update_sqlite do
110
+ next_version = ENV['VERSION']
111
+ raise "VERSION env variable must be set" unless next_version
112
+ puts "downloading ..."
113
+ url = URI.parse("http://sqlite.org/sqlite-amalgamation-#{next_version}.tar.gz")
114
+ file = "tmp/#{File.basename( url.path ) }"
115
+ FileUtils.mkdir "tmp" unless File.directory?( "tmp" )
116
+ File.open( file, "wb+") do |f|
117
+ res = Net::HTTP.get_response( url )
118
+ f.write( res.body )
119
+ end
120
+
121
+ puts "extracting..."
122
+ upstream_files = %w[ sqlite3.h sqlite3.c sqlite3ext.h ]
123
+ Zlib::GzipReader.open( file ) do |tgz|
124
+ Archive::Tar::Minitar::Reader.open( tgz ) do |tar|
125
+ tar.each_entry do |entry|
126
+ bname = File.basename( entry.full_name )
127
+ if upstream_files.include?( bname ) then
128
+ dest_file = File.join( "ext", "amalgalite", bname )
129
+ puts "updating #{ dest_file }"
130
+ File.open( dest_file, "wb" ) do |df|
131
+ while bytes = entry.read do
132
+ df.write bytes
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end