diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mruby-core-ext.rb | 33 | ||||
| -rw-r--r-- | lib/mruby/build.rb | 33 | ||||
| -rw-r--r-- | lib/mruby/build/command.rb | 45 | ||||
| -rw-r--r-- | lib/mruby/gem.rb | 37 |
4 files changed, 72 insertions, 76 deletions
diff --git a/lib/mruby-core-ext.rb b/lib/mruby-core-ext.rb index 4c6d3ca76..8c985f147 100644 --- a/lib/mruby-core-ext.rb +++ b/lib/mruby-core-ext.rb @@ -16,39 +16,6 @@ class String def relative_path relative_path_from(Dir.pwd) end - - # Compatible with 1.9 on 1.8 - def %(params) - if params.is_a?(Hash) - str = self.clone - params.each do |k, v| - str.gsub!("%{#{k}}") { v } - end - str - else - if params.is_a?(Array) - sprintf(self, *params) - else - sprintf(self, params) - end - end - end -end - -class Symbol - # Compatible with 1.9 on 1.8 - def to_proc - proc { |obj, *args| obj.send(self, *args) } - 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 diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb index ae17d372c..90943f3b1 100644 --- a/lib/mruby/build.rb +++ b/lib/mruby/build.rb @@ -22,7 +22,6 @@ module MRuby def initialize(name, &block) @name, @initializer = name.to_s, block - MRuby::Toolchain.toolchains ||= {} MRuby::Toolchain.toolchains[@name] = self end @@ -30,13 +29,8 @@ module MRuby conf.instance_exec(conf, params, &@initializer) end - def self.load - Dir.glob("#{MRUBY_ROOT}/tasks/toolchains/*.rake").each do |file| - Kernel.load file - end - end + self.toolchains = {} end - Toolchain.load class Build class << self @@ -170,8 +164,6 @@ module MRuby end def compile_as_cxx src, cxx_src, obj = nil, includes = [] - src = File.absolute_path src - cxx_src = File.absolute_path cxx_src obj = objfile(cxx_src) if obj.nil? file cxx_src => [src, __FILE__] do |t| @@ -183,7 +175,7 @@ module MRuby #ifndef MRB_ENABLE_CXX_ABI extern "C" { #endif -#include "#{src}" +#include "#{File.absolute_path src}" #ifndef MRB_ENABLE_CXX_ABI } #endif @@ -206,10 +198,15 @@ EOS end def toolchain(name, params={}) - tc = Toolchain.toolchains[name.to_s] - fail "Unknown #{name} toolchain" unless tc + name = name.to_s + tc = Toolchain.toolchains[name] || begin + path = "#{MRUBY_ROOT}/tasks/toolchains/#{name}.rake" + fail "Unknown #{name} toolchain" unless File.exist?(path) + load path + Toolchain.toolchains[name] + end tc.setup(self, params) - @toolchains.unshift name.to_s + @toolchains.unshift name end def primary_toolchain @@ -265,7 +262,7 @@ EOS if name.is_a?(Array) name.flatten.map { |n| filename(n) } else - '"%s"' % name.gsub('/', file_separator) + name.gsub('/', file_separator) end end @@ -273,15 +270,18 @@ EOS if name.is_a?(Array) name.flatten.map { |n| cygwin_filename(n) } else - '"%s"' % `cygpath -w "#{filename(name)}"`.strip + `cygpath -w "#{filename(name)}"`.strip end end def exefile(name) if name.is_a?(Array) name.flatten.map { |n| exefile(n) } - else + elsif File.extname(name).empty? "#{name}#{exts.executable}" + else + # `name` sometimes have (non-standard) extension (e.g. `.bat`). + name end end @@ -321,6 +321,7 @@ EOS end def run_bintest + puts ">>> Bintest #{name} <<<" targets = @gems.select { |v| File.directory? "#{v.dir}/bintest" }.map { |v| filename v.dir } targets << filename(".") if File.directory? "./bintest" sh "ruby test/bintest.rb#{verbose_flag} #{targets.join ' '}" diff --git a/lib/mruby/build/command.rb b/lib/mruby/build/command.rb index e3dc0d78c..a98f2ca7e 100644 --- a/lib/mruby/build/command.rb +++ b/lib/mruby/build/command.rb @@ -67,8 +67,8 @@ module MRuby path && build.filename("#{path}/#{name}").sub(/^"(.*)"$/, '\1') end - def all_flags(_defineds=[], _include_paths=[], _flags=[]) - define_flags = [defines, _defineds].flatten.map{ |d| option_define % d } + def all_flags(_defines=[], _include_paths=[], _flags=[]) + define_flags = [defines, _defines].flatten.map{ |d| option_define % d } include_path_flags = [include_paths, _include_paths].flatten.map do |f| if MRUBY_BUILD_HOST_IS_CYGWIN option_include_path % cygwin_filename(f) @@ -79,14 +79,14 @@ module MRuby [flags, define_flags, include_path_flags, _flags].flatten.join(' ') end - def run(outfile, infile, _defineds=[], _include_paths=[], _flags=[]) + def run(outfile, infile, _defines=[], _include_paths=[], _flags=[]) FileUtils.mkdir_p File.dirname(outfile) _pp "CC", infile.relative_path, outfile.relative_path if MRUBY_BUILD_HOST_IS_CYGWIN - _run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags), + _run compile_options, { :flags => all_flags(_defines, _include_paths, _flags), :infile => cygwin_filename(infile), :outfile => cygwin_filename(outfile) } else - _run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags), + _run compile_options, { :flags => all_flags(_defines, _include_paths, _flags), :infile => filename(infile), :outfile => filename(outfile) } end end @@ -127,13 +127,40 @@ module MRuby end private + + # + # === Example of +.d+ file + # + # ==== Without <tt>-MP</tt> compiler flag + # + # /build/host/src/array.o: \ + # /src/array.c \ + # /include/mruby/common.h \ + # /include/mruby/value.h \ + # /src/value_array.h + # + # ==== With <tt>-MP</tt> compiler flag + # + # /build/host/src/array.o: \ + # /src/array.c \ + # /include/mruby/common.h \ + # /include/mruby/value.h \ + # /src/value_array.h + # + # /include/mruby/common.h: + # + # /include/mruby/value.h: + # + # /src/value_array.h: + # def get_dependencies(file) file = file.ext('d') unless File.extname(file) == '.d' + deps = [] if File.exist?(file) - File.read(file).gsub("\\\n ", "").scan(/^\S+:\s+(.+)$/).flatten.map {|s| s.split(' ') }.flatten - else - [] - end + [ MRUBY_CONFIG ] + File.foreach(file){|line| deps << $1 if /^ +(.*?)(?: *\\)?$/ =~ line} + deps.uniq! + end + deps << MRUBY_CONFIG end end diff --git a/lib/mruby/gem.rb b/lib/mruby/gem.rb index a1216aced..95c1d4bc3 100644 --- a/lib/mruby/gem.rb +++ b/lib/mruby/gem.rb @@ -52,6 +52,8 @@ module MRuby end def setup + return if defined?(@linker) # return if already set up + MRuby::Gem.current = self MRuby::Build::COMMANDS.each do |command| instance_variable_set("@#{command}", @build.send(command).clone) @@ -110,17 +112,13 @@ module MRuby end def add_test_dependency(*args) - add_dependency(*args) if build.test_enabled? + add_dependency(*args) if build.test_enabled? || build.bintest_enabled? end def add_conflict(name, *req) @conflicts << {:gem => name, :requirements => req.empty? ? nil : req} end - def self.bin=(bin) - @bins = [bin].flatten - end - def build_dir "#{build.build_dir}/mrbgems/#{name}" end @@ -269,16 +267,18 @@ module MRuby # ~> compare algorithm # # Example: + # ~> 2 means >= 2.0.0 and < 3.0.0 # ~> 2.2 means >= 2.2.0 and < 3.0.0 - # ~> 2.2.0 means >= 2.2.0 and < 2.3.0 + # ~> 2.2.2 means >= 2.2.2 and < 2.3.0 def twiddle_wakka_ok?(other) gr_or_eql = (self <=> other) >= 0 - still_minor = (self <=> other.skip_minor) < 0 - gr_or_eql and still_minor + still_major_or_minor = (self <=> other.skip_major_or_minor) < 0 + gr_or_eql and still_major_or_minor end - def skip_minor + def skip_major_or_minor a = @ary.dup + a << 0 if a.size == 1 # ~> 2 can also be represented as ~> 2.0 a.slice!(-1) a[-1] = a[-1].succ a @@ -334,26 +334,26 @@ module MRuby end def generate_gem_table build - gem_table = @ary.reduce({}) { |res,v| res[v.name] = v; res } + gem_table = each_with_object({}) { |spec, h| h[spec.name] = spec } - default_gems = [] + default_gems = {} each do |g| g.dependencies.each do |dep| - default_gems << default_gem_params(dep) unless gem_table.key? dep[:gem] + default_gems[dep[:gem]] ||= default_gem_params(dep) end end until default_gems.empty? - def_gem = default_gems.pop + def_name, def_gem = default_gems.shift + next if gem_table[def_name] - spec = build.gem def_gem[:default] - fail "Invalid gem name: #{spec.name} (Expected: #{def_gem[:gem]})" if spec.name != def_gem[:gem] + spec = gem_table[def_name] = build.gem(def_gem[:default]) + fail "Invalid gem name: #{spec.name} (Expected: #{def_name})" if spec.name != def_name spec.setup spec.dependencies.each do |dep| - default_gems << default_gem_params(dep) unless gem_table.key? dep[:gem] + default_gems[dep[:gem]] ||= default_gem_params(dep) end - gem_table[spec.name] = spec end each do |g| @@ -428,7 +428,8 @@ module MRuby end def import_include_paths(g) - gem_table = @ary.reduce({}) { |res,v| res[v.name] = v; res } + gem_table = each_with_object({}) { |spec, h| h[spec.name] = spec } + g.dependencies.each do |dep| dep_g = gem_table[dep[:gem]] # We can do recursive call safely |
