Merge branch 'Homebrew:master' into mohammad

This commit is contained in:
Mohammad Zain Abbas 2022-07-30 11:49:52 +02:00 committed by GitHub
commit a91dbd4a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 350 additions and 154 deletions

View File

@ -11,7 +11,7 @@ GEM
public_suffix (>= 2.0.2, < 5.0) public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2) ast (2.4.2)
bindata (2.4.10) bindata (2.4.10)
bootsnap (1.12.0) bootsnap (1.13.0)
msgpack (~> 1.2) msgpack (~> 1.2)
byebug (11.1.3) byebug (11.1.3)
coderay (1.1.3) coderay (1.1.3)

View File

@ -556,6 +556,9 @@ EOS
[[ -d "${DIR}/.git" ]] || continue [[ -d "${DIR}/.git" ]] || continue
cd "${DIR}" || continue cd "${DIR}" || continue
# Git's fsmonitor prevents the release of our locks
git config --bool core.fsmonitor false
if ! git config --local --get remote.origin.url &>/dev/null if ! git config --local --get remote.origin.url &>/dev/null
then then
opoo "No remote 'origin' in ${DIR}, skipping update!" opoo "No remote 'origin' in ${DIR}, skipping update!"

View File

@ -15,8 +15,7 @@ module OnSystem
def arch_condition_met?(arch) def arch_condition_met?(arch)
raise ArgumentError, "Invalid arch condition: #{arch.inspect}" if ARCH_OPTIONS.exclude?(arch) raise ArgumentError, "Invalid arch condition: #{arch.inspect}" if ARCH_OPTIONS.exclude?(arch)
current_arch = Homebrew::SimulateSystem.arch || Hardware::CPU.type arch == Homebrew::SimulateSystem.current_arch
arch == current_arch
end end
sig { params(os_name: Symbol, or_condition: T.nilable(Symbol)).returns(T::Boolean) } sig { params(os_name: Symbol, or_condition: T.nilable(Symbol)).returns(T::Boolean) }
@ -26,14 +25,7 @@ module OnSystem
return true if [:macos, *MacOSVersions::SYMBOLS.keys].include?(os_name) return true if [:macos, *MacOSVersions::SYMBOLS.keys].include?(os_name)
end end
if BASE_OS_OPTIONS.include?(os_name) return Homebrew::SimulateSystem.send("simulating_or_running_on_#{os_name}?") if BASE_OS_OPTIONS.include?(os_name)
if Homebrew::SimulateSystem.none?
return OS.linux? if os_name == :linux
return OS.mac? if os_name == :macos
end
return Homebrew::SimulateSystem.send("#{os_name}?")
end
raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name) raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name)
@ -41,10 +33,10 @@ module OnSystem
raise ArgumentError, "Invalid OS `or_*` condition: #{or_condition.inspect}" raise ArgumentError, "Invalid OS `or_*` condition: #{or_condition.inspect}"
end end
return false if Homebrew::SimulateSystem.linux? || (Homebrew::SimulateSystem.none? && OS.linux?) return false if Homebrew::SimulateSystem.simulating_or_running_on_linux?
base_os = MacOS::Version.from_symbol(os_name) base_os = MacOS::Version.from_symbol(os_name)
current_os = MacOS::Version.from_symbol(Homebrew::SimulateSystem.os || MacOS.version.to_sym) current_os = MacOS::Version.from_symbol(Homebrew::SimulateSystem.current_os)
return current_os >= base_os if or_condition == :or_newer return current_os >= base_os if or_condition == :or_newer
return current_os <= base_os if or_condition == :or_older return current_os <= base_os if or_condition == :or_older

View File

@ -23,17 +23,4 @@ class Formula
sig { params(targets: T.nilable(T.any(Pathname, String))).void } sig { params(targets: T.nilable(T.any(Pathname, String))).void }
def deuniversalize_machos(*targets); end def deuniversalize_machos(*targets); end
class << self
undef ignore_missing_libraries
def ignore_missing_libraries(*libs)
libraries = libs.flatten
if libraries.any? { |x| !x.is_a?(String) && !x.is_a?(Regexp) }
raise FormulaSpecificationError, "#{__method__} can handle Strings and Regular Expressions only"
end
allowed_missing_libraries.merge(libraries)
end
end
end end

View File

