Class: TestRunnerFormula

Inherits:
Object show all
Defined in:
test_runner_formula.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formula, include_uninstalled: false) ⇒ 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)
  • include_uninstalled (Boolean) (defaults to: false)


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

def initialize(formula, include_uninstalled: false)
  Formulary.enable_factory_cache!
  @formula = formula
  @name = T.let(formula.name, String)
  @dependent_hash = T.let({}, T::Hash[Symbol, T::Array[TestRunnerFormula]])
  @include_uninstalled = include_uninstalled
  freeze
end

Instance Attribute Details

#formula ⇒ Formula (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

#include_uninstalled ⇒ Boolean (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 include_uninstalled
  @include_uninstalled
end

#name ⇒ String (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?(platform:, arch:, macos_version: nil) ⇒ 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)


81
82
83
84
85
86
# File 'test_runner_formula.rb', line 81

def compatible?(platform:, arch:, macos_version: nil)
  return false if macos_version && !compatible_with?(macos_version)
  return false unless public_send(:"#{platform}_compatible?")

  !!public_send(:"#{arch}_compatible?")
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

#compatible_with_tag?(tag) ⇒ 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.

Reloads the formula as the runner building tag bottles would so its on_* blocks apply.

Parameters:

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
98
# File 'test_runner_formula.rb', line 90

def compatible_with_tag?(tag)
  platform = tag.linux? ? :linux : :macos
  arch = tag.standardized_arch
  macos_version = tag.to_macos_version if tag.macos?

  Homebrew::SimulateSystem.with(os: tag.system, arch: Homebrew::SimulateSystem.arch_symbols.fetch(arch)) do
    TestRunnerFormula.new(Formulary.factory(formula.full_name)).compatible?(platform:, arch:, macos_version:)
  end
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:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'test_runner_formula.rb', line 107

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

  @dependent_hash[cache_key] ||= begin
    os = macos_version || platform
    arch = Homebrew::SimulateSystem.arch_symbols.fetch(arch)

    Homebrew::SimulateSystem.with(os:, arch:) do
      (include_uninstalled ? Formula.all : Formula.installed)
        .select { |candidate_f| candidate_f.deps.map(&:name).include?(name) }
        .map { |formula| TestRunnerFormula.new(formula, include_uninstalled:) }
        .freeze
    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?
  formula.supports_linux?
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?
  !macos_compatible?
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?
  formula.supports_macos?
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?
  !linux_compatible?
end

#versioned_macos_requirement ⇒ MacOSRequirement?

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