Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 31b6d41

Browse files
SMillerDevdduugg
andcommittedJan 19, 2025··
feat: allow font install on linux
Apply suggestions from code review Co-authored-by: Douglas Eichelberger <[email protected]> feat: add linux appdir Apply suggestions from code review Co-authored-by: Douglas Eichelberger <[email protected]>
1 parent 4d3fedf commit 31b6d41

File tree

15 files changed

+160
-7
lines changed

15 files changed

+160
-7
lines changed
 

‎Library/Homebrew/cask/artifact/moved.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def move_back(skip: false, force: false, adopt: false, command: nil, **options)
180180

181181
def delete(target, force: false, successor: nil, command: nil, **_)
182182
ohai "Removing #{self.class.english_name} '#{target}'"
183-
raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if MacOS.undeletable?(target)
183+
raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if undeletable?(target)
184184

185185
return unless Utils.path_occupied?(target)
186186

@@ -196,6 +196,10 @@ def delete(target, force: false, successor: nil, command: nil, **_)
196196
Utils.gain_permissions_remove(target, command:)
197197
end
198198
end
199+
200+
def undeletable?(target); end
199201
end
200202
end
201203
end
204+
205+
require "extend/os/cask/artifact/moved"

‎Library/Homebrew/cask/config.rb

+11-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class Config
3333
T::Hash[Symbol, String],
3434
)
3535

36-
sig { returns(T::Hash[Symbol, T.untyped]) }
36+
sig { returns(T::Hash[Symbol, String]) }
3737
def self.defaults
3838
{
39-
languages: LazyObject.new { MacOS.languages },
39+
languages: LazyObject.new { ::OS::Mac.languages },
4040
}.merge(DEFAULT_DIRS).freeze
4141
end
4242

@@ -221,5 +221,14 @@ def to_json(*options)
221221
explicit:,
222222
}.to_json(*options)
223223
end
224+
225+
private
226+
227+
sig { params(dir: Symbol).returns(T.any(String, Pathname)) }
228+
def get_dir_path(dir)
229+
T.cast(explicit.fetch(dir, env.fetch(dir, default.fetch(dir))), T.any(String, Pathname))
230+
end
224231
end
225232
end
233+
234+
require "extend/os/cask/config"

‎Library/Homebrew/cask/installer.rb

+13-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def fetch(quiet: nil, timeout: nil)
7676
satisfy_cask_and_formula_dependencies
7777
end
7878

79+
sig { void }
7980
def stage
8081
odebug "Cask::Installer#stage"
8182

@@ -88,6 +89,7 @@ def stage
8889
raise e
8990
end
9091

92+
sig { void }
9193
def install
9294
start_time = Time.now
9395
odebug "Cask::Installer#install"
@@ -152,6 +154,7 @@ def check_deprecate_disable
152154
end
153155
end
154156

157+
sig { void }
155158
def check_conflicts
156159
return unless @cask.conflicts_with
157160

@@ -168,6 +171,7 @@ def check_conflicts
168171
end
169172
end
170173

174+
sig { void }
171175
def uninstall_existing_cask
172176
return unless @cask.installed?
173177

@@ -196,6 +200,7 @@ def download(quiet: nil, timeout: nil)
196200
timeout:)
197201
end
198202

203+
sig { void }
199204
def verify_has_sha
200205
odebug "Checking cask has checksum"
201206
return if @cask.sha256 != :no_check
@@ -213,6 +218,12 @@ def primary_container
213218
end
214219
end
215220

221+
sig { returns(ArtifactSet) }
222+
def artifacts
223+
@cask.artifacts
224+
end
225+
226+
sig { params(to: Pathname).void }
216227
def extract_primary_container(to: @cask.staged_path)
217228
odebug "Extracting primary container"
218229

@@ -242,7 +253,6 @@ def extract_primary_container(to: @cask.staged_path)
242253

243254
sig { params(predecessor: T.nilable(Cask)).void }
244255
def install_artifacts(predecessor: nil)
245-
artifacts = @cask.artifacts
246256
already_installed_artifacts = []
247257

248258
odebug "Installing artifacts"
@@ -301,6 +311,7 @@ def check_macos_requirements
301311
raise CaskError, @cask.depends_on.macos.message(type: :cask)
302312
end
303313

314+
sig { void }
304315
def check_arch_requirements
305316
return if @cask.depends_on.arch.nil?
306317

@@ -316,6 +327,7 @@ def check_arch_requirements
316327
"but you are running #{@current_arch}."
317328
end
318329

330+
sig { returns(T::Array[T.untyped]) }
319331
def cask_and_formula_dependencies
320332
return @cask_and_formula_dependencies if @cask_and_formula_dependencies
321333

@@ -489,8 +501,6 @@ def finalize_upgrade
489501

490502
sig { params(clear: T::Boolean, successor: T.nilable(Cask)).void }
491503
def uninstall_artifacts(clear: false, successor: nil)
492-
artifacts = @cask.artifacts
493-
494504
odebug "Uninstalling artifacts"
495505
odebug "#{::Utils.pluralize("artifact", artifacts.length, include_count: true)} defined", artifacts
496506

