Class: Vanagon::Project::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/vanagon/project/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, platform, include_components = []) ⇒ Vanagon::Project::DSL

Constructor for the DSL object

Parameters:

  • name (String)

    name of the project

  • platform (Vanagon::Platform)

    platform for the project to build against

  • include_components (List) (defaults to: [])

    optional list restricting the loaded components



15
16
17
18
19
# File 'lib/vanagon/project/dsl.rb', line 15

def initialize(name, platform, include_components = [])
  @name = name
  @project = Vanagon::Project.new(@name, platform)
  @include_components = include_components.to_set
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Project attributes and DSL methods defined below

All purpose getter. This object, which is passed to the project block, won’t have easy access to the attributes of the @project, so we make a getter for each attribute.

We only magically handle get_ methods, any other methods just get the standard method_missing treatment.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vanagon/project/dsl.rb', line 47

def method_missing(method_name, *args)
  attribute_match = method_name.to_s.match(/get_(.*)/)
  if attribute_match
    attribute = attribute_match.captures.first
    @project.send(attribute)
  elsif @project.settings.key?(method_name)
    return @project.settings[method_name]
  else
    super
  end
end

Instance Method Details

#_projectVanagon::Project

Accessor for the project.

Returns:



32
33
34
# File 'lib/vanagon/project/dsl.rb', line 32

def _project
  @project
end

#bill_of_materials(target) ⇒ Object

This method will write the project’s bill-of-materials to a designated directory during package creation.

Parameters:

  • target (String)

    a full path to the directory for the bill-of-materials for the project



280
281
282
# File 'lib/vanagon/project/dsl.rb', line 280

def bill_of_materials(target)
  @project.bill_of_materials = Vanagon::Common::Pathname.new(target)
end

#cleanup_during_buildObject

Toggle to apply additional cleanup during the build for space constrained systems



268
269
270
# File 'lib/vanagon/project/dsl.rb', line 268

def cleanup_during_build
  @project.cleanup = true
end

#component(name) ⇒ Object

Adds a component to the project

Parameters:

  • name (String)

    name of component to add. must be present in configdir/components and named $name.rb currently



239
240
241
242
243
244
245
# File 'lib/vanagon/project/dsl.rb', line 239

def component(name)
  $stderr.puts "Loading #{name}" if @project.settings[:verbose]
  if @include_components.empty? or @include_components.include?(name)
    component = Vanagon::Component.load_component(name, File.join(Vanagon::Driver.configdir, "components"), @project.settings, @project.platform)
    @project.components << component
  end
end

#conflicts(pkgname, version = nil) ⇒ Object

Indicates that this component conflicts with another package, so both cannot be installed at the same time. Conflicts can be collected and used by the project and package.

Parameters:

  • pkgname (String)

    name of the package which conflicts with this component

  • version (String) (defaults to: nil)

    the version of the package that conflicts with this component



133
134
135
# File 'lib/vanagon/project/dsl.rb', line 133

def conflicts(pkgname, version = nil)
  @project.conflicts << OpenStruct.new(:pkgname => pkgname, :version => version)
end

#description(descr) ⇒ Object

Sets the description of the project. Mainly for use in packaging.

Parameters:

  • descr (String)

    description of the project



79
80
81
# File 'lib/vanagon/project/dsl.rb', line 79

def description(descr)
  @project.description = descr
end

#directory(dir, mode: nil, owner: nil, group: nil) ⇒ Object

Adds a directory to the list of directories provided by the project, to be included in any packages of the project

Parameters:

  • dir (String)

    directory to add to the project

  • mode (String) (defaults to: nil)

    octal mode to apply to the directory

  • owner (String) (defaults to: nil)

    owner of the directory

  • group (String) (defaults to: nil)

    group of the directory



201
202
203
# File 'lib/vanagon/project/dsl.rb', line 201

def directory(dir, mode: nil, owner: nil, group: nil)
  @project.directories << Vanagon::Common::Pathname.new(dir, mode: mode, owner: owner, group: group)
end

#environment(name, value) ⇒ Object

Adds an arbitrary environment variable to the project, which will be passed on to the platform and inherited by any components built on that platform



207
208
209
# File 'lib/vanagon/project/dsl.rb', line 207

def environment(name, value)
  @project.environment[name] = value
end

#generate_source_artifacts(source_artifacts) ⇒ Object

