Class: Vanagon::Component::Rules
- Inherits:
-
Object
- Object
- Vanagon::Component::Rules
- 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
-
#component ⇒ Object
Returns the value of attribute component.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#project ⇒ Object
Returns the value of attribute project.
Class Method Summary collapse
-
.rule(target) {|rule| ... } ⇒ void
Create methods that generate Makefile rules.
Instance Method Summary collapse
-
#build ⇒ Makefile::Rule
Build this component.
-
#check ⇒ Makefile::Rule
Run tests for this component.
-
#clean ⇒ Makefile::Rule
Clean up any files generated while building this project.
-
#cleanup ⇒ Makefile::Rule
Run any post-installation cleanup steps for this component.
-
#clobber ⇒ Makefile::Rule
Remove all files associated with this component.
-
#component_rule ⇒ Makefile::Rule
Generate a top level rule to build this component.
-
#configure ⇒ Makefile::Rule
Create a build directory for this component if an out of source tree build is specified, and any configure steps, if any.
-
#format ⇒ String
(also: #to_s)
Generate a Makefile fragment that contains all of the rules for the component.
-
#initialize(component, project, platform) ⇒ Rules
constructor
A new instance of Rules.
-
#install ⇒ Makefile::Rule
Install this component.
-
#patch ⇒ Makefile::Rule
Apply any patches for this component.
-
#rules ⇒ Array<Makefile::Rule>
Generate all Makefile rules for this component.
-
#unpack ⇒ Makefile::Rule
Unpack the source for this component.
Methods included from Utilities::ShellUtilities
andand, andand_multiline, cmdjoin
Constructor Details
#initialize(component, project, platform) ⇒ Rules
Returns a new instance of Rules.
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
#component ⇒ Object
Returns the value of attribute component.
31 32 33 |
# File 'lib/vanagon/component/rules.rb', line 31 def component @component end |
#platform ⇒ Object
Returns the value of attribute platform.
33 34 35 |
# File 'lib/vanagon/component/rules.rb', line 33 def platform @platform end |
#project ⇒ Object
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.
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
#build ⇒ Makefile::Rule
Build this component.
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 |
#check ⇒ Makefile::Rule
Run tests for this component.
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 |
#clean ⇒ Makefile::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.
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 |
#cleanup ⇒ Makefile::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.
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 |
#clobber ⇒ Makefile::Rule
Remove all files associated with this component.
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_rule ⇒ Makefile::Rule
Generate a top level rule to build this component.
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 |
#configure ⇒ Makefile::Rule
Create a build directory for this component if an out of source tree build is specified, and any configure steps, if any.
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 |
#format ⇒ String Also known as: to_s
Generate a Makefile fragment that contains all of the rules for the component.
211 212 213 |
# File 'lib/vanagon/component/rules.rb', line 211 def format rules.map(&:to_s).join("\n") end |
#install ⇒ Makefile::Rule
Install this component.
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 |
#patch ⇒ Makefile::Rule
Apply any patches for this component.
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 |
#rules ⇒ Array<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.
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 |
#unpack ⇒ Makefile::Rule
Unpack the source for this component. The unpacking behavior depends on the source type of the component.
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 |