gclient: resolve symlink in gclient_entries before checking with current path

This allows repo to be symlinked in the workspace and gclient config is
pointing to the symlink. For example, if repo is checked out at
`${WS}/chromium`, a symlink is created from `${WS}/src` and ${WS}/.gclient 
is pointing to `${WS}/src`, when the code is trying to determine the
gclient root with cwd=`${WS}/chromium/XXX/XXX`, the code won't treat ${WS}
as the workspace root. Because .gclient_entries all started with `src/`
and `${WS}/chromium/XXX/XXX` won't match anything in .gclient_entries.

The fix here is to calculate the realpath (i.e. resolving the symlink)
for all paths in .gclient_entries and path_to_check before comparison.

Change-Id: I914ba5a7131588fa99d6900ada954f3694dda197
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5656593
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
changes/93/5656593/3
Yiwei Zhang 10 months ago committed by LUCI CQ
parent 7e547050e8
commit e6f497f72b

@ -57,8 +57,12 @@ def FindGclientRoot(from_dir, filename='.gclient'):
except (SyntaxError, Exception) as e:
gclient_utils.SyntaxErrorToError(filename, e)
all_directories = scope['entries'].keys()
path_to_check = os.path.relpath(real_from_dir, path)
all_directories = set(
os.path.relpath(os.path.realpath(os.path.join(path, *k.split('/'))),
start=os.path.realpath(path))
for k in scope['entries'].keys())
path_to_check = os.path.relpath(os.path.realpath(real_from_dir),
start=os.path.realpath(path))
while path_to_check:
if path_to_check in all_directories:
return path

Loading…
Cancel
Save