From 48d10172453511b549dfb3b46c717c60dc9786f1 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 25 Nov 2020 20:56:03 -0500 Subject: [PATCH] [gn build] sync script: handle multiple source lists if only deleting With this, changes like b534beabeed3ba can be merged automatically. --- llvm/utils/gn/build/sync_source_lists_from_cmake.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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 ae65b50..bb57d49 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: -- 2.7.4