11cb0ef41Sopenharmony_ci# Copyright (c) 2019 Refael Ackeramnn<refack@gmail.com>. All rights reserved. 21cb0ef41Sopenharmony_ci# Use of this source code is governed by an MIT-style license. 31cb0ef41Sopenharmony_ciimport re 41cb0ef41Sopenharmony_ciimport os 51cb0ef41Sopenharmony_ciimport sys 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciPLAIN_SOURCE_RE = re.compile('\s*"([^/$].+)"\s*') 81cb0ef41Sopenharmony_cidef DoMain(args): 91cb0ef41Sopenharmony_ci gn_filename, pattern = args 101cb0ef41Sopenharmony_ci src_root = os.path.dirname(gn_filename) 111cb0ef41Sopenharmony_ci with open(gn_filename, 'rb') as gn_file: 121cb0ef41Sopenharmony_ci gn_content = gn_file.read().decode('utf-8') 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci scraper_re = re.compile(pattern + r'\[([^\]]+)', re.DOTALL) 151cb0ef41Sopenharmony_ci matches = scraper_re.search(gn_content) 161cb0ef41Sopenharmony_ci match = matches.group(1) 171cb0ef41Sopenharmony_ci files = [] 181cb0ef41Sopenharmony_ci for l in match.splitlines(): 191cb0ef41Sopenharmony_ci m2 = PLAIN_SOURCE_RE.match(l) 201cb0ef41Sopenharmony_ci if not m2: 211cb0ef41Sopenharmony_ci continue 221cb0ef41Sopenharmony_ci files.append(m2.group(1)) 231cb0ef41Sopenharmony_ci # always use `/` since GYP will process paths further downstream 241cb0ef41Sopenharmony_ci rel_files = ['"%s/%s"' % (src_root, f) for f in files] 251cb0ef41Sopenharmony_ci return ' '.join(rel_files) 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciif __name__ == '__main__': 281cb0ef41Sopenharmony_ci print(DoMain(sys.argv[1:])) 29