blob: 1c34fea6f6c6e1fd5aa8b7f48311502477397d42 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001#!/usr/bin/env python
2# Copyright (c) 2011 The Chromium 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"""Small utility function to find depot_tools and add it to the python path.
6
7Will throw an ImportError exception if depot_tools can't be found since it
8imports breakpad.
9
10This can also be used as a standalone script to print out the depot_tools
11directory location.
12"""
13
14import os
15import sys
16
17
18def IsRealDepotTools(path):
19 return os.path.isfile(os.path.join(path, 'gclient.py'))
20
21
22def add_depot_tools_to_path():
23 """Search for depot_tools and add it to sys.path."""
24 # First look if depot_tools is already in PYTHONPATH.
25 for i in sys.path:
26 if i.rstrip(os.sep).endswith('depot_tools') and IsRealDepotTools(i):
27 return i
28 # Then look if depot_tools is in PATH, common case.
29 for i in os.environ['PATH'].split(os.pathsep):
30 if IsRealDepotTools(i):
31 sys.path.append(i.rstrip(os.sep))
32 return i
33 # Rare case, it's not even in PATH, look upward up to root.
34 root_dir = os.path.dirname(os.path.abspath(__file__))
35 previous_dir = os.path.abspath(__file__)
36 while root_dir and root_dir != previous_dir:
37 i = os.path.join(root_dir, 'depot_tools')
38 if IsRealDepotTools(i):
39 sys.path.append(i)
40 return i
41 previous_dir = root_dir
42 root_dir = os.path.dirname(root_dir)
43 print >> sys.stderr, 'Failed to find depot_tools'
44 return None
45
46DEPOT_TOOLS_PATH = add_depot_tools_to_path()
47
48# pylint: disable=W0611
49import breakpad
50
51
52def main():
53 if DEPOT_TOOLS_PATH is None:
54 return 1
55 print DEPOT_TOOLS_PATH
56 return 0
57
58
59if __name__ == '__main__':
60 sys.exit(main())