Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kconfig parser #2553

Merged
merged 5 commits into from
May 26, 2020
Merged

Conversation

MaximeChretien
Copy link
Contributor

Kconfig is a language used for build configurations used in a lot of
open source projects (ex: linux, u-boot, barebox, ...)

Reference:
https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html

Kconfig is a language used for build configurations used in a lot of
open source projects (ex: linux, u-boot, barebox, ...)

Reference:
https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html

Signed-off-by: Maxime Chretien <maxime.chretien@bootlin.com>
@coveralls
Copy link

coveralls commented May 22, 2020

Coverage Status

Coverage increased (+0.006%) to 86.669% when pulling 4ab2053 on MaximeChretien:kconfig-parser into 062b562 on universal-ctags:master.

@codecov
Copy link

codecov bot commented May 22, 2020

Codecov Report

Merging #2553 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2553      +/-   ##
==========================================
+ Coverage   86.55%   86.56%   +0.01%     
==========================================
  Files         182      183       +1     
  Lines       38350    38384      +34     
==========================================
+ Hits        33192    33227      +35     
+ Misses       5158     5157       -1     
Impacted Files Coverage Δ
optlib/kconfig.c 100.00% <100.00%> (ø)
parsers/ruby.c 98.13% <0.00%> (+0.04%) ⬆️
parsers/asm.c 98.51% <0.00%> (+0.05%) ⬆️
parsers/cpreprocessor.c 93.11% <0.00%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c52a29d...4ab2053. Read the comment docs.

@cxw42
Copy link

cxw42 commented May 22, 2020

This is part of bootlin/elixir#130, in case anyone wonders about the use case.

parsers/kconfig.c Outdated Show resolved Hide resolved
@masatake
Copy link
Member

Thank you for making this pull request.

Could you add "Kconfig" as a new parser to docs/news.rst ?

Signed-off-by: Maxime Chretien <maxime.chretien@bootlin.com>
Signed-off-by: Maxime Chretien <maxime.chretien@bootlin.com>
@MaximeChretien
Copy link
Contributor Author

Hi,
Thanks for the review, I made the requested changes

@masatake
Copy link
Member

I also had a Kconfig parser that is derrived from linux/scripts/tags.sh.
I have not merged my parser because tags.sh is just GPLv2; it is not "or later version".

Your version is not based on the tags.sh script. So I can arrange my parser based on your parser.
Please, allow me to stack my parser on your pull request.

My version is not written in C. Both yours and mine just use regex pattern matching. So C is not needed.

@masatake
Copy link
Member

I made the kconfig parser tags more items like menu.
Such tags may help vim build "tree" structured navigation interface.

If elixir doesn't need it, you can turn off from the command line.
The way for disabling is written in the ctags.1 man page.

@masatake
Copy link
Member

@MaximeChretien, could you try my changes stacked on you changes?
If I introduced something you don't want, could you let me know?

@masatake
Copy link
Member

"mainmenu" kind should be renamed to "mainMenu".

New kinds are introduced:
* menu
* mainmenu
* kconfig (loaded by source directive)
* choice

CONFIG_FOO for FOO config is tagged as a "configPrefixed" extra tag.

scopes made by menus are tracked.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
The test inputs are taken from linux kernel.
@MaximeChretien
Copy link
Contributor Author

Hi,
It looks good for me, with some command line options it will work fine for Elixir.
But maybe configPrefixed should be disabled by default ? Because when it's activated each element appears twice, one with CONFIG_ and the other without

@MaximeChretien
Copy link
Contributor Author

And is there a way to have only the result with configPrefixed ?

@masatake
Copy link
Member

Hi,
It looks good for me, with some command line options it will work fine for Elixir.
But maybe configPrefixed should be disabled by default ? Because when it's activated each element appears twice, one with CONFIG_ and the other without

I can disable it. But... do you really want to disable it?
In scripts/tags.sh shipped as part of linux kernel, it is enabled by default.
As I wrote in the comment of kconfig.ctags, I developed this minor feature and it is really useful.

And is there a way to have only the result with configPrefixed ?

ctags itself doesn't have a feature to do it. However, --fields=+{extras} (or --fields=+E) option may help you.
Let me explain.

$ cat Kconfig.test
config FOO
	bool
$ ./ctags -o test.tags --fields=+'{extras}' Kconfig.test
$ cat test.tags 
!_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/;"	extras:pseudo
!_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/;"	extras:pseudo
!_TAG_OUTPUT_FILESEP	slash	/slash or backslash/;"	extras:pseudo
!_TAG_OUTPUT_MODE	u-ctags	/u-ctags or e-ctags/;"	extras:pseudo
!_TAG_PATTERN_LENGTH_LIMIT	96	/0 for no limit/;"	extras:pseudo
!_TAG_PROGRAM_AUTHOR	Universal Ctags Team	//;"	extras:pseudo
!_TAG_PROGRAM_NAME	Universal Ctags	/Derived from Exuberant Ctags/;"	extras:pseudo
!_TAG_PROGRAM_URL	https://ctags.io/	/official site/;"	extras:pseudo
!_TAG_PROGRAM_VERSION	0.0.0	/4ab20532/;"	extras:pseudo
CONFIG_FOO	Kconfig.test	/^config FOO$/;"	c	language:Kconfig	extras:configPrefixed
FOO	Kconfig.test	/^config FOO$/;"	c	language:Kconfig

