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 19, 2025
1 parent 6f9a4cf commit ddf1c8e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
12 changes: 4 additions & 8 deletions Library/Homebrew/cask/artifact/symlinked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 9 additions & 0 deletions Library/Homebrew/extend/on_system.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ 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:)

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)
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 ddf1c8e

Please sign in to comment.