Class: DevBall::PkgSpec::Base
- Inherits:
-
Object
- Object
- DevBall::PkgSpec::Base
- Defined in:
- lib/devball/pkgspec/base.rb
Class Attribute Summary collapse
-
.ball ⇒ Object
readonly
Returns the value of attribute ball.
-
.packages_inorder ⇒ Object
readonly
Returns the value of attribute packages_inorder.
-
.patches ⇒ Object
readonly
Returns the value of attribute patches.
Class Method Summary collapse
- .depends_on(*deps) ⇒ Object
- .find(name) ⇒ Object
- .load_packages(dir, explicit, only_explicit = false) ⇒ Object
- .register_package(klass, name, required) ⇒ Object
- .set_ball(name, required = true) ⇒ Object
-
.set_lib_ball(name) ⇒ Object
defines it as a library that is only required if somethind depended on it.
- .set_patch(*patches) ⇒ Object
Instance Method Summary collapse
- #ball ⇒ Object
- #ball_file_name ⇒ Object
-
#ball_name ⇒ Object
get the name of the ball without version.
-
#ball_version ⇒ Object
get the name of the ball without extention.
- #build_concurrent? ⇒ Boolean
-
#build_dir_name ⇒ Object
get the name of the subdirectory the ball was extracted to provides a default implementation that uses ball() and takes off known extensions on the assumption that its name will be derived from the ball name that way.
-
#build_targets ⇒ Object
targets for the build call to make to use.
-
#configure_params ⇒ Object
configure options to pass to ./configure.
- #configure_script_name ⇒ Object
- #depends_on ⇒ Object
-
#install_links(base_from, base_into, subdir) ⇒ Object
internal implementation of setting the links up for a given directory.
- #install_service_links(base_from) ⇒ Object
- #install_targets ⇒ Object
-
#link_mappings ⇒ Object
Returns any explicit filename translations that should be performed on a file when linking it into the right place in the tree.
-
#package_install_dir ⇒ Object
Returns the directory the package will be installed in.
-
#package_name ⇒ Object
get the name of the package without any version information.
- #recursive_depends_on ⇒ Object
- #remove_build ⇒ Object
- #remove_install ⇒ Object
-
#step_build ⇒ Object
do the build step.
-
#step_configure ⇒ Object
do the configure step.
- #step_environment_setup ⇒ Object
-
#step_extract ⇒ Object
extracts the ball to the correct place in the builddir.
-
#step_install ⇒ Object
do the install step.
- #step_patch ⇒ Object
-
#step_setup_links ⇒ Object
Build the appropriate links for the package so it can be run properly from /nexopia.
- #to_s ⇒ Object
Class Attribute Details
.ball ⇒ Object (readonly)
Returns the value of attribute ball.
111 112 113 |
# File 'lib/devball/pkgspec/base.rb', line 111 def ball @ball end |
.packages_inorder ⇒ Object (readonly)
Returns the value of attribute packages_inorder.
83 84 85 |
# File 'lib/devball/pkgspec/base.rb', line 83 def packages_inorder @packages_inorder end |
.patches ⇒ Object (readonly)
Returns the value of attribute patches.
122 123 124 |
# File 'lib/devball/pkgspec/base.rb', line 122 def patches @patches end |
Class Method Details
.depends_on(*deps) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/devball/pkgspec/base.rb', line 91 def depends_on(*deps) @deps ||= [] @deps.push(*deps) if (deps.length > 0) deps = [] if (superclass && superclass.respond_to?(:depends_on)) deps.push(*superclass.depends_on) end deps.push(*@deps) deps end |
.find(name) ⇒ Object
85 86 87 88 89 |
# File 'lib/devball/pkgspec/base.rb', line 85 def find(name) @packages ||= {} return @packages[name] end |
.load_packages(dir, explicit, only_explicit = false) ⇒ Object
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 77 78 79 80 81 82 |
# File 'lib/devball/pkgspec/base.rb', line 51 def load_packages(dir, explicit, only_explicit = false) # load all the packagespecs @packages ||= {} @install_packages ||= {} Dir["#{dir}/*.pkgspec"].each {|f| load "#{f}" } def explicit.include?(str) each {|i| if (i === str) return true end } return false end @packages_inorder = @install_packages.collect {|name, pkg| if (deps = pkg.recursive_depends_on) [deps, name].flatten else name end }.flatten.uniq.collect {|pkgname| if (!only_explicit || explicit.include?(pkgname)) @packages[pkgname] || raise(Error, "Unknown package #{pkgname} in package list (#{@packages.keys.join(",")})") else nil end }.compact return @packages_inorder end |
.register_package(klass, name, required) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/devball/pkgspec/base.rb', line 103 def register_package(klass, name, required) @packages ||= {} @packages[name] = klass if (required) @install_packages ||= {} @install_packages[name] = klass end end |
.set_ball(name, required = true) ⇒ Object
112 113 114 115 116 |
# File 'lib/devball/pkgspec/base.rb', line 112 def set_ball(name, required = true) @ball = name @instance = self.new PkgSpec::Base.register_package(@instance, @instance.package_name, required) end |
.set_lib_ball(name) ⇒ Object
defines it as a library that is only required if somethind depended on it.
118 119 120 |
# File 'lib/devball/pkgspec/base.rb', line 118 def set_lib_ball(name) set_ball(name, false) end |
.set_patch(*patches) ⇒ Object
123 124 125 126 |
# File 'lib/devball/pkgspec/base.rb', line 123 def set_patch(*patches) @patches ||= [] @patches += patches end |
Instance Method Details
#ball ⇒ Object
128 129 130 |
# File 'lib/devball/pkgspec/base.rb', line 128 def ball return self.class.ball end |
#ball_file_name ⇒ Object
141 142 143 |
# File 'lib/devball/pkgspec/base.rb', line 141 def ball_file_name() return "#{ball}" end |
#ball_name ⇒ Object
get the name of the ball without version. Cuts off after the first hyphen
166 167 168 |
# File 'lib/devball/pkgspec/base.rb', line 166 def ball_name() ball_version().gsub(/^([^\-]+)$/, '\1') end |
#ball_version ⇒ Object
get the name of the ball without extention
161 162 163 |
# File 'lib/devball/pkgspec/base.rb', line 161 def ball_version() ball().gsub(/^(.*)\.(gem|tar\.gz|tgz|tar\.bz2)$/, '\1') end |
#build_concurrent? ⇒ Boolean
232 233 234 |
# File 'lib/devball/pkgspec/base.rb', line 232 def build_concurrent?() return true end |
#build_dir_name ⇒ Object
get the name of the subdirectory the ball was extracted to provides a default implementation that uses ball() and takes off known extensions on the assumption that its name will be derived from the ball name that way. If that’s not true, it should be overriden
174 175 176 |
# File 'lib/devball/pkgspec/base.rb', line 174 def build_dir_name() return "#{$build_dir}/#{ball_version}" end |
#build_targets ⇒ Object
targets for the build call to make to use
228 229 230 |
# File 'lib/devball/pkgspec/base.rb', line 228 def build_targets() return ["all"] end |
#configure_params ⇒ Object
configure options to pass to ./configure. The default step_configure function uses this, but derived versions don’t have to, but whatever they do should have the same effect as the prefix set by the hash this returns. if this is overloaded, you should merge your options with super()
198 199 200 |
# File 'lib/devball/pkgspec/base.rb', line 198 def configure_params() return {:prefix=>package_install_dir} end |
#configure_script_name ⇒ Object
205 206 207 |
# File 'lib/devball/pkgspec/base.rb', line 205 def configure_script_name() "./configure" end |
#depends_on ⇒ Object
131 132 133 |
# File 'lib/devball/pkgspec/base.rb', line 131 def depends_on return self.class.depends_on end |
#install_links(base_from, base_into, subdir) ⇒ Object
internal implementation of setting the links up for a given directory. pass nil into subdir to suppress recursion.
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/devball/pkgspec/base.rb', line 286 def install_links(base_from, base_into, subdir) recurse = subdir subdir = "" if !subdir Dir[File.join(base_from, subdir, "*")].each {|file| stat = File.lstat(file) if (stat.directory? && recurse) FileUtils.mkdir_p(File.join(base_into, subdir, File.basename(file))) install_links(base_from, base_into, File.join(subdir, File.basename(file))) end if (!stat.directory?) target = File.join(base_into, subdir, File.basename(file)) begin File.delete(target) rescue end File.symlink(file, target) end } end |
#install_service_links(base_from) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/devball/pkgspec/base.rb', line 268 def install_service_links(base_from) Dir[File.join(base_from, "*")].each {|service| supervise_dir = File.join("/var#{$install_base}/supervise", File.basename(service)) begin File.delete(File.join(service, "supervise")) rescue; end File.symlink(supervise_dir, File.join(service, "supervise")) if (File.directory?(File.join(service, "log"))) begin File.delete(File.join(service, "log", "supervise")) rescue; end File.symlink("#{supervise_dir}-log", File.join(service, "log", "supervise")) end } end |
#install_targets ⇒ Object
248 249 250 |
# File 'lib/devball/pkgspec/base.rb', line 248 def install_targets() return ["install"] end |
#link_mappings ⇒ Object
Returns any explicit filename translations that should be performed on a file when linking it into the right place in the tree.
264 265 266 |
# File 'lib/devball/pkgspec/base.rb', line 264 def link_mappings() return {} end |
#package_install_dir ⇒ Object
Returns the directory the package will be installed in.
190 191 192 |
# File 'lib/devball/pkgspec/base.rb', line 190 def package_install_dir() return "#{$install_base}/packages/#{package_name}" end |
#package_name ⇒ Object
get the name of the package without any version information. Default implementation bases it on the class name.
180 181 182 183 184 |
# File 'lib/devball/pkgspec/base.rb', line 180 def package_name() package_name = self.class.name.to_s package_name = package_name.gsub(/^(.+?)(Package)?$/, '\1') return package_name end |
#recursive_depends_on ⇒ Object
134 135 136 137 138 139 |
# File 'lib/devball/pkgspec/base.rb', line 134 def recursive_depends_on return self.class.depends_on.collect {|dep| pkg = PkgSpec::Base.find(dep) || raise(PackageLoadError, "Package #{to_s} depends on #{dep} which doesn't exist.") [pkg.recursive_depends_on, dep] }.flatten end |
#remove_build ⇒ Object
333 334 335 |
# File 'lib/devball/pkgspec/base.rb', line 333 def remove_build() system("rm", "-rf", build_dir_name) || raise(RemoveFailed, "Could not delete existing build directory.") end |
#remove_install ⇒ Object
337 338 339 |
# File 'lib/devball/pkgspec/base.rb', line 337 def remove_install() system("rm", "-rf", package_install_dir) || raise(RemoveFailed, "Could not delete installed directory.") end |
#step_build ⇒ Object
do the build step. Default implementation is to simply run make in the build dir.
237 238 239 240 241 242 243 244 245 246 |
# File 'lib/devball/pkgspec/base.rb', line 237 def step_build() Dir.chdir(build_dir_name) {|dir| args = [] args.push("-j4") if build_concurrent? args += build_targets if (!system("make", *args)) raise BuildFailed, "Build failed with error: #{$?}" end } end |
#step_configure ⇒ Object
do the configure step. The only requirement is that this end up installing things in /$install_base/packages/##package_name. The default implementation runs ./configure in the build dir with the results of configure_params.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/devball/pkgspec/base.rb', line 212 def step_configure() Dir.chdir(build_dir_name) {|dir| params = configure_params.collect {|key, val| if (val) "--#{key}=#{val}" else "--#{key}" end } if (!system(configure_script_name, *params)) raise ConfigureFailed, "Configuration failed with error: #{$?}" end } end |
#step_environment_setup ⇒ Object
202 203 |
# File 'lib/devball/pkgspec/base.rb', line 202 def step_environment_setup() end |
#step_extract ⇒ Object
extracts the ball to the correct place in the builddir
145 146 147 |
# File 'lib/devball/pkgspec/base.rb', line 145 def step_extract() raise Undefined, "Behaviour undefined for extracting the ball" end |
#step_install ⇒ Object
do the install step. Default implementation is to simply run “make install” in the build dir
253 254 255 256 257 258 259 260 |
# File 'lib/devball/pkgspec/base.rb', line 253 def step_install() Dir.chdir(build_dir_name) {|dir| if (!system("make", *install_targets)) raise InstallFailed, "Install failed with error: #{$?}" end } return [] end |
#step_patch ⇒ Object
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/devball/pkgspec/base.rb', line 149 def step_patch() if (File.directory?(build_dir_name) && self.class.patches && self.class.patches.length) orig = Dir.getwd Dir.chdir(build_dir_name) {|dir| self.class.patches.each {|patch| system("patch -p1 < #{orig}/#{patch}") || raise(PatchFailed, "Patch #{patch} failed to apply. Errno #{$?}") } } end end |
#step_setup_links ⇒ Object
Build the appropriate links for the package so it can be run properly from /nexopia
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/devball/pkgspec/base.rb', line 307 def step_setup_links() install_links(package_install_dir, "#{$install_base}", nil) FileUtils.mkdir_p("#{$install_base}/bin") install_links(File.join(package_install_dir, "bin"), "#{$install_base}/bin", "") install_links(File.join(package_install_dir, "sbin"), "#{$install_base}/bin", "") install_links(File.join(package_install_dir, "libexec"), "#{$install_base}/bin", "") FileUtils.mkdir_p("#{$install_base}/lib") install_links(File.join(package_install_dir, "lib"), "#{$install_base}/lib", "") FileUtils.mkdir_p("#{$install_base}/include") install_links(File.join(package_install_dir, "include"), "#{$install_base}/include", "") FileUtils.mkdir_p("#{$install_base}/man") install_links(File.join(package_install_dir, "man"), "#{$install_base}/man", "") FileUtils.mkdir_p("#{$install_base}/etc") install_links(File.join(package_install_dir, "etc"), "#{$install_base}/etc", "") FileUtils.mkdir_p("#{$install_base}/service-privileged") install_service_links(File.join(package_install_dir, "service-privileged")) install_links(File.join(package_install_dir, "service-privileged"), "#{$install_base}/service-privileged", "") FileUtils.mkdir_p("#{$install_base}/service-required") install_service_links(File.join(package_install_dir, "service-required")) install_links(File.join(package_install_dir, "service-required"), "#{$install_base}/service-required", "") FileUtils.mkdir_p("#{$install_base}/service-optional") install_service_links(File.join(package_install_dir, "service-optional")) install_links(File.join(package_install_dir, "service-optional"), "#{$install_base}/service-optional", "") end |
#to_s ⇒ Object
185 186 187 |
# File 'lib/devball/pkgspec/base.rb', line 185 def to_s() package_name() end |