Skip to content

Commit 3c3bb32

Browse files
committed
Only use MachOShim/ELFShim when required
Not including this globally in `Pathname` speeds up the creation of other `Pathname` objects by ~200x making all of Homebrew faster.
1 parent 143769a commit 3c3bb32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+433
-371
lines changed

Library/Homebrew/build.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def install
198198
(formula.logs/"00.options.out").write \
199199
"#{formula.full_name} #{formula.build.used_options.sort.join(" ")}".strip
200200

201-
Pathname.prepend WriteMkpathExtension
201+
Pathname.activate_extensions!
202202
formula.install
203203

204204
stdlibs = detect_stdlibs

Library/Homebrew/cask/artifact/abstract_uninstall.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,10 @@ def uninstall_rmdir(*directories, **kwargs)
541541
end
542542
end
543543

544-
def undeletable?(target); end
544+
sig { params(target: Pathname).returns(T::Boolean) }
545+
def undeletable?(target)
546+
!target.parent.writable?
547+
end
545548
end
546549
end
547550
end

Library/Homebrew/cask/artifact/moved.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ def delete(target, force: false, successor: nil, command: nil, **_)
197197
end
198198
end
199199

200-
def undeletable?(target); end
200+
sig { params(target: Pathname).returns(T::Boolean) }
201+
def undeletable?(target)
202+
!target.parent.writable?
203+
end
201204
end
202205
end
203206
end

Library/Homebrew/cask/artifact/symlinked.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ def unlink(command: nil, **)
8282
end
8383

8484
sig { params(command: T.class_of(SystemCommand)).void }
85-
def create_filesystem_link(command); end
85+
def create_filesystem_link(command)
86+
Utils.gain_permissions_mkpath(target.dirname, command:)
87+
88+
command.run! "/bin/ln", args: ["--no-dereference", "--force", "--symbolic", source, target],
89+
sudo: !target.dirname.writable?
90+
end
8691

8792
# Check if the target file is a symlink that originates from a formula
8893
# with the same name as this cask, indicating a potential conflict

Library/Homebrew/cask/macos.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ module Mac
232232
"/var/spool/mail",
233233
"/var/tmp",
234234
]
235-
.to_set { |path| Pathname(path) }
236-
.freeze, T::Set[Pathname])
235+
.to_set { |path| ::Pathname.new(path) }
236+
.freeze, T::Set[::Pathname])
237237
private_constant :SYSTEM_DIRS
238238

239239
# TODO: There should be a way to specify a containing
@@ -373,19 +373,19 @@ module Mac
373373
"~/Library/Widgets",
374374
"~/Library/Workflows",
375375
]
376-
.to_set { |path| Pathname(path.sub(%r{^~(?=(/|$))}, Dir.home)).expand_path }
376+
.to_set { |path| ::Pathname.new(path.sub(%r{^~(?=(/|$))}, Dir.home)).expand_path }
377377
.union(SYSTEM_DIRS)
378-
.freeze, T::Set[Pathname])
378+
.freeze, T::Set[::Pathname])
379379
private_constant :UNDELETABLE_PATHS
380380

381-
sig { params(dir: T.any(Pathname, String)).returns(T::Boolean) }
381+
sig { params(dir: T.any(::Pathname, String)).returns(T::Boolean) }
382382
def self.system_dir?(dir)
383-
SYSTEM_DIRS.include?(Pathname.new(dir).expand_path)
383+
SYSTEM_DIRS.include?(::Pathname.new(dir).expand_path)
384384
end
385385

386-
sig { params(path: T.any(Pathname, String)).returns(T::Boolean) }
386+
sig { params(path: T.any(::Pathname, String)).returns(T::Boolean) }
387387
def self.undeletable?(path)
388-
UNDELETABLE_PATHS.include?(Pathname.new(path).expand_path)
388+
UNDELETABLE_PATHS.include?(::Pathname.new(path).expand_path)
389389
end
390390
end
391391
end

Library/Homebrew/extend/module.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33

44
class Module
55
include T::Sig
6+
7+
# The inverse of <tt>Module#include?</tt>. Returns true if the module
8+
# does not include the other module.
9+
sig { params(mod: T::Module[T.anything]).returns(T::Boolean) }
10+
def exclude?(mod) = !include?(mod)
611
end

Library/Homebrew/extend/os/cask/artifact/abstract_uninstall.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
# frozen_string_literal: true
33

44
require "extend/os/mac/cask/artifact/abstract_uninstall" if OS.mac?
5-
require "extend/os/linux/cask/artifact/abstract_uninstall" if OS.linux?

Library/Homebrew/extend/os/cask/artifact/moved.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
# frozen_string_literal: true
33

44
require "extend/os/mac/cask/artifact/moved" if OS.mac?
5-
require "extend/os/linux/cask/artifact/moved" if OS.linux?

Library/Homebrew/extend/os/cask/artifact/symlinked.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
# frozen_string_literal: true
33

44
require "extend/os/mac/cask/artifact/symlinked" if OS.mac?
5-
require "extend/os/linux/cask/artifact/symlinked" if OS.linux?

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)