Class: Homebrew::InstallSteps::Runner Private

Inherits:
Object
  • Object
show all
Includes:
SystemCommand::Mixin, Utils::Output::Mixin
Defined in:
install_steps.rb,
install_steps/formula_actions.rb

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.

Constant Summary collapse

PRIVILEGED_STEP_REQUEST =

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.

"homebrew_cask_privileged_step"
PRIVILEGED_STEP_SUCCEEDED =

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.

"homebrew_cask_privileged_step_succeeded"
CONTENT_PATH_TOKENS =

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.

Path tokens reuse the step base resolution; formula metadata tokens are resolved separately. Anything else is left verbatim so literal braces in templates are never rewritten.

%w[
  prefix opt_prefix bin sbin lib libexec share pkgshare var etc pkgetc staged_path appdir caskroom_path
  temp rack
  bash_completion zsh_completion fish_completion pwsh_completion
].freeze

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_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods included from SystemCommand::Mixin

#command_sandbox, #system_command, #system_command!

Constructor Details

#initialize(context:, command: SystemCommand) ⇒ 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:



912
913
914
915
916
# File 'install_steps.rb', line 912

def initialize(context:, command: SystemCommand)
  @context = context
  @command = command
  @guard_results = T.let({}, T::Hash[PathSpec, T::Boolean])
end

Instance Method Details

#make_cpython_venv_activation_scripts_writable(lib_cellar) ⇒ 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:



273
274
275
# File 'install_steps/formula_actions.rb', line 273

def make_cpython_venv_activation_scripts_writable(lib_cellar)
  FileUtils.chmod "u+w", lib_cellar.glob("venv/scripts/**/*").select(&:file?)
end

#run(steps, phase: :install, privileged_step_handler: nil, reset_guard_results: true) ⇒ 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.

privileged_step_handler delegates steps that may need sudo to the caller (the parent process broker for sandboxed cask steps), and reset_guard_results: false lets that broker run steps one at a time while keeping guard snapshots from earlier steps in the same plan.

Parameters:

  • steps (Steps)
  • phase (Symbol) (defaults to: :install)
  • privileged_step_handler (T.proc.params(index: Integer).void, nil) (defaults to: nil)
  • reset_guard_results (Boolean) (defaults to: true)


930
931
932
933
934
935
936
937
938
939
940
941
942
943
# File 'install_steps.rb', line 930

def run(steps, phase: :install, privileged_step_handler: nil, reset_guard_results: true)
  @guard_results.clear if reset_guard_results
  DSL.normalise_steps(steps).each_with_index do |step, index|
    next if phase != :uninstall && !step_guards_match?(step)

    if privileged_step_handler && sudo_required?([step])
      privileged_step_handler.call(index)
    elsif phase == :uninstall
      run_uninstall_step(step)
    else
      run_install_step(step)
    end
  end
end

#sandbox_write_paths(steps, phase: :install) ⇒ Array<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:



946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
# File 'install_steps.rb', line 946

def sandbox_write_paths(steps, phase: :install)
  DSL.normalise_steps(steps).flat_map do |step|
    if phase == :uninstall
      next [] if step["type"] != "symlink" || step["uninstall"] != true

      next [resolve_path(step_path(step, "target")).parent]
    end

    case step.fetch("type")
    when "mkdir_p"
      path = resolve_path(step_path(step, "path"))
      [path.parent.directory? ? path : path.parent]
    when "mkdir", "touch", "write"
      [resolve_path(step_path(step, "path")).parent]
    when "move"
      [resolve_path(step_path(step, "source")).parent, resolve_path(step_path(step, "target")).parent]
    when "move_children", "move_contents"
      [resolve_path(step_path(step, "source")), resolve_path(step_path(step, "target"))]
    when "copy", "symlink"
      [resolve_path(step_path(step, "target")).parent]
    when "remove"
      step_paths(step, "paths").flat_map { |path| expand_path_glob(path) }.map(&:parent)
    when "inreplace", "change_dylib_id"
      path = resolve_path(step_path(step, (step["type"] == "inreplace") ? "path" : "source"))
      [path.exist? ? path : path.parent]
    when "link_dir", "link_children"
      [resolve_path(step_path(step, "target"))]
    when "run"
      paths = step.key?("stdout_path") ? [resolve_path(step_path(step, "stdout_path")).parent] : []
      if step.key?("writable_paths")
        paths.concat(step_paths(step, "writable_paths").map do |path|
          resolve_path(path)
        end)
      end
      paths
    when "set_permissions", "set_ownership"
      existing_step_paths(step)
    else
      []
    end
  end.uniq
end

#sudo_required?(steps, include_optional: true) ⇒ Boolean

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.

Include optional elevation when routing steps out of the sandbox.

Parameters:

  • steps (Steps)
  • include_optional (Boolean) (defaults to: true)

Returns:

  • (Boolean)


991
992
993
994
995
996
# File 'install_steps.rb', line 991

def sudo_required?(steps, include_optional: true)
  DSL.normalise_steps(steps).any? do |step|
    step["sudo"] == true || step["type"] == "delete_keychain_certificate" ||
      (include_optional && (step["sudo"] == "if_needed" || step["type"] == "set_ownership"))
  end
end