Skip to content

Commit

Permalink
Merge pull request #9403 from MikeMcQuaid/deprecate-cask-requirements
Browse files Browse the repository at this point in the history
Deprecate cask requirements.
  • Loading branch information
MikeMcQuaid committed Dec 18, 2020
2 parents 9db324a + 87dd13a commit 010ae37
Show file tree
Hide file tree
Showing 24 changed files with 50 additions and 252 deletions.
1 change: 0 additions & 1 deletion Library/Homebrew/build.rb
Expand Up @@ -87,7 +87,6 @@ def install
ENV.keg_only_deps = keg_only_deps
ENV.deps = formula_deps
ENV.run_time_deps = run_time_deps
ENV.x11 = reqs.any? { |rq| rq.is_a?(X11Requirement) }
ENV.setup_build_environment(
formula: formula,
cc: args.cc,
Expand Down
11 changes: 9 additions & 2 deletions Library/Homebrew/cask/dsl/depends_on.rb
Expand Up @@ -27,8 +27,7 @@ class DependsOn < SimpleDelegator
arm64: { type: :arm, bits: 64 },
}.freeze

attr_accessor :java
attr_reader :arch, :cask, :formula, :macos, :x11
attr_reader :arch, :cask, :formula, :java, :macos, :x11

def initialize
super({})
Expand Down Expand Up @@ -83,9 +82,17 @@ def arch=(*args)
@arch.concat(arches.map { |arch| VALID_ARCHES[arch] })
end

def java=(arg)
odeprecated "depends_on :java", "depends_on a specific Java formula"

@java = arg
end

def x11=(arg)
raise "invalid 'depends_on x11' value: #{arg.inspect}" unless [true, false].include?(arg)

odeprecated "depends_on :x11", "depends_on specific X11 formula(e)"

@x11 = arg
end
end
Expand Down
5 changes: 1 addition & 4 deletions Library/Homebrew/dev-cmd/sh.rb
Expand Up @@ -36,10 +36,7 @@ def sh

ENV.activate_extensions!(env: args.env)

if superenv?(args.env)
ENV.set_x11_env_if_installed
ENV.deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? }
end
ENV.deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? } if superenv?(args.env)
ENV.setup_build_environment
if superenv?(args.env)
# superenv stopped adding brew's bin but generally users will want it
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/extend/ENV/std.rb
Expand Up @@ -209,7 +209,9 @@ def set_cpu_flags(flags, map = Hardware::CPU.optimization_flags)
end

sig { void }
def x11; end
def x11
odeprecated "ENV.x11", "depends_on specific X11 formula(e)"
end

# @private
sig { params(map: T::Hash[Symbol, String]).void }
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/extend/ENV/super.rb
Expand Up @@ -343,7 +343,9 @@ def refurbish_args
end

sig { void }
def set_x11_env_if_installed; end
def set_x11_env_if_installed
odeprecated "ENV.set_x11_env_if_installed"
end
end

require "extend/os/extend/ENV/super"
Expand Up @@ -6,6 +6,11 @@
class OsxfuseRequirement < Requirement
extend T::Sig

def initialize(tags = [])
odeprecated "depends_on :osxfuse", 'on_linux do; depends_on "libfuse"; end'
super(tags)
end

download "https://github.com/libfuse/libfuse"

satisfy(build_env: false) do
Expand Down
25 changes: 1 addition & 24 deletions Library/Homebrew/extend/os/mac/extend/ENV/std.rb
Expand Up @@ -4,35 +4,12 @@
module Stdenv
# @private

undef homebrew_extra_pkg_config_paths, x11
undef homebrew_extra_pkg_config_paths

def homebrew_extra_pkg_config_paths
["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.sdk_version}"]
end

def x11
# There are some config scripts here that should go in the PATH
append_path "PATH", MacOS::XQuartz.bin.to_s

# Append these to PKG_CONFIG_LIBDIR so they are searched
# *after* our own pkgconfig directories, as we dupe some of the
# libs in XQuartz.
append_path "PKG_CONFIG_LIBDIR", "#{MacOS::XQuartz.lib}/pkgconfig"
append_path "PKG_CONFIG_LIBDIR", "#{MacOS::XQuartz.share}/pkgconfig"

append "LDFLAGS", "-L#{MacOS::XQuartz.lib}"
append_path "CMAKE_PREFIX_PATH", MacOS::XQuartz.prefix.to_s
append_path "CMAKE_INCLUDE_PATH", MacOS::XQuartz.include.to_s
append_path "CMAKE_INCLUDE_PATH", "#{MacOS::XQuartz.include}/freetype2"