Generate source packages in addition to binary packages. Currently only implemented for rpm/deb packages.

Parameters:

  • source_artifacts (Boolean)

    whether or not to output source packages



156
157
158
# File 'lib/vanagon/project/dsl.rb', line 156

def generate_source_artifacts(source_artifacts)
  @project.source_artifacts = source_artifacts
end

#homepage(page) ⇒ Object

Sets the homepage for the project. Mainly for use in packaging.

Parameters:

  • page (String)

    url of homepage of the project



93
94
95
# File 'lib/vanagon/project/dsl.rb', line 93

def homepage(page)
  @project.homepage = page
end

#identifier(ident) ⇒ Object

Sets the identifier for the project. Mainly for use in OSX packaging.

Parameters:

  • ident (String)

    uses the reverse-domain naming convention



232
233
234
# File 'lib/vanagon/project/dsl.rb', line 232

def identifier(ident)
  @project.identifier = ident
end

#license(lic) ⇒ Object

Sets the license for the project. Mainly for use in packaging.

Parameters:

  • lic (String)

    the license the project is released under



225
226
227
# File 'lib/vanagon/project/dsl.rb', line 225

def license(lic)
  @project.license = lic
end

#name(the_name) ⇒ Object

Resets the name of the project. Is useful for dynamically changing the project name.

Parameters:

  • the_name (String)

    name of the project



86
87
88
# File 'lib/vanagon/project/dsl.rb', line 86

def name(the_name)
  @project.name = the_name
end

#noarchObject

Sets the project to be architecture independent, or noarch



255
256
257
# File 'lib/vanagon/project/dsl.rb', line 255

def noarch
  @project.noarch = true
end

#package_override(var) ⇒ Object

Set a package override. Will call the platform-specific implementation This will get set in the spec file, deb rules, etc.

Parameters:

  • var

    the string to be included in the build script



293
294
295
296
# File 'lib/vanagon/project/dsl.rb', line 293

def package_override(var)
  platform = @project.platform
  platform.package_override(self._project, var)
end

#project(name, &block) {|_self| ... } ⇒ Object

Primary way of interacting with the DSL

Parameters:

  • name (String)

    name of the project

  • block (Proc)

    DSL definition of the project to call

Yields:

  • (_self)

Yield Parameters:



25
26
27
# File 'lib/vanagon/project/dsl.rb', line 25

def project(name, &block)
  yield(self)
end

#provides(provide, version = nil) ⇒ Object

Indicates that this component provides a system level package. Provides can be collected and used by the project and package.

Parameters:

  • provide (String)

    a package that is provided with this component

  • version (String) (defaults to: nil)

    the version of the package that is provided with this component



123
124
125
# File 'lib/vanagon/project/dsl.rb', line 123

def provides(provide, version = nil)
  @project.provides << OpenStruct.new(:provide => provide, :version => version)
end

#register_rewrite_rule(protocol, rule) ⇒ Object

Sets up a rewrite rule for component sources for a given protocol

Parameters:

  • protocol (String)

    a supported component source type (Http, Git, …)

  • rule (String, Proc)

    a rule used to rewrite component source urls



263
264
265
# File 'lib/vanagon/project/dsl.rb', line 263

def register_rewrite_rule(protocol, rule)
  Vanagon::Component::Source::Rewrite.register_rewrite_rule(protocol, rule)
end

#release(rel) ⇒ Object

Sets the release for the project. Mainly for use in packaging.

Parameters:

  • rel (String)

    release of the project



147
148
149
# File 'lib/vanagon/project/dsl.rb', line 147

def release(rel)
  @project.release = rel
end

#replaces(replacement, version = nil) ⇒ Object

Indicates that this component replaces a system level package. Replaces can be collected and used by the project and package.

Parameters:

  • replacement (String)

    a package that is replaced with this component

  • version (String) (defaults to: nil)

    the version of the package that is replaced



115
116
117
# File 'lib/vanagon/project/dsl.rb', line 115

def replaces(replacement, version = nil)
  @project.replaces << OpenStruct.new(:replacement => replacement, :version => version)
end

#requires(req) ⇒ Object

Sets the run time requirements for the project. Mainly for use in packaging.

Parameters:

  • req (String)

    of requirements of the project



107
108
109
# File 'lib/vanagon/project/dsl.rb', line 107

def requires(req)
  @project.requires << req
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/vanagon/project/dsl.rb', line 59

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.start_with?('get_') || @project.settings.key?(method_name) || super
end

