Skip to content

Commit

Permalink
git-cl-upload-hook: improved finding depot_tools algorithm
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
[email protected] committed Jun 30, 2010
1 parent 3fda4cc commit f6613be
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions git-cl-upload-hook
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit f6613be

Please sign in to comment.