@ -1,27 +0,0 @@
# typed: true
# frozen_string_literal: true
# The Library/Homebrew/extend/os/software_spec.rb conditional logic will need to be more nuanced
# if this file ever includes more than `uses_from_macos`.
class SoftwareSpec
undef uses_from_macos
def uses_from_macos(deps, bounds = {})
if deps.is_a?(Hash)
bounds = deps.dup
deps = [bounds.shift].to_h
end
@uses_from_macos_elements << deps
bounds = bounds.transform_values { |v| MacOS::Version.from_symbol(v) }
# Linux simulating macOS. Assume oldest macOS version.
return if Homebrew::EnvConfig.simulate_macos_on_linux? && !bounds.key?(:since)
# macOS new enough for dependency to not be required.
return if MacOS.version >= bounds[:since]
depends_on deps
end
end

View File

@ -1,9 +1,4 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
# This logic will need to be more nuanced if this file includes more than `uses_from_macos`. require "extend/os/linux/software_spec" if OS.linux?
if OS.mac? || Homebrew::EnvConfig.simulate_macos_on_linux?
require "extend/os/mac/software_spec"
elsif OS.linux?
require "extend/os/linux/software_spec"
end

View File

@ -3214,12 +3214,19 @@ class Formula
end end
# Permit links to certain libraries that don't exist. Available on Linux only. # Permit links to certain libraries that don't exist. Available on Linux only.
def ignore_missing_libraries(*) def ignore_missing_libraries(*libs)
return if Homebrew::SimulateSystem.linux? unless Homebrew::SimulateSystem.simulating_or_running_on_linux?
raise FormulaSpecificationError, "#{__method__} is available on Linux only" raise FormulaSpecificationError, "#{__method__} is available on Linux only"
end end
libraries = libs.flatten
if libraries.any? { |x| !x.is_a?(String) && !x.is_a?(Regexp) }
raise FormulaSpecificationError, "#{__method__} can handle Strings and Regular Expressions only"
end
allowed_missing_libraries.merge(libraries)
end
# @private # @private
def allowed_missing_libraries def allowed_missing_libraries
@allowed_missing_libraries ||= Set.new @allowed_missing_libraries ||= Set.new

View File

@ -307,6 +307,13 @@ module Homebrew
EOS EOS
end end
if dep_f.deprecated? && !formula.deprecated? && !formula.disabled?
problem <<~EOS
Dependency '#{dep.name}' is deprecated but has un-deprecated dependents. Either
un-deprecate '#{dep.name}' or deprecate it and all of its dependents.
EOS
end
# we want to allow uses_from_macos for aliases but not bare dependencies # we want to allow uses_from_macos for aliases but not bare dependencies
if self.class.aliases.include?(dep.name) && spec.uses_from_macos_names.exclude?(dep.name) if self.class.aliases.include?(dep.name) && spec.uses_from_macos_names.exclude?(dep.name)
problem "Dependency '#{dep.name}' is an alias; use the canonical name '#{dep.to_formula.full_name}'." problem "Dependency '#{dep.name}' is an alias; use the canonical name '#{dep.to_formula.full_name}'."
@ -410,13 +417,11 @@ module Homebrew
end end
def audit_glibc def audit_glibc
return if formula.name != "glibc"
return unless @core_tap return unless @core_tap
return if formula.name != "glibc"
return if [OS::CI_GLIBC_VERSION, "2.27", "2.31", "2.35"].include?(formula.version.to_s)
version = formula.version.to_s problem "The glibc version must be #{OS::CI_GLIBC_VERSION}, as this is the version used by our CI on Linux. " \
return if version == OS::CI_GLIBC_VERSION
problem "The glibc version must be #{version}, as this is the version used by our CI on Linux. " \
"Glibc is for users who have a system Glibc with a lower version, " \ "Glibc is for users who have a system Glibc with a lower version, " \
"which allows them to use our Linux bottles, which were compiled against system Glibc on CI." "which allows them to use our Linux bottles, which were compiled against system Glibc on CI."
end end

View File

@ -136,6 +136,18 @@ module Formulary
class_s = Formulary.class_s(name) class_s = Formulary.class_s(name)
json_formula = Homebrew::API::Formula.all_formulae[name] json_formula = Homebrew::API::Formula.all_formulae[name]
if (bottle_tag = Utils::Bottles.tag.to_s.presence) &&
(variations = json_formula["variations"].presence) &&
(variation = variations[bottle_tag].presence)
json_formula = json_formula.merge(variation)
end
uses_from_macos_names = json_formula["uses_from_macos"].map do |dep|
next dep unless dep.is_a? Hash
dep.keys.first
end
klass = Class.new(::Formula) do klass = Class.new(::Formula) do
desc json_formula["desc"] desc json_formula["desc"]
homepage json_formula["homepage"] homepage json_formula["homepage"]
@ -176,20 +188,18 @@ module Formulary
disable! date: disable_date, because: reason disable! date: disable_date, because: reason
end end
json_formula["build_dependencies"].each do |dep|
depends_on dep => :build
end
json_formula["dependencies"].each do |dep| json_formula["dependencies"].each do |dep|
next if uses_from_macos_names.include? dep
depends_on dep depends_on dep
end end
json_formula["recommended_dependencies"].each do |dep| [:build, :recommended, :optional].each do |type|
depends_on dep => :recommended json_formula["#{type}_dependencies"].each do |dep|
end next if uses_from_macos_names.include? dep
json_formula["optional_dependencies"].each do |dep| depends_on dep => type
depends_on dep => :optional end
end end
json_formula["uses_from_macos"].each do |dep| json_formula["uses_from_macos"].each do |dep|

