brew/Library/Homebrew/requirements/language_module_requirement.rb

55 lines
1.5 KiB
Ruby
Raw Normal View History

require "requirement"
2013-04-02 15:33:35 -05:00
class LanguageModuleRequirement < Requirement
2013-04-02 15:33:35 -05:00
fatal true
def initialize(language, module_name, import_name = nil)
2013-04-02 15:33:35 -05:00
@language = language
@module_name = module_name
@import_name = import_name || module_name
super([language, module_name, import_name])
2013-04-02 15:33:35 -05:00
end
satisfy(build_env: false) { quiet_system(*the_test) }
2013-04-02 15:33:35 -05:00
def message
s = <<-EOS.undent
Unsatisfied dependency: #{@module_name}
Homebrew does not provide special #{@language.to_s.capitalize} dependencies; install with:
`#{command_line} #{@module_name}`
2013-04-02 15:33:35 -05:00
EOS
unless [:python, :perl, :ruby].include? @language
s += <<-EOS.undent
You may need to: `brew install #{@language}`
EOS
end
s
2013-04-02 15:33:35 -05:00
end
def the_test
case @language
2015-08-06 18:46:56 +01:00
when :lua then %W[/usr/bin/env luarocks-5.2 show #{@import_name}]
when :lua51 then %W[/usr/bin/env luarocks-5.1 show #{@import_name}]
when :perl then %W[/usr/bin/env perl -e use\ #{@import_name}]
when :python then %W[/usr/bin/env python -c import\ #{@import_name}]
when :python3 then %W[/usr/bin/env python3 -c import\ #{@import_name}]
when :ruby then %W[/usr/bin/env ruby -rubygems -e require\ '#{@import_name}']
2013-04-02 15:33:35 -05:00
end
end
def command_line
case @language
2015-08-06 18:46:56 +01:00
when :lua then "luarocks-5.2 install"
when :lua51 then "luarocks-5.1 install"
when :perl then "cpan -i"
when :python then "pip install"
when :python3 then "pip3 install"
when :ruby then "gem install"
2013-04-02 15:33:35 -05:00
end
end
end