Class: Omnibus::Packager::Base

Inherits:
Object
  • Object
show all
Includes:
Cleanroom, Digestable, Logging, NullArgumentable, Templating, Util
Defined in:
lib/omnibus/packagers/base.rb

Direct Known Subclasses

Compressor::Base, BFF, DEB, MSI, Makeself, PKG, RPM, Solaris

Constant Summary

Constants included from Util

Util::SHELLOUT_OPTIONS

Constants included from NullArgumentable

NullArgumentable::NULL

Instance Attribute Summary collapse

DSL methods collapse

Resource methods collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#copy_file, #create_directory, #create_file, #create_link, included, #remove_directory, #remove_file, #shellout, #shellout!, #windows_safe_path

Methods included from Templating

included, #render_template

Methods included from NullArgumentable

included, #null?

Methods included from Logging

included

Methods included from Digestable

#digest, #digest_directory

Constructor Details

#initialize(project) ⇒ Base

Create a new packager object.


64
65
66
# File 'lib/omnibus/packagers/base.rb', line 64

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

The Omnibus::Project instance that we are packaging


29
30
31
# File 'lib/omnibus/packagers/base.rb', line 29

def project
  @project
end

Class Method Details

.build(&block) ⇒ Object

The commands/steps to build the package.


54
55
56
# File 'lib/omnibus/packagers/base.rb', line 54

def build(&block)
  block ? @build = block : @build
end

.id(name) ⇒ Object

Set the unique of this packager.

See Also:

  • {{#id}

40
41
42
43
44
45
46
# File 'lib/omnibus/packagers/base.rb', line 40

def id(name)
  class_eval "def id\n:\#{name}\nend\n", __FILE__, __LINE__
end

.setup(&block) ⇒ Object

The commands/steps use to setup the filesystem.


49
50
51
# File 'lib/omnibus/packagers/base.rb', line 49

def setup(&block)
  block ? @setup = block : @setup
end

Instance Method Details

#exclusionsArray<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).


99
100
101
102
103
104
105
106
# File 'lib/omnibus/packagers/base.rb', line 99

def exclusions
  project.exclusions + %w(
    **/.git
    **/.hg
    **/.svn
    **/.gitkeep
  )
end

#idSymbol

This method is abstract.

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!

Raises:

  • (NotImplementedError)

77
78
79
# File 'lib/omnibus/packagers/base.rb', line 77

def id
  raise NotImplementedError
end

#install_dirString

Retrieve the path at which the project will be installed by the generated package.


118
119
120
# File 'lib/omnibus/packagers/base.rb', line 118

def install_dir
  project.install_dir
end

#package_nameString

This method is abstract.

The ending name of this package on disk. This method is used to generate metadata about the package after it is built.

Raises:

  • (NotImplementedError)

89
90
91
# File 'lib/omnibus/packagers/base.rb', line 89

def package_name
  raise NotImplementedError
end

#package_pathString

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.


166
167
168
# File 'lib/omnibus/packagers/base.rb', line 166

def package_path
  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.

Examples:

When the resource exists locally

resource_path("spec.erb") #=> "/path/to/project/resources/rpm/spec.erb"

When the resource does not exist locally

resource_path("spec.erb") #=> "/omnibus-x.y.z/resources/rpm/spec.erb"

198
199
200
201
202
203
204
205
206
207
208
# File 'lib/omnibus/packagers/base.rb', line 198

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_pathString

The path where this packager's resources reside on disk. This is the given Omnibus::Project#resources_path combined with the packager's #id.

Examples:

RPM packager

resources_path #=> "/path/to/project/resources/rpm"

219
220
221
# File 'lib/omnibus/packagers/base.rb', line 219

def resources_path
  File.expand_path("#{project.resources_path}/#{id}")
end

#run!Object

Execute this packager by running the following phases in order:

- setup
- build

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/omnibus/packagers/base.rb', line 138

def run!
  # Ensure the package directory exists
  create_directory(Config.package_dir)

  # 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
  .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

#staging_dirString

The path to the staging dir on disk.


175
176
177
# File 'lib/omnibus/packagers/base.rb', line 175

def staging_dir
  @staging_dir ||= Dir.mktmpdir(project.package_name)
end