Class: Vanagon::Component

Inherits:
Object
  • Object
show all
Includes:
HashableAttributes
Defined in:
lib/vanagon/component.rb,
lib/vanagon/component/dsl.rb,
lib/vanagon/component/rules.rb,
lib/vanagon/component/source.rb,
lib/vanagon/extensions/hashable.rb,
lib/vanagon/component/source/git.rb,
lib/vanagon/component/source/http.rb,
lib/vanagon/component/source/local.rb

Defined Under Namespace

Classes: DSL, Rules, Source

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashableAttributes

#to_hash, #to_json

Constructor Details

#initialize(name, settings, platform) ⇒ Vanagon::Component

Component constructor.

Parameters:

  • name (String)

    the name of the component

  • settings (Hash)

    the settings to be used in the component

  • platform (Vanagon::Platform)

    the platform to build the component for



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vanagon/component.rb', line 44

def initialize(name, settings, platform) # rubocop:disable Metrics/AbcSize
  @name = name
  @settings = settings
  @platform = platform
  @options = {}
  @build_requires = []
  @requires = []
  @configure = []
  @install = []
  @build = []
  @check = []
  @patches = []
  @files = Set.new
  @directories = []
  @replaces = []
  @provides = []
  @conflicts = []
  @environment = {}
  @sources = []
  @preinstall_actions = []
  @postinstall_actions = []
  @preremove_actions = []
  @postremove_actions = []
end

Instance Attribute Details

#buildObject

Returns the value of attribute build.



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

def build
  @build
end

#build_dirObject

Returns the value of attribute build_dir.



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

def build_dir
  @build_dir
end

#build_requiresObject

Returns the value of attribute build_requires.



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

def build_requires
  @build_requires
end

#checkObject

Returns the value of attribute check.



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

def check
  @check
end

#cleanup_sourceObject

Returns the value of attribute cleanup_source.



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

def cleanup_source
  @cleanup_source
end

#configureObject

Returns the value of attribute configure.



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

def configure
  @configure
end

#conflictsObject

Returns the value of attribute conflicts.



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

def conflicts
  @conflicts
end

#directoriesObject

Returns the value of attribute directories.



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

def directories
  @directories
end

#dirnameObject

Returns the value of attribute dirname.



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

def dirname
  @dirname
end

#environmentObject

Returns the value of attribute environment.



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

def environment
  @environment
end

#extract_withObject

Returns the value of attribute extract_with.



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

def extract_with
  @extract_with
end

#filesSet (readonly)

Retrieve all items from @files not marked as configuration files

Returns:

  • (Set)

    all files not marked as configuration files



10
# File 'lib/vanagon/component.rb', line 10

attr_accessor :name, :version, :source, :url, :configure, :build, :check, :install

#installObject

Returns the value of attribute install.



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

def install
  @install
end

#licenseObject

Returns the value of attribute license.



15
16
17
# File 'lib/vanagon/component.rb', line 15

def license
  @license
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#patchesObject

Returns the value of attribute patches.



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

def patches
  @patches
end

#platformObject

Returns the value of attribute platform.



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

def platform
  @platform
end

#postinstall_actionsObject

Returns the value of attribute postinstall_actions.



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

def postinstall_actions
  @postinstall_actions
end

#postremove_actionsObject

Returns the value of attribute postremove_actions.



15
16
17
# File 'lib/vanagon/component.rb', line 15

def postremove_actions
  @postremove_actions
end

#preinstall_actionsObject

Returns the value of attribute preinstall_actions.



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

def preinstall_actions
  @preinstall_actions
end

#preremove_actionsObject

Returns the value of attribute preremove_actions.



15
16
17
# File 'lib/vanagon/component.rb', line 15

def preremove_actions
  @preremove_actions
end

#providesObject

Returns the value of attribute provides.



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

def provides
  @provides
end

#replacesObject

Returns the value of attribute replaces.



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

def replaces
  @replaces
end

#requiresObject

Returns the value of attribute requires.



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

def requires
  @requires
end

#serviceObject

Returns the value of attribute service.



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

def service
  @service
end

#settingsObject

Returns the value of attribute settings.



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

def settings
  @settings
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

#sourcesObject

Returns the value of attribute sources.



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

def sources
  @sources
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#versionObject

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.load_component(name, configdir, settings, platform) ⇒ Vanagon::Component

Loads a given component from the configdir

Parameters:

  • name (String)

    the name of the component

  • configdir (String)

    the path to the component config file

  • settings (Hash)

    the settings to be used in the component

  • platform (Vanagon::Platform)

    the platform to build the component for

