autoremove: ignore build deps when built from src
Now the build dependencies of formula that were installed from source will not be removed by `brew autoremove`. This is especially helpful for those who've installed brew in an alternative prefix.
This commit is contained in:
		
							parent
							
								
									2d0c32fa91
								
							
						
					
					
						commit
						ae17d3cffd
					
				@ -37,7 +37,7 @@ module Homebrew
 | 
			
		||||
  def leaves
 | 
			
		||||
    args = leaves_args.parse
 | 
			
		||||
 | 
			
		||||
    leaves_list = Formula.formulae_with_no_formula_dependents(Formula.installed)
 | 
			
		||||
    leaves_list = Formula.installed - Formula.installed.flat_map(&:runtime_formula_dependencies)
 | 
			
		||||
 | 
			
		||||
    leaves_list.select!(&method(:installed_on_request?)) if args.installed_on_request?
 | 
			
		||||
    leaves_list.select!(&method(:installed_as_dependency?)) if args.installed_as_dependency?
 | 
			
		||||
 | 
			
		||||
@ -1853,12 +1853,21 @@ class Formula
 | 
			
		||||
         .flat_map { |f| [f, *f.runtime_formula_dependencies].compact }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # An array of all installed {Formula} without {Formula} dependents
 | 
			
		||||
  # An array of all installed {Formula} without runtime {Formula}
 | 
			
		||||
  # dependents for bottles and without build {Formula} dependents
 | 
			
		||||
  # for those built from source.
 | 
			
		||||
  # @private
 | 
			
		||||
  def self.formulae_with_no_formula_dependents(formulae)
 | 
			
		||||
    return [] if formulae.blank?
 | 
			
		||||
 | 
			
		||||
    formulae - formulae.flat_map(&:runtime_formula_dependencies)
 | 
			
		||||
    formulae - formulae.each_with_object([]) do |formula, dependents|
 | 
			
		||||
      dependents.concat(formula.runtime_formula_dependencies)
 | 
			
		||||
 | 
			
		||||
      # Include build dependencies when the formula is not a bottle
 | 
			
		||||
      unless Tab.for_keg(formula.any_installed_keg).poured_from_bottle
 | 
			
		||||
        dependents.concat(formula.deps.select(&:build?).map(&:to_formula))
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # Recursive function that returns an array of {Formula} without
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user