Class: Cask::Artifact::AbstractArtifact Abstract Private

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, Utils::Output::Mixin
Includes:
Comparable, Utils::Output::Mixin
Defined in:
cask/artifact/abstract_artifact.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the abstract methods below.

Abstract superclass for all artifacts.

Constant Summary collapse

DirectivesType =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.anything or the union of all possible argument types would be better choice, but it's convenient to be able to invoke .inspect, .to_s, etc. without the overhead of type guards.

T.type_alias { Object }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_outdated, pretty_uninstalled, pretty_upgradable

Constructor Details

#initialize(cask, *dsl_args) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • cask (Cask)
  • dsl_args (T.anything)


178
179
180
181
182
183
184
185
186
# File 'cask/artifact/abstract_artifact.rb', line 178

def initialize(cask, *dsl_args)
  @cask = cask
  @dirmethod = T.let(nil, T.nilable(Symbol))
  @dsl_args = T.let(dsl_args.deep_dup, T::Array[T.anything])
  @dsl_key = T.let(nil, T.nilable(Symbol))
  @english_article = T.let(nil, T.nilable(String))
  @english_name = T.let(nil, T.nilable(String))
  @sort_order = T.let(nil, T.nilable(T::Hash[T.class_of(AbstractArtifact), Integer]))
end

Instance Attribute Details

#caskCask (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



175
176
177
# File 'cask/artifact/abstract_artifact.rb', line 175

def cask
  @cask
end

Class Method Details

.dirmethodSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



43
44
45
# File 'cask/artifact/abstract_artifact.rb', line 43

def self.dirmethod
  @dirmethod ||= T.let(:"#{dsl_key}dir", T.nilable(Symbol))
end

.dsl_keySymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



37
38
39
40
# File 'cask/artifact/abstract_artifact.rb', line 37

def self.dsl_key
  @dsl_key ||= T.let(T.must(name).sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym,
                     T.nilable(Symbol))
end

.english_articleString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



32
33
34
# File 'cask/artifact/abstract_artifact.rb', line 32

def self.english_article
  @english_article ||= T.let(/^[aeiou]/i.match?(english_name) ? "an" : "a", T.nilable(String))
end

.english_nameString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



27
28
29
# File 'cask/artifact/abstract_artifact.rb', line 27

def self.english_name
  @english_name ||= T.let(T.must(name).sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2'), T.nilable(String))
end

.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil) ⇒ Array<([String, nil], Hash{Symbol => T.untyped})>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

TODO:

this sort of logic would make more sense in dsl.rb, or a constructor called from dsl.rb, so long as that isn't slow.

Parameters:

Returns:



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'cask/artifact/abstract_artifact.rb', line 137

def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil)
  # TODO: when stanza names are harmonized with class names,
  #       stanza may not be needed as an explicit argument
  description = key ? "#{stanza} #{key.inspect}" : stanza.to_s

  arguments = case arguments
  when String then { executable: arguments } # backward-compatible string value
  when Hash then arguments.dup # Avoid mutating the original argument
  else odie "Unsupported arguments type #{arguments.class}"
  end

  # key sanity
  permitted_keys = [:args, :input, :executable, :must_succeed, :sudo, :print_stdout, :print_stderr]
  unknown_keys = arguments.keys - permitted_keys
  unless unknown_keys.empty?
    opoo "Unknown arguments to #{description} -- " \
         "#{unknown_keys.inspect} (ignored). Running " \
         "`brew update; brew cleanup` will likely fix it."
  end
  arguments.select! { |k| permitted_keys.include?(k) }

  # key warnings
  override_keys = override_arguments.keys
  ignored_keys = arguments.keys & override_keys
  unless ignored_keys.empty?
    onoe "Some arguments to #{description} will be ignored -- :#{unknown_keys.inspect} (overridden)."
  end

  # extract executable
  executable = arguments.key?(:executable) ? arguments.delete(:executable) : nil

  arguments = default_arguments.merge arguments
  arguments.merge! override_arguments

  [executable, arguments]
