4"""Small utility function to find depot_tools and add it to the python path.
5Will throw an ImportError exception if depot_tools can't be found since it
9from __future__
import print_function
14def IsRealDepotTools(path):
15 return os.path.isfile(os.path.join(path,
'gclient.py'))
18def add_depot_tools_to_path():
19 """Search for depot_tools and add it to sys.path."""
22 if i.rstrip(os.sep).endswith(
'depot_tools')
and IsRealDepotTools(i):
25 for i
in os.environ[
'PATH'].split(os.pathsep):
26 if IsRealDepotTools(i):
27 sys.path.append(i.rstrip(os.sep))
30 root_dir = os.path.dirname(os.path.abspath(__file__))
31 previous_dir = os.path.abspath(__file__)
32 while root_dir
and root_dir != previous_dir:
33 i = os.path.join(root_dir,
'depot_tools')
34 if IsRealDepotTools(i):
37 previous_dir = root_dir
38 root_dir = os.path.dirname(root_dir)
39 print(
'Failed to find depot_tools', file=sys.stderr)
43add_depot_tools_to_path()