All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ahmed S. Darwish" <darwi@linutronix.de>
To: Masahiro Yamada <masahiroy@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nicolas Schier <nicolas@fjasle.eu>,
	Jonathan Corbet <corbet@lwn.net>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	"Ahmed S. Darwish" <darwi@linutronix.de>
Subject: [PATCH v3 1/2] scripts/tags.sh: Resolve gtags empty index generation
Date: Mon, 15 May 2023 19:32:16 +0200	[thread overview]
Message-ID: <20230515173217.64864-2-darwi@linutronix.de> (raw)
In-Reply-To: <20230515173217.64864-1-darwi@linutronix.de>

gtags considers any file outside of its current working directory
"outside the source tree" and refuses to index it. For O= 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" anyway (as evidenced by "gtags --dump").

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Cc: <stable@vger.kernel.org>
---
 scripts/tags.sh | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/scripts/tags.sh b/scripts/tags.sh
index ea31640b2671..f6b3c7cd39c7 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -32,6 +32,13 @@ else
 	tree=${srctree}/
 fi
 
+# 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" == "gtags" && -n "${tree}" ]]; then
+	tree=$(realpath "$tree")/
+fi
+
 # Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
 if [ "${ALLSOURCE_ARCHS}" = "" ]; then
 	ALLSOURCE_ARCHS=${SRCARCH}
@@ -131,7 +138,7 @@ docscope()
 
 dogtags()
 {
-	all_target_sources | gtags -i -f -
+	all_target_sources | gtags -i -C "${tree:-.}" -f - "$PWD"
 }
 
 # Basic regular expressions with an optional /kind-spec/ for ctags and
-- 
2.30.2


  reply	other threads:[~2023-05-15 17:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04 20:18 [PATCH v1 0/1] scripts: Fix "make gtags" for O= kernel builds Ahmed S. Darwish
2023-05-04 20:18 ` [PATCH v1 1/1] scripts/tags.sh: Fix gtags generation " Ahmed S. Darwish
2023-05-04 21:32   ` Nathan Chancellor
2023-05-04 22:00     ` Ahmed S. Darwish
2023-05-05  5:13       ` Masahiro Yamada
2023-05-05  5:17         ` Masahiro Yamada
2023-05-08 14:11         ` Ahmed S. Darwish
2023-05-09  1:26 ` [PATCH v2 0/2] scripts: Resolve gtags empty index generation Ahmed S. Darwish
2023-05-09  1:26   ` [PATCH v2 1/2] scripts/tags.sh: " Ahmed S. Darwish
2023-05-11 18:51     ` Masahiro Yamada
2023-05-15 15:23       ` Ahmed S. Darwish
2023-05-15 16:35         ` Ahmed S. Darwish
2023-05-09  1:26   ` [PATCH v2 2/2] docs: Set minimal gtags / GNU GLOBAL version to 6.6.5 Ahmed S. Darwish
2023-05-15 17:32   ` [PATCH v3 0/2] scripts: Resolve gtags empty index generation Ahmed S. Darwish
2023-05-15 17:32     ` Ahmed S. Darwish [this message]
2023-05-15 17:32     ` [PATCH v3 2/2] docs: Set minimal gtags / GNU GLOBAL version to 6.6.5 Ahmed S. Darwish
2023-05-20 22:41     ` [PATCH v3 0/2] scripts: Resolve gtags empty index generation Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230515173217.64864-2-darwi@linutronix.de \
    --to=darwi@linutronix.de \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nicolas@fjasle.eu \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.