Skip to content

Commit

Permalink
Merge pull request Homebrew#13998 from EricFromCanada/bump-cask-pr-ad…
Browse files Browse the repository at this point in the history
…ditions

bump-cask-pr: handle additional use cases
  • Loading branch information
EricFromCanada authored Oct 14, 2022
2 parents 9045132 + 504bdd2 commit f0f8475
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 43 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class DSL
:discontinued?,
:livecheck,
:livecheckable?,
:on_system_blocks_exist?,
*ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key),
*ACTIVATABLE_ARTIFACT_CLASSES.map(&:dsl_key),
*ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] },
Expand Down
91 changes: 48 additions & 43 deletions Library/Homebrew/dev-cmd/bump-cask-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def bump_cask_pr
odie "This cask's tap is not a Git repository!" unless cask.tap.git?

new_version = args.version
new_version = :latest if ["latest", ":latest"].include?(new_version)
new_version = :latest if ["latest", ":latest"].include? new_version
new_version = Cask::DSL::Version.new(new_version) if new_version.present?
new_base_url = args.url
new_hash = args.sha256
new_hash = :no_check if ["no_check", ":no_check"].include? new_hash

if new_version.nil? && new_base_url.nil? && new_hash.nil?
raise UsageError, "No --version=/--url=/--sha256= argument specified!"
raise UsageError, "No `--version=`, `--url=` or `--sha256=` argument specified!"
end

old_version = cask.version
Expand All @@ -104,6 +104,52 @@ def bump_cask_pr
/version\s+#{old_version_regex}/m,
"version #{new_version.latest? ? ":latest" : "\"#{new_version}\""}",
]
if new_version.latest? || new_hash == :no_check
opoo "Ignoring specified `--sha256=` argument." if new_hash.is_a? String
replacement_pairs << [/"#{old_hash}"/, ":no_check"] if old_hash != :no_check
elsif old_hash != :no_check
if new_hash.nil? || cask.languages.present?
if new_hash.present? && cask.languages.present?
opoo "Multiple hash replacements required; ignoring specified `--sha256=` argument."
end
tmp_contents = Utils::Inreplace.inreplace_pairs(cask.sourcefile_path,
replacement_pairs.uniq.compact,
read_only_run: true,
silent: true)

tmp_cask = Cask::CaskLoader.load(tmp_contents)
tmp_config = tmp_cask.config

[:arm, :intel].each do |arch|
Homebrew::SimulateSystem.arch = arch

languages = cask.languages
languages = [nil] if languages.empty?
languages.each do |language|
new_hash_config = if language.blank?
tmp_config
else
tmp_config.merge(Cask::Config.new(explicit: { languages: [language] }))
end

new_hash_cask = Cask::CaskLoader.load(tmp_contents)
new_hash_cask.config = new_hash_config
old_hash = new_hash_cask.sha256.to_s

cask_download = Cask::Download.new(new_hash_cask, quarantine: true)
download = cask_download.fetch(verify_download_integrity: false)
Utils::Tar.validate_file(download)

replacement_pairs << [new_hash_cask.sha256.to_s, download.sha256]
end

Homebrew::SimulateSystem.clear
end
elsif new_hash.present?
opoo "Cask contains multiple hashes; only updating hash for current arch." if cask.on_system_blocks_exist?
replacement_pairs << [old_hash.to_s, new_hash]
end
end
end

if new_base_url.present?
Expand All @@ -118,47 +164,6 @@ def bump_cask_pr
]
end

if new_version.present?
if new_version.latest?
opoo "Ignoring specified `--sha256=` argument." if new_hash.present?
replacement_pairs << [old_hash, ":no_check"]
elsif old_hash != :no_check && (new_hash.nil? || cask.languages.present?)
tmp_contents = Utils::Inreplace.inreplace_pairs(cask.sourcefile_path,
replacement_pairs.uniq.compact,
read_only_run: true,
silent: true)

tmp_cask = Cask::CaskLoader.load(tmp_contents)
tmp_config = tmp_cask.config

[:arm, :intel].each do |arch|
Homebrew::SimulateSystem.arch = arch

languages = cask.languages
languages = [nil] if languages.empty?
languages.each do |language|
new_hash_config = if language.blank?
tmp_config
else
tmp_config.merge(Cask::Config.new(explicit: { languages: [language] }))
end

new_hash_cask = Cask::CaskLoader.load(tmp_contents)
new_hash_cask.config = new_hash_config
old_hash = new_hash_cask.sha256.to_s

cask_download = Cask::Download.new(new_hash_cask, quarantine: true)
download = cask_download.fetch(verify_download_integrity: false)
Utils::Tar.validate_file(download)

replacement_pairs << [new_hash_cask.sha256.to_s, download.sha256]
end

Homebrew::SimulateSystem.clear
end
end
end

Utils::Inreplace.inreplace_pairs(cask.sourcefile_path,
replacement_pairs.uniq.compact,
read_only_run: args.dry_run?,
Expand Down

0 comments on commit f0f8475

Please sign in to comment.