Class: Omnibus::Packager::Base

Inherits:
Object
  • Object
show all
Includes:
Cleanroom, Digestable, Logging, NullArgumentable, Sugarable, 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 Sugarable

extended, included, #node

Methods included from NullArgumentable

included, #null?

Methods included from Logging

included

Methods included from Digestable

#digest, #digest_directory, included

Constructor Details

#initialize(project) ⇒ Base

Create a new packager object.


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

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

The Omnibus::Project instance that we are packaging


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

def project
  @project
end

Class Method Details

.build(&block) ⇒ Object

The commands/steps to build the package.


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

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

.id(name) ⇒ Object

Set the unique of this packager.

See Also:

  • {{#id}

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

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.


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

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


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

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)

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

def id
  raise NotImplementedError
end

#install_dirString

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


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

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)

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

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.


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

def package_path
  File.expand_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"

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

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"

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

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

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

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.


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

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