scripts: Fix "make gtags" for O= kernel builds
Subsystems (3)
cover scripts: Fix "make gtags" for O= kernel builds
Hi,
make gtags for O= kernel builds is currently broken. For example, when doing:
make O=../build/ x86_64_defconfig
make O=../build/ gtags
gtags generates a warning for each kernel source file to be indexed:
make[1]: Entering directory '/home/darwi/build'
GEN gtags
Warning: '/home/darwi/linux/arch/x86/include/asm/qspinlock.h' is out of source tree. ignored.
Warning: '/home/darwi/linux/arch/x86/include/asm/hpet.h' is out of source tree. ignored.
...
Warning: '/home/darwi/linux/virt/lib/irqbypass.c' is out of source tree. ignored. make[1]: Leaving directory '/home/darwi/build/'
and then generates an empty index:
$ du -hs ~/build/G* 16K /home/darwi/build/GPATH 16K /home/darwi/build/GRTAGS 16K /home/darwi/build/GTAGS
This series includes a proposed fix. After applying it:
$ make O=../build/ gtags
make[1]: Entering directory '/home/darwi/build'
GEN gtags
make[1]: Leaving directory '/home/darwi/build'$ du -hs ~/build/G* 9.1M /home/darwi/build/GPATH 506M /home/darwi/build/GRTAGS 696M /home/darwi/build/GTAGS
The generated files can then be integrated with editors or IDEs as usual.
Thanks,
=>
Ahmed S. Darwish (1):
scripts/tags.sh: Fix gtags generation for O= kernel builds
scripts/tags.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
base-commit: 1a5304fecee523060f26e2778d9d8e33c0562df3 --
2.30.2
PATCH 1/1 scripts/tags.sh: Fix gtags generation for O= kernel builds
gtags considers any file outside of its current working directory "outside the source tree" and refuses to index it.
For O= kernel builds, scripts/tags.sh invokes gtags with the current working directory set to ${O}. This leads to gtags ignoring the entire kernel source and generating an empty index.
For O= builds, set gtags' working directory to the kernel source tree and explicitly set its output path through parameters instead.
--- scripts/tags.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/tags.sh +8 -1
@@ -131,7 +131,14 @@ docscope() dogtags() { - all_target_sources | gtags -i -f - + # gtags refuses to index any file outside of the current working + # directory. For O= builds, set the current working directory to + # the kernel source tree and the output tags dir to ${O}. + suffixparams= + if [ -v O ]; then + suffixparams="-C $tree $O" + fi + all_target_sources | gtags -i -f - $suffixparams } # Basic regular expressions with an optional /kind-spec/ for ctags and
Signature · 1 line
2.30.2
Re: [PATCH v1 1/1] scripts/tags.sh: Fix gtags generation for O= kernel builds
Quoted 11 lines · Ahmed S. Darwish
gtags considers any file outside of its current working directory "outside the source tree" and refuses to index it.
For O= kernel builds,
scripts/tags.shinvokes gtags with the current working directory set to ${O}. This leads to gtags ignoring the entire kernel source and generating an empty index.For O= builds, set gtags' working directory to the kernel source tree and explicitly set its output path through parameters instead.
Signed-off-by Ahmed S. Darwish <[email protected]>
Quoted 9 lines
--- scripts/tags.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)scripts/tags.sh +0
-0
scripts/tags.sh docscope() · line 138
Quoted 9 lines
scripts/tags.sh +5
-1@@ -131,7 +131,14 @@ docscope() dogtags() { - all_target_sources | gtags -i -f - + # gtags refuses to index any file outside of the current working + # directory. For O= builds, set the current working directory to + # the kernel source tree and the output tags dir to ${O}. + suffixparams= + if [ -v O ]; then
I think
if [ -n "$O" ]; then
would match the style preferred by Kbuild (though that is usually for portability sake, which probably does not matter here since bash is explicitly requested). Perhaps not worth addressing if there is no other reason for a v2.
Quoted 9 lines
scripts/tags.sh +3
-0+ suffixparams="-C $tree $O" + fi + all_target_sources | gtags -i -f - $suffixparams } # Basic regular expressions with an optional /kind-spec/ for ctags andSignature · 1 line
2.30.2
Re: [PATCH v1 1/1] scripts/tags.sh: Fix gtags generation for O= kernel builds
Hi Nathan,
Quoted 2 lines · Nathan Chancellor
On Thu, May 04, 2023 at 10:18:33PM +0200, Ahmed S. Darwish wrote:
...
Quoted 5 lines
scripts/tags.sh docscope() · line 138
Quoted 2 lines
scripts/tags.sh +2
-0+ suffixparams= + if [ -v O ]; thenI think
Quoted 7 lines
if [ -n "$O" ]; then
would match the style preferred by
Kbuild(though that is usually for portability sake, which probably does not matter here since bash is explicitly requested). Perhaps not worth addressing if there is no other reason for a v2.
Thanks, I'll do it. I've just discovered that a v2 is necessary anyway.
If O= has a "~", for example as in:
make O=~/build/ gtags
the snippet below:
Quoted 3 lines
scripts/tags.sh docscope() · line 141
Quoted 3 lines
scripts/tags.sh +3
-0+ suffixparams="-C $tree $O" + fi + all_target_sources | gtags -i -f - $suffixparams
^
will fail since the "~" in the O= directory path won't get dereferenced before getting passed to the gtags call (an eval is needed).
I'll submit a v2 shortly.
Kind regards,
--
Ahmed S. Darwish
Linutronix GmbH
Re: [PATCH v1 1/1] scripts/tags.sh: Fix gtags generation for O= kernel builds
Quoted 35 lines · Ahmed S. Darwish
Hi Nathan,
Quoted 2 lines · Nathan Chancellor
On Thu, May 04, 2023 at 10:18:33PM +0200, Ahmed S. Darwish wrote:
...
Quoted 12 lines
scripts/tags.sh docscope() · line 138
Quoted 2 lines
scripts/tags.sh +2
-0+ suffixparams= + if [ -v O ]; thenI think
if [ -n "$O" ]; then
would match the style preferred by
Kbuild(though that is usually for portability sake, which probably does not matter here since bash is explicitly requested). Perhaps not worth addressing if there is no other reason for a v2.Thanks, I'll do it. I've just discovered that a v2 is necessary anyway.
If O= has a "~", for example as in:
make O=~/build/ gtags
the snippet below:
Quoted 3 lines
scripts/tags.sh docscope() · line 141
Quoted 3 lines
scripts/tags.sh +3
-0+ suffixparams="-C $tree $O" + fi + all_target_sources | gtags -i -f - $suffixparams^will fail since the "~" in the O= directory path won't get dereferenced before getting passed to the gtags call (an eval is needed).
Quoted 7 lines
I'll submit a v2 shortly.
Kind regards,
--
Ahmed S. Darwish
Linutronix GmbH
It is wrong to check whether you are building out of the source tree. See line 159 of the Makefile.
BTW, this patch does not work for me.
It spits a ton of "not found" warnings, then generates empty tags.
$ make O=build gtags make[1]: Entering directory '/home/masahiro/ref/linux/build' GEN gtags Warning: '../arch/x86/include/asm/vmalloc.h' not found. ignored. Warning: '../arch/x86/include/asm/pgtable-3level_types.h' not found. ignored. Warning: '../arch/x86/include/asm/paravirt.h' not found. ignored. Warning: '../arch/x86/include/asm/text-patching.h' not found. ignored. Warning: '../arch/x86/include/asm/softirq_stack.h' not found. ignored. Warning: '../arch/x86/include/asm/intel_ds.h' not found. ignored. Warning: '../arch/x86/include/asm/resctrl.h' not found. ignored. Warning: '../arch/x86/include/asm/setup_arch.h' not found. ignored. Warning: '../arch/x86/include/asm/simd.h' not found. ignored. Warning: '../arch/x86/include/asm/mmconfig.h' not found. ignored. Warning: '../arch/x86/include/asm/pgtable_types.h' not found. ignored. Warning: '../arch/x86/include/asm/mem_encrypt.h' not found. ignored. Warning: '../arch/x86/include/asm/dmi.h' not found. ignored. Warning: '../arch/x86/include/asm/thermal.h' not found. ignored.
...
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v1 1/1] scripts/tags.sh: Fix gtags generation for O= kernel builds
Quoted 41 lines · Masahiro Yamada
Quoted 39 lines · Ahmed S. Darwish
Hi Nathan,
Quoted 2 lines · Nathan Chancellor
On Thu, May 04, 2023 at 10:18:33PM +0200, Ahmed S. Darwish wrote:
...
Quoted 12 lines
scripts/tags.sh docscope() · line 138
Quoted 2 lines
scripts/tags.sh +2
-0+ suffixparams= + if [ -v O ]; thenI think
if [ -n "$O" ]; then
would match the style preferred by
Kbuild(though that is usually for portability sake, which probably does not matter here since bash is explicitly requested). Perhaps not worth addressing if there is no other reason for a v2.Thanks, I'll do it. I've just discovered that a v2 is necessary anyway.
If O= has a "~", for example as in:
make O=~/build/ gtags
the snippet below:
Quoted 3 lines
scripts/tags.sh docscope() · line 141
Quoted 3 lines
scripts/tags.sh +3
-0+ suffixparams="-C $tree $O" + fi + all_target_sources | gtags -i -f - $suffixparams^will fail since the "~" in the O= directory path won't get dereferenced before getting passed to the gtags call (an eval is needed).
I'll submit a v2 shortly.
Kind regards,
Quoted 8 lines
Quoted 3 lines
--
Ahmed S. Darwish
Linutronix GmbHIt is wrong to check whether you are building out of the source tree. See line 159 of the
Makefile.
Let me correct this sentense.
It is wrong to use 'O' to check whether you are building out of the source tree.
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH v1 1/1] scripts/tags.sh: Fix gtags generation for O= kernel builds
In reply to Masahiro YamadaHi Masahiro,
Quoted 4 lines · Masahiro Yamada
It is wrong to check whether you are building out of the source tree. See line 159 of the
Makefile.
Oh, didn't think about that case. Thanks for the reference and the further clarification in reply.
I'll remove the ${O} check then and use saner mechanisms.
Quoted 6 lines
BTW, this patch does not work for me.
It spits a ton of "not found" warnings, then generates empty tags.$ make O=build gtags
Interesting...
When doing:
$ make O=../build gtags
scripts/tags.sh "$tree" variable is set to the absolute path of the kernel source tree. Thus all the paths fed to gtags are absolute and this patch series works.
When doing what you tested with:
$ make O=build/ gtags
scripts/tags.sh "$tree" variable is set to the path of the kernel source tree *relative* to O=build/. So in that case kernel source "$tree" equals ".."
With this series, the build will fail as gtags current working dir is the kernel source tree, and all the fed paths are thus invalid as they're relative to O=build/ instead.
Without this series the build will still fail given the original problem of having the files "outside the source tree", where gtags thinks the source tree is "build/".
I'll think of something that can cover the both cases.
Kind regards,
Ahmed
--
Linutronix GmbH
v2 cover scripts: Resolve gtags empty index generation
In reply to Ahmed S. DarwishHi,
v2-changelog
------------
Handle review remarks from Masahiro Yamada:
- scripts/tags.sh: remove the O= language, and focus on the general case of the build directory being different from the kernel source tree, as specified in kernel Makefile L159.
- Fix failure when build directory is a subdirectory of the kernel source tree.
NEW:
- Update Documentation/process/changes.rst with new gtags (GNU GLOBAL) requirements.
Thanks!
Cover letter / v1
-----------------
https://lkml.kernel.org/r/[email protected]
make gtags for O= kernel builds is currently broken. For example, when doing:
make O=../build/ x86_64_defconfig
make O=../build/ gtags
gtags generates a warning for each kernel source file to be indexed:
make[1]: Entering directory '/home/darwi/build'
GEN gtags
Warning: '/home/darwi/linux/arch/x86/include/asm/qspinlock.h' is out of source tree. ignored.
Warning: '/home/darwi/linux/arch/x86/include/asm/hpet.h' is out of source tree. ignored.
...
Warning: '/home/darwi/linux/virt/lib/irqbypass.c' is out of source tree. ignored. make[1]: Leaving directory '/home/darwi/build/'
and then generates an empty index:
$ du -hs ~/build/G* 16K /home/darwi/build/GPATH 16K /home/darwi/build/GRTAGS 16K /home/darwi/build/GTAGS
This series includes a proposed fix. After applying it:
$ make O=../build/ gtags
make[1]: Entering directory '/home/darwi/build'
GEN gtags
make[1]: Leaving directory '/home/darwi/build'$ du -hs ~/build/G* 9.1M /home/darwi/build/GPATH 506M /home/darwi/build/GRTAGS 696M /home/darwi/build/GTAGS
The generated files can then be integrated with editors or IDEs as usual.
=>
Ahmed S. Darwish (2):
scripts/tags.sh: Resolve gtags empty index generation
docs: Set minimal gtags / GNU GLOBAL version to 6.6.5
Documentation/process/changes.rst | 7 +++++++ scripts/tags.sh | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)
base-commit: ba0ad6ed89fd5dada3b7b65ef2b08e95d449d4ab --
2.40.0
PATCH v2 1/2 scripts/tags.sh: Resolve gtags empty index generation
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" (as evidenced by "gtags --dump").
--- scripts/tags.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
scripts/tags.sh +13 -1
@@ -32,6 +32,14 @@ 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" -a -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 +139,11 @@ docscope() dogtags() { - all_target_sources | gtags -i -f - + local gtagsoutdir="${PWD}" + local gtagsroot="${tree}" + + [ -z "${gtagsroot}" ] && gtagsroot="." + all_target_sources | gtags -i -C $gtagsroot -f - $gtagsoutdir } # Basic regular expressions with an optional /kind-spec/ for ctags and
Signature · 1 line
2.40.0
Re: [PATCH v2 1/2] scripts/tags.sh: Resolve gtags empty index generation
Quoted 17 lines · Ahmed S. Darwish
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 kernelMakefilewill 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.
Quoted 6 lines
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=foo 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.
scripts/tags.sh else · line 35
Quoted 9 lines
scripts/tags.sh +1
-0@@ -32,6 +32,14 @@ else tree=${srctree}/ fi +
Unneeded empty line addition.
scripts/tags.sh else · line 40
Quoted 5 lines
scripts/tags.sh +5
-0+# 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" -a -n "${tree}" ]; then + tree=$(realpath $tree)/
I decided to run shellcheck for new code.
Please follow the suggestion from the tool.
In scripts/tags.sh line 40:
tree=$(realpath $tree)/
^---^ SC2086 (info): Double quote to prevent
globbing and word splitting.
Did you mean:
tree=$(realpath "$tree")/
(You do not need to fix the entire script.
This is only for new code).
scripts/tags.sh docscope() · line 147
Quoted 11 lines
scripts/tags.sh +5
-1@@ -131,7 +139,11 @@ docscope() dogtags() { - all_target_sources | gtags -i -f - + local gtagsoutdir="${PWD}" + local gtagsroot="${tree}" + + [ -z "${gtagsroot}" ] && gtagsroot="." + 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
Re: [PATCH v2 1/2] scripts/tags.sh: Resolve gtags empty index generation
Quoted 2 lines · Masahiro Yamada
The code works as claimed, but I am just curious.
Thanks.
Quoted 8 lines
If all the paths are relative, how can you use the tags files located in a separate directory?
"make O=foo 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.
Correct.
In theory, since all the indexed linux source tree paths at the gtags generated files (GPATH/GRTAGS/GTAGS) are relative to the linux source tree root, opening such files from emacs ggtags-mode, *wherever* these files are, "should" work.
In practice, ggtags/global (and thus also emacs ggtags-mode) operate with a model of the world where all indexed files must be under the source "root directory". So, the GPATH/GRTAGS/GTAGS files are expected to be under the source tree (except in special GTAGSLIBPATH= cases).
Quoted 2 lines
I set GTAGSROOT to the source tree, but I could not find a way to use it in a useful way.
Yes, that won't work, as emacs will search for the G* database files under that folder instead.
Meanwhile setting GTAGSROOT to the O= directory, or to a build directory that is different from the kernel source tree, as in:
cd ~/linux
O=~/build/build-linux-x86
make O=$O x86_64_defconfig
make O=$O gtags
GTAGSROOT=$O emacs init/main.c
will "mostly" succeed (as you hinted at):
M-x ggtags-mode
# emacs finds gtags files under ${GTAGSROOT} and sets ${GTAGSROOT} as
# the root of the project M-x ggtags-find-definition
Definition: rcu_read_lock
-*- mode: ggtags-global; default-directory: "~/build/build-linux-x86/" -*- Global started at Mon May 15 15:54:01
global -v --result=grep --color=always --path-style=shorter -- rcu_read_lock include/linux/rcupdate.h:769:static __always_inline void rcu_read_lock(void) 1 object located (using '/home/darwi/build/build-linux-x86/GTAGS').
Global found 1 definition at Mon May 15 15:54:01
# Prompt
Find this match in (default include/linux/rcupdate.h)?: ~/build/build-linux-x86/ ^^^
But at the Prompt step above, things break.
In a fully working setup, this prompt will not be shown and emacs just jumps to rcuupdate.h line 769.
What I personally do to mitigate that problem is:
cd ~/linux
for f in GTAGS GRTAGS GPATH; do
ln -vsf ${O}/$f .
done
and switch these symlinks through minor local shell plumbing whenever I'm switching kernel projects with different build directories.
It is not ideal, but maybe we can discuss this with the global(1) people at a later step. At least with this patch series, "make O=xyz/ gtags" produces a valid index.
Quoted 12 lines
scripts/tags.sh else · line 40
Quoted 6 lines
scripts/tags.sh +5
-0+# 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" -a -n "${tree}" ]; then + tree=$(realpath $tree)/I decided to run shellcheck for new code.
Please follow the suggestion from the tool.In
scripts/tags.shline 40:
tree=$(realpath $tree)/
Quoted 9 lines
^---^ SC2086 (info): Double quote to preventglobbing and word splitting.
Did you mean:
tree=$(realpath "$tree")/(You do not need to fix the entire script.
This is only for new code).
Yes, the reason was to following the existing coding pattern at scripts/tags.sh. But, sure, will do.
Quoted 15 lines
scripts/tags.sh docscope() · line 147
Quoted 12 lines
scripts/tags.sh +5
-1@@ -131,7 +139,11 @@ docscope() dogtags() { - all_target_sources | gtags -i -f - + local gtagsoutdir="${PWD}" + local gtagsroot="${tree}" + + [ -z "${gtagsroot}" ] && gtagsroot="." + all_target_sources | gtags -i -C $gtagsroot -f - $gtagsoutdir }You can write it in one line.
Quoted 5 lines
dogtags(){ all_target_sources | gtags -i -C "${tree:-.}" -f - "${PWD}" }
Ditto. The script was almost-fully POSIX style (except the first line), so I avoided bash features on purpose.
I personlly always prefer using Bash features though, so I'll definitely update the code.
Thanks a lot for the review. I'll send a v3.
--
Ahmed S. Darwish
Linutronix GmbH
Re: [PATCH v2 1/2] scripts/tags.sh: Resolve gtags empty index generation
Quoted 4 lines · Ahmed S. Darwish
Quoted 3 lines · Masahiro Yamada
You can write it in one line.
Quoted 9 lines
Quoted 5 lines
dogtags(){ all_target_sources | gtags -i -C "${tree:-.}" -f - "${PWD}" }Ditto. The script was almost-fully POSIX style (except the first line), so I avoided bash features on purpose.
Nitpick for correctness sake the "Use default values" parameter expansion is actually POSIX-ly correct:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
Thanks,
Ahmed
PATCH v2 2/2 docs: Set minimal gtags / GNU GLOBAL version to 6.6.5
In reply to Ahmed S. DarwishKernel build now uses the gtags "-C (--directory)" option, available since GNU GLOBAL v6.6.5. Update the documentation accordingly.
--- Documentation/process/changes.rst | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/process/changes.rst +7 -0
@@ -60,6 +60,7 @@ openssl & libcrypto 1.0.0 openssl version bc 1.06.95 bc --version Sphinx\ [#f1]_ 1.7 sphinx-build --version cpio any cpio --version +gtags (optional) 6.6.5 gtags --version ====================== =============== ======================================== .. [#f1] Sphinx is needed only to build the Kernel documentation
@@ -174,6 +175,12 @@ You will need openssl to build kernels 3.7 and higher if module signing is enabled. You will also need openssl development packages to build kernels 4.3 and higher. +gtags / GNU GLOBAL (optional) +----------------------------- + +The kernel build requires GNU GLOBAL version 6.6.5 or later to generate +tag files through ``make gtags``. This is due to its use of the gtags +``-C (--directory)`` flag. System utilities ****************
Signature · 1 line
2.40.0
v3 cover scripts: Resolve gtags empty index generation
In reply to Ahmed S. DarwishHi,
v3-changelog
------------
Handle review remarks from Masahiro Yamada:
- Apply shellcheck on new "scripts/tags.sh" code.
- Shorten code through shell's "default value" parameter expansion.
NEW:
- Cc docs maintainer (Documentation/process/changes.rst change).
Thanks!
v2-changelog
------------
https://lkml.kernel.org/r/[email protected]
Handle review remarks from Masahiro Yamada:
- scripts/tags.sh: remove the O= language, and focus on the general case of the build directory being different from the kernel source tree, as specified in kernel Makefile L159.
- Fix failure when build directory is a subdirectory of the kernel source tree.
NEW:
- Update Documentation/process/changes.rst with new gtags (GNU GLOBAL) requirements.
Thanks!
Cover letter / v1
-----------------
https://lkml.kernel.org/r/[email protected]
make gtags for O= kernel builds is currently broken. For example, when doing:
make O=../build/ x86_64_defconfig
make O=../build/ gtags
gtags generates a warning for each kernel source file to be indexed:
make[1]: Entering directory '/home/darwi/build'
GEN gtags
Warning: '/home/darwi/linux/arch/x86/include/asm/qspinlock.h' is out of source tree. ignored.
Warning: '/home/darwi/linux/arch/x86/include/asm/hpet.h' is out of source tree. ignored.
...
Warning: '/home/darwi/linux/virt/lib/irqbypass.c' is out of source tree. ignored. make[1]: Leaving directory '/home/darwi/build/'
and then generates an empty index:
$ du -hs ~/build/G* 16K /home/darwi/build/GPATH 16K /home/darwi/build/GRTAGS 16K /home/darwi/build/GTAGS
This series includes a proposed fix. After applying it:
$ make O=../build/ gtags
make[1]: Entering directory '/home/darwi/build'
GEN gtags
make[1]: Leaving directory '/home/darwi/build'$ du -hs ~/build/G* 9.1M /home/darwi/build/GPATH 506M /home/darwi/build/GRTAGS 696M /home/darwi/build/GTAGS
The generated files can then be integrated with editors or IDEs as usual.
=>
Ahmed S. Darwish (2):
scripts/tags.sh: Resolve gtags empty index generation
docs: Set minimal gtags / GNU GLOBAL version to 6.6.5
Documentation/process/changes.rst | 7 +++++++ scripts/tags.sh | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
base-commit: f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6 --
2.30.2
PATCH v3 1/2 scripts/tags.sh: Resolve gtags empty index generation
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").
--- scripts/tags.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
scripts/tags.sh +8 -1
@@ -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
Signature · 1 line
2.30.2
PATCH v3 2/2 docs: Set minimal gtags / GNU GLOBAL version to 6.6.5
In reply to Ahmed S. DarwishKernel build now uses the gtags "-C (--directory)" option, available since GNU GLOBAL v6.6.5. Update the documentation accordingly.
--- Documentation/process/changes.rst | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/process/changes.rst +7 -0
@@ -60,6 +60,7 @@ openssl & libcrypto 1.0.0 openssl version bc 1.06.95 bc --version Sphinx\ [#f1]_ 1.7 sphinx-build --version cpio any cpio --version +gtags (optional) 6.6.5 gtags --version ====================== =============== ======================================== .. [#f1] Sphinx is needed only to build the Kernel documentation
@@ -174,6 +175,12 @@ You will need openssl to build kernels 3.7 and higher if module signing is enabled. You will also need openssl development packages to build kernels 4.3 and higher. +gtags / GNU GLOBAL (optional) +----------------------------- + +The kernel build requires GNU GLOBAL version 6.6.5 or later to generate +tag files through ``make gtags``. This is due to its use of the gtags +``-C (--directory)`` flag. System utilities ****************
Signature · 1 line
2.30.2
Re: [PATCH v3 0/2] scripts: Resolve gtags empty index generation
In reply to Ahmed S. DarwishQuoted 78 lines · Ahmed S. Darwish
Hi,
v3-changelog
------------Handle review remarks from Masahiro Yamada:
- Apply shellcheck on new "
scripts/tags.sh" code.- Shorten code through shell's "default value" parameter expansion.
NEW:
- Cc docs maintainer (
Documentation/process/changes.rstchange).Thanks!
v2-changelog
------------https://lkml.kernel.org/r/[email protected]
Handle review remarks from Masahiro Yamada:
-
scripts/tags.sh: remove the O= language, and focus on the general case of the build directory being different from the kernel source tree, as specified in kernelMakefileL159.- Fix failure when build directory is a subdirectory of the kernel source tree.
NEW:
- Update
Documentation/process/changes.rstwith new gtags (GNU GLOBAL) requirements.Thanks!
Cover letter / v1
-----------------https://lkml.kernel.org/r/[email protected]
make gtags for O= kernel builds is currently broken. For example, when doing:
make O=../build/
x86_64_defconfig
make O=../build/ gtagsgtags generates a warning for each kernel source file to be indexed:
make[1]: Entering directory '
/home/darwi/build'
GEN gtags
Warning: '/home/darwi/linux/arch/x86/include/asm/qspinlock.h' is out of source tree. ignored.
Warning: '/home/darwi/linux/arch/x86/include/asm/hpet.h' is out of source tree. ignored.
...
Warning: '/home/darwi/linux/virt/lib/irqbypass.c' is out of source tree. ignored. make[1]: Leaving directory '/home/darwi/build/'and then generates an empty index:
$ du -hs ~/build/G* 16K /home/darwi/build/GPATH 16K /home/darwi/build/GRTAGS 16K /home/darwi/build/GTAGSThis series includes a proposed fix. After applying it:
$ make O=../build/ gtags make[1]: Entering directory '/home/darwi/build' GEN gtags make[1]: Leaving directory '/home/darwi/build'$ du -hs ~/build/G* 9.1M /home/darwi/build/GPATH 506M /home/darwi/build/GRTAGS 696M /home/darwi/build/GTAGS
Quoted 8 lines
The generated files can then be integrated with editors or IDEs as usual.
=>
Ahmed S. Darwish (2):
scripts/tags.sh: Resolve gtags empty index generation
docs: Set minimal gtags / GNU GLOBAL version to 6.6.5
Both applied. Thanks.
Quoted 8 lines
Documentation/process/changes.rst | 7 +++++++ scripts/tags.sh | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)base-commit:
f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6--
2.30.2
Signature · 2 lines
Best Regards Masahiro Yamada