‎Library/Homebrew/cask/quarantine.rb

+2
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,5 @@ def self.app_management_permissions_granted?(app:, command:)
266266
end
267267
end
268268
end
269+
270+
require "extend/os/cask/quarantine"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "extend/os/mac/cask/artifact/moved" if OS.mac?
5+
require "extend/os/linux/cask/artifact/moved" if OS.linux?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "extend/os/linux/cask/config" if OS.linux?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "extend/os/linux/cask/quarantine" if OS.linux?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module OS
5+
module Linux
6+
module Cask
7+
module Artifact
8+
module Moved
9+
extend T::Helpers
10+
11+
requires_ancestor { ::Cask::Artifact::Moved }
12+
13+
sig { params(target: Pathname).returns(T::Boolean) }
14+
def undeletable?(target)
15+
!target.parent.writable?
16+
end
17+
end
18+
end
19+
end
20+
end
21+
end
22+
23+
Cask::Artifact::Moved.prepend(OS::Linux::Cask::Config)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "os/linux"
5+
6+
module OS
7+
module Linux
8+
module Cask
9+
module Config
10+
module ClassMethods
11+
DEFAULT_DIRS = T.let({
12+
vst_plugindir: "~/.vst",
13+
vst3_plugindir: "~/.vst3",
14+
fontdir: "#{ENV.fetch("XDG_DATA_HOME", "~/.local/share")}/fonts",
15+
appdir: "~/.config/apps",
16+
}.freeze, T::Hash[Symbol, String])
17+
18+
sig { returns(T::Hash[Symbol, String]) }
19+
def defaults
20+
{
21+
languages: LazyObject.new { Linux.languages },
22+
}.merge(DEFAULT_DIRS).freeze
23+
end
24+
end
25+
end
26+
end
27+
end
28+
end
29+
30+
Cask::Config.singleton_class.prepend(OS::Linux::Cask::Config::ClassMethods)

‎Library/Homebrew/extend/os/linux/cask/installer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module Installer
1313

1414
sig { void }
1515
def check_stanza_os_requirements
16+
return if artifacts.all?(::Cask::Artifact::Font)
17+
1618
raise ::Cask::CaskError, "macOS is required for this software."
1719
end
1820
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module OS
5+
module Linux
6+
module Cask
7+
module Quarantine
8+
extend T::Helpers
9+
10+
requires_ancestor { ::Cask::Quarantine }
11+
12+
sig { returns(Symbol) }
13+
def self.check_quarantine_support = :linux
14+
15+
sig { returns(T::Boolean) }
16+
def self.available? = false
17+
end
18+
end
19+
end
20+
end
21+
22+
Cask::Quarantine.prepend(OS::Linux::Cask::Quarantine)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "cask/macos"
5+
6+
module OS
7+
module Mac
8+
module Cask
9+
module Artifact
10+
module Moved
11+
extend T::Helpers
12+
13+
requires_ancestor { ::Cask::Artifact::Moved }
14+
15+
sig { params(target: Pathname).returns(T::Boolean) }
16+
def undeletable?(target)
17+
MacOS.undeletable?(target)
18+
end
19+
end
20+
end
21+
end
22+
end
23+
end
24+
25+
Cask::Artifact::Moved.prepend(OS::Mac::Cask::Artifact::Moved)

‎Library/Homebrew/extend/os/mac/readall.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def valid_casks?(tap, os_name: nil, arch: ::Hardware::CPU.type)
2020

2121
success = T.let(true, T::Boolean)
2222
tap.cask_files.each do |file|
23-
cask = Cask::CaskLoader.load(file)
23+
cask = ::Cask::CaskLoader.load(file)
2424

2525
# Fine to have missing URLs for unsupported macOS
2626
macos_req = cask.depends_on.macos

‎Library/Homebrew/os/linux.rb

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module Linux
1313
raise "Loaded OS::Linux on macOS!" if OS.mac?
1414
# rubocop:enable Homebrew/MoveToExtendOS
1515

16+
@languages = T.let([], T::Array[String])
17+
1618
# Get the OS version.
1719
#
1820
# @api internal
@@ -56,5 +58,15 @@ def self.wsl_version
5658
Version::NULL
5759
end
5860
end
61+
62+
sig { returns(T::Array[String]) }
63+
def self.languages
64+
return @languages if @languages.present?
65+
66+
os_langs = Utils.popen_read("localectl", "list-locales")
67+
os_langs = os_langs.scan(/[^ \n"(),]+/).map { |item| item.split(".").first.tr("_", "-") }
68+
69+
@languages = os_langs
70+
end
5971
end
6072
end

‎Library/Homebrew/os/mac.rb

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def self.preferred_perl_version
6969
end
7070
end
7171

72+
sig { returns(T::Array[String]) }
7273
def self.languages
7374
return @languages if @languages
7475

0 commit comments

Comments
 (0)
Please sign in to comment.