Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cask install receipts #17554

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def install
formula.install

stdlibs = detect_stdlibs
tab = Tab.create(formula, ENV.compiler, stdlibs.first)
tab.write
tab = Tab.create_from_formula(formula, ENV.compiler, stdlibs.first)
tab.write_formula_file

# Find and link metafiles
formula.prefix.install_metafiles formula.buildpath
Expand Down
35 changes: 22 additions & 13 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def bundle_long_version
bundle_version&.version
end

def tab
Tab.for_cask(self)
end

def config_path
metadata_main_container_path/"config.json"
end
Expand Down Expand Up @@ -465,6 +469,24 @@ def to_hash_with_variations(hash_method: :to_h)
hash
end

def artifacts_list(compact: false, uninstall_phase_only: false)
artifacts.filter_map do |artifact|
if uninstall_phase_only &&
!artifact.respond_to?(:uninstall_phase) && !artifact.respond_to?(:post_uninstall_phase)
next
end
Rylan12 marked this conversation as resolved.
Show resolved Hide resolved

case artifact
when Artifact::AbstractFlightBlock
# Only indicate whether this block is used as we don't load it from the API
# We can skip this entirely once we move to internal JSON v3.
{ artifact.summarize => nil } unless compact
else
{ artifact.class.dsl_key => artifact.to_args }
end
end
end

private

sig { returns(T.nilable(Homebrew::BundleVersion)) }
Expand All @@ -482,19 +504,6 @@ def api_to_local_hash(hash)
hash
end

def artifacts_list(compact: false)
artifacts.filter_map do |artifact|
case artifact
when Artifact::AbstractFlightBlock
# Only indicate whether this block is used as we don't load it from the API
# We can skip this entirely once we move to internal JSON v3.
{ artifact.summarize => nil } unless compact
else
{ artifact.class.dsl_key => artifact.to_args }
end
end
end

def url_specs
url&.specs.dup.tap do |url_specs|
case url_specs&.dig(:user_agent)
Expand Down
11 changes: 8 additions & 3 deletions Library/Homebrew/cask/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage
deprecate_disable = DeprecateDisable.message(cask)
output << "#{deprecate_disable.capitalize}\n" if deprecate_disable
output << installation_info(cask)
output << "#{installation_info(cask)}\n"
repo = repo_info(cask)
output << "#{repo}\n" if repo
output << name_info(cask)
Expand All @@ -37,7 +37,7 @@
end

def self.installation_info(cask)
return "Not installed\n" unless cask.installed?
return "Not installed" unless cask.installed?

versioned_staged_path = cask.caskroom_path.join(cask.installed_version)
path_details = if versioned_staged_path.exist?
Expand All @@ -46,7 +46,12 @@
Formatter.error("does not exist")
end

"Installed\n#{versioned_staged_path} (#{path_details})\n"
tab = Tab.for_cask(cask)

Check warning on line 49 in Library/Homebrew/cask/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/info.rb#L49

Added line #L49 was not covered by tests

info = ["Installed"]
info << "#{versioned_staged_path} (#{path_details})"

Check warning on line 52 in Library/Homebrew/cask/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/info.rb#L51-L52

Added lines #L51 - L52 were not covered by tests
info << " #{tab.to_cask_install_message}" if tab.tabfile&.exist?
info.join("\n")

Check warning on line 54 in Library/Homebrew/cask/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/info.rb#L54

Added line #L54 was not covered by tests
end

def self.name_info(cask)
Expand Down
20 changes: 17 additions & 3 deletions Library/Homebrew/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Installer
def initialize(cask, command: SystemCommand, force: false, adopt: false,
skip_cask_deps: false, binaries: true, verbose: false,
zap: false, require_sha: false, upgrade: false, reinstall: false,
installed_as_dependency: false, quarantine: true,
verify_download_integrity: true, quiet: false)
installed_as_dependency: false, installed_on_request: true,
quarantine: true, verify_download_integrity: true, quiet: false)
@cask = cask
@command = command
@force = force
Expand All @@ -35,13 +35,14 @@ def initialize(cask, command: SystemCommand, force: false, adopt: false,
@reinstall = reinstall
@upgrade = upgrade
@installed_as_dependency = installed_as_dependency
@installed_on_request = installed_on_request
@quarantine = quarantine
@verify_download_integrity = verify_download_integrity
@quiet = quiet
end

attr_predicate :binaries?, :force?, :adopt?, :skip_cask_deps?, :require_sha?,
:reinstall?, :upgrade?, :verbose?, :zap?, :installed_as_dependency?,
:reinstall?, :upgrade?, :verbose?, :zap?, :installed_as_dependency?, :installed_on_request?,
:quarantine?, :quiet?

def self.caveats(cask)
Expand Down Expand Up @@ -112,6 +113,11 @@ def install

install_artifacts(predecessor:)

tab = Tab.create_from_cask(@cask)
tab.installed_as_dependency = installed_as_dependency?
tab.installed_on_request = installed_on_request?
tab.write_cask_file

if (tap = @cask.tap) && tap.should_report_analytics?
::Utils::Analytics.report_package_event(:cask_install, package_name: @cask.token, tap_name: tap.name,
on_request: true)
Expand Down Expand Up @@ -356,6 +362,7 @@ def satisfy_cask_and_formula_dependencies
binaries: binaries?,
verbose: verbose?,
installed_as_dependency: true,
installed_on_request: false,
force: false,
).install
else
Expand Down Expand Up @@ -408,13 +415,20 @@ def uninstall(successor: nil)
oh1 "Uninstalling Cask #{Formatter.identifier(@cask)}"
uninstall_artifacts(clear: true, successor:)
if !reinstall? && !upgrade?
remove_tabfile
remove_download_sha
remove_config_file
end
purge_versioned_files
purge_caskroom_path if force?
end