View File

@ -32,19 +32,31 @@ module Homebrew
end end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def none? def simulating_or_running_on_macos?
@os.nil? && @arch.nil? return OS.mac? if @os.blank?
end
sig { returns(T::Boolean) }
def macos?
[:macos, *MacOSVersions::SYMBOLS.keys].include?(@os) [:macos, *MacOSVersions::SYMBOLS.keys].include?(@os)
end end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def linux? def simulating_or_running_on_linux?
return OS.linux? if @os.blank?
@os == :linux @os == :linux
end end
sig { returns(Symbol) }
def current_arch
@arch || Hardware::CPU.type
end
sig { returns(Symbol) }
def current_os
return @os if @os.present?
return :linux if OS.linux?
MacOS.version.to_sym
end
end end
end end
end end

View File

@ -162,12 +162,25 @@ class SoftwareSpec
add_dep_option(dep) if dep add_dep_option(dep) if dep
end end
def uses_from_macos(spec, _bounds = {}) def uses_from_macos(deps, bounds = {})
spec = [spec.dup.shift].to_h if spec.is_a?(Hash) if deps.is_a?(Hash)
bounds = deps.dup
deps = [bounds.shift].to_h
end
@uses_from_macos_elements << spec @uses_from_macos_elements << deps
depends_on(spec) # Linux simulating macOS. Assume oldest macOS version.
return if Homebrew::EnvConfig.simulate_macos_on_linux? && !bounds.key?(:since)
# macOS new enough for dependency to not be required.
if Homebrew::SimulateSystem.simulating_or_running_on_macos?
current_os = MacOS::Version.from_symbol(Homebrew::SimulateSystem.current_os)
since_os = MacOS::Version.from_symbol(bounds[:since]) if bounds.key?(:since)
return if current_os >= since_os
end
depends_on deps
end end
def uses_from_macos_names def uses_from_macos_names

View File

@ -1845,4 +1845,52 @@ describe Formula do
expect(f.test).to eq(2) expect(f.test).to eq(2)
end end
end end
describe "#ignore_missing_libraries" do
after do
Homebrew::SimulateSystem.clear
end
it "adds library to allowed_missing_libraries on Linux", :needs_linux do
Homebrew::SimulateSystem.clear
f = formula do
url "foo-1.0"
ignore_missing_libraries "bar.so"
end
expect(f.class.allowed_missing_libraries.to_a).to eq(["bar.so"])
end
it "adds library to allowed_missing_libraries on macOS when simulating Linux", :needs_macos do
Homebrew::SimulateSystem.os = :linux
f = formula do
url "foo-1.0"
ignore_missing_libraries "bar.so"
end
expect(f.class.allowed_missing_libraries.to_a).to eq(["bar.so"])
end
it "raises an error on macOS", :needs_macos do
Homebrew::SimulateSystem.clear
expect {
formula do
url "foo-1.0"
ignore_missing_libraries "bar.so"
end
}.to raise_error("ignore_missing_libraries is available on Linux only")
end
it "raises an error on Linux when simulating macOS", :needs_linux do
Homebrew::SimulateSystem.os = :macos
expect {
formula do
url "foo-1.0"
ignore_missing_libraries "bar.so"
end
}.to raise_error("ignore_missing_libraries is available on Linux only")
end
end
end end

View File

