Class: Omnibus::Packager::Base

Inherits:
Object
  • Object
show all
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

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

#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

extended, included, #node

Methods included from NullArgumentable

included, #null?

Methods included from Logging

included

Methods included from Instrumentation

#measure

Methods included from Digestable

#digest, #digest_directory, included

Constructor Details

#initialize(project) ⇒ Base

Create a new packager object.

Parameters:



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

def initialize(project)
  @project = project
end

Instance Attribute Details

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

Parameters:

  • name (Symbol)

    the id

See Also:

  • {{#id}


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

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

Returns:

  • (Array<String>)


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

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

Returns:

  • (Symbol)

Raises:

  • (NotImplementedError)


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

def id
  raise NotImplementedError
end

#install_dirString

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

Returns:

  • (String)


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

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.

Returns:

  • (String)

Raises:

  • (NotImplementedError)


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

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.

Returns:

  • (String)


190
191
192
# File 'lib/omnibus/packagers/base.rb', line 190

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"

Parameters:

  • name (String)

    the name of the resource on disk to find



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_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"

Returns:

  • (String)


252
253
254
# File 'lib/omnibus/packagers/base.rb', line 252

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


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

Examples:

skip_package true

Parameters:

  • value (TrueClass, FalseClass)

    whether to delay validation or not

Returns:

  • (TrueClass, FalseClass)

    whether to skip this packager type or not



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_dirString

The path to the staging dir on disk.

Returns:

  • (String)


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

Returns:

  • (String)


208
209
210
# File 'lib/omnibus/packagers/base.rb', line 208

def staging_dir_path(file_name)
  File.join(staging_dir, file_name)
end