MCPcopy Create free account
hub / github.com/nodejs/node / EvalSingleCondition

Function EvalSingleCondition

tools/gyp/pylib/gyp/input.py:1157–1197  ·  view source on GitHub ↗

Returns true_dict if cond_expr evaluates to true, and false_dict otherwise.

(cond_expr, true_dict, false_dict, phase, variables, build_file)

Source from the content-addressed store, hash-verified

1155
1156
1157def EvalSingleCondition(cond_expr, true_dict, false_dict, phase, variables, build_file):
1158 """Returns true_dict if cond_expr evaluates to true, and false_dict
1159 otherwise."""
1160 # Do expansions on the condition itself. Since the condition can naturally
1161 # contain variable references without needing to resort to GYP expansion
1162 # syntax, this is of dubious value for variables, but someone might want to
1163 # use a command expansion directly inside a condition.
1164 cond_expr_expanded = ExpandVariables(cond_expr, phase, variables, build_file)
1165 if type(cond_expr_expanded) not in (str, int):
1166 raise ValueError(
1167 "Variable expansion in this context permits str and int "
1168 + "only, found "
1169 + cond_expr_expanded.__class__.__name__
1170 )
1171
1172 try:
1173 if cond_expr_expanded in cached_conditions_asts:
1174 ast_code = cached_conditions_asts[cond_expr_expanded]
1175 else:
1176 ast_code = compile(cond_expr_expanded, "<string>", "eval")
1177 cached_conditions_asts[cond_expr_expanded] = ast_code
1178 env = {"__builtins__": {}, "v": Version}
1179 if eval(ast_code, env, variables):
1180 return true_dict
1181 return false_dict
1182 except SyntaxError as e:
1183 syntax_error = SyntaxError(
1184 "%s while evaluating condition '%s' in %s "
1185 "at character %d." % (str(e.args[0]), e.text, build_file, e.offset),
1186 e.filename,
1187 e.lineno,
1188 e.offset,
1189 e.text,
1190 )
1191 raise syntax_error
1192 except NameError as e:
1193 gyp.common.ExceptionAppend(
1194 e,
1195 f"while evaluating condition '{cond_expr_expanded}' in {build_file}",
1196 )
1197 raise GypError(e)
1198
1199
1200def ProcessConditionsInDict(the_dict, phase, variables, build_file):

Callers 1

EvalConditionFunction · 0.85

Calls 6

GypErrorClass · 0.90
ExpandVariablesFunction · 0.85
compileFunction · 0.85
strFunction · 0.85
typeFunction · 0.50
evalFunction · 0.50

Tested by

no test coverage detected