lib/setup/install.rb in setup-4.1.0 vs lib/setup/install.rb in setup-4.2.0

- old
+ new

@@ -1,21 +1,35 @@ require 'optparse' require 'setup/config' -# TODO: we need to abort install if tests fail (how?) -# We will also need to add a force install option then. -# TODO: Need to get name setting from where? -# TODO: Add support for rdoc once project name issue is worked out. (see RDOC HERE.) -# TODO: Generate rdocs? Package developer may want to deactivate this. +# TODO: we need to abort install if tests fail (check return code of TESTER) +# We will also need to add a force install option then to by pass failed tests. +# +# TODO: Generate rdocs... Package developer may want to deactivate this. How? +# +# TODO: Should be using Rdoc programmatically, but load issue arose and an error +# was being generated on ri generation. Reverting back to shelling out for now. -# Need the package name. This is used to install docs in system doc/ruby-{name}/ location. -PACKAGE_NAME = "" +# The name of the package, used to install docs in system doc/ruby-{name}/ location. +# The information must be provided in a file called meta/package. +PACKAGE =( + if file = Dir["{meta,.meta}/package"].first + File.read(file).strip + else + nil + end +) -#-- -#File.read(Dir.glob('{.,meta/}unixname{,.txt}', File::FNM_CASEFOLD).first).strip -#++ +# A ruby script that instructs setup how to run tests, located at meta/setup/test.rb +# If the tests fail, the script should exit with a fail status (eg. -1). +TESTER = Dir.glob('{meta,.meta}/setup/test{,rc}.rb', File::FNM_CASEFOLD).first +# A ruby script that instructs setup how to generate docs, located at meta/setup/doc.rb +# NOTE: Docs must be generate into the doc/ for them to be installed. +DOCTOR = Dir.glob('{meta,.meta}/setup/doc{,rc}.rb', File::FNM_CASEFOLD).first + + module Setup # Installer class handles the actual install procedure, # as well as the other tasks, such as testing. @@ -44,17 +58,18 @@ @srcdir = File.expand_path(srcroot) @objdir = File.expand_path(objroot) @currdir = '.' - self.quiet = ENV['quiet'] if ENV['quiet'] + self.quiet = ENV['quiet'] if ENV['quiet'] self.verbose = ENV['verbose'] if ENV['verbose'] self.no_harm = ENV['nowrite'] if ENV['nowrite'] yield(self) if block_given? end + # def inspect "#<#{self.class} #{File.basename(@srcdir)}>" end # Are we running an installation? @@ -165,23 +180,20 @@ end ## # TASK setup # - # FIXME: Update shebang at time of install not before. - # for now I've commented out the shebang. - # - + # FIXME: Update shebang on install rather than before. def exec_setup report_header('setup') exec_task_traverse 'setup' puts "Ok." end def setup_dir_bin(rel) files_of(curr_srcdir()).each do |fname| - #update_shebang_line "#{curr_srcdir()}/#{fname}" # HERE + update_shebang_line "#{curr_srcdir()}/#{fname}" # MOVE TO INSTALL (BUT HOW?) end end alias setup_dir_lib noop @@ -272,22 +284,21 @@ ## # TASK test # # Complexities arise in trying to figure out what test framework # is used, and how to run tests. To simplify the process, this - # method simply looks for a script, either '.config/setup/testrc.rb', - # or 'script/test' or 'task/test' and runs it if found. + # simply looks for a script in meta/setup called testrc.rb, + # or just test.rb. # def exec_test return if install_no_test - file = nil - file ||= Dir.glob('.config/setup/test{,rc}{,.rb}', File::FNM_CASEFOLD).first - file ||= Dir.glob('{script,task}/test', File::FNM_CASEFOLD).first + file = TESTER if file report_header('test') ruby(file) end + #puts "Ok." unless quiet? end ### DEPRECATED #def exec_test #runner = config.testrunner @@ -336,54 +347,80 @@ #def test_dir_test #end ## # TASK doc - # - # NOT USED YET. def exec_doc - return if config.without_doc? + return if config.withoutdoc? report_header('doc') - #exec_rdoc unless config.without_doc? # RDOC HERE - exec_ri + if file = DOCTOR + ruby(file) + else + exec_rdoc + end + exec_ri end # Generate rdocs. - + # + # NOT USED YET B/C WE WOULD HAVE TO KNOW THE NAME OF THE PROJECT + # TO DO THIS CORRECTLY. (WHERE DO WE GET THAT?) + # + # Answer: meta/package or .meta/package + # def exec_rdoc - output = File.join('doc', 'rdoc') - title = (PACKAGE_NAME.capitalize + " API").strip - main = Dir.glob("README{,.txt}", File::FNM_CASEFOLD).first - template = config.doctemplate || 'html' + main = Dir.glob("README{,.*}", File::FNM_CASEFOLD).first - opt = [] - opt << "-U" - opt << "-S" - opt << "--op=#{output}" - opt << "--template=#{template}" - opt << "--title=#{title}" - opt << "--main=#{main}" if main - if File.exist?('.document') files = File.read('.document').split("\n") files.reject!{ |l| l =~ /^\s*[#]/ || l !~ /\S/ } files.collect!{ |f| f.strip } - opt << files else - opt << main if main - opt << ["lib", "ext"] + files = [] + files << main if main + files << 'lib' if File.directory?('lib') + files << 'ext' if File.directory?('ext') end + checkfiles = (files + files.map{ |f| Dir[File.join(f,'*','**')] }).flatten.uniq + if FileUtils.uptodate?('doc/rdoc', checkfiles) + puts "RDocs look uptodate." + return + end + + output = 'doc/rdoc' + title = (PACKAGE.capitalize + " API").strip + template = config.doctemplate || 'html' + + opt = [] + opt << "-U" + opt << "-q" #if quiet? + opt << "--op=#{output}" + #opt << "--template=#{template}" + opt << "--title=#{title}" + opt << "--main=#{main}" if main + #opt << "--debug" + opt << files + opt = opt.flatten + cmd = "rdoc " + opt.join(' ') + if no_harm? - puts "rdoc " + opt.join(' ').strip + puts cmd else - #sh "rdoc {opt.join(' ').strip}" - require 'rdoc/rdoc' - ::RDoc::RDoc.new.document(opt) + begin + system(cmd) + #require 'rdoc/rdoc' + #::RDoc::RDoc.new.document(opt) + puts "Ok rdoc." unless quiet? + rescue Exception + puts "Fail rdoc." + puts "Command was: '#{cmd}'" + puts "Proceeding with install anyway." + end end end # Generate ri documentation. @@ -402,34 +439,47 @@ if File.exist?('.document') files = File.read('.document').split("\n") files.reject!{ |l| l =~ /^\s*[#]/ || l !~ /\S/ } files.collect!{ |f| f.strip } else - files = ["lib", "ext"] + files = [] + files << 'lib' if File.directory?('lib') + files << 'ext' if File.directory?('ext') end opt = [] opt << "-U" + opt << "-q" #if quiet? + #opt << "-D" #if $DEBUG opt << output opt << files + opt = opt.flatten + cmd = "rdoc " + opt.join(' ') + if no_harm? - puts "rdoc #{opt.join(' ').strip}" + puts cmd else # Generate in system location specified - #sh "rdoc #{opt.join(' ').strip}" - require 'rdoc/rdoc' - ::RDoc::RDoc.new.document(opt) - + begin + system(cmd) + #require 'rdoc/rdoc' + #::RDoc::RDoc.new.document(opt) + puts "Ok ri." unless quiet? + rescue Exception + puts "Fail ri." + puts "Command was: '#{cmd}'" + puts "Proceeding with install anyway." + end # Now in local directory - opt = [] - opt << "-U" - opt << "--ri --op 'doc/ri'" - opt << files - opt = opt.flatten - ::RDoc::RDoc.new.document(opt) + #opt = [] + #opt << "-U" + #opt << "--ri --op 'doc/ri'" + #opt << files + #opt = opt.flatten + #::RDoc::RDoc.new.document(opt) end end ## # TASK install @@ -471,19 +521,16 @@ install_files targetfiles(), "#{config.mandir}/#{rel}", 0644 end # doc installs to directory named: "ruby-#{package}" def install_dir_doc(rel) - return if config.without_doc? - dir = "#{config.docdir}/ruby-#{PACKAGE_NAME}/#{rel}" # "#{config.docdir}/#{rel}" + return if config.withoutdoc? + return unless PACKAGE + dir = "#{config.docdir}/ruby-#{PACKAGE}/#{rel}" # "#{config.docdir}/#{rel}" install_files targetfiles(), dir, 0644 end - # doc installs to directory named: "ruby-#{package}" - def install_dir_doc(rel) - end - def install_files(list, dest, mode) mkdir_p dest, install_prefix list.each do |fname| install fname, dest, mode, install_prefix end @@ -517,11 +564,11 @@ end } end # picked up many entries from cvs-1.11.1/src/ignore.c - JUNK_FILES = %w( + JUNK_FILES = %w( core RCSLOG tags TAGS .make.state .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb *~ *.old *.bak *.BAK *.orig *.rej _$* *$ *.org *.in .* @@ -566,15 +613,30 @@ def exec_uninstall paths = File.read(MANIFEST).split("\n") dirs, files = paths.partition{ |f| File.dir?(f) } - files.each do |file| + remove = [] + files.uniq.each do |file| next if /^\#/ =~ file # skip comments - rm_f(file) if File.exist?(file) + remove << file if File.exist?(file) end + if verbose? && !no_harm? + puts remove.collect{ |f| "rm #{f}" }.join("\n") + ans = ask("Continue?", "yN") + case ans + when 'y', 'Y', 'yes' + else + return # abort? + end + end + + remove.each do |file| + rm_f(file) + end + dirs.each do |dir| # okay this is over kill, but playing it safe... empty = Dir[File.join(dir,'*')].empty? begin if no_harm? @@ -643,11 +705,11 @@ # def exec_task_traverse(task) run_hook "pre-#{task}" FILETYPES.each do |type| - if type == 'ext' and config.without_ext == 'yes' + if type == 'ext' and config.withoutext? #== 'yes' $stderr.puts 'skipping ext/* by user option' if verbose? next end traverse task, type, "#{task}_dir_#{type}" end @@ -864,10 +926,18 @@ Dir.open(dir) {|d| return d.select {|ent| File.dir?("#{dir}/#{ent}") } - DIR_REJECT } end + # Ask a question of the user. + def ask(question, answers=nil) + $stdout << "#{question}" + $stdout << " [#{answers}] " if answers + until inp = $stdin.gets ; sleep 1 ; end + inp.strip + end + ## # Hook Script API # # These require: #srcdir_root, #objdir_root, #relpath # @@ -883,10 +953,10 @@ config[key] = val end # srcdir/objdir (works only in the package directory) # - # TODO: Since package directory has been deprecated these + # TODO: Since package directory has been deprecated these # probably can be worked out of the system. ? # def curr_srcdir "#{srcdir_root()}/#{relpath()}"