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

- old
+ new

@@ -19,11 +19,11 @@ # Installer class handles the actual install procedure, # as well as the other tasks, such as testing. class Installer - MANIFEST = '.installedfiles' + MANIFEST = '.cache/setup/installedfiles' FILETYPES = %w( bin lib ext data etc man doc ) # Configuration attr :config @@ -31,17 +31,18 @@ attr_writer :no_harm attr_writer :verbose attr_writer :quiet attr_accessor :install_prefix + attr_accessor :install_no_test # New Installer. - def initialize #:yield: + def initialize(config=nil) #:yield: srcroot = '.' objroot = '.' - @config = ConfigTable.new + @config = config || ConfigTable.new @srcdir = File.expand_path(srcroot) @objdir = File.expand_path(objroot) @currdir = '.' @@ -58,13 +59,13 @@ # Are we running an installation? def installation?; @installation; end def installation!; @installation = true; end - def no_harm?; @no_harm; end - def verbose?; @verbose; end - def quiet?; @quiet; end + def no_harm? ; @no_harm ; end + def verbose? ; @verbose ; end + def quiet? ; @quiet ; end def verbose_off #:yield: begin save, @verbose = verbose?, false yield @@ -96,11 +97,11 @@ end # def noop(rel); end - # + ## # Hook Script API bases # def srcdir_root @srcdir @@ -112,23 +113,23 @@ def relpath @currdir end - # + ## # Task all # def exec_all exec_config exec_setup - exec_test # TODO: stop here if fail (?) + exec_test exec_doc exec_install end - # + ## # TASK config # def exec_config report_header('config') @@ -153,19 +154,19 @@ def extconf ruby "#{curr_srcdir()}/extconf.rb", config.extconfopt end - # + ## # TASK show # def exec_show config.show end - # + ## # TASK setup # # FIXME: Update shebang at time of install not before. # for now I've commented out the shebang. # @@ -266,75 +267,90 @@ def to_s "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}") end end - # + ## # TASK test # - # TODO: Add spec support. - + # 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. + # def exec_test - report_header('test') - runner = config.testrunner - case runner - when 'testrb' # TODO: needs work - opt = [] - opt << " -v" if verbose? - opt << " --runner #{runner}" - if File.file?('test/suite.rb') - notests = false - opt << "test/suite.rb" - else - notests = Dir["test/**/*.rb"].empty? - lib = ["lib"] + config.extensions.collect{ |d| File.dirname(d) } - opt << "-I" + lib.join(':') - opt << Dir["test/**/{test,tc}*.rb"] - end - opt = opt.flatten.join(' ').strip - # run tests - if notests - $stderr.puts 'no test in this package' if verbose? - else - cmd = "testrb #{opt}" - $stderr.puts cmd if verbose? - system cmd #config.ruby "-S tesrb", opt - end - else # autorunner - unless File.directory?('test') - $stderr.puts 'no test in this package' if verbose? - return - end - begin - require 'test/unit' - rescue LoadError - setup_rb_error 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.' - end - autorunner = Test::Unit::AutoRunner.new(true) - autorunner.to_run << 'test' - autorunner.run + 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 + if file + report_header('test') + ruby(file) end end + ### DEPRECATED + #def exec_test + #runner = config.testrunner + #case runner + #when 'testrb' # TODO: needs work + # opt = [] + # opt << " -v" if verbose? + # opt << " --runner #{runner}" + # if File.file?('test/suite.rb') + # notests = false + # opt << "test/suite.rb" + # else + # notests = Dir["test/**/*.rb"].empty? + # lib = ["lib"] + config.extensions.collect{ |d| File.dirname(d) } + # opt << "-I" + lib.join(':') + # opt << Dir["test/**/{test,tc}*.rb"] + # end + # opt = opt.flatten.join(' ').strip + # # run tests + # if notests + # $stderr.puts 'no test in this package' if verbose? + # else + # cmd = "testrb #{opt}" + # $stderr.puts cmd if verbose? + # system cmd #config.ruby "-S testrb", opt + # end + #else # autorunner + # unless File.directory?('test') + # $stderr.puts 'no test in this package' if verbose? + # return + # end + # begin + # require 'test/unit' + # rescue LoadError + # setup_rb_error 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.' + # end + # lib = ["lib"] + config.extensions.collect{ |d| File.dirname(d) } + # lib.each{ |l| $LOAD_PATH << l } + # autorunner = Test::Unit::AutoRunner.new(true) + # autorunner.to_run << 'test' + # autorunner.run + #end + #end + # MAYBE: We could traverse and run each test independently (?) #def test_dir_test #end + ## + # TASK doc # - # - # + # NOT USED YET. def exec_doc return if config.without_doc? report_header('doc') #exec_rdoc unless config.without_doc? # RDOC HERE exec_ri end - # TASK rdoc - # - # NOTE USED YET. + # Generate rdocs. def exec_rdoc output = File.join('doc', 'rdoc') title = (PACKAGE_NAME.capitalize + " API").strip main = Dir.glob("README{,.txt}", File::FNM_CASEFOLD).first @@ -367,11 +383,11 @@ require 'rdoc/rdoc' ::RDoc::RDoc.new.document(opt) end end - # TASK ri + # Generate ri documentation. def exec_ri case config.installdirs when 'std' output = "--ri-system" @@ -413,11 +429,11 @@ opt = opt.flatten ::RDoc::RDoc.new.document(opt) end end - # + ## # TASK install # def exec_install report_header('install') @@ -542,11 +558,11 @@ /\A(?:#{ pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|') })\z/ end - # + ## # TASK uninstall # def exec_uninstall paths = File.read(MANIFEST).split("\n") @@ -572,11 +588,11 @@ end rm_f(MANIFEST) end - # + ## # TASK clean # def exec_clean exec_task_traverse 'clean' @@ -594,11 +610,11 @@ def clean_dir_ext(rel) return unless extdir?(curr_srcdir()) make 'clean' if File.file?('Makefile') end - # + ## # TASK distclean # def exec_distclean exec_task_traverse 'distclean' @@ -620,11 +636,11 @@ def distclean_dir_doc(rel) #rm_rf('rdoc') if File.directory?('rdoc') # RDOC HERE end - # + ## # Traversing # def exec_task_traverse(task) run_hook "pre-#{task}" @@ -647,10 +663,11 @@ end run_hook "post-#{task}" } end + # def dive_into(rel) return unless File.dir?("#{@srcdir}/#{rel}") dir = File.basename(rel) Dir.mkdir dir unless File.dir?(dir) @@ -662,10 +679,11 @@ Dir.chdir prevdir $stderr.puts '<--- ' + rel if verbose? @currdir = File.dirname(rel) end + # def run_hook(id) path = [ "#{curr_srcdir()}/#{id}", "#{curr_srcdir()}/#{id}.rb" ].detect {|cand| File.file?(cand) } return unless path begin @@ -674,10 +692,11 @@ raise if $DEBUG setup_rb_error "hook #{path} failed:\n" + $!.message end end + ## # File Operations # # This module requires: #verbose?, #no_harm? def binread(fname) @@ -802,10 +821,11 @@ record_installation(path) end end def record_installation(path) + FileUtils.mkdir_p(File.dirname("#{objdir_root()}/#{MANIFEST}")) File.open("#{objdir_root()}/#{MANIFEST}", 'a') do |f| f.puts(path) end end @@ -844,30 +864,32 @@ Dir.open(dir) {|d| return d.select {|ent| File.dir?("#{dir}/#{ent}") } - DIR_REJECT } end - # + ## # Hook Script API # # These require: #srcdir_root, #objdir_root, #relpath # # def get_config(key) - config.__send__(key) + config[key] end # obsolete: use metaconfig to change configuration # TODO: what to do with? def set_config(key, val) config[key] = val end - # # srcdir/objdir (works only in the package directory) # + # TODO: Since package directory has been deprecated these + # probably can be worked out of the system. ? + # def curr_srcdir "#{srcdir_root()}/#{relpath()}" end def curr_objdir