From 3f724825d36b467fb8a0ae074e8332369edaa304 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 23 Dec 2016 15:01:02 +0000 Subject: [PATCH 1/3] Revert "Revert "formula: runtime deps of build deps aren't runtime"" This reverts commit 862c3ba4a2fb76140e46fdf49a1ea6857f140a29. --- Library/Homebrew/formula.rb | 2 +- Library/Homebrew/test/formula_test.rb | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index b3927d260b..600f9c2e97 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1505,7 +1505,7 @@ class Formula # Returns a list of Dependency objects that are required at runtime. # @private def runtime_dependencies - recursive_dependencies.reject(&:build?) + recursive_dependencies { |_, dep| Dependency.prune if dep.build? } end # Returns a list of formulae depended on by this formula that aren't diff --git a/Library/Homebrew/test/formula_test.rb b/Library/Homebrew/test/formula_test.rb index a6db1b57f2..28d376b7c2 100644 --- a/Library/Homebrew/test/formula_test.rb +++ b/Library/Homebrew/test/formula_test.rb @@ -651,12 +651,19 @@ class FormulaTests < Homebrew::TestCase f4 = formula("f4") do url "f4-1.0" - depends_on "f3" + depends_on "f1" + end + stub_formula_loader f4 + + f5 = formula("f5") do + url "f5-1.0" + depends_on "f3" => :build + depends_on "f4" end - assert_equal %w[f3], f4.deps.map(&:name) - assert_equal %w[f1 f2 f3], f4.recursive_dependencies.map(&:name) - assert_equal %w[f2 f3], f4.runtime_dependencies.map(&:name) + assert_equal %w[f3 f4], f5.deps.map(&:name) + assert_equal %w[f1 f2 f3 f4], f5.recursive_dependencies.map(&:name) + assert_equal %w[f1 f4], f5.runtime_dependencies.map(&:name) end def test_to_hash From 43f2e9e7bbb5917b14af81fd226d763dae388cdb Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 23 Dec 2016 15:01:02 +0000 Subject: [PATCH 2/3] formula: don't expand unused optional dependencies This properly addresses Homebrew/homebrew-core#7826. --- Library/Homebrew/formula.rb | 7 ++++++- Library/Homebrew/test/formula_test.rb | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 600f9c2e97..4578216853 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1505,7 +1505,12 @@ class Formula # Returns a list of Dependency objects that are required at runtime. # @private def runtime_dependencies - recursive_dependencies { |_, dep| Dependency.prune if dep.build? } + recursive_dependencies do |_dependent, dependency| + Dependency.prune if dependency.build? + if dependency.optional? || dependency.recommended? + Dependency.prune unless build.with?(dependency) + end + end end # Returns a list of formulae depended on by this formula that aren't diff --git a/Library/Homebrew/test/formula_test.rb b/Library/Homebrew/test/formula_test.rb index 28d376b7c2..81022d2202 100644 --- a/Library/Homebrew/test/formula_test.rb +++ b/Library/Homebrew/test/formula_test.rb @@ -666,6 +666,29 @@ class FormulaTests < Homebrew::TestCase assert_equal %w[f1 f4], f5.runtime_dependencies.map(&:name) end + def test_runtime_dependencies_with_optional_deps_from_tap + tap_loader = mock + tap_loader.stubs(:get_formula).raises(RuntimeError, "tried resolving tap formula") + Formulary.stubs(:loader_for).with("foo/bar/f1", from: nil).returns(tap_loader) + + stub_formula_loader formula("f2") { url "f2-1.0" }, "baz/qux/f2" + + f3 = formula("f3") do + url "f3-1.0" + depends_on "foo/bar/f1" => :optional + depends_on "baz/qux/f2" + end + + # f1 shouldn't be loaded by default. + # If it is, an exception will be raised. + assert_equal %w[baz/qux/f2], f3.runtime_dependencies.map(&:name) + + # If --with-f1, f1 should be loaded. + stub_formula_loader formula("f1") { url "f1-1.0" }, "foo/bar/f1" + f3.build = BuildOptions.new(Options.create(%w[--with-f1]), f3.options) + assert_equal %w[foo/bar/f1 baz/qux/f2], f3.runtime_dependencies.map(&:name) + end + def test_to_hash f1 = formula("foo") do url "foo-1.0" From ef5cff5e7196b7371239d1028a0f07cd8af980b9 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 23 Dec 2016 20:56:39 +0000 Subject: [PATCH 3/3] formula: make runtime_dependencies logic clearer --- Library/Homebrew/formula.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 4578216853..bc1dbd9705 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1507,9 +1507,7 @@ class Formula def runtime_dependencies recursive_dependencies do |_dependent, dependency| Dependency.prune if dependency.build? - if dependency.optional? || dependency.recommended? - Dependency.prune unless build.with?(dependency) - end + Dependency.prune if !dependency.required? && build.without?(dependency) end end