1# Copyright (c) 2019 Refael Ackeramnn<refack@gmail.com>. All rights reserved. 2# Use of this source code is governed by an MIT-style license. 3import re 4import os 5 6PLAIN_SOURCE_RE = re.compile(r'\s*"([^/$].+)"\s*') 7def DoMain(args): 8 gn_filename, pattern = args 9 src_root = os.path.dirname(gn_filename) 10 with open(gn_filename, 'rb') as gn_file: 11 gn_content = gn_file.read().decode('utf-8') 12 13 scraper_re = re.compile(pattern + r'\[([^\]]+)', re.DOTALL) 14 matches = scraper_re.search(gn_content) 15 match = matches.group(1) 16 files = [] 17 for l in match.splitlines(): 18 m2 = PLAIN_SOURCE_RE.match(l) 19 if not m2: 20 continue 21 files.append(m2.group(1)) 22 # always use `/` since GYP will process paths further downstream 23 rel_files = ['"%s/%s"' % (src_root, f) for f in files] 24 return ' '.join(rel_files) 25