feat: allow cask binaries on linux

This commit is contained in:
Sean Molenaar 2025-01-19 16:15:19 +00:00 committed by Sean Molenaar
parent 6de67b6c45
commit 975fe8a83f
7 changed files with 96 additions and 13 deletions

View File

@ -62,7 +62,7 @@ module Cask
end end
ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'" ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'"
create_filesystem_link(command:) create_filesystem_link(command)
end end
def unlink(command: nil, **) def unlink(command: nil, **)
@ -72,14 +72,10 @@ module Cask
Utils.gain_permissions_remove(target, command:) Utils.gain_permissions_remove(target, command:)
end end
def create_filesystem_link(command: nil) sig { params(command: T.class_of(SystemCommand)).void }
Utils.gain_permissions_mkpath(target.dirname, command:) def create_filesystem_link(command); end
command.run! "/bin/ln", args: ["-h", "-f", "-s", "--", source, target],
sudo: !target.dirname.writable?
add_altname_metadata(source, target.basename, command:)
end
end end
end end
end end
require "extend/os/cask/artifact/symlinked"

View File

@ -312,16 +312,17 @@ module Cask
# ```ruby # ```ruby
# sha256 arm: "7bdb497080ffafdfd8cc94d8c62b004af1be9599e865e5555e456e2681e150ca", # sha256 arm: "7bdb497080ffafdfd8cc94d8c62b004af1be9599e865e5555e456e2681e150ca",
# intel: "b3c1c2442480a0219b9e05cf91d03385858c20f04b764ec08a3fa83d1b27e7b2" # intel: "b3c1c2442480a0219b9e05cf91d03385858c20f04b764ec08a3fa83d1b27e7b2"
# linux: "1a2aee7f1ddc999993d4d7d42a150c5e602bc17281678050b8ed79a0500cc90f"
# ``` # ```
# #
# @api public # @api public
def sha256(arg = nil, arm: nil, intel: nil) def sha256(arg = nil, arm: nil, intel: nil, linux: nil)
should_return = arg.nil? && arm.nil? && intel.nil? should_return = arg.nil? && arm.nil? && intel.nil?
set_unique_stanza(:sha256, should_return) do set_unique_stanza(:sha256, should_return) do
@on_system_blocks_exist = true if arm.present? || intel.present? @on_system_blocks_exist = true if arm.present? || intel.present? || linux.present?
val = arg || on_arch_conditional(arm:, intel:) val = arg || on_system_conditional(macos: on_arch_conditional(arm:, intel:), linux:)
case val case val
when :no_check when :no_check
val val
@ -352,6 +353,25 @@ module Cask
end end
end end
# Sets the cask's os strings.
#
# ### Example
#
# ```ruby
# os macos: "darwin", linux: "tux"
# ```
#
# @api public
def os(macos: nil, linux: nil)
should_return = macos.nil? && linux.nil?
set_unique_stanza(:os, should_return) do
@on_system_blocks_exist = true
on_system_conditional(macos:, linux:)
end
end
# Declare dependencies and requirements for a cask. # Declare dependencies and requirements for a cask.
# #
# NOTE: Multiple dependencies can be specified. # NOTE: Multiple dependencies can be specified.

View File

@ -20,4 +20,7 @@ module OnSystem::MacOSAndLinux
.returns(T.type_parameter(:U)) .returns(T.type_parameter(:U))
} }
def on_macos(&block); end def on_macos(&block); end
sig { params(arm: T.nilable(String), intel: T.nilable(String)).returns(T.nilable(String)) }
def on_arch_conditional(arm: nil, intel: nil); end
end end

View File

@ -0,0 +1,5 @@
# typed: strict
# frozen_string_literal: true
require "extend/os/mac/cask/artifact/symlinked" if OS.mac?
require "extend/os/linux/cask/artifact/symlinked" if OS.linux?

View File

@ -0,0 +1,26 @@
# typed: strict
# frozen_string_literal: true
module OS
module Linux
module Cask
module Artifact
module Symlinked
extend T::Helpers
requires_ancestor { ::Cask::Artifact::Symlinked }
sig { params(command: T.class_of(SystemCommand)).void }
def create_filesystem_link(command)
::Cask::Utils.gain_permissions_mkpath(target.dirname, command:)
command.run! "/bin/ln", args: ["--no-dereference", "--force", "--symbolic", source, target],
sudo: !target.dirname.writable?
end
end
end
end
end
end
Cask::Artifact::Symlinked.prepend(OS::Linux::Cask::Artifact::Symlinked)

View File

@ -15,6 +15,9 @@ module OS
def check_stanza_os_requirements def check_stanza_os_requirements
return if artifacts.all?(::Cask::Artifact::Font) return if artifacts.all?(::Cask::Artifact::Font)
install_artifacts = artifacts.reject { |artifact| artifact.instance_of?(::Cask::Artifact::Zap) }
return if install_artifacts.all?(::Cask::Artifact::Binary)
raise ::Cask::CaskError, "macOS is required for this software." raise ::Cask::CaskError, "macOS is required for this software."
end end
end end

View File

@ -0,0 +1,30 @@
# typed: strict
# frozen_string_literal: true
require "cask/macos"
module OS
module Mac
module Cask
module Artifact
module Symlinked
extend T::Helpers
requires_ancestor { ::Cask::Artifact::Symlinked }
sig { params(command: T.class_of(SystemCommand)).void }
def create_filesystem_link(command)
::Cask::Utils.gain_permissions_mkpath(target.dirname, command:)
command.run! "/bin/ln", args: ["-h", "-f", "-s", "--", source, target],
sudo: !target.dirname.writable?
add_altname_metadata(source, target.basename, command:)
end
end
end
end
end
end
Cask::Artifact::Symlinked.prepend(OS::Mac::Cask::Artifact::Symlinked)