Class: Omnibus::Packager::Base
- Inherits:
-
Object
- Object
- Omnibus::Packager::Base
- Includes:
- Cleanroom, Digestable, Instrumentation, Logging, NullArgumentable, Sugarable, Templating, Util
- Defined in:
- lib/omnibus/packagers/base.rb
Direct Known Subclasses
Compressor::Base, BFF, DEB, IPS, Makeself, PKG, PKGSRC, RPM, Solaris, WindowsBase
Constant Summary
Constants included from Util
Constants included from NullArgumentable
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
The Omnibus::Project instance that we are packaging.
DSL methods collapse
-
#install_dir ⇒ String
Retrieve the path at which the project will be installed by the generated package.
-
#skip_packager(val = false) ⇒ TrueClass, FalseClass
Skip this packager during build process.
Resource methods collapse
-
#resource_path(name) ⇒ Object
The preferred path to a resource on disk with the given
name
. -
#resources_path ⇒ String
The path where this packager’s resources reside on disk.
Class Method Summary collapse
-
.build(&block) ⇒ Object
The commands/steps to build the package.
-
.id(name) ⇒ Object
Set the unique of this packager.
-
.setup(&block) ⇒ Object
The commands/steps use to setup the filesystem.
Instance Method Summary collapse
-
#exclusions ⇒ Array<String>
The list of files to exclude when syncing files.
-
#id ⇒ Symbol
abstract
The unique identifier for this class - this is used in file paths and packager searching, so please do not change unless you know what you are doing!.
-
#initialize(project) ⇒ Base
constructor
Create a new packager object.
-
#package_name ⇒ String
abstract
The ending name of this package on disk.
-
#package_path ⇒ String
The path to the rendered package on disk.
-
#run! ⇒ Object
Execute this packager by running the following phases in order:.
-
#staging_dir ⇒ String
The path to the staging dir on disk.
-
#staging_dir_path(file_name) ⇒ String
Helper method to produce staging paths.
Methods included from Util
#compiler_safe_path, #copy_file, #create_directory, #create_file, #create_link, included, #path_key, #remove_directory, #remove_file, #retry_block, #shellout, #shellout!, #windows_safe_path
Methods included from Templating
included, #render_template, #render_template_content
Methods included from Sugarable
Methods included from NullArgumentable
Methods included from Logging
Methods included from Instrumentation
Methods included from Digestable
#digest, #digest_directory, included
Constructor Details
#initialize(project) ⇒ Base
Create a new packager object.
66 67 68 |
# File 'lib/omnibus/packagers/base.rb', line 66 def initialize(project) @project = project end |
Instance Attribute Details
#project ⇒ Object (readonly)
The Omnibus::Project instance that we are packaging
31 32 33 |
# File 'lib/omnibus/packagers/base.rb', line 31 def project @project end |
Class Method Details
.build(&block) ⇒ Object
The commands/steps to build the package.
56 57 58 |
# File 'lib/omnibus/packagers/base.rb', line 56 def build(&block) block ? @build = block : @build end |
.id(name) ⇒ Object
Set the unique of this packager.
42 43 44 45 46 47 48 |
# File 'lib/omnibus/packagers/base.rb', line 42 def id(name) class_eval <<-EOH, __FILE__, __LINE__ def id :#{name} end EOH end |
.setup(&block) ⇒ Object
The commands/steps use to setup the filesystem.
51 52 53 |
# File 'lib/omnibus/packagers/base.rb', line 51 def setup(&block) block ? @setup = block : @setup end |
Instance Method Details
#exclusions ⇒ Array<String>
The list of files to exclude when syncing files. This comes from the list of project exclusions and includes “common” SCM directories (like .git
).
101 102 103 104 105 106 107 108 |
# File 'lib/omnibus/packagers/base.rb', line 101 def exclusions project.exclusions + %w{ **/.git **/.hg **/.svn **/.gitkeep } end |
#id ⇒ Symbol
Subclasses should define the id
attribute.
The unique identifier for this class - this is used in file paths and packager searching, so please do not change unless you know what you are doing!
79 80 81 |
# File 'lib/omnibus/packagers/base.rb', line 79 def id raise NotImplementedError end |
#install_dir ⇒ String
Retrieve the path at which the project will be installed by the generated package.
120 121 122 |
# File 'lib/omnibus/packagers/base.rb', line 120 def install_dir project.install_dir end |
#package_name ⇒ String
The ending name of this package on disk. This method is used to generate metadata about the package after it is built.
91 92 93 |
# File 'lib/omnibus/packagers/base.rb', line 91 def package_name raise NotImplementedError end |
#package_path ⇒ String
The path to the rendered package on disk. This is calculated by combining the Config#package_dir with the name of the package, as calculated by one of the subclasses.
190 191 192 |
# File 'lib/omnibus/packagers/base.rb', line 190 def package_path File.(File.join(Config.package_dir, package_name)) end |
#resource_path(name) ⇒ Object
The preferred path to a resource on disk with the given name
. This method will perform an “intelligent” search for a resource by first looking in the local project expected #resources_path, and then falling back to Omnibus’ files.
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/omnibus/packagers/base.rb', line 231 def resource_path(name) local = File.join(resources_path, name) if File.exist?(local) log.info(log_key) { "Using local resource `#{name}' from `#{local}'" } local else log.debug(log_key) { "Using vendored resource `#{name}'" } Omnibus.source_root.join("resources/#{id}/#{name}").to_s end end |
#resources_path ⇒ String
The path where this packager’s resources reside on disk. This is the given Omnibus::Project#resources_path combined with the packager’s #id.
252 253 254 |
# File 'lib/omnibus/packagers/base.rb', line 252 def resources_path File.("#{project.resources_path}/#{id}") end |
#run! ⇒ Object
Execute this packager by running the following phases in order:
- setup
- build
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/omnibus/packagers/base.rb', line 160 def run! # Ensure the package directory exists create_directory(Config.package_dir) measure("Packaging time") do # Run the setup and build sequences instance_eval(&self.class.setup) if self.class.setup instance_eval(&self.class.build) if self.class.build # Render the metadata Metadata.generate(package_path, project) # Ensure the temporary directory is removed at the end of a successful # run. Without removal, successful builds will "leak" in /tmp and cause # increased disk usage. # # Instead of having this as an +ensure+ block, failed builds will persist # this directory so developers can go poke around and figure out why the # build failed. remove_directory(staging_dir) end end |
#skip_packager(val = false) ⇒ TrueClass, FalseClass
Skip this packager during build process
141 142 143 144 145 146 147 |
# File 'lib/omnibus/packagers/base.rb', line 141 def skip_packager(val = false) unless val.is_a?(TrueClass) || val.is_a?(FalseClass) raise InvalidValue.new(:skip_packager, "be TrueClass or FalseClass") end @skip_package ||= val end |
#staging_dir ⇒ String
The path to the staging dir on disk.
199 200 201 |
# File 'lib/omnibus/packagers/base.rb', line 199 def staging_dir @staging_dir ||= Dir.mktmpdir(project.package_name) end |
#staging_dir_path(file_name) ⇒ String
Helper method to produce staging paths
208 209 210 |
# File 'lib/omnibus/packagers/base.rb', line 208 def staging_dir_path(file_name) File.join(staging_dir, file_name) end |