From a5cb621fb86cdb87761a8113ffb17d72a0f6d3ae Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Thu, 29 Apr 2021 17:51:13 +0100 Subject: [PATCH] tab: add declared_directly field for runtime deps --- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/tab.rb | 10 +++++++--- Library/Homebrew/test/tab_spec.rb | 11 ++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index a629bbd545..db5bc17eff 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -805,7 +805,7 @@ class FormulaInstaller tab = Tab.for_keg(keg) Tab.clear_cache f_runtime_deps = formula.runtime_dependencies(read_from_tab: false) - tab.runtime_dependencies = Tab.runtime_deps_hash(f_runtime_deps) + tab.runtime_dependencies = Tab.runtime_deps_hash(formula, f_runtime_deps) tab.write # let's reset Utils::Git.available? if we just installed git diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index 3e6cc5aade..7ce6b00c08 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -36,7 +36,7 @@ class Tab < OpenStruct "compiler" => compiler, "stdlib" => stdlib, "aliases" => formula.aliases, - "runtime_dependencies" => Tab.runtime_deps_hash(runtime_deps), + "runtime_dependencies" => Tab.runtime_deps_hash(formula, runtime_deps), "arch" => Hardware::CPU.arch, "source" => { "path" => formula.specified_path.to_s, @@ -210,10 +210,14 @@ class Tab < OpenStruct new(attributes) end - def self.runtime_deps_hash(deps) + def self.runtime_deps_hash(formula, deps) deps.map do |dep| f = dep.to_formula - { "full_name" => f.full_name, "version" => f.version.to_s } + { + "full_name" => f.full_name, + "version" => f.version.to_s, + "declared_directly" => formula.deps.include?(dep), + } end end diff --git a/Library/Homebrew/test/tab_spec.rb b/Library/Homebrew/test/tab_spec.rb index d6e4f2b170..24b64daf5a 100644 --- a/Library/Homebrew/test/tab_spec.rb +++ b/Library/Homebrew/test/tab_spec.rb @@ -137,13 +137,14 @@ describe Tab do specify "::runtime_deps_hash" do runtime_deps = [Dependency.new("foo")] - stub_formula_loader formula("foo") { url "foo-1.0" } - runtime_deps_hash = described_class.runtime_deps_hash(runtime_deps) + foo = formula("foo") { url "foo-1.0" } + stub_formula_loader foo + runtime_deps_hash = described_class.runtime_deps_hash(foo, runtime_deps) tab = described_class.new tab.homebrew_version = "1.1.6" tab.runtime_dependencies = runtime_deps_hash expect(tab.runtime_dependencies).to eql( - [{ "full_name" => "foo", "version" => "1.0" }], + [{ "full_name" => "foo", "version" => "1.0", "declared_directly" => false }], ) end @@ -268,8 +269,8 @@ describe Tab do tab = described_class.create(f, compiler, stdlib) runtime_dependencies = [ - { "full_name" => "bar", "version" => "2.0" }, - { "full_name" => "user/repo/from_tap", "version" => "1.0" }, + { "full_name" => "bar", "version" => "2.0", "declared_directly" => true }, + { "full_name" => "user/repo/from_tap", "version" => "1.0", "declared_directly" => true }, ] expect(tab.runtime_dependencies).to eq(runtime_dependencies)