def remove_tabfile
tabfile = @cask.tab.tabfile
FileUtils.rm_f tabfile if tabfile.present? && tabfile.exist?
@cask.config_path.parent.rmdir_if_possible
end

def remove_config_file
FileUtils.rm_f @cask.config_path
@cask.config_path.parent.rmdir_if_possible
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
puts "Installed"
kegs.each do |keg|
puts "#{keg} (#{keg.abv})#{" *" if keg.linked?}"
tab = keg.tab.to_s
tab = keg.tab.to_formula_install_message

Check warning on line 307 in Library/Homebrew/cmd/info.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/info.rb#L307

Added line #L307 was not covered by tests
puts " #{tab}" unless tab.empty?
end
end
Expand Down
56 changes: 37 additions & 19 deletions Library/Homebrew/cmd/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class TabCmd < AbstractCommand
cmd_args do
description <<~EOS
Edit tab information for installed formulae.
Edit tab information for installed formulae or casks.

This can be useful when you want to control whether an installed
formula should be removed by `brew autoremove`.
Expand All @@ -19,13 +19,18 @@
EOS

switch "--installed-on-request",
description: "Mark <formula> as installed on request."
description: "Mark <installed_formula> or <installed_cask> as installed on request."
switch "--no-installed-on-request",
description: "Mark <formula> as not installed on request."
description: "Mark <installed_formula> or <installed_cask> as not installed on request."
switch "--formula", "--formulae",
description: "Only mark formulae."
switch "--cask", "--casks",
description: "Only mark casks."

conflicts "--formula", "--cask"
conflicts "--installed-on-request", "--no-installed-on-request"

named_args :formula, min: 1
named_args [:installed_formula, :installed_cask], min: 1
end

sig { override.void }
Expand All @@ -37,38 +42,51 @@
end
raise UsageError, "No marking option specified." if installed_on_request.nil?

formulae = args.named.to_formulae
if (formulae_not_installed = formulae.reject(&:any_version_installed?)).any?
formula_names = formulae_not_installed.map(&:name)
is_or_are = (formula_names.length == 1) ? "is" : "are"
odie "#{formula_names.to_sentence} #{is_or_are} not installed."
formulae, casks = args.named.to_formulae_to_casks
formulae_not_installed = formulae.reject(&:any_version_installed?)
casks_not_installed = casks.reject(&:installed?)
if formulae_not_installed.any? || casks_not_installed.any?
names = formulae_not_installed.map(&:name) + casks_not_installed.map(&:token)
is_or_are = (names.length == 1) ? "is" : "are"
odie "#{names.to_sentence} #{is_or_are} not installed."

Check warning on line 51 in Library/Homebrew/cmd/tab.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/tab.rb#L51

Added line #L51 was not covered by tests
end

formulae.each do |formula|
update_tab formula, installed_on_request:
[*formulae, *casks].each do |formula_or_cask|
update_tab formula_or_cask, installed_on_request:
end
end

private

sig { params(formula: Formula, installed_on_request: T::Boolean).void }
def update_tab(formula, installed_on_request:)
tab = Tab.for_formula(formula)
unless tab.tabfile.exist?
sig { params(formula_or_cask: T.any(Formula, Cask::Cask), installed_on_request: T::Boolean).void }
def update_tab(formula_or_cask, installed_on_request:)
name, tab, type = if formula_or_cask.is_a?(Formula)
[formula_or_cask.name, Tab.for_formula(formula_or_cask), :formula]
else
[formula_or_cask.token, Tab.for_cask(formula_or_cask), :cask]
end

if tab.tabfile.blank? || !tab.tabfile.exist?
raise ArgumentError,
"Tab file for #{formula.name} does not exist."
"Tab file for #{name} does not exist."
end

installed_on_request_str = "#{"not " unless installed_on_request}installed on request"
if (tab.installed_on_request && installed_on_request) ||
(!tab.installed_on_request && !installed_on_request)
ohai "#{formula.name} is already marked as #{installed_on_request_str}."
ohai "#{name} is already marked as #{installed_on_request_str}."
return
end

