[llvm] 12c2646 - [gn build] sync script: only compute tokloc when adding files
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 25 18:19:32 PST 2020
Author: Nico Weber
Date: 2020-11-25T21:05:13-05:00
New Revision: 12c2646feb10c3aa14f590bcf9f5a3f9fc7b41b7
URL: https://github.com/llvm/llvm-project/commit/12c2646feb10c3aa14f590bcf9f5a3f9fc7b41b7
DIFF: https://github.com/llvm/llvm-project/commit/12c2646feb10c3aa14f590bcf9f5a3f9fc7b41b7.diff
LOG: [gn build] sync script: only compute tokloc when adding files
No behavior change, but maybe a bit clearer.
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 bb57d49179ea..5c96fd7263f4 100755
--- a/llvm/utils/gn/build/sync_source_lists_from_cmake.py
+++ b/llvm/utils/gn/build/sync_source_lists_from_cmake.py
@@ -26,20 +26,17 @@
def patch_gn_file(gn_file, add, remove):
with open(gn_file) as f:
gn_contents = f.read()
-
- 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)] == ']':
- tokloc = gn_contents.find(srcs_tok, tokloc + 1)
-
- if tokloc == -1: raise ValueError(gn_file + ': Failed to find source list')
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)] == ']':
+ 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:
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) +
More information about the llvm-commits
mailing list