Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add back in custom rake tasks for amalgalite management

  • Loading branch information...
commit 1cdf529d76e80300492c372ca1833519823be524 1 parent 2f887ba
Jeremy Hinegardner authored March 13, 2013

Showing 2 changed files with 100 additions and 0 deletions. Show diff stats Hide diff stats

  1. 1  Rakefile
  2. 99  tasks/custom.rake
1  Rakefile
@@ -21,3 +21,4 @@ end
21 21
 
22 22
 load 'tasks/default.rake'
23 23
 load 'tasks/extension.rake'
  24
+load 'tasks/custom.rake'
99  tasks/custom.rake
... ...
@@ -0,0 +1,99 @@
  1
+#-----------------------------------------------------------------------
  2
+# Custom tasks for this project
  3
+#-----------------------------------------------------------------------
  4
+require 'pathname'
  5
+namespace :util do
  6
+  desc "List the sqlite api calls that are not implemented"
  7
+  task :todo do
  8
+
  9
+    not_implementing = %w[
  10
+      sqlite3_exec
  11
+      sqlite3_open
  12
+      sqlite3_os_end
  13
+      sqlite3_os_init
  14
+      sqlite3_malloc
  15
+      sqlite3_realloc
  16
+      sqlite3_free
  17
+      sqlite3_get_table
  18
+      sqlite3_free_table
  19
+      sqlite3_key
  20
+      sqlite3_rekey
  21
+      sqlite3_next_stmt
  22
+      sqlite3_release_memory
  23
+      sqlite3_sleep
  24
+      sqlite3_snprintf
  25
+      sqlite3_vmprintf
  26
+      sqlite3_strnicmp
  27
+      sqlite3_test_control
  28
+      sqlite3_unlock_notify
  29
+      sqlite3_vfs_find
  30
+      sqlite3_vfs_register
  31
+      sqlite3_vfs_unregister
  32
+    ]
  33
+
  34
+    sqlite_h = File.join( *%w[ ext amalgalite c sqlite3.h ] )
  35
+    api_todo = {}
  36
+    IO.readlines( sqlite_h ).each do |line|
  37
+      if line =~ /\ASQLITE_API/ then
  38
+        if line !~ /SQLITE_DEPRECATED/ and line !~ /SQLITE_EXPERIMENTAL/ then
  39
+          if md = line.match( /(sqlite3_[^(\s]+)\(/ ) then
  40
+                                next if not_implementing.include?(md.captures[0])
  41
+                                api_todo[md.captures[0]] = true
  42
+          end
  43
+        end
  44
+      end
  45
+    end
  46
+
  47
+    Dir.glob("ext/amalgalite/c/amalgalite*.c").each do |am_file|
  48
+      IO.readlines( am_file ).each do |am_line|
  49
+        if md = am_line.match( /(sqlite3_[^(\s]+)\(/ ) then
  50
+                                 api_todo.delete( md.captures[0] )
  51
+        end
  52
+      end
  53
+    end
  54
+
  55
+    puts "#{api_todo.keys.size} functions to still implement"
  56
+    puts api_todo.keys.sort.join("\n")
  57
+  end
  58
+
  59
+  desc "Download and integrate the next version of sqlite (use VERSION=x.y.z)"
  60
+  task :update_sqlite do
  61
+    require 'uri'
  62
+    require 'net/http'
  63
+    require 'zip'
  64
+
  65
+    parts = ENV['VERSION'].split(".")
  66
+    next_version = [ parts.shift.to_s ]
  67
+    parts.each do |p|
  68
+      next_version << "#{"%02d" % p }"
  69
+    end
  70
+    next_version << "00" if next_version.size == 3
  71
+
  72
+    next_version = next_version.join('')
  73
+
  74
+    raise "VERSION env variable must be set" unless next_version
  75
+    url = ::URI.parse("http://sqlite.org/sqlite-amalgamation-#{next_version}.zip")
  76
+    puts "downloading #{url.to_s} ..."
  77
+    file = "tmp/#{File.basename( url.path ) }"
  78
+    FileUtils.mkdir "tmp" unless File.directory?( "tmp" )
  79
+    File.open( file, "wb+") do |f|
  80
+      res = Net::HTTP.get_response( url )
  81
+      f.write( res.body )
  82
+    end
  83
+
  84
+    puts "extracting..."
  85
+    upstream_files = %w[ sqlite3.h sqlite3.c sqlite3ext.h ]
  86
+    Zip::ZipInputStream.open( file ) do |io|
  87
+      loop do
  88
+        entry = io.get_next_entry
  89
+        break unless entry
  90
+        bname = File.basename( entry.name )
  91
+        if upstream_files.include?( bname ) then
  92
+          dest_file = File.join( "ext", "amalgalite", "c", bname )
  93
+          puts "updating #{dest_file}"
  94
+          entry.extract( dest_file ) { true }
  95
+        end
  96
+      end
  97
+    end
  98
+  end
  99
+end

0 notes on commit 1cdf529

Please sign in to comment.
Something went wrong with that request. Please try again.