Preliminary compatibility fixes for Ruby 3
This commit is contained in:
parent
f30f68be7d
commit
9b99594753
@ -11,8 +11,10 @@ module Cask
|
|||||||
class StageOnly < AbstractArtifact
|
class StageOnly < AbstractArtifact
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
def self.from_args(cask, *args)
|
def self.from_args(cask, *args, **kwargs)
|
||||||
raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") if args != [true]
|
if args != [true] || kwargs.present?
|
||||||
|
raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true")
|
||||||
|
end
|
||||||
|
|
||||||
new(cask, true)
|
new(cask, true)
|
||||||
end
|
end
|
||||||
|
22
Library/Homebrew/cask/artifact_set.rb
Normal file
22
Library/Homebrew/cask/artifact_set.rb
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "set"
|
||||||
|
|
||||||
|
module Cask
|
||||||
|
# Sorted set containing all cask artifacts.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
|
class ArtifactSet < ::Set
|
||||||
|
def each(&block)
|
||||||
|
return enum_for(__method__) { size } unless block
|
||||||
|
|
||||||
|
to_a.each(&block)
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_a
|
||||||
|
super.sort
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -33,8 +33,9 @@ module Cask
|
|||||||
Cmd.parser do
|
Cmd.parser do
|
||||||
instance_eval(&block) if block
|
instance_eval(&block) if block
|
||||||
|
|
||||||
OPTIONS.each do |option|
|
OPTIONS.map(&:dup).each do |option|
|
||||||
send(*option)
|
kwargs = option.pop
|
||||||
|
send(*option, **kwargs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,8 +24,9 @@ module Cask
|
|||||||
switch "--force",
|
switch "--force",
|
||||||
description: "Force overwriting existing files."
|
description: "Force overwriting existing files."
|
||||||
|
|
||||||
OPTIONS.each do |option|
|
OPTIONS.map(&:dup).each do |option|
|
||||||
send(*option)
|
kwargs = option.pop
|
||||||
|
send(*option, **kwargs)
|
||||||
end
|
end
|
||||||
|
|
||||||
instance_eval(&block) if block
|
instance_eval(&block) if block
|
||||||
|
@ -6,6 +6,7 @@ require "lazy_object"
|
|||||||
require "livecheck"
|
require "livecheck"
|
||||||
|
|
||||||
require "cask/artifact"
|
require "cask/artifact"
|
||||||
|
require "cask/artifact_set"
|
||||||
|
|
||||||
require "cask/caskroom"
|
require "cask/caskroom"
|
||||||
require "cask/exceptions"
|
require "cask/exceptions"
|
||||||
@ -207,14 +208,14 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @api public
|
# @api public
|
||||||
def appcast(*args)
|
def appcast(*args, **kwargs)
|
||||||
set_unique_stanza(:appcast, args.empty?) { DSL::Appcast.new(*args) }
|
set_unique_stanza(:appcast, args.empty? && kwargs.empty?) { DSL::Appcast.new(*args, **kwargs) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# @api public
|
# @api public
|
||||||
def container(*args)
|
def container(**kwargs)
|
||||||
set_unique_stanza(:container, args.empty?) do
|
set_unique_stanza(:container, kwargs.empty?) do
|
||||||
DSL::Container.new(*args)
|
DSL::Container.new(**kwargs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -261,12 +262,12 @@ module Cask
|
|||||||
|
|
||||||
# `depends_on` uses a load method so that multiple stanzas can be merged.
|
# `depends_on` uses a load method so that multiple stanzas can be merged.
|
||||||
# @api public
|
# @api public
|
||||||
def depends_on(*args)
|
def depends_on(**kwargs)
|
||||||
@depends_on ||= DSL::DependsOn.new
|
@depends_on ||= DSL::DependsOn.new
|
||||||
return @depends_on if args.empty?
|
return @depends_on if kwargs.empty?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@depends_on.load(*args)
|
@depends_on.load(**kwargs)
|
||||||
rescue RuntimeError => e
|
rescue RuntimeError => e
|
||||||
raise CaskInvalidError.new(cask, e)
|
raise CaskInvalidError.new(cask, e)
|
||||||
end
|
end
|
||||||
@ -274,13 +275,13 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @api public
|
# @api public
|
||||||
def conflicts_with(*args)
|
def conflicts_with(**kwargs)
|
||||||
# TODO: remove this constraint, and instead merge multiple conflicts_with stanzas
|
# TODO: remove this constraint, and instead merge multiple conflicts_with stanzas
|
||||||
set_unique_stanza(:conflicts_with, args.empty?) { DSL::ConflictsWith.new(*args) }
|
set_unique_stanza(:conflicts_with, kwargs.empty?) { DSL::ConflictsWith.new(**kwargs) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def artifacts
|
def artifacts
|
||||||
@artifacts ||= SortedSet.new
|
@artifacts ||= ArtifactSet.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def caskroom_path
|
def caskroom_path
|
||||||
@ -337,13 +338,13 @@ module Cask
|
|||||||
end
|
end
|
||||||
|
|
||||||
ORDINARY_ARTIFACT_CLASSES.each do |klass|
|
ORDINARY_ARTIFACT_CLASSES.each do |klass|
|
||||||
define_method(klass.dsl_key) do |*args|
|
define_method(klass.dsl_key) do |*args, **kwargs|
|
||||||
if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) &&
|
if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) &&
|
||||||
(artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any?
|
(artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any?
|
||||||
raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.")
|
raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.")
|
||||||
end
|
end
|
||||||
|
|
||||||
artifacts.add(klass.from_args(cask, *args))
|
artifacts.add(klass.from_args(cask, *args, **kwargs))
|
||||||
rescue CaskInvalidError
|
rescue CaskInvalidError
|
||||||
raise
|
raise
|
||||||
rescue => e
|
rescue => e
|
||||||
|
@ -16,7 +16,7 @@ module Cask
|
|||||||
|
|
||||||
attr_accessor(*VALID_KEYS, :pairs)
|
attr_accessor(*VALID_KEYS, :pairs)
|
||||||
|
|
||||||
def initialize(pairs = {})
|
def initialize(**pairs)
|
||||||
@pairs = pairs
|
@pairs = pairs
|
||||||
pairs.each do |key, value|
|
pairs.each do |key, value|
|
||||||
raise "invalid container key: #{key.inspect}" unless VALID_KEYS.include?(key)
|
raise "invalid container key: #{key.inspect}" unless VALID_KEYS.include?(key)
|
||||||
|
@ -156,6 +156,12 @@ module Cask
|
|||||||
version { gsub(DIVIDER_REGEX, "") }
|
version { gsub(DIVIDER_REGEX, "") }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @api public
|
||||||
|
sig { params(separator: T.nilable(String)).returns(T.self_type) }
|
||||||
|
def chomp(separator = nil)
|
||||||
|
version { to_s.chomp(T.unsafe(separator)) }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
sig { returns(T.self_type) }
|
sig { returns(T.self_type) }
|
||||||
|
@ -367,8 +367,9 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cask_options
|
def cask_options
|
||||||
self.class.global_cask_options.each do |method, *args, **options|
|
self.class.global_cask_options.each do |args|
|
||||||
send(method, *args, **options)
|
options = args.pop
|
||||||
|
send(*args, **options)
|
||||||
conflicts "--formula", args.last
|
conflicts "--formula", args.last
|
||||||
end
|
end
|
||||||
@cask_options = true
|
@cask_options = true
|
||||||
|
@ -121,16 +121,18 @@ module Homebrew
|
|||||||
[:switch, "--overwrite", {
|
[:switch, "--overwrite", {
|
||||||
description: "Delete files that already exist in the prefix while linking.",
|
description: "Delete files that already exist in the prefix while linking.",
|
||||||
}],
|
}],
|
||||||
].each do |*args, **options|
|
].each do |args|
|
||||||
|
options = args.pop
|
||||||
send(*args, **options)
|
send(*args, **options)
|
||||||
conflicts "--cask", args.last
|
conflicts "--cask", args.last
|
||||||
end
|
end
|
||||||
formula_options
|
formula_options
|
||||||
[
|
[
|
||||||
[:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }],
|
[:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }],
|
||||||
*Cask::Cmd::AbstractCommand::OPTIONS,
|
*Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup),
|
||||||
*Cask::Cmd::Install::OPTIONS,
|
*Cask::Cmd::Install::OPTIONS.map(&:dup),
|
||||||
].each do |*args, **options|
|
].each do |args|
|
||||||
|
options = args.pop
|
||||||
send(*args, **options)
|
send(*args, **options)
|
||||||
conflicts "--formula", args.last
|
conflicts "--formula", args.last
|
||||||
end
|
end
|
||||||
|
@ -68,18 +68,20 @@ module Homebrew
|
|||||||
[:switch, "-g", "--git", {
|
[:switch, "-g", "--git", {
|
||||||
description: "Create a Git repository, useful for creating patches to the software.",
|
description: "Create a Git repository, useful for creating patches to the software.",
|
||||||
}],
|
}],
|
||||||
].each do |options|
|
].each do |args|
|
||||||
send(*options)
|
options = args.pop
|
||||||
conflicts "--cask", options[-2]
|
send(*args, **options)
|
||||||
|
conflicts "--cask", args.last
|
||||||
end
|
end
|
||||||
formula_options
|
formula_options
|
||||||
[
|
[
|
||||||
[:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }],
|
[:switch, "--cask", "--casks", { description: "Treat all named arguments as casks." }],
|
||||||
*Cask::Cmd::AbstractCommand::OPTIONS,
|
*Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup),
|
||||||
*Cask::Cmd::Install::OPTIONS,
|
*Cask::Cmd::Install::OPTIONS.map(&:dup),
|
||||||
].each do |options|
|
].each do |args|
|
||||||
send(*options)
|
options = args.pop
|
||||||
conflicts "--formula", options[-2]
|
send(*args, **options)
|
||||||
|
conflicts "--formula", args.last
|
||||||
end
|
end
|
||||||
cask_options
|
cask_options
|
||||||
|
|
||||||
|
@ -76,9 +76,10 @@ module Homebrew
|
|||||||
env: :display_install_times,
|
env: :display_install_times,
|
||||||
description: "Print install times for each package at the end of the run.",
|
description: "Print install times for each package at the end of the run.",
|
||||||
}],
|
}],
|
||||||
].each do |options|
|
].each do |args|
|
||||||
send(*options)
|
options = args.pop
|
||||||
conflicts "--cask", options[-2]
|
send(*args, **options)
|
||||||
|
conflicts "--cask", args.last
|
||||||
end
|
end
|
||||||
formula_options
|
formula_options
|
||||||
[
|
[
|
||||||
@ -86,11 +87,12 @@ module Homebrew
|
|||||||
description: "Treat all named arguments as casks. If no named arguments " \
|
description: "Treat all named arguments as casks. If no named arguments " \
|
||||||
"are specified, upgrade only outdated casks.",
|
"are specified, upgrade only outdated casks.",
|
||||||
}],
|
}],
|
||||||
*Cask::Cmd::AbstractCommand::OPTIONS,
|
*Cask::Cmd::AbstractCommand::OPTIONS.map(&:dup),
|
||||||
*Cask::Cmd::Upgrade::OPTIONS,
|
*Cask::Cmd::Upgrade::OPTIONS.map(&:dup),
|
||||||
].each do |options|
|
].each do |args|
|
||||||
send(*options)
|
options = args.pop
|
||||||
conflicts "--formula", options[-2]
|
send(*args, **options)
|
||||||
|
conflicts "--formula", args.last
|
||||||
end
|
end
|
||||||
cask_options
|
cask_options
|
||||||
|
|
||||||
|
@ -594,7 +594,7 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy
|
|||||||
# GitHub Packages authorization header.
|
# GitHub Packages authorization header.
|
||||||
# HOMEBREW_GITHUB_PACKAGES_AUTH set in brew.sh
|
# HOMEBREW_GITHUB_PACKAGES_AUTH set in brew.sh
|
||||||
meta[:headers] << "Authorization: #{HOMEBREW_GITHUB_PACKAGES_AUTH}"
|
meta[:headers] << "Authorization: #{HOMEBREW_GITHUB_PACKAGES_AUTH}"
|
||||||
super(url, name, version, meta)
|
super(url, name, version, **meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -107,7 +107,7 @@ class SoftwareSpec
|
|||||||
def url(val = nil, specs = {})
|
def url(val = nil, specs = {})
|
||||||
return @resource.url if val.nil?
|
return @resource.url if val.nil?
|
||||||
|
|
||||||
@resource.url(val, specs)
|
@resource.url(val, **specs)
|
||||||
dependency_collector.add(@resource)
|
dependency_collector.add(@resource)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -467,10 +467,11 @@ class Bottle
|
|||||||
|
|
||||||
image_name = GitHubPackages.image_formula_name(@name)
|
image_name = GitHubPackages.image_formula_name(@name)
|
||||||
image_tag = GitHubPackages.image_version_rebuild(version_rebuild)
|
image_tag = GitHubPackages.image_version_rebuild(version_rebuild)
|
||||||
resource.url("#{root_url}/#{image_name}/manifests/#{image_tag}", {
|
resource.url(
|
||||||
|
"#{root_url}/#{image_name}/manifests/#{image_tag}",
|
||||||
using: CurlGitHubPackagesDownloadStrategy,
|
using: CurlGitHubPackagesDownloadStrategy,
|
||||||
headers: ["Accept: application/vnd.oci.image.index.v1+json"],
|
headers: ["Accept: application/vnd.oci.image.index.v1+json"],
|
||||||
})
|
)
|
||||||
resource.downloader.resolved_basename = "#{name}-#{version_rebuild}.bottle_manifest.json"
|
resource.downloader.resolved_basename = "#{name}-#{version_rebuild}.bottle_manifest.json"
|
||||||
resource
|
resource
|
||||||
end
|
end
|
||||||
@ -501,7 +502,7 @@ class Bottle
|
|||||||
|
|
||||||
filename = Filename.create(resource.owner, @tag, @spec.rebuild)
|
filename = Filename.create(resource.owner, @tag, @spec.rebuild)
|
||||||
path, resolved_basename = Utils::Bottles.path_resolved_basename(val, name, resource.checksum, filename)
|
path, resolved_basename = Utils::Bottles.path_resolved_basename(val, name, resource.checksum, filename)
|
||||||
@resource.url("#{val}/#{path}", select_download_strategy(specs))
|
@resource.url("#{val}/#{path}", **select_download_strategy(specs))
|
||||||
@resource.downloader.resolved_basename = resolved_basename if resolved_basename.present?
|
@resource.downloader.resolved_basename = resolved_basename if resolved_basename.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,12 +24,12 @@ class SystemCommand
|
|||||||
module Mixin
|
module Mixin
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
def system_command(*args)
|
def system_command(executable, **options)
|
||||||
T.unsafe(SystemCommand).run(*args)
|
SystemCommand.run(executable, **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def system_command!(*args)
|
def system_command!(command, **options)
|
||||||
T.unsafe(SystemCommand).run!(*args)
|
SystemCommand.run!(command, **options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,11 +37,11 @@ class SystemCommand
|
|||||||
extend Predicable
|
extend Predicable
|
||||||
|
|
||||||
def self.run(executable, **options)
|
def self.run(executable, **options)
|
||||||
T.unsafe(self).new(executable, **options).run!
|
new(executable, **options).run!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run!(command, **options)
|
def self.run!(command, **options)
|
||||||
T.unsafe(self).run(command, **options, must_succeed: true)
|
run(command, **options, must_succeed: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(SystemCommand::Result) }
|
sig { returns(SystemCommand::Result) }
|
||||||
|
@ -10,7 +10,7 @@ describe User do
|
|||||||
|
|
||||||
describe "#gui?" do
|
describe "#gui?" do
|
||||||
before do
|
before do
|
||||||
allow(SystemCommand).to receive(:run).with("who")
|
allow(SystemCommand).to receive(:run).with("who", {})
|
||||||
.and_return([who_output, "", instance_double(Process::Status, success?: true)])
|
.and_return([who_output, "", instance_double(Process::Status, success?: true)])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -119,6 +119,10 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def install_bundler!
|
def install_bundler!
|
||||||
|
if Gem.ruby_version >= Gem::Version.new("2.7")
|
||||||
|
raise "Installing and using Bundler is currently only supported on Ruby 2.6."
|
||||||
|
end
|
||||||
|
|
||||||
setup_gem_environment!(gem_home: gem_user_dir, gem_bindir: gem_user_bindir)
|
setup_gem_environment!(gem_home: gem_user_dir, gem_bindir: gem_user_bindir)
|
||||||
install_gem_setup_path!(
|
install_gem_setup_path!(
|
||||||
"bundler",
|
"bundler",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user