Skip to content

Kconfig: Add build system integration and test application#12773

Merged
kaspar030 merged 3 commits intoRIOT-OS:masterfrom
leandrolanzieri:pr/makefiles/kconfig
Dec 4, 2019
Merged

Kconfig: Add build system integration and test application#12773
kaspar030 merged 3 commits intoRIOT-OS:masterfrom
leandrolanzieri:pr/makefiles/kconfig

Conversation

@leandrolanzieri
Copy link
Copy Markdown
Contributor

@leandrolanzieri leandrolanzieri commented Nov 21, 2019

Contribution description

This PR adds the Kconfig integration with the build system, for the first phase of migration, as discussed in the mailing list and the last maintainers assembly.

It makes use of the tool introduced in #12695. This also adds a small test application to see this in action. The $(BINDIR)/generated/autoconf.h header file is used to pass the configuration parameters to applications.

Testing procedure

Currently only the test application (tests/kconfig) is exposing configuration options:

  • Run make all test -C tests/kconfig to use the default configuration provided in the app.config file. Test should pass.
  • Modify configurations by editing app.config, by adding an user.config file or by running make menuconfig -C tests/kconfig, if you want an interface.
  • Take a look at the generated files in $(BINDIR)/generated.

Issues/PRs references

Depends on #12695

@leandrolanzieri leandrolanzieri added Area: build system Area: Build system Type: new feature The issue requests / The PR implemements a new feature for RIOT State: waiting for other PR State: The PR requires another PR to be merged first TF: Config Marks issues and PRs related to the work of the Configuration Task Force labels Nov 21, 2019
@kaspar030
Copy link
Copy Markdown
Contributor

I'm getting an error compiling tests/kconfig for native:

Building application "tests_kconfig" for "native" with MCU "native".

