[gn build] sync script: try to make a loop clearer
authorNico Weber <thakis@chromium.org>
Thu, 26 Nov 2020 02:11:50 +0000 (21:11 -0500)
committerNico Weber <thakis@chromium.org>
Thu, 26 Nov 2020 02:16:22 +0000 (21:16 -0500)
We want to find 'sources = [', but only if it's not the prefix
of 'sources = []' -- we're looking for a non-empty list.

No behavior change.

llvm/utils/gn/build/sync_source_lists_from_cmake.py

index 5c96fd7..912cf37 100755 (executable)
@@ -29,8 +29,7 @@ def patch_gn_file(gn_file, add, remove):
     if add:
         srcs_tok = 'sources = ['
         tokloc = gn_contents.find(srcs_tok)
-        while tokloc != -1 and tokloc + len(srcs_tok) < len(gn_contents) and \
-                gn_contents[tokloc + len(srcs_tok)] == ']':
+        while gn_contents[tokloc:].startswith('sources = []'):
             tokloc = gn_contents.find(srcs_tok, tokloc + 1)
         if tokloc == -1: raise ValueError(gn_file + ': No source list')
         if gn_contents.find(srcs_tok, tokloc + 1) != -1: