Commit b52227fd authored by Ben Pastene's avatar Ben Pastene Committed by Commit Bot

gn_helpers: Allow the checkout root to be passed in.

Will be used by clients that have a vendored copy of the lib:
https://source.chromium.org/chromiumos/chromiumos/codesearch/+/master:chromite/third_party/gn_helpers/

Bug: 937821
Change-Id: I6f2380fe60fe5bdc661bcbf7947bf3e221011e9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225264
Commit-Queue: Ben Pastene <bpastene@chromium.org>
Reviewed-by: default avatarTakuto Ikuta <tikuta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773877}
parent 0af7d7aa
......@@ -25,6 +25,8 @@ import re
import sys
_CHROMIUM_ROOT = os.path.join(os.path.dirname(__file__), os.pardir)
IMPORT_RE = re.compile(r'^import\("//(\S+)"\)')
......@@ -182,9 +184,11 @@ class GNValueParser(object):
If you expect input as a specific type, you can also call one of the Parse*
functions directly. All functions throw GNError on invalid input.
"""
def __init__(self, string):
def __init__(self, string, checkout_root=_CHROMIUM_ROOT):
self.input = string
self.cur = 0
self.checkout_root = checkout_root
def IsDone(self):
return self.cur == len(self.input)
......@@ -204,8 +208,7 @@ class GNValueParser(object):
regex_match = IMPORT_RE.match(line)
if not regex_match:
raise GNError('Not a valid import string: %s' % line)
import_path = os.path.join(
os.path.dirname(__file__), os.pardir, regex_match.group(1))
import_path = os.path.join(self.checkout_root, regex_match.group(1))
with open(import_path) as f:
imported_args = f.read()
self.input = self.input.replace(line, imported_args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment