Class: Vanagon::Component::Rules

Inherits:
Object
  • Object
show all
Includes:
Utilities::ShellUtilities
Defined in:
lib/vanagon/component/rules.rb

Overview

Vanagon::Component::Rules creates all Makefile rules for a given component.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities::ShellUtilities

andand, andand_multiline, cmdjoin

Constructor Details

#initialize(component, project, platform) ⇒ Rules

Returns a new instance of Rules.

Parameters:



38
39
40
41
42
# File 'lib/vanagon/component/rules.rb', line 38

def initialize(component, project, platform)
  @component = component
  @project = project
  @platform = platform
end

Instance Attribute Details

#componentObject

Returns the value of attribute component.



31
32
33
# File 'lib/vanagon/component/rules.rb', line 31

def component
  @component
end

#platformObject

Returns the value of attribute platform.



33
34
35
# File 'lib/vanagon/component/rules.rb', line 33

def platform
  @platform
end

#projectObject

Returns the value of attribute project.



32
33
34
# File 'lib/vanagon/component/rules.rb', line 32

def project
  @project
end

Class Method Details

.rule(target) {|rule| ... } ⇒ void

This method returns an undefined value.

Create methods that generate Makefile rules.

This method cuts out some of the boilerplate of creating Makefile rules by creating methods and Makefile objects with a common name.

Parameters:

  • target (Symbol)

    The rule target name.

  • dependencies (Array<String>)

    An optional list of dependencies for the rule

Yield Parameters:



23
24
25
26
27
28
29
# File 'lib/vanagon/component/rules.rb', line 23

def self.rule(target, &block)
  define_method("#{target}_rule") do
    Makefile::Rule.new("#{component.name}-#{target}") do |rule|
      instance_exec(rule, &block)
    end
  end
end

Instance Method Details

#buildMakefile::Rule

Build this component.

Returns:



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/vanagon/component/rules.rb', line 122

rule("build") do |r|
  r.dependencies = ["#{component.name}-configure"]
  unless component.build.empty?
    r.recipe << andand_multiline(
      component.environment_variables,
      "cd #{component.get_build_dir}",
      component.build
    )
  end

  r.recipe << "touch #{r.target}"
end

#checkMakefile::Rule

Run tests for this component.

Returns:



136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/vanagon/component/rules.rb', line 136

rule("check") do |r|
  r.dependencies = ["#{component.name}-build"]
  unless component.check.empty? || project.settings[:skipcheck]
    r.recipe << andand_multiline(
      component.environment_variables,
      "cd #{component.get_build_dir}",
      component.check
    )
  end

  r.recipe << "touch #{r.target}"
end

#cleanMakefile::Rule

Clean up any files generated while building this project.

This cleans up the project by invoking ‘make clean` and removing the touch files for the configure/build/install steps.

Returns:



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/vanagon/component/rules.rb', line 184

rule("clean") do |r|
  r.recipe << andand(
    "[ -d #{component.get_build_dir} ]",
    "cd #{component.get_build_dir}",
    "#{platform[:make]} clean"
  )

  %w[configure build install].each do |type|
    touchfile = "#{component.name}-#{type}"
    r.recipe << andand(
      "[ -e #{touchfile} ]",
      "rm #{touchfile}"
    )
  end
end

#cleanupMakefile::Rule

Run any post-installation cleanup steps for this component.

This component is only included by #rules if the associated project has the ‘cleanup` attribute set.

Returns:



175
176
177
178
# File 'lib/vanagon/component/rules.rb', line 175

rule("cleanup") do |r|
  r.dependencies = ["#{component.name}-install"]
  r.recipe = [component.cleanup_source, "touch #{r.target}"]
end

#clobberMakefile::Rule

Remove all files associated with this component.

Returns:



201
202
203
204
205
206
207
# File 'lib/vanagon/component/rules.rb', line 201

rule("clobber") do |r|
  r.dependencies = ["#{component.name}-clean"]
  r.recipe = [
    andand("[ -d #{component.dirname} ]", "rm -r #{component.dirname}"),
    andand("[ -e #{component.name}-unpack ]", "rm #{component.name}-unpack")
  ]
end

#component_ruleMakefile::Rule

Generate a top level rule to build this component.

Returns:



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

def component_rule
  Makefile::Rule.new(component.name) do |rule|
    rule.dependencies = ["#{component.name}-install"]
  end
end

#configureMakefile::Rule

Create a build directory for this component if an out of source tree build is specified, and any configure steps, if any.

Returns:



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/vanagon/component/rules.rb', line 104

rule("configure") do |r|
  r.dependencies = ["#{component.name}-patch"].concat(project.list_component_dependencies(component))
  if component.get_build_dir
    r.recipe << "[ -d #{component.get_build_dir} ] || mkdir -p #{component.get_build_dir}"
  end

  unless component.configure.empty?
    r.recipe << andand_multiline(
      component.environment_variables,
      "cd #{component.get_build_dir}",
      component.configure
    )
  end

  r.recipe << "touch #{r.target}"
end

#formatString Also known as: to_s

Generate a Makefile fragment that contains all of the rules for the component.

Returns:



211
212
213
# File 'lib/vanagon/component/rules.rb', line 211

def format
  rules.map(&:to_s).join("\n")
end

#installMakefile::Rule

Install this component.

Returns:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/vanagon/component/rules.rb', line 150

rule("install") do |r|
  r.dependencies = ["#{component.name}-check"]
  unless component.install.empty?
    r.recipe << andand_multiline(
      component.environment_variables,
      "cd #{component.get_build_dir}",
      component.install
    )
  end

  after_install_patches = component.patches.select { |patch| patch.after == "install" }
  after_install_patches.each do |patch|
    r.recipe << andand(
      "cd #{patch.destination}",
      patch.cmd(platform),
    )
  end

  r.recipe << "touch #{r.target}"
end

#patchMakefile::Rule

Apply any patches for this component.

Returns:



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/vanagon/component/rules.rb', line 89

rule("patch") do |r|
  r.dependencies = ["#{component.name}-unpack"]
  after_unpack_patches = component.patches.select { |patch| patch.after == "unpack" }
  unless after_unpack_patches.empty?
    r.recipe << andand_multiline(
      "cd #{component.dirname}",
      after_unpack_patches.map { |patch| patch.cmd(platform) }
    )
  end

  r.recipe << "touch #{r.target}"
end

#rulesArray<Makefile::Rule>

Generate all Makefile rules for this component.

If the project has the cleanup attribute set, a cleanup rule will be included in the returned rules.

Returns:



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

def rules
  list = [
    component_rule,
    unpack_rule,
    patch_rule,
    configure_rule,
    build_rule,
    check_rule,
    install_rule,
    clean_rule,
    clobber_rule,
  ]
  if project.cleanup
    list << cleanup_rule
  end

  list
end

#unpackMakefile::Rule

Unpack the source for this component. The unpacking behavior depends on the source type of the component.

Returns:

See Also:

  • Vanagon::Component::Rules.[Vanagon[Vanagon::Component[Vanagon::Component::Source]


82
83
84
85
86
# File 'lib/vanagon/component/rules.rb', line 82

rule("unpack") do |r|
  r.dependencies = ['file-list-before-build']
  r.recipe << andand_multiline(component.environment_variables, component.extract_with)
  r.recipe << "touch #{r.target}"
end