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.
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/vanagon/component/rules.rb', line 131 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.
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/vanagon/component/rules.rb', line 145 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.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/vanagon/component/rules.rb', line 200 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.
191 192 193 194 |
# File 'lib/vanagon/component/rules.rb', line 191 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.
217 218 219 220 221 222 223 |
# File 'lib/vanagon/component/rules.rb', line 217 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.
81 82 83 84 85 |
# File 'lib/vanagon/component/rules.rb', line 81 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.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vanagon/component/rules.rb', line 113 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.
227 228 229 |
# File 'lib/vanagon/component/rules.rb', line 227 def format rules.map(&:to_s).join("\n") end |
#install ⇒ Makefile::Rule
Install this component.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/vanagon/component/rules.rb', line 159 rule("install") do |r| r.dependencies = ["#{component.name}-check"] unless component.install_only unless component.install.empty? if component.install_only r.recipe << andand_multiline( component.environment_variables, component.install ) else r.recipe << andand_multiline( component.environment_variables, "cd #{component.get_build_dir}", component.install ) end 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.
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/vanagon/component/rules.rb', line 98 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 68 69 70 71 72 73 74 75 76 |
# File 'lib/vanagon/component/rules.rb', line 50 def rules # rubocop:disable Metrics/AbcSize list_of_rules = [ component_rule, unpack_rule, patch_rule, configure_rule, build_rule, check_rule, install_rule, clean_rule, clobber_rule, ] if component.install_only list_of_rules = [ component_rule, install_rule, clean_rule, clobber_rule, ] end if project.cleanup list_of_rules << cleanup_rule end list_of_rules end |
#unpack ⇒ Makefile::Rule
Unpack the source for this component. The unpacking behavior depends on the source type of the component.
91 92 93 94 95 |
# File 'lib/vanagon/component/rules.rb', line 91 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 |