Class: Vanagon::Project

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

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#erb_file, #erb_string, #ex, #find_program_on_path, #get_md5sum, #get_sum, #git, #git_version, #http_request, #is_git_repo?, #local_command, #remote_ssh_command, #retry_with_timeout, #rsync_from, #rsync_to, #ssh_command

Constructor Details

#initialize(name, platform) ⇒ Vanagon::Project

Project constructor. Takes just the name. Also sets the @name and @platform, and initializes @components, @directories and @settings.

Parameters:



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vanagon/project.rb', line 43

def initialize(name, platform)
  @name = name
  @components = []
  @requires = []
  @directories = []
  @settings = {}
  @platform = platform
  @release = "1"
  @replaces = []
  @provides = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Magic getter to retrieve settings in the project



56
57
58
59
60
# File 'lib/vanagon/project.rb', line 56

def method_missing(method, *args)
  if @settings.has_key?(method)
    return @settings[method]
  end
end

Instance Attribute Details

#bill_of_materialsObject

Returns the value of attribute bill_of_materials.



14
15
16
# File 'lib/vanagon/project.rb', line 14

def bill_of_materials
  @bill_of_materials
end

#cleanupObject

Returns the value of attribute cleanup.



13
14
15
# File 'lib/vanagon/project.rb', line 13

def cleanup
  @cleanup
end

#componentsObject

Returns the value of attribute components.



10
11
12
# File 'lib/vanagon/project.rb', line 10

def components
  @components
end

#configdirObject

Returns the value of attribute configdir.



10
11
12
# File 'lib/vanagon/project.rb', line 10

def configdir
  @configdir
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/vanagon/project.rb', line 11

def description
  @description
end

#directoriesObject

Returns the value of attribute directories.



11
12
13
# File 'lib/vanagon/project.rb', line 11

def directories
  @directories
end

#homepageObject

Returns the value of attribute homepage.



12
13
14
# File 'lib/vanagon/project.rb', line 12

def homepage
  @homepage
end

#identifierObject

Returns the value of attribute identifier.



12
13
14
# File 'lib/vanagon/project.rb', line 12

def identifier
  @identifier
end

#licenseObject

Returns the value of attribute license.



11
12
13
# File 'lib/vanagon/project.rb', line 11

def license
  @license
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/vanagon/project.rb', line 10

def name
  @name
end

#noarchObject

Returns the value of attribute noarch.



12
13
14
# File 'lib/vanagon/project.rb', line 12

def noarch
  @noarch
end

#platformObject

Returns the value of attribute platform.



10
11
12
# File 'lib/vanagon/project.rb', line 10

def platform
  @platform
end

#providesObject

Returns the value of attribute provides.



13
14
15
# File 'lib/vanagon/project.rb', line 13

def provides
  @provides
end

#releaseObject

Returns the value of attribute release.



13
14
15
# File 'lib/vanagon/project.rb', line 13

def release
  @release
end

#replacesObject

Returns the value of attribute replaces.



13
14
15
# File 'lib/vanagon/project.rb', line 13

def replaces
  @replaces
end

#repoObject

Returns the value of attribute repo.



12
13
14
# File 'lib/vanagon/project.rb', line 12

def repo
  @repo
end

#requiresObject

Returns the value of attribute requires.



12
13
14
# File 'lib/vanagon/project.rb', line 12

def requires
  @requires
end

#retry_countObject

Returns the value of attribute retry_count.



14
15
16
# File 'lib/vanagon/project.rb', line 14

def retry_count
  @retry_count
end

#settingsObject

Returns the value of attribute settings.



10
11
12
# File 'lib/vanagon/project.rb', line 10

def settings
  @settings
end

#timeoutObject

Returns the value of attribute timeout.



14
15
16
# File 'lib/vanagon/project.rb', line 14

def timeout
  @timeout
end

#userObject

Returns the value of attribute user.



12
13
14
# File 'lib/vanagon/project.rb', line 12

def user
  @user
end

#vendorObject

Returns the value of attribute vendor.



11
12
13
# File 'lib/vanagon/project.rb', line 11