tab.installed_on_request = installed_on_request
tab.write
ohai "#{formula.name} is now marked as #{installed_on_request_str}."

if type == :formula
tab.write_formula_file
else
tab.write_cask_file
end

ohai "#{name} is now marked as #{installed_on_request_str}."
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
tab = keg.tab
# force a `brew upgrade` from the linuxbrew-core version to the homebrew-core version (even if lower)
tab.source["versions"]["version_scheme"] = -1
tab.write
tab.write_formula_file

Check warning on line 168 in Library/Homebrew/cmd/update-report.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/update-report.rb#L168

Added line #L168 was not covered by tests
end

Settings.write "linuxbrewmigrated", true
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
raise "This bottle does not contain the file INSTALL_RECEIPT.json: #{bottle_path}" unless tab_path

tab_json = Utils::Bottles.file_from_bottle(bottle_path, tab_path)
tab = Tab.from_file_content(tab_json, tab_path)
tab = Tab.from_formula_file_content(tab_json, tab_path)

Check warning on line 462 in Library/Homebrew/dev-cmd/bottle.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bottle.rb#L462

Added line #L462 was not covered by tests

tag_spec = Formula[formula.name].bottle_specification
.tag_specification_for(bottle_tag, no_older_versions: true)
Expand Down Expand Up @@ -504,7 +504,7 @@
tab.changed_files.delete(Pathname.new(Tab::FILENAME))
tab.tabfile.unlink
else
tab.write
tab.write_formula_file
end

sbom = SBOM.create(formula, tab)
Expand Down Expand Up @@ -578,7 +578,7 @@
raise
ensure
ignore_interrupts do
original_tab&.write
original_tab&.write_formula_file
keg.replace_placeholders_with_locations changed_files unless args.skip_relocation?
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/linux/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
tab = keg.tab
# Force reinstallation upon `brew upgrade` to fix the bottle RPATH.
tab.source["versions"]["version_scheme"] = -1
tab.write
tab.write_formula_file

Check warning on line 29 in Library/Homebrew/extend/os/linux/cmd/update-report.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/cmd/update-report.rb#L29

Added line #L29 was not covered by tests
rescue TapFormulaUnavailableError
nil
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/mac/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
return unless findutils.any_version_installed?

gnubin = %W[#{findutils.opt_libexec}/gnubin #{findutils.libexec}/gnubin]
default_names = Tab.for_name("findutils").with? "default-names"
default_names = Tab.for_formula_name("findutils").with? "default-names"

Check warning on line 98 in Library/Homebrew/extend/os/mac/diagnostic.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/mac/diagnostic.rb#L98

Added line #L98 was not covered by tests
return if !default_names && !paths.intersect?(gnubin)

<<~EOS
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def install
tab = keg.tab
tab.installed_as_dependency = installed_as_dependency?
tab.installed_on_request = installed_on_request?
tab.write
tab.write_formula_file
end

build_bottle_postinstall if build_bottle?
Expand Down Expand Up @@ -826,8 +826,8 @@ def finish
tab = keg.tab
Tab.clear_cache
f_runtime_deps = formula.runtime_dependencies(read_from_tab: false)
tab.runtime_dependencies = Tab.runtime_deps_hash(formula, f_runtime_deps)
tab.write
tab.runtime_dependencies = Tab.formula_runtime_deps_hash(formula, f_runtime_deps)
tab.write_formula_file

# write/update a SBOM file (if we aren't bottling)
unless build_bottle?
Expand Down Expand Up @@ -1312,7 +1312,7 @@ def pour
tab.source["path"] = formula.specified_path.to_s
tab.source["tap_git_head"] = formula.tap&.installed? ? formula.tap&.git_head : nil
tab.tap = formula.tap
tab.write
tab.write_formula_file

keg = Keg.new(formula.prefix)
skip_linkage = formula.bottle_specification.skip_relocation?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
tab = keg.tab
unless tab.installed_on_request
tab.installed_on_request = true
tab.write
tab.write_formula_file

Check warning on line 217 in Library/Homebrew/install.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/install.rb#L217

Added line #L217 was not covered by tests
end

false
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
def fix_tabs
old_tabs.each do |tab|
tab.tap = formula.tap
tab.write
tab.write_formula_file

Check warning on line 160 in Library/Homebrew/migrator.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/migrator.rb#L160

Added line #L160 was not covered by tests
end
end

Expand Down Expand Up @@ -377,7 +377,7 @@
new_tabs = new_cellar.subdirs.map { |d| Keg.new(d).tab }
new_tabs.each do |tab|
tab.source["path"] = formula.path.to_s if tab.source["path"]
tab.write
tab.write_formula_file
end
end

Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/sorbet/rbi/parlour.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ module Cask
sig { returns(T::Boolean) }
def installed_as_dependency?; end

sig { returns(T::Boolean) }
def installed_on_request?; end

sig { returns(T::Boolean) }
def quarantine?; end

Expand Down
Loading