Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp9254244rwr; Thu, 11 May 2023 12:08:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zMNPSrhEvDONEj1ZI6J3etzgzu+JNidtPbOw+HZxWgOQmqc7Y9uuZciksEQd/PMxx6NkB X-Received: by 2002:a17:90a:13ce:b0:24e:3ed9:23a1 with SMTP id s14-20020a17090a13ce00b0024e3ed923a1mr22894202pjf.28.1683832103397; Thu, 11 May 2023 12:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683832103; cv=none; d=google.com; s=arc-20160816; b=OrrP93hTv4olEsvVsn3gyj/yuS39CSy6tMmHuaPduuHCSdpIQWhkct/p/rJ+KCy6q1 H+89gUsX/gxBqs8wyasBjseAaB1ThTF4fSdJ7bIPvsU/+TbolsP+0uTi+flr2Jo4yb1Q q4FX/apSHxCCcbeIJfwrUwx+OOV1PZK6q5Yjzgbirzc0MaYxy6PEy7ec42mB+Vd9l3/G e0++X+upmttTHuQDOC7B0OT7Za/0JdmDZVMchtSQNJ7wunx8NBcMff8GnbvUt5pr4tUF q4uWKH+W826TjOdlZ5vScbFHnqk2jbRCwvHx3lS6BL29igfV//MuYBAjJWDEzi81ulRr fU/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=c4G0EuLnryHzLb3RNJtijjoJKAz2fEREjbh9K6WasOg=; b=xQgYqJiVrFRZQB23Q5zp+iU2crH985mUTQ4gh/kf8buCLpli4AYOppXw4UnC/UZLbH GOMcIJTYSRbkgbnIrOAxF8YPT+TFuSrospYSjkisB+X5KzUomKvRzqPrVg2ZJ+b8dIEx o+GSB24ROHivNRQa9WBk8sOr0GSZIAprgzBhsZ+iSyng2stuQTvzsK9mbniLHQnfo+E8 mRGMM7Ypf16kjnWkkzS6GwjiuXEbCOVkQXQFwlITMaV+OyY5bU3r748IL6HG+AXCTmtm MUN8FII6kXfXYZTU9fkp3knjeKVVJDcvquK1FGhhFZoHWmj2aUnuRFRiylq0nmOxKbUC cSGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BhheZ8GG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a17090a074100b002470e893981si14574895pje.79.2023.05.11.12.08.11; Thu, 11 May 2023 12:08:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BhheZ8GG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238792AbjEKSwa (ORCPT + 99 others); Thu, 11 May 2023 14:52:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238407AbjEKSw3 (ORCPT ); Thu, 11 May 2023 14:52:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3637C40E0; Thu, 11 May 2023 11:52:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BDB1960DBF; Thu, 11 May 2023 18:52:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22092C4339B; Thu, 11 May 2023 18:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683831147; bh=jEXwF+0RlkbCYQKQZTZb+wHdb2EimuH8kjGlzRTWiqg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BhheZ8GGX95ss0MBGeRAM2iHQIpKuBlxn4/65pyeTqQVRif5/l8aUb33IBAx+eeb1 ksSeWkeBWqM8CL/waUyR+fBbzKqvs6afHF4g0rSAf/yV/olFpvzWEDebTXWDfYdD8o aTXGq90eyzg0l0U7rXeoBiDy7MwIoTe5g7XpaRvcIIegVm1NwVKpl/eYR4ewXGW8+k 23Sz7SkhQZwTA99jRgDjNfcagdTvG9K0NP1jwLhdIY4Um7Ir8alF2m0W+qa7dSU9t2 eaJKyE8VMgLsdK7BeZm7qmKkWJDatN0QH5YY3wgz6gQrtYfTTf1gYbr+Fn8zorfdqh q6VoHM/9myVUg== Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-38e3228d120so4550322b6e.3; Thu, 11 May 2023 11:52:27 -0700 (PDT) X-Gm-Message-State: AC+VfDyzEToMQkhfbcd473LY/RKkucxgybp5caAMLWWG28v154uSKrgc KGzAZ3YUQebHcP8GZROccR2T/cgJiPUIVSBfCbI= X-Received: by 2002:a05:6808:3ab:b0:394:4870:5722 with SMTP id n11-20020a05680803ab00b0039448705722mr2056191oie.53.1683831146340; Thu, 11 May 2023 11:52:26 -0700 (PDT) MIME-Version: 1.0 References: <20230504201833.202494-1-darwi@linutronix.de> <20230509012616.81579-1-darwi@linutronix.de> <20230509012616.81579-2-darwi@linutronix.de> In-Reply-To: <20230509012616.81579-2-darwi@linutronix.de> From: Masahiro Yamada Date: Fri, 12 May 2023 03:51:50 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/2] scripts/tags.sh: Resolve gtags empty index generation To: "Ahmed S. Darwish" Cc: Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Thomas Gleixner , linux-kbuild@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 9, 2023 at 10:26=E2=80=AFAM Ahmed S. Darwish wrote: > > gtags considers any file outside of its current working directory > "outside the source tree" and refuses to index it. For O=3D kernel builds= , > or when "make" is invoked from a directory other then the kernel source > tree, gtags ignores the entire kernel source and generates an empty > index. > > Force-set gtags current working directory to the kernel source tree. > > Due to commit 9da0763bdd82 ("kbuild: Use relative path when building in > a subdir of the source tree"), if the kernel build is done in a > sub-directory of the kernel source tree, the kernel Makefile will set > the kernel's $srctree to ".." for shorter compile-time and run-time > warnings. Consequently, the list of files to be indexed will be in the > "../*" form, rendering all such paths invalid once gtags switches to the > kernel source tree as its current working directory. > > If gtags indexing is requested and the build directory is not the kernel > source tree, index all files in absolute-path form. > > Note, indexing in absolute-path form will not affect the generated > index, as paths in gtags indices are always relative to the gtags "root > directory" (as evidenced by "gtags --dump"). The code works as claimed, but I am just curious. If all the paths are relative, how can you use the tags files located in a separate directory? "make O=3Dfoo gtags" creates tags files in foo/. I want to use them from emacs. emacs cannot find the right file because it assumes the path is relative to 'foo' instead of the source tree. I set GTAGSROOT to the source tree, but I could not find a way to use it in a useful way. > diff --git a/scripts/tags.sh b/scripts/tags.sh > index ea31640b2671..3de4b4ebd891 100755 > --- a/scripts/tags.sh > +++ b/scripts/tags.sh > @@ -32,6 +32,14 @@ else > tree=3D${srctree}/ > fi > > + Unneeded empty line addition. > +# gtags(1) refuses to index any file outside of its current working dir. > +# If gtags indexing is requested and the build output directory is not > +# the kernel source tree, index all files in absolute-path form. > +if [ "$1" =3D "gtags" -a -n "${tree}" ]; then > + tree=3D$(realpath $tree)/ I decided to run shellcheck for new code. Please follow the suggestion from the tool. In scripts/tags.sh line 40: tree=3D$(realpath $tree)/ ^---^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: tree=3D$(realpath "$tree")/ (You do not need to fix the entire script. This is only for new code). > @@ -131,7 +139,11 @@ docscope() > > dogtags() > { > - all_target_sources | gtags -i -f - > + local gtagsoutdir=3D"${PWD}" > + local gtagsroot=3D"${tree}" > + > + [ -z "${gtagsroot}" ] && gtagsroot=3D"." > + all_target_sources | gtags -i -C $gtagsroot -f - $gtagsoutdir > } You can write it in one line. dogtags() { all_target_sources | gtags -i -C "${tree:-.}" -f - "${PWD}" } -- Best Regards Masahiro Yamada