tasks/build.rake in auser-skelerl-0.0.4 vs tasks/build.rake in auser-skelerl-0.0.5

- old
+ new

@@ -10,11 +10,11 @@ DEPS_FILES = DEPS.map {|d| "./deps/#{File.basename(d)}" } EXTRA_ERLC = DEPS_FILES.map {|a| "-pa #{a}/ebin" }.join(" ") ERLC_FLAGS = "-I#{INCLUDE} +warn_unused_vars +warn_unused_import -o ebin -W0 #{EXTRA_ERLC}" -SRC = FileList["src/*.erl"] +SRC = FileList["src/**/*.erl"] SRC_OBJ = SRC.pathmap("%{src,ebin}X.beam") DEP = DEPS_FILES.map {|d| FileList["#{d}/src/*.erl"]} DEP_OBJ = DEP.map {|d| d.pathmap("%{src,ebin}X.beam")} @@ -53,11 +53,12 @@ task :run_tests => :compile do puts "Modules under test:" TEST_OBJ.each do |obj| obj[%r{.*/(.*).beam}] mod = $1 - test_cmd = "erl -pa ebin -pa test/ebin -run #{mod} test -run init stop" + test_cmd = "erl -pa ebin -pa test/ebin #{EXTRA_ERLC} -run #{mod} test -run init stop" + $stdout.puts test_cmd test_output = `#{test_cmd}` puts test_output if Rake.application.options.trace if /\*failed\*/ =~ test_output @@ -68,10 +69,78 @@ puts "#{mod}: #{$1}" end end +class << self + %w{src ebin}.each do |type| + define_method "#{type}_dirs" do + Dir[Dir.pwd + "/#{type}"] + + Dir[Dir.pwd + "/**/deps/**/#{type}"] + + Dir[Dir.pwd + "/test/#{type}"] + end + end +end + +desc "Run all tests with coverage" +task :coverage => :compile do + puts "Modules under test:" + TEST_OBJ.each do |obj| + obj[%r{.*/(.*).beam}] + mod = $1 + next if ENV['MODULE'] && mod != ENV['MODULE'] + + FileUtils.mkdir(Dir.pwd + "/coverage") unless File.exists?(Dir.pwd + "/coverage") + compile = ebin_dirs.collect{|dir| "cover:compile_beam_directory(\"#{dir}\")," }.join("\n ") + analyse = src_dirs.inject([]) do |mem,dir| + Dir[dir + "/*.erl"].each do |file| + base = File.basename(file, ".erl") + mem << "cover:analyse_to_file(#{base}, \"coverage/#{base}.html\", [html])," + end + mem + end.join("\n ") + + test_cmd =<<EOF + +erl +A 10 -sname #{$$} -pa ebin -pa test/ebin #{EXTRA_ERLC} -eval ' + Module = list_to_atom (hd(init:get_plain_arguments())), + {value, {exports, E}} = lists:keysearch (exports, + 1, + Module:module_info()), + case lists:member({test, 0}, E) of + true -> ok; + false -> io:format("error, ~p:test/0 not exported; " ++ + "possibly you do not have eunit installed~n", + [Module]), + halt(77) + end, + #{compile} + io:format("~p:test () ...", [Module]), + ok = Module:test(), + #{analyse} + ok +' -noshell -run init stop -extra "#{mod}" +EOF + + # $stdout.puts test_cmd + test_output = `#{test_cmd}` + + puts test_output if Rake.application.options.trace + + if /\*failed\*/ =~ test_output + test_output[/(Failed.*Aborted.*Skipped.*Succeeded.*$)/] + else + test_output[/1>\s*(.*)\n/] + end + + puts "#{mod}: #{$1}" + + exit 1 if /\*failed\*/ =~ test_output + end +end + + desc "Clean the beams from the ebin directory" task :clean do # cmd = "rm #{::File.dirname(__FILE__)}/ebin/*.beam" # Kernel.system cmd end @@ -88,15 +157,17 @@ desc "Rebuild the boot scripts" task :build_boot_scripts => [:recompile] do puts "Rebuilding boot scripts" - root_dir = ::File.expand_path( ::File.join(::File.dirname(__FILE__)) ) + rakefile, location = Rake.application.find_rakefile_location + root_dir = ::File.expand_path( ::File.join(location) ) @version = ENV["VERSION"] || ENV["V"] || "0.1" - @name = ENV["NAME"] || ::File.basename(::File.dirname( root_dir )) + @name = ENV["NAME"] || ::File.basename(root_dir) cmd = "erl -pa ./ebin/ -run packager start #{@name} #{@version} -run init stop -noshell" + puts cmd Kernel.system cmd end desc "Rebuild and repackage" task :repackage => [:build_boot_scripts] do @@ -129,15 +200,36 @@ end end desc "Update and compile deps/" task :up => [:update, :compile] + + desc "Clean the deps" + task :clean do + DEPS_FILES.each do |dir| + cmd = "cd #{dir}/ebin && rm *.beam" + puts cmd if Rake.application.options.trace + Kernel.system cmd + end + end end desc "Build eunit" task :build_eunit do cmd = "cd test/include/eunit && make" Kernel.system cmd end desc "Compile and get a shell" -task :compile_shell => [:compile, :shell] +task :compile_shell => [:compile, :shell] + +desc "Generate ctags" +task :ctags do + ctags_cmd = "ctags -R --language-force=Erlang -F tags src/ deps/*/src test/src" + puts ctags_cmd + exec ctags_cmd +end + +desc "Generate Documentation" +task :doc do + sh("cd doc && erl -noshell -run edoc files ../#{SRC.join(" ../")} -run init stop") +end \ No newline at end of file