Skip to content

Commit ed30ba7

Browse files
committed
feat: allow font install on linux
1 parent cb23433 commit ed30ba7

File tree

16 files changed

+219
-10
lines changed

16 files changed

+219
-10
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ class Config
3030
vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3",
3131
screen_saverdir: "~/Library/Screen Savers",
3232
}.freeze,
33-
T::Hash[Symbol, String],
33+
T::Hash[Symbol, T.nilable(String)],
3434
)
3535

3636
sig { returns(T::Hash[Symbol, T.untyped]) }
3737
def self.defaults
38-
{
39-
languages: LazyObject.new { MacOS.languages },
40-
}.merge(DEFAULT_DIRS).freeze
38+
DEFAULT_DIRS.freeze
4139
end
4240

4341
sig { params(args: Homebrew::CLI::Args).returns(T.attached_class) }
@@ -223,3 +221,5 @@ def to_json(*options)
223221
end
224222
end
225223
end
224+
225+
require "extend/os/cask/config"

Library/Homebrew/cask/installer.rb

+14-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"
@@ -134,6 +136,7 @@ def install
134136
raise
135137
end
136138

139+
sig { void }
137140
def check_deprecate_disable
138141
deprecate_disable_type = DeprecateDisable.type(@cask)
139142
return if deprecate_disable_type.nil?
@@ -150,6 +153,7 @@ def check_deprecate_disable
150153
end
151154
end
152155

156+
sig { void }
153157
def check_conflicts
154158
return unless @cask.conflicts_with
155159

@@ -166,6 +170,7 @@ def check_conflicts
166170
end
167171
end
168172

173+
sig { void }
169174
def uninstall_existing_cask
170175
return unless @cask.installed?
171176

@@ -194,6 +199,7 @@ def download(quiet: nil, timeout: nil)
194199
timeout:)
195200
end
196201

202+
sig { void }
197203
def verify_has_sha
198204
odebug "Checking cask has checksum"
199205
return if @cask.sha256 != :no_check
@@ -211,6 +217,12 @@ def primary_container
211217
end
212218
end
213219

220+
sig { returns(ArtifactSet) }
221+
def artifacts
222+
@cask.artifacts
223+
end
224+
225+
sig { params(to: Pathname).void }
214226
def extract_primary_container(to: @cask.staged_path)
215227
odebug "Extracting primary container"
216228

@@ -240,7 +252,6 @@ def extract_primary_container(to: @cask.staged_path)
240252

241253
sig { params(predecessor: T.nilable(Cask)).void }
242254
def install_artifacts(predecessor: nil)
243-
artifacts = @cask.artifacts
244255
already_installed_artifacts = []
245256

246257
odebug "Installing artifacts"
@@ -299,6 +310,7 @@ def check_macos_requirements
299310
raise CaskError, @cask.depends_on.macos.message(type: :cask)
300311
end
301312

313+
sig { void }
302314
def check_arch_requirements
303315
return if @cask.depends_on.arch.nil?
304316

@@ -314,6 +326,7 @@ def check_arch_requirements
314326
"but you are running #{@current_arch}."
315327
end
316328

329+
sig { returns(T::Array[T.untyped]) }
317330
def cask_and_formula_dependencies
318331
return @cask_and_formula_dependencies if @cask_and_formula_dependencies
319332

@@ -487,8 +500,6 @@ def finalize_upgrade
487500

488501
sig { params(clear: T::Boolean, successor: T.nilable(Cask)).void }
489502
def uninstall_artifacts(clear: false, successor: nil)
490-
artifacts = @cask.artifacts
491-
492503
odebug "Uninstalling artifacts"
493504
odebug "#{::Utils.pluralize("artifact", artifacts.length, include_count: true)} defined", artifacts
494505

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,5 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "extend/os/mac/cask/config" if OS.mac?
5+
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,43 @@
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+
extend T::Helpers
11+
12+
requires_ancestor { ::Cask::Config }
13+
14+
DEFAULT_DIRS = T.let({
15+
vst_plugindir: "~/.vst",
16+
vst3_plugindir: "~/.vst3",
17+
fontdir: "#{ENV.fetch("XDG_DATA_HOME", "~/.local/share")}/fonts",
18+
appdir: nil,
19+
keyboard_layoutdir: nil,
20+
colorpickerdir: nil,
21+
prefpanedir: nil,
22+
qlplugindir: nil,
23+
mdimporterdir: nil,
24+
servicedir: nil,
25+
dictionarydir: nil,
26+
screen_saverdir: nil,
27+
input_methoddir: nil,
28+
internet_plugindir: nil,
29+
audio_unit_plugindir: nil,
30+
}.freeze, T::Hash[Symbol, T.nilable(String)])
31+
32+
sig { returns(T::Hash[Symbol, T.untyped]) }
33+
def self.defaults
34+
{
35+
languages: LazyObject.new { Linux.languages },
36+
}.merge(DEFAULT_DIRS).freeze
37+
end
38+
end
39+
end
40+
end
41+
end
42+
43+
Cask::Config.prepend(OS::Linux::Cask::Config)

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ module Installer
1313

1414
sig { void }
1515
def check_stanza_os_requirements
16-
raise ::Cask::CaskError, "macOS is required for this software."
16+
raise ::Cask::CaskError, "macOS is required for this software." unless artifacts.reject do |k|
17+
k.is_a?(::Cask::Artifact::Font)
18+
end.empty?
1719
end
1820
end
1921
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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
14+
:linux
15+
end
16+
17+
sig { returns(T::Boolean) }
18+
def self.available?
19+
false
20+
end
21+
end
22+
end
23+
end
24+
end
25+
26+
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::Config)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 Config
10+
extend T::Helpers
11+
12+
requires_ancestor { ::Cask::Config }
13+
14+
DEFAULT_DIRS = T.let(
15+
{
16+
appdir: "/Applications",
17+
keyboard_layoutdir: "/Library/Keyboard Layouts",
18+
colorpickerdir: "~/Library/ColorPickers",
19+
prefpanedir: "~/Library/PreferencePanes",
20+
qlplugindir: "~/Library/QuickLook",
21+
mdimporterdir: "~/Library/Spotlight",
22+
dictionarydir: "~/Library/Dictionaries",
23+
fontdir: "~/Library/Fonts",
24+
servicedir: "~/Library/Services",
25+
input_methoddir: "~/Library/Input Methods",
26+
internet_plugindir: "~/Library/Internet Plug-Ins",
27+
audio_unit_plugindir: "~/Library/Audio/Plug-Ins/Components",
28+
vst_plugindir: "~/Library/Audio/Plug-Ins/VST",
29+
vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3",
30+
screen_saverdir: "~/Library/Screen Savers",
31+
}.freeze,
32+
T::Hash[Symbol, String],
33+
)
34+
35+
sig { returns(T::Hash[Symbol, T.untyped]) }
36+
def self.defaults
37+
{
38+
languages: LazyObject.new { ::OS::Mac.languages },
39+
}.merge(DEFAULT_DIRS).freeze
40+
end
41+
end
42+
end
43+
end
44+
end
45+
46+
Cask::Config.prepend(OS::Mac::Cask::Config)

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)