Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow linux binaries in casks #19121

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Library/Homebrew/cask/artifact/abstract_uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def each_resolved_path(action, paths)
next
end

if MacOS.undeletable?(resolved_path)
if undeletable?(resolved_path)
opoo "Skipping #{Formatter.identifier(action)} for undeletable path '#{path}'."
next
end
Expand Down Expand Up @@ -538,6 +538,10 @@ def uninstall_rmdir(*directories, **kwargs)
recursive_rmdir(*resolved_paths, **kwargs)
end
end

def undeletable?(target); end
end
end
end

require "extend/os/cask/artifact/abstract_uninstall"
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"
32 changes: 26 additions & 6 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
]).freeze

extend Attrable
include OnSystem::MacOSOnly
include OnSystem::MacOSAndLinux
SMillerDev marked this conversation as resolved.
Show resolved Hide resolved

attr_reader :cask, :token, :deprecation_date, :deprecation_reason, :deprecation_replacement, :disable_date,
:disable_reason, :disable_replacement, :on_system_block_min_os
Expand Down Expand Up @@ -311,17 +311,18 @@
#
# ```ruby
# sha256 arm: "7bdb497080ffafdfd8cc94d8c62b004af1be9599e865e5555e456e2681e150ca",
# intel: "b3c1c2442480a0219b9e05cf91d03385858c20f04b764ec08a3fa83d1b27e7b2"
# intel: "b3c1c2442480a0219b9e05cf91d03385858c20f04b764ec08a3fa83d1b27e7b2"
# linux: "1a2aee7f1ddc999993d4d7d42a150c5e602bc17281678050b8ed79a0500cc90f"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this imply linux x86_64? Given linux arm will be coming in the near future: what do you invisage doing there? linux_intel or something may make more sense

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this, but it feels weird:

sha256 macos:
         arm: "abc"
       intel: "def"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel like having some Linux-specific makes more sense until the majority of casks support Linux

# ```
#
# @api public
def sha256(arg = nil, arm: nil, intel: nil)
should_return = arg.nil? && arm.nil? && intel.nil?
def sha256(arg = nil, arm: nil, intel: nil, linux: nil)
should_return = arg.nil? && arm.nil? && intel.nil? && linux.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 @@
end
end

# Sets the cask's os strings.
#
# ### Example
#
# ```ruby
# os macos: "darwin", linux: "tux"
# ```
#
# @api public
def os(macos: nil, linux: nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to use a linux: nil state here to infer "this cask does not support Linux", at least in certain cases, rather than needing thousands of depends_on :macos CC @p-linnane for thoughts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that if you use an on_linux block this assumption breaks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SMillerDev could be if neither of those are used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll need @Rylan12 to help me with that one. Will probably be somewhere during FOSDEM.

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
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/abstract_uninstall" if OS.mac?
require "extend/os/linux/cask/artifact/abstract_uninstall" if OS.linux?
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?
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# typed: strict
# frozen_string_literal: true

module OS
module Linux
module Cask
module Artifact
module AbstractUninstall
extend T::Helpers

requires_ancestor { ::Cask::Artifact::AbstractUninstall }

sig { params(target: Pathname).returns(T::Boolean) }
def undeletable?(target)
!target.parent.writable?

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L15 was not covered by tests
end
end
end
end
end
end

Cask::Artifact::AbstractUninstall.prepend(OS::Linux::Cask::Artifact::AbstractUninstall)
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/linux/cask/artifact/moved.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def undeletable?(target)
end
end

Cask::Artifact::Moved.prepend(OS::Linux::Cask::Config)
Cask::Artifact::Moved.prepend(OS::Linux::Cask::Artifact::Moved)
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
25 changes: 25 additions & 0 deletions Library/Homebrew/extend/os/mac/cask/artifact/abstract_uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# typed: strict
# frozen_string_literal: true

require "cask/macos"

module OS
module Mac
module Cask
module Artifact
module AbstractUninstall
extend T::Helpers

requires_ancestor { ::Cask::Artifact::AbstractUninstall }

sig { params(target: Pathname).returns(T::Boolean) }
def undeletable?(target)
MacOS.undeletable?(target)
end
end
end
end
end
end

Cask::Artifact::AbstractUninstall.prepend(OS::Mac::Cask::Artifact::AbstractUninstall)
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)
Loading