Refactor Tab create method
This commit is contained in:
parent
46cb7f2847
commit
3a732460e9
@ -9,23 +9,15 @@ module Cask
|
|||||||
|
|
||||||
# Instantiates a {Tab} for a new installation of a cask.
|
# Instantiates a {Tab} for a new installation of a cask.
|
||||||
def self.create(cask)
|
def self.create(cask)
|
||||||
attributes = generic_attributes(cask).merge({
|
tab = super
|
||||||
"tabfile" => cask.metadata_main_container_path/FILENAME,
|
|
||||||
"uninstall_flight_blocks" => cask.uninstall_flight_blocks?,
|
|
||||||
"runtime_dependencies" => Tab.runtime_deps_hash(cask, cask.depends_on),
|
|
||||||
"source" => {
|
|
||||||
"path" => cask.sourcefile_path.to_s,
|
|
||||||
"tap" => cask.tap&.name,
|
|
||||||
"tap_git_head" => nil, # Filled in later if possible
|
|
||||||
"version" => cask.version.to_s,
|
|
||||||
},
|
|
||||||
"uninstall_artifacts" => cask.artifacts_list(uninstall_only: true),
|
|
||||||
})
|
|
||||||
|
|
||||||
# We can only get `tap_git_head` if the tap is installed locally
|
tab.tabfile = cask.metadata_main_container_path/FILENAME
|
||||||
attributes["source"]["tap_git_head"] = cask.tap.git_head if cask.tap&.installed?
|
tab.uninstall_flight_blocks = cask.uninstall_flight_blocks?
|
||||||
|
tab.runtime_dependencies = Tab.runtime_deps_hash(cask, cask.depends_on)
|
||||||
|
tab.source["version"] = cask.version.to_s
|
||||||
|
tab.uninstall_artifacts = cask.artifacts_list(uninstall_only: true)
|
||||||
|
|
||||||
new(attributes)
|
tab
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a {Tab} for an already installed cask,
|
# Returns a {Tab} for an already installed cask,
|
||||||
@ -39,11 +31,10 @@ module Cask
|
|||||||
tab.source = {
|
tab.source = {
|
||||||
"path" => cask.sourcefile_path.to_s,
|
"path" => cask.sourcefile_path.to_s,
|
||||||
"tap" => cask.tap&.name,
|
"tap" => cask.tap&.name,
|
||||||
"tap_git_head" => nil,
|
"tap_git_head" => (cask.tap&.installed? ? cask.tap.git_head : nil),
|
||||||
"version" => cask.version.to_s,
|
"version" => cask.version.to_s,
|
||||||
}
|
}
|
||||||
tab.uninstall_artifacts = cask.artifacts_list(uninstall_only: true)
|
tab.uninstall_artifacts = cask.artifacts_list(uninstall_only: true)
|
||||||
tab.source["tap_git_head"] = cask.tap.git_head if cask.tap&.installed?
|
|
||||||
|
|
||||||
tab
|
tab
|
||||||
end
|
end
|
||||||
|
|||||||
@ -30,16 +30,24 @@ class AbstractTab
|
|||||||
# @api internal
|
# @api internal
|
||||||
attr_accessor :runtime_dependencies
|
attr_accessor :runtime_dependencies
|
||||||
|
|
||||||
def self.generic_attributes(formula_or_cask)
|
# Instantiates a {Tab} for a new installation of a formula or cask.
|
||||||
{
|
def self.create(formula_or_cask)
|
||||||
|
attributes = {
|
||||||
"homebrew_version" => HOMEBREW_VERSION,
|
"homebrew_version" => HOMEBREW_VERSION,
|
||||||
"installed_as_dependency" => false,
|
"installed_as_dependency" => false,
|
||||||
"installed_on_request" => false,
|
"installed_on_request" => false,
|
||||||
"loaded_from_api" => formula_or_cask.loaded_from_api?,
|
"loaded_from_api" => formula_or_cask.loaded_from_api?,
|
||||||
"time" => Time.now.to_i,
|
"time" => Time.now.to_i,
|
||||||
"arch" => Hardware::CPU.arch,
|
"arch" => Hardware::CPU.arch,
|
||||||
|
"source" => {
|
||||||
|
"path" => formula_or_cask.sourcefile_path.to_s,
|
||||||
|
"tap" => formula_or_cask.tap&.name,
|
||||||
|
"tap_git_head" => (formula_or_cask.tap&.installed? ? formula_or_cask.tap.git_head : nil),
|
||||||
|
},
|
||||||
"built_on" => DevelopmentTools.build_system_info,
|
"built_on" => DevelopmentTools.build_system_info,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new(attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the {Tab} for a formula or cask install receipt at `path`.
|
# Returns the {Tab} for a formula or cask install receipt at `path`.
|
||||||
@ -124,36 +132,28 @@ class Tab < AbstractTab
|
|||||||
|
|
||||||
# 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)
|
||||||
|
tab = super(formula)
|
||||||
build = formula.build
|
build = formula.build
|
||||||
runtime_deps = formula.runtime_dependencies(undeclared: false)
|
runtime_deps = formula.runtime_dependencies(undeclared: false)
|
||||||
attributes = generic_attributes(formula).merge({
|
|
||||||
"used_options" => build.used_options.as_flags,
|
|
||||||
"unused_options" => build.unused_options.as_flags,
|
|
||||||
"tabfile" => formula.prefix/FILENAME,
|
|
||||||
"built_as_bottle" => build.bottle?,
|
|
||||||
"poured_from_bottle" => false,
|
|
||||||
"source_modified_time" => formula.source_modified_time.to_i,
|
|
||||||
"compiler" => compiler,
|
|
||||||
"stdlib" => stdlib,
|
|
||||||
"aliases" => formula.aliases,
|
|
||||||
"runtime_dependencies" => Tab.runtime_deps_hash(formula, runtime_deps),
|
|
||||||
"source" => {
|
|
||||||
"path" => formula.specified_path.to_s,
|
|
||||||
"tap" => formula.tap&.name,
|
|
||||||
"tap_git_head" => nil, # Filled in later if possible
|
|
||||||
"spec" => formula.active_spec_sym.to_s,
|
|
||||||
"versions" => {
|
|
||||||
"stable" => formula.stable&.version&.to_s,
|
|
||||||
"head" => formula.head&.version&.to_s,
|
|
||||||
"version_scheme" => formula.version_scheme,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
# We can only get `tap_git_head` if the tap is installed locally
|
tab.used_options = build.used_options.as_flags
|
||||||
attributes["source"]["tap_git_head"] = formula.tap.git_head if formula.tap&.installed?
|
tab.unused_options = build.unused_options.as_flags
|
||||||
|
tab.tabfile = formula.prefix/FILENAME
|
||||||
|
tab.built_as_bottle = build.bottle?
|
||||||
|
tab.poured_from_bottle = false
|
||||||
|
tab.source_modified_time = formula.source_modified_time.to_i
|
||||||
|
tab.compiler = compiler
|
||||||
|
tab.stdlib = stdlib
|
||||||
|
tab.aliases = formula.aliases
|
||||||
|
tab.runtime_dependencies = Tab.runtime_deps_hash(formula, runtime_deps)
|
||||||
|
tab.source["spec"] = formula.active_spec_sym.to_s
|
||||||
|
tab.source["versions"] = {
|
||||||
|
"stable" => formula.stable&.version&.to_s,
|
||||||
|
"head" => formula.head&.version&.to_s,
|
||||||
|
"version_scheme" => formula.version_scheme,
|
||||||
|
}
|
||||||
|
|
||||||
new(attributes)
|
tab
|
||||||
end
|
end
|
||||||
|
|
||||||
# Like {from_file}, but bypass the cache.
|
# Like {from_file}, but bypass the cache.
|
||||||
@ -253,10 +253,11 @@ class Tab < AbstractTab
|
|||||||
tab = empty
|
tab = empty
|
||||||
tab.unused_options = formula.options.as_flags
|
tab.unused_options = formula.options.as_flags
|
||||||
tab.source = {
|
tab.source = {
|
||||||
"path" => formula.specified_path.to_s,
|
"path" => formula.specified_path.to_s,
|
||||||
"tap" => formula.tap&.name,
|
"tap" => formula.tap&.name,
|
||||||
"spec" => formula.active_spec_sym.to_s,
|
"tap_git_head" => (formula.tap&.installed? ? formula.tap.git_head : nil),
|
||||||
"versions" => {
|
"spec" => formula.active_spec_sym.to_s,
|
||||||
|
"versions" => {
|
||||||
"stable" => formula.stable&.version&.to_s,
|
"stable" => formula.stable&.version&.to_s,
|
||||||
"head" => formula.head&.version&.to_s,
|
"head" => formula.head&.version&.to_s,
|
||||||
"version_scheme" => formula.version_scheme,
|
"version_scheme" => formula.version_scheme,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user