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

cask: read bundle version from Info.plist when sensible. #16826

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: true

require "attrable"
require "bundle_version"
require "cask/cask_loader"
require "cask/config"
require "cask/dsl"
Expand Down Expand Up @@ -176,8 +177,20 @@

sig { returns(T.nilable(String)) }
def installed_version
return unless (installed_caskfile = self.installed_caskfile)

# <caskroom_path>/.metadata/<version>/<timestamp>/Casks/<token>.{rb,json} -> <version>
installed_caskfile&.dirname&.dirname&.dirname&.basename&.to_s
installed_caskfile.dirname.dirname.dirname.basename.to_s

Check warning on line 183 in Library/Homebrew/cask/cask.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/cask.rb#L183

Added line #L183 was not covered by tests
end

sig { returns(T.nilable(String)) }
def bundle_short_version
bundle_version&.short_version
end

sig { returns(T.nilable(String)) }
def bundle_long_version
bundle_version&.version
end

def config_path
Expand Down Expand Up @@ -326,6 +339,8 @@
"version" => version,
"installed" => installed_version,
"installed_time" => install_time&.to_i,
"bundle_version" => bundle_long_version,
"bundle_short_version" => bundle_short_version,
"outdated" => outdated?,
"sha256" => sha256,
"artifacts" => artifacts_list,
Expand Down Expand Up @@ -386,6 +401,14 @@

private

sig { returns(T.nilable(Homebrew::BundleVersion)) }
def bundle_version
@bundle_version ||= if (bundle = artifacts.find { |a| a.is_a?(Artifact::App) }&.target) &&
(plist = Pathname("#{bundle}/Contents/Info.plist")) && plist.exist?

Check warning on line 407 in Library/Homebrew/cask/cask.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/cask.rb#L407

Added line #L407 was not covered by tests
Homebrew::BundleVersion.from_info_plist(plist)
end
end

def api_to_local_hash(hash)
hash["token"] = token
hash["installed"] = installed_version
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/support/fixtures/cask/everything.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"version": "1.2.3",
"installed": null,
"installed_time": null,
"bundle_version": null,
"bundle_short_version": null,
"outdated": false,
"sha256": "c64c05bdc0be845505d6e55e69e696a7f50d40846e76155f0c85d5ff5e7bbb84",
"artifacts": [
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def numeric?
def null?
false
end

sig { returns(T::Boolean) }
def blank? = null?
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved
end

# A pseudo-token representing the absence of a token.
Expand Down Expand Up @@ -127,6 +130,9 @@ def null?
true
end

sig { returns(T::Boolean) }
def blank? = true

sig { override.returns(String) }
def inspect
"#<#{self.class.name}>"
Expand Down