diff options
| author | Mike McQuaid | 2017-12-30 18:58:30 +0000 |
|---|---|---|
| committer | Mike McQuaid | 2017-12-30 20:56:55 +0000 |
| commit | d54e670a6491ae3e6681448cfcf9332635149aa8 (patch) | |
| tree | 6499f8269f928376e66ffa06b99bbcf3b426ece7 /Library/Homebrew/compat | |
| parent | faf2182495e770041274c59e3b9ac80b98326fae (diff) | |
| download | brew-d54e670a6491ae3e6681448cfcf9332635149aa8.tar.bz2 | |
requirements: move more to compat.
Diffstat (limited to 'Library/Homebrew/compat')
8 files changed, 319 insertions, 9 deletions
diff --git a/Library/Homebrew/compat/dependency_collector.rb b/Library/Homebrew/compat/dependency_collector.rb index 2e97d9d7f..82511bcc7 100644 --- a/Library/Homebrew/compat/dependency_collector.rb +++ b/Library/Homebrew/compat/dependency_collector.rb @@ -22,31 +22,61 @@ class DependencyCollector case spec when :clt odeprecated "'depends_on :clt'" + when :tex + # odeprecated "'depends_on :tex'" + TeXRequirement.new(tags) when :autoconf, :automake, :bsdmake, :libtool output_deprecation(spec, tags) autotools_dep(spec, tags) when :cairo, :fontconfig, :freetype, :libpng, :pixman output_deprecation(spec, tags) Dependency.new(spec.to_s, tags) - when :apr - # output_deprecation(spec, tags, "apr-util") - Dependency.new("apr-util", tags) + when :ant, :expat + # output_deprecation(spec, tags) + Dependency.new(spec.to_s, tags) when :libltdl tags << :run output_deprecation("libtool", tags) Dependency.new("libtool", tags) + when :apr + # output_deprecation(spec, tags, "apr-util") + Dependency.new("apr-util", tags) + when :fortran + # output_deprecation(spec, tags, "gcc") + FortranRequirement.new(tags) + when :gpg + # output_deprecation(spec, tags, "gnupg") + GPG2Requirement.new(tags) + when :hg + # output_deprecation(spec, tags, "mercurial") + MercurialRequirement.new(tags) + when :mpi + # output_deprecation(spec, tags, "open-mpi") + MPIRequirement.new(*tags) + when :emacs + # output_deprecation(spec, tags) + EmacsRequirement.new(tags) when :mysql - # output_deprecation("mysql", tags) + # output_deprecation(spec, tags) MysqlRequirement.new(tags) + when :perl + # output_deprecation(spec, tags) + PerlRequirement.new(tags) when :postgresql - # output_deprecation("postgresql", tags) + # output_deprecation(spec, tags) PostgresqlRequirement.new(tags) - when :gpg - # output_deprecation("gnupg", tags) - GPG2Requirement.new(tags) + when :python, :python2 + # output_deprecation(spec, tags) + PythonRequirement.new(tags) + when :python3 + # output_deprecation(spec, tags) + Python3Requirement.new(tags) when :rbenv - # output_deprecation("rbenv", tags) + # output_deprecation(spec, tags) RbenvRequirement.new(tags) + when :ruby + # output_deprecation(spec, tags) + RubyRequirement.new(tags) else _parse_symbol_spec(spec, tags) end diff --git a/Library/Homebrew/compat/requirements.rb b/Library/Homebrew/compat/requirements.rb index da6d867b3..48911b52b 100644 --- a/Library/Homebrew/compat/requirements.rb +++ b/Library/Homebrew/compat/requirements.rb @@ -1,5 +1,11 @@ require "requirements" +require "compat/requirements/emacs_requirement" +require "compat/requirements/fortran_requirement" require "compat/requirements/language_module_requirement" +require "compat/requirements/mpi_requirement" +require "compat/requirements/perl_requirement" +require "compat/requirements/python_requirement" +require "compat/requirements/ruby_requirement" require "compat/requirements/tex_requirement" class MysqlRequirement < Requirement diff --git a/Library/Homebrew/compat/requirements/emacs_requirement.rb b/Library/Homebrew/compat/requirements/emacs_requirement.rb new file mode 100644 index 000000000..c8e2ec274 --- /dev/null +++ b/Library/Homebrew/compat/requirements/emacs_requirement.rb @@ -0,0 +1,35 @@ +class EmacsRequirement < Requirement + fatal true + default_formula "emacs" + + def initialize(tags) + @version = tags.shift if /\d+\.*\d*/ =~ tags.first + super + end + + satisfy build_env: false do + next false unless which "emacs" + next true unless @version + emacs_version = Utils.popen_read("emacs", "--batch", "--eval", "(princ emacs-version)") + Version.create(emacs_version) >= Version.create(@version) + end + + env do + ENV.prepend_path "PATH", which("emacs").dirname + ENV["EMACS"] = "emacs" + end + + def message + if @version + s = "Emacs #{@version} or later is required." + else + s = "Emacs is required." + end + s += super + s + end + + def inspect + "#<#{self.class.name}: #{name.inspect} #{tags.inspect} version=#{@version.inspect}>" + end +end diff --git a/Library/Homebrew/compat/requirements/fortran_requirement.rb b/Library/Homebrew/compat/requirements/fortran_requirement.rb new file mode 100644 index 000000000..ba3fead6f --- /dev/null +++ b/Library/Homebrew/compat/requirements/fortran_requirement.rb @@ -0,0 +1,13 @@ +require "requirement" + +class FortranRequirement < Requirement + fatal true + + default_formula "gcc" + + env { ENV.fortran } + + satisfy build_env: false do + which(ENV["FC"] || "gfortran") + end +end diff --git a/Library/Homebrew/compat/requirements/mpi_requirement.rb b/Library/Homebrew/compat/requirements/mpi_requirement.rb new file mode 100644 index 000000000..065b56c8b --- /dev/null +++ b/Library/Homebrew/compat/requirements/mpi_requirement.rb @@ -0,0 +1,66 @@ +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 MPIRequirement < Requirement + attr_reader :lang_list + + fatal true + + default_formula "open-mpi" + + env :userpaths + + # This method must accept varargs rather than an array for + # backwards compatibility with formulae that call it directly. + def initialize(*tags) + @non_functional = [] + @unknown_langs = [] + @lang_list = [:cc, :cxx, :f77, :f90] & tags + tags -= @lang_list + super(tags) + end + + def mpi_wrapper_works?(compiler) + compiler = which compiler + return false if compiler.nil? || !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 + + def inspect + "#<#{self.class.name}: #{name.inspect} #{tags.inspect} lang_list=#{@lang_list.inspect}>" + 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? && @non_functional.empty? + end + + env do + # Set environment variables to help configure scripts find MPI compilers. + # Variable names taken from: + # https://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 +end diff --git a/Library/Homebrew/compat/requirements/perl_requirement.rb b/Library/Homebrew/compat/requirements/perl_requirement.rb new file mode 100644 index 000000000..70eb2a36c --- /dev/null +++ b/Library/Homebrew/compat/requirements/perl_requirement.rb @@ -0,0 +1,36 @@ +class PerlRequirement < Requirement + fatal true + default_formula "perl" + + def initialize(tags) + @version = tags.shift if /^\d+\.\d+$/ =~ tags.first + raise "PerlRequirement requires a version!" unless @version + super + end + + satisfy(build_env: false) do + which_all("perl").detect do |perl| + perl_version = Utils.popen_read(perl, "--version")[/v(\d+\.\d+)(?:\.\d+)?/, 1] + next unless perl_version + Version.create(perl_version.to_s) >= Version.create(@version) + end + end + + def message + s = "Perl #{@version} is required to install this formula." + s += super + s + end + + def inspect + "#<#{self.class.name}: #{name.inspect} #{tags.inspect} version=#{@version.inspect}>" + end + + def display_s + if @version + "#{name} >= #{@version}" + else + name + end + end +end diff --git a/Library/Homebrew/compat/requirements/python_requirement.rb b/Library/Homebrew/compat/requirements/python_requirement.rb new file mode 100644 index 000000000..3215d0a6c --- /dev/null +++ b/Library/Homebrew/compat/requirements/python_requirement.rb @@ -0,0 +1,68 @@ +require "language/python" + +class PythonRequirement < Requirement + fatal true + default_formula "python" + + satisfy build_env: false do + python = which_python + next unless python + next unless short_version + # Always use Python 2.7 for consistency on older versions of Mac OS X. + short_version == Version.create("2.7") + end + + env do + if !system_python? && short_version == Version.create("2.7") + ENV.prepend_path "PATH", which_python.dirname + end + + # Homebrew Python should take precedence over other Pythons in the PATH + ENV.prepend_path "PATH", Formula["python"].opt_bin + ENV.prepend_path "PATH", Formula["python"].opt_libexec/"bin" + + if system_python? + ENV["PYTHONPATH"] = "#{HOMEBREW_PREFIX}/lib/python#{short_version}/site-packages" + end + end + + private + + def short_version + @short_version ||= Language::Python.major_minor_version which_python + end + + def which_python + python = which python_binary + return unless python + Pathname.new Utils.popen_read(python, "-c", "import sys; print(sys.executable)").strip + end + + def system_python + "/usr/bin/#{python_binary}" + end + + def system_python? + system_python == which_python.to_s + end + + def python_binary + "python2.7" + end + + # Deprecated + alias to_s python_binary +end + +class Python3Requirement < PythonRequirement + fatal true + default_formula "python3" + + satisfy(build_env: false) { which_python } + + private + + def python_binary + "python3" + end +end diff --git a/Library/Homebrew/compat/requirements/ruby_requirement.rb b/Library/Homebrew/compat/requirements/ruby_requirement.rb new file mode 100644 index 000000000..a9ec8c42d --- /dev/null +++ b/Library/Homebrew/compat/requirements/ruby_requirement.rb @@ -0,0 +1,56 @@ +class RubyRequirement < Requirement + fatal true + default_formula "ruby" + + def initialize(tags) + @version = tags.shift if /(\d\.)+\d/ =~ tags.first + raise "RubyRequirement requires a version!" unless @version + super + end + + satisfy(build_env: false) { new_enough_ruby } + + env do + ENV.prepend_path "PATH", new_enough_ruby.dirname + end + + def message + s = "Ruby >= #{@version} is required to install this formula." + s += super + s + end + + def inspect + "#<#{self.class.name}: #{name.inspect} #{tags.inspect} version=#{@version.inspect}>" + end + + def display_s + if @version + "#{name} >= #{@version}" + else + name + end + end + + private + + def new_enough_ruby + rubies.detect { |ruby| new_enough?(ruby) } + end + + def rubies + rubies = which_all("ruby") + ruby_formula = Formula["ruby"] + rubies.unshift ruby_formula.bin/"ruby" if ruby_formula&.installed? + rubies.uniq + end + + def new_enough?(ruby) + version = Utils.popen_read(ruby, "-e", "print RUBY_VERSION").strip + version =~ /^\d+\.\d+/ && Version.create(version) >= min_version + end + + def min_version + @min_version ||= Version.create(@version) + end +end |
