Properly implement the config entries that are within the choice keyword
for kconfig. Currently, the script only stops the previous config entry
when a choice keyword is encountered.
When the keyword "choice" is encountered, do the following:
- distribute the lines immediately following the "choice"
keyword to each config entry inside the "choice" section.
- process the config entries with the distributed lines.
Signed-off-by: David Hunter <david.hunter.linux@gmail.com>
---
V1 https://lore.kernel.org/all/20240913171205.22126-6-david.hunter.linux@gmail.com/
V2
- changed the subject prefix
- changed the method for storing and distributing the choice
block. No longer using temp file.
---
scripts/kconfig/streamline_config.pl | 47 ++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl
index b7ed79c5e070..4149c4b344db 100755
--- a/scripts/kconfig/streamline_config.pl
+++ b/scripts/kconfig/streamline_config.pl
@@ -149,6 +149,34 @@ my $var;
my $iflevel = 0;
my @ifdeps;
+# distributes choice entries to different config options
+sub set_hash_value {
+ my %htable = %{$_[0]};
+ my $tmp_config = $_[1];
+ my $current_config = $_[2];
+ if (defined($htable{$tmp_config})) {
+ ${$_[0]}{$current_config} = $htable{$tmp_config};
+ }
+}
+
+# distribute choice config entries
+sub copy_configs {
+ my $tmp_config = "TMP_CONFIG";
+ my $choice_config = $_[0];
+ set_hash_value (\%depends, $tmp_config, $choice_config);
+ set_hash_value (\%selects, $tmp_config, $choice_config);
+ set_hash_value (\%prompts, $tmp_config, $choice_config);
+ set_hash_value (\%defaults, $tmp_config, $choice_config);
+}
+
+sub delete_temp_config {
+ my $tmp_config = "TMP_CONFIG";
+ $depends{$tmp_config} = undef;
+ $selects{$tmp_config} = undef;
+ $prompts{$tmp_config} = undef;
+ $defaults{$tmp_config} = undef;
+}
+
# prevent recursion
my %read_kconfigs;
@@ -163,6 +191,7 @@ sub read_kconfig {
my $source = "$ksource/$kconfig";
my $last_source = "";
+ my $choice_activated = 0;
# Check for any environment variables used
while ($source =~ /\$\((\w+)\)/ && $last_source ne $source) {
@@ -205,9 +234,13 @@ sub read_kconfig {
$config = $2;
$config2kfile{"CONFIG_$config"} = $kconfig;
+ if ($choice_activated) {
+ copy_configs $config;
+ }
+
# Add depends for 'if' nesting
for (my $i = 0; $i < $iflevel; $i++) {
- if ($i) {
+ if (defined($depends{$config})) {
$depends{$config} .= " " . $ifdeps[$i];
} else {
$depends{$config} = $ifdeps[$i];
@@ -260,8 +293,18 @@ sub read_kconfig {
$iflevel-- if ($iflevel);
# stop on "help" and keywords that end a menu entry
- } elsif (/^\s*(---)?help(---)?\s*$/ || /^(comment|choice|menu)\b/) {
+ } elsif (/^\s*(---)?help(---)?\s*$/ || /^(comment|menu)\b/) {
$state = "NONE";
+
+ # for choice, distribute the lines before each config entry to
+ # each config entry
+ } elsif (/^\s*choice\b/) {
+ $choice_activated = 1;
+ $config = "TMP_CONFIG";
+ $state = "NEW";
+ } elsif (/^\s*endchoice/) {
+ delete_temp_config;
+ $choice_activated = 0;
}
}
close($kinfile);
--
2.43.0
On Mon, Oct 14, 2024 at 11:14 PM David Hunter
<david.hunter.linux@gmail.com> wrote:
>
> Properly implement the config entries that are within the choice keyword
> for kconfig. Currently, the script only stops the previous config entry
> when a choice keyword is encountered.
>
> When the keyword "choice" is encountered, do the following:
> - distribute the lines immediately following the "choice"
> keyword to each config entry inside the "choice" section.
> - process the config entries with the distributed lines.
>
> Signed-off-by: David Hunter <david.hunter.linux@gmail.com>
> ---
> V1 https://lore.kernel.org/all/20240913171205.22126-6-david.hunter.linux@gmail.com/
>
> V2
> - changed the subject prefix
> - changed the method for storing and distributing the choice
> block. No longer using temp file.
> ---
> scripts/kconfig/streamline_config.pl | 47 ++++++++++++++++++++++++++--
> 1 file changed, 45 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl
> index b7ed79c5e070..4149c4b344db 100755
> --- a/scripts/kconfig/streamline_config.pl
> +++ b/scripts/kconfig/streamline_config.pl
> @@ -149,6 +149,34 @@ my $var;
> my $iflevel = 0;
> my @ifdeps;
>
> +# distributes choice entries to different config options
> +sub set_hash_value {
> + my %htable = %{$_[0]};
> + my $tmp_config = $_[1];
> + my $current_config = $_[2];
> + if (defined($htable{$tmp_config})) {
> + ${$_[0]}{$current_config} = $htable{$tmp_config};
> + }
> +}
> +
> +# distribute choice config entries
> +sub copy_configs {
> + my $tmp_config = "TMP_CONFIG";
> + my $choice_config = $_[0];
> + set_hash_value (\%depends, $tmp_config, $choice_config);
> + set_hash_value (\%selects, $tmp_config, $choice_config);
> + set_hash_value (\%prompts, $tmp_config, $choice_config);
> + set_hash_value (\%defaults, $tmp_config, $choice_config);
> +}
> +
> +sub delete_temp_config {
> + my $tmp_config = "TMP_CONFIG";
> + $depends{$tmp_config} = undef;
> + $selects{$tmp_config} = undef;
> + $prompts{$tmp_config} = undef;
> + $defaults{$tmp_config} = undef;
> +}
> +
I previously suggested checking how the 'if' statement is handled.
https://lore.kernel.org/lkml/CAK7LNAQ8D4OVT81iTVs8jjrBXX6Zgwc+VJ_vb7hb4J-vCZZN=g@mail.gmail.com/
These two behave in a similar way
regarding the dependency propagation.
if FOO
config A
bool "A"
config B
bool "B"
endif
choice
prompt "choose"
depends on FOO
config A
bool "A"
config B
bool "B"
endchoice
The inner A and B inherit the dependency on FOO.
I attached a completely-untested patch.
I think 'if' and 'choice' can share the code.
BTW, 'menu' also can have 'depends on'.
menu "menu"
depends on FOO
config A
bool "A"
config B
bool "B"
endmenu
This is not implemented, either.
I am not sure how much effort should be invested in this script, though.
--
Best Regards
Masahiro Yamada
On 11/5/24 18:33, Masahiro Yamada wrote: > I previously suggested checking how the 'if' statement is handled. > https://lore.kernel.org/lkml/CAK7LNAQ8D4OVT81iTVs8jjrBXX6Zgwc+VJ_vb7hb4J-vCZZN=g@mail.gmail.com/ > I think I understand now what you were saying. I misunderstood what you were saying because I thought that you were saying that the "if" blocks were not implemented. To paraphrase, I believe that you are saying that the "choice" blocks should have a similar style to the "if" blocks. I will take a look at the patch that you sent and figure out how it would work. I would like some clarification on the information in the choice blocks that are not "depends." Should those also have the same style as the "if" block? I am not sure if you saw this email: https://lore.kernel.org/all/994efba2-2829-4874-b5fa-9f5317f6ea6b@gmail.com/ There are lots of information, specifically "prompts" and "defaults" that are distributed to each of the config options in the "choice" blocks. > > BTW, 'menu' also can have 'depends on'. > > > menu "menu" > depends on FOO > config A > bool "A" > config B > bool "B" > endmenu > > > This is not implemented, either. > > I am not sure how much effort should be invested in this script, though. > > I will look into distributing the "menu" information.
On Wed, Nov 27, 2024 at 10:18 PM David Hunter
<david.hunter.linux@gmail.com> wrote:
>
> On 11/5/24 18:33, Masahiro Yamada wrote:
> > I previously suggested checking how the 'if' statement is handled.
> > https://lore.kernel.org/lkml/CAK7LNAQ8D4OVT81iTVs8jjrBXX6Zgwc+VJ_vb7hb4J-vCZZN=g@mail.gmail.com/
> >
> I think I understand now what you were saying. I misunderstood what you
> were saying because I thought that you were saying that the "if" blocks
> were not implemented.
>
> To paraphrase, I believe that you are saying that the "choice" blocks
> should have a similar style to the "if" blocks.
>
> I will take a look at the patch that you sent and figure out how it
> would work. I would like some clarification on the information in the
> choice blocks that are not "depends." Should those also have the same
> style as the "if" block?
>
I am not sure if I understood your question correctly, but I guess you are
referring to the similarity between the following two constructs:
[1]
choice
prompt "choice"
depends on X
[ code block]
endchoice
[2]
if X
[code block]
endif
choice ... endchoice
if ... endif
are similar in the sense that they both define a code block.
The if ... endif construct is always associated with a dependency.
The choice ... endchoice construct can optionally have a 'depends on'
statement. If it does, the dependency is applied to the entire code block
within choice ... endchoice.
> I am not sure if you saw this email:
> https://lore.kernel.org/all/994efba2-2829-4874-b5fa-9f5317f6ea6b@gmail.com/
>
> There are lots of information, specifically "prompts" and "defaults"
> that are distributed to each of the config options in the "choice" blocks.
- A choice entry cannot have a 'select' property.
- A choice entry should always have 'prompt', otherwise
the choice statement is non-sense.
- A choice entry can optionally have 'default'.
If 'default' is not explicitly specified, the first CONFIG option within
the choice block is the default.
- A choice entry can optionally have 'depends on'.
> >
> > BTW, 'menu' also can have 'depends on'.
> >
> >
> > menu "menu"
> > depends on FOO
> > config A
> > bool "A"
> > config B
> > bool "B"
> > endmenu
> >
> >
> > This is not implemented, either.
> >
> > I am not sure how much effort should be invested in this script, though.
> >
> >
> I will look into distributing the "menu" information.
--
Best Regards
Masahiro Yamada
On Mon, 14 Oct 2024 10:13:35 -0400
David Hunter <david.hunter.linux@gmail.com> wrote:
> Properly implement the config entries that are within the choice keyword
> for kconfig. Currently, the script only stops the previous config entry
> when a choice keyword is encountered.
>
> When the keyword "choice" is encountered, do the following:
> - distribute the lines immediately following the "choice"
> keyword to each config entry inside the "choice" section.
> - process the config entries with the distributed lines.
>
> Signed-off-by: David Hunter <david.hunter.linux@gmail.com>
> ---
> V1 https://lore.kernel.org/all/20240913171205.22126-6-david.hunter.linux@gmail.com/
>
> V2
> - changed the subject prefix
> - changed the method for storing and distributing the choice
> block. No longer using temp file.
> ---
> scripts/kconfig/streamline_config.pl | 47 ++++++++++++++++++++++++++--
> 1 file changed, 45 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl
> index b7ed79c5e070..4149c4b344db 100755
> --- a/scripts/kconfig/streamline_config.pl
> +++ b/scripts/kconfig/streamline_config.pl
> @@ -149,6 +149,34 @@ my $var;
> my $iflevel = 0;
> my @ifdeps;
>
> +# distributes choice entries to different config options
> +sub set_hash_value {
> + my %htable = %{$_[0]};
> + my $tmp_config = $_[1];
> + my $current_config = $_[2];
The other functions usually make this a single line. Also, we should give
names for all parameters.
sub set_hash_value {
my ($phtable, $tmp_config, $current_config) = @_;
my %htable = %{$phtable};
if (defined($htable{$tmp_config})) {
${$phtable}{$current_config} = $htable{$tmp_config};
}
}
Names make it a bit easier to read. Perl is already know as being very
cryptic, we don't need to make it worse.
> + if (defined($htable{$tmp_config})) {
> + ${$_[0]}{$current_config} = $htable{$tmp_config};
> + }
> +}
> +
> +# distribute choice config entries
> +sub copy_configs {
> + my $tmp_config = "TMP_CONFIG";
> + my $choice_config = $_[0];
And this as:
sub copy_configs {
my ($choice_config) = $@;
my $tmp_config = "TMP_CONFIG"
As parameters should always be first, which is how the rest of the file
does it. Consistency would be good.
-- Steve
> + set_hash_value (\%depends, $tmp_config, $choice_config);
> + set_hash_value (\%selects, $tmp_config, $choice_config);
> + set_hash_value (\%prompts, $tmp_config, $choice_config);
> + set_hash_value (\%defaults, $tmp_config, $choice_config);
> +}
> +
> +sub delete_temp_config {
> + my $tmp_config = "TMP_CONFIG";
> + $depends{$tmp_config} = undef;
> + $selects{$tmp_config} = undef;
> + $prompts{$tmp_config} = undef;
> + $defaults{$tmp_config} = undef;
> +}
> +
> # prevent recursion
> my %read_kconfigs;
>
> @@ -163,6 +191,7 @@ sub read_kconfig {
>
> my $source = "$ksource/$kconfig";
> my $last_source = "";
> + my $choice_activated = 0;
>
> # Check for any environment variables used
> while ($source =~ /\$\((\w+)\)/ && $last_source ne $source) {
> @@ -205,9 +234,13 @@ sub read_kconfig {
> $config = $2;
> $config2kfile{"CONFIG_$config"} = $kconfig;
>
> + if ($choice_activated) {
> + copy_configs $config;
> + }
> +
> # Add depends for 'if' nesting
> for (my $i = 0; $i < $iflevel; $i++) {
> - if ($i) {
> + if (defined($depends{$config})) {
> $depends{$config} .= " " . $ifdeps[$i];
> } else {
> $depends{$config} = $ifdeps[$i];
> @@ -260,8 +293,18 @@ sub read_kconfig {
> $iflevel-- if ($iflevel);
>
> # stop on "help" and keywords that end a menu entry
> - } elsif (/^\s*(---)?help(---)?\s*$/ ||
> /^(comment|choice|menu)\b/) {
> + } elsif (/^\s*(---)?help(---)?\s*$/ || /^(comment|menu)\b/) {
> $state = "NONE";
> +
> + # for choice, distribute the lines before each config entry to
> + # each config entry
> + } elsif (/^\s*choice\b/) {
> + $choice_activated = 1;
> + $config = "TMP_CONFIG";
> + $state = "NEW";
> + } elsif (/^\s*endchoice/) {
> + delete_temp_config;
> + $choice_activated = 0;
> }
> }
> close($kinfile);
© 2016 - 2026 Red Hat, Inc.