From c88ad7af1a5c20b6788d52beb54f33203de492a8 Mon Sep 17 00:00:00 2001 From: Fumitoshi Ukai Date: Thu, 30 Jan 2025 16:57:44 -0800 Subject: [PATCH] gn_helper: handle absolute path import Bug: 393209409 Change-Id: Ic26b4502ab1744c7af7c0b06de2e4d1b9f2d3980 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6217699 Commit-Queue: Fumitoshi Ukai Reviewed-by: Takuto Ikuta Reviewed-by: Philipp Wollermann Auto-Submit: Fumitoshi Ukai Reviewed-by: Dirk Pranke --- gn_helper.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gn_helper.py b/gn_helper.py index 36aa2dbae..440d8be7e 100644 --- a/gn_helper.py +++ b/gn_helper.py @@ -34,7 +34,25 @@ def _gn_lines(output_dir, path): import_path = os.path.normpath( os.path.join(_find_root(output_dir), raw_import_path[2:])) + elif raw_import_path.startswith('/'): + # GN uses "/"-prefix as absolute path, + # https://gn.googlesource.com/gn/+/main/docs/reference.md#labels + # e.g. + # /usr/local/foo:bar + # /C:/Program Files/MyLibs:bar + # but Win32's absolute path doesn't have "/"-prefix. + if sys.platform.startswith('win32'): + import_path = raw_import_path[1:] + else: + import_path = raw_import_path + if not os.path.isabs(import_path): + raise Exception('Wrong absolute path for import %s' % + raw_import_path) else: + if os.path.isabs(raw_import_path): + raise Execption( + 'Absolute path "%s" should start with "/" in GN' % + raw_import_path) import_path = os.path.normpath( os.path.join(os.path.dirname(path), raw_import_path)) yield from _gn_lines(output_dir, import_path)