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)