From 9bd77b18197ecf5e3b4d048fb2452d7be474ee13 Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Tue, 17 Sep 2019 18:10:02 -0400 Subject: [PATCH 1/2] formula API: expose uses_from_macos list --- Library/Homebrew/extend/os/mac/software_spec.rb | 8 +++++++- Library/Homebrew/formula.rb | 5 +++++ Library/Homebrew/software_spec.rb | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/software_spec.rb b/Library/Homebrew/extend/os/mac/software_spec.rb index 970a1aa94e..3e1dfd1c1b 100644 --- a/Library/Homebrew/extend/os/mac/software_spec.rb +++ b/Library/Homebrew/extend/os/mac/software_spec.rb @@ -4,12 +4,18 @@ class SoftwareSpec undef uses_from_macos def uses_from_macos(deps, **args) + @uses_from_macos_elements ||= [] + if deps.is_a?(Hash) args = deps deps = Hash[*args.shift] end - depends_on(deps) if add_mac_dependency?(args) + if add_mac_dependency?(args) + depends_on(deps) + else + @uses_from_macos_elements << deps + end end private diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 3e22bd8d11..047c4271b1 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -428,6 +428,9 @@ class Formula # The {Dependency}s for the currently active {SoftwareSpec}. delegate deps: :active_spec + # Dependencies provided by macOS for the currently active {SoftwareSpec}. + delegate uses_from_macos_elements: :active_spec + # The {Requirement}s for the currently active {SoftwareSpec}. delegate requirements: :active_spec @@ -1589,6 +1592,7 @@ class Formula # @private def to_hash dependencies = deps + uses_from_macos = uses_from_macos_elements || [] hsh = { "name" => name, @@ -1624,6 +1628,7 @@ class Formula "optional_dependencies" => dependencies.select(&:optional?) .map(&:name) .uniq, + "uses_from_macos" => uses_from_macos.uniq, "requirements" => [], "conflicts_with" => conflicts.map(&:name), "caveats" => caveats&.gsub(HOMEBREW_PREFIX, "$(brew --prefix)"), diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index fb2d8646ba..5beee67ca7 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -26,6 +26,7 @@ class SoftwareSpec attr_reader :dependency_collector attr_reader :bottle_specification attr_reader :compiler_failures + attr_reader :uses_from_macos_elements def_delegators :@resource, :stage, :fetch, :verify_download_integrity, :source_modified_time def_delegators :@resource, :download_name, :cached_download, :clear_cache From f6ef26a127fdcc2687004ffef198f519fd160cfd Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Tue, 17 Sep 2019 18:34:37 -0400 Subject: [PATCH 2/2] Fix OS version logic for uses_from_macos --- .../Homebrew/extend/os/mac/software_spec.rb | 4 ++-- .../test/os/mac/software_spec_spec.rb | 21 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/software_spec.rb b/Library/Homebrew/extend/os/mac/software_spec.rb index 3e1dfd1c1b..4f6f9aef27 100644 --- a/Library/Homebrew/extend/os/mac/software_spec.rb +++ b/Library/Homebrew/extend/os/mac/software_spec.rb @@ -23,9 +23,9 @@ class SoftwareSpec def add_mac_dependency?(args) args.each { |key, version| args[key] = OS::Mac::Version.from_symbol(version) } - return false if args[:after] && OS::Mac.version < args[:after] + return false if args[:after] && OS::Mac.version >= args[:after] - return false if args[:before] && OS::Mac.version >= args[:before] + return false if args[:before] && OS::Mac.version < args[:before] args.present? end diff --git a/Library/Homebrew/test/os/mac/software_spec_spec.rb b/Library/Homebrew/test/os/mac/software_spec_spec.rb index 63abc9e2d9..b6b8ed2be8 100644 --- a/Library/Homebrew/test/os/mac/software_spec_spec.rb +++ b/Library/Homebrew/test/os/mac/software_spec_spec.rb @@ -13,27 +13,30 @@ describe SoftwareSpec do allow(OS::Mac).to receive(:version).and_return(OS::Mac::Version.new(sierra_os_version)) end - it "allows specifying dependencies before certain version" do + it "allows specifying macOS dependencies before a certain version" do spec.uses_from_macos("foo", before: :high_sierra) - expect(spec.deps.first.name).to eq("foo") + expect(spec.deps).to be_empty + expect(spec.uses_from_macos_elements.first).to eq("foo") end - it "allows specifying dependencies after certain version" do + it "allows specifying macOS dependencies after a certain version" do spec.uses_from_macos("foo", after: :el_capitan) - expect(spec.deps.first.name).to eq("foo") + expect(spec.deps).to be_empty + expect(spec.uses_from_macos_elements.first).to eq("foo") end - it "doesn't adds a dependency if it doesn't meet OS version requirements" do + it "doesn't add a macOS dependency if the OS version doesn't meet requirements" do spec.uses_from_macos("foo", after: :high_sierra) spec.uses_from_macos("bar", before: :el_capitan) - expect(spec.deps).to be_empty + expect(spec.deps.first.name).to eq("foo") + expect(spec.uses_from_macos_elements).to be_empty end it "works with tags" do - spec.uses_from_macos("foo" => :head, :after => :el_capitan) + spec.uses_from_macos("foo" => :head, :after => :high_sierra) dep = spec.deps.first @@ -41,7 +44,7 @@ describe SoftwareSpec do expect(dep.tags).to include(:head) end - it "doesn't adds the dependency without OS version requirements" do + it "doesn't add a dependency if no OS version is specified" do spec.uses_from_macos("foo") spec.uses_from_macos("bar" => :head) @@ -49,7 +52,7 @@ describe SoftwareSpec do end it "respects OS version requirements with tags" do - spec.uses_from_macos("foo" => :head, :after => :mojave) + spec.uses_from_macos("foo" => :head, :before => :mojave) expect(spec.deps).to be_empty end