#retry_count(retry_count) ⇒ Object

Counter for the number of times a project should retry a task



285
286
287
# File 'lib/vanagon/project/dsl.rb', line 285

def retry_count(retry_count)
  @project.retry_count = retry_count
end

#setting(name, value) ⇒ Object

Sets a key value pair on the settings hash of the project

Parameters:

  • name (String)

    name of the setting

  • value (String)

    value of the setting



68
69
70
# File 'lib/vanagon/project/dsl.rb', line 68

def setting(name, value)
  @project.settings[name] = value
end

#settingsObject



72
73
74
# File 'lib/vanagon/project/dsl.rb', line 72

def settings
  @project.settings
end

#target_repo(repo) ⇒ Object

Adds a target repo for the project

Parameters:

  • repo (String)

    name of the target repository to ship to used in laying out the packages on disk



250
251
252
# File 'lib/vanagon/project/dsl.rb', line 250

def target_repo(repo)
  @project.repo = repo
end

#timeout(to) ⇒ Object

Sets the timeout for the project retry logic

Parameters:

  • page (Integer)

    timeout in seconds



100
101
102
# File 'lib/vanagon/project/dsl.rb', line 100

def timeout(to)
  @project.timeout = to
end

#user(name, group: nil, shell: nil, is_system: false, homedir: nil) ⇒ Object

Add a user to the project

Parameters:

  • name (String)

    name of the user to create

  • group (String) (defaults to: nil)

    group of the user

  • shell (String) (defaults to: nil)

    login shell to set for the user

  • is_system (true, false) (defaults to: false)

    if the user should be a system user

  • homedir (String) (defaults to: nil)

    home directory for the user



218
219
220
# File 'lib/vanagon/project/dsl.rb', line 218

def user(name, group: nil, shell: nil, is_system: false, homedir: nil)
  @project.user = Vanagon::Common::User.new(name, group, shell, is_system, homedir)
end

#vendor(vend) ⇒ Object

Sets the vendor for the project. Used in packaging artifacts.

Parameters:

  • vend (String)

    vendor or author of the project



191
192
193
# File 'lib/vanagon/project/dsl.rb', line 191

def vendor(vend)
  @project.vendor = vend
end

#version(ver) ⇒ Object

Sets the version for the project. Mainly for use in packaging.

Parameters:

  • ver (String)

    version of the project



140
141
142
# File 'lib/vanagon/project/dsl.rb', line 140

def version(ver)
  @project.version = ver.tr('-', '.')
end

#version_from_branchObject

Get the version string from a git branch name. This will look for a ‘.’ delimited string of numbers of any length and return that as the version. For example, ‘maint/1.7.0/fixing-some-bugs’ will return ‘1.7.0’ and ‘4.8.x’ will return ‘4.8’.

Returns:

  • version string parsed from branch name, fails if unable to find version



177
178
179
180
181
182
183
184
185
186
# File 'lib/vanagon/project/dsl.rb', line 177

def version_from_branch
  branch = Git.open(File.expand_path("..", Vanagon::Driver.configdir)).current_branch
  if branch =~ /(\d+(\.\d+)+)/
    return $1
  else
    fail "Can't find a version in your branch, make sure it matches <number>.<number>, like maint/1.7.0/fixing-some-bugs"
  end
rescue Git::GitExecuteError => e
  fail "Something went wrong trying to find your git branch.\n#{e}"
end

#version_from_gitObject

Sets the version for the project based on a git describe of the directory that holds the configs. Requires that a git tag be present and reachable from the current commit in that repository.



164
165
166
167
168
169
# File 'lib/vanagon/project/dsl.rb', line 164

def version_from_git
  git_version = Git.open(File.expand_path("..", Vanagon::Driver.configdir)).describe('HEAD', tags: true)
  version(git_version.split('-').reject(&:empty?).join('.'))
rescue Git::GitExecuteError
  warn "Directory '#{dirname}' cannot be versioned by git. Maybe it hasn't been tagged yet?"
end

#write_version_file(target) ⇒ Object

This method will write the project’s version to a designated file during package creation

Parameters:

  • target (String)

    a full path to the version file for the project



274
275
276
# File 'lib/vanagon/project/dsl.rb', line 274

def write_version_file(target)
  @project.version_file = Vanagon::Common::Pathname.file(target)
end