how to merge multiple Kconfig(absolute path) by `source "${var}"`
Neutree opened this issue · 8 comments
I want to merge three Kconfig
file to one,
- root Kconfig(abs path:
/home/aaa/Kconfig
):
mainmenu "C/CPP CMake project framework Kconfig configuration"
menu "Components configuration"
source "$(SUB_KCONFIGS)"
endmenu
- Kconfig 1(abs path:
/home/aaa/abcd/Kconfig
):
...
- Kconfig 2(abs path:
/root/aaa/abcd/Kconfig
):
...
and I want to merge Kconfig 2 and Kconfig 1 to root Kconfig like this way
cd /home/aaa/
export SUB_KCONFIGS="/home/aaa/abcd/Kconfig /root/aaa/abcd/Kconfig"
menuconfig
but it's not work, maybe because of this code:
Lines 2846 to 2856 in f1e6f32
for temporary use, I changed code to
filenames = pattern.split(" ")
if not os.path.exists(filenames[0]):
filenames = sorted(iglob( join(self._srctree_prefix, pattern) ))
but can you tell me what's the right way to merge these three kconfig files?
best regards!
Hello,
source
currently isn't designed to include more than one file, except via globbing.
To implement it, you'd have to do something like this, so that the code works with a list of patterns instead of a single pattern (untested):
elif t0 in _SOURCE_TOKENS:
patterns = self._expect_str_and_eol().split()
if t0 in _REL_SOURCE_TOKENS:
patterns = [join(dirname(self._filename), pattern)
for pattern in patterns]
filenames = []
for pattern in patterns:
filenames += glob(join(self,_srctree_prefix, pattern))
filenames.sort()
# Same as before...
Could add a helper too and do this instead:
elif t0 in _SOURCE_TOKENS:
for pattern in self._expect_str_and_eol().split():
self._source_pattern(t0, pattern)
_source_pattern()
would be the same as the old logic.
How are you planning to use it by the way?
One thing that makes it feel a bit iffy to me is that the Kconfig source
requires its argument to be quoted. Would be nice if it had been designed to work like include
in make
from the beginning, where you can do this:
include foo bar $(baz) qaz/Kconfig.*
This looks more confusing:
include "foo bar $(baz) qaz/Kconfig.*"
Is there any pattern to how the Kconfig files are placed by the way?
For example, if all component Kconfigs are placed in components/<component name>/Kconfig
, and there's also an additional Kconfig file pointed at by $FOO
, then you could do this instead:
(o)source "components/*/Kconfig"`
(o)source "$(FOO)"
osource
makes it an optional source, turning it into a no-op if the file(s) don't exist.
(Unrelated, but IMO, it's often nicer to just list all the files, if you know them. That way, you don't risk any "scratch" files that are not checked in getting globbed up, and it's handy for grep
ing. :)
Thanks!
I'am writing a template project by cmake and your kconfiglib here,
directly include files via globbing is ok by (o)source "components/*/Kconfig"
, and in some scenarios this is more intuitive and easy to use.
But for my template repository, the example(project) folder may be separated into two places, so I need to use absolute path or multiple path, e.g. in my repository, the source file from components/*/Kconfig
and examples/*/Kconfig
, and if I place my example in /root/temp/demo1
, it'll need to include '/root/temp/demo1/*/Kconfig',
so I want to update the path in cmake or script, so it would be great if you could support multiple pattern.
And I also think the keyword include
is better than source
Think this could work, moving some of the work over to Kconfig?
source "components/*/Kconfig"
source "examples/*/Kconfig"
source "$(SOME_VARIABLE)/*/Kconfig"
(Could list the files instead of globbing too.)
Want to make sure that it's something that can't be easily solved in other ways. One thing it would break is spaces in filenames, though I'm not sure if anyone uses those.
Wonder if it might be okay to just include a comment like
# Your component Kconfig files are sourced here. You can refer to the foo directory with $(FOO).
Just editing the file directly removes one layer of indirection. Would it cause problems?
Ok, I will use this method first, and It can meet the current needs for the time being.
And it would be nice to support each include command can contain multiple files, the spacer may use more special symbols such as commas (,
) instead of spaces.
source "file1, file2, file3, ..."
include "file1, file2, file3, ..."
Thank you for your patient reply, feel free to close this issue~~
Ok, I will use this method first, and It can meet the current needs for the time being.
Alright, great!
And it would be nice to support each include command can contain multiple files, the spacer may use more special symbols such as commas (
,
) instead of spaces.source "file1, file2, file3, ..." include "file1, file2, file3, ..."
Files with ,
in them might show up too. Bit worried about making it too magic.
Thank you for your patient reply, feel free to close this issue~~
No problems. Open a new one if you run into anything else.
Hi @ulfalizer. Would you be interested in a PR implementing this feature?
I'm thinking that maybe lsource
(l
for list) could be added to support inclusion of all files.
My intention is to use it for example here https://github.com/espressif/esp-idf/blob/master/Kconfig#L67 like lsource "$VAR"
which should be equivalent with
source "path1"
source "path2"
source "path3"
if $VAR
is "path1 path2 path3"
.
We cannot use globbing because we want to process the list of files resulted from globbing (mostly remove which are currently not needed).