Modify parts only marked as autogenerated.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-11-15 11:30:59 +00:00
parent a4a2fbdf64
commit a895babbff

View file

@ -257,7 +257,8 @@ def compare_deps(make_deps, actual_deps, out=$stdout)
rescue Errno::ENOENT rescue Errno::ENOENT
[] []
end end
depline = "#{target2}: #{source2} \# #{target}: #{source}\n" #depline = "#{target2}: #{source2} \# #{target}: #{source}\n"
depline = "#{target2}: #{source2}\n"
if !make_sources.include?(source) if !make_sources.include?(source)
out.puts "add #{makefile} : #{depline}" out.puts "add #{makefile} : #{depline}"
elsif !actual_sources.include?(source) elsif !actual_sources.include?(source)
@ -298,42 +299,86 @@ def extract_deplines(problems)
dels = {} dels = {}
problems.each_line {|line| problems.each_line {|line|
case line case line
when /\Aadd (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/ when /\Aadd (\S+) : (\S.*\n)\z/
(adds[$1] ||= []) << $2 (adds[$1] ||= []) << $2
when /\AdelL (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/ when /\AdelL (\S+) : (\S.*\n)\z/
(dels[$1] ||= []) << $2 (dels[$1] ||= []) << $2
when /\AdelP (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/ when /\AdelP (\S+) : (\S.*\n)\z/
(dels[$1] ||= []) << $2 (dels[$1] ||= []) << $2
when /\AokL (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/ when /\AokL (\S+) : (\S.*\n)\z/
when /\AokP (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/ when /\AokP (\S+) : (\S.*\n)\z/
(adds[$1] ||= []) << $2 (adds[$1] ||= []) << $2
end end
} }
return adds, dels return adds, dels
end end
DEPENDENCIES_SECTION_START_MARK = "\# AUTOGENERATED DEPENDENCIES START\n"
DEPENDENCIES_SECTION_END_MARK = "\# AUTOGENERATED DEPENDENCIES END\n"
def main_actual_fix(problems) def main_actual_fix(problems)
adds, dels = extract_deplines(problems) adds, dels = extract_deplines(problems)
(adds.keys | dels.keys).sort.each {|makefile| (adds.keys | dels.keys).sort.each {|makefile|
lines = begin content = begin
File.readlines(makefile) File.read(makefile)
rescue Errno::ENOENT rescue Errno::ENOENT
[] ''
end end
if /^#{Regexp.escape DEPENDENCIES_SECTION_START_MARK}((?:.*\n)*)#{Regexp.escape DEPENDENCIES_SECTION_END_MARK}/ =~ content
pre_post_part = [$`, $']
lines = $1.lines.to_a
else
pre_post_part = nil
lines = []
end
lines_original = lines.dup
if dels[makefile] if dels[makefile]
lines -= dels[makefile] lines -= dels[makefile]
end end
if adds[makefile] if adds[makefile]
lines.concat(adds[makefile] - lines) lines.concat(adds[makefile] - lines)
end end
if lines.empty?
if File.exist? makefile if lines == lines_original
File.open(makefile, 'w') {|f| } next
end end
else
if pre_post_part
new_content = [
pre_post_part.first,
DEPENDENCIES_SECTION_START_MARK,
*lines,
DEPENDENCIES_SECTION_END_MARK,
pre_post_part.last
].join
tmp_makefile = "#{makefile}.new#{$$}" tmp_makefile = "#{makefile}.new#{$$}"
File.open(tmp_makefile, 'w') {|f| f.puts lines } File.write(tmp_makefile, new_content)
File.rename tmp_makefile, makefile File.rename tmp_makefile, makefile
puts "modified: #{makefile}"
else
new_content = [
DEPENDENCIES_SECTION_START_MARK,
*lines,
DEPENDENCIES_SECTION_END_MARK,
].join
if !File.exist?(makefile)
if !lines.empty?
File.open(makefile, 'w') {|f|
f.print new_content
}
puts "created: #{makefile}"
end
else
puts "no dependencies section: #{makefile}"
(lines_original - lines).each {|line|
puts " del: #{line}"
}
(lines - lines_original).each {|line|
puts " add: #{line}"
}
end
end end
} }
end end
@ -341,7 +386,7 @@ end
def main_fix def main_fix
problems = StringIO.new problems = StringIO.new
main_show(problems) main_show(problems)
main_actual_fix(problems.read) main_actual_fix(problems.string)
end end
def run def run