Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2844016rdb; Mon, 4 Dec 2023 08:59:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLjOQqJZ3JffsRLd/g5c4+bryB0X3anXL9O6F1ayIH5RYfAS6ya2VEVfwsHlRV3RgUE3CG X-Received: by 2002:a05:6a00:9386:b0:6cd:fe6e:ac9b with SMTP id ka6-20020a056a00938600b006cdfe6eac9bmr79747pfb.0.1701709171970; Mon, 04 Dec 2023 08:59:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701709171; cv=none; d=google.com; s=arc-20160816; b=eYaRnYNqfPTF58LAM2uAQ2nutk9UJU4Evc5GLTfModJaM/XBYJT4+UKF/BNdNvepUH zhPgVp38nMnPoKj4435lG0zMZ2gkr78goSxQd8VkJ0RJ7e6YDkY5jErAbANeH8tqCepr 5mA01IeovBFH4cn2cRtoAVrABXk2GG12TUW77tOSVgy8rVhgpu5bVSiDiqAzOqPqG9wM Tn6vn593b0Huw6TEmbl+xu1Yy01Ct8tRPyV7iqRofX9nbdfbrjHkYVpYZVFcJCcXA+N1 VtjtWASeA6PNtq6YumDxSHygs7gAuEjJUjZ6i2oyE/xF3bA3Bkqm5eU9rNURDQiTH4JI PnMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6ZXX7OTXZawSzAkUsDp1sHZdwj9G/IQ74R5Yhsk84p8=; fh=6WvU0nT5zFVRgavOlciXfZyT46E2rRaGp53nOeB/eb0=; b=I8Iez0gfv6EU4Zle3z6Gb91JroSSNp8RUoboDj1EhXozpRJAkAl3vRKymFXpvEmcLr PBmXJkWh85O5MLSCSy0RLIPZeUruVQgHCf4ii+0Wqbu5jiAgZkebNNhc7R84UkbgJ1zh Dljq9S8RXj1HfmSOa925I6C97NZkfkMcZfq+ToqSB7C/bXx+MBMxvionwHlcLnXcBMlT ZPukQLlAmrSvW87vFh+8uM9yeJlkqt8h2Jg5jMidjGJX5WKTTVXJsfW2xVRxg7hyGmTI CL55Jixz3noC4PO/GOMwoYbN8DRUItN5a3J3Tku/haLleZODwCvPNu4nRlg8an2Ss9Hc rAAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=didfVJq6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id f35-20020a631f23000000b005c688dc20ecsi2083819pgf.510.2023.12.04.08.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:59:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=didfVJq6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 7FF3A8034631; Mon, 4 Dec 2023 08:59:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbjLDQ7R (ORCPT + 99 others); Mon, 4 Dec 2023 11:59:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229488AbjLDQ7Q (ORCPT ); Mon, 4 Dec 2023 11:59:16 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F427B9 for ; Mon, 4 Dec 2023 08:59:23 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62E5FC433C8; Mon, 4 Dec 2023 16:59:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701709162; bh=HsRSNN6CpvmvZAZ4yUoTzbjW0yuOeGGx/khxv4eeGtU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=didfVJq6y/6VNbAau4ux2zMDTvbk3bR1iCMcgr2s7RSHUt7Plq0+NIfgG+QGn0sVq USjAh5l0Cy6smgZwKWSI4he5ofSZLKwjFYpJZUKFMXt29Q8W96SgYuguTd5ruv978n 3VCYNsJcW/jGfNNsJQFAJlk+OeF+6dESEMS2XXo/xQCWYipcGRZlkL4xjF9lSNLWxR cvj/4S6wlmf0//Sq0RbjpmrgBYKouefqpankUA5aeytIdMTQAhhrDMs4Kio+5fDs6n zlfzMHXtmHQO0AeX3IJKZAI2pku39SJmepOsQUhQCqMMF/9Z1WpRCKukQt987+KeG1 cdtcCSbcC9cAQ== Date: Mon, 4 Dec 2023 09:59:20 -0700 From: Nathan Chancellor To: Jialu Xu Cc: ndesaulniers@google.com, morbo@google.com, justinstitt@google.com, llvm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] gen_compile_commands.py: fix path resolve with symlinks in it Message-ID: <20231204165920.GA16980@dev-arch.thelio-3990X> References: <20231204104141.3618547-1-xujialu@vimux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231204104141.3618547-1-xujialu@vimux.org> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 04 Dec 2023 08:59:29 -0800 (PST) On Mon, Dec 04, 2023 at 06:41:42PM +0800, Jialu Xu wrote: > 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. Can you provide an example or more detailed description of how this behavior is currently broken? I can't really understand how having symlinks in the path after normalization would break anything but I am potentially missing something :) > 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()) I think this can be more simply: abs_path = str(Path(root_directory, file_path).resolve()) I think there should be a comment around why we are creating a Path object then creating a string from it, rather than using the Path object directly, namely that PosixPath is not JSON serializable. > if not os.path.exists(abs_path): > raise ValueError('File %s not found' % abs_path) > return { > -- > 2.39.2 >