| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Small utility to find depot_tools.""" | |
| 7 | |
| 8 import os | |
| 9 import sys | |
| 10 | |
| 11 | |
| 12 def _IsRealDepotTools(path): | |
| 13 return os.path.isfile(os.path.join(path, 'gclient')) | |
| 14 | |
| 15 | |
| 16 def FindDepotTools(): | |
| 17 """Search for depot_tools and return its path.""" | |
| 18 # First look if depot_tools is already in PYTHONPATH. | |
| 19 for i in sys.path: | |
| 20 if i.rstrip(os.sep).endswith('depot_tools') and _IsRealDepotTools(i): | |
| 21 return i | |
| 22 # Then look if depot_tools is in PATH, common case. | |
| 23 for i in os.environ['PATH'].split(os.pathsep): | |
| 24 if _IsRealDepotTools(i): | |
| 25 return i.rstrip(os.sep) | |
| 26 # Rare case, it's not even in PATH, look upward up to root. | |
| 27 root_dir = os.path.dirname(os.path.abspath(__file__)) | |
| 28 previous_dir = os.path.abspath(__file__) | |
| 29 while root_dir and root_dir != previous_dir: | |
| 30 i = os.path.join(root_dir, 'depot_tools') | |
| 31 if _IsRealDepotTools(i): | |
| 32 return i | |
| 33 previous_dir = root_dir | |
| 34 root_dir = os.path.dirname(root_dir) | |
| 35 return None | |
| 36 | |
| 37 | |
| 38 def main(): | |
| 39 path = FindDepotTools() | |
| 40 if not path: | |
| 41 print >> sys.stderr, 'Failed to find depot_tools' | |
| 42 return 1 | |
| 43 print path | |
| 44 return 0 | |
| 45 | |
| 46 | |
| 47 if __name__ == '__main__': | |
| 48 sys.exit(main()) | |
| OLD | NEW |