mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/rdoc] update all files if any file is newer
Cross references need parse all files which define the subject names. This commit makes `--force-update` option enforce to parse all files if any file is newer than the previous parse, not only updated files. https://github.com/ruby/rdoc/commit/13e9a44896
This commit is contained in:
parent
b5db9b8a31
commit
e23f0f29da
3 changed files with 33 additions and 20 deletions
|
@ -755,7 +755,7 @@ Usage: #{opt.program_name} [options] [names...]
|
||||||
|
|
||||||
opt.on("--[no-]force-update", "-U",
|
opt.on("--[no-]force-update", "-U",
|
||||||
"Forces rdoc to scan all sources even if",
|
"Forces rdoc to scan all sources even if",
|
||||||
"newer than the flag file.") do |value|
|
"no files are newer than the flag file.") do |value|
|
||||||
@force_update = value
|
@force_update = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -112,11 +112,17 @@ class RDoc::RDoc
|
||||||
|
|
||||||
file_list = normalized_file_list files, true, @options.exclude
|
file_list = normalized_file_list files, true, @options.exclude
|
||||||
|
|
||||||
file_list = file_list.uniq
|
file_list = remove_unparseable(file_list)
|
||||||
|
|
||||||
file_list = remove_unparseable file_list
|
if file_list.count {|name, mtime|
|
||||||
|
file_list[name] = @last_modified[name] unless mtime
|
||||||
file_list.sort
|
mtime
|
||||||
|
} > 0
|
||||||
|
@last_modified.replace file_list
|
||||||
|
file_list.keys.sort
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -254,11 +260,11 @@ option)
|
||||||
# read and strip comments
|
# read and strip comments
|
||||||
patterns = File.read(filename).gsub(/#.*/, '')
|
patterns = File.read(filename).gsub(/#.*/, '')
|
||||||
|
|
||||||
result = []
|
result = {}
|
||||||
|
|
||||||
patterns.split(' ').each do |patt|
|
patterns.split(' ').each do |patt|
|
||||||
candidates = Dir.glob(File.join(in_dir, patt))
|
candidates = Dir.glob(File.join(in_dir, patt))
|
||||||
result.concat normalized_file_list(candidates, false, @options.exclude)
|
result.update normalized_file_list(candidates, false, @options.exclude)
|
||||||
end
|
end
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -278,21 +284,21 @@ option)
|
||||||
|
|
||||||
def normalized_file_list(relative_files, force_doc = false,
|
def normalized_file_list(relative_files, force_doc = false,
|
||||||
exclude_pattern = nil)
|
exclude_pattern = nil)
|
||||||
file_list = []
|
file_list = {}
|
||||||
|
|
||||||
relative_files.each do |rel_file_name|
|
relative_files.each do |rel_file_name|
|
||||||
|
rel_file_name = rel_file_name.sub(/^\.\//, '')
|
||||||
next if rel_file_name.end_with? 'created.rid'
|
next if rel_file_name.end_with? 'created.rid'
|
||||||
next if exclude_pattern && exclude_pattern =~ rel_file_name
|
next if exclude_pattern && exclude_pattern =~ rel_file_name
|
||||||
stat = File.stat rel_file_name rescue next
|
stat = File.stat rel_file_name rescue next
|
||||||
|
|
||||||
case type = stat.ftype
|
case type = stat.ftype
|
||||||
when "file" then
|
when "file" then
|
||||||
next if last_modified = @last_modified[rel_file_name] and
|
mtime = (stat.mtime unless (last_modified = @last_modified[rel_file_name] and
|
||||||
stat.mtime.to_i <= last_modified.to_i
|
stat.mtime.to_i <= last_modified.to_i))
|
||||||
|
|
||||||
if force_doc or RDoc::Parser.can_parse(rel_file_name) then
|
if force_doc or RDoc::Parser.can_parse(rel_file_name) then
|
||||||
file_list << rel_file_name.sub(/^\.\//, '')
|
file_list[rel_file_name] = mtime
|
||||||
@last_modified[rel_file_name] = stat.mtime
|
|
||||||
end
|
end
|
||||||
when "directory" then
|
when "directory" then
|
||||||
next if rel_file_name == "CVS" || rel_file_name == ".svn"
|
next if rel_file_name == "CVS" || rel_file_name == ".svn"
|
||||||
|
@ -303,16 +309,16 @@ option)
|
||||||
dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
|
dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
|
||||||
|
|
||||||
if File.file? dot_doc then
|
if File.file? dot_doc then
|
||||||
file_list << parse_dot_doc_file(rel_file_name, dot_doc)
|
file_list.update(parse_dot_doc_file(rel_file_name, dot_doc))
|
||||||
else
|
else
|
||||||
file_list << list_files_in_directory(rel_file_name)
|
file_list.update(list_files_in_directory(rel_file_name))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
warn "rdoc can't parse the #{type} #{rel_file_name}"
|
warn "rdoc can't parse the #{type} #{rel_file_name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
file_list.flatten
|
file_list
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -427,7 +433,7 @@ The internal error was:
|
||||||
# files for emacs and vim.
|
# files for emacs and vim.
|
||||||
|
|
||||||
def remove_unparseable files
|
def remove_unparseable files
|
||||||
files.reject do |file|
|
files.reject do |file, *|
|
||||||
file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
|
file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
|
||||||
(file =~ /tags$/i and
|
(file =~ /tags$/i and
|
||||||
open(file, 'rb') { |io|
|
open(file, 'rb') { |io|
|
||||||
|
|
|
@ -73,6 +73,11 @@ class TestRDocRDoc < RDoc::TestCase
|
||||||
b = File.expand_path '../test_rdoc_text.rb', __FILE__
|
b = File.expand_path '../test_rdoc_text.rb', __FILE__
|
||||||
|
|
||||||
assert_equal [a, b], @rdoc.gather_files([b, a, b])
|
assert_equal [a, b], @rdoc.gather_files([b, a, b])
|
||||||
|
|
||||||
|
assert_empty @rdoc.gather_files([b, a, b])
|
||||||
|
|
||||||
|
@rdoc.last_modified[a] -= 10
|
||||||
|
assert_equal [a, b], @rdoc.gather_files([b, a, b])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_handle_pipe
|
def test_handle_pipe
|
||||||
|
@ -146,7 +151,7 @@ class TestRDocRDoc < RDoc::TestCase
|
||||||
@rdoc.normalized_file_list [test_path, flag_file]
|
@rdoc.normalized_file_list [test_path, flag_file]
|
||||||
end
|
end
|
||||||
|
|
||||||
files = files.map { |file| File.expand_path file }
|
files = files.map { |file, *| File.expand_path file }
|
||||||
|
|
||||||
assert_equal [test_path], files
|
assert_equal [test_path], files
|
||||||
end
|
end
|
||||||
|
@ -156,7 +161,9 @@ class TestRDocRDoc < RDoc::TestCase
|
||||||
|
|
||||||
files = @rdoc.normalized_file_list [__FILE__]
|
files = @rdoc.normalized_file_list [__FILE__]
|
||||||
|
|
||||||
assert_empty files
|
files = files.collect {|file, mtime| file if mtime}.compact
|
||||||
|
|
||||||
|
assert_empty(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_normalized_file_list_non_file_directory
|
def test_normalized_file_list_non_file_directory
|
||||||
|
@ -205,7 +212,7 @@ class TestRDocRDoc < RDoc::TestCase
|
||||||
@rdoc.normalized_file_list [File.realpath(dir)]
|
@rdoc.normalized_file_list [File.realpath(dir)]
|
||||||
end
|
end
|
||||||
|
|
||||||
files = files.map { |file| File.expand_path file }
|
files = files.map { |file, *| File.expand_path file }
|
||||||
|
|
||||||
assert_equal expected_files, files
|
assert_equal expected_files, files
|
||||||
end
|
end
|
||||||
|
@ -236,7 +243,7 @@ class TestRDocRDoc < RDoc::TestCase
|
||||||
@rdoc.normalized_file_list [File.realpath(dir)]
|
@rdoc.normalized_file_list [File.realpath(dir)]
|
||||||
end
|
end
|
||||||
|
|
||||||
files = files.map { |file| File.expand_path file }
|
files = files.map { |file, *| File.expand_path file }
|
||||||
|
|
||||||
assert_equal expected_files, files
|
assert_equal expected_files, files
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue