include OnSystem to define DSL methods

This commit is contained in:
Rylan Polster 2022-06-29 11:38:55 -04:00
parent ac067eedb2
commit a9e62b9e38
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
5 changed files with 18 additions and 25 deletions

View File

@ -92,6 +92,7 @@ module Cask
]).freeze
extend Predicable
include OnSystem
attr_reader :cask, :token
@ -319,8 +320,6 @@ module Cask
@livecheckable == true
end
OnSystem.setup_methods! onto: self, include_linux: false
ORDINARY_ARTIFACT_CLASSES.each do |klass|
define_method(klass.dsl_key) do |*args|
if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) &&

View File

@ -55,10 +55,10 @@ module OnSystem
method_name.to_s.sub(/^on_/, "").to_sym
end
sig { params(onto: Class, include_linux: T::Boolean).void }
def setup_methods!(onto:, include_linux: true)
sig { params(base: Class).void }
def self.included(base)
ARCH_OPTIONS.each do |arch|
onto.define_method("on_#{arch}") do |&block|
base.define_method("on_#{arch}") do |&block|
@on_system_blocks_exist = true
return unless OnSystem.arch_condition_met? OnSystem.condition_from_method_name(__method__)
@ -71,9 +71,8 @@ module OnSystem
end
end
if include_linux
BASE_OS_OPTIONS.each do |base_os|
onto.define_method("on_#{base_os}") do |&block|
base.define_method("on_#{base_os}") do |&block|
@on_system_blocks_exist = true
return unless OnSystem.os_condition_met? OnSystem.condition_from_method_name(__method__)
@ -85,10 +84,9 @@ module OnSystem
result
end
end
end
MacOSVersions::SYMBOLS.each_key do |os_name|
onto.define_method("on_#{os_name}") do |or_condition = nil, &block|
base.define_method("on_#{os_name}") do |or_condition = nil, &block|
@on_system_blocks_exist = true
os_condition = OnSystem.condition_from_method_name __method__

View File

@ -64,12 +64,11 @@ class Formula
include Utils::Shebang
include Utils::Shell
include Context
include OnSystem
extend Forwardable
extend Cachable
extend Predicable
OnSystem.setup_methods! onto: self
# @!method inreplace(paths, before = nil, after = nil)
# @see Utils::Inreplace.inreplace
@ -2471,6 +2470,7 @@ class Formula
# The methods below define the formula DSL.
class << self
include BuildEnvironment::DSL
include OnSystem
def method_added(method)
super
@ -2483,8 +2483,6 @@ class Formula
end
end
OnSystem.setup_methods! onto: self
# The reason for why this software is not linked (by default) to
# {::HOMEBREW_PREFIX}.
# @private

View File

@ -17,8 +17,7 @@ class Resource
include Context
include FileUtils
OnSystem.setup_methods! onto: self
include OnSystem
attr_reader :mirrors, :specs, :using, :source_modified_time, :patches, :owner
attr_writer :version

View File

@ -18,14 +18,13 @@ class SoftwareSpec
extend T::Sig
extend Forwardable
include OnSystem
PREDEFINED_OPTIONS = {
universal: Option.new("universal", "Build a universal binary"),
cxx11: Option.new("c++11", "Build using C++11 mode"),
}.freeze
OnSystem.setup_methods! onto: self
attr_reader :name, :full_name, :owner, :build, :resources, :patches, :options, :deprecated_flags,
:deprecated_options, :dependency_collector, :bottle_specification, :compiler_failures,
:uses_from_macos_elements
@ -584,7 +583,7 @@ class BottleSpecification
end
class PourBottleCheck
OnSystem.setup_methods! onto: self
include OnSystem
def initialize(formula)
@formula = formula