1
0
mirror of https://github.com/facebook/proxygen.git synced 2025-08-07 07:02:53 +03:00

fail if unknown variables are used in a manifest

Summary:
Check that all variable names are valid when loading manifest files.
This ensures that getdeps.py will error out if someone makes a typo in a
variable name, rather than treating it as never equal to anything.

Reviewed By: pkaush

Differential Revision: D16477397

fbshipit-source-id: 030e0642ff4a08db8eb74a0a0223e03d53e4880f
This commit is contained in:
Adam Simpkins
2019-07-31 20:53:07 -07:00
committed by Facebook Github Bot
parent 55fb767d25
commit 7844e79b03
4 changed files with 31 additions and 16 deletions

View File

@@ -12,7 +12,7 @@ import re
import shlex
def parse_expr(expr_text):
def parse_expr(expr_text, valid_variables):
""" parses the simple criteria expression syntax used in
dependency specifications.
Returns an ExprNode instance that can be evaluated like this:
@@ -37,7 +37,7 @@ def parse_expr(expr_text):
# none of them evaluated true.
"""
p = Parser(expr_text)
p = Parser(expr_text, valid_variables)
return p.parse()
@@ -112,9 +112,10 @@ class EqualExpr(ExprNode):
class Parser(object):
def __init__(self, text):
def __init__(self, text, valid_variables):
self.text = text
self.lex = shlex.shlex(text)
self.valid_variables = valid_variables
def parse(self):
expr = self.top()
@@ -141,6 +142,8 @@ class Parser(object):
return func()
if op == "=":
if name not in self.valid_variables:
raise Exception("unknown variable %r in expression" % (name,))
return EqualExpr(name, self.lex.get_token())
raise Exception(