[前][次][番号順一覧][スレッド一覧]

ruby-changes:36362

From: akr <ko1@a...>
Date: Sat, 15 Nov 2014 20:31:25 +0900 (JST)
Subject: [ruby-changes:36362] akr:r48443 (trunk): Modify parts only marked as autogenerated.

akr	2014-11-15 20:30:59 +0900 (Sat, 15 Nov 2014)

  New Revision: 48443

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48443

  Log:
    Modify parts only marked as autogenerated.

  Modified files:
    trunk/tool/update-deps
Index: tool/update-deps
===================================================================
--- tool/update-deps	(revision 48442)
+++ tool/update-deps	(revision 48443)
@@ -257,7 +257,8 @@ def compare_deps(make_deps, actual_deps, https://github.com/ruby/ruby/blob/trunk/tool/update-deps#L257
         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) https://github.com/ruby/ruby/blob/trunk/tool/update-deps#L299
   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 https://github.com/ruby/ruby/blob/trunk/tool/update-deps#L386
 def main_fix
   problems = StringIO.new
   main_show(problems)
-  main_actual_fix(problems.read)
+  main_actual_fix(problems.string)
 end
 
 def run

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]