make compiling easier if you installed bdb in the default location

This commit is contained in:
Justin Balthrop 2009-11-23 23:29:11 -08:00
parent 06357cb391
commit e0a617bde7
2 changed files with 3 additions and 128 deletions

View file

@ -1,43 +1,11 @@
#!/usr/bin/env ruby
require 'mkmf'
inc, lib = dir_config('db')
# OS X compatibility
if(PLATFORM =~ /darwin/) then
# test if Bdb is probably universal
filetype = (IO.popen("file #{inc}/../db_dump").readline.chomp rescue nil)
# if it's not universal, ARCHFLAGS should be set
if((filetype !~ /universal binary/) && ENV['ARCHFLAGS'].nil?) then
arch = (IO.popen("uname -m").readline.chomp rescue nil)
$stderr.write %{
=========== WARNING ===========
You are building this extension on OS X without setting the
ARCHFLAGS environment variable, and BerkeleyDB does not appear
to have been built as a universal binary. If you are seeing this
message, that means that the build will probably fail.
Try setting the environment variable ARCHFLAGS
to '-arch #{arch}' before building.
For example:
(in bash) $ export ARCHFLAGS='-arch #{arch}'
(in tcsh) % setenv ARCHFLAGS '-arch #{arch}'
Then try building again.
===================================
}
# We don't exit here. Who knows? It might build.
end
end
default_dir = '/usr/local/BerkeleyDB.4.8'
inc, lib = dir_config('db', "#{default_dir}/include", "#{default_dir}/lib")
versions=%w(db-4.8 db-4.7 db-4.6 db-4.5 db-4.4 db-4.3 db-4.2)
until versions.empty?
(lib_ok = have_library(versions.shift,'db_version', 'db.h')) && break
(lib_ok = have_library(versions.shift, 'db_version', 'db.h')) && break
end
def create_header

View file

@ -1,93 +0,0 @@
require 'test_helper'
require File.dirname(__FILE__) + '/../lib/bdb/simple'
class SimpleTest < Test::Unit::TestCase
def setup
@path = File.join(File.dirname(__FILE__), 'tmp')
rm_rf @path
mkdir @path
open
end
def teardown
close
rm_rf @path
end
def open
@db = Bdb::Simple.new(@path)
@dbd = Bdb::Simple.new(@path, :name => 'dup', :dup => true)
end
def close
@db.close
@dbd.close
end
def test_put_and_get
@db['key'] = 'data'
assert_equal 'data', @db['key']
@dbd['key'] = 'data1'
@dbd['key'] = 'data2'
assert_equal ['data1', 'data2'], @dbd['key'].to_a
end
def test_update
@db[:key] = 0
close
pids = []
5.times do
pids << Process.fork do
db = Bdb::Simple.new(@path)
10.times do
db.update(:key) do |v|
sleep(0.1)
v + 1
end
end
db.close
end
end
pids.each {|pid| Process.wait(pid)}
open
assert_equal 50, @db[:key]
end
def test_delete
@db['key'] = 'data'
assert_equal 'data', @db['key']
@db.delete('key')
assert_nil @db['key']
end
def test_range
(1..10).each {|i| @db[i] = "data#{i}"}
assert_equal (3..7).collect {|i| "data#{i}"}, @db[3..7].to_a
end
def test_compare_absolute
list = [5, 6, "foo", :bar, "bar", :foo, [1,2,4], true, [1,2,3], false, [1], [2], nil, {}, {:b => 1, :a => 1}, {:b => 2, :a => 1}]
expected = [nil, false, true, 5, 6, :bar, :foo, "bar", "foo", [1], [1, 2, 3], [1, 2, 4], [2], {}, {:a=>1, :b=>1}, {:a=>1, :b=>2}]
assert_equal expected, list.sort {|a,b| Bdb::Simple.compare_absolute(a,b)}
100.times do
assert_equal expected, list.shuffle.sort {|a,b| Bdb::Simple.compare_absolute(a,b)}
end
end
def parallel(n)
threads = []
n.times do |i|
threads << Thread.new do
yield(i)
end
end
threads.each { |thread| thread.join }
end
end