Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2016 PDFium Authors. All rights reserved. | |
|
Lei Zhang
2016/04/18 20:58:02
IANAL, but we've copied other files from Chromium
Wei Li
2016/04/18 22:22:00
Done.
| |
| 3 # Copyright 2011 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 """Small utility function to find depot_tools and add it to the python path. | |
| 7 | |
| 8 Will throw an ImportError exception if depot_tools can't be found since it | |
| 9 imports breakpad. | |
| 10 | |
| 11 This can also be used as a standalone script to print out the depot_tools | |
| 12 directory location. | |
| 13 """ | |
| 14 | |
| 15 import os | |
| 16 import sys | |
| 17 | |
| 18 | |
| 19 def IsRealDepotTools(path): | |
| 20 return os.path.isfile(os.path.join(path, 'gclient.py')) | |
| 21 | |
| 22 | |
| 23 def add_depot_tools_to_path(): | |
| 24 """Search for depot_tools and add it to sys.path.""" | |
| 25 # First look if depot_tools is already in PYTHONPATH. | |
| 26 for i in sys.path: | |
| 27 if i.rstrip(os.sep).endswith('depot_tools') and IsRealDepotTools(i): | |
| 28 return i | |
| 29 # Then look if depot_tools is in PATH, common case. | |
| 30 for i in os.environ['PATH'].split(os.pathsep): | |
| 31 if IsRealDepotTools(i): | |
| 32 sys.path.append(i.rstrip(os.sep)) | |
| 33 return i | |
| 34 # Rare case, it's not even in PATH, look upward up to root. | |
| 35 root_dir = os.path.dirname(os.path.abspath(__file__)) | |
| 36 previous_dir = os.path.abspath(__file__) | |
| 37 while root_dir and root_dir != previous_dir: | |
| 38 i = os.path.join(root_dir, 'depot_tools') | |
| 39 if IsRealDepotTools(i): | |
| 40 sys.path.append(i) | |
| 41 return i | |
| 42 previous_dir = root_dir | |
| 43 root_dir = os.path.dirname(root_dir) | |
| 44 print >> sys.stderr, 'Failed to find depot_tools' | |
| 45 return None | |
| 46 | |
| 47 DEPOT_TOOLS_PATH = add_depot_tools_to_path() | |
| 48 | |
| 49 # pylint: disable=W0611 | |
| 50 import breakpad | |
| 51 | |
| 52 | |
| 53 def main(): | |
| 54 if DEPOT_TOOLS_PATH is None: | |
| 55 return 1 | |
| 56 print DEPOT_TOOLS_PATH | |
| 57 return 0 | |
| 58 | |
| 59 | |
| 60 if __name__ == '__main__': | |
| 61 sys.exit(main()) | |
| OLD | NEW |