diff mbox series

[v1,1/1] scripts/tags.sh: Fix gtags generation for O= kernel builds

Message ID 20230504201833.202494-2-darwi@linutronix.de (mailing list archive)
State New, archived
Headers show
Series scripts: Fix "make gtags" for O= kernel builds | expand

Commit Message

Ahmed S. Darwish May 4, 2023, 8:18 p.m. UTC
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.

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

Comments

Nathan Chancellor May 4, 2023, 9:32 p.m. UTC | #1
On Thu, May 04, 2023 at 10:18:33PM +0200, 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= 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.
> 
> Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>

Reviewed-by: Nathan Chancellor <nathan@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..1a6db535503b 100755
> --- a/scripts/tags.sh
> +++ b/scripts/tags.sh
> @@ -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.

> +		suffixparams="-C $tree $O"
> +	fi
> +	all_target_sources | gtags -i -f - $suffixparams
>  }
>  
>  # Basic regular expressions with an optional /kind-spec/ for ctags and
> -- 
> 2.30.2
>
Ahmed S. Darwish May 4, 2023, 10 p.m. UTC | #2
Hi Nathan,

On Thu, 04 May 2023, Nathan Chancellor wrote:
>
> On Thu, May 04, 2023 at 10:18:33PM +0200, Ahmed S. Darwish wrote:
...
> > +	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.
>

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:

> > +		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
Masahiro Yamada May 5, 2023, 5:13 a.m. UTC | #3
On Fri, May 5, 2023 at 12:00 AM Ahmed S. Darwish <darwi@linutronix.de> wrote:
>
> Hi Nathan,
>
> On Thu, 04 May 2023, Nathan Chancellor wrote:
> >
> > On Thu, May 04, 2023 at 10:18:33PM +0200, Ahmed S. Darwish wrote:
> ...
> > > +   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.
> >
>
> 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:
>
> > > +           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



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.

    ...
Masahiro Yamada May 5, 2023, 5:17 a.m. UTC | #4
On Fri, May 5, 2023 at 7:13 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Fri, May 5, 2023 at 12:00 AM Ahmed S. Darwish <darwi@linutronix.de> wrote:
> >
> > Hi Nathan,
> >
> > On Thu, 04 May 2023, Nathan Chancellor wrote:
> > >
> > > On Thu, May 04, 2023 at 10:18:33PM +0200, Ahmed S. Darwish wrote:
> > ...
> > > > +   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.
> > >
> >
> > 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:
> >
> > > > +           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
>
>
>
> It 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.
Ahmed S. Darwish May 8, 2023, 2:11 p.m. UTC | #5
Hi Masahiro,

On Fri, 05 May 2023, Masahiro Yamada wrote:
>
> 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.

> 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
diff mbox series

Patch

diff --git a/scripts/tags.sh b/scripts/tags.sh
index ea31640b2671..1a6db535503b 100755
--- a/scripts/tags.sh
+++ b/scripts/tags.sh
@@ -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