Skip to content

Commit 378ff7c

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

File tree

16 files changed

+245
-10
lines changed

16 files changed

+245
-10
lines changed

Library/Homebrew/cask/artifact/moved.rb

Lines changed: 5 additions & 1 deletion
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

Lines changed: 23 additions & 4 deletions
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) }
@@ -197,6 +195,8 @@ def languages=(languages)
197195
end
198196

199197
DEFAULT_DIRS.each_key do |dir|
198+
next if dir == :fontdir
199+
200200
define_method(dir) do
201201
T.bind(self, Config)
202202
explicit.fetch(dir, env.fetch(dir, default.fetch(dir)))
@@ -208,6 +208,16 @@ def languages=(languages)
208208
end
209209
end
210210

211+
sig { returns(T.any(String, Pathname)) }
212+
def fontdir
213+
get_dir_path(:fontdir)
214+
end
215+
216+
sig { params(path: String).returns(Pathname) }
217+
def fontdir=(path)
218+
explicit[:fontdir] = Pathname(path).expand_path
219+
end
220+
211221
sig { params(other: Config).returns(T.self_type) }
212222
def merge(other)
213223
self.class.new(explicit: other.explicit.merge(explicit))
@@ -221,5 +231,14 @@ def to_json(*options)
221231
explicit:,
222232
}.to_json(*options)
223233
end
234+
235+
private
236+
237+
sig { params(dir: Symbol).returns(T.any(String, Pathname)) }
238+
def get_dir_path(dir)
239+
T.cast(explicit.fetch(dir, env.fetch(dir, default.fetch(dir))), T.any(String, Pathname))
240+
end
224241
end
225242
end
243+
244+
require "extend/os/cask/config"

Library/Homebrew/cask/installer.rb

Lines changed: 14 additions & 3 deletions
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

Lines changed: 2 additions & 0 deletions
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"
Lines changed: 5 additions & 0 deletions
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?
Lines changed: 5 additions & 0 deletions
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?
Lines changed: 4 additions & 0 deletions
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?
Lines changed: 23 additions & 0 deletions
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)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
39+
sig { returns(String) }
40+
def fontdir
41+
@fontdir ||= T.let("#{ENV.fetch("XDG_DATA_HOME", "~/.local/share")}/fonts", T.nilable(String))
42+
end
43+
44+
45+
end
46+
end
47+
end
48+
end
49+
50+
Cask::Config.prepend(OS::Linux::Cask::Config)

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

Lines changed: 3 additions & 1 deletion
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

0 commit comments

Comments
 (0)