From f6613be37a714a9a2a50dffc692295c0520932e0 Mon Sep 17 00:00:00 2001 From: "zbehan@chromium.org" Date: Wed, 30 Jun 2010 01:14:05 +0000 Subject: [PATCH] git-cl-upload-hook: improved finding depot_tools algorithm * also allow PATH entry to end in / (which is valid) * in case depot_tools cannot be located in PATH, search for them using which * added dependency on subprocess (new in python 2.4) M git-cl-upload-hook TEST=run the hook manually with: 1) PATH containing the depot_tools, depot_tools/ (success) 2) checkout of depot_tools into ~/x, and PATH containing that (success) 3) PATH not containing any copy of depot_tools (fail) 4) Several PATH entries containing gclient, not called depot_tools (success) Review URL: http://codereview.chromium.org/2852032 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@51207 0039d316-1c4b-4281-b951-d872f2087c98 --- git-cl-upload-hook | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/git-cl-upload-hook b/git-cl-upload-hook index 62c3addfc..ab1932037 100755 --- a/git-cl-upload-hook +++ b/git-cl-upload-hook @@ -5,18 +5,30 @@ import os import sys +from subprocess import Popen, PIPE # Try locating depot_tools from the user's PATH. depot_tools_path = None + +# First parse PATH if there's a "depot_tools" inside for path in os.environ.get("PATH").split(os.pathsep): - if not path.endswith("depot_tools"): + if not path.endswith("depot_tools") and not path.endswith("depot_tools/"): continue depot_tools_path = path break +# If depot_tools dir is not called depot_tools, or other weirdness +if not depot_tools_path: + # Grab a `which gclient', which gives first match + # `which' also uses PATH, but is not restricted to specific directory name + path = Popen(["which", "gclient"], stdout=PIPE).communicate()[0] + if path: + depot_tools_path = path.replace("/gclient","") + # If we found depot_tools, add it to the script's import path. +# Use realpath to normalize the actual path if depot_tools_path: - sys.path.append(depot_tools_path) + sys.path.append(os.path.realpath(depot_tools_path)) else: print "ERROR: Could not find depot_tools in your PATH." print "ERROR: Please add it to your PATH and try again."