Commit c592c093 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Refine `mrbgems/mruby-bin-config/mrbgem.rake`

- Use `MRuby::Gem::Specification`
- Fix a binary name is added to `MRuby::Build#bins` multiple times
- Close file immediately (avoid using `open(...).read`)
- Simplify
parent 37bc343e
MRuby.each_target do unless MRuby::Build.current.kind_of?(MRuby::CrossBuild)
next if kind_of? MRuby::CrossBuild MRuby::Gem::Specification.new('mruby-bin-config') do |spec|
name = 'mruby-config'
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = "#{name} command"
mruby_config = 'mruby-config' + (ENV['OS'] == 'Windows_NT' ? '.bat' : '') mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '')
mruby_config_path = "#{build_dir}/bin/#{mruby_config}" mruby_config_path = "#{build.build_dir}/bin/#{mruby_config}"
@bins << mruby_config make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak"
build.bins << mruby_config
make_cfg = "#{build_dir}/lib/libmruby.flags.mak" file mruby_config_path => [build.libmruby_static, make_cfg] do |t|
file mruby_config_path => [libmruby_static, make_cfg] do |t| config = Hash[File.readlines(make_cfg).map(&:chomp).map {|l|
FileUtils.copy "#{File.dirname(__FILE__)}/#{mruby_config}", t.name l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')}
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| tmplt = File.read("#{__dir__}/#{mruby_config}")
f.read.gsub (/echo (MRUBY_CFLAGS|MRUBY_LIBS|MRUBY_LDFLAGS_BEFORE_LIBS|MRUBY_LDFLAGS|MRUBY_LIBMRUBY_PATH)/) {|x| config[$1].empty? ? '' : "echo #{config[$1]}"} File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config))
}) FileUtils.chmod(0755, t.name)
FileUtils.chmod(0755, t.name) end
end end
end end
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