From f715f2ddeacdf6301e8882b771252080b90d2b18 Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Wed, 13 Jun 2018 23:32:08 +0900 Subject: Fix unnecessary rebuild of tests. --- mrbgems/mruby-test/mrbgem.rake | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 7da0b5e50..27c635a5d 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -155,14 +155,18 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| # store the last gem selection and make the re-build # of the test gem depending on a change to the gem # selection - active_gems = "#{build_dir}/active_gems.lst" - FileUtils.mkdir_p File.dirname(active_gems) - open(active_gems, 'w+') do |f| - build.gems.each do |g| - f.puts g.name - end + active_gems_path = "#{build_dir}/active_gems_path.lst" + active_gem_list = if File.exist? active_gems_path + File.read active_gems_path + else + FileUtils.mkdir_p File.dirname(active_gems_path) + nil + end + current_gem_list = build.gems.map(&:name).join("\n") + if active_gem_list != current_gem_list + File.write active_gems_path, current_gem_list end - file clib => active_gems + file clib => active_gems_path file mlib => clib file clib => init do |t| -- cgit v1.2.3 From dfddc6a09f6c287f76d5276cb9dfa43444708f12 Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Wed, 20 Jun 2018 18:21:33 +0900 Subject: Fix dependencies. --- mrbgems/mruby-bin-mruby-config/mrbgem.rake | 5 +++-- mrbgems/mruby-compiler/mrbgem.rake | 3 +-- mrbgems/mruby-test/mrbgem.rake | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-bin-mruby-config/mrbgem.rake b/mrbgems/mruby-bin-mruby-config/mrbgem.rake index 66d6ef80b..32ae2164b 100644 --- a/mrbgems/mruby-bin-mruby-config/mrbgem.rake +++ b/mrbgems/mruby-bin-mruby-config/mrbgem.rake @@ -19,9 +19,10 @@ MRuby.each_target do mruby_config_path = "#{build_dir}/bin/#{mruby_config}" @bins << mruby_config - file mruby_config_path => libfile("#{build_dir}/lib/libmruby") do |t| + make_cfg = "#{build_dir}/lib/libmruby.flags.mak" + file mruby_config_path => [libfile("#{build_dir}/lib/libmruby"), make_cfg] do |t| FileUtils.copy "#{File.dirname(__FILE__)}/#{mruby_config}", t.name - config = Hash[open("#{build_dir}/lib/libmruby.flags.mak").read.split("\n").map {|x| a = x.split(/\s*=\s*/, 2); [a[0], a[1].gsub('\\"', '"') ]}] + config = Hash[open(make_cfg).read.split("\n").map {|x| a = x.split(/\s*=\s*/, 2); [a[0], a[1].gsub('\\"', '"') ]}] IO.write(t.name, File.open(t.name) {|f| f.read.gsub (/echo (MRUBY_CFLAGS|MRUBY_LIBS|MRUBY_LDFLAGS_BEFORE_LIBS|MRUBY_LDFLAGS|MRUBY_LIBMRUBY_PATH)/) {|x| config[$1].empty? ? '' : "echo #{config[$1]}"} }) diff --git a/mrbgems/mruby-compiler/mrbgem.rake b/mrbgems/mruby-compiler/mrbgem.rake index 6decd643b..e9e0cc2c7 100644 --- a/mrbgems/mruby-compiler/mrbgem.rake +++ b/mrbgems/mruby-compiler/mrbgem.rake @@ -23,10 +23,9 @@ MRuby::Gem::Specification.new 'mruby-compiler' do |spec| cc.run t.name, t.prerequisites.first, [], ["#{current_dir}/core"] end end - file objfile("#{current_build_dir}/core/y.tab") => lex_def # Parser - file "#{current_build_dir}/core/y.tab.c" => ["#{current_dir}/core/parse.y"] do |t| + file "#{current_build_dir}/core/y.tab.c" => ["#{current_dir}/core/parse.y", lex_def] do |t| FileUtils.mkdir_p File.dirname t.name yacc.run t.name, t.prerequisites.first end diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 27c635a5d..b9b10fc60 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -31,7 +31,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| mrbtest_objs << assert_lib file assert_lib => assert_c - file assert_c => assert_rb do |t| + file assert_c => [assert_rb, build.mrbcfile] do |t| open(t.name, 'w') do |f| mrbc.run f, assert_rb, 'mrbtest_assert_irep' end @@ -45,7 +45,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| dep_list = build.gems.tsort_dependencies(g.test_dependencies, gem_table).select(&:generate_functions) file test_rbobj => g.test_rbireps - file g.test_rbireps => [g.test_rbfiles].flatten do |t| + file g.test_rbireps => [g.test_rbfiles, build.mrbcfile].flatten do |t| FileUtils.mkdir_p File.dirname(t.name) open(t.name, 'w') do |f| g.print_gem_test_header(f) @@ -169,7 +169,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| file clib => active_gems_path file mlib => clib - file clib => init do |t| + file clib => [init, build.mrbcfile] do |t| _pp "GEN", "*.rb", "#{clib.relative_path}" FileUtils.mkdir_p File.dirname(clib) open(clib, 'w') do |f| -- cgit v1.2.3 From 633599a2cb90ff5b7eb7259e0247c3220b048d85 Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Wed, 20 Jun 2018 18:21:57 +0900 Subject: Fix forgotten argument passing. --- mrbgems/mruby-test/mrbgem.rake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index b9b10fc60..01835c542 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -146,7 +146,8 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| 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 + build.linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, + gem_flags_before_libraries, gem_flags_after_libraries end end -- cgit v1.2.3 From a212428fede9fd05c118b5153936af7560b0a8eb Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Wed, 20 Jun 2018 18:22:50 +0900 Subject: Comment out unused variable. --- mrbgems/mruby-test/mrbgem.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 01835c542..ac9c2fe21 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -23,7 +23,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| mrbtest_objs = [] driver_obj = objfile("#{build_dir}/driver") - driver = "#{spec.dir}/driver.c" + # driver = "#{spec.dir}/driver.c" assert_c = "#{build_dir}/assert.c" assert_rb = "#{MRUBY_ROOT}/test/assert.rb" -- cgit v1.2.3 From 1d7c69a7cb9d58a8d6b9754fa45e2cad2dca64fa Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Wed, 20 Jun 2018 18:23:08 +0900 Subject: Fix dependencies. --- mrbgems/mruby-test/mrbgem.rake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index ac9c2fe21..0aecae274 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -164,10 +164,11 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| nil end current_gem_list = build.gems.map(&:name).join("\n") - if active_gem_list != current_gem_list - File.write active_gems_path, current_gem_list + task active_gems_path do |t| + FileUtils.mkdir_p File.dirname t.name + File.write t.name, current_gem_list end - file clib => active_gems_path + file clib => active_gems_path if active_gem_list != current_gem_list file mlib => clib file clib => [init, build.mrbcfile] do |t| -- cgit v1.2.3 From b8fec13cabc8ee306c9bde530a89878fb8d29284 Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Wed, 20 Jun 2018 18:29:11 +0900 Subject: Make codacy happy. --- mrbgems/mruby-test/mrbgem.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 0aecae274..11d780f75 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -171,7 +171,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| file clib => active_gems_path if active_gem_list != current_gem_list file mlib => clib - file clib => [init, build.mrbcfile] do |t| + file clib => [init, build.mrbcfile] do |_t| _pp "GEN", "*.rb", "#{clib.relative_path}" FileUtils.mkdir_p File.dirname(clib) open(clib, 'w') do |f| -- cgit v1.2.3 From b1f1fe2f81f4b8a236c8fb8dbd5bea0aec25ee54 Mon Sep 17 00:00:00 2001 From: Sebastián Katzer Date: Sun, 8 Jul 2018 13:51:00 +0200 Subject: Fix task name is not necessarily a valid path Errno::ENOENT: No such file or directory @ dir_s_mkdir - mruby:Z:/Documents --- mrbgems/mruby-test/mrbgem.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 11d780f75..589fc688a 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -164,9 +164,9 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| nil end current_gem_list = build.gems.map(&:name).join("\n") - task active_gems_path do |t| - FileUtils.mkdir_p File.dirname t.name - File.write t.name, current_gem_list + task active_gems_path do |_t| + FileUtils.mkdir_p File.dirname(active_gems_path) + File.write active_gems_path, current_gem_list end file clib => active_gems_path if active_gem_list != current_gem_list -- cgit v1.2.3 From c240aeada99a410e41afcfa5f36f1a0d370f7aa3 Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Mon, 29 Oct 2018 13:58:57 +0900 Subject: Add missing dependency of source code generator --- mrbgems/mruby-test/mrbgem.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 589fc688a..ee70d906f 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -171,7 +171,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| file clib => active_gems_path if active_gem_list != current_gem_list file mlib => clib - file clib => [init, build.mrbcfile] do |_t| + file clib => [init, build.mrbcfile, __FILE__] do |_t| _pp "GEN", "*.rb", "#{clib.relative_path}" FileUtils.mkdir_p File.dirname(clib) open(clib, 'w') do |f| -- cgit v1.2.3 From b37b31208152fdee0cb99e00cffec0b9e57040c6 Mon Sep 17 00:00:00 2001 From: take-cheeze Date: Mon, 29 Oct 2018 13:56:20 +0900 Subject: Rename libmruby stuff to avoid confusion --- Rakefile | 4 ++-- lib/mruby/build.rb | 18 ++++++++++++++++-- lib/mruby/gem.rb | 2 +- mrbgems/mruby-bin-mrbc/mrbgem.rake | 2 +- mrbgems/mruby-bin-mruby-config/mrbgem.rake | 2 +- mrbgems/mruby-compiler/mrbgem.rake | 2 +- mrbgems/mruby-test/mrbgem.rake | 5 +---- mrblib/mrblib.rake | 2 +- src/mruby_core.rake | 4 ++-- tasks/libmruby.rake | 6 +++--- tasks/mrbgems.rake | 2 +- 11 files changed, 30 insertions(+), 19 deletions(-) (limited to 'mrbgems/mruby-test') diff --git a/Rakefile b/Rakefile index d2ad9044c..20b6096f5 100644 --- a/Rakefile +++ b/Rakefile @@ -65,7 +65,7 @@ MRuby.each_target do |target| exec = exefile("#{build_dir}/bin/#{bin}") objs = Dir.glob("#{current_dir}/tools/#{bin}/*.{c,cpp,cxx,cc}").map { |f| objfile(f.pathmap("#{current_build_dir}/tools/#{bin}/%n")) } - file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t| + file exec => objs + target.libraries do |t| gem_flags = gems.map { |g| g.linker.flags } gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries } gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries } @@ -100,7 +100,7 @@ MRuby.each_target do |target| end depfiles += MRuby.targets.map { |n, t| - [t.libfile("#{t.build_dir}/lib/libmruby")] + t.libraries }.flatten depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t| diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index 047ae13dc..7a0f7a759 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -45,9 +45,11 @@ module MRuby include Rake::DSL include LoadGems attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir - attr_reader :libmruby, :gems, :toolchains + attr_reader :libmruby_objs, :gems, :toolchains attr_writer :enable_bintest, :enable_test + alias libmruby libmruby_objs + COMPILERS = %w(cc cxx objc asm) COMMANDS = COMPILERS + %w(linker archiver yacc gperf git exts mrbc) attr_block MRuby::Build::COMMANDS @@ -81,7 +83,7 @@ module MRuby @mrbc = Command::Mrbc.new(self) @bins = [] - @gems, @libmruby = MRuby::Gem::List.new, [] + @gems, @libmruby_objs = MRuby::Gem::List.new, [] @build_mrbtest_lib_only = false @cxx_exception_enabled = false @cxx_exception_disabled = false @@ -327,6 +329,18 @@ EOS puts "================================================" puts end + + def libmruby_static + libfile("#{build_dir}/lib/libmruby") + end + + def libmruby_core_static + libfile("#{build_dir}/lib/libmruby_core") + end + + def libraries + [libmruby_static] + end end # Build class CrossBuild < Build diff --git a/lib/mruby/gem.rb b/lib/mruby/gem.rb index 7e97c34f3..ba4d5d17a 100644 --- a/lib/mruby/gem.rb +++ b/lib/mruby/gem.rb @@ -87,7 +87,7 @@ module MRuby fail "#{name || dir} required to set name, license(s) and author(s)" end - build.libmruby << @objs + build.libmruby_objs << @objs instance_eval(&@build_config_initializer) if @build_config_initializer end diff --git a/mrbgems/mruby-bin-mrbc/mrbgem.rake b/mrbgems/mruby-bin-mrbc/mrbgem.rake index e710b5a49..48b67aedb 100644 --- a/mrbgems/mruby-bin-mrbc/mrbgem.rake +++ b/mrbgems/mruby-bin-mrbc/mrbgem.rake @@ -8,7 +8,7 @@ MRuby::Gem::Specification.new 'mruby-bin-mrbc' do |spec| exec = exefile("#{build.build_dir}/bin/mrbc") mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }.flatten - file exec => mrbc_objs + [libfile("#{build.build_dir}/lib/libmruby_core")] do |t| + file exec => mrbc_objs + [build.libmruby_core_static] do |t| build.linker.run t.name, t.prerequisites end diff --git a/mrbgems/mruby-bin-mruby-config/mrbgem.rake b/mrbgems/mruby-bin-mruby-config/mrbgem.rake index 32ae2164b..cca7423ac 100644 --- a/mrbgems/mruby-bin-mruby-config/mrbgem.rake +++ b/mrbgems/mruby-bin-mruby-config/mrbgem.rake @@ -20,7 +20,7 @@ MRuby.each_target do @bins << mruby_config make_cfg = "#{build_dir}/lib/libmruby.flags.mak" - file mruby_config_path => [libfile("#{build_dir}/lib/libmruby"), make_cfg] do |t| + file mruby_config_path => [libmruby_static, make_cfg] do |t| FileUtils.copy "#{File.dirname(__FILE__)}/#{mruby_config}", t.name config = Hash[open(make_cfg).read.split("\n").map {|x| a = x.split(/\s*=\s*/, 2); [a[0], a[1].gsub('\\"', '"') ]}] IO.write(t.name, File.open(t.name) {|f| diff --git a/mrbgems/mruby-compiler/mrbgem.rake b/mrbgems/mruby-compiler/mrbgem.rake index e9e0cc2c7..fa191e69b 100644 --- a/mrbgems/mruby-compiler/mrbgem.rake +++ b/mrbgems/mruby-compiler/mrbgem.rake @@ -35,6 +35,6 @@ MRuby::Gem::Specification.new 'mruby-compiler' do |spec| gperf.run t.name, t.prerequisites.first end - file libfile("#{build.build_dir}/lib/libmruby_core") => core_objs + file build.libmruby_core_static => core_objs build.libmruby << core_objs end diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 589fc688a..c9d254bfe 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -16,9 +16,6 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| mlib = clib.ext(exts.object) exec = exefile("#{build.build_dir}/bin/mrbtest") - libmruby = libfile("#{build.build_dir}/lib/libmruby") - libmruby_core = libfile("#{build.build_dir}/lib/libmruby_core") - mrbtest_lib = libfile("#{build_dir}/mrbtest") mrbtest_objs = [] @@ -140,7 +137,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| end unless build.build_mrbtest_lib_only? - file exec => [driver_obj, mlib, mrbtest_lib, libmruby_core, libmruby] do |t| + file exec => [driver_obj, 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 } diff --git a/mrblib/mrblib.rake b/mrblib/mrblib.rake index fe4aae1f7..6895d4252 100644 --- a/mrblib/mrblib.rake +++ b/mrblib/mrblib.rake @@ -3,7 +3,7 @@ MRuby.each_target do relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT) current_build_dir = "#{build_dir}/#{relative_from_root}" - self.libmruby << objfile("#{current_build_dir}/mrblib") + self.libmruby_objs << objfile("#{current_build_dir}/mrblib") file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c" file "#{current_build_dir}/mrblib.c" => [mrbcfile, __FILE__] + Dir.glob("#{current_dir}/*.rb").sort do |t| diff --git a/src/mruby_core.rake b/src/mruby_core.rake index bb3d7b633..3024c8544 100644 --- a/src/mruby_core.rake +++ b/src/mruby_core.rake @@ -12,9 +12,9 @@ MRuby.each_target do if cxx_exception_enabled? objs += %w(vm error).map { |v| compile_as_cxx "#{current_dir}/#{v}.c", "#{current_build_dir}/#{v}.cxx" } end - self.libmruby << objs + self.libmruby_objs << objs - file libfile("#{build_dir}/lib/libmruby_core") => objs do |t| + file libmruby_core_static => objs do |t| archiver.run t.name, t.prerequisites end end diff --git a/tasks/libmruby.rake b/tasks/libmruby.rake index b6ef29986..ab5a15b4a 100644 --- a/tasks/libmruby.rake +++ b/tasks/libmruby.rake @@ -1,9 +1,9 @@ MRuby.each_target do - file libfile("#{build_dir}/lib/libmruby") => libmruby.flatten do |t| + file libmruby_static => libmruby_objs.flatten do |t| archiver.run t.name, t.prerequisites end - file "#{build_dir}/lib/libmruby.flags.mak" => [__FILE__, libfile("#{build_dir}/lib/libmruby")] do |t| + file "#{build_dir}/lib/libmruby.flags.mak" => [__FILE__, libmruby_static] do |t| FileUtils.mkdir_p File.dirname t.name open(t.name, 'w') do |f| f.puts "MRUBY_CFLAGS = #{cc.all_flags}" @@ -18,7 +18,7 @@ MRuby.each_target do gem_libraries = gems.map { |g| g.linker.libraries } f.puts "MRUBY_LIBS = #{linker.option_library % 'mruby'} #{linker.library_flags(gem_libraries)}" - f.puts "MRUBY_LIBMRUBY_PATH = #{libfile("#{build_dir}/lib/libmruby")}" + f.puts "MRUBY_LIBMRUBY_PATH = #{libmruby_static}" end end task :all => "#{build_dir}/lib/libmruby.flags.mak" diff --git a/tasks/mrbgems.rake b/tasks/mrbgems.rake index e2aeb1514..fb76856e5 100644 --- a/tasks/mrbgems.rake +++ b/tasks/mrbgems.rake @@ -5,7 +5,7 @@ MRuby.each_target do gems.check self # loader all gems - self.libmruby << objfile("#{build_dir}/mrbgems/gem_init") + 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" => [MRUBY_CONFIG, __FILE__] do |t| FileUtils.mkdir_p "#{build_dir}/mrbgems" -- cgit v1.2.3 From 366a14f297a6b31301b8e01f5ef21ad8fe184977 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Wed, 16 Jan 2019 23:48:59 +0900 Subject: Remove special treatments for `MRB_WITHOUT_FLOAT` in build scripts --- mrbgems/mruby-test/mrbgem.rake | 4 ---- src/mruby_core.rake | 1 - 2 files changed, 5 deletions(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 6f94da92d..61bdf9ced 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -7,10 +7,6 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| spec.add_dependency('mruby-compiler', :core => 'mruby-compiler') spec.test_rbfiles = Dir.glob("#{MRUBY_ROOT}/test/t/*.rb") - if build.cc.defines.flatten.include?("MRB_WITHOUT_FLOAT") - spec.test_rbfiles.delete("#{MRUBY_ROOT}/test/t/float.rb") - end - clib = "#{build_dir}/mrbtest.c" mlib = clib.ext(exts.object) diff --git a/src/mruby_core.rake b/src/mruby_core.rake index 3024c8544..73fddb220 100644 --- a/src/mruby_core.rake +++ b/src/mruby_core.rake @@ -5,7 +5,6 @@ MRuby.each_target do objs = Dir.glob("#{current_dir}/*.c").map { |f| next nil if cxx_exception_enabled? and f =~ /(error|vm).c$/ - next nil if self.cc.defines.flatten.include?("MRB_WITHOUT_FLOAT") and f =~ /fmt_fp.c$/ objfile(f.pathmap("#{current_build_dir}/%n")) }.compact -- cgit v1.2.3 From f209f781acdeb6dabafdab955f685daf6c5d1421 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Fri, 22 Feb 2019 20:41:20 +0900 Subject: Integrate `init_mrbtest.c` to `driver.c` in `mruby-test` mrbgem - `mrbgemtest_init()` is needed if `DISABLE_GEMS` is enabled because core tests are run as part of `mruby-test` mrbgem (moreover, `DISABLE_GEMS` is disabled when `enable_test` is used in build config). - For the same reason `mrb_open_core()` etc for core tests is unneeded. --- mrbgems/mruby-test/driver.c | 8 +++++--- mrbgems/mruby-test/init_mrbtest.c | 39 --------------------------------------- mrbgems/mruby-test/mrbgem.rake | 7 +++---- 3 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 mrbgems/mruby-test/init_mrbtest.c (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/driver.c b/mrbgems/mruby-test/driver.c index 434d1fee5..4b2707319 100644 --- a/mrbgems/mruby-test/driver.c +++ b/mrbgems/mruby-test/driver.c @@ -18,8 +18,9 @@ #include #include -void -mrb_init_mrbtest(mrb_state *); +extern const uint8_t mrbtest_assert_irep[]; + +void mrbgemtest_init(mrb_state* mrb); /* Print a short remark for the user */ static void @@ -167,7 +168,8 @@ main(int argc, char **argv) } mrb_init_test_driver(mrb, verbose); - mrb_init_mrbtest(mrb); + mrb_load_irep(mrb, mrbtest_assert_irep); + mrbgemtest_init(mrb); ret = eval_test(mrb); mrb_close(mrb); diff --git a/mrbgems/mruby-test/init_mrbtest.c b/mrbgems/mruby-test/init_mrbtest.c deleted file mode 100644 index 7678a5200..000000000 --- a/mrbgems/mruby-test/init_mrbtest.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include - -extern const uint8_t mrbtest_assert_irep[]; - -void mrbgemtest_init(mrb_state* mrb); -void mrb_init_test_driver(mrb_state* mrb, mrb_bool verbose); -void mrb_t_pass_result(mrb_state *mrb_dst, mrb_state *mrb_src); - -void -mrb_init_mrbtest(mrb_state *mrb) -{ - mrb_state *core_test; - - mrb_load_irep(mrb, mrbtest_assert_irep); - - core_test = mrb_open_core(mrb_default_allocf, NULL); - if (core_test == NULL) { - fprintf(stderr, "Invalid mrb_state, exiting %s", __FUNCTION__); - exit(EXIT_FAILURE); - } - mrb_init_test_driver(core_test, mrb_test(mrb_gv_get(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose")))); - mrb_load_irep(core_test, mrbtest_assert_irep); - mrb_t_pass_result(mrb, core_test); - -#ifndef DISABLE_GEMS - mrbgemtest_init(mrb); -#endif - - if (mrb->exc) { - mrb_print_error(mrb); - mrb_close(mrb); - exit(EXIT_FAILURE); - } - mrb_close(core_test); -} - diff --git a/mrbgems/mruby-test/mrbgem.rake b/mrbgems/mruby-test/mrbgem.rake index 61bdf9ced..dcb7bb719 100644 --- a/mrbgems/mruby-test/mrbgem.rake +++ b/mrbgems/mruby-test/mrbgem.rake @@ -144,8 +144,6 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| end end - init = "#{spec.dir}/init_mrbtest.c" - # store the last gem selection and make the re-build # of the test gem depending on a change to the gem # selection @@ -164,7 +162,7 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| file clib => active_gems_path if active_gem_list != current_gem_list file mlib => clib - file clib => [init, build.mrbcfile, __FILE__] do |_t| + file clib => [build.mrbcfile, __FILE__] do |_t| _pp "GEN", "*.rb", "#{clib.relative_path}" FileUtils.mkdir_p File.dirname(clib) open(clib, 'w') do |f| @@ -177,7 +175,8 @@ MRuby::Gem::Specification.new('mruby-test') do |spec| f.puts %Q[ * All manual changes will get lost.] f.puts %Q[ */] f.puts %Q[] - f.puts IO.read(init) + f.puts %Q[struct mrb_state;] + f.puts %Q[typedef struct mrb_state mrb_state;] build.gems.each do |g| f.puts %Q[void GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb_state *mrb);] end -- cgit v1.2.3 From f6326803c744e05918a1f124d0055bf35e0f6851 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Thu, 7 Mar 2019 21:36:54 +0900 Subject: Add a missing file for #4314 --- mrbgems/mruby-test/driver.c | 1 + 1 file changed, 1 insertion(+) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/driver.c b/mrbgems/mruby-test/driver.c index 4b2707319..6e58c3e28 100644 --- a/mrbgems/mruby-test/driver.c +++ b/mrbgems/mruby-test/driver.c @@ -131,6 +131,7 @@ mrb_t_pass_result(mrb_state *mrb_dst, mrb_state *mrb_src) TEST_COUNT_PASS(ok_test); TEST_COUNT_PASS(ko_test); TEST_COUNT_PASS(kill_test); + TEST_COUNT_PASS(skip_test); #undef TEST_COUNT_PASS -- cgit v1.2.3 From c3122c887a7fb842aac78b4735a64004a9b71a20 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Wed, 13 Mar 2019 22:04:14 +0900 Subject: Do not raise an exception when bintest fail - An exception do not raise when mrbtest fail. - There are no useful informations in exception message and backtrace. --- mrbgems/mruby-test/driver.c | 18 +++--------------- test/assert.rb | 4 +++- test/bintest.rb | 2 +- test/report.rb | 4 ---- 4 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 test/report.rb (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/driver.c b/mrbgems/mruby-test/driver.c index 6e58c3e28..6b91b7457 100644 --- a/mrbgems/mruby-test/driver.c +++ b/mrbgems/mruby-test/driver.c @@ -29,32 +29,20 @@ print_hint(void) printf("mrbtest - Embeddable Ruby Test\n\n"); } -static int -check_error(mrb_state *mrb) -{ - /* Error check */ - /* $ko_test and $kill_test should be 0 */ - mrb_value ko_test = mrb_gv_get(mrb, mrb_intern_lit(mrb, "$ko_test")); - mrb_value kill_test = mrb_gv_get(mrb, mrb_intern_lit(mrb, "$kill_test")); - - return mrb_fixnum_p(ko_test) && mrb_fixnum(ko_test) == 0 && mrb_fixnum_p(kill_test) && mrb_fixnum(kill_test) == 0; -} - static int eval_test(mrb_state *mrb) { /* evaluate the test */ - mrb_funcall(mrb, mrb_top_self(mrb), "report", 0); + mrb_value result = mrb_funcall(mrb, mrb_top_self(mrb), "report", 0); /* did an exception occur? */ if (mrb->exc) { mrb_print_error(mrb); mrb->exc = 0; return EXIT_FAILURE; } - else if (!check_error(mrb)) { - return EXIT_FAILURE; + else { + return mrb_bool(result) ? EXIT_SUCCESS : EXIT_FAILURE; } - return EXIT_SUCCESS; } static void diff --git a/test/assert.rb b/test/assert.rb index 623ec9138..2873eece1 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -213,7 +213,7 @@ end ## # Report the test result and print all assertions # which were reported broken. -def report() +def report t_print("\n") $asserts.each do |msg| @@ -232,6 +232,8 @@ def report() t_time = Time.now - $test_start t_print(" Time: #{t_time.round(2)} seconds\n") end + + $ko_test == 0 && $kill_test == 0 end ## diff --git a/test/bintest.rb b/test/bintest.rb index 2bcecaec5..ed71e57fd 100644 --- a/test/bintest.rb +++ b/test/bintest.rb @@ -39,4 +39,4 @@ ARGV.each do |gem| end end -load 'test/report.rb' +exit report diff --git a/test/report.rb b/test/report.rb deleted file mode 100644 index fb77fd0aa..000000000 --- a/test/report.rb +++ /dev/null @@ -1,4 +0,0 @@ -report -if $ko_test > 0 or $kill_test > 0 - raise "mrbtest failed (KO:#{$ko_test}, Crash:#{$kill_test})" -end -- cgit v1.2.3 From df4b08139200bf6f1c941914d5059d51b91f25b1 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Sat, 23 Mar 2019 19:27:21 +0900 Subject: Refactor `t_print` for test --- mrbgems/mruby-test/driver.c | 34 +++++++++++++--------------------- test/assert.rb | 18 ++++++++---------- 2 files changed, 21 insertions(+), 31 deletions(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/driver.c b/mrbgems/mruby-test/driver.c index 6b91b7457..fd180b1bb 100644 --- a/mrbgems/mruby-test/driver.c +++ b/mrbgems/mruby-test/driver.c @@ -45,29 +45,21 @@ eval_test(mrb_state *mrb) } } -static void -t_printstr(mrb_state *mrb, mrb_value obj) -{ - char *s; - mrb_int len; - - if (mrb_string_p(obj)) { - s = RSTRING_PTR(obj); - len = RSTRING_LEN(obj); - fwrite(s, len, 1, stdout); - fflush(stdout); - } -} - -mrb_value -mrb_t_printstr(mrb_state *mrb, mrb_value self) +/* Implementation of print due to the reason that there might be no print */ +static mrb_value +t_print(mrb_state *mrb, mrb_value self) { - mrb_value argv; + mrb_value *argv; + mrb_int argc; - mrb_get_args(mrb, "o", &argv); - t_printstr(mrb, argv); + mrb_get_args(mrb, "*!", &argv, &argc); + for (mrb_int i = 0; i < argc; ++i) { + mrb_value s = mrb_obj_as_string(mrb, argv[i]); + fwrite(RSTRING_PTR(s), RSTRING_LEN(s), 1, stdout); + } + fflush(stdout); - return argv; + return mrb_nil_value(); } void @@ -76,7 +68,7 @@ mrb_init_test_driver(mrb_state *mrb, mrb_bool verbose) struct RClass *krn, *mrbtest; krn = mrb->kernel_module; - mrb_define_method(mrb, krn, "__t_printstr__", mrb_t_printstr, MRB_ARGS_REQ(1)); + mrb_define_method(mrb, krn, "t_print", t_print, MRB_ARGS_ANY()); mrbtest = mrb_define_module(mrb, "Mrbtest"); diff --git a/test/assert.rb b/test/assert.rb index d6359022f..f6914cf81 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -5,14 +5,12 @@ $skip_test = 0 $asserts = [] $test_start = Time.now if Object.const_defined?(:Time) -# Implementation of print due to the reason that there might be no print -def t_print(*args) - i = 0 - len = args.size - while i < len - str = args[i].to_s - __t_printstr__ str rescue print str - i += 1 +unless RUBY_ENGINE == "mruby" + # For bintest on Ruby + def t_print(*args) + print *args + $stdout.flush + nil end end @@ -110,8 +108,8 @@ def assert_not_equal(exp, act_or_msg = nil, msg = nil, &block) assert_true(!ret, msg, diff) end -def assert_same(*args); _assert_same(true, *args) end -def assert_not_same(*args); _assert_same(false, *args) end +def assert_same(*args); _assert_same(true, *args) end +def assert_not_same(*args); _assert_same(false, *args) end def _assert_same(affirmed, exp, act, msg = nil) unless ret = exp.equal?(act) == affirmed exp_str, act_str = [exp, act].map do |o| -- cgit v1.2.3 From b351bdb8d53ef2ff2d91c51e2179103e3c76e9a4 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 10 Apr 2019 06:00:38 +0900 Subject: Fixed old style declaration; ref #4365 --- mrbgems/mruby-test/driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/driver.c b/mrbgems/mruby-test/driver.c index fd180b1bb..fcbe15a56 100644 --- a/mrbgems/mruby-test/driver.c +++ b/mrbgems/mruby-test/driver.c @@ -51,9 +51,10 @@ t_print(mrb_state *mrb, mrb_value self) { mrb_value *argv; mrb_int argc; + mrb_int i; mrb_get_args(mrb, "*!", &argv, &argc); - for (mrb_int i = 0; i < argc; ++i) { + for (i = 0; i < argc; ++i) { mrb_value s = mrb_obj_as_string(mrb, argv[i]); fwrite(RSTRING_PTR(s), RSTRING_LEN(s), 1, stdout); } -- cgit v1.2.3 From 716a99b069461b11c2b46099119f8578cd2c8f3f Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Wed, 3 Apr 2019 21:38:47 +0900 Subject: Add `assert_match` and `assert_not_match` --- mrbgems/mruby-test/driver.c | 146 ++++++++++++++++++++++++++++++++++++++++++++ test/assert.rb | 33 ++++++++++ test/t/module.rb | 7 +-- 3 files changed, 181 insertions(+), 5 deletions(-) (limited to 'mrbgems/mruby-test') diff --git a/mrbgems/mruby-test/driver.c b/mrbgems/mruby-test/driver.c index fd180b1bb..9e3dbea9d 100644 --- a/mrbgems/mruby-test/driver.c +++ b/mrbgems/mruby-test/driver.c @@ -62,6 +62,151 @@ t_print(mrb_state *mrb, mrb_value self) return mrb_nil_value(); } +#define UNESCAPE(p, endp) ((p) != (endp) && *(p) == '\\' ? (p)+1 : (p)) +#define CHAR_CMP(c1, c2) ((unsigned char)(c1) - (unsigned char)(c2)) + +static const char * +str_match_bracket(const char *p, const char *pat_end, + const char *s, const char *str_end) +{ + mrb_bool ok = FALSE, negated = FALSE; + + if (p == pat_end) return NULL; + if (*p == '!' || *p == '^') { + negated = TRUE; + ++p; + } + + while (*p != ']') { + const char *t1 = p; + if ((t1 = UNESCAPE(t1, pat_end)) == pat_end) return NULL; + if ((p = t1 + 1) == pat_end) return NULL; + if (p[0] == '-' && p[1] != ']') { + const char *t2 = p + 1; + if ((t2 = UNESCAPE(t2, pat_end)) == pat_end) return NULL; + p = t2 + 1; + if (!ok && CHAR_CMP(*t1, *s) <= 0 && CHAR_CMP(*s, *t2) <= 0) ok = TRUE; + } + else { + if (!ok && CHAR_CMP(*t1, *s) == 0) ok = TRUE; + } + } + + return ok == negated ? NULL : p + 1; +} + +static mrb_bool +str_match_no_brace_p(const char *pat, mrb_int pat_len, + const char *str, mrb_int str_len) +{ + const char *p = pat, *s = str; + const char *pat_end = pat + pat_len, *str_end = str + str_len; + const char *p_tmp = NULL, *s_tmp = NULL; + + for (;;) { + if (p == pat_end) return s == str_end; + switch (*p) { + case '*': + do { ++p; } while (p != pat_end && *p == '*'); + if (UNESCAPE(p, pat_end) == pat_end) return TRUE; + if (s == str_end) return FALSE; + p_tmp = p; + s_tmp = s; + continue; + case '?': + if (s == str_end) return FALSE; + ++p; + ++s; + continue; + case '[': { + const char *t; + if (s == str_end) return FALSE; + if ((t = str_match_bracket(p+1, pat_end, s, str_end))) { + p = t; + ++s; + continue; + } + goto L_failed; + } + } + + /* ordinary */ + p = UNESCAPE(p, pat_end); + if (s == str_end) return p == pat_end; + if (p == pat_end) goto L_failed; + if (*p++ != *s++) goto L_failed; + continue; + + L_failed: + if (p_tmp && s_tmp) { + /* try next '*' position */ + p = p_tmp; + s = ++s_tmp; + continue; + } + + return FALSE; + } +} + +#define COPY_AND_INC(dst, src, len) \ + do { memcpy(dst, src, len); dst += len; } while (0) + +static mrb_bool +str_match_p(mrb_state *mrb, + const char *pat, mrb_int pat_len, + const char *str, mrb_int str_len) +{ + const char *p = pat, *pat_end = pat + pat_len; + const char *lbrace = NULL, *rbrace = NULL; + int nest = 0; + mrb_bool ret = FALSE; + + for (; p != pat_end; ++p) { + if (*p == '{' && nest++ == 0) lbrace = p; + else if (*p == '}' && lbrace && --nest == 0) { rbrace = p; break; } + else if (*p == '\\' && ++p == pat_end) break; + } + + if (lbrace && rbrace) { + /* expand brace */ + char *ex_pat = (char *)mrb_malloc(mrb, pat_len-2); /* expanded pattern */ + char *ex_p = ex_pat; + + COPY_AND_INC(ex_p, pat, lbrace-pat); + p = lbrace; + while (p < rbrace) { + char *orig_ex_p = ex_p; + const char *t = ++p; + for (nest = 0; p < rbrace && !(*p == ',' && nest == 0); ++p) { + if (*p == '{') ++nest; + else if (*p == '}') --nest; + else if (*p == '\\' && ++p == rbrace) break; + } + COPY_AND_INC(ex_p, t, p-t); + COPY_AND_INC(ex_p, rbrace+1, pat_end-rbrace-1); + if ((ret = str_match_p(mrb, ex_pat, ex_p-ex_pat, str, str_len))) break; + ex_p = orig_ex_p; + } + mrb_free(mrb, ex_pat); + } + else if (!lbrace && !rbrace) { + ret = str_match_no_brace_p(pat, pat_len, str, str_len); + } + + return ret; +} + +static mrb_value +m_str_match_p(mrb_state *mrb, mrb_value self) +{ + const char *pat, *str; + mrb_int pat_len, str_len; + + mrb_get_args(mrb, "ss", &pat, &pat_len, &str, &str_len); + return mrb_bool_value(str_match_p(mrb, pat, pat_len, str, str_len)); +} + void mrb_init_test_driver(mrb_state *mrb, mrb_bool verbose) { @@ -69,6 +214,7 @@ mrb_init_test_driver(mrb_state *mrb, mrb_bool verbose) krn = mrb->kernel_module; mrb_define_method(mrb, krn, "t_print", t_print, MRB_ARGS_ANY()); + mrb_define_method(mrb, krn, "_str_match?", m_str_match_p, MRB_ARGS_REQ(2)); mrbtest = mrb_define_module(mrb, "Mrbtest"); diff --git a/test/assert.rb b/test/assert.rb index c57b04c12..4b01bd450 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -136,6 +136,39 @@ def _assert_include(affirmed, collection, obj, msg = nil) assert_true(ret, msg, diff) end +## +# Fail unless +str+ matches against +pattern+. +# +# +pattern+ is interpreted as pattern for File.fnmatch?. It may contain the +# following metacharacters: +# +# * :: +# Matches any string. +# +# ? :: +# Matches any one character. +# +# [_SET_], [^_SET_] ([!_SET_]) :: +# Matches any one character in _SET_. Behaves like character sets in +# Regexp, including set negation ([^a-z]). +# +# {_A_,_B_} :: +# Matches pattern _A_ or pattern _B_. +# +# \ :: +# Escapes the next character. +def assert_match(*args); _assert_match(true, *args) end +def assert_not_match(*args); _assert_match(false, *args) end +def _assert_match(affirmed, pattern, str, msg = nil) + receiver, *args = RUBY_ENGINE == "mruby" ? + [self, :_str_match?, pattern, str] : + [File, :fnmatch?, pattern, str, File::FNM_EXTGLOB|File::FNM_DOTMATCH] + unless ret = !receiver.__send__(*args) == !affirmed + diff = " Expected #{pattern.inspect} to #{'not ' unless affirmed}match #{str.inspect}." + end + assert_true(ret, msg, diff) +end + ## # Fails unless +obj+ is a kind of +cls+. def assert_kind_of(cls, obj, msg = nil) diff --git a/test/t/module.rb b/test/t/module.rb index ec36855e8..1694ef577 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -640,11 +640,8 @@ assert('Module#to_s') do assert_equal 'SetOuter', SetOuter.to_s assert_equal 'SetOuter::SetInner', SetOuter::SetInner.to_s - mod = Module.new - cls = Class.new - - assert_equal "#", Module.new.to_s + assert_match "#", Class.new.to_s end assert('Module#inspect') do -- cgit v1.2.3