Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2616528rdb; Mon, 4 Dec 2023 02:42:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHftKns9E493mrCF2x2prbk9EnGZLQ9utJMwNEf0opDZjmhGzZbzUeoU1v8mEI0pnPjdSMB X-Received: by 2002:a17:902:c40d:b0:1cf:d19e:fae with SMTP id k13-20020a170902c40d00b001cfd19e0faemr4348769plk.34.1701686570120; Mon, 04 Dec 2023 02:42:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701686570; cv=none; d=google.com; s=arc-20160816; b=MR3rE6ci9Fze6MTTiubixtwUkJFu6CYPITlVY8hzIo+rRIAcnSAD4ZWY7TljFqP4gO WZ8DYRTz62o+6Q9OOCqHba03Ki9SJ3AQhXXS4UJDvmIUjd2wJbCr/QqFyNOpR7PxOeOo xqbTIkp6mxB4kfZuXu3MjW1AQycnC/DtHPiIx3jM8wIR8goMV8dFijX10jdW4qXRR5Fh 6SHU3BjnQlPaGo9H+wBcRB7HFsHGgUkRJ/47ITbQN6/OJ1/OUEPfHsPHpdMK6p7ztOMC qtL/Ji8doD4sgsUE5gWjztqYls07lJxZ3EngKAHZ9ajOwT9tujA89UKKrCaa2IHXnaBD exjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=KYbcAarfiXKgLRpNK9U9BhBRwOXHWsWfyQvim+Dz8m4=; fh=lXBO2FScL5RCyEXeb++fQ3IlGPbZSJDK7v6HDtPvlXg=; b=WtbhM8uMNXRgwzqJK+3F6gJ96jtxSZfKKitmwOl0zShY31Vp+w7mL02//CQ0EbGYrf V4djLcghstgDD1e8FxuutWxXfRoUwrVqUXfyKd47eyymy1PPtf0A07iEltN/66i3/DcM oLtMmsxbqEXRbZLL5+hbP5+xFr4T+i4XP8QKdmL7bt0/lCy/IJ5i+er+9uGP3nNInOXe ChQkGT0IIr4NgJktn2y7q74XpdG1B8rLLz74IeK1uw2aW4P020qsJr42jXbPx7/iT2fM kJ8sJCb3yl6WKa+O8GM5OcpqYPsfS0OQZGzmMWGHLZiLfZf9HBfMMeedbe3VyCsKJA0w x8Rg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id n9-20020a170902e54900b001d078e31ca8si3299546plf.293.2023.12.04.02.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 02:42:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9351B805DC64; Mon, 4 Dec 2023 02:42:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235365AbjLDKmY (ORCPT + 99 others); Mon, 4 Dec 2023 05:42:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235338AbjLDKmW (ORCPT ); Mon, 4 Dec 2023 05:42:22 -0500 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72AE4D5 for ; Mon, 4 Dec 2023 02:42:28 -0800 (PST) X-QQ-mid: bizesmtp90t1701686533t9w18dy6 Received: from localhost.localdomain ( [112.6.196.165]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 04 Dec 2023 18:42:10 +0800 (CST) X-QQ-SSF: 01200000000000B0J000000A0000000 X-QQ-FEAT: ZdHcY4j9T+I4a9YN8Gv8XPmWt4O1cvJndJZZex7Xb7xsJrCqjKY4egbNCxmRi D96ArEymkCRQjw6F64Nbn5aVHKh4RDRQYSo68gXBQow0mmylNPEGaFP0ngOh5JbocUGQBzS 5RjS4vS66FL7R9Qa7l9O/U5Ad1YI23Nzp6Wrq+wupOg5Lg6uFyO0JCq7SshpgwILAXdxmj2 GsNDkCpQRnTr0V4l/pjeMVCOKyA3NoesngcY7+oebuOaVC+p/kpVzKKB640LD6BSf3ZGWXt eJQv9Zelnt554Ope6Ynn81h2AQ/KzctOJorfg6gZXmTPGmyHm9s+ejA8JTpXziUBmAsdw28 OQ+B2ngRHObnR14Md0= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 72683575249682803 From: Jialu Xu To: nathan@kernel.org, ndesaulniers@google.com, morbo@google.com, justinstitt@google.com Cc: llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Jialu Xu Subject: [PATCH] gen_compile_commands.py: fix path resolve with symlinks in it Date: Mon, 4 Dec 2023 18:41:42 +0800 Message-Id: <20231204104141.3618547-1-xujialu@vimux.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:vimux.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 02:42:47 -0800 (PST) When symbolic links are involved in the path, os.path.abspath might not resolve the symlinks and instead return the absolute path with the symlinks intact. use pathlib.Path resolve() instead of os.path.abspath() Signed-off-by: Jialu Xu --- scripts/clang-tools/gen_compile_commands.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/clang-tools/gen_compile_commands.py b/scripts/clang-tools/gen_compile_commands.py index 180952fb91c1b..0a6c0996b4a8f 100755 --- a/scripts/clang-tools/gen_compile_commands.py +++ b/scripts/clang-tools/gen_compile_commands.py @@ -11,6 +11,7 @@ import argparse import json import logging import os +from pathlib import Path import re import subprocess import sys @@ -172,8 +173,8 @@ def process_line(root_directory, command_prefix, file_path): # by Make, so this code replaces the escaped version with '#'. prefix = command_prefix.replace('\#', '#').replace('$(pound)', '#') - # Use os.path.abspath() to normalize the path resolving '.' and '..' . - abs_path = os.path.abspath(os.path.join(root_directory, file_path)) + # Make the path absolute, resolving all symlinks on the way and also normalizing it. + abs_path = str(Path(os.path.join(root_directory, file_path)).resolve()) if not os.path.exists(abs_path): raise ValueError('File %s not found' % abs_path) return { -- 2.39.2