diff --git a/lib/mruby/gem.rb b/lib/mruby/gem.rb index 8794763bc..f1a403a46 100644 --- a/lib/mruby/gem.rb +++ b/lib/mruby/gem.rb @@ -26,7 +26,6 @@ module MRuby attr_accessor :rbfiles, :objs attr_reader :port_objs - attr_accessor :hal_pattern attr_writer :test_objs, :test_rbfiles attr_accessor :test_args, :test_preload @@ -67,7 +66,7 @@ module MRuby # chain: later names act as defaults for gems that don't ship # a port for the earlier names. These objs are tracked # separately so List#resolve_external_hal! can drop them when - # an external HAL provider matching spec.hal_pattern is loaded. + # an external HAL provider (gem named hal--*) is loaded. @port_objs = [] build.effective_ports.each do |port| port_dir = "#{@dir}/ports/#{port}" @@ -466,22 +465,23 @@ module MRuby resolve_external_hal! end - # If a gem declares `spec.hal_pattern = /regex/`, any other gem - # whose name matches the regex is treated as the external HAL - # provider for that gem -- the target gem's ports/* sources are - # dropped from its object list (the matching gem itself supplies - # the implementation). Two or more matches is a build error. + # A gem named `hal--` is treated as the external + # HAL provider for the gem whose name's last `-`-separated + # segment is (e.g., hal-task-glib provides the HAL for + # mruby-task). The target gem's ports/* sources are dropped + # from its object list -- the matching gem supplies the + # implementation. Two or more matches is a build error. def resolve_external_hal! each do |target| - next unless target.hal_pattern - overriders = select { |g| g != target && g.name =~ target.hal_pattern } + next if target.port_objs.nil? || target.port_objs.empty? + short = target.name.split('-').last + pattern = /\Ahal-#{Regexp.escape(short)}-.+\z/ + overriders = select { |g| g != target && g.name =~ pattern } next if overriders.empty? if overriders.size > 1 - fail "Multiple gems match #{target.hal_pattern.inspect} as " \ - "HAL provider for '#{target.name}': " + + fail "Multiple HAL providers for '#{target.name}': " + overriders.map(&:name).join(", ") end - next if target.port_objs.nil? || target.port_objs.empty? target.objs.reject! { |o| target.port_objs.include?(o) } end end diff --git a/mrbgems/mruby-task/mrbgem.rake b/mrbgems/mruby-task/mrbgem.rake index 681bd47f7..e753b3b41 100644 --- a/mrbgems/mruby-task/mrbgem.rake +++ b/mrbgems/mruby-task/mrbgem.rake @@ -6,10 +6,6 @@ MRuby::Gem::Specification.new('mruby-task') do |spec| # Enable task scheduler globally (required for vm.c integration) spec.build.defines << 'MRB_USE_TASK_SCHEDULER' - # A gem named hal--task (declaring add_dependency 'mruby-task') - # replaces the built-in ports// HAL implementation. - spec.hal_pattern = /\Ahal-.*-task\z/ - if spec.for_windows? spec.linker.libraries << "winmm" end