Traceback (most recent call last):
  File "/home/kaspar/src/riot.tmp/dist/tools/kconfiglib/merge_config.py", line 82, in <module>
    kconf = Kconfig(sys.argv[1])
  File "/home/kaspar/src/riot.tmp/dist/tools/kconfiglib/kconfiglib.py", line 1056, in __init__
    self._parse_block(None, self.top_node, self.top_node)
  File "/home/kaspar/src/riot.tmp/dist/tools/kconfiglib/kconfiglib.py", line 2931, in _parse_block
    prev = self._parse_block(None, parent, prev)
  File "/home/kaspar/src/riot.tmp/dist/tools/kconfiglib/kconfiglib.py", line 2856, in _parse_block
    while self._next_line():
  File "/home/kaspar/src/riot.tmp/dist/tools/kconfiglib/kconfiglib.py", line 2183, in _next_line
    self._tokens = self._tokenize(line)
  File "/home/kaspar/src/riot.tmp/dist/tools/kconfiglib/kconfiglib.py", line 2467, in _tokenize
    self._parse_error("unknown tokens in line")
  File "/home/kaspar/src/riot.tmp/dist/tools/kconfiglib/kconfiglib.py", line 3820, in _parse_error
    raise KconfigError("{}couldn't parse '{}': {}".format(
kconfiglib.KconfigError: bin/native/generated/Kconfig.dep:1: couldn't parse 'config MODULE_AUTO_INIT\NBOARD\NCORE\NCORE_MSG\NCPU\NNATIVE_DRIVERS\NPERIPH\NPERIPH_COMMON\NPERIPH_GPIO\NPERIPH_PM\NPERIPH_UART\NSYS': unknown tokens in line
make: *** [/home/kaspar/src/riot.tmp/makefiles/kconfig.mk:72: /home/kaspar/src/riot.tmp/tests/kconfig/bin/native/generated/merged.config] Error 1

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

I'm getting an error compiling tests/kconfig for native:

The good old 'it works on my machine' :-) . This should be more portable now.

Copy link
Copy Markdown

@ulfalizer ulfalizer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spies a bit

Since it's easy to miss, this page covers some good practices and pitfalls and things that I've seen confuse people re. Kconfig in practice by the way.

@kaspar030
Copy link
Copy Markdown
Contributor

kaspar030 commented Nov 25, 2019

This compiles now just fine.

With an empty bin/ folder, I can do "make menuconfig", disable msg2, change msg one, do "make" and see the results.
If I now do "make menuconfig" again, re-enabling msg2, re-doing "make", the built binary still shows message one. Is that intended?

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

This compiles now just fine.

Nice! Thanks for confirming.

With an empty bin/ folder, I can do "make menuconfig", disable msg2, change msg one, do "make" and see the results.
If I now do "make menuconfig" again, re-enabling msg2, re-doing "make", the built binary still shows message one. Is that intended?

After re-enabling msg2 it shows up again (together with msg1), right? If that is the case then it is correct. msg1 and msg2 are independent.

The idea was to show with msg1 how configuration options would be handled in modules. When you enable "Configure message 1" (KCONFIG_APP_MSG_1), as the help string mentions, what you are doing is enabling the configuration of that message via Kconfig. So it will allow the user to change the text of msg1 via Kconfig symbol APP_MSG_1_TEXT. When that is not enabled then the default text from the header file will be used.

In short, msg1 is meant to be always on, you can only modify the text itself.
On the other hand, msg2 actually allows to enable/disable the message.

@kaspar030
Copy link
Copy Markdown
Contributor

kaspar030 commented Nov 25, 2019

After re-enabling msg2 it shows up again (together with msg1), right?

No, it doesn't. I think just doing "make" doesn't rebuild properly.

Like this:

  1. cd tests/kconfig
  2. rm -Rf bin
  3. make
  4. ... run .elf, see both message 1 and MSG_2
  5. make menuconfig, disable MSG2, save
  6. make
  7. ... run .elf, MSG_2 is still shown.

I usually always build with "make clean all", but IIRC this will clean bin/ and thus the changed configuration.

@kaspar030
Copy link
Copy Markdown
Contributor

5\. `make menuconfig`, disable MSG2, save

I can confirm that "bin/native/generated/merged.config" contains # CONFIG_APP_MSG_2 is not set.

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

5\. `make menuconfig`, disable MSG2, save

I can confirm that "bin/native/generated/merged.config" contains # CONFIG_APP_MSG_2 is not set.

Is CONFIG_APP_MSG_2 being defined in bin/native/generated/autoconf.h?

@kaspar030
Copy link
Copy Markdown
Contributor

Is CONFIG_APP_MSG_2 being defined in bin/native/generated/autoconf.h?

no, not present there.

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

Is CONFIG_APP_MSG_2 being defined in bin/native/generated/autoconf.h?

no, not present there.

Ok, so the header file is being generated correctly. I don't see why the binary would not be updated as autoconf.h is dependency, and it's changing. Can you confirm that the last-change date of the binary stays the same after changing autoconf.h?

After re-enabling msg2 it shows up again (together with msg1), right?

No, it doesn't. I think just doing "make" doesn't rebuild properly.

Like this:

  1. cd tests/kconfig
  2. rm -Rf bin
  3. make
  4. ... run .elf, see both message 1 and MSG_2
  5. make menuconfig, disable MSG2, save
  6. make
  7. ... run .elf, MSG_2 is still shown.

I usually always build with "make clean all", but IIRC this will clean bin/ and thus the changed configuration.

I can't reproduce the issue. I followed the steps and after disabling msg2 the .elf is updated and the message is gone.

@kaspar030
Copy link
Copy Markdown
Contributor

I can't reproduce the issue. I followed the steps and after disabling msg2 the .elf is updated and the message is gone.

If I disable ccache ($ unset CCACHE), this works as expected (msg_2 gone in step 7.).

@kaspar030
Copy link
Copy Markdown
Contributor

If I disable ccache ($ unset CCACHE), this works as expected (msg_2 gone in step 7.).

I don't understand why.
touch bin/native/generated/autoconf.h && make QUIET=0 correctly rebuilds everything, if ccache is not used. With ccache enabled, ccache/gcc is not even called, so ccache is not returning a wrong cache result.

@kaspar030
Copy link
Copy Markdown
Contributor

I think the issue is that ccache transform absolute path's to relative paths within the dependency file, which make doesn't seem to match properly. So probably, with ccache, the automatic dependencies were broken before. With ccache, always rebuilding with "clean" isn't nearly as slow as depending on make's dependency resolution, so noone realized.

Problem is that the kconfig user configuration sits in "bin/" (and gets cleared with "make clean"), so as of now, it's either kconfig or ccache.

@kaspar030
Copy link
Copy Markdown
Contributor

I think the issue is that ccache transform absolute path's to relative paths within the dependency file, which make doesn't seem to match properly.

Hm, but touching riotbuild.h properly causes a rebuild independent of ccache enabled or not.

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

I think the issue is that ccache transform absolute path's to relative paths within the dependency file, which make doesn't seem to match properly.

Hm, but touching riotbuild.h properly causes a rebuild independent of ccache enabled or not.

I now enabled ccache and can confirm that the binary is not being updated. I managed to get the application re-compiled by manually adding the autoconf.h file to ccache 'extra_files_to_hash' configuration. So I think it's as you say, there is some dependency problem with ccache.

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

@kaspar030 I added autoconf.h as a dependency for the object files, so now when the configurations are changed the binaries should be re-compiled.

@leandrolanzieri leandrolanzieri removed the State: waiting for other PR State: The PR requires another PR to be merged first label Nov 25, 2019
@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

I rebased to current master, now that #12695 is merged.

@cgundogan cgundogan added Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Dec 2, 2019
@cgundogan cgundogan added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 3, 2019
@kaspar030
Copy link
Copy Markdown
Contributor

BTW you can limit what murdock builds by adding a "REMOVEME" commit that sets e.g., "APPS=examples/hello-world" and/or "BOARDS=samr21-xpro" in .murdock, so only a subset is built. That helps improving iteration time for figuring out a specific issue.

@kaspar030
Copy link
Copy Markdown
Contributor

I can easily trigger the issue locally with BOARD=nrf52dk make -Ctests/pkg_microcoap clean all -j

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

Nice! Thanks @kaspar030, that worked!

@cgundogan
Copy link
Copy Markdown
Member

Murdock is happy now! @kaspar030 anything else that is missing?

- The autoconf.h header file, generated with the current Kconfig
  configurations, is added as a build dependency.

- autoconf.h depends on the proper tool (genconfig) and a Kconfig.dep
  which contains the dependencies for the given application and board,
  this is generated from $(USEMODULE).

- The menuconfig target is added, to allow the configuration of modules
  using the Kconfig system.
@kaspar030
Copy link
Copy Markdown
Contributor

Murdock is happy now! @kaspar030 anything else that is missing?

Nope, LGTM.

@gschorcht
Copy link
Copy Markdown
Contributor

gschorcht commented Jan 10, 2020

@leandrolanzieri A short question. At the moment, it is possible to define menu items in Kconfig depending on enabled modules. Would it also be possible to enable a module for compilation by enabling an option in Kconfig? For example:

    ESP32 --->
        [  ] ESP-WiFi settings
        [  ] ESP-NOW setting

Enabling the ESP-WiFi settings would enter into the configuration menu for ESP-WiFi and would add USEMODULE += esp_wifi to the make configuration.

The background for my question is that a lot of configurations are done in RIOT using pseudomodules. Now, where we have a menu driven way for configuration, it would be nice to be able to enable or disable also modules.

@gschorcht
Copy link
Copy Markdown
Contributor

@leandrolanzieri One further question. I'm working on exposing ESP configurations with Kconfig. In all your PRs, you use menuconfig KCONFIG_MODULE_XYZ instead of menu "XYZ" for sub-categories. This has the disadvantage that the user must first select the subcategory before he can enter the configuration.

Is this the desired behavior? It feels a little strange from the user's perspective. It suggests that this enables the module.

Are there any design rules or coding conventions, or could I also use menu "XYZ"?

@leandrolanzieri
Copy link
Copy Markdown
Contributor Author

@gschorcht

Would it also be possible to enable a module for compilation by enabling an option in Kconfig?

Not at the moment, but that's part of the plan for the second phase of migration (to resolve dependencies via Kconfig). The problem is that modules should be resolved by the time the Kconfig configurator is called. If we enable modules via Kconfig that may result in new modules being enabled, so the input Kconfig had may no longer be valid.

I'm working on exposing ESP configurations with Kconfig

Thanks for working on this!

Is this the desired behavior? It feels a little strange from the user's perspective. It suggests that this enables the module.

This is the intended behavior. During this phase of migration we are making the configuration of modules via Kconfig optional (that's why prompts say 'Configure ', and help strings also mention this). In the future though, the idea is that it actually enables the module as you suggest.

I wrote some documentation in #13040, there you can find more background and some conventions.

@gschorcht
Copy link
Copy Markdown
Contributor

@leandrolanzieri Thanks for the explanation.

This is the intended behavior. During this phase of migration we are making the configuration of modules via Kconfig optional (that's why prompts say 'Configure ', and help strings also mention this). In the future though, the idea is that it actually enables the module as you suggest.

OK, then I will do it in same way.

I wrote some documentation in #13040, there you can find more background and some conventions.

I will have look on it later this week.

@ekuiter ekuiter mentioned this pull request Feb 14, 2026
66 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines TF: Config Marks issues and PRs related to the work of the Configuration Task Force Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants