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 /lib | |
| 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`.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mruby/build.rb | 21 | ||||
| -rw-r--r-- | lib/mruby/gem.rb | 38 |
2 files changed, 38 insertions, 21 deletions
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 |
