[gn build] minor tweaks to sync script
authorNico Weber <thakis@chromium.org>
Tue, 31 Mar 2020 02:07:23 +0000 (22:07 -0400)
committerNico Weber <thakis@chromium.org>
Tue, 31 Mar 2020 02:07:23 +0000 (22:07 -0400)
- only complain about duplicate 'sources' lines if they contain
  more than 1 elements each (before, 0 and 1 element lists were
  counted too). In practice, this only has an effect for
  clang/lib/Headers/BUILD.gn

- make the '# NOSORT' diag actually work. This too only affects
  clang/lib/Headers/BUILD.gn.

In aggregate, changes to clang/lib/Headers/BUILD.gn still can't
be auto-merged, but for a slighly better reason.

llvm/utils/gn/build/sync_source_lists_from_cmake.py

index 0b13a8a..46a779e 100755 (executable)
@@ -27,13 +27,13 @@ def patch_gn_file(gn_file, add, remove):
     with open(gn_file) as f:
         gn_contents = f.read()
 
-    srcs_tok = 'sources = ['
+    srcs_tok = 'sources = [\n'
     tokloc = gn_contents.find(srcs_tok)
 
     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_file.find('# NOSORT', 0, tokloc) != -1:
+    if gn_contents.find('# NOSORT', 0, tokloc) != -1:
         raise ValueError(gn_file + ': Found # NOSORT, needs manual merge')
 
     tokloc += len(srcs_tok)