def vendor
  @vendor
end

#versionObject

Returns the value of attribute version.



11
12
13
# File 'lib/vanagon/project.rb', line 11

def version
  @version
end

#version_fileObject

Returns the value of attribute version_file.



13
14
15
# File 'lib/vanagon/project.rb', line 13

def version_file
  @version_file
end

Class Method Details

.load_project(name, configdir, platform, include_components = []) ⇒ Vanagon::Project

Loads a given project from the configdir

Parameters:

  • name (String)

    the name of the project

  • configdir (String)

    the path to the project config file

  • platform (Vanagon::Platform)

    platform to build against

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

    optional list restricting the loaded components

Returns:

Raises:

  • if the instance_eval on Project fails, the exception is reraised



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vanagon/project.rb', line 24

def self.load_project(name, configdir, platform, include_components = [])
  projfile = File.join(configdir, "#{name}.rb")
  code = File.read(projfile)
  dsl = Vanagon::Project::DSL.new(name, platform, include_components)
  dsl.instance_eval(code, __FILE__, __LINE__)
  dsl._project
rescue => e
  puts "Error loading project '#{name}' using '#{projfile}':"
  puts e
  puts e.backtrace.join("\n")
  raise e
end

Instance Method Details

#fetch_sources(workdir) ⇒ Object

Collects all sources and patches into the provided workdir

Parameters:

  • workdir (String)

    directory to stage sources into



65
66
67
68
69
70
71
72
# File 'lib/vanagon/project.rb', line 65

def fetch_sources(workdir)
  @components.each do |component|
    component.get_source(workdir)
    # Fetch secondary sources
    component.get_sources(workdir)
    component.get_patches(workdir)
  end
end

#generate_bill_of_materialsArray

Generate a bill-of-materials: a listing of the components and their versions in the current project

Returns:

  • (Array)

    a listing of component names and versions



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

def generate_bill_of_materials
  @components.map { |comp| "#{comp.name} #{comp.version}" }.sort
end

#generate_packageString, Array

Ascertain how to build a package for the current platform

Returns:

  • (String, Array)

    commands to build a package for the current project as defined by the platform



312
313
314
# File 'lib/vanagon/project.rb', line 312

def generate_package
  @platform.generate_package(self)
end

#generate_packaging_artifacts(workdir) ⇒ Object

Generate any required files to build a package for this project on the current platform into the provided workdir

Parameters:

  • workdir (String)

    workdir to put the packaging files into



320
321
322
# File 'lib/vanagon/project.rb', line 320

def generate_packaging_artifacts(workdir)
  @platform.generate_packaging_artifacts(workdir, @name, binding)
end

#get_configfilesArray

Collects any configfiles supplied by components

Returns:

  • (Array)

    array of configfiles installed by components of the project



198
199
200
# File 'lib/vanagon/project.rb', line 198

def get_configfiles
  @components.map(&:configfiles).flatten.uniq
end

#get_directoriesArray

Collects any directories declared by the project and components

Returns:

  • (Array)

    the directories in the project and components



205
206
207
208
209
210
# File 'lib/vanagon/project.rb', line 205

def get_directories
  dirs = []
  dirs.push @directories
  dirs.push @components.map(&:directories).flatten
  dirs.flatten.uniq
end

#get_filesArray

Collects any additional files supplied by components

Returns:

  • (Array)

    array of files installed by components of the project



77
78
79
80
81
82
# File 'lib/vanagon/project.rb', line 77

def get_files
  files = []
  files.push @version_file if @version_file
  files.push @components.map(&:files).flatten
  files.flatten.uniq
end

#get_postinstall_actions(pkg_state) ⇒ String

Collects the postinstall packaging actions for the project and it’s components for the specified packaging state

Parameters:

  • pkg_state (String)

    the package state we want to run the given scripts for. Can be one or more of ‘install’ or ‘upgrade’

Returns:

  • (String)

    string of Bourne shell compatible scriptlets to execute during the postinstall phase of packaging during the state of the system defined by pkg_state (either install or upgrade)



154
155
156
157
158
159
160
161
# File 'lib/vanagon/project.rb', line 154

def get_postinstall_actions(pkg_state)
  scripts = @components.map(&:postinstall_actions).flatten.compact.select { |s| s.pkg_state.include? pkg_state }.map(&:scripts)
  if scripts.empty?
    return ':'
  else
    return scripts.join("\n")
  end
end

#get_postremove_actions(pkg_state) ⇒ String

Collects the postremove packaging actions for the project and it’s components for the specified packaging state

Parameters:

  • pkg_state (String)

    the package state we want to run the given scripts for. Can be one or more of ‘removal’ or ‘upgrade’

Returns:

  • (String)

    string of Bourne shell compatible scriptlets to execute during the postremove phase of packaging during the state of the system defined by pkg_state (either removal or upgrade)



186
187
188
189
190
191
192
193
# File 'lib/vanagon/project.rb', line 186

def get_postremove_actions(pkg_state)
  scripts = @components.map(&:postremove_actions).flatten.compact.select { |s| s.pkg_state.include? pkg_state }.map(&:scripts)
  if scripts.empty?
    return ':'
  else
    return scripts.join("\n")
  end
end

#get_preinstall_actions(pkg_state) ⇒ String

Collects the preinstall packaging actions for the project and it’s components for the specified packaging state

Parameters:

  • pkg_state (String)

    the package state we want to run the given scripts for. Can be one or more of ‘install’ or ‘upgrade’

Returns:

  • (String)

    string of Bourne shell compatible scriptlets to execute during the preinstall phase of packaging during the state of the system defined by pkg_state (either install or upgrade)



137
138
139
140
141
142
143
144
# File 'lib/vanagon/project.rb', line 137

def get_preinstall_actions(pkg_state)
  scripts = @components.map(&:preinstall_actions).flatten.compact.select { |s| s.pkg_state.include? pkg_state }.map(&:scripts)
  if scripts.empty?
    return ':'
  else
    return scripts.join("\n")
  end
end

#get_preremove_actions(pkg_state) ⇒ String

Collects the preremove packaging actions for the project and it’s components for the specified packaging state

Parameters:

  • pkg_state (String)

    the package state we want to run the given scripts for. Can be one or more of ‘removal’ or ‘upgrade’

Returns:

  • (String)

    string of Bourne shell compatible scriptlets to execute during the preremove phase of packaging during the state of the system defined by pkg_state (either removal or upgrade)



170
171
172
173
174
175
176
177
# File 'lib/vanagon/project.rb', line 170

def get_preremove_actions(pkg_state)
  scripts = @components.map(&:preremove_actions).flatten.compact.select { |s| s.pkg_state.include? pkg_state }.map(&:scripts)
  if scripts.empty?
    return ':'
  else
    return scripts.join("\n")
  end
end

#get_providesArray

Collects all of the provides for the project and its components

Returns:

  • (Array)

    array of package level provides for the project



123
124
125
126
127
128
# File 'lib/vanagon/project.rb', line 123

def get_provides
  provides = []
  provides.push @provides.flatten
  provides.push @components.map(&:provides).flatten
  provides.flatten.uniq
end

#get_replacesArray

Collects all of the replacements for the project and its components

Returns:

  • (Array)

    array of package level replacements for the project



97
98
99
100
101
102
# File 'lib/vanagon/project.rb', line 97

def get_replaces
  replaces = []
  replaces.push @replaces.flatten
  replaces.push @components.map(&:replaces).flatten
  replaces.flatten.uniq
end

#get_requiresArray

Collects all of the requires for both the project and its components

Returns:

  • (Array)

    array of runtime requirements for the project



87
88
89
90
91
92
# File 'lib/vanagon/project.rb', line 87

def get_requires
  req = []
  req << @components.map(&:requires).flatten
  req << @requires
  req.flatten.uniq
end

#get_root_directoriesArray

Gets the highest level directories declared by the project

Returns:

  • (Array)

    the highest level directories that have been declared by the project



215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/vanagon/project.rb', line 215