Returns:

Raises:

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



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

def self.load_component(name, configdir, settings, platform)
  compfile = File.join(configdir, "#{name}.rb")
  code = File.read(compfile)
  dsl = Vanagon::Component::DSL.new(name, settings, platform)
  dsl.instance_eval(code, __FILE__, __LINE__)
  dsl._component
rescue => e
  puts "Error loading project '#{name}' using '#{compfile}':"
  puts e
  puts e.backtrace.join("\n")
  raise e
end

Instance Method Details

#add_file(file) ⇒ Set?

Adds the given file to the list of files and returns @files.

Parameters:

Returns:

  • (Set, nil)

    Returns @files if file is successfully added to @files or nil if file already exists



74
75
76
# File 'lib/vanagon/component.rb', line 74

def add_file(file)
  @files.add file
end

#configfilesSet

Retrieve all items from @files explicitly marked as configuration files

Returns:

  • (Set)

    all files explicitly marked as configuration files



99
100
101
# File 'lib/vanagon/component.rb', line 99

def configfiles
  @files.select(&:configfile?)
end

#delete_file(file) ⇒ Set?

Deletes the given file from the list of files and returns @files.

Parameters:

  • file (String)

    path of file to delete from a component’s list of files

Returns:

  • (Set, nil)

    Returns @files if file is successfully deleted from @files or nil if file doesn’t exist; this matches strictly on the path of a given file, and ignores other attributes like :mode, :owner, or :group.



85
86
87
# File 'lib/vanagon/component.rb', line 85

def delete_file(file)
  @files.delete_if { |this_file| this_file.path == file }
end

#get_build_dirObject

Expands the build directory



131
132
133
134
135
136
137
# File 'lib/vanagon/component.rb', line 131

def get_build_dir
  if @build_dir
    File.join(@dirname, @build_dir)
  else
    @dirname
  end
end

#get_environmentString

Prints the environment in a way suitable for use in a Makefile or shell script.

Returns:

  • (String)

    environment suitable for inclusion in a Makefile



165
166
167
168
169
170
171
172
# File 'lib/vanagon/component.rb', line 165

def get_environment
  if @environment.empty?
    ":"
  else
    env = @environment.map { |key, value| %(#{key}="#{value}") }
    "export #{env.join(' ')}"
  end
end

#get_patches(workdir) ⇒ Object

Fetches patches if any are provided for the project.

Parameters:

  • workdir (String)

    working directory to put the patches into



153
154
155
156
157
158
159
# File 'lib/vanagon/component.rb', line 153

def get_patches(workdir)
  unless @patches.empty?
    patchdir = File.join(workdir, "patches")
    FileUtils.mkdir_p(patchdir)
    FileUtils.cp(@patches.map(&:path), patchdir)
  end
end

#get_source(workdir) ⇒ Object

Fetches the primary source for the component. As a side effect, also sets @extract_with, @dirname and @version for the component for use in the makefile template

Parameters:

  • workdir (String)

    working directory to put the source into



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vanagon/component.rb', line 108

def get_source(workdir)
  if @url
    @source = Vanagon::Component::Source.source(@url, @options, workdir)
    @source.fetch
    @source.verify
    @extract_with = @source.respond_to?(:extract) ? @source.extract(@platform.tar) : ':'
    @cleanup_source = @source.cleanup if @source.respond_to?(:cleanup)
    @dirname = @source.dirname

    # Git based sources probably won't set the version, so we load it if it hasn't been already set
    @version ||= @source.version
  else
    warn "No source given for component '#{@name}'"

    # If there is no source, we don't want to try to change directories, so we just change to the current directory.
    @dirname = './'

    # If there is no source, there is nothing to do to extract
    @extract_with = ':'
  end
end

#get_sources(workdir) ⇒ Object

Fetches secondary sources for the component. These are just dumped into the workdir currently.

Parameters:

  • workdir (String)

    working directory to put the source into



142
143
144
145
146
147
148
# File 'lib/vanagon/component.rb', line 142

def get_sources(workdir)
  @sources.each do |source|
    cur_source = Vanagon::Component::Source.source(source.url, { :ref => source.ref, :sum => source.sum }, workdir)
    cur_source.fetch
    cur_source.verify
  end
end

#rules(project, platform) ⇒ Object



174
175
176
# File 'lib/vanagon/component.rb', line 174

def rules(project, platform)
  Vanagon::Component::Rules.new(self, project, platform)
end