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) +