The readtags command that is part of u-ctags, you can extract tags having the field.

$ readtags -Q '(and ($ "extras") (substr? ($ "extras") "onfigPrefixed"))' -t test.tags -ne -l
CONFIG_FOO	Kconfig.test	/^config FOO$/;"	kind:c	language:Kconfig	extras:configPrefixed

@MaximeChretien
Copy link
Contributor Author

I can disable it. But... do you really want to disable it?
In scripts/tags.sh shipped as part of linux kernel, it is enabled by default.
As I wrote in the comment of kconfig.ctags, I developed this minor feature and it is really useful.

If it's enabled by default in scripts/tags.sh, I guess it should be enabled here too, it's not that hard to disable it if needed.

ctags itself doesn't have a feature to do it. However, --fields=+{extras} (or --fields=+E) option may help you.

Ok I will look at that, currently what we do in Elixir is parsing the output of ctags with awk '{print "CONFIG_"$1" "$2" "$3}' so we have the CONFIG_ added at the beginning. I think we will stay with that as we will still need to use awk for formatting.
So for our needs I will need to disable the extra if it's enabled by default but it's not a problem ^^

@masatake
Copy link
Member

Thank you for replying and the contribution.

@masatake masatake merged commit 0c78c0c into universal-ctags:master May 26, 2020
@masatake
Copy link
Member

masatake commented May 26, 2020

BTW, Elixir can find "jiffies" for x86_64?
I guess it cannot.
If you turn on LdScript parser of u-ctags, Elixir may find it!

@MaximeChretien
Copy link
Contributor Author

The problem with jiffies is that this
https://elixir.bootlin.com/linux/latest/source/include/linux/jiffies.h#L81
is not identified as jiffies prototype and thus not listed in the definitions here :
https://elixir.bootlin.com/linux/latest/ident/jiffies

So I think there is a problem in the .h parsing
And I can confirm jiffies is not returned by ctags when parsing include/linux/jiffies.h

MaximeChretien added a commit to MaximeChretien/elixir that referenced this pull request May 26, 2020
The parser has been modified before being merged so we adapt to the
changes.

See : universal-ctags/ctags#2553

Signed-off-by: Maxime Chretien <maxime.chretien@bootlin.com>
@masatake
Copy link
Member

--kinds-C++=+x is needed to capture them.

% u-ctags -o - --kinds-C++=+x  ~/var/linux/include/linux/jiffies.h | grep ^jif          
jiffies	/home/yamato/var/linux/include/linux/jiffies.h	/^extern unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data jiffies;$/;"	x	language:C++	typeref:typename:unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data
jiffies_64	/home/yamato/var/linux/include/linux/jiffies.h	/^extern u64 __cacheline_aligned_in_smp jiffies_64;$/;"	x	language:C++	typeref:typename:u64 __cacheline_aligned_in_smp
jiffies_delta_to_clock_t	/home/yamato/var/linux/include/linux/jiffies.h	/^static inline clock_t jiffies_delta_to_clock_t(long delta)$/;"	f	language:C++	typeref:typename:clock_t
jiffies_delta_to_msecs	/home/yamato/var/linux/include/linux/jiffies.h	/^static inline unsigned int jiffies_delta_to_msecs(long delta)$/;"	flanguage:C++	typeref:typename:unsigned int
jiffies_to_nsecs	/home/yamato/var/linux/include/linux/jiffies.h	/^static inline u64 jiffies_to_nsecs(const unsigned long j)$/;"	f	language:C++	typeref:typename:u64

@MaximeChretien
Copy link
Contributor Author

--kinds-C++=+x is needed to capture them.

% u-ctags -o - --kinds-C++=+x  ~/var/linux/include/linux/jiffies.h | grep ^jif          
jiffies	/home/yamato/var/linux/include/linux/jiffies.h	/^extern unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data jiffies;$/;"	x	language:C++	typeref:typename:unsigned long volatile __cacheline_aligned_in_smp __jiffy_arch_data
jiffies_64	/home/yamato/var/linux/include/linux/jiffies.h	/^extern u64 __cacheline_aligned_in_smp jiffies_64;$/;"	x	language:C++	typeref:typename:u64 __cacheline_aligned_in_smp
jiffies_delta_to_clock_t	/home/yamato/var/linux/include/linux/jiffies.h	/^static inline clock_t jiffies_delta_to_clock_t(long delta)$/;"	f	language:C++	typeref:typename:clock_t
jiffies_delta_to_msecs	/home/yamato/var/linux/include/linux/jiffies.h	/^static inline unsigned int jiffies_delta_to_msecs(long delta)$/;"	flanguage:C++	typeref:typename:unsigned int
jiffies_to_nsecs	/home/yamato/var/linux/include/linux/jiffies.h	/^static inline u64 jiffies_to_nsecs(const unsigned long j)$/;"	f	language:C++	typeref:typename:u64

Oh nice ! Thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants