0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
nodejs/tools/v8_gypfiles/GN-scraper.py
Christian Clauss 6afd1a3dc1 tools: fix mixup with bytes.decode() and str.encode()
We want to read a bytes file and decode the contents as utf-8 so we can
compare against a utf-8 pattern.

PR-URL: https://github.com/nodejs/node/pull/29208
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-08-21 22:16:59 -07:00

25 lines
816 B
Python

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