Skip to content

Commit

Permalink
feat: allow cask binaries on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Jan 28, 2025
1 parent dee907d commit 29e28d1
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 13 deletions.
14 changes: 5 additions & 9 deletions Library/Homebrew/cask/artifact/symlinked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def link(force: false, adopt: false, command: nil, **_options)
end

ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'"
create_filesystem_link(command:)
create_filesystem_link(command)
end

def unlink(command: nil, **)
Expand All @@ -72,14 +72,10 @@ def unlink(command: nil, **)
Utils.gain_permissions_remove(target, command:)
end

def create_filesystem_link(command: nil)
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
sig { params(command: T.class_of(SystemCommand)).void }
def create_filesystem_link(command); end
end
end
end

require "extend/os/cask/artifact/symlinked"
28 changes: 24 additions & 4 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,18 @@ def version(arg = nil)
#
# ```ruby
# sha256 arm: "7bdb497080ffafdfd8cc94d8c62b004af1be9599e865e5555e456e2681e150ca",
# intel: "b3c1c2442480a0219b9e05cf91d03385858c20f04b764ec08a3fa83d1b27e7b2"
# intel: "b3c1c2442480a0219b9e05cf91d03385858c20f04b764ec08a3fa83d1b27e7b2"
# linux: "1a2aee7f1ddc999993d4d7d42a150c5e602bc17281678050b8ed79a0500cc90f"
# ```
#
# @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?

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
when :no_check
val
Expand Down Expand Up @@ -352,6 +353,25 @@ def arch(arm: nil, intel: nil)
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?

Check warning on line 366 in Library/Homebrew/cask/dsl.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/dsl.rb#L366

Added line #L366 was not covered by tests

set_unique_stanza(:os, should_return) do
@on_system_blocks_exist = true

Check warning on line 369 in Library/Homebrew/cask/dsl.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/dsl.rb#L368-L369

Added lines #L368 - L369 were not covered by tests

on_system_conditional(macos:, linux:)

Check warning on line 371 in Library/Homebrew/cask/dsl.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/dsl.rb#L371

Added line #L371 was not covered by tests
end
end

# Declare dependencies and requirements for a cask.
#
# NOTE: Multiple dependencies can be specified.
Expand Down
8 changes: 8 additions & 0 deletions Library/Homebrew/extend/on_system.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ module OnSystem::MacOSOnly
sig { params(arm: T.nilable(String), intel: T.nilable(String)).returns(T.nilable(String)) }
def on_arch_conditional(arm: nil, intel: nil); end
end

module OnSystem::MacOSAndLinux
sig { params(macos: T.nilable(String), linux: T.nilable(String)).returns(T.nilable(String)) }
def on_system_conditional(macos: nil, linux: nil); 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
5 changes: 5 additions & 0 deletions Library/Homebrew/extend/os/cask/artifact/symlinked.rb
Original file line number Diff line number Diff line change
@@ -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?
26 changes: 26 additions & 0 deletions Library/Homebrew/extend/os/linux/cask/artifact/symlinked.rb
Original file line number Diff line number Diff line change
@@ -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:)

Check warning on line 15 in Library/Homebrew/extend/os/linux/cask/artifact/symlinked.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/cask/artifact/symlinked.rb#L15

Added line #L15 was not covered by tests

command.run! "/bin/ln", args: ["--no-dereference", "--force", "--symbolic", source, target],
sudo: !target.dirname.writable?

Check warning on line 18 in Library/Homebrew/extend/os/linux/cask/artifact/symlinked.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/cask/artifact/symlinked.rb#L17-L18

Added lines #L17 - L18 were not covered by tests
end
end
end
end
end
end

Cask::Artifact::Symlinked.prepend(OS::Linux::Cask::Artifact::Symlinked)
3 changes: 3 additions & 0 deletions Library/Homebrew/extend/os/linux/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module Installer
def check_stanza_os_requirements
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."
end
end
Expand Down
30 changes: 30 additions & 0 deletions Library/Homebrew/extend/os/mac/cask/artifact/symlinked.rb
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 29e28d1

Please sign in to comment.