append "CPPFLAGS", "-I#{MacOS::XQuartz.include}"
append "CPPFLAGS", "-I#{MacOS::XQuartz.include}/freetype2"

append_path "ACLOCAL_PATH", "#{MacOS::XQuartz.share}/aclocal"

append "CFLAGS", "-I#{MacOS::XQuartz.include}" unless MacOS::CLT.installed?
end

def setup_build_environment(**options)
generic_setup_build_environment(**options)

Expand Down
6 changes: 1 addition & 5 deletions Library/Homebrew/extend/os/mac/extend/ENV/super.rb
Expand Up @@ -23,7 +23,7 @@ def bin
homebrew_extra_cmake_include_paths,
homebrew_extra_cmake_library_paths,
homebrew_extra_cmake_frameworks_paths,
determine_cccfg, set_x11_env_if_installed
determine_cccfg

def homebrew_extra_paths
paths = []
Expand Down Expand Up @@ -105,10 +105,6 @@ def determine_cccfg
s.freeze
end

def set_x11_env_if_installed
ENV.x11 = MacOS::XQuartz.installed?
end

# @private
def setup_build_environment(**options)
formula = options[:formula]
Expand Down
Expand Up @@ -6,6 +6,11 @@
class OsxfuseRequirement < Requirement
extend T::Sig

def initialize(tags = [])
odeprecated "depends_on :osxfuse"
super(tags)
end

download "https://osxfuse.github.io/"

satisfy(build_env: false) { self.class.binary_osxfuse_installed? }
Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/formula.rb
Expand Up @@ -2526,9 +2526,6 @@ def go_resource(name, &block)
# depends_on "sqlite" if MacOS.version >= :catalina
# depends_on xcode: :build # If the formula really needs full Xcode to compile.
# depends_on macos: :mojave # Needs at least macOS Mojave (10.14) to run.
# depends_on x11: :optional # X11/XQuartz components.
# depends_on :osxfuse # Permits the use of the upstream signed binary or our cask.
# depends_on :tuntap # Does the same thing as above. This is vital for Yosemite and later.</pre>
# <pre># It is possible to only depend on something if
# # `build.with?` or `build.without? "another_formula"`:
# depends_on "postgresql" if build.without? "sqlite"</pre>
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/requirements/tuntap_requirement.rb
Expand Up @@ -9,6 +9,11 @@
class TuntapRequirement < Requirement
extend T::Sig

def initialize(tags = [])
odeprecated "depends_on :tuntap"
super(tags)
end

fatal true
cask "tuntap"
satisfy(build_env: false) { self.class.binary_tuntap_installed? }
Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/requirements/x11_requirement.rb
Expand Up @@ -8,16 +8,18 @@
# @api private
class X11Requirement < Requirement
extend T::Sig

include Comparable

def initialize(tags = [])
odeprecated "depends_on :x11", "depends_on specific X11 formula(e)"
super(tags)
end

fatal true

cask "xquartz"
download "https://xquartz.macosforge.org"

env { ENV.x11 }

sig { returns(String) }
def min_version
"1.12.2"
Expand Down
4 changes: 0 additions & 4 deletions Library/Homebrew/rubocops/lines.rb
Expand Up @@ -551,10 +551,6 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated."
end

find_instance_method_call(body_node, "ENV", :x11) do
problem 'Use "depends_on :x11" instead of "ENV.x11"'
end

find_every_method_call_by_name(body_node, :depends_on).each do |method|
next unless method_called?(method, :new)

Expand Down
33 changes: 0 additions & 33 deletions Library/Homebrew/test/cask/depends_on_spec.rb
Expand Up @@ -74,37 +74,4 @@
end
end
end

describe "depends_on x11" do
before do
allow(MacOS::XQuartz).to receive(:installed?).and_return(x11_installed)
end

context "when satisfied" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-x11")) }
let(:x11_installed) { true }

it "does not raise an error" do
expect { install }.not_to raise_error
end
end

context "when not satisfied" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-x11")) }
let(:x11_installed) { false }

it "does not raise an error" do
expect { install }.to raise_error Cask::CaskX11DependencyError
end
end

context "when depends_on x11: false" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-depends-on-x11-false")) }
let(:x11_installed) { false }

it "does not raise an error" do
expect { install }.not_to raise_error
end
end
end
end
8 changes: 0 additions & 8 deletions Library/Homebrew/test/cask/dsl_spec.rb
Expand Up @@ -410,14 +410,6 @@ def caveats
end

