From e6f497f72bb89c2c5fcd06be2c87ac6033491679 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 26 Jun 2024 16:15:53 +0000 Subject: [PATCH] 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 Commit-Queue: Gavin Mak --- gclient_paths.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gclient_paths.py b/gclient_paths.py index 3e4522a5a2..dc66094116 100644 --- a/gclient_paths.py +++ b/gclient_paths.py @@ -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