[llvm] 0bd6be9 - [gn build] Fix sync script on renames like "Foo.cpp" -> "LLVMFoo.cpp"

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 13 06:26:57 PST 2020


Author: Nico Weber
Date: 2020-02-13T09:26:47-05:00
New Revision: 0bd6be9c3da8024b4f01218afcbf6c17618066ec

URL: https://github.com/llvm/llvm-project/commit/0bd6be9c3da8024b4f01218afcbf6c17618066ec
DIFF: https://github.com/llvm/llvm-project/commit/0bd6be9c3da8024b4f01218afcbf6c17618066ec.diff

LOG: [gn build] Fix sync script on renames like "Foo.cpp" -> "LLVMFoo.cpp"

Before, the script used `git log -SFoo.cpp` to find a commit where
the number of occurrences of "Foo.cpp" changed -- but since
a patch with

  + LLVMFoo.cpp
  - Foo.cpp

contains the same number of instances of "Foo.cpp", the script
incorrectly skipped this type of rename.

As fix, look for '\bFoo\.cpp\b' instead and pass --pickaxe-regex
so that we can grep for word boundaries.

To test, check out 7531a5039fd (which renamed in llvm/lib/IR
RemarkStreamer.cpp to LLVMRemarkStreamer.cpp) and look at the output of
the script.  Before this change, it correctly assigned the addition
of LLVMRemarkStreamer.cpp to 7531a5039fd but incorrectly assigned
the removal of RemarkStreamer.cpp to b8a847c.  With this, it
correctly assigns both to 7531a5039fd.

Added: 
    

Modified: 
    llvm/utils/gn/build/sync_source_lists_from_cmake.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/build/sync_source_lists_from_cmake.py b/llvm/utils/gn/build/sync_source_lists_from_cmake.py
index f4a9933e2327..93974e660ac6 100755
--- a/llvm/utils/gn/build/sync_source_lists_from_cmake.py
+++ b/llvm/utils/gn/build/sync_source_lists_from_cmake.py
@@ -66,8 +66,12 @@ def git_out(args):
     changes_by_rev = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
 
     def find_gitrev(touched_line, in_file):
-        return git_out(
-            ['log', '--format=%h', '-1', '-S' + touched_line, in_file]).rstrip()
+        # re.escape() escapes e.g. '-', which works in practice but has
+        # undefined behavior according to the POSIX extended regex spec.
+        posix_re_escape = lambda s: re.sub(r'([.[{()\\*+?|^$])', r'\\\1', s)
+        cmd = ['log', '--format=%h', '-1', '--pickaxe-regex',
+               r'-S\<%s\>' % posix_re_escape(touched_line), in_file]
+        return git_out(cmd).rstrip()
 
     # Collect changes to gn files, grouped by revision.
     for gn_file in gn_files:


        


More information about the llvm-commits mailing list