describe "depends_on x11" do
context "valid" do
let(:token) { "with-depends-on-x11" }

it "is allowed to be specified" do
expect(cask.depends_on.x11).not_to be nil
end
end

context "invalid depends_on x11 value" do
let(:token) { "invalid/invalid-depends-on-x11-value" }

Expand Down
7 changes: 2 additions & 5 deletions Library/Homebrew/test/cask_dependent_spec.rb
Expand Up @@ -13,7 +13,6 @@
depends_on formula: "baz"
depends_on cask: "foo-cask"
depends_on macos: ">= :mojave"
depends_on x11: true
end
RUBY
end
Expand All @@ -28,7 +27,7 @@
describe "#requirements" do
it "is the requirements of the cask" do
expect(dependent.requirements.map(&:name))
.to eq %w[foo-cask macos x11]
.to eq %w[foo-cask macos]
end
end

Expand All @@ -39,7 +38,6 @@
setup_test_formula "baz", <<-RUBY
url "https://brew.sh/baz-1.0"
depends_on "bar"
depends_on :osxfuse
RUBY

expect(dependent.recursive_dependencies.map(&:name))
Expand All @@ -54,11 +52,10 @@
setup_test_formula "baz", <<-RUBY
url "https://brew.sh/baz-1.0"
depends_on "bar"
depends_on :osxfuse
RUBY

expect(dependent.recursive_requirements.map(&:name))
.to eq(%w[foo-cask macos x11 osxfuse])
.to eq(%w[foo-cask macos])
end
end
end
18 changes: 3 additions & 15 deletions Library/Homebrew/test/dependency_collector_spec.rb
Expand Up @@ -27,32 +27,20 @@ def find_requirement(klass)
end

specify "requirement creation" do
subject.add :x11
expect(find_requirement(X11Requirement)).to be_an_instance_of(X11Requirement)
subject.add :xcode
expect(find_requirement(XcodeRequirement)).to be_an_instance_of(XcodeRequirement)
end

it "deduplicates requirements" do
2.times { subject.add :x11 }
2.times { subject.add :xcode }
expect(subject.requirements.count).to eq(1)
end

specify "requirement tags" do
subject.add :x11
subject.add xcode: :build
expect(find_requirement(X11Requirement).tags).to be_empty
expect(find_requirement(XcodeRequirement)).to be_a_build_requirement
end

specify "x11 without tag" do
subject.add :x11
expect(find_requirement(X11Requirement).tags).to be_empty
end

specify "x11 with tag" do
subject.add x11: :optional
expect(find_requirement(X11Requirement)).to be_optional
end

it "doesn't mutate the dependency spec" do
spec = { "foo" => :optional }
copy = spec.dup
Expand Down
14 changes: 6 additions & 8 deletions Library/Homebrew/test/formula_spec.rb
Expand Up @@ -794,17 +794,15 @@
f1 = formula "f1" do
url "f1-1"

depends_on x11: :recommended
depends_on xcode: ["1.0", :optional]
end
stub_formula_loader(f1)

x11 = X11Requirement.new([:recommended])
xcode = XcodeRequirement.new(["1.0", :optional])

expect(Set.new(f1.recursive_requirements)).to eq(Set[x11])
expect(Set.new(f1.recursive_requirements)).to eq(Set[])

f1.build = BuildOptions.new(["--with-xcode", "--without-x11"], f1.options)
f1.build = BuildOptions.new(["--with-xcode"], f1.options)

expect(Set.new(f1.recursive_requirements)).to eq(Set[xcode])

Expand All @@ -815,14 +813,14 @@
depends_on "f1"
end

expect(Set.new(f2.recursive_requirements)).to eq(Set[x11])
expect(Set.new(f2.recursive_requirements {})).to eq(Set[x11, xcode])
expect(Set.new(f2.recursive_requirements)).to eq(Set[])
expect(Set.new(f2.recursive_requirements {})).to eq(Set[xcode])

requirements = f2.recursive_requirements do |_dependent, requirement|
Requirement.prune if requirement.is_a?(X11Requirement)
Requirement.prune if requirement.is_a?(XcodeRequirement)
end

expect(Set.new(requirements)).to eq(Set[xcode])
expect(Set.new(requirements)).to eq(Set[])
end

specify "#to_hash" do
Expand Down

0 comments on commit 010ae37

Please sign in to comment.