| Index: pipa/py/gitdeps.py
|
| diff --git a/pipa/build/gitdeps.py b/pipa/py/gitdeps.py
|
| similarity index 92%
|
| rename from pipa/build/gitdeps.py
|
| rename to pipa/py/gitdeps.py
|
| index 0d97843e768eae5944ea5ce420a6a1f82fd7d5af..fddaef58b3e7c0fe900aeb7d73de6267ca3a028e 100644
|
| --- a/pipa/build/gitdeps.py
|
| +++ b/pipa/py/gitdeps.py
|
| @@ -54,6 +54,7 @@ import re
|
| import subprocess
|
| import threading
|
|
|
| +import deps_utils
|
|
|
| _LOGGER = logging.getLogger(os.path.basename(__file__))
|
|
|
| @@ -630,77 +631,6 @@ def _RecurseRepository(options, repo):
|
| _Shell('gclient', 'sync', cwd=repo.checkout_dir, dry_run=options.dry_run)
|
|
|
|
|
| -def _FindGlobalVariableInAstTree(tree, name, functions=None):
|
| - """Finds and evaluates to global assignment of the variables |name| in the
|
| - AST |tree|. Will allow the evaluations of some functions as defined in
|
| - |functions|.
|
| - """
|
| - if functions is None:
|
| - functions = {}
|
| -
|
| - class FunctionEvaluator(ast.NodeTransformer):
|
| - """A tree transformer that evaluates permitted functions."""
|
| -
|
| - def visit_BinOp(self, binop_node):
|
| - """Is called for BinOp nodes. We only support string additions."""
|
| - if type(binop_node.op) != ast.Add:
|
| - return binop_node
|
| - left = ast.literal_eval(self.visit(binop_node.left))
|
| - right = ast.literal_eval(self.visit(binop_node.right))
|
| - value = left + right
|
| - new_node = ast.Str(s=value)
|
| - new_node = ast.copy_location(new_node, binop_node)
|
| - return new_node
|
| -
|
| - def visit_Call(self, call_node):
|
| - """Evaluates function calls that return a single string as output."""
|
| - func_name = call_node.func.id
|
| - if func_name not in functions:
|
| - return call_node
|
| - func = functions[func_name]
|
| -
|
| - # Evaluate the arguments. We don't care about starargs, keywords or
|
| - # kwargs.
|
| - args = [ast.literal_eval(self.visit(arg)) for arg in
|
| - call_node.args]
|
| -
|
| - # Now evaluate the function.
|
| - value = func(*args)
|
| - new_node = ast.Str(s=value)
|
| - new_node = ast.copy_location(new_node, call_node)
|
| - return new_node
|
| -
|
| - # Look for assignment nodes.
|
| - for node in tree.body:
|
| - if type(node) != ast.Assign:
|
| - continue
|
| - # Look for assignment in the 'store' context, to a variable with
|
| - # the given name.
|
| - for target in node.targets:
|
| - if type(target) != ast.Name:
|
| - continue
|
| - if type(target.ctx) != ast.Store:
|
| - continue
|
| - if target.id == name:
|
| - value = FunctionEvaluator().visit(node.value)
|
| - value = ast.fix_missing_locations(value)
|
| - value = ast.literal_eval(value)
|
| - return value
|
| -
|
| -
|
| -def _ParseDepsFile(path):
|
| - """Parsed a DEPS-like file at the given |path|."""
|
| - # Utility function for performing variable expansions.
|
| - vars_dict = {}
|
| - def _Var(s):
|
| - return vars_dict[s]
|
| -
|
| - contents = open(path, 'rb').read()
|
| - tree = ast.parse(contents, path)
|
| - vars_dict = _FindGlobalVariableInAstTree(tree, 'vars')
|
| - deps_dict = _FindGlobalVariableInAstTree(
|
| - tree, 'deps', functions={'Var': _Var})
|
| - return deps_dict
|
|
|
|
|
| def _RemoveFile(options, path):
|
| @@ -874,7 +804,7 @@ def main():
|
| output_dirs = {}
|
| all_deps = []
|
| for deps_file in args:
|
| - deps = _ParseDepsFile(deps_file)
|
| + deps = deps_utils.ParseDepsFile(deps_file)
|
| for key, value in deps.iteritems():
|
| repo_options = _ParseRepoOptions(
|
| options.cache_dir, options.output_dir, deps_file, key, value)
|
|
|