Shrink requirements.rb
This commit is contained in:
parent
c3d48b5d8a
commit
b82ae7067d
@ -1,254 +1,8 @@
|
|||||||
require 'requirement'
|
require 'requirement'
|
||||||
require 'extend/set'
|
require 'requirements/conflict_requirement'
|
||||||
|
require 'requirements/language_module_dependency'
|
||||||
# A dependency on a language-specific module.
|
require 'requirements/x11_dependency'
|
||||||
class LanguageModuleDependency < Requirement
|
require 'requirements/mpi_dependency'
|
||||||
fatal true
|
|
||||||
|
|
||||||
def initialize language, module_name, import_name=module_name
|
|
||||||
@language = language
|
|
||||||
@module_name = module_name
|
|
||||||
@import_name = import_name
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
satisfy { quiet_system(*the_test) }
|
|
||||||
|
|
||||||
def message; <<-EOS.undent
|
|
||||||
Unsatisfied dependency: #{@module_name}
|
|
||||||
Homebrew does not provide #{@language.to_s.capitalize} dependencies; install with:
|
|
||||||
#{command_line} #{@module_name}
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
def the_test
|
|
||||||
case @language
|
|
||||||
when :chicken then %W{/usr/bin/env csi -e (use\ #{@import_name})}
|
|
||||||
when :jruby then %W{/usr/bin/env jruby -rubygems -e require\ '#{@import_name}'}
|
|
||||||
when :lua then %W{/usr/bin/env luarocks show #{@import_name}}
|
|
||||||
when :node then %W{/usr/bin/env node -e require('#{@import_name}');}
|
|
||||||
when :ocaml then %W{/usr/bin/env opam list #{@import_name} | grep #{@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 :ruby then %W{/usr/bin/env ruby -rubygems -e require\ '#{@import_name}'}
|
|
||||||
when :rbx then %W{/usr/bin/env rbx -rubygems -e require\ '#{@import_name}'}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def command_line
|
|
||||||
case @language
|
|
||||||
when :chicken then "chicken-install"
|
|
||||||
when :jruby then "jruby -S gem install"
|
|
||||||
when :lua then "luarocks install"
|
|
||||||
when :node then "npm install"
|
|
||||||
when :ocaml then "opam install"
|
|
||||||
when :perl then "cpan -i"
|
|
||||||
when :python then "pip install"
|
|
||||||
when :rbx then "rbx gem install"
|
|
||||||
when :ruby then "gem install"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# This requirement is used to require an X11 implementation,
|
|
||||||
# optionally with a minimum version number.
|
|
||||||
class X11Dependency < Requirement
|
|
||||||
include Comparable
|
|
||||||
attr_reader :min_version
|
|
||||||
|
|
||||||
fatal true
|
|
||||||
|
|
||||||
env { ENV.x11 }
|
|
||||||
|
|
||||||
def initialize(name="x11", *tags)
|
|
||||||
tags.flatten!
|
|
||||||
@name = name
|
|
||||||
@min_version = tags.shift if /(\d\.)+\d/ === tags.first
|
|
||||||
super(tags)
|
|
||||||
end
|
|
||||||
|
|
||||||
satisfy :build_env => false do
|
|
||||||
MacOS::XQuartz.installed? && (@min_version.nil? || @min_version <= MacOS::XQuartz.version)
|
|
||||||
end
|
|
||||||
|
|
||||||
def message; <<-EOS.undent
|
|
||||||
Unsatisfied dependency: XQuartz #{@min_version}
|
|
||||||
Homebrew does not package XQuartz. Installers may be found at:
|
|
||||||
https://xquartz.macosforge.org
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
def <=> other
|
|
||||||
unless other.is_a? X11Dependency
|
|
||||||
raise TypeError, "expected X11Dependency"
|
|
||||||
end
|
|
||||||
|
|
||||||
if min_version.nil? && other.min_version.nil?
|
|
||||||
0
|
|
||||||
elsif other.min_version.nil?
|
|
||||||
1
|
|
||||||
elsif @min_version.nil?
|
|
||||||
-1
|
|
||||||
else
|
|
||||||
@min_version <=> other.min_version
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# When X11Dependency is subclassed, the new class should
|
|
||||||
# also inherit the information specified in the DSL above.
|
|
||||||
def self.inherited(mod)
|
|
||||||
instance_variables.each do |ivar|
|
|
||||||
mod.instance_variable_set(ivar, instance_variable_get(ivar))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# X11Dependency::Proxy is a base class for the X11 pseudo-deps.
|
|
||||||
# Rather than instantiate it directly, a separate class is built
|
|
||||||
# for each of the packages that we proxy to X11Dependency.
|
|
||||||
class Proxy < self
|
|
||||||
PACKAGES = [:libpng, :freetype, :fontconfig]
|
|
||||||
|
|
||||||
class << self
|
|
||||||
def defines_const?(const)
|
|
||||||
if ::RUBY_VERSION >= "1.9"
|
|
||||||
const_defined?(const, false)
|
|
||||||
else
|
|
||||||
const_defined?(const)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def for(name, *tags)
|
|
||||||
constant = name.capitalize
|
|
||||||
|
|
||||||
if defines_const?(constant)
|
|
||||||
klass = const_get(constant)
|
|
||||||
else
|
|
||||||
klass = Class.new(self) do
|
|
||||||
def initialize(name, *tags) super end
|
|
||||||
end
|
|
||||||
|
|
||||||
const_set(constant, klass)
|
|
||||||
end
|
|
||||||
klass.new(name, *tags)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# There are multiple implementations of MPI-2 available.
|
|
||||||
# http://www.mpi-forum.org/
|
|
||||||
# This requirement is used to find an appropriate one.
|
|
||||||
class MPIDependency < Requirement
|
|
||||||
|
|
||||||
attr_reader :lang_list
|
|
||||||
|
|
||||||
fatal true
|
|
||||||
|
|
||||||
env :userpaths
|
|
||||||
|
|
||||||
def initialize *lang_list
|
|
||||||
@lang_list = lang_list
|
|
||||||
@non_functional = []
|
|
||||||
@unknown_langs = []
|
|
||||||
super()
|
|
||||||
end
|
|
||||||
|
|
||||||
def mpi_wrapper_works? compiler
|
|
||||||
compiler = which compiler
|
|
||||||
return false if compiler.nil? or not compiler.executable?
|
|
||||||
|
|
||||||
# Some wrappers are non-functional and will return a non-zero exit code
|
|
||||||
# when invoked for version info.
|
|
||||||
#
|
|
||||||
# NOTE: A better test may be to do a small test compilation a la autotools.
|
|
||||||
quiet_system compiler, '--version'
|
|
||||||
end
|
|
||||||
|
|
||||||
satisfy do
|
|
||||||
@lang_list.each do |lang|
|
|
||||||
case lang
|
|
||||||
when :cc, :cxx, :f90, :f77
|
|
||||||
compiler = 'mpi' + lang.to_s
|
|
||||||
@non_functional << compiler unless mpi_wrapper_works? compiler
|
|
||||||
else
|
|
||||||
@unknown_langs << lang.to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@unknown_langs.empty? and @non_functional.empty?
|
|
||||||
end
|
|
||||||
|
|
||||||
env do
|
|
||||||
# Set environment variables to help configure scripts find MPI compilers.
|
|
||||||
# Variable names taken from:
|
|
||||||
# http://www.gnu.org/software/autoconf-archive/ax_mpi.html
|
|
||||||
@lang_list.each do |lang|
|
|
||||||
compiler = 'mpi' + lang.to_s
|
|
||||||
mpi_path = which compiler
|
|
||||||
|
|
||||||
# Fortran 90 environment var has a different name
|
|
||||||
compiler = 'MPIFC' if lang == :f90
|
|
||||||
ENV[compiler.upcase] = mpi_path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def message
|
|
||||||
if not @unknown_langs.empty?
|
|
||||||
<<-EOS.undent
|
|
||||||
There is no MPI compiler wrapper for:
|
|
||||||
#{@unknown_langs.join ', '}
|
|
||||||
|
|
||||||
The following values are valid arguments to `MPIDependency.new`:
|
|
||||||
:cc, :cxx, :f90, :f77
|
|
||||||
EOS
|
|
||||||
else
|
|
||||||
<<-EOS.undent
|
|
||||||
Homebrew could not locate working copies of the following MPI compiler
|
|
||||||
wrappers:
|
|
||||||
#{@non_functional.join ', '}
|
|
||||||
|
|
||||||
If you have a MPI installation, please ensure the bin folder is on your
|
|
||||||
PATH and that all the wrappers are functional. Otherwise, a MPI
|
|
||||||
installation can be obtained from homebrew by *picking one* of the
|
|
||||||
following formulae:
|
|
||||||
open-mpi, mpich2
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# This requirement added by the `conflicts_with` DSL method.
|
|
||||||
class ConflictRequirement < Requirement
|
|
||||||
attr_reader :formula
|
|
||||||
|
|
||||||
# The user can chose to force installation even in the face of conflicts.
|
|
||||||
fatal !ARGV.force?
|
|
||||||
|
|
||||||
def initialize formula, name, opts={}
|
|
||||||
@formula = formula
|
|
||||||
@name = name
|
|
||||||
@opts = opts
|
|
||||||
super(formula)
|
|
||||||
end
|
|
||||||
|
|
||||||
def message
|
|
||||||
message = "#{@name.downcase} cannot be installed alongside #{@formula}.\n"
|
|
||||||
message << "This is because #{@opts[:because]}\n" if @opts[:because]
|
|
||||||
message << <<-EOS.undent unless ARGV.force?
|
|
||||||
Please `brew unlink #{@formula}` before continuing. Unlinking removes
|
|
||||||
the formula's symlinks from #{HOMEBREW_PREFIX}. You can link the
|
|
||||||
formula again after the install finishes. You can --force this install
|
|
||||||
but the build may fail or cause obscure side-effects in the end-binary.
|
|
||||||
EOS
|
|
||||||
message
|
|
||||||
end
|
|
||||||
|
|
||||||
satisfy :build_env => false do
|
|
||||||
keg = Formula.factory(@formula).prefix
|
|
||||||
not keg.exist? && Keg.new(keg).linked?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class XcodeDependency < Requirement
|
class XcodeDependency < Requirement
|
||||||
fatal true
|
fatal true
|
||||||
@ -349,8 +103,7 @@ class ArchRequirement < Requirement
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def message; <<-EOS.undent
|
def message
|
||||||
This formula requires an #{@arch} architecture.
|
"This formula requires an #{@arch} architecture."
|
||||||
EOS
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
33
Library/Homebrew/requirements/conflict_requirement.rb
Normal file
33
Library/Homebrew/requirements/conflict_requirement.rb
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
require 'requirement'
|
||||||
|
|
||||||
|
# This requirement added by the `conflicts_with` DSL method.
|
||||||
|
class ConflictRequirement < Requirement
|
||||||
|
attr_reader :formula
|
||||||
|
|
||||||
|
# The user can chose to force installation even in the face of conflicts.
|
||||||
|
fatal !ARGV.force?
|
||||||
|
|
||||||
|
def initialize formula, name, opts={}
|
||||||
|
@formula = formula
|
||||||
|
@name = name
|
||||||
|
@opts = opts
|
||||||
|
super(formula)
|
||||||
|
end
|
||||||
|
|
||||||
|
def message
|
||||||
|
message = "#{@name.downcase} cannot be installed alongside #{@formula}.\n"
|
||||||
|
message << "This is because #{@opts[:because]}\n" if @opts[:because]
|
||||||
|
message << <<-EOS.undent unless ARGV.force?
|
||||||
|
Please `brew unlink #{@formula}` before continuing. Unlinking removes
|
||||||
|
the formula's symlinks from #{HOMEBREW_PREFIX}. You can link the
|
||||||
|
formula again after the install finishes. You can --force this install
|
||||||
|
but the build may fail or cause obscure side-effects in the end-binary.
|
||||||
|
EOS
|
||||||
|
message
|
||||||
|
end
|
||||||
|
|
||||||
|
satisfy :build_env => false do
|
||||||
|
keg = Formula.factory(@formula).prefix
|
||||||
|
not keg.exist? && Keg.new(keg).linked?
|
||||||
|
end
|
||||||
|
end
|
||||||
49
Library/Homebrew/requirements/language_module_dependency.rb
Normal file
49
Library/Homebrew/requirements/language_module_dependency.rb
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
require 'requirement'
|
||||||
|
|
||||||
|
class LanguageModuleDependency < Requirement
|
||||||
|
fatal true
|
||||||
|
|
||||||
|
def initialize language, module_name, import_name=module_name
|
||||||
|
@language = language
|
||||||
|
@module_name = module_name
|
||||||
|
@import_name = import_name
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
satisfy { quiet_system(*the_test) }
|
||||||
|
|
||||||
|
def message; <<-EOS.undent
|
||||||
|
Unsatisfied dependency: #{@module_name}
|
||||||
|
Homebrew does not provide #{@language.to_s.capitalize} dependencies; install with:
|
||||||
|
#{command_line} #{@module_name}
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
def the_test
|
||||||
|
case @language
|
||||||
|
when :chicken then %W{/usr/bin/env csi -e (use\ #{@import_name})}
|
||||||
|
when :jruby then %W{/usr/bin/env jruby -rubygems -e require\ '#{@import_name}'}
|
||||||
|
when :lua then %W{/usr/bin/env luarocks show #{@import_name}}
|
||||||
|
when :node then %W{/usr/bin/env node -e require('#{@import_name}');}
|
||||||
|
when :ocaml then %W{/usr/bin/env opam list #{@import_name} | grep #{@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 :ruby then %W{/usr/bin/env ruby -rubygems -e require\ '#{@import_name}'}
|
||||||
|
when :rbx then %W{/usr/bin/env rbx -rubygems -e require\ '#{@import_name}'}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def command_line
|
||||||
|
case @language
|
||||||
|
when :chicken then "chicken-install"
|
||||||
|
when :jruby then "jruby -S gem install"
|
||||||
|
when :lua then "luarocks install"
|
||||||
|
when :node then "npm install"
|
||||||
|
when :ocaml then "opam install"
|
||||||
|
when :perl then "cpan -i"
|
||||||
|
when :python then "pip install"
|
||||||
|
when :rbx then "rbx gem install"
|
||||||
|
when :ruby then "gem install"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
82
Library/Homebrew/requirements/mpi_dependency.rb
Normal file
82
Library/Homebrew/requirements/mpi_dependency.rb
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
require 'requirement'
|
||||||
|
|
||||||
|
# There are multiple implementations of MPI-2 available.
|
||||||
|
# http://www.mpi-forum.org/
|
||||||
|
# This requirement is used to find an appropriate one.
|
||||||
|
class MPIDependency < Requirement
|
||||||
|
|
||||||
|
attr_reader :lang_list
|
||||||
|
|
||||||
|
fatal true
|
||||||
|
|
||||||
|
env :userpaths
|
||||||
|
|
||||||
|
def initialize *lang_list
|
||||||
|
@lang_list = lang_list
|
||||||
|
@non_functional = []
|
||||||
|
@unknown_langs = []
|
||||||
|
super()
|
||||||
|
end
|
||||||
|
|
||||||
|
def mpi_wrapper_works? compiler
|
||||||
|
compiler = which compiler
|
||||||
|
return false if compiler.nil? or not compiler.executable?
|
||||||
|
|
||||||
|
# Some wrappers are non-functional and will return a non-zero exit code
|
||||||
|
# when invoked for version info.
|
||||||
|
#
|
||||||
|
# NOTE: A better test may be to do a small test compilation a la autotools.
|
||||||
|
quiet_system compiler, '--version'
|
||||||
|
end
|
||||||
|
|
||||||
|
satisfy do
|
||||||
|
@lang_list.each do |lang|
|
||||||
|
case lang
|
||||||
|
when :cc, :cxx, :f90, :f77
|
||||||
|
compiler = 'mpi' + lang.to_s
|
||||||
|
@non_functional << compiler unless mpi_wrapper_works? compiler
|
||||||
|
else
|
||||||
|
@unknown_langs << lang.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@unknown_langs.empty? and @non_functional.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
env do
|
||||||
|
# Set environment variables to help configure scripts find MPI compilers.
|
||||||
|
# Variable names taken from:
|
||||||
|
# http://www.gnu.org/software/autoconf-archive/ax_mpi.html
|
||||||
|
@lang_list.each do |lang|
|
||||||
|
compiler = 'mpi' + lang.to_s
|
||||||
|
mpi_path = which compiler
|
||||||
|
|
||||||
|
# Fortran 90 environment var has a different name
|
||||||
|
compiler = 'MPIFC' if lang == :f90
|
||||||
|
ENV[compiler.upcase] = mpi_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def message
|
||||||
|
if not @unknown_langs.empty?
|
||||||
|
<<-EOS.undent
|
||||||
|
There is no MPI compiler wrapper for:
|
||||||
|
#{@unknown_langs.join ', '}
|
||||||
|
|
||||||
|
The following values are valid arguments to `MPIDependency.new`:
|
||||||
|
:cc, :cxx, :f90, :f77
|
||||||
|
EOS
|
||||||
|
else
|
||||||
|
<<-EOS.undent
|
||||||
|
Homebrew could not locate working copies of the following MPI compiler
|
||||||
|
wrappers:
|
||||||
|
#{@non_functional.join ', '}
|
||||||
|
|
||||||
|
If you have a MPI installation, please ensure the bin folder is on your
|
||||||
|
PATH and that all the wrappers are functional. Otherwise, a MPI
|
||||||
|
installation can be obtained from homebrew by *picking one* of the
|
||||||
|
following formulae:
|
||||||
|
open-mpi, mpich2
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
84
Library/Homebrew/requirements/x11_dependency.rb
Normal file
84
Library/Homebrew/requirements/x11_dependency.rb
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
require 'requirement'
|
||||||
|
|
||||||
|
class X11Dependency < Requirement
|
||||||
|
include Comparable
|
||||||
|
attr_reader :min_version
|
||||||
|
|
||||||
|
fatal true
|
||||||
|
|
||||||
|
env { ENV.x11 }
|
||||||
|
|
||||||
|
def initialize(name="x11", *tags)
|
||||||
|
tags.flatten!
|
||||||
|
@name = name
|
||||||
|
@min_version = tags.shift if /(\d\.)+\d/ === tags.first
|
||||||
|
super(tags)
|
||||||
|
end
|
||||||
|
|
||||||
|
satisfy :build_env => false do
|
||||||
|
MacOS::XQuartz.installed? && (@min_version.nil? || @min_version <= MacOS::XQuartz.version)
|
||||||
|
end
|
||||||
|
|
||||||
|
def message; <<-EOS.undent
|
||||||
|
Unsatisfied dependency: XQuartz #{@min_version}
|
||||||
|
Homebrew does not package XQuartz. Installers may be found at:
|
||||||
|
https://xquartz.macosforge.org
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
def <=> other
|
||||||
|
unless other.is_a? X11Dependency
|
||||||
|
raise TypeError, "expected X11Dependency"
|
||||||
|
end
|
||||||
|
|
||||||
|
if min_version.nil? && other.min_version.nil?
|
||||||
|
0
|
||||||
|
elsif other.min_version.nil?
|
||||||
|
1
|
||||||
|
elsif @min_version.nil?
|
||||||
|
-1
|
||||||
|
else
|
||||||
|
@min_version <=> other.min_version
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# When X11Dependency is subclassed, the new class should
|
||||||
|
# also inherit the information specified in the DSL above.
|
||||||
|
def self.inherited(mod)
|
||||||
|
instance_variables.each do |ivar|
|
||||||
|
mod.instance_variable_set(ivar, instance_variable_get(ivar))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# X11Dependency::Proxy is a base class for the X11 pseudo-deps.
|
||||||
|
# Rather than instantiate it directly, a separate class is built
|
||||||
|
# for each of the packages that we proxy to X11Dependency.
|
||||||
|
class Proxy < self
|
||||||
|
PACKAGES = [:libpng, :freetype, :fontconfig]
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def defines_const?(const)
|
||||||
|
if ::RUBY_VERSION >= "1.9"
|
||||||
|
const_defined?(const, false)
|
||||||
|
else
|
||||||
|
const_defined?(const)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def for(name, *tags)
|
||||||
|
constant = name.capitalize
|
||||||
|
|
||||||
|
if defines_const?(constant)
|
||||||
|
klass = const_get(constant)
|
||||||
|
else
|
||||||
|
klass = Class.new(self) do
|
||||||
|
def initialize(name, *tags) super end
|
||||||
|
end
|
||||||
|
|
||||||
|
const_set(constant, klass)
|
||||||
|
end
|
||||||
|
klass.new(name, *tags)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,5 +1,7 @@
|
|||||||
require 'testing_env'
|
require 'testing_env'
|
||||||
require 'requirements'
|
require 'requirements/language_module_dependency'
|
||||||
|
|
||||||
|
# XXX: Figure out what env file needs to require hardware
|
||||||
require 'hardware'
|
require 'hardware'
|
||||||
|
|
||||||
class LanguageModuleDependencyTests < Test::Unit::TestCase
|
class LanguageModuleDependencyTests < Test::Unit::TestCase
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user