def get_root_directories
  dirs = get_directories.map { |dir| dir.path.split('/') }
  dirs.sort! { |dir1, dir2| dir1.length <=> dir2.length }
  ret_dirs = []

  dirs.each do |dir|
    unless ret_dirs.include?(dir.first(dir.length - 1).join('/'))
      ret_dirs << dir.join('/')
    end
  end
  ret_dirs
end

#get_service(name) ⇒ @component.service obj

Grabs a specific service based on which name is passed in note that if the name is wrong or there was no will return nil

Parameters:

  • name (string)

    of service to grab

Returns:

  • (@component.service obj)

    specific service



111
112
113
114
115
116
117
118
# File 'lib/vanagon/project.rb', line 111

def get_service(name)
  @components.each do |component|
    if component.name == name
      return component.service
    end
  end
  return nil
end

#get_servicesArray

Get any services registered by components in the project

Returns:

  • (Array)

    the services provided by components in the project



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

def get_services
  @components.map(&:service).flatten.compact
end

#get_tarball_filesArray

Generate a list of all files and directories to be included in a tarball for the project

Returns:

  • (Array)

    all the files and directories that should be included in the tarball



247
248
249
250
251
252
253
254
255
256
# File 'lib/vanagon/project.rb', line 247

def get_tarball_files
  files = ['file-list', 'bill-of-materials']
  files.push get_files.map(&:path)
  files.push get_configfiles.map(&:path)
  if @platform.is_windows?
    files.flatten.map { |f| "$$(cygpath --mixed --long-name '#{f}')" }
  else
    files.flatten
  end
end

#has_services?True, False

Simple utility for determining if the components in the project declare any services

Returns:

  • (True, False)

    Whether or not there are services declared for this project or not



239
240
241
# File 'lib/vanagon/project.rb', line 239

def has_services?
  !get_services.empty?
end

#list_component_dependencies(component) ⇒ Array

Return a list of the build_dependencies that are satisfied by an internal component

Parameters:

  • component (Vanagon::Component)

    component to check for already satisfied build dependencies

Returns:

  • (Array)

    a list of the build dependencies for the given component that are satisfied by other components in the project



298
299
300
# File 'lib/vanagon/project.rb', line 298

def list_component_dependencies(component)
  component.build_requires.select { |dep| @components.map(&:name).include?(dep) }
end

#make_bill_of_materials(workdir) ⇒ String

Generates a bill-of-materials and writes the contents to the workdir for use in building the project

Parameters:

  • workdir (String)

    full path to the workdir to send the bill-of-materials

Returns:

  • (String)

    full path to the generated bill-of-materials



290
291
292
# File 'lib/vanagon/project.rb', line 290

def make_bill_of_materials(workdir)
  File.open(File.join(workdir, 'bill-of-materials'), 'w') { |f| f.puts(generate_bill_of_materials.join("\n")) }
end

#make_makefile(workdir) ⇒ String

Evaluates the makefile template and writes the contents to the workdir for use in building the project

Parameters:

  • workdir (String)

    full path to the workdir to send the evaluated template

Returns:

  • (String)

    full path to the generated Makefile



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

def make_makefile(workdir)
  erb_file(File.join(VANAGON_ROOT, "resources/Makefile.erb"), File.join(workdir, "Makefile"))
end

#pack_tarball_commandString

Method to generate the command to create a tarball of the project

Returns:

  • (String)

    cross platform command to generate a tarball of the project



269
270
271
272
273
274
# File 'lib/vanagon/project.rb', line 269

def pack_tarball_command
  tar_root = "#{@name}-#{@version}"
  ["mkdir -p '#{tar_root}'",
   %('#{@platform.tar}' -cf - -T "#{get_tarball_files.join('" "')}" | ( cd '#{tar_root}/'; '#{@platform.tar}' xfp -)),
   %('#{@platform.tar}' -cf - #{tar_root}/ | gzip -9c > #{tar_root}.tar.gz)].join("\n\t")
end

#package_nameString

Get the package name for the project on the current platform

Returns:

  • (String)

    package name for the current project as defined by the platform



305
306
307
# File 'lib/vanagon/project.rb', line 305

def package_name
  @platform.package_name(self)
end