Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: depot_tools/gclient_utils.py

Issue 3342020: Do not blindly assume that a .gclient file in a parent directory belongs to t... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | depot_tools/tests/gclient_smoketest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: depot_tools/gclient_utils.py
===================================================================
--- depot_tools/gclient_utils.py (revision 58680)
+++ depot_tools/gclient_utils.py (working copy)
@@ -336,12 +336,39 @@
def FindGclientRoot(from_dir, filename='.gclient'):
"""Tries to find the gclient root."""
- path = os.path.realpath(from_dir)
+ real_from_dir = os.path.realpath(from_dir)
+ path = real_from_dir
while not os.path.exists(os.path.join(path, filename)):
split_path = os.path.split(path)
if not split_path[1]:
return None
path = split_path[0]
+
+ # If we did not find the file in the current directory, make sure we are in a
+ # sub directory that is controlled by this configuration.
+ if path != real_from_dir:
+ entries_filename = os.path.join(path, filename + '_entries')
+ if not os.path.exists(entries_filename):
+ # If .gclient_entries does not exist, a previous call to gclient sync
+ # might have failed. In that case, we cannot verify that the .gclient
+ # is the one we want to use. In order to not to cause too much trouble,
+ # just issue a warning and return the path anyway.
+ print >>sys.stderr, ("%s file in parent directory %s might not be the "
+ "file you want to use" % (filename, path))
+ return path
+ scope = {}
+ try:
+ exec(FileRead(entries_filename), scope)
+ except SyntaxError, e:
+ SyntaxErrorToError(filename, e)
+ all_directories = scope['entries'].keys()
+ path_to_check = real_from_dir[len(path)+1:]
+ while path_to_check:
+ if path_to_check in all_directories:
+ return path
+ path_to_check = os.path.dirname(path_to_check)
+ return None
+
logging.info('Found gclient root at ' + path)
return path
« no previous file with comments | « no previous file | depot_tools/tests/gclient_smoketest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698