Merge pull request #14981 from dduugg/tab-no-ostruct
Remove OpenStruct use in Tab
This commit is contained in:
commit
83aea49d8a
@ -390,7 +390,6 @@ Style/NumericLiterals:
|
|||||||
Style/OpenStructUse:
|
Style/OpenStructUse:
|
||||||
Exclude:
|
Exclude:
|
||||||
- "Homebrew/cli/args.rb"
|
- "Homebrew/cli/args.rb"
|
||||||
- "Homebrew/tab.rb"
|
|
||||||
- "Taps/**/*.rb"
|
- "Taps/**/*.rb"
|
||||||
|
|
||||||
# Rescuing `StandardError` is an understood default.
|
# Rescuing `StandardError` is an understood default.
|
||||||
|
|||||||
@ -400,7 +400,6 @@ module Homebrew
|
|||||||
tab = Tab.for_keg(keg)
|
tab = Tab.for_keg(keg)
|
||||||
original_tab = tab.dup
|
original_tab = tab.dup
|
||||||
tab.poured_from_bottle = false
|
tab.poured_from_bottle = false
|
||||||
tab.HEAD = nil
|
|
||||||
tab.time = nil
|
tab.time = nil
|
||||||
tab.changed_files = changed_files.dup
|
tab.changed_files = changed_files.dup
|
||||||
if args.only_json_tab?
|
if args.only_json_tab?
|
||||||
|
|||||||
@ -157,8 +157,8 @@ class Keg
|
|||||||
brewed_perl = runtime_dependencies&.any? { |dep| dep["full_name"] == "perl" && dep["declared_directly"] }
|
brewed_perl = runtime_dependencies&.any? { |dep| dep["full_name"] == "perl" && dep["declared_directly"] }
|
||||||
perl_path = if brewed_perl || name == "perl"
|
perl_path = if brewed_perl || name == "perl"
|
||||||
"#{HOMEBREW_PREFIX}/opt/perl/bin/perl"
|
"#{HOMEBREW_PREFIX}/opt/perl/bin/perl"
|
||||||
elsif tab["built_on"].present?
|
elsif tab.built_on.present?
|
||||||
perl_path = "/usr/bin/perl#{tab["built_on"]["preferred_perl"]}"
|
perl_path = "/usr/bin/perl#{tab.built_on["preferred_perl"]}"
|
||||||
|
|
||||||
# For `:all` bottles, we could have built this bottle with a Perl we don't have.
|
# For `:all` bottles, we could have built this bottle with a Perl we don't have.
|
||||||
# Such bottles typically don't have strict version requirements.
|
# Such bottles typically don't have strict version requirements.
|
||||||
|
|||||||
@ -1,23 +1,25 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cxxstdlib"
|
require "cxxstdlib"
|
||||||
require "ostruct"
|
|
||||||
require "options"
|
require "options"
|
||||||
require "json"
|
require "json"
|
||||||
require "development_tools"
|
require "development_tools"
|
||||||
require "extend/cachable"
|
require "extend/cachable"
|
||||||
|
|
||||||
# Inherit from OpenStruct to gain a generic initialization method that takes a
|
# Rather than calling `new` directly, use one of the class methods like {Tab.create}.
|
||||||
# hash and creates an attribute for each key and value. Rather than calling
|
class Tab
|
||||||
# `new` directly, use one of the class methods like {Tab.create}.
|
|
||||||
class Tab < OpenStruct
|
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
extend Cachable
|
extend Cachable
|
||||||
|
|
||||||
FILENAME = "INSTALL_RECEIPT.json"
|
FILENAME = "INSTALL_RECEIPT.json"
|
||||||
|
|
||||||
|
attr_accessor :homebrew_version, :tabfile, :built_as_bottle, :installed_as_dependency, :installed_on_request,
|
||||||
|
:changed_files, :poured_from_bottle, :loaded_from_api, :time, :stdlib, :aliases, :arch, :source,
|
||||||
|
:built_on
|
||||||
|
attr_writer :used_options, :unused_options, :compiler, :runtime_dependencies, :source_modified_time
|
||||||
|
|
||||||
# Instantiates a Tab for a new installation of a formula.
|
# Instantiates a Tab for a new installation of a formula.
|
||||||
def self.create(formula, compiler, stdlib)
|
def self.create(formula, compiler, stdlib)
|
||||||
build = formula.build
|
build = formula.build
|
||||||
@ -120,7 +122,7 @@ class Tab < OpenStruct
|
|||||||
empty
|
empty
|
||||||
end
|
end
|
||||||
|
|
||||||
tab["tabfile"] = path
|
tab.tabfile = path
|
||||||
tab
|
tab
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -226,6 +228,10 @@ class Tab < OpenStruct
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def initialize(attributes = {})
|
||||||
|
attributes.each { |key, value| instance_variable_set("@#{key}", value) }
|
||||||
|
end
|
||||||
|
|
||||||
def any_args_or_options?
|
def any_args_or_options?
|
||||||
!used_options.empty? || !unused_options.empty?
|
!used_options.empty? || !unused_options.empty?
|
||||||
end
|
end
|
||||||
@ -255,15 +261,15 @@ class Tab < OpenStruct
|
|||||||
end
|
end
|
||||||
|
|
||||||
def used_options
|
def used_options
|
||||||
Options.create(super)
|
Options.create(@used_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unused_options
|
def unused_options
|
||||||
Options.create(super)
|
Options.create(@unused_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def compiler
|
def compiler
|
||||||
super || DevelopmentTools.default_compiler
|
@compiler || DevelopmentTools.default_compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
def parsed_homebrew_version
|
def parsed_homebrew_version
|
||||||
@ -275,7 +281,7 @@ class Tab < OpenStruct
|
|||||||
def runtime_dependencies
|
def runtime_dependencies
|
||||||
# Homebrew versions prior to 1.1.6 generated incorrect runtime dependency
|
# Homebrew versions prior to 1.1.6 generated incorrect runtime dependency
|
||||||
# lists.
|
# lists.
|
||||||
super unless parsed_homebrew_version < "1.1.6"
|
@runtime_dependencies unless parsed_homebrew_version < "1.1.6"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cxxstdlib
|
def cxxstdlib
|
||||||
@ -324,7 +330,7 @@ class Tab < OpenStruct
|
|||||||
|
|
||||||
sig { returns(Time) }
|
sig { returns(Time) }
|
||||||
def source_modified_time
|
def source_modified_time
|
||||||
Time.at(super || 0)
|
Time.at(@source_modified_time || 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json(options = nil)
|
def to_json(options = nil)
|
||||||
|
|||||||
@ -47,5 +47,4 @@ TESTBALL_PATCHES_SHA256 = "799c2d551ac5c3a5759bea7796631a7906a6a24435b52261a3171
|
|||||||
PATCH_A_SHA256 = "83404f4936d3257e65f176c4ffb5a5b8d6edd644a21c8d8dcc73e22a6d28fcfa"
|
PATCH_A_SHA256 = "83404f4936d3257e65f176c4ffb5a5b8d6edd644a21c8d8dcc73e22a6d28fcfa"
|
||||||
PATCH_B_SHA256 = "57958271bb802a59452d0816e0670d16c8b70bdf6530bcf6f78726489ad89b90"
|
PATCH_B_SHA256 = "57958271bb802a59452d0816e0670d16c8b70bdf6530bcf6f78726489ad89b90"
|
||||||
|
|
||||||
TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
|
||||||
TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
|
||||||
|
|||||||
@ -29,7 +29,6 @@ describe Tab do
|
|||||||
"changed_files" => [],
|
"changed_files" => [],
|
||||||
"time" => time,
|
"time" => time,
|
||||||
"source_modified_time" => 0,
|
"source_modified_time" => 0,
|
||||||
"HEAD" => TEST_SHA1,
|
|
||||||
"compiler" => "clang",
|
"compiler" => "clang",
|
||||||
"stdlib" => "libcxx",
|
"stdlib" => "libcxx",
|
||||||
"runtime_dependencies" => [],
|
"runtime_dependencies" => [],
|
||||||
@ -71,7 +70,6 @@ describe Tab do
|
|||||||
expect(tab).not_to be_head
|
expect(tab).not_to be_head
|
||||||
expect(tab.tap).to be_nil
|
expect(tab.tap).to be_nil
|
||||||
expect(tab.time).to be_nil
|
expect(tab.time).to be_nil
|
||||||
expect(tab.HEAD).to be_nil
|
|
||||||
expect(tab.runtime_dependencies).to be_nil
|
expect(tab.runtime_dependencies).to be_nil
|
||||||
expect(tab.stable_version).to be_nil
|
expect(tab.stable_version).to be_nil
|
||||||
expect(tab.head_version).to be_nil
|
expect(tab.head_version).to be_nil
|
||||||
@ -154,7 +152,6 @@ describe Tab do
|
|||||||
end
|
end
|
||||||
|
|
||||||
specify "other attributes" do
|
specify "other attributes" do
|
||||||
expect(tab.HEAD).to eq(TEST_SHA1)
|
|
||||||
expect(tab.tap.name).to eq("homebrew/core")
|
expect(tab.tap.name).to eq("homebrew/core")
|
||||||
expect(tab.time).to eq(time)
|
expect(tab.time).to eq(time)
|
||||||
expect(tab).not_to be_built_as_bottle
|
expect(tab).not_to be_built_as_bottle
|
||||||
@ -179,7 +176,6 @@ describe Tab do
|
|||||||
expect(tab.tap.name).to eq("homebrew/core")
|
expect(tab.tap.name).to eq("homebrew/core")
|
||||||
expect(tab.spec).to eq(:stable)
|
expect(tab.spec).to eq(:stable)
|
||||||
expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
|
expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
|
||||||
expect(tab.HEAD).to eq(TEST_SHA1)
|
|
||||||
expect(tab.cxxstdlib.compiler).to eq(:clang)
|
expect(tab.cxxstdlib.compiler).to eq(:clang)
|
||||||
expect(tab.cxxstdlib.type).to eq(:libcxx)
|
expect(tab.cxxstdlib.type).to eq(:libcxx)
|
||||||
expect(tab.runtime_dependencies).to eq(runtime_dependencies)
|
expect(tab.runtime_dependencies).to eq(runtime_dependencies)
|
||||||
@ -207,7 +203,6 @@ describe Tab do
|
|||||||
expect(tab.tap.name).to eq("homebrew/core")
|
expect(tab.tap.name).to eq("homebrew/core")
|
||||||
expect(tab.spec).to eq(:stable)
|
expect(tab.spec).to eq(:stable)
|
||||||
expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
|
expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
|
||||||
expect(tab.HEAD).to eq(TEST_SHA1)
|
|
||||||
expect(tab.cxxstdlib.compiler).to eq(:clang)
|
expect(tab.cxxstdlib.compiler).to eq(:clang)
|
||||||
expect(tab.cxxstdlib.type).to eq(:libcxx)
|
expect(tab.cxxstdlib.type).to eq(:libcxx)
|
||||||
expect(tab.runtime_dependencies).to eq(runtime_dependencies)
|
expect(tab.runtime_dependencies).to eq(runtime_dependencies)
|
||||||
@ -229,7 +224,6 @@ describe Tab do
|
|||||||
expect(tab.tap.name).to eq("homebrew/core")
|
expect(tab.tap.name).to eq("homebrew/core")
|
||||||
expect(tab.spec).to eq(:stable)
|
expect(tab.spec).to eq(:stable)
|
||||||
expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
|
expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
|
||||||
expect(tab.HEAD).to eq(TEST_SHA1)
|
|
||||||
expect(tab.cxxstdlib.compiler).to eq(:clang)
|
expect(tab.cxxstdlib.compiler).to eq(:clang)
|
||||||
expect(tab.cxxstdlib.type).to eq(:libcxx)
|
expect(tab.cxxstdlib.type).to eq(:libcxx)
|
||||||
expect(tab.runtime_dependencies).to be_nil
|
expect(tab.runtime_dependencies).to be_nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user