Class: Vanagon::Project::DSL
- Inherits:
-
Object
- Object
- Vanagon::Project::DSL
- Defined in:
- lib/vanagon/project/dsl.rb
Instance Method Summary collapse
-
#_project ⇒ Vanagon::Project
Accessor for the project.
-
#bill_of_materials(target) ⇒ Object
This method will write the project’s bill-of-materials to a designated directory during package creation.
-
#cleanup_during_build ⇒ Object
Toggle to apply additional cleanup during the build for space constrained systems.
-
#component(name) ⇒ Object
Adds a component to the project.
-
#conflicts(pkgname, version = nil) ⇒ Object
Indicates that this component conflicts with another package, so both cannot be installed at the same time.
-
#description(descr) ⇒ Object
Sets the description of the project.
-
#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.
-
#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.
-
#fetch_artifact(path) ⇒ Object
Set additional artifacts to fetch from the build.
-
#generate_archives(archive) ⇒ Object
Output os-specific archives containing the binary output.
-
#generate_packages(pkg) ⇒ Object
Generate os-specific packaging artifacts (rpm, deb, etc).
-
#generate_source_artifacts(source_artifacts) ⇒ Object
Generate source packages in addition to binary packages.
-
#homepage(page) ⇒ Object
Sets the homepage for the project.
-
#identifier(ident) ⇒ Object
Sets the identifier for the project.
-
#inherit_settings(upstream_project_name, upstream_git_url, upstream_git_branch) ⇒ Object
Inherit the settings hash from an upstream project.
-
#initialize(name, platform, include_components = []) ⇒ Vanagon::Project::DSL
constructor
Constructor for the DSL object.
-
#license(lic) ⇒ Object
Sets the license for the project.
-
#method_missing(method_name, *args) ⇒ Object
Project attributes and DSL methods defined below.
-
#name(the_name) ⇒ Object
Resets the name of the project.
-
#no_packaging(var) ⇒ Object
Set to true to skip packaging steps during the vanagon build.
-
#noarch ⇒ Object
Sets the project to be architecture independent, or noarch.
-
#package_override(var) ⇒ Object
Set a package override.
-
#project(name, &block) {|_self| ... } ⇒ Object
Primary way of interacting with the DSL.
-
#provides(provide, version = nil) ⇒ Object
Indicates that this component provides a system level package.
-
#register_rewrite_rule(protocol, rule) ⇒ Object
Sets up a rewrite rule for component sources for a given protocol.
-
#release(rel) ⇒ Object
Sets the release for the project.
-
#release_from_git ⇒ Object
Sets the release for the project to the number of commits since the last tag.
-
#replaces(replacement, version = nil) ⇒ Object
Indicates that this component replaces a system level package.
-
#requires(req) ⇒ Object
Sets the run time requirements for the project.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#retry_count(retry_count) ⇒ Object
Counter for the number of times a project should retry a task.
-
#setting(name, value) ⇒ Object
Sets a key value pair on the settings hash of the project.
- #settings ⇒ Object
-
#target_repo(repo) ⇒ Object
Adds a target repo for the project.
-
#timeout(to) ⇒ Object
Sets the timeout for the project retry logic.
-
#user(name, group: nil, shell: nil, is_system: false, homedir: nil) ⇒ Object
Add a user to the project.
-
#vendor(vend) ⇒ Object
Sets the vendor for the project.
-
#version(ver) ⇒ Object
Sets the version for the project.
-
#version_from_branch ⇒ Object
Get the version string from a git branch name.
-
#version_from_git ⇒ Object
Sets the version for the project based on a git describe of the directory that holds the configs.
-
#write_version_file(target) ⇒ Object
This method will write the project’s version to a designated file during package creation.
Constructor Details
#initialize(name, platform, include_components = []) ⇒ Vanagon::Project::DSL
Constructor for the DSL object
16 17 18 19 20 |
# File 'lib/vanagon/project/dsl.rb', line 16 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.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vanagon/project/dsl.rb', line 48 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
#_project ⇒ Vanagon::Project
Accessor for the project.
33 34 35 |
# File 'lib/vanagon/project/dsl.rb', line 33 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.
307 308 309 |
# File 'lib/vanagon/project/dsl.rb', line 307 def bill_of_materials(target) @project.bill_of_materials = Vanagon::Common::Pathname.new(target) end |
#cleanup_during_build ⇒ Object
Toggle to apply additional cleanup during the build for space constrained systems
295 296 297 |
# File 'lib/vanagon/project/dsl.rb', line 295 def cleanup_during_build @project.cleanup = true end |
#component(name) ⇒ Object
Adds a component to the project
266 267 268 269 270 271 272 |
# File 'lib/vanagon/project/dsl.rb', line 266 def component(name) warn "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.
134 135 136 |
# File 'lib/vanagon/project/dsl.rb', line 134 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.
80 81 82 |
# File 'lib/vanagon/project/dsl.rb', line 80 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
228 229 230 |
# File 'lib/vanagon/project/dsl.rb', line 228 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
234 235 236 |
# File 'lib/vanagon/project/dsl.rb', line 234 def environment(name, value) @project.environment[name] = value end |
#fetch_artifact(path) ⇒ Object
Set additional artifacts to fetch from the build
337 338 339 |
# File 'lib/vanagon/project/dsl.rb', line 337 def fetch_artifact(path) @project.artifacts_to_fetch << path end |
#generate_archives(archive) ⇒ Object
Output os-specific archives containing the binary output
171 172 173 |
# File 'lib/vanagon/project/dsl.rb', line 171 def generate_archives(archive) @project.compiled_archive = archive end |
#generate_packages(pkg) ⇒ Object
Generate os-specific packaging artifacts (rpm, deb, etc)
164 165 166 |
# File 'lib/vanagon/project/dsl.rb', line 164 def generate_packages(pkg) @project.generate_packages = pkg end |
#generate_source_artifacts(source_artifacts) ⇒ Object
Generate source packages in addition to binary packages. Currently only implemented for rpm/deb packages.
157 158 159 |
# File 'lib/vanagon/project/dsl.rb', line 157 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.
94 95 96 |
# File 'lib/vanagon/project/dsl.rb', line 94 def homepage(page) @project.homepage = page end |
#identifier(ident) ⇒ Object
Sets the identifier for the project. Mainly for use in OSX packaging.
259 260 261 |
# File 'lib/vanagon/project/dsl.rb', line 259 def identifier(ident) @project.identifier = ident end |
#inherit_settings(upstream_project_name, upstream_git_url, upstream_git_branch) ⇒ Object
Inherit the settings hash from an upstream project
321 322 323 |
# File 'lib/vanagon/project/dsl.rb', line 321 def inherit_settings(upstream_project_name, upstream_git_url, upstream_git_branch) @project.load_upstream_settings(upstream_project_name, upstream_git_url, upstream_git_branch) end |
#license(lic) ⇒ Object
Sets the license for the project. Mainly for use in packaging.
252 253 254 |
# File 'lib/vanagon/project/dsl.rb', line 252 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.
87 88 89 |
# File 'lib/vanagon/project/dsl.rb', line 87 def name(the_name) @project.name = the_name end |
#no_packaging(var) ⇒ Object
Set to true to skip packaging steps during the vanagon build
344 345 346 |
# File 'lib/vanagon/project/dsl.rb', line 344 def no_packaging(var) @project.no_packaging = var end |
#noarch ⇒ Object
Sets the project to be architecture independent, or noarch
282 283 284 |
# File 'lib/vanagon/project/dsl.rb', line 282 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.
329 330 331 332 |
# File 'lib/vanagon/project/dsl.rb', line 329 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
26 27 28 |
# File 'lib/vanagon/project/dsl.rb', line 26 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.
124 125 126 |
# File 'lib/vanagon/project/dsl.rb', line 124 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
290 291 292 |
# File 'lib/vanagon/project/dsl.rb', line 290 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.
148 149 150 |
# File 'lib/vanagon/project/dsl.rb', line 148 def release(rel) @project.release = rel end |
#release_from_git ⇒ Object
Sets the release for the project to the number of commits since the last tag. Requires that a git tag be present and reachable from the current commit in that repository.
179 180 181 182 183 184 185 |
# File 'lib/vanagon/project/dsl.rb', line 179 def release_from_git repo_object = Git.open(File.("..", Vanagon::Driver.configdir)) last_tag = repo_object.describe('HEAD', { :abbrev => 0 }) release(repo_object.rev_list("#{last_tag}..HEAD", { :count => true })) rescue Git::GitExecuteError warn "Directory '#{dirname}' cannot be versioned by git. Maybe it hasn't been tagged yet?" 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.
116 117 118 |
# File 'lib/vanagon/project/dsl.rb', line 116 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.
108 109 110 |
# File 'lib/vanagon/project/dsl.rb', line 108 def requires(req) @project.requires << req end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
60 61 62 |
# File 'lib/vanagon/project/dsl.rb', line 60 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
312 313 314 |
# File 'lib/vanagon/project/dsl.rb', line 312 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
69 70 71 |
# File 'lib/vanagon/project/dsl.rb', line 69 def setting(name, value) @project.settings[name] = value end |
#settings ⇒ Object
73 74 75 |
# File 'lib/vanagon/project/dsl.rb', line 73 def settings @project.settings end |
#target_repo(repo) ⇒ Object
Adds a target repo for the project
277 278 279 |
# File 'lib/vanagon/project/dsl.rb', line 277 def target_repo(repo) @project.repo = repo end |
#timeout(to) ⇒ Object
Sets the timeout for the project retry logic
101 102 103 |
# File 'lib/vanagon/project/dsl.rb', line 101 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
245 246 247 |
# File 'lib/vanagon/project/dsl.rb', line 245 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.
218 219 220 |
# File 'lib/vanagon/project/dsl.rb', line 218 def vendor(vend) @project.vendor = vend end |
#version(ver) ⇒ Object
Sets the version for the project. Mainly for use in packaging.
141 142 143 |
# File 'lib/vanagon/project/dsl.rb', line 141 def version(ver) @project.version = ver.tr('-', '.') end |
#version_from_branch ⇒ Object
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’.
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/vanagon/project/dsl.rb', line 204 def version_from_branch branch = Git.open(File.("..", 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_git ⇒ Object
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.
191 192 193 194 195 196 |
# File 'lib/vanagon/project/dsl.rb', line 191 def version_from_git git_version = Git.open(File.("..", 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 |