Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp13989rdb; Mon, 4 Dec 2023 18:17:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgNJyzTJD/7Oj9aA6t3juy537G0zpEmiYCv8A2u6RzsqU8GPOqL+DRkGhC23TIz7IvWGiV X-Received: by 2002:a05:6a00:18a4:b0:6cd:8436:dfc with SMTP id x36-20020a056a0018a400b006cd84360dfcmr736581pfh.12.1701742660831; Mon, 04 Dec 2023 18:17:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701742660; cv=none; d=google.com; s=arc-20160816; b=Wkj/4s5UiZwq+kAjgpoE3sFnpJxFHGTCdwKUC2vRu8niT4HWSG+QraLZ9tZVdn8o4C EUbpSi+FwEG0UXNBoXmYttcJ3Vdy2eNE6JH4gD5PQUWbSLMXYt6swonJqVyQSD0e7phs wAaxlxmV/XjRX1QD4emNmlTl08M+EQPSGRV3SXKKwIcAI2sppN5r/8O+MZl5kwKN0tq7 o2x3HIzFdZcckM3a95mjYrQ0yQ2agIWf1eGA/z3PlOhJ6i1326YZq/MM3u3XRyLhzfTs ZBE0OMqEQpysuIqYcBzLNM83xWjcmX5JFTF6Hsu5QyecApvMR+vrw9MU+fGBlWt6W0GS jxqg== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=7pFDts8RX9/cj8ztOsbf3etLaiNPCFABpu+CshzaRLo=; fh=lXBO2FScL5RCyEXeb++fQ3IlGPbZSJDK7v6HDtPvlXg=; b=qJTCVcokoE8Y95XOVpQZ3LlVVxG10VHPWyJmDuROYGxzVbTJlARp8y1LJcMEohMDp4 vxdOIdMmBfRNXQ3H7eYFch0Otpw6+WSDmjZkNR5eVOBg0yL/Ch6NpWrMwq27itSzVjZT yak/JLWtCF8APaww+PCZPtFXKz5LGP8PJGJr2Be4B787Svx2kxexJX2BkrMPsgwAOfQt Kh1Aw9FuFNmNwE7G0MNWUiVtJM4wCjnJojk1ql+r3SnUyct430OaEl8LzVBpept5iq2c 5XDsDgKCcv3L4g4dzwcmewTAgMZfRkModGlwG6lTK+c2yaS+efsbDdy+uUMBt7R/tZ5m aR9g== 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:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u23-20020a056a00099700b006cdd83f45c0si8808526pfg.229.2023.12.04.18.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:17:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 9989D804C210; Mon, 4 Dec 2023 18:17:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231860AbjLECRZ (ORCPT + 99 others); Mon, 4 Dec 2023 21:17:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbjLECRY (ORCPT ); Mon, 4 Dec 2023 21:17:24 -0500 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 068D2107 for ; Mon, 4 Dec 2023 18:17:29 -0800 (PST) X-QQ-mid: bizesmtp73t1701742630tlxdw301 Received: from localhost.localdomain ( [219.147.26.62]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 05 Dec 2023 10:16:14 +0800 (CST) X-QQ-SSF: 01200000000000B0J000000A0000000 X-QQ-FEAT: k0mQ4ihyJQPgishzlGfWTZNfXN6f40onPWxHaDYCN1gveOrb8wvY1GV2C3fmO FdH3zNbGQFzov4jkdI7bl6fKtjXLTUgRvFuqAF19DnkDRognDl8nDtWCOKTpVIBr+wwjjG5 O5uDuPeg3o06KxzZVC32mDakfdjDlgQGZxl872ouxCGWwtcOMhj8bFYuuj6HFzDFCi5b/su h0MxxWowiAaQS90XnSTU82rAatqMTungJQZqkAqAkZTioB3G6ERlTnE+kxNB6D4kwsu1y/e +Vaj2TKVgh6hPvzWefYS0AHJQBNvxxP7hTk0of5R3MveTvaupHOCrbjhirjBiF3zbqyH7A7 CbFwtfrI0buvUCt22sGPhyDGIoyvOJuU1HpFPphhUIwVLJQj6RhkiYG8DDWpg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 16628219759286156628 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 v2] gen_compile_commands.py: fix path resolve with symlinks in it Date: Tue, 5 Dec 2023 10:15:26 +0800 Message-Id: <20231205021523.4152128-2-xujialu@vimux.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231204165920.GA16980@dev-arch.thelio-3990X> References: <20231204165920.GA16980@dev-arch.thelio-3990X> 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:17:38 -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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/clang-tools/gen_compile_commands.py b/scripts/clang-tools/gen_compile_commands.py index 180952fb91c1b..99e28b7152c19 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,9 @@ 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. + # Convert Path object to a string because 'PosixPath' is not JSON serializable. + abs_path = str(Path(root_directory, file_path).resolve()) if not os.path.exists(abs_path): raise ValueError('File %s not found' % abs_path) return { -- 2.39.2