Merge pull request #9531 from reitermarkus/tilde-artifact-targets
Properly handle `~` artifact targets.
This commit is contained in:
commit
d49f31cdea
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cask/artifact/moved"
|
require "cask/artifact/moved"
|
||||||
@ -19,25 +19,26 @@ module Cask
|
|||||||
"Generic Artifact"
|
"Generic Artifact"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(cask: Cask, args: T.untyped).returns(T.attached_class) }
|
||||||
def self.from_args(cask, *args)
|
def self.from_args(cask, *args)
|
||||||
source_string, target_hash = args
|
source, options = args
|
||||||
|
|
||||||
raise CaskInvalidError.new(cask.token, "no source given for #{english_name}") if source_string.nil?
|
raise CaskInvalidError.new(cask.token, "No source provided for #{english_name}.") if source.blank?
|
||||||
|
|
||||||
unless target_hash.is_a?(Hash)
|
unless options.try(:key?, :target)
|
||||||
raise CaskInvalidError.new(cask.token, "target required for #{english_name} '#{source_string}'")
|
raise CaskInvalidError.new(cask.token, "#{english_name} '#{source}' requires a target.")
|
||||||
end
|
end
|
||||||
|
|
||||||
target_hash.assert_valid_keys!(:target)
|
new(cask, source, **options)
|
||||||
|
|
||||||
new(cask, source_string, **target_hash)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(target: T.any(String, Pathname)).returns(Pathname) }
|
||||||
def resolve_target(target)
|
def resolve_target(target)
|
||||||
Pathname(target)
|
super(target, base_dir: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(cask, source, target: nil)
|
sig { params(cask: Cask, source: T.any(String, Pathname), target: T.any(String, Pathname)).void }
|
||||||
|
def initialize(cask, source, target:)
|
||||||
super(cask, source, target: target)
|
super(cask, source, target: target)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,12 +28,23 @@ module Cask
|
|||||||
new(cask, source_string, **target_hash)
|
new(cask, source_string, **target_hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def resolve_target(target)
|
def resolve_target(target, base_dir: config.public_send(self.class.dirmethod))
|
||||||
config.public_send(self.class.dirmethod).join(target)
|
target = Pathname(target)
|
||||||
|
|
||||||
|
if target.relative?
|
||||||
|
return target.expand_path if target.descend.first.to_s == "~"
|
||||||
|
return base_dir/target if base_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
target
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :source, :target
|
attr_reader :source, :target
|
||||||
|
|
||||||
|
sig do
|
||||||
|
params(cask: Cask, source: T.nilable(T.any(String, Pathname)), target: T.nilable(T.any(String, Pathname)))
|
||||||
|
.void
|
||||||
|
end
|
||||||
def initialize(cask, source, target: nil)
|
def initialize(cask, source, target: nil)
|
||||||
super(cask)
|
super(cask)
|
||||||
|
|
||||||
|
@ -5,5 +5,7 @@ module Cask
|
|||||||
def artifacts; end
|
def artifacts; end
|
||||||
|
|
||||||
def homepage; end
|
def homepage; end
|
||||||
|
|
||||||
|
def staged_path; end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,23 @@ describe Cask::Artifact::Artifact, :cask do
|
|||||||
it "fails to load" do
|
it "fails to load" do
|
||||||
expect {
|
expect {
|
||||||
Cask::CaskLoader.load(cask_path("invalid/invalid-generic-artifact-no-target"))
|
Cask::CaskLoader.load(cask_path("invalid/invalid-generic-artifact-no-target"))
|
||||||
}.to raise_error(Cask::CaskInvalidError, /target required for Generic Artifact/)
|
}.to raise_error(Cask::CaskInvalidError, /Generic Artifact.*requires.*target/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with relative target" do
|
||||||
|
it "does not fail to load" do
|
||||||
|
expect {
|
||||||
|
Cask::CaskLoader.load(cask_path("generic-artifact-relative-target"))
|
||||||
|
}.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with user-relative target" do
|
||||||
|
it "does not fail to load" do
|
||||||
|
expect {
|
||||||
|
Cask::CaskLoader.load(cask_path("generic-artifact-user-relative-target"))
|
||||||
|
}.not_to raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -756,13 +756,19 @@ describe Cask::Audit, :cask do
|
|||||||
context "with relative target" do
|
context "with relative target" do
|
||||||
let(:cask_token) { "generic-artifact-relative-target" }
|
let(:cask_token) { "generic-artifact-relative-target" }
|
||||||
|
|
||||||
it { is_expected.to fail_with(/target must be absolute path for Generic Artifact/) }
|
it { is_expected.to fail_with(/target must be.*absolute/) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with user-relative target" do
|
||||||
|
let(:cask_token) { "generic-artifact-user-relative-target" }
|
||||||
|
|
||||||
|
it { is_expected.not_to fail_with(/target must be.*absolute/) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with absolute target" do
|
context "with absolute target" do
|
||||||
let(:cask_token) { "generic-artifact-absolute-target" }
|
let(:cask_token) { "generic-artifact-absolute-target" }
|
||||||
|
|
||||||
it { is_expected.not_to fail_with(/target required for Generic Artifact/) }
|
it { is_expected.not_to fail_with(/target must be.*absolute/) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
cask "generic-artifact-user-relative-target" do
|
||||||
|
version "1.2.3"
|
||||||
|
sha256 "d5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2"
|
||||||
|
|
||||||
|
url "file://#{TEST_FIXTURE_DIR}/cask/AppWithBinary.zip"
|
||||||
|
name "With Binary"
|
||||||
|
desc "Cask with a binary stanza"
|
||||||
|
homepage "https://brew.sh/with-binary"
|
||||||
|
|
||||||
|
artifact "Caffeine.app", target: "~/Desktop/Caffeine.app"
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user