lib/rbbt/resource/util.rb in rbbt-util-5.1.0 vs lib/rbbt/resource/util.rb in rbbt-util-5.2.0

- old
+ new

@@ -1,6 +1,5 @@ -require 'rbbt/resource/rake' module Path def self.caller_lib_dir(file = nil, relative_to = 'lib') file = caller.reject{|l| @@ -29,57 +28,64 @@ end end module Resource def set_software_env(software_dir) - bin_dir = File.join(software_dir, 'bin') - opt_dir = File.join(software_dir, 'opt') + software_dir.find_all.each do |software_dir| + bin_dir = File.join(software_dir, 'bin') + opt_dir = File.join(software_dir, 'opt') - Misc.env_add 'PATH', bin_dir + Misc.env_add 'PATH', bin_dir - FileUtils.mkdir_p opt_dir unless File.exists? opt_dir - %w(.ld-paths .pkgconfig-paths .aclocal-paths .java-classpaths).each do |file| - filename = File.join(opt_dir, file) - FileUtils.touch filename unless File.exists? filename - end + FileUtils.mkdir_p opt_dir unless File.exists? opt_dir - if not File.exists? File.join(opt_dir,'.post_install') - Open.write(File.join(opt_dir,'.post_install'),"#!/bin/bash\n") - end + %w(.ld-paths .pkgconfig-paths .aclocal-paths .java-classpaths).each do |file| + filename = File.join(opt_dir, file) + begin + FileUtils.touch filename unless File.exists? filename + rescue + Log.warn("Could not touch #{ filename }") + end + end - Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line| - Misc.env_add('LD_LIBRARY_PATH',line.chomp) - Misc.env_add('LD_RUN_PATH',line.chomp) - end + begin + if not File.exists? File.join(opt_dir,'.post_install') + Open.write(File.join(opt_dir,'.post_install'),"#!/bin/bash\n") + end + rescue Exception + Log.warn("Could not create default .post_install in #{ software_dir }") + end - Open.read(File.join opt_dir, '.pkgconfig-paths').split(/\n/).each do |line| - Misc.env_add('PKG_CONFIG_PATH',line.chomp) - end + Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line| + Misc.env_add('LD_LIBRARY_PATH',line.chomp) + Misc.env_add('LD_RUN_PATH',line.chomp) + end if File.exists? File.join(opt_dir, '.ld-paths') - Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line| - Misc.env_add('LD_LIBRARY_PATH',line.chomp) - end + Open.read(File.join opt_dir, '.pkgconfig-paths').split(/\n/).each do |line| + Misc.env_add('PKG_CONFIG_PATH',line.chomp) + end if File.exists? File.join(opt_dir, '.pkgconfig-paths') - Open.read(File.join opt_dir, '.ld-paths').split(/\n/).each do |line| - Misc.env_add('LD_LIBRARY_PATH',line.chomp) - end + Open.read(File.join opt_dir, '.aclocal-paths').split(/\n/).each do |line| + Misc.env_add('ACLOCAL_FLAGS', "-I#{File.join(opt_dir, line.chomp)}", ' ') + end if File.exists? File.join(opt_dir, '.aclocal-paths') - Open.read(File.join opt_dir, '.aclocal-paths').split(/\n/).each do |line| - Misc.env_add('ACLOCAL_FLAGS', "-I#{File.join(opt_dir, line.chomp)}", ' ') - end + Open.read(File.join opt_dir, '.java-classpaths').split(/\n/).each do |line| + Misc.env_add('CLASSPATH', "#{File.join(opt_dir,'java', 'lib', line.chomp)}") + end if File.exists? File.join(opt_dir, '.java-classpaths') - Open.read(File.join opt_dir, '.java-classpaths').split(/\n/).each do |line| - Misc.env_add('CLASSPATH', "#{File.join(opt_dir,'java', 'lib', line.chomp)}") - end + Dir.glob(File.join opt_dir, 'jars', '*').each do |file| + Misc.env_add('CLASSPATH', "#{File.expand_path(file)}") + end - Dir.glob(File.join opt_dir, 'jars', '*').each do |file| - Misc.env_add('CLASSPATH', "#{File.expand_path(file)}") - end + begin + File.chmod 0777, File.join(opt_dir, '.post_install') + rescue + Log.warn("Could not change permisions of .post_install in #{ software_dir }") + end - File.chmod 0774, File.join(opt_dir, '.post_install') - - CMD.cmd(File.join(opt_dir, '.post_install')) + CMD.cmd(File.join(opt_dir, '.post_install')) if File.exists? File.join(opt_dir, '.post_install') + end end def rake_for(path) @rake_dirs.reject{|dir, content| @@ -98,9 +104,10 @@ rakefile = rakefile.produce if rakefile.respond_to? :produce rake_dir = rake_dir.find if rake_dir.respond_to? :find begin + require 'rbbt/resource/rake' Rake.run(rakefile, rake_dir, task) rescue Rake::TaskNotFound raise $! if rake_dir.nil? or rake_dir.empty? or rake_dir == "/" or rake_dir == "./" task = File.join(File.basename(rake_dir), task) rake_dir = File.dirname(rake_dir)