From 1195718d0ee0413d271f109c40bd58e73431ea8f Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 29 Oct 2014 22:38:49 -0500 Subject: [PATCH] Rename "f" to "formula" in the installer --- Library/Homebrew/cmd/audit.rb | 38 ++--- Library/Homebrew/formula_cellar_checks.rb | 42 +++--- Library/Homebrew/formula_installer.rb | 161 +++++++++++----------- 3 files changed, 121 insertions(+), 120 deletions(-) diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb index 4ac5bb4f19..2bc10882e1 100644 --- a/Library/Homebrew/cmd/audit.rb +++ b/Library/Homebrew/cmd/audit.rb @@ -70,7 +70,7 @@ end class FormulaAuditor include FormulaCellarChecks - attr_reader :f, :text, :problems + attr_reader :formula, :text, :problems BUILD_TIME_DEPS = %W[ autoconf @@ -87,27 +87,27 @@ class FormulaAuditor swig ] - def initialize f - @f = f + def initialize(formula) + @formula = formula @problems = [] - @text = f.text.without_patch - @specs = %w{stable devel head}.map { |s| f.send(s) }.compact + @text = formula.text.without_patch + @specs = %w{stable devel head}.map { |s| formula.send(s) }.compact end def audit_file - unless f.path.stat.mode.to_s(8) == "100644" - problem "Incorrect file permissions: chmod 644 #{f.path}" + unless formula.path.stat.mode.to_s(8) == "100644" + problem "Incorrect file permissions: chmod 644 #{formula.path}" end - if f.text.has_DATA? and not f.text.has_END? + if formula.text.has_DATA? and not formula.text.has_END? problem "'DATA' was found, but no '__END__'" end - if f.text.has_END? and not f.text.has_DATA? + if formula.text.has_END? and not formula.text.has_DATA? problem "'__END__' was found, but 'DATA' is not used" end - unless f.text.has_trailing_newline? + unless formula.text.has_trailing_newline? problem "File should end with a newline" end end @@ -167,7 +167,7 @@ class FormulaAuditor end def audit_conflicts - f.conflicts.each do |c| + formula.conflicts.each do |c| begin Formulary.factory(c.name) rescue FormulaUnavailableError @@ -177,7 +177,7 @@ class FormulaAuditor end def audit_urls - homepage = f.homepage + homepage = formula.homepage unless homepage =~ %r[^https?://] problem "The homepage should start with http or https (URL is #{homepage})." @@ -266,10 +266,10 @@ class FormulaAuditor end def audit_specs - problem "Head-only (no stable download)" if f.head_only? + problem "Head-only (no stable download)" if formula.head_only? %w[Stable Devel HEAD].each do |name| - next unless spec = f.send(name.downcase) + next unless spec = formula.send(name.downcase) ra = ResourceAuditor.new(spec).audit problems.concat ra.problems.map { |problem| "#{name}: #{problem}" } @@ -284,17 +284,17 @@ class FormulaAuditor spec.patches.select(&:external?).each { |p| audit_patch(p) } end - if f.stable && f.devel - if f.devel.version < f.stable.version - problem "devel version #{f.devel.version} is older than stable version #{f.stable.version}" - elsif f.devel.version == f.stable.version + if formula.stable && formula.devel + if formula.devel.version < formula.stable.version + problem "devel version #{formula.devel.version} is older than stable version #{formula.stable.version}" + elsif formula.devel.version == formula.stable.version problem "stable and devel versions are identical" end end end def audit_patches - legacy_patches = Patch.normalize_legacy_patches(f.patches).grep(LegacyPatch) + legacy_patches = Patch.normalize_legacy_patches(formula.patches).grep(LegacyPatch) if legacy_patches.any? problem "Use the patch DSL instead of defining a 'patches' method" legacy_patches.each { |p| audit_patch(p) } diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 2c12701515..6f621510f2 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -18,7 +18,7 @@ module FormulaCellarChecks def check_manpages # Check for man pages that aren't in share/man - return unless (f.prefix+'man').directory? + return unless (formula.prefix+'man').directory? <<-EOS.undent A top-level "man" directory was found @@ -29,7 +29,7 @@ module FormulaCellarChecks def check_infopages # Check for info pages that aren't in share/info - return unless (f.prefix+'info').directory? + return unless (formula.prefix+'info').directory? <<-EOS.undent A top-level "info" directory was found @@ -39,12 +39,12 @@ module FormulaCellarChecks end def check_jars - return unless f.lib.directory? - jars = f.lib.children.select { |g| g.extname == ".jar" } + return unless formula.lib.directory? + jars = formula.lib.children.select { |g| g.extname == ".jar" } return if jars.empty? <<-EOS.undent - JARs were installed to "#{f.lib}" + JARs were installed to "#{formula.lib}" Installing JARs to "lib" can cause conflicts between packages. For Java software, it is typically better for the formula to install to "libexec" and then symlink or wrap binaries into "bin". @@ -55,18 +55,18 @@ module FormulaCellarChecks end def check_non_libraries - return unless f.lib.directory? + return unless formula.lib.directory? valid_extensions = %w(.a .dylib .framework .jnilib .la .o .so .jar .prl .pm .sh) - non_libraries = f.lib.children.select do |g| + non_libraries = formula.lib.children.select do |g| next if g.directory? not valid_extensions.include? g.extname end return if non_libraries.empty? <<-EOS.undent - Non-libraries were installed to "#{f.lib}" + Non-libraries were installed to "#{formula.lib}" Installing non-libraries to "lib" is discouraged. The offending files are: #{non_libraries * "\n "} @@ -104,17 +104,17 @@ module FormulaCellarChecks end def check_shadowed_headers - return if f.name == "libtool" || f.name == "subversion" - return if f.keg_only? || !f.include.directory? + return if formula.name == "libtool" || formula.name == "subversion" + return if formula.keg_only? || !formula.include.directory? - files = relative_glob(f.include, "**/*.h") + files = relative_glob(formula.include, "**/*.h") files &= relative_glob("#{MacOS.sdk_path}/usr/include", "**/*.h") - files.map! { |p| File.join(f.include, p) } + files.map! { |p| File.join(formula.include, p) } return if files.empty? <<-EOS.undent - Header files that shadow system header files were installed to "#{f.include}" + Header files that shadow system header files were installed to "#{formula.include}" The offending files are: #{files * "\n "} EOS @@ -135,9 +135,9 @@ module FormulaCellarChecks end def check_openssl_links - return unless f.prefix.directory? - return if f.name == "android-ndk" - keg = Keg.new(f.prefix) + return unless formula.prefix.directory? + return if formula.name == "android-ndk" + keg = Keg.new(formula.prefix) system_openssl = keg.mach_o_files.select do |obj| dlls = obj.dynamically_linked_libraries dlls.any? { |dll| /\/usr\/lib\/lib(crypto|ssl).(\d\.)*dylib/.match dll } @@ -157,12 +157,12 @@ module FormulaCellarChecks audit_check_output(check_infopages) audit_check_output(check_jars) audit_check_output(check_non_libraries) - audit_check_output(check_non_executables(f.bin)) - audit_check_output(check_generic_executables(f.bin)) - audit_check_output(check_non_executables(f.sbin)) - audit_check_output(check_generic_executables(f.sbin)) + audit_check_output(check_non_executables(formula.bin)) + audit_check_output(check_generic_executables(formula.bin)) + audit_check_output(check_non_executables(formula.sbin)) + audit_check_output(check_generic_executables(formula.sbin)) audit_check_output(check_shadowed_headers) - audit_check_output(check_easy_install_pth(f.lib)) + audit_check_output(check_easy_install_pth(formula.lib)) audit_check_output(check_openssl_links) end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index ae0787c522..9b2099430e 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -22,15 +22,15 @@ class FormulaInstaller names.each { |name| define_method("#{name}?") { !!send(name) }} end - attr_reader :f + attr_reader :formula attr_accessor :options mode_attr_accessor :show_summary_heading, :show_header mode_attr_accessor :build_from_source, :build_bottle, :force_bottle mode_attr_accessor :ignore_deps, :only_deps, :interactive mode_attr_accessor :verbose, :debug - def initialize ff - @f = ff + def initialize(formula) + @formula = formula @show_header = false @ignore_deps = false @only_deps = false @@ -49,19 +49,21 @@ class FormulaInstaller end def pour_bottle? install_bottle_options={:warn=>false} - return true if Homebrew::Hooks::Bottles.formula_has_bottle?(f) + return true if Homebrew::Hooks::Bottles.formula_has_bottle?(formula) return false if @pour_failed - return true if force_bottle? && f.bottle + + bottle = formula.bottle + return true if force_bottle? && bottle return false if build_from_source? || build_bottle? || interactive? return false unless options.empty? - return true if f.local_bottle_path - return false unless f.bottle && f.pour_bottle? + return true if formula.local_bottle_path + return false unless bottle && formula.pour_bottle? - unless f.bottle.compatible_cellar? + unless bottle.compatible_cellar? if install_bottle_options[:warn] - opoo "Building source; cellar of #{f.name}'s bottle is #{f.bottle.cellar}" + opoo "Building source; cellar of #{formula.name}'s bottle is #{bottle.cellar}" end return false end @@ -70,7 +72,7 @@ class FormulaInstaller end def install_bottle_for?(dep, build) - return pour_bottle? if dep == f + return pour_bottle? if dep == formula return false if build_from_source? return false unless dep.bottle && dep.pour_bottle? return false unless build.used_options.empty? @@ -86,7 +88,7 @@ class FormulaInstaller def verify_deps_exist begin - f.recursive_dependencies.map(&:to_formula) + formula.recursive_dependencies.map(&:to_formula) rescue TapFormulaUnavailableError => e if Homebrew.install_tap(e.user, e.repo) retry @@ -95,25 +97,25 @@ class FormulaInstaller end end rescue FormulaUnavailableError => e - e.dependent = f.name + e.dependent = formula.name raise end def check_install_sanity - raise FormulaInstallationAlreadyAttemptedError, f if @@attempted.include? f + raise FormulaInstallationAlreadyAttemptedError, formula if @@attempted.include?(formula) - if f.installed? - msg = "#{f.name}-#{f.installed_version} already installed" - msg << ", it's just not linked" unless f.linked_keg.symlink? or f.keg_only? + if formula.installed? + msg = "#{formula.name}-#{formula.installed_version} already installed" + msg << ", it's just not linked" unless formula.linked_keg.symlink? or formula.keg_only? raise FormulaAlreadyInstalledError, msg end unless ignore_deps? - unlinked_deps = f.recursive_dependencies.map(&:to_formula).select do |dep| + unlinked_deps = formula.recursive_dependencies.map(&:to_formula).select do |dep| dep.installed? and not dep.keg_only? and not dep.linked_keg.directory? end raise CannotInstallFormulaError, - "You must `brew link #{unlinked_deps*' '}' before #{f.name} can be installed" unless unlinked_deps.empty? + "You must `brew link #{unlinked_deps*' '}' before #{formula.name} can be installed" unless unlinked_deps.empty? end end @@ -125,7 +127,7 @@ class FormulaInstaller def build_bottle_postinstall @etc_var_postinstall = Dir[@etc_var_glob] (@etc_var_postinstall - @etc_var_preinstall).each do |file| - Pathname.new(file).cp_path_sub(HOMEBREW_PREFIX, f.bottle_prefix) + Pathname.new(file).cp_path_sub(HOMEBREW_PREFIX, formula.bottle_prefix) end end @@ -133,11 +135,11 @@ class FormulaInstaller # not in initialize so upgrade can unlink the active keg before calling this # function but after instantiating this class so that it can avoid having to # relink the active keg if possible (because it is slow). - if f.linked_keg.directory? + if formula.linked_keg.directory? # some other version is already installed *and* linked raise CannotInstallFormulaError, <<-EOS.undent - #{f.name}-#{f.linked_keg.resolved_path.basename} already installed - To install this version, first `brew unlink #{f.name}' + #{formula.name}-#{formula.linked_keg.resolved_path.basename} already installed + To install this version, first `brew unlink #{formula.name}' EOS end @@ -151,15 +153,15 @@ class FormulaInstaller raise "Unrecognized architecture for --bottle-arch: #{arch}" end - f.active_spec.deprecated_flags.each do |deprecated_option| + formula.active_spec.deprecated_flags.each do |deprecated_option| old_flag = deprecated_option.old_flag new_flag = deprecated_option.current_flag - opoo "#{f.name}: #{old_flag} was deprecated; using #{new_flag} instead!" + opoo "#{formula.name}: #{old_flag} was deprecated; using #{new_flag} instead!" end - oh1 "Installing #{Tty.green}#{f.name}#{Tty.reset}" if show_header? + oh1 "Installing #{Tty.green}#{formula.name}#{Tty.reset}" if show_header? - @@attempted << f + @@attempted << formula if pour_bottle?(:warn => true) begin @@ -184,13 +186,13 @@ class FormulaInstaller build_bottle_postinstall if build_bottle? - opoo "Nothing was installed to #{f.prefix}" unless f.installed? + opoo "Nothing was installed to #{formula.prefix}" unless formula.installed? end # HACK: If readline is present in the dependency tree, it will clash # with the stdlib's Readline module when the debugger is loaded def perform_readline_hack - if (f.recursive_dependencies.any? { |d| d.name == "readline" } || f.name == "readline") && debug? + if (formula.recursive_dependencies.any? { |d| d.name == "readline" } || formula.name == "readline") && debug? ENV['HOMEBREW_NO_READLINE'] = '1' end end @@ -198,12 +200,12 @@ class FormulaInstaller def check_conflicts return if ARGV.force? - conflicts = f.conflicts.reject do |c| + conflicts = formula.conflicts.reject do |c| keg = Formulary.factory(c.name).prefix not keg.directory? && Keg.new(keg).linked? end - raise FormulaConflictError.new(f, conflicts) unless conflicts.empty? + raise FormulaConflictError.new(formula, conflicts) unless conflicts.empty? end def compute_and_install_dependencies @@ -213,10 +215,10 @@ class FormulaInstaller check_requirements(req_map) - deps = expand_dependencies(req_deps + f.deps) + deps = expand_dependencies(req_deps + formula.deps) if deps.empty? and only_deps? - puts "All dependencies for #{f.name} are satisfied." + puts "All dependencies for #{formula.name} are satisfied." else install_dependencies(deps) end @@ -244,10 +246,9 @@ class FormulaInstaller def expand_requirements unsatisfied_reqs = Hash.new { |h, k| h[k] = [] } deps = [] - formulae = [f] + formulae = [formula] while f = formulae.pop - f.recursive_requirements do |dependent, req| build = effective_build_options_for(dependent) @@ -274,7 +275,7 @@ class FormulaInstaller def expand_dependencies(deps) inherited_options = {} - expanded_deps = Dependency.expand(f, deps) do |dependent, dep| + expanded_deps = Dependency.expand(formula, deps) do |dependent, dep| options = inherited_options[dep.name] = inherited_options_for(dep) build = effective_build_options_for( dependent, @@ -295,7 +296,7 @@ class FormulaInstaller def effective_build_options_for(dependent, inherited_options=[]) args = dependent.build.used_options - args |= dependent == f ? options : inherited_options + args |= dependent == formula ? options : inherited_options args |= Tab.for_formula(dependent).used_options BuildOptions.new(args, dependent.options) end @@ -303,7 +304,7 @@ class FormulaInstaller def inherited_options_for(dep) inherited_options = Options.new u = Option.new("universal") - if (options.include?(u) || f.require_universal_deps?) && !dep.build? && dep.to_formula.option_defined?(u) + if (options.include?(u) || formula.require_universal_deps?) && !dep.build? && dep.to_formula.option_defined?(u) inherited_options << u end inherited_options @@ -311,7 +312,7 @@ class FormulaInstaller def install_dependencies(deps) if deps.length > 1 - oh1 "Installing dependencies for #{f.name}: #{Tty.green}#{deps.map(&:first)*", "}#{Tty.reset}" + oh1 "Installing dependencies for #{formula.name}: #{Tty.green}#{deps.map(&:first)*", "}#{Tty.reset}" end deps.each { |dep, options| install_dependency(dep, options) } @@ -320,7 +321,7 @@ class FormulaInstaller end class DependencyInstaller < FormulaInstaller - def initialize ff + def initialize(*) super @ignore_deps = true end @@ -355,7 +356,7 @@ class FormulaInstaller fi.verbose = verbose? unless verbose == :quieter fi.debug = debug? fi.prelude - oh1 "Installing #{f.name} dependency: #{Tty.green}#{dep.name}#{Tty.reset}" + oh1 "Installing #{formula.name} dependency: #{Tty.green}#{dep.name}#{Tty.reset}" fi.install fi.caveats fi.finish @@ -372,9 +373,9 @@ class FormulaInstaller def caveats return if only_deps? - audit_installed if ARGV.homebrew_developer? and not f.keg_only? + audit_installed if ARGV.homebrew_developer? and not formula.keg_only? - c = Caveats.new(f) + c = Caveats.new(formula) unless c.empty? @show_summary_heading = true @@ -389,7 +390,7 @@ class FormulaInstaller install_plist - keg = Keg.new(f.prefix) + keg = Keg.new(formula.prefix) link(keg) fix_install_names(keg) if OS.mac? @@ -408,7 +409,7 @@ class FormulaInstaller def summary s = "" s << "#{emoji} " if MacOS.version >= :lion and not ENV['HOMEBREW_NO_EMOJI'] - s << "#{f.prefix}: #{f.prefix.abv}" + s << "#{formula.prefix}: #{formula.prefix.abv}" s << ", built in #{pretty_duration build_time}" if build_time s end @@ -436,12 +437,12 @@ class FormulaInstaller args << "--cc=#{ARGV.cc}" if ARGV.cc args << "--env=#{ARGV.env}" if ARGV.env - case f.active_spec - when f.head then args << "--HEAD" - when f.devel then args << "--devel" + case formula.active_spec + when formula.head then args << "--HEAD" + when formula.devel then args << "--devel" end - f.options.each do |opt| + formula.options.each do |opt| name = opt.name[/\A(.+)=\z$/, 1] value = ARGV.value(name) args << "--#{name}=#{value}" if name && value @@ -455,7 +456,7 @@ class FormulaInstaller end def build - FileUtils.rm Dir["#{HOMEBREW_LOGS}/#{f.name}/*"] + FileUtils.rm Dir["#{HOMEBREW_LOGS}/#{formula.name}/*"] @start_time = Time.now @@ -472,7 +473,7 @@ class FormulaInstaller -I #{HOMEBREW_LIBRARY_PATH} -- #{HOMEBREW_LIBRARY_PATH}/build.rb - #{f.path} + #{formula.path} ].concat(build_argv) # Ruby 2.0+ sets close-on-exec on all file descriptors except for @@ -501,24 +502,24 @@ class FormulaInstaller raise "Suspicious installation failure" unless $?.success? end - raise "Empty installation" if Dir["#{f.prefix}/*"].empty? + raise "Empty installation" if Dir["#{formula.prefix}/*"].empty? rescue Exception ignore_interrupts do # any exceptions must leave us with nothing installed - f.prefix.rmtree if f.prefix.directory? - f.rack.rmdir_if_possible + formula.prefix.rmtree if formula.prefix.directory? + formula.rack.rmdir_if_possible end raise end def link(keg) - if f.keg_only? + if formula.keg_only? begin keg.optlink rescue Keg::LinkError => e - onoe "Failed to create #{f.opt_prefix}" - puts "Things that depend on #{f.name} will probably not build." + onoe "Failed to create #{formula.opt_prefix}" + puts "Things that depend on #{formula.name} will probably not build." puts e Homebrew.failed = true end @@ -548,7 +549,7 @@ class FormulaInstaller puts e puts puts "You can try again using:" - puts " brew link #{f.name}" + puts " brew link #{formula.name}" @show_summary_heading = true Homebrew.failed = true rescue Exception => e @@ -564,9 +565,9 @@ class FormulaInstaller end def install_plist - return unless f.plist - f.plist_path.atomic_write(f.plist) - f.plist_path.chmod 0644 + return unless formula.plist + formula.plist_path.atomic_write(formula.plist) + formula.plist_path.chmod 0644 rescue Exception => e onoe "Failed to install plist file" ohai e, e.backtrace if debug? @@ -574,11 +575,11 @@ class FormulaInstaller end def fix_install_names(keg) - keg.fix_install_names(:keg_only => f.keg_only?) + keg.fix_install_names(:keg_only => formula.keg_only?) if @poured_bottle keg.relocate_install_names Keg::PREFIX_PLACEHOLDER, HOMEBREW_PREFIX.to_s, - Keg::CELLAR_PLACEHOLDER, HOMEBREW_CELLAR.to_s, :keg_only => f.keg_only? + Keg::CELLAR_PLACEHOLDER, HOMEBREW_CELLAR.to_s, :keg_only => formula.keg_only? end rescue Exception => e onoe "Failed to fix install names" @@ -591,7 +592,7 @@ class FormulaInstaller def clean ohai "Cleaning" if verbose? - Cleaner.new(f).clean + Cleaner.new(formula).clean rescue Exception => e opoo "The cleaning step did not complete successfully" puts "Still, the installation was successful, so we will link it into your prefix" @@ -601,42 +602,42 @@ class FormulaInstaller end def post_install - f.post_install + formula.post_install rescue Exception => e opoo "The post-install step did not complete successfully" - puts "You can try again using `brew postinstall #{f.name}`" + puts "You can try again using `brew postinstall #{formula.name}`" ohai e, e.backtrace if debug? Homebrew.failed = true @show_summary_heading = true end def pour - if Homebrew::Hooks::Bottles.formula_has_bottle?(f) - return if Homebrew::Hooks::Bottles.pour_formula_bottle(f) + if Homebrew::Hooks::Bottles.formula_has_bottle?(formula) + return if Homebrew::Hooks::Bottles.pour_formula_bottle(formula) end - if f.local_bottle_path - downloader = LocalBottleDownloadStrategy.new(f) + if formula.local_bottle_path + downloader = LocalBottleDownloadStrategy.new(formula) else - downloader = f.bottle + downloader = formula.bottle downloader.verify_download_integrity(downloader.fetch) end HOMEBREW_CELLAR.cd do downloader.stage end - Pathname.glob("#{f.bottle_prefix}/{etc,var}/**/*") do |path| + Pathname.glob("#{formula.bottle_prefix}/{etc,var}/**/*") do |path| path.extend(InstallRenamed) - path.cp_path_sub(f.bottle_prefix, HOMEBREW_PREFIX) + path.cp_path_sub(formula.bottle_prefix, HOMEBREW_PREFIX) end - FileUtils.rm_rf f.bottle_prefix + FileUtils.rm_rf formula.bottle_prefix CxxStdlib.check_compatibility( - f, f.recursive_dependencies, - Keg.new(f.prefix), MacOS.default_compiler + formula, formula.recursive_dependencies, + Keg.new(formula.prefix), MacOS.default_compiler ) - tab = Tab.for_keg(f.prefix) + tab = Tab.for_keg(formula.prefix) tab.poured_from_bottle = true tab.write end @@ -649,8 +650,8 @@ class FormulaInstaller end def audit_installed - audit_check_output(check_PATH(f.bin)) - audit_check_output(check_PATH(f.sbin)) + audit_check_output(check_PATH(formula.bin)) + audit_check_output(check_PATH(formula.sbin)) super end @@ -662,10 +663,10 @@ class FormulaInstaller def lock if (@@locked ||= []).empty? - f.recursive_dependencies.each do |dep| + formula.recursive_dependencies.each do |dep| @@locked << dep.to_formula end unless ignore_deps? - @@locked.unshift(f) + @@locked.unshift(formula) @@locked.uniq! @@locked.each(&:lock) @hold_locks = true