Skip to content

Commit

Permalink
Merge pull request #1813 from MikeMcQuaid/installed_as_dependency
Browse files Browse the repository at this point in the history
tab: store installed_as_dependency, installed_on_request.
  • Loading branch information
MikeMcQuaid committed Jan 18, 2017
2 parents 22e8ddc + 89d8864 commit aa926a1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Library/Homebrew/cmd/install.rb
Expand Up @@ -184,6 +184,14 @@ def install
# FormulaInstaller will handle this case.
formulae << f
end

# Even if we don't install this formula mark it as no longer just
# installed as a dependency.
next unless f.opt_prefix.directory?
keg = Keg.new(f.opt_prefix.resolved_path)
tab = Tab.for_keg(keg)
tab.installed_on_request = true
tab.write
end

perform_preinstall_checks
Expand Down
24 changes: 17 additions & 7 deletions Library/Homebrew/cmd/upgrade.rb
Expand Up @@ -94,14 +94,24 @@ def upgrade_formula(f)
.select(&:directory?)
.map { |k| Keg.new(k.resolved_path) }

if f.opt_prefix.directory?
keg = Keg.new(f.opt_prefix.resolved_path)
tab = Tab.for_keg(keg)
end

fi = FormulaInstaller.new(f)
fi.options = f.build.used_options
fi.options &= f.options
fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.build_bottle?)
fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
fi.verbose = ARGV.verbose?
fi.quieter = ARGV.quieter?
fi.debug = ARGV.debug?
fi.options = f.build.used_options
fi.options &= f.options
fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.build_bottle?)
fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
fi.verbose = ARGV.verbose?
fi.quieter = ARGV.quieter?
fi.debug = ARGV.debug?
fi.installed_on_request = !ARGV.named.empty?
if tab
fi.installed_as_dependency = tab.installed_as_dependency
fi.installed_on_request ||= tab.installed_on_request
end
fi.prelude

oh1 "Upgrading #{f.full_specified_name} #{fi.options.to_a.join " "}"
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/formula.rb
Expand Up @@ -1629,6 +1629,8 @@ def to_hash
"built_as_bottle" => tab.built_as_bottle,
"poured_from_bottle" => tab.poured_from_bottle,
"runtime_dependencies" => tab.runtime_dependencies,
"installed_as_dependency" => tab.installed_as_dependency,
"installed_on_request" => tab.installed_on_request,
}
end

Expand Down
19 changes: 19 additions & 0 deletions Library/Homebrew/formula_installer.rb
Expand Up @@ -36,6 +36,7 @@ def self.mode_attr_accessor(*names)
mode_attr_accessor :build_from_source, :force_bottle
mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git
mode_attr_accessor :verbose, :debug, :quieter
mode_attr_accessor :installed_as_dependency, :installed_on_request

def initialize(formula)
@formula = formula
Expand All @@ -50,6 +51,8 @@ def initialize(formula)
@verbose = false
@quieter = false
@debug = false
@installed_as_dependency = false
@installed_on_request = true
@options = Options.new
@invalid_option_names = []
@requirement_messages = []
Expand Down Expand Up @@ -250,6 +253,12 @@ def install
category = "install"
action = ([formula.full_name] + options).join(" ")
Utils::Analytics.report_event(category, action)

if installed_on_request
category = "install_on_request"
action = ([formula.full_name] + options).join(" ")
Utils::Analytics.report_event(category, action)
end
end

@@attempted << formula
Expand Down Expand Up @@ -287,6 +296,12 @@ def install
brew_prefix = formula.prefix/".brew"
brew_prefix.mkdir
Pathname(brew_prefix/"#{formula.name}.rb").atomic_write(s)

keg = Keg.new(formula.prefix)
tab = Tab.for_keg(keg)
tab.installed_as_dependency = installed_as_dependency
tab.installed_on_request = installed_on_request
tab.write
end

build_bottle_postinstall if build_bottle?
Expand Down Expand Up @@ -483,6 +498,8 @@ def install_dependency(dep, inherited_options)
fi.build_from_source = ARGV.build_formula_from_source?(df)
fi.verbose = verbose? && !quieter?
fi.debug = debug?
fi.installed_as_dependency = true
fi.installed_on_request = false
fi.prelude
oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}"
fi.install
Expand Down Expand Up @@ -809,6 +826,8 @@ def pour
tab.time = Time.now.to_i
tab.head = HOMEBREW_REPOSITORY.git_head
tab.source["path"] = formula.specified_path.to_s
tab.installed_as_dependency = installed_as_dependency
tab.installed_on_request = installed_on_request
tab.write
end

Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/tab.rb
Expand Up @@ -25,6 +25,8 @@ def self.create(formula, compiler, stdlib)
"unused_options" => build.unused_options.as_flags,
"tabfile" => formula.prefix.join(FILENAME),
"built_as_bottle" => build.bottle?,
"installed_as_dependency" => false,
"installed_on_request" => true,
"poured_from_bottle" => false,
"time" => Time.now.to_i,
"source_modified_time" => formula.source_modified_time.to_i,
Expand Down Expand Up @@ -172,6 +174,8 @@ def self.empty
"used_options" => [],
"unused_options" => [],
"built_as_bottle" => false,
"installed_as_dependency" => false,
"installed_on_request" => true,
"poured_from_bottle" => false,
"time" => nil,
"source_modified_time" => 0,
Expand Down Expand Up @@ -313,6 +317,8 @@ def to_json
"unused_options" => unused_options.as_flags,
"built_as_bottle" => built_as_bottle,
"poured_from_bottle" => poured_from_bottle,
"installed_as_dependency" => installed_as_dependency,
"installed_on_request" => installed_on_request,
"changed_files" => changed_files && changed_files.map(&:to_s),
"time" => time,
"source_modified_time" => source_modified_time.to_i,
Expand Down

0 comments on commit aa926a1

Please sign in to comment.