1# Copyright (c) 2011 The Chromium Embedded Framework Authors. 2# Portions 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 6from __future__ import absolute_import 7from __future__ import print_function 8import os, sys 9 10try: 11 # depot_tools may already be in the import path. 12 import gclient_utils 13except ImportError as e: 14 # Search the PATH environment variable to find the depot_tools folder. 15 depot_tools = None 16 paths = os.environ.get('PATH').split(os.pathsep) 17 for path in paths: 18 if os.path.exists(os.path.join(path, 'gclient_utils.py')): 19 depot_tools = path 20 break 21 22 if depot_tools is None: 23 print('Error: could not find depot_tools in PATH.', file=sys.stderr) 24 sys.exit(2) 25 26 # Add depot_tools to import path. 27 sys.path.append(depot_tools) 28 import gclient_utils 29 30 31# Copied from gclient.py python code. 32def RunAction(dir, command): 33 """Runs the action.""" 34 try: 35 gclient_utils.CheckCallAndFilter( 36 command, cwd=dir, always_show_header=True, print_stdout=True) 37 except gclient_utils.Error as e: 38 # Use a discrete exit status code of 2 to indicate that a hook action 39 # failed. Users of this script may wish to treat hook action failures 40 # differently from VC failures. 41 print('Error: %s' % str(e), file=sys.stderr) 42 sys.exit(2) 43