From 392f342f04b8039bb5a352b17dac02311e260276 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 17 Sep 2006 14:46:13 +0000 Subject: * lib/rdoc/rdoc.rb (RDoc::RDoc#document): scan only files modified after the previous generation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/rdoc.rb | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'lib/rdoc/rdoc.rb') diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index cb5d6501d8..91f5611196 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -16,6 +16,7 @@ require 'rdoc/diagram' require 'find' require 'ftools' +require 'time' # We put rdoc stuff in the RDoc module to avoid namespace # clutter. @@ -106,25 +107,38 @@ module RDoc # then we refuse to use it, as we may clobber some # manually generated documentation - def setup_output_dir(op_dir) - flag_file = File.join(op_dir, "created.rid") + def setup_output_dir(op_dir, force) + flag_file = output_flag_file(op_dir) if File.exist?(op_dir) unless File.directory?(op_dir) error "'#{op_dir}' exists, and is not a directory" end - unless File.file?(flag_file) + begin + created = File.read(flag_file) + rescue SystemCallError error "\nDirectory #{op_dir} already exists, but it looks like it\n" + "isn't an RDoc directory. Because RDoc doesn't want to risk\n" + "destroying any of your existing files, you'll need to\n" + "specify a different output directory name (using the\n" + "--op option).\n\n" + else + last = (Time.parse(created) unless force rescue nil) end else File.makedirs(op_dir) end - File.open(flag_file, "w") {|f| f.puts Time.now } + last + end + + # Update the flag file in an output directory. + def update_output_dir(op_dir, time) + File.open(output_flag_file(op_dir), "w") {|f| f.puts time.rfc2822 } + end + + # Return the path name of the flag file in an output directory. + def output_flag_file(op_dir) + File.join(op_dir, "created.rid") end - # The .document file contains a list of file and directory name # patterns, representing candidates for documentation. It may @@ -160,8 +174,10 @@ module RDoc relative_files.each do |rel_file_name| next if exclude_pattern && exclude_pattern =~ rel_file_name - case type = File.stat(rel_file_name).ftype + stat = File.stat(rel_file_name) + case type = stat.ftype when "file" + next if @last_created and stat.mtime < @last_created file_list << rel_file_name.sub(/^\.\//, '') if force_doc || ParserFactory.can_parse(rel_file_name) when "directory" next if rel_file_name == "CVS" || rel_file_name == ".svn" @@ -238,22 +254,25 @@ module RDoc options = Options.instance options.parse(argv, GENERATORS) - + + @last_created = nil unless options.all_one_file - setup_output_dir(options.op_dir) + @last_created = setup_output_dir(options.op_dir, options.force_update) end + start_time = Time.now file_info = parse_files(options) - gen = options.generator - - $stderr.puts "\nGenerating #{gen.key.upcase}..." unless options.quiet - - require gen.file_name - - gen_class = Generators.const_get(gen.class_name) - - unless file_info.empty? + if file_info.empty? + $stderr.puts "\nNo newer files." unless options.quiet + else + gen = options.generator + + $stderr.puts "\nGenerating #{gen.key.upcase}..." unless options.quiet + + require gen.file_name + + gen_class = Generators.const_get(gen.class_name) gen = gen_class.for(options) pwd = Dir.pwd @@ -263,6 +282,7 @@ module RDoc begin Diagram.new(file_info, options).draw if options.diagram gen.generate(file_info) + update_output_dir(".", start_time) ensure Dir.chdir(pwd) end -- cgit v1.2.3