@ -260,6 +260,26 @@ describe Formulary do
} }
end end
let(:variations_json) do
{
"variations" => {
Utils::Bottles.tag.to_s => {
"dependencies" => ["dep", "variations_dep"],
},
},
}
end
let(:linux_variations_json) do
{
"variations" => {
"x86_64_linux" => {
"dependencies" => ["dep", "uses_from_macos_dep"],
},
},
}
end
before do before do
allow(described_class).to receive(:loader_for).and_return(described_class::FormulaAPILoader.new(formula_name)) allow(described_class).to receive(:loader_for).and_return(described_class::FormulaAPILoader.new(formula_name))
end end
@ -303,6 +323,25 @@ describe Formulary do
formula.install formula.install
}.to raise_error("Cannot build from source from abstract formula.") }.to raise_error("Cannot build from source from abstract formula.")
end end
it "returns a Formula with variations when given a name", :needs_macos do
allow(Homebrew::API::Formula).to receive(:all_formulae).and_return formula_json_contents(variations_json)
formula = described_class.factory(formula_name)
expect(formula).to be_kind_of(Formula)
expect(formula.deps.count).to eq 5
expect(formula.deps.map(&:name).include?("variations_dep")).to be true
end
it "returns a Formula without duplicated deps and uses_from_macos with variations on Linux", :needs_linux do
allow(Homebrew::API::Formula)
.to receive(:all_formulae).and_return formula_json_contents(linux_variations_json)
formula = described_class.factory(formula_name)
expect(formula).to be_kind_of(Formula)
expect(formula.deps.count).to eq 5
expect(formula.deps.map(&:name).include?("uses_from_macos_dep")).to be true
end
end end
end end

View File

@ -1,51 +0,0 @@
# typed: false
# frozen_string_literal: true
require "software_spec"
describe SoftwareSpec do
subject(:spec) { described_class.new }
describe "#uses_from_macos" do
before do
allow(OS).to receive(:mac?).and_return(true)
allow(OS::Mac).to receive(:version).and_return(OS::Mac::Version.from_symbol(:sierra))
end
it "adds a macOS dependency if the OS version meets requirements" do
spec.uses_from_macos("foo", since: :el_capitan)
expect(spec.deps).to be_empty
expect(spec.uses_from_macos_elements.first).to eq("foo")
end
it "doesn't add a macOS dependency if the OS version doesn't meet requirements" do
spec.uses_from_macos("foo", since: :high_sierra)
expect(spec.deps.first.name).to eq("foo")
expect(spec.uses_from_macos_elements).to eq(["foo"])
end
it "works with tags" do
spec.uses_from_macos("foo" => :build, :since => :high_sierra)
dep = spec.deps.first
expect(dep.name).to eq("foo")
expect(dep.tags).to include(:build)
end
it "doesn't add a dependency if no OS version is specified" do
spec.uses_from_macos("foo")
spec.uses_from_macos("bar" => :build)
expect(spec.deps).to be_empty
end
it "raises an error if passing invalid OS versions" do
expect {
spec.uses_from_macos("foo", since: :bar)
}.to raise_error(MacOSVersionError, "unknown or unsupported macOS version: :bar")
end
end
end

View File

@ -0,0 +1,118 @@
# typed: false
# frozen_string_literal: true
require "settings"
describe Homebrew::SimulateSystem do
after do
described_class.clear
end
describe "::simulating_or_running_on_macos?" do
it "returns true on macOS", :needs_macos do
described_class.clear
expect(described_class.simulating_or_running_on_macos?).to be true
end
it "returns false on Linux", :needs_linux do
described_class.clear
expect(described_class.simulating_or_running_on_macos?).to be false
end
it "returns false on macOS when simulating Linux", :needs_macos do
described_class.clear
described_class.os = :linux
expect(described_class.simulating_or_running_on_macos?).to be false
end
it "returns true on Linux when simulating a generic macOS version", :needs_linux do
described_class.clear
described_class.os = :macos
expect(described_class.simulating_or_running_on_macos?).to be true
end
it "returns true on Linux when simulating a specific macOS version", :needs_linux do
described_class.clear
described_class.os = :monterey
expect(described_class.simulating_or_running_on_macos?).to be true
end
end
describe "::simulating_or_running_on_linux?" do
it "returns true on Linux", :needs_linux do
described_class.clear
expect(described_class.simulating_or_running_on_linux?).to be true
end
it "returns false on macOS", :needs_macos do
described_class.clear
expect(described_class.simulating_or_running_on_linux?).to be false
end
it "returns true on macOS when simulating Linux", :needs_macos do
described_class.clear
described_class.os = :linux
expect(described_class.simulating_or_running_on_linux?).to be true
end
it "returns false on Linux when simulating a generic macOS version", :needs_linux do
described_class.clear
described_class.os = :macos
expect(described_class.simulating_or_running_on_linux?).to be false
end
it "returns false on Linux when simulating a specific macOS version", :needs_linux do
described_class.clear
described_class.os = :monterey
expect(described_class.simulating_or_running_on_linux?).to be false
end
end
describe "::current_arch" do
it "returns the current architecture" do
described_class.clear
expect(described_class.current_arch).to eq Hardware::CPU.type
end
it "returns the simulated architecture" do
described_class.clear
simulated_arch = if Hardware::CPU.arm?
:intel
else
:arm
end
described_class.arch = simulated_arch
expect(described_class.current_arch).to eq simulated_arch
end
end
describe "::current_os" do
it "returns the current macOS version on macOS", :needs_macos do
described_class.clear
expect(described_class.current_os).to eq MacOS.version.to_sym
end
it "returns `:linux` on Linux", :needs_linux do
described_class.clear
expect(described_class.current_os).to eq :linux
end
it "returns `:linux` when simulating Linux on macOS", :needs_macos do
described_class.clear
described_class.os = :linux
expect(described_class.current_os).to eq :linux
end
it "returns `:macos` when simulating a generic macOS version on Linux", :needs_linux do
described_class.clear
described_class.os = :macos
expect(described_class.current_os).to eq :macos
end
it "returns `:macos` when simulating a specific macOS version on Linux", :needs_linux do
described_class.clear
described_class.os = :monterey
expect(described_class.current_os).to eq :monterey
end
end
end

