Class: TestRunnerFormula

Inherits:
Object show all
Defined in:
test_runner_formula.rb

Constant Summary collapse

SIMULATE_SYSTEM_SYMBOLS =
T.let({ arm64: :arm, x86_64: :intel }.freeze, T::Hash[Symbol, Symbol])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formula, eval_all: Homebrew::EnvConfig.eval_all?) ⇒ 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:

  • formula (Formula)
  • eval_all (Boolean) (defaults to: Homebrew::EnvConfig.eval_all?)


17
18
19
20
21
22
23
24
# File 'test_runner_formula.rb', line 17

def initialize(formula, eval_all: Homebrew::EnvConfig.eval_all?)
  Formulary.enable_factory_cache!
  @formula = T.let(formula, Formula)
  @name = T.let(formula.name, String)
  @dependent_hash = T.let({}, T::Hash[Symbol, T::Array[TestRunnerFormula]])
  @eval_all = T.let(eval_all, T::Boolean)
  freeze
end

Instance Attribute Details

#eval_allBoolean (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:

  • (Boolean)


14
15
16
# File 'test_runner_formula.rb', line 14

def eval_all
  @eval_all
end

#formulaFormula (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:



11
12
13
# File 'test_runner_formula.rb', line 11

def formula
  @formula
end

#nameString (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:



8
9
10
# File 'test_runner_formula.rb', line 8

def name
  @name
end

Instance Method Details

#arm64_compatible?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.

Returns:

  • (Boolean)


62
63
64
# File 'test_runner_formula.rb', line 62

def arm64_compatible?
  !x86_64_only?
end

#arm64_only?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.

Returns:

  • (Boolean)


57
58
59
# File 'test_runner_formula.rb', line 57

def arm64_only?
  formula.requirements.any? { |r| r.is_a?(ArchRequirement) && (r.arch == :arm64) }
end

#compatible_with?(macos_version) ⇒ 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.

Parameters:

Returns:

  • (Boolean)


72
73
74
75
76
77
78
# File 'test_runner_formula.rb', line 72

def compatible_with?(macos_version)
  # Assign to a variable to assist type-checking.
  requirement = versioned_macos_requirement
  return true if requirement.blank?

  macos_version.public_send(requirement.comparator, requirement.version)
end

#dependents(platform:, arch:, macos_version:) ⇒ Array<TestRunnerFormula>

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:



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
# File 'test_runner_formula.rb', line 89

def dependents(platform:, arch:, macos_version:)
  cache_key = :"#{platform}_#{arch}_#{macos_version}"

  @dependent_hash[cache_key] ||= begin
    formula_selector, eval_all_env = if eval_all
      [:all, "1"]
    else
      [:installed, nil]
    end

    with_env(HOMEBREW_EVAL_ALL: eval_all_env) do
      os = macos_version || platform
      arch = SIMULATE_SYSTEM_SYMBOLS.fetch(arch)

      Homebrew::SimulateSystem.with(os:, arch:) do
        Formula.public_send(formula_selector)
               .select { |candidate_f| candidate_f.deps.map(&:name).include?(name) }
               .map { |f| TestRunnerFormula.new(f, eval_all:) }
               .freeze
      end
    end
  end

  @dependent_hash.fetch(cache_key)
end

#linux_compatible?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.

Returns:

  • (Boolean)


42
43
44
# File 'test_runner_formula.rb', line 42

def linux_compatible?
  !macos_only?
end

#linux_only?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.

Returns:

  • (Boolean)


37
38
39
# File 'test_runner_formula.rb', line 37

def linux_only?
  formula.requirements.any?(LinuxRequirement)
end

#macos_compatible?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.

Returns:

  • (Boolean)


32
33
34
# File 'test_runner_formula.rb', line 32

def macos_compatible?
  !linux_only?
end

#macos_only?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.

Returns:

  • (Boolean)


27
28
29
# File 'test_runner_formula.rb', line 27

def macos_only?
  formula.requirements.any? { |r| r.is_a?(MacOSRequirement) && !r.version_specified? }
end

#versioned_macos_requirementMacOSRequirement?

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:



67
68
69
# File 'test_runner_formula.rb', line 67

def versioned_macos_requirement
  formula.requirements.find { |r| r.is_a?(MacOSRequirement) && r.version_specified? }
end

#x86_64_compatible?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.

Returns:

  • (Boolean)


52
53
54
# File 'test_runner_formula.rb', line 52

def x86_64_compatible?
  !arm64_only?
end

#x86_64_only?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.

Returns:

  • (Boolean)


47
48
49
# File 'test_runner_formula.rb', line 47

def x86_64_only?
  formula.requirements.any? { |r| r.is_a?(ArchRequirement) && (r.arch == :x86_64) }
end