Class: Vanagon::Component
- Inherits:
-
Object
- Object
- Vanagon::Component
- Includes:
- HashableAttributes, Utilities
- Defined in:
- lib/vanagon/component.rb,
lib/vanagon/component/dsl.rb,
lib/vanagon/component/rules.rb,
lib/vanagon/component/source.rb,
lib/vanagon/extensions/hashable.rb,
lib/vanagon/component/source/git.rb,
lib/vanagon/component/source/http.rb,
lib/vanagon/component/source/local.rb,
lib/vanagon/component/source/rewrite.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#activate_triggers ⇒ Object
activate_triggers is a one-dimentional Array of Strings, describing scripts that should be executed when a package identifies an activate trigger.
-
#build ⇒ Object
build will hold an Array of the commands required to build a given component.
-
#build_dir ⇒ Object
the optional name of a directory to build a component in; most likely to be used for cmake projects, which do not like to be configured or compiled in their own top-level directories.
-
#build_requires ⇒ Object
build_requires holds an Array with a list of the dependencies that a given component needs satisfied before it can be built.
-
#check ⇒ Object
check will hold an Array of the commands required to validate/test a given component.
-
#cleanup_source ⇒ Object
cleanup_source contains whatever value a given component’s Source has specified as instructions for cleaning up after a build is completed.
-
#configure ⇒ Object
how should this component be configured?.
-
#conflicts ⇒ Object
conflicts holds an Array of OpenStructs that describe a package that a given component will replace on installation.
-
#directories ⇒ Object
directories holds an Array with a list of expected directories that will be packed into the resulting artifact’s bill of materials.
-
#dirname ⇒ Object
holds the expected directory name of a given component, once it’s been unpacked/decompressed.
-
#environment ⇒ Object
holds a Vanagon::Environment object, to map out any desired environment variables that should be rendered into the Makefile.
-
#extract_with ⇒ Array
The specific tool or command line invocations that should be used to extract a given component’s primary source.
-
#files ⇒ Set
readonly
Retrieve all items from @files not marked as configuration files.
-
#homepage ⇒ Object
Returns the value of attribute homepage.
-
#install ⇒ Object
install will hold an Array of the commands required to install a given component.
-
#install_only ⇒ Object
When dealing with compiled artifacts generated by setting ‘project.generate_archives true`, you only need to install the component.
-
#install_triggers ⇒ Object
install_triggers is a one-dimensional Array of OpenStructs, describing scripts that should be executed when a package is installed or upgraded.
-
#interest_triggers ⇒ Object
interest_triggers is a one-dimensional Array of OpenStructs, describing scripts that should be executed when a package identifies an interest trigger.
-
#license ⇒ Object
Returns the value of attribute license.
-
#mirrors ⇒ Set
A list of unique mirror URIs that should be used to retrieve the upstream source before attempting to retrieve from whatever URI was defined for #uri.
-
#name ⇒ Object
The name, version, primary source, supplementary sources, associated patches, upstream URL (for fetching the source), homepage, and license of a given component.
-
#options ⇒ Object
used to hold the checksum settings or other weirdo metadata related to building a given component (git ref, sha, etc.).
-
#patches ⇒ Object
Returns the value of attribute patches.
-
#platform ⇒ Object
the platform that a given component will be built for – due to the fact that Ruby is pass-by-reference, it’s usually just a reference to the same Platform object that the overall Project object also contains.
-
#postinstall_actions ⇒ Object
postinstall_actions is a two-dimensional Array, describing scripts that should be executed after a given component is installed.
-
#postremove_actions ⇒ Object
preinstall_actions is a two-dimensional Array, describing scripts that should be executed after a given component is uninstalled.
-
#preinstall_actions ⇒ Object
preinstall_actions is a two-dimensional Array, describing scripts that should be executed before a given component is installed.
-
#preremove_actions ⇒ Object
preremove_actions is a two-dimensional Array, describing scripts that should be executed before a given component is uninstalled.
-
#provides ⇒ Object
provides holds an Array of OpenStructs that describe any capabilities that a given component will provide beyond the its filesystem payload.
-
#replaces ⇒ Object
replaces holds an Array of OpenStructs that describe a package that a given component will replace on installation.
-
#requires ⇒ Object
requires holds an Array with a list of all dependencies that a given component needs satisfied before it can be installed.
-
#service ⇒ Object
holds an OpenStruct describing all of the particular details about how any services associated with a given component should be defined.
-
#settings ⇒ Object
holds a OpenStruct, or an Array, or maybe it’s a Hash? It’s often overloaded as a freeform key-value lookup for platforms that require additional configuration beyond the “basic” component attributes.
-
#source ⇒ Object
Returns the value of attribute source.
-
#sources ⇒ Object
Returns the value of attribute sources.
-
#url ⇒ Object
Returns the value of attribute url.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.load_component(name, configdir, settings, platform) ⇒ Vanagon::Component
Loads a given component from the configdir.
Instance Method Summary collapse
-
#add_file(file) ⇒ Set?
Adds the given file to the list of files and returns @files.
-
#add_rpm_ghost_file(file) ⇒ Set?
Adds the given file to the list of %ghost files to be added to an rpm spec’s %files.
-
#configfiles ⇒ Set
Retrieve all items from @files explicitly marked as configuration files.
-
#delete_file(file) ⇒ Set?
Deletes the given file from the list of files and returns @files.
- #environment_variables ⇒ Object
-
#fetch_mirrors(options) ⇒ Boolean
Retrieve upstream source file from a mirror, by randomly iterating through #mirrors until there’s no more mirrors left.
-
#fetch_url(options) ⇒ Boolean
Retrieve upstream source file from the canonical URL.
-
#force_version ⇒ Object
Force version determination for components.
-
#get_build_dir ⇒ Object
Expands the build directory.
- #get_dependency_hash ⇒ Object
- #get_environment ⇒ String deprecated Deprecated.
-
#get_patches(patch_root) ⇒ Object
Fetches patches if any are provided for the project.
-
#get_source(workdir) ⇒ Object
Fetches the primary source for the component.
-
#get_sources(workdir) ⇒ Object
Fetches secondary sources for the component.
-
#initialize(name, settings, platform) ⇒ Vanagon::Component
constructor
Component constructor.
-
#rpm_ghost_files ⇒ Array
Retrieve all the files intended as %ghost entries for an rpm spec %files section.
- #rules(project, platform) ⇒ Object
Methods included from HashableAttributes
Methods included from Utilities
#erb_file, #erb_string, #ex, #find_program_on_path, #get_md5sum, #get_sum, #http_request, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command
Constructor Details
#initialize(name, settings, platform) ⇒ Vanagon::Component
Component constructor.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/vanagon/component.rb', line 153 def initialize(name, settings, platform) # rubocop:disable Metrics/AbcSize @name = name @settings = settings @platform = platform @options = {} @build_requires = [] @requires = [] @configure = [] @install = [] @build = [] @check = [] @patches = [] @files = Set.new @ghost_files = Set.new @directories = [] @replaces = [] @provides = [] @conflicts = [] @environment = Vanagon::Environment.new @sources = [] @preinstall_actions = [] @install_triggers = [] @interest_triggers = [] @activate_triggers = [] @postinstall_actions = [] @preremove_actions = [] @postremove_actions = [] @install_only = false end |
Instance Attribute Details
#activate_triggers ⇒ Object
activate_triggers is a one-dimentional Array of Strings, describing scripts that should be executed when a package identifies an activate trigger
106 107 108 |
# File 'lib/vanagon/component.rb', line 106 def activate_triggers @activate_triggers end |
#build ⇒ Object
build will hold an Array of the commands required to build a given component
48 49 50 |
# File 'lib/vanagon/component.rb', line 48 def build @build end |
#build_dir ⇒ Object
the optional name of a directory to build a component in; most likely to be used for cmake projects, which do not like to be configured or compiled in their own top-level directories.
45 46 47 |
# File 'lib/vanagon/component.rb', line 45 def build_dir @build_dir end |
#build_requires ⇒ Object
build_requires holds an Array with a list of the dependencies that a given component needs satisfied before it can be built.
82 83 84 |
# File 'lib/vanagon/component.rb', line 82 def build_requires @build_requires end |
#check ⇒ Object
check will hold an Array of the commands required to validate/test a given component
51 52 53 |
# File 'lib/vanagon/component.rb', line 51 def check @check end |
#cleanup_source ⇒ Object
cleanup_source contains whatever value a given component’s Source has specified as instructions for cleaning up after a build is completed. usually a String, but not required to be.
119 120 121 |
# File 'lib/vanagon/component.rb', line 119 def cleanup_source @cleanup_source end |
#configure ⇒ Object
how should this component be configured?
41 42 43 |
# File 'lib/vanagon/component.rb', line 41 def configure @configure end |
#conflicts ⇒ Object
conflicts holds an Array of OpenStructs that describe a package that a given component will replace on installation.
94 95 96 |
# File 'lib/vanagon/component.rb', line 94 def conflicts @conflicts end |
#directories ⇒ Object
directories holds an Array with a list of expected directories that will be packed into the resulting artifact’s bill of materials.
79 80 81 |
# File 'lib/vanagon/component.rb', line 79 def directories @directories end |
#dirname ⇒ Object
holds the expected directory name of a given component, once it’s been unpacked/decompressed. For git repos, it’s usually the directory that they were cloned to. For the outlying flat files, it’ll end up being defined explicitly as the string ‘./’
36 37 38 |
# File 'lib/vanagon/component.rb', line 36 def dirname @dirname end |
#environment ⇒ Object
holds a Vanagon::Environment object, to map out any desired environment variables that should be rendered into the Makefile
58 59 60 |
# File 'lib/vanagon/component.rb', line 58 def environment @environment end |
#extract_with ⇒ Array
Returns the specific tool or command line invocations that should be used to extract a given component’s primary source.
39 40 41 |
# File 'lib/vanagon/component.rb', line 39 def extract_with @extract_with end |
#files ⇒ Set (readonly)
Retrieve all items from @files not marked as configuration files
|
# File 'lib/vanagon/component.rb', line 9
|
#homepage ⇒ Object
Returns the value of attribute homepage.
26 27 28 |
# File 'lib/vanagon/component.rb', line 26 def homepage @homepage end |
#install ⇒ Object
install will hold an Array of the commands required to install a given component
54 55 56 |
# File 'lib/vanagon/component.rb', line 54 def install @install end |
#install_only ⇒ Object
When dealing with compiled artifacts generated by setting ‘project.generate_archives true`, you only need to install the component. By setting install_only to true the component ’build’ will exclude the unpack, patch, configure, build, and check steps.
125 126 127 |
# File 'lib/vanagon/component.rb', line 125 def install_only @install_only end |
#install_triggers ⇒ Object
install_triggers is a one-dimensional Array of OpenStructs, describing scripts that should be executed when a package is installed or upgraded
100 101 102 |
# File 'lib/vanagon/component.rb', line 100 def install_triggers @install_triggers end |
#interest_triggers ⇒ Object
interest_triggers is a one-dimensional Array of OpenStructs, describing scripts that should be executed when a package identifies an interest trigger
103 104 105 |
# File 'lib/vanagon/component.rb', line 103 def interest_triggers @interest_triggers end |
#license ⇒ Object
Returns the value of attribute license.
25 26 27 |
# File 'lib/vanagon/component.rb', line 25 def license @license end |
#mirrors ⇒ Set
Returns a list of unique mirror URIs that should be used to retrieve the upstream source before attempting to retrieve from whatever URI was defined for #uri. If no mirrors are set and the deprecated rewrite system has been configured, this will return rewritten URIs.
240 241 242 |
# File 'lib/vanagon/component.rb', line 240 def mirrors @mirrors end |
#name ⇒ Object
The name, version, primary source, supplementary sources, associated patches, upstream URL (for fetching the source), homepage, and license of a given component
18 19 20 |
# File 'lib/vanagon/component.rb', line 18 def name @name end |
#options ⇒ Object
used to hold the checksum settings or other weirdo metadata related to building a given component (git ref, sha, etc.). Probably conflicts or collides with #settings to some degree.
68 69 70 |
# File 'lib/vanagon/component.rb', line 68 def @options end |
#patches ⇒ Object
Returns the value of attribute patches.
22 23 24 |
# File 'lib/vanagon/component.rb', line 22 def patches @patches end |
#platform ⇒ Object
the platform that a given component will be built for – due to the fact that Ruby is pass-by-reference, it’s usually just a reference to the same Platform object that the overall Project object also contains. This is a definite code smell, and should be slated for refactoring ASAP because it’s going to have weird side-effects if the underlying pass-by-reference assumptions change.
75 76 77 |
# File 'lib/vanagon/component.rb', line 75 def platform @platform end |
#postinstall_actions ⇒ Object
postinstall_actions is a two-dimensional Array, describing scripts that should be executed after a given component is installed.
109 110 111 |
# File 'lib/vanagon/component.rb', line 109 def postinstall_actions @postinstall_actions end |
#postremove_actions ⇒ Object
preinstall_actions is a two-dimensional Array, describing scripts that should be executed after a given component is uninstalled.
115 116 117 |
# File 'lib/vanagon/component.rb', line 115 def postremove_actions @postremove_actions end |
#preinstall_actions ⇒ Object
preinstall_actions is a two-dimensional Array, describing scripts that should be executed before a given component is installed.
97 98 99 |
# File 'lib/vanagon/component.rb', line 97 def preinstall_actions @preinstall_actions end |
#preremove_actions ⇒ Object
preremove_actions is a two-dimensional Array, describing scripts that should be executed before a given component is uninstalled.
112 113 114 |
# File 'lib/vanagon/component.rb', line 112 def preremove_actions @preremove_actions end |
#provides ⇒ Object
provides holds an Array of OpenStructs that describe any capabilities that a given component will provide beyond the its filesystem payload.
91 92 93 |
# File 'lib/vanagon/component.rb', line 91 def provides @provides end |
#replaces ⇒ Object
replaces holds an Array of OpenStructs that describe a package that a given component will replace on installation.
88 89 90 |
# File 'lib/vanagon/component.rb', line 88 def replaces @replaces end |
#requires ⇒ Object
requires holds an Array with a list of all dependencies that a given component needs satisfied before it can be installed.
85 86 87 |
# File 'lib/vanagon/component.rb', line 85 def requires @requires end |
#service ⇒ Object
holds an OpenStruct describing all of the particular details about how any services associated with a given component should be defined.
30 31 32 |
# File 'lib/vanagon/component.rb', line 30 def service @service end |
#settings ⇒ Object
holds a OpenStruct, or an Array, or maybe it’s a Hash? It’s often overloaded as a freeform key-value lookup for platforms that require additional configuration beyond the “basic” component attributes. it’s pretty heavily overloaded and should maybe be refactored before Vanagon 1.0.0 is tagged.
64 65 66 |
# File 'lib/vanagon/component.rb', line 64 def settings @settings end |
#source ⇒ Object
Returns the value of attribute source.
20 21 22 |
# File 'lib/vanagon/component.rb', line 20 def source @source end |
#sources ⇒ Object
Returns the value of attribute sources.
21 22 23 |
# File 'lib/vanagon/component.rb', line 21 def sources @sources end |
#url ⇒ Object
Returns the value of attribute url.
23 24 25 |
# File 'lib/vanagon/component.rb', line 23 def url @url end |
#version ⇒ Object
Returns the value of attribute version.
19 20 21 |
# File 'lib/vanagon/component.rb', line 19 def version @version end |
Class Method Details
.load_component(name, configdir, settings, platform) ⇒ Vanagon::Component
Loads a given component from the configdir
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/vanagon/component.rb', line 135 def self.load_component(name, configdir, settings, platform) compfile = File.join(configdir, "#{name}.rb") dsl = Vanagon::Component::DSL.new(name, settings, platform) dsl.instance_eval(File.read(compfile), compfile, 1) dsl._component rescue StandardError => e warn "Error loading project '#{name}' using '#{compfile}':" warn e warn e.backtrace.join("\n") raise e end |
Instance Method Details
#add_file(file) ⇒ Set?
Adds the given file to the list of files and returns @files.
188 189 190 |
# File 'lib/vanagon/component.rb', line 188 def add_file(file) @files.add file end |
#add_rpm_ghost_file(file) ⇒ Set?
Adds the given file to the list of %ghost files to be added to an rpm spec’s %files.
198 199 200 |
# File 'lib/vanagon/component.rb', line 198 def add_rpm_ghost_file(file) @ghost_files.add file end |
#configfiles ⇒ Set
Retrieve all items from @files explicitly marked as configuration files
223 224 225 |
# File 'lib/vanagon/component.rb', line 223 def configfiles @files.select(&:configfile?) end |
#delete_file(file) ⇒ Set?
Deletes the given file from the list of files and returns @files.
209 210 211 |
# File 'lib/vanagon/component.rb', line 209 def delete_file(file) @files.delete_if { |this_file| this_file.path == file } end |
#environment_variables ⇒ Object
423 424 425 |
# File 'lib/vanagon/component.rb', line 423 def environment_variables environment.map { |key, value| %(export #{key}="#{value}") } end |
#fetch_mirrors(options) ⇒ Boolean
Retrieve upstream source file from a mirror, by randomly iterating through #mirrors until there’s no more mirrors left. Will #warn if the mirror’s URI cannot be resolved or if the URI cannot be retrieved. Does not suppress any errors from Vanagon::Component::Source.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/vanagon/component.rb', line 254 def fetch_mirrors() mirrors.to_a.shuffle.each do |mirror| begin warn %(Attempting to fetch from mirror URL "#{mirror}") @source = Vanagon::Component::Source.source(mirror, ) return true if source.fetch rescue SocketError # SocketError means that there was no DNS/name resolution # for whatever remote protocol the mirror tried to use. warn %(Unable to resolve mirror URL "#{mirror}") rescue RuntimeError # Source retrieval does not consistently return a meaningful # namespaced error message, which means we're brute-force rescuing # RuntimeError. Not a good look, and we should fix this. warn %(Unable to retrieve mirror URL "#{mirror}") end end false end |
#fetch_url(options) ⇒ Boolean
Retrieve upstream source file from the canonical URL. Does not suppress any errors from Vanagon::Component::Source.
279 280 281 282 283 284 285 286 |
# File 'lib/vanagon/component.rb', line 279 def fetch_url() warn %(Attempting to fetch from canonical URL "#{url}") @source = Vanagon::Component::Source.source(url, ) # Explicitly coerce the return value of #source.fetch, # because each subclass of Vanagon::Component::Source returns # an inconsistent value if #fetch is successful. !!source.fetch end |
#force_version ⇒ Object
Force version determination for components
If the component doesn’t already have a version set (which normally happens for git sources), the source will be fetched into a temporary directory to attempt to figure out the version if the source type supports :version. This directory will be cleaned once the get_sources method returns
393 394 395 396 397 398 399 400 401 |
# File 'lib/vanagon/component.rb', line 393 def force_version if @version.nil? Dir.mktmpdir do |dir| get_source(dir) end end raise Vanagon::Error, "Unable to determine source version for component #{@name}!" if @version.nil? @version end |
#get_build_dir ⇒ Object
Expands the build directory
333 334 335 336 337 338 339 |
# File 'lib/vanagon/component.rb', line 333 def get_build_dir if @build_dir File.join(@dirname, @build_dir) else @dirname end end |
#get_dependency_hash ⇒ Object
341 342 343 |
# File 'lib/vanagon/component.rb', line 341 def get_dependency_hash { name => { 'version' => version, 'url' => url, 'ref' => [:ref] }.delete_if { |_, v| !v } } end |
#get_environment ⇒ String
Prints the environment in a way suitable for use in a Makefile or shell script. This is deprecated, because all Env. Vars. are moving directly into the Makefile (and out of recipe subshells).
409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/vanagon/component.rb', line 409 def get_environment warn <<-WARNING.undent #get_environment is deprecated; environment variables have been moved into the Makefile, and should not be used within a Makefile's recipe. The #get_environment method will be removed by Vanagon 1.0.0. WARNING if environment.empty? ": no environment variables defined" else environment_variables end end |
#get_patches(patch_root) ⇒ Object
Fetches patches if any are provided for the project.
373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/vanagon/component.rb', line 373 def get_patches(patch_root) return if @patches.empty? @patches.each do |patch| patch_assembly_path = File.join(patch_root, patch.assembly_path) if File.exist?(patch_assembly_path) raise Vanagon::Error, "Duplicate patch files detected, '#{patch.origin_path}' would have overwritten '#{patch.assembly_path}'. Ensure all patch file names within a component are unique." end patch_target_directory = File.dirname(patch_assembly_path) FileUtils.mkdir_p(patch_target_directory) FileUtils.cp(patch.origin_path, patch_assembly_path) end end |
#get_source(workdir) ⇒ Object
Fetches the primary source for the component. As a side effect, also sets @extract_with, @dirname and @version for the component for use in the makefile template
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/vanagon/component.rb', line 303 def get_source(workdir) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity opts = .merge({ workdir: workdir }) if url || !mirrors.empty? if ENV['VANAGON_USE_MIRRORS'] == 'n' fetch_url(opts) else fetch_mirrors(opts) || fetch_url(opts) end source.verify extract_with << source.extract(platform.tar) if source.respond_to? :extract @cleanup_source = source.cleanup if source.respond_to?(:cleanup) @dirname ||= source.dirname # Git based sources probably won't set the version, so we load it if it hasn't been already set if source.respond_to?(:version) @version ||= source.version end else warn "No source given for component '#{@name}'" # If there is no source, we don't want to try to change directories, so we just change to the current directory. @dirname = './' # If there is no source, there is nothing to do to extract extract_with << ': no source, so nothing to extract' end end |
#get_sources(workdir) ⇒ Object
Fetches secondary sources for the component. These are just dumped into the workdir currently.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/vanagon/component.rb', line 348 def get_sources(workdir) # rubocop:disable Metrics/AbcSize sources.each do |source| src = Vanagon::Component::Source.source( source.url, workdir: workdir, ref: source.ref, sum: source.sum ) src.fetch src.verify if source.erb erb_file(src.file, File.join(File.dirname(src.file), File.basename(src.file, ".erb")), true) end # set src.file to only be populated with the basename instead of entire file path src.file = File.basename(src.url) extract_with << src.extract(platform.tar) if src.respond_to? :extract end end |
#rpm_ghost_files ⇒ Array
Retrieve all the files intended as %ghost entries for an rpm spec %files section.
231 232 233 |
# File 'lib/vanagon/component.rb', line 231 def rpm_ghost_files @ghost_files.to_a end |