From 58970fd32cb2cf17d51f897d5ca6997acafa47b0 Mon Sep 17 00:00:00 2001 From: Phillip Toland Date: Thu, 12 Feb 2009 12:49:50 -0600 Subject: [PATCH] Use Erlbox. --- .gitignore | 3 +- Rakefile | 53 +++-------- base.rake | 181 -------------------------------------- int_test/stress_SUITE.erl | 2 +- 4 files changed, 12 insertions(+), 227 deletions(-) delete mode 100644 base.rake diff --git a/.gitignore b/.gitignore index eab0f42..7aaecde 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,7 @@ *.beam *.tmproj c_src/system -test/logs +logs test/test.cover -int_test/logs int_test/test.cover bdberl-* diff --git a/Rakefile b/Rakefile index ff0ac70..f74974f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,56 +1,23 @@ -load "base.rake" +require 'erlbox' +require 'erlbox/driver' -C_SRCS = FileList["c_src/*.c"] -C_OBJS = C_SRCS.pathmap("%X.o") - -CLEAN.include %w( c_src/*.o priv/*.so ) CLOBBER.include %w( c_src/system ) -directory 'c_src' +UNIT_TEST_FLAGS << '+A10' +INT_TEST_FLAGS << '+A10' DB_LIB = "c_src/system/lib/libdb.a" -DRIVER = "priv/bdberl_drv.so" file DB_LIB do sh "cd c_src && ./buildlib.sh 2>&1" end -file DRIVER => [:compile_c] do - puts "linking priv/#{DRIVER}..." - sh "gcc -g #{erts_link_cflags()} c_src/*.o c_src/system/lib/libdb-*.a -o #{DRIVER}", :verbose => false -end +# This is a slightl kludgey way of getting DB_LIB into +# dependency chain early enough +file 'c_src/bdberl_drv.c' => [DB_LIB] -rule ".o" => ["%X.c", "%X.h"] do |t| - puts "compiling #{t.source}..." - sh "gcc -g -c -Wall -Werror -fPIC #{dflag} -Ic_src/system/include -I#{erts_dir()}/include #{t.source} -o #{t.name}", :verbose => false -end - -def dflag() - ENV["release"] ? "" : "-DDEBUG" -end - -task :compile_c => ['c_src'] + C_OBJS - -task :compile => [DB_LIB, DRIVER] - -task :test do - run_tests "test", "+A10" -end - -task :int_test do - run_tests "int_test", "+A10" -end - -task :package => [:compile] do - app = File.basename(APP, ".app") - vsn = erl_app_version(app) - target_dir = "#{app}-#{vsn}" - Dir.mkdir target_dir - cp_r 'ebin', target_dir - cp_r 'include', target_dir - cp_r 'src', target_dir - cp_r 'priv', target_dir +task :package do + target_dir = package_dir Dir.mkdir "#{target_dir}/priv/bin" - cp_r Dir.glob('c_src/system/bin/*'), "#{target_dir}/priv/bin" - puts "Packaged to #{target_dir}" + FileUtils.cp_r Dir.glob('c_src/system/bin/*'), "#{target_dir}/priv/bin", :verbose => false end diff --git a/base.rake b/base.rake deleted file mode 100644 index 3b0f0a1..0000000 --- a/base.rake +++ /dev/null @@ -1,181 +0,0 @@ -require 'rake/clean' -require 'set' - -PWD = Dir.getwd -BASE_DIR = File.expand_path "#{PWD}" - -SRC = FileList['src/*.erl'] -OBJ = SRC.pathmap("%{src,ebin}X.beam") -EBIN = FileList["#{BASE_DIR}/**/ebin"] -APP = FileList["#{PWD}/ebin/*.app"][0] - -INCLUDE = "./include" -ERLC_FLAGS = "-I#{INCLUDE} -pa #{EBIN.join(' -pa ')} +debug_info " - -CLEAN.include %w( **/*.beam **/erl_crash.dump ) -CLOBBER.include %w( perf_test/logs int_test/logs test/logs doc ) - -directory 'ebin' - -rule ".beam" => ["%{ebin,src}X.erl"] do |t| - puts "compiling #{t.source}..." - sh "erlc -W #{ERLC_FLAGS} -o ebin #{t.source}", :verbose => false -end - -desc "Compile Erlang sources to .beam files" -task :compile => ['ebin'] + OBJ do - do_validate_app -end - -desc "Do a fresh build from scratch" -task :rebuild => [:clean, :compile] - -task :default => [:compile] - -task :compile_tests do - do_compile_tests("test") -end - -desc "Run unit tests" -task :test => [:compile, :compile_tests] - -task :compile_int_tests do - do_compile_tests("int_test") -end - -desc "Run integration tests" -task :int_test => [:compile, :compile_int_tests] - -def erl_run(script, args = "") - `erl -eval '#{script}' -s erlang halt #{args} -noshell 2>&1`.strip -end - -def erl_where(lib) - script = <<-ERL - io:format("~s\n", [filename:join(code:lib_dir(#{lib}), "include")]) - ERL - erl_run(script) -end - -def erl_app_modules(app) - script = <<-ERL - ok = application:load(#{app}), - {ok, M} = application:get_key(#{app}, modules), - [io:format("~s\\n", [Mod]) || Mod <- M]. - ERL - - output = erl_run(script, "-pa ebin") - if output[/badmatch/] - fail "Error processing .app file: ", output - "" - else - output.split("\n") - end -end - -def erl_app_version(app) - script = <<-ERL - ok = application:load(#{app}), - {ok, Vsn} = application:get_key(#{app}, vsn), - io:format("~s\\n", [Vsn]). - ERL - output = erl_run(script, "-pa ebin") - output.strip() -end - -def erl_app_version(app) - script = <<-ERL - ok = application:load(#{app}), - {ok, Vsn} = application:get_key(#{app}, vsn), - io:format("~s\\n", [Vsn]). - ERL - output = erl_run(script, "-pa ebin") - output.strip() -end - -def erts_dir() - script = <<-ERL - io:format("~s\n", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)])]) - ERL - erl_run(script) -end - -def erts_link_cflags() - if `uname`.strip() == "Darwin" - " -fPIC -bundle -flat_namespace -undefined suppress " - else - " -fpic -shared" - end -end - -def do_validate_app() - # Setup app name and build sets of modules from the .app as well as - # beams that got compiled - if APP == nil - puts "No .app file found; skipping validation." - return - end - - app = File.basename(APP, ".app") - modules = Set.new(erl_app_modules(app)) - beams = Set.new(OBJ.pathmap("%n").to_a) - - puts "validating #{app}.app..." - - # Identify .beam files which are listed in the .app, but not present in ebin/ - missing_beams = (modules - beams) - if not missing_beams.empty? - msg = "One or more modules listed in #{app}.app do not exist as .beam:\n" - missing_beams.each { |m| msg << " * #{m}\n" } - fail msg - end - - # Identify modules which are not listed in the .app, but are present in ebin/ - missing_modules = (beams - modules) - if not missing_modules.empty? - msg = "One or more .beam files exist that are not listed in #{app}.app:\n" - missing_modules.each { |m| msg << " * #{m}\n" } - fail msg - end -end - - -def do_compile_tests(dir) - if File.directory?(dir) - compile_cmd = "erlc #{ERLC_FLAGS} -I#{erl_where('common_test')} \ - -I#{erl_where('test_server')} -o #{dir} #{dir}/*.erl".squeeze(" ") - - sh compile_cmd, :verbose => false - - Dir.mkdir "#{dir}/logs" unless File.directory?("#{dir}/logs") - end -end - -def run_tests(dir, rest = "") - sh "erl -pa #{EBIN.join(' ')} #{PWD}/ebin #{PWD}/include \ - -noshell -s ct_run script_start -s erlang halt \ - #{get_cover(dir)} \ - #{get_suites(dir)} -logdir #{dir}/logs -env TEST_DIR #{PWD}/#{dir} \ - #{rest}"# , :verbose => false - -end - -def get_cover(dir) - use_cover = ENV["use_cover"] - if use_cover - "-cover #{dir}/cover.spec" - else - "" - end -end - -def get_suites(dir) - suites = ENV['suites'] - if suites - all_suites = "" - suites.each(' ') {|s| all_suites << "#{PWD}/#{dir}/#{s.strip}_SUITE "} - "-suite #{all_suites}" - else - "-dir #{dir}" - end -end diff --git a/int_test/stress_SUITE.erl b/int_test/stress_SUITE.erl index 3d08c2b..e34cd08 100644 --- a/int_test/stress_SUITE.erl +++ b/int_test/stress_SUITE.erl @@ -20,7 +20,7 @@ all() -> init_per_suite(Config) -> {ok, Cwd} = file:get_cwd(), - {ok, _} = file:copy(lists:append([Cwd, "/../../../int_test/DB_CONFIG"]), + {ok, _} = file:copy(lists:append([Cwd, "/../../int_test/DB_CONFIG"]), lists:append([Cwd, "/DB_CONFIG"])), crypto:start(), Config.