View File

@ -135,21 +135,22 @@ describe SoftwareSpec do
end end
end end
describe "#uses_from_macos" do describe "#uses_from_macos", :needs_linux do
it "allows specifying dependencies", :needs_linux do context "when running on Linux", :needs_linux do
it "allows specifying dependencies" do
spec.uses_from_macos("foo") spec.uses_from_macos("foo")
expect(spec.deps.first.name).to eq("foo") expect(spec.deps.first.name).to eq("foo")
end end
it "works with tags", :needs_linux do it "works with tags" do
spec.uses_from_macos("foo" => :build) spec.uses_from_macos("foo" => :build)
expect(spec.deps.first.name).to eq("foo") expect(spec.deps.first.name).to eq("foo")
expect(spec.deps.first.tags).to include(:build) expect(spec.deps.first.tags).to include(:build)
end end
it "ignores OS version specifications", :needs_linux do it "ignores OS version specifications" do
spec.uses_from_macos("foo", since: :mojave) spec.uses_from_macos("foo", since: :mojave)
spec.uses_from_macos("bar" => :build, :since => :mojave) spec.uses_from_macos("bar" => :build, :since => :mojave)
@ -159,6 +160,50 @@ describe SoftwareSpec do
end end
end end
context "when running on macOS", :needs_macos do
before do
allow(OS).to receive(:mac?).and_return(true)
allow(OS::Mac).to receive(:version).and_return(OS::Mac::Version.from_symbol(:sierra))
end
it "adds a macOS dependency if the OS version meets requirements" do
spec.uses_from_macos("foo", since: :el_capitan)
expect(spec.deps).to be_empty
expect(spec.uses_from_macos_elements.first).to eq("foo")
end
it "doesn't add a macOS dependency if the OS version doesn't meet requirements" do
spec.uses_from_macos("foo", since: :high_sierra)
expect(spec.deps.first.name).to eq("foo")
expect(spec.uses_from_macos_elements).to eq(["foo"])
end
it "works with tags" do
spec.uses_from_macos("foo" => :build, :since => :high_sierra)
dep = spec.deps.first
expect(dep.name).to eq("foo")
expect(dep.tags).to include(:build)
end
it "doesn't add a dependency if no OS version is specified" do
spec.uses_from_macos("foo")
spec.uses_from_macos("bar" => :build)
expect(spec.deps).to be_empty
end
it "raises an error if passing invalid OS versions" do
expect {
spec.uses_from_macos("foo", since: :bar)
}.to raise_error(MacOSVersionError, "unknown or unsupported macOS version: :bar")
end
end
end
specify "explicit options override defaupt depends_on option description" do specify "explicit options override defaupt depends_on option description" do
spec.option("with-foo", "blah") spec.option("with-foo", "blah")
spec.depends_on("foo" => :optional) spec.depends_on("foo" => :optional)

View File

@ -15,8 +15,8 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ast-2.4.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/bindata-2.4.10/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/bindata-2.4.10/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-15/2.6.0-static/msgpack-1.5.4" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-15/2.6.0-static/msgpack-1.5.4"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/msgpack-1.5.4/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/msgpack-1.5.4/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-15/2.6.0-static/bootsnap-1.12.0" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-15/2.6.0-static/bootsnap-1.13.0"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/bootsnap-1.12.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/bootsnap-1.13.0/lib"
$:.unshift "#{path}/" $:.unshift "#{path}/"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-15/2.6.0-static/byebug-11.1.3" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-15/2.6.0-static/byebug-11.1.3"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/byebug-11.1.3/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/byebug-11.1.3/lib"