forked from Homebrew/brew
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.rb
101 lines (83 loc) · 2.81 KB
/
installer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# typed: true
# frozen_string_literal: true
require "cask/artifact/abstract_artifact"
require "extend/hash/keys"
module Cask
module Artifact
# Artifact corresponding to the `installer` stanza.
class Installer < AbstractArtifact
VALID_KEYS = Set.new([
:manual,
:script,
]).freeze
# Extension module for manual installers.
module ManualInstaller
def install_phase(**)
puts <<~EOS
Cask #{cask} only provides a manual installer. To run it and complete the installation:
open #{cask.staged_path.join(path).to_s.shellescape}
EOS
end
end
# Extension module for script installers.
module ScriptInstaller
def install_phase(command: nil, **_)
# TODO: The `T.unsafe` is a false positive that is unnecessary in newer releasese of Sorbet
# (confirmend with sorbet v0.5.10672)
ohai "Running #{T.unsafe(self.class).dsl_key} script '#{path}'"
executable_path = staged_path_join_executable(path)
command.run!(
executable_path,
**args,
env: { "PATH" => PATH.new(
HOMEBREW_PREFIX/"bin", HOMEBREW_PREFIX/"sbin", ENV.fetch("PATH")
) },
)
end
end
def self.from_args(cask, **args)
raise CaskInvalidError.new(cask, "'installer' stanza requires an argument.") if args.empty?
if args.key?(:script) && !args[:script].respond_to?(:key?)
if args.key?(:executable)
raise CaskInvalidError.new(cask, "'installer' stanza gave arguments for both :script and :executable.")
end
args[:executable] = args[:script]
args.delete(:script)
args = { script: args }
end
if args.keys.count != 1
raise CaskInvalidError.new(
cask,
"invalid 'installer' stanza: Only one of #{VALID_KEYS.inspect} is permitted.",
)
end
args.assert_valid_keys(*VALID_KEYS)
new(cask, **args)
end
attr_reader :path, :args
def initialize(cask, **args)
super(cask, **args)
if args.key?(:manual)
@path = Pathname(args[:manual])
@args = []
extend(ManualInstaller)
return
end
path, @args = self.class.read_script_arguments(
args[:script], self.class.dsl_key.to_s, { must_succeed: true, sudo: false }, print_stdout: true
)
raise CaskInvalidError.new(cask, "#{self.class.dsl_key} missing executable") if path.nil?
@path = Pathname(path)
extend(ScriptInstaller)
end
def summarize
path.to_s
end
def to_h
{ path: }.tap do |h|
h[:args] = args unless is_a?(ManualInstaller)
end
end
end
end
end