[llvm-branch-commits] [llvm] 48d1017 - [gn build] sync script: handle multiple source lists if only deleting

Nico Weber via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 25 18:02:57 PST 2020


Author: Nico Weber
Date: 2020-11-25T20:57:55-05:00
New Revision: 48d10172453511b549dfb3b46c717c60dc9786f1

URL: https://github.com/llvm/llvm-project/commit/48d10172453511b549dfb3b46c717c60dc9786f1
DIFF: https://github.com/llvm/llvm-project/commit/48d10172453511b549dfb3b46c717c60dc9786f1.diff

LOG: [gn build] sync script: handle multiple source lists if only deleting

With this, changes like b534beabeed3ba can be merged automatically.

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 ae65b50b1b55..bb57d49179ea 100755
--- a/llvm/utils/gn/build/sync_source_lists_from_cmake.py
+++ b/llvm/utils/gn/build/sync_source_lists_from_cmake.py
@@ -34,15 +34,16 @@ def patch_gn_file(gn_file, add, remove):
         tokloc = gn_contents.find(srcs_tok, tokloc + 1)
 
     if tokloc == -1: raise ValueError(gn_file + ': Failed to find source list')
-    if gn_contents.find(srcs_tok, tokloc + 1) != -1:
-        raise ValueError(gn_file + ': Multiple source lists')
-    if gn_contents.find('# NOSORT', 0, tokloc) != -1:
-        raise ValueError(gn_file + ': Found # NOSORT, needs manual merge')
-
-    tokloc += len(srcs_tok)
-    for a in add:
-        gn_contents = (gn_contents[:tokloc] + ('"%s",' % a) +
-                       gn_contents[tokloc:])
+    if add:
+        if gn_contents.find(srcs_tok, tokloc + 1) != -1:
+            raise ValueError(gn_file + ': Multiple source lists')
+        if gn_contents.find('# NOSORT', 0, tokloc) != -1:
+            raise ValueError(gn_file + ': Found # NOSORT, needs manual merge')
+
+        tokloc += len(srcs_tok)
+        for a in add:
+            gn_contents = (gn_contents[:tokloc] + ('"%s",' % a) +
+                           gn_contents[tokloc:])
     for r in remove:
         gn_contents = gn_contents.replace('"%s",' % r, '')
     with open(gn_file, 'w') as f:


        


More information about the llvm-branch-commits mailing list