diff options
| author | KOBAYASHI Shuji <[email protected]> | 2021-01-08 20:32:08 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2021-01-08 20:36:54 +0900 |
| commit | 3a8d7bdf82dddb8d5e54330503d9ed11b4f68ad0 (patch) | |
| tree | e5c1e9c5f62a9bd4e495593c59b0d035a1d193ff | |
| parent | 04561cd999431264e10bb96915a26049cff29d92 (diff) | |
| download | mruby-3a8d7bdf82dddb8d5e54330503d9ed11b4f68ad0.tar.gz mruby-3a8d7bdf82dddb8d5e54330503d9ed11b4f68ad0.zip | |
Delay test code build until `rake test`
With this change, the test code will not be built unless `rake test` is
run, so there will be almost no side effects even if `enable_test` is
always set (but, gems specified by `add_test_dependency` are included
in `libmruby.a`).
Also added are `test: build` task, which only builds the test code
(including the main code), and `test: run` task, which only runs tests
independent of build. Therefore, the idiom for building in parallel and
not running tests in parallel is `rake -m test:build && rake test:run`.
| -rw-r--r-- | .github/workflows/build.yml | 16 | ||||
| -rw-r--r-- | .travis.yml | 2 | ||||
| -rw-r--r-- | Rakefile | 25 | ||||
| -rw-r--r-- | appveyor.yml | 4 | ||||
| -rw-r--r-- | lib/mruby/build.rb | 21 | ||||
| -rw-r--r-- | lib/mruby/gem.rb | 38 | ||||
| -rw-r--r-- | mrbgems/mruby-test/mrbgem.rake | 34 | ||||
| -rw-r--r-- | tasks/bin.rake | 20 | ||||
| -rw-r--r-- | tasks/mrbgems.rake | 20 | ||||
| -rw-r--r-- | tasks/test.rake | 64 |
10 files changed, 138 insertions, 106 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5e530ae5e..135e39ca7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: - name: Compiler version run: ${{ env.CC }} --version - name: Build and test - run: rake -m && rake test + run: rake -m test:build && rake test:run Ubuntu-1804-gcc: needs: Check-Skip @@ -40,7 +40,7 @@ jobs: - name: Compiler version run: ${{ env.CC }} --version - name: Build and test - run: rake -m && rake test + run: rake -m test:build && rake test:run Ubuntu-1804-clang: needs: Check-Skip @@ -55,7 +55,7 @@ jobs: - name: Compiler version run: ${{ env.CC }} --version - name: Build and test - run: rake -m && rake test + run: rake -m test:build && rake test:run macOS: needs: Check-Skip @@ -70,7 +70,7 @@ jobs: - name: Compiler version run: ${{ env.CC }} --version - name: Build and test - run: rake -m && rake test + run: rake -m test:build && rake test:run Windows-MinGW: needs: Check-Skip @@ -85,9 +85,7 @@ jobs: - name: Compiler version run: ${{ env.CC }} --version - name: Build and test - # If build and test are separated like `rake && rake test`, somehow - # it will be fully built even at `rake test`, so it is not separated. - run: rake test + run: rake -m test:build && rake test:run Windows-Cygwin: needs: Check-Skip @@ -130,7 +128,7 @@ jobs: run: ${{ env.CC }} --version - name: Build and test shell: cmd - run: ruby /usr/bin/rake -m && ruby /usr/bin/rake test + run: ruby /usr/bin/rake -m test:build && ruby /usr/bin/rake test:run - name: Set PATH for cache archiving (tar) # set Windows path so that Cygwin tar is not used for cache archiving run: echo '::set-env name=PATH::C:\windows\System32' @@ -148,4 +146,4 @@ jobs: shell: cmd run: | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" - rake -m && rake test + rake -m test:build && rake test:run diff --git a/.travis.yml b/.travis.yml index 1e09654be..c47a54494 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ env: - MRUBY_CONFIG=ci/gcc-clang script: - - rake -m && rake test + - rake -m test:build && rake test:run @@ -29,6 +29,7 @@ load "#{MRUBY_ROOT}/tasks/mrbgems.rake" load "#{MRUBY_ROOT}/tasks/libmruby.rake" load "#{MRUBY_ROOT}/tasks/bin.rake" load "#{MRUBY_ROOT}/tasks/presym.rake" +load "#{MRUBY_ROOT}/tasks/test.rake" load "#{MRUBY_ROOT}/tasks/benchmark.rake" load "#{MRUBY_ROOT}/tasks/gitlab.rake" load "#{MRUBY_ROOT}/tasks/doc.rake" @@ -51,37 +52,17 @@ end task :build => MRuby.targets.flat_map{|_, build| build.products} -desc "run all mruby tests" -task :test -MRuby.each_target do - if test_enabled? - t = :"test_#{self.name}" - task t => ["all"] do - run_test - end - task :test => t - end - - if bintest_enabled? - t = :"bintest_#{self.name}" - task t => ["all"] do - run_bintest - end - task :test => t - end -end - desc "clean all built and in-repo installed artifacts" task :clean do MRuby.each_target do |build| - rm_rf build.products rm_rf build.build_dir + rm_f build.products end puts "Cleaned up target build folder" end desc "clean everything!" -task :deep_clean => ["clean", "clean_doc"] do +task :deep_clean => %w[clean doc:clean] do MRuby.each_target do |build| rm_rf build.gem_clone_dir end diff --git a/appveyor.yml b/appveyor.yml index 227d7898e..9803bfa8d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -41,5 +41,5 @@ init: build_script: - set MRUBY_CONFIG=ci/msvc - - rake -m - - rake test + - rake -m test:build + - rake test:run diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index 2819ad594..ca2b28457 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -100,7 +100,7 @@ module MRuby @cc = Command::Compiler.new(self, %w(.c), label: "CC") @cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp), label: "CXX") @objc = Command::Compiler.new(self, %w(.m), label: "OBJC") - @asm = Command::Compiler.new(self, %w(.S .asm), label: "ASM") + @asm = Command::Compiler.new(self, %w(.S .asm .s), label: "ASM") @linker = Command::Linker.new(self) @archiver = Command::Archiver.new(self) @yacc = Command::Yacc.new(self) @@ -140,7 +140,6 @@ module MRuby end end current.presym = Presym.new(current) if current.presym_enabled? - current.build_mrbtest if current.test_enabled? end def libmruby_enabled? @@ -303,15 +302,12 @@ EOS def enable_test @enable_test = true end + alias build_mrbtest enable_test def test_enabled? @enable_test end - def build_mrbtest - gem :core => 'mruby-test' unless @gems['mruby-test'] - end - def build_mrbc_exec gem :core => 'mruby-bin-mrbc' unless @gems['mruby-bin-mrbc'] end @@ -363,6 +359,19 @@ EOS end end + def define_installer(src) + dst = "#{self.class.install_dir}/#{File.basename(src)}" + file dst => src do + install_D src, dst + end + dst + end + + def define_installer_if_needed(bin) + exe = exefile("#{build_dir}/bin/#{bin}") + host? ? define_installer(exe) : exe + end + def filename(name) if name.is_a?(Array) name.flatten.map { |n| filename(n) } diff --git a/lib/mruby/gem.rb b/lib/mruby/gem.rb index 4e918745f..f967bcb35 100644 --- a/lib/mruby/gem.rb +++ b/lib/mruby/gem.rb @@ -25,8 +25,8 @@ module MRuby alias :author= :authors= attr_accessor :rbfiles, :objs - attr_accessor :test_objs, :test_rbfiles, :test_args - attr_accessor :test_preload + attr_writer :test_objs, :test_rbfiles + attr_accessor :test_args, :test_preload attr_accessor :bins @@ -58,15 +58,8 @@ module MRuby @linker.run_attrs.each(&:clear) @rbfiles = Dir.glob("#{@dir}/mrblib/**/*.rb").sort - @objs = Dir.glob("#{@dir}/src/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| - objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X")) - end + @objs = srcs_to_objs("src") - @test_rbfiles = Dir.glob("#{@dir}/test/**/*.rb").sort - @test_objs = Dir.glob("#{@dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| - objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X")) - end - @custom_test_init = !@test_objs.empty? @test_preload = nil # 'test/assert.rb' @test_args = {} @@ -149,6 +142,14 @@ module MRuby "#{build_dir}/gem_test.c" end + def test_objs + @test_objs ||= srcs_to_objs("test") + end + + def test_rbfiles + @test_rbfiles ||= Dir["#{@dir}/test/**/*.rb"].sort! + end + def search_package(name, version_query=nil) package_query = name package_query += " #{version_query}" if version_query @@ -174,6 +175,13 @@ module MRuby end end + def srcs_to_objs(src_dir_from_gem_dir) + exts = compilers.flat_map{|c| c.source_exts} * "," + Dir["#{@dir}/#{src_dir_from_gem_dir}/*{#{exts}}"].map do |f| + objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X")) + end + end + def define_gem_init_builder file "#{build_dir}/gem_init.c" => [build.mrbcfile, __FILE__] + [rbfiles].flatten do |t| mkdir_p build_dir @@ -253,12 +261,8 @@ module MRuby f.puts %Q[#include <mruby/hash.h>] unless test_args.empty? end - def test_dependencies - [@name] - end - def custom_test_init? - @custom_test_init + !test_objs.empty? end def version_ok?(req_versions) @@ -487,6 +491,10 @@ module MRuby end end end + + def linker_attrs + map{|g| g.linker.run_attrs}.transpose + end end # List end # Gem diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 4a4a7af8f..421108e0b 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -3,26 +3,17 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| spec.author = 'mruby developers' spec.summary = 'mruby test' - build.bins << 'mrbtest' - spec.add_dependency('mruby-compiler', :core => 'mruby-compiler') - spec.test_rbfiles = Dir.glob("#{MRUBY_ROOT}/test/t/*.rb") clib = "#{build_dir}/mrbtest.c" mlib = clib.ext(exts.object) exec = exefile("#{build.build_dir}/bin/mrbtest") - - mrbtest_lib = libfile("#{build_dir}/mrbtest") - mrbtest_objs = [] - - driver_objs = Dir.glob("#{dir}/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| - objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X")) - end - assert_c = "#{build_dir}/assert.c" assert_rb = "#{MRUBY_ROOT}/test/assert.rb" assert_lib = assert_c.ext(exts.object) - mrbtest_objs << assert_lib + mrbtest_lib = libfile("#{build_dir}/mrbtest") + mrbtest_objs = [assert_lib] + driver_objs = srcs_to_objs(".") file assert_lib => assert_c file assert_c => [assert_rb, build.mrbcfile] do |t| @@ -37,8 +28,9 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| build.gems.each do |g| test_rbobj = g.test_rbireps.ext(exts.object) - g.test_objs << test_rbobj - dep_list = build.gems.tsort_dependencies(g.test_dependencies, gem_table).select(&:generate_functions) + mrbtest_objs.concat(g.test_objs) + mrbtest_objs << test_rbobj + dep_list = build.gems.tsort_dependencies([g.name], gem_table).select(&:generate_functions) file test_rbobj => g.test_rbireps file g.test_rbireps => [g.test_rbfiles, build.mrbcfile].flatten do |t| @@ -65,7 +57,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| g.test_rbfiles.flatten.each_with_index do |rbfile, i| g.build.mrbc.run f, rbfile, "gem_test_irep_#{g.funcname}_#{i}", false end - f.puts %Q[void mrb_#{g.funcname}_gem_test(mrb_state *mrb);] unless g.test_objs.empty? + f.puts %Q[void mrb_#{g.funcname}_gem_test(mrb_state *mrb);] if g.custom_test_init? dep_list.each do |d| f.puts %Q[void GENERATED_TMP_mrb_#{d.funcname}_gem_init(mrb_state *mrb);] f.puts %Q[void GENERATED_TMP_mrb_#{d.funcname}_gem_final(mrb_state *mrb);] @@ -128,23 +120,13 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| end end - build.gems.each do |v| - mrbtest_objs.concat v.test_objs - end - file mrbtest_lib => mrbtest_objs do |t| build.archiver.run t.name, t.prerequisites end unless build.build_mrbtest_lib_only? file exec => [*driver_objs, mlib, mrbtest_lib, build.libmruby_static] do |t| - gem_flags = build.gems.map { |g| g.linker.flags } - gem_flags_before_libraries = build.gems.map { |g| g.linker.flags_before_libraries } - gem_flags_after_libraries = build.gems.map { |g| g.linker.flags_after_libraries } - gem_libraries = build.gems.map { |g| g.linker.libraries } - gem_library_paths = build.gems.map { |g| g.linker.library_paths } - build.linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, - gem_flags_before_libraries, gem_flags_after_libraries + build.linker.run t.name, t.prerequisites, *build.gems.linker_attrs end end diff --git a/tasks/bin.rake b/tasks/bin.rake index afef065a1..bc8820b66 100644 --- a/tasks/bin.rake +++ b/tasks/bin.rake @@ -1,35 +1,23 @@ -install_task = ->(src) do - dst = "#{MRuby::Build.install_dir}/#{File.basename(src)}" - file dst => src do - install_D src, dst - end - dst -end - MRuby.each_target do |build| if build.host? && build.mrbc_build && !build.gems["mruby-bin-mrbc"] exe = build.exefile("#{build.mrbc_build.build_dir}/bin/mrbc") - build.products << install_task.(exe) + build.products << build.define_installer(exe) end - build.bins.each do |bin| - exe = build.exefile("#{build.build_dir}/bin/#{bin}") - build.products << (build.host? ? install_task.(exe) : exe) - end + build.bins.each{|bin| build.products << define_installer_if_needed(bin)} - linker_attrs = build.gems.map{|gem| gem.linker.run_attrs}.transpose + linker_attrs = build.gems.linker_attrs build.gems.each do |gem| gem.bins.each do |bin| exe = build.exefile("#{build.build_dir}/bin/#{bin}") objs = Dir["#{gem.dir}/tools/#{bin}/*.{c,cpp,cxx,cc}"].map do |f| build.objfile(f.pathmap("#{gem.build_dir}/tools/#{bin}/%n")) end - file exe => objs.concat(build.libraries) do |t| build.linker.run t.name, t.prerequisites, *linker_attrs end - build.products << (build.host? ? install_task.(exe) : exe) + build.products << define_installer_if_needed(bin) end end end diff --git a/tasks/mrbgems.rake b/tasks/mrbgems.rake index 0a3ae652d..ad98f7356 100644 --- a/tasks/mrbgems.rake +++ b/tasks/mrbgems.rake @@ -1,11 +1,12 @@ MRuby.each_target do + active_gems_txt = "#{build_dir}/mrbgems/active_gems.txt" + if enable_gems? # set up all gems gems.each(&:setup) gems.check self # loader all gems - active_gems_txt = "#{build_dir}/mrbgems/active_gems.txt" self.libmruby_objs << objfile("#{build_dir}/mrbgems/gem_init") file objfile("#{build_dir}/mrbgems/gem_init") => ["#{build_dir}/mrbgems/gem_init.c", "#{build_dir}/LEGAL"] file "#{build_dir}/mrbgems/gem_init.c" => [active_gems_txt, MRUBY_CONFIG, __FILE__] do |t| @@ -50,14 +51,15 @@ MRuby.each_target do f.puts %Q[}] end end - file active_gems_txt => :generate_active_gems_txt - task :generate_active_gems_txt do |t| - def t.timestamp; Time.at(0) end - active_gems = gems.sort_by(&:name).inject(""){|s, g| s << "#{g.name}\n"} - if !File.exist?(active_gems_txt) || File.read(active_gems_txt) != active_gems - mkdir_p File.dirname(active_gems_txt) - File.write(active_gems_txt, active_gems) - end + end + + file active_gems_txt => :generate_active_gems_txt + task :generate_active_gems_txt do |t| + def t.timestamp; Time.at(0) end + active_gems = gems.sort_by(&:name).inject(""){|s, g| s << "#{g.name}\n"} + if !File.exist?(active_gems_txt) || File.read(active_gems_txt) != active_gems + mkdir_p File.dirname(active_gems_txt) + File.write(active_gems_txt, active_gems) end end diff --git a/tasks/test.rake b/tasks/test.rake new file mode 100644 index 000000000..80f7670af --- /dev/null +++ b/tasks/test.rake @@ -0,0 +1,64 @@ +desc "build and run all mruby tests" +task :test => "test:build" do + Rake::Task["test:run"].invoke +end + +namespace :test do |test_ns| + desc "build and run library tests" + task :lib => "build:lib" do + test_ns["run:lib"].invoke + end + + desc "build and run command binaries tests" + task :bin => :all do + test_ns["run:bin"].invoke + end + + desc "build all mruby tests" + task :build => "build:lib" + + namespace :build do + desc "build library tests" + task :lib + end + + desc "run all mruby tests" + task :run + + namespace :run do + desc "run library tests" + task :lib + + desc "run command binaries tests" + task :bin + end +end + +MRuby.each_target do |build| + if build.test_enabled? + t = task "test:build:lib:#{build.name}" => :all do + gem = build.gem(core: 'mruby-test') + gem.setup + gem.setup_compilers + Rake::Task[build.define_installer_if_needed("mrbtest")].invoke + end + task "test:build:lib" => t + + t = task "test:run:lib:#{build.name}" do + build.run_test + end + task "test:run" => t + task "test:run:lib" => t + end + if build.bintest_enabled? + t = task "test:run:bin:#{build.name}" do + build.run_bintest + end + task "test:run" => t + task "test:run:bin" => t + end +end + +task :clean do + rm_f "#{MRuby::Build.install_dir}/mrbtest" +end |