end

Instance Method Details

#cask_sandboxSandbox?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'cask/artifact/abstract_artifact.rb', line 194

def cask_sandbox
  return if Homebrew::EnvConfig.no_sandbox_cask?

  Sandbox.ensure_sandbox_installed!
  return unless Sandbox.available?

  Sandbox.new.tap do |sandbox|
    sandbox.allow_read(path: cask.staged_path, type: :subpath)
    sandbox.allow_write_temp_and_cache
    sandbox.deny_read_home
    sandbox.deny_all_network
  end
end

#cask_sandbox_command(env, args, home:) ⇒ Array<String, Pathname>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



215
216
217
218
# File 'cask/artifact/abstract_artifact.rb', line 215

def cask_sandbox_command(env, args, home:)
  env = { "HOME" => home }.merge(env)
  ["/usr/bin/env", *env.map { |key, value| "#{key}=#{value}" }, *args]
end

#configConfig

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



189
190
191
# File 'cask/artifact/abstract_artifact.rb', line 189

def config
  cask.config
end

#run_cask_sandbox(sandbox, args, input: []) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'cask/artifact/abstract_artifact.rb', line 227

def run_cask_sandbox(sandbox, args, input: [])
  return sandbox.run(*args) if Array(input).empty?

  Tempfile.create("homebrew-cask-script-input", HOMEBREW_TEMP) do |input_file|
    input_file.write(Array(input).join)
    input_file.close
    sandbox.allow_read(path: input_file.path)
    sandbox.run(
      "/bin/sh",
      "-c",
      "input=$1; shift; exec \"$@\" < \"$input\"",
      "sh",
      input_file.path,
      *args,
    )
  end
end

#sort_orderHash{T.class_of(AbstractArtifact) => Integer}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



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
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'cask/artifact/abstract_artifact.rb', line 71

def sort_order
  @sort_order ||= T.let(
    [
      PreflightBlock,
      PreflightSteps,
      UninstallPreflightSteps,
      # The `uninstall` stanza should be run first, as it may
      # depend on other artifacts still being installed.
      Uninstall,
      Installer,
      # `pkg` should be run before `binary`, so
      # targets are created prior to linking.
      # `pkg` should be run before `app`, since an `app` could
      # contain a nested installer (e.g. `wireshark`).
      Pkg,
      [
        App,
        Suite,
        Artifact,
        Colorpicker,
        Prefpane,
        Qlplugin,
        Mdimporter,
        Dictionary,
        Font,
        Service,
        InputMethod,
        InternetPlugin,
        KeyboardLayout,
        AudioUnitPlugin,
        VstPlugin,
        Vst3Plugin,
        ScreenSaver,
      ],
      Binary,
      Manpage,
      PostflightSteps,
      UninstallPostflightSteps,
      PostflightBlock,
      Zap,
    ].each_with_index.flat_map { |classes, i| Array(classes).map { |c| [c, i] } }.to_h,
    T.nilable(T::Hash[T.class_of(AbstractArtifact), Integer]),
  )
end

#staged_path_join_executable(path) ⇒ Pathname

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'cask/artifact/abstract_artifact.rb', line 51

def staged_path_join_executable(path)
  path = Pathname(path)
  path = path.expand_path if path.to_s.start_with?("~")

  absolute_path = if path.absolute?
    path
  else
    cask.staged_path.join(path)
  end

  FileUtils.chmod "+x", absolute_path if absolute_path.exist? && !absolute_path.executable?

  if absolute_path.exist?
    absolute_path
  else
    path
  end
end

#summarizeString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method is abstract.

Returns:



48
# File 'cask/artifact/abstract_artifact.rb', line 48

def summarize; end

#to_argsArray<T.anything>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



251
252
253
# File 'cask/artifact/abstract_artifact.rb', line 251

def to_args
  @dsl_args.compact_blank
end