summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtool/update-deps77
1 files changed, 61 insertions, 16 deletions
diff --git a/tool/update-deps b/tool/update-deps
index 29f233b40a..8e27f8a510 100755
--- a/tool/update-deps
+++ b/tool/update-deps
@@ -257,7 +257,8 @@ def compare_deps(make_deps, actual_deps, out=$stdout)
rescue Errno::ENOENT
[]
end
- depline = "#{target2}: #{source2} \# #{target}: #{source}\n"
+ #depline = "#{target2}: #{source2} \# #{target}: #{source}\n"
+ depline = "#{target2}: #{source2}\n"
if !make_sources.include?(source)
out.puts "add #{makefile} : #{depline}"
elsif !actual_sources.include?(source)
@@ -298,42 +299,86 @@ def extract_deplines(problems)
dels = {}
problems.each_line {|line|
case line
- when /\Aadd (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/
+ when /\Aadd (\S+) : (\S.*\n)\z/
(adds[$1] ||= []) << $2
- when /\AdelL (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/
+ when /\AdelL (\S+) : (\S.*\n)\z/
(dels[$1] ||= []) << $2
- when /\AdelP (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/
+ when /\AdelP (\S+) : (\S.*\n)\z/
(dels[$1] ||= []) << $2
- when /\AokL (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/
- when /\AokP (\S+) : (\S+: \S+ \# \S+: \S+\n)\z/
+ when /\AokL (\S+) : (\S.*\n)\z/
+ when /\AokP (\S+) : (\S.*\n)\z/
(adds[$1] ||= []) << $2
end
}
return adds, dels
end
+DEPENDENCIES_SECTION_START_MARK = "\# AUTOGENERATED DEPENDENCIES START\n"
+DEPENDENCIES_SECTION_END_MARK = "\# AUTOGENERATED DEPENDENCIES END\n"
+
def main_actual_fix(problems)
adds, dels = extract_deplines(problems)
(adds.keys | dels.keys).sort.each {|makefile|
- lines = begin
- File.readlines(makefile)
+ content = begin
+ File.read(makefile)
rescue Errno::ENOENT
- []
+ ''
+ 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]
lines -= dels[makefile]
end
if adds[makefile]
lines.concat(adds[makefile] - lines)
end
- if lines.empty?
- if File.exist? makefile
- File.open(makefile, 'w') {|f| }
- end
- else
+
+ if lines == lines_original
+ next
+ end
+
+ 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#{$$}"
- File.open(tmp_makefile, 'w') {|f| f.puts lines }
+ File.write(tmp_makefile, new_content)
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
@@ -341,7 +386,7 @@ end
def main_fix
problems = StringIO.new
main_show(problems)
- main_actual_fix(problems.read)
+ main_actual_fix(problems.string)
end
def run