Commit 2b74fa54 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2503 from cremno/dont-always-generate-gem-functions

don't always generate gem functions
parents f3f54cb6 6526bb10
...@@ -36,6 +36,8 @@ module MRuby ...@@ -36,6 +36,8 @@ module MRuby
attr_accessor :export_include_paths attr_accessor :export_include_paths
attr_reader :generate_functions
attr_block MRuby::Build::COMMANDS attr_block MRuby::Build::COMMANDS
def initialize(name, &block) def initialize(name, &block)
...@@ -56,7 +58,9 @@ module MRuby ...@@ -56,7 +58,9 @@ module MRuby
@objs = Dir.glob("#{dir}/src/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| @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")) objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X"))
end end
@objs << objfile("#{build_dir}/gem_init")
@generate_functions = !(@rbfiles.empty? && @objs.empty?)
@objs << objfile("#{build_dir}/gem_init") if @generate_functions
@test_rbfiles = Dir.glob("#{dir}/test/*.rb") @test_rbfiles = Dir.glob("#{dir}/test/*.rb")
@test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f| @test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f|
...@@ -89,7 +93,7 @@ module MRuby ...@@ -89,7 +93,7 @@ module MRuby
compiler.include_paths << "#{dir}/include" if File.directory? "#{dir}/include" compiler.include_paths << "#{dir}/include" if File.directory? "#{dir}/include"
end end
define_gem_init_builder define_gem_init_builder if @generate_functions
end end
def add_dependency(name, *requirements) def add_dependency(name, *requirements)
......
...@@ -10,6 +10,17 @@ MRuby.each_target do ...@@ -10,6 +10,17 @@ MRuby.each_target do
file "#{build_dir}/mrbgems/gem_init.c" => [MRUBY_CONFIG, __FILE__] do |t| file "#{build_dir}/mrbgems/gem_init.c" => [MRUBY_CONFIG, __FILE__] do |t|
FileUtils.mkdir_p "#{build_dir}/mrbgems" FileUtils.mkdir_p "#{build_dir}/mrbgems"
open(t.name, 'w') do |f| open(t.name, 'w') do |f|
gem_func_gems = gems.select { |g| g.generate_functions }
gem_func_decls = gem_func_gems.each_with_object('') do |g, s|
s << "void GENERATED_TMP_mrb_#{g.funcname}_gem_init(mrb_state*);\n" \
"void GENERATED_TMP_mrb_#{g.funcname}_gem_final(mrb_state*);\n"
end
gem_init_calls = gem_func_gems.each_with_object('') do |g, s|
s << " GENERATED_TMP_mrb_#{g.funcname}_gem_init(mrb);\n"
end
gem_final_calls = gem_func_gems.each_with_object('') do |g, s|
s << " GENERATED_TMP_mrb_#{g.funcname}_gem_final(mrb);\n"
end
f.puts %Q[/*] f.puts %Q[/*]
f.puts %Q[ * This file contains a list of all] f.puts %Q[ * This file contains a list of all]
f.puts %Q[ * initializing methods which are] f.puts %Q[ * initializing methods which are]
...@@ -22,19 +33,17 @@ MRuby.each_target do ...@@ -22,19 +33,17 @@ MRuby.each_target do
f.puts %Q[] f.puts %Q[]
f.puts %Q[#include "mruby.h"] f.puts %Q[#include "mruby.h"]
f.puts %Q[] f.puts %Q[]
f.puts %Q[#{gems.map{|g| "void GENERATED_TMP_mrb_%s_gem_init(mrb_state* mrb);" % g.funcname}.join("\n")}] f.write gem_func_decls
f.puts %Q[]
f.puts %Q[#{gems.map{|g| "void GENERATED_TMP_mrb_%s_gem_final(mrb_state* mrb);" % g.funcname}.join("\n")}]
f.puts %Q[] f.puts %Q[]
f.puts %Q[static void] f.puts %Q[static void]
f.puts %Q[mrb_final_mrbgems(mrb_state *mrb) {] f.puts %Q[mrb_final_mrbgems(mrb_state *mrb) {]
f.puts %Q[#{gems.map{|g| "GENERATED_TMP_mrb_%s_gem_final(mrb);" % g.funcname}.join("\n")}] f.write gem_final_calls
f.puts %Q[}] f.puts %Q[}]
f.puts %Q[] f.puts %Q[]
f.puts %Q[void] f.puts %Q[void]
f.puts %Q[mrb_init_mrbgems(mrb_state *mrb) {] f.puts %Q[mrb_init_mrbgems(mrb_state *mrb) {]
f.puts %Q[#{gems.map{|g| "GENERATED_TMP_mrb_%s_gem_init(mrb);" % g.funcname}.join("\n")}] f.write gem_init_calls
f.puts %Q[mrb_state_atexit(mrb, mrb_final_mrbgems);] f.puts %Q[ mrb_state_atexit(mrb, mrb_final_mrbgems);] unless gem_final_calls.empty?
f.puts %Q[}] f.puts %Q[}]
end end
end end
......
...@@ -42,6 +42,15 @@ class Symbol ...@@ -42,6 +42,15 @@ class Symbol
end end
end end
module Enumerable
# Compatible with 1.9 on 1.8
def each_with_object(memo)
return to_enum :each_with_object, memo unless block_given?
each { |obj| yield obj, memo }
memo
end
end
$pp_show = true $pp_show = true
if $verbose.nil? if $verbose.nil?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment