On Mon, Oct 14, 2024 at 11:14 PM David Hunter <david.hunter.linux@xxxxxxxxx> 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@xxxxxxxxx> > --- > V1 https://lore.kernel.org/all/20240913171205.22126-6-david.hunter.linux@xxxxxxxxx/ > > 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@xxxxxxxxxxxxxx/ 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
diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl index 8e23faab5d22..28faf8cd0e2a 100755 --- a/scripts/kconfig/streamline_config.pl +++ b/scripts/kconfig/streamline_config.pl @@ -146,7 +146,7 @@ my %objects; my %config2kfile; my %defaults; my $var; -my $iflevel = 0; +my $iflevel = -1; my @ifdeps; # prevent recursion @@ -206,7 +206,7 @@ sub read_kconfig { $config2kfile{"CONFIG_$config"} = $kconfig; # Add depends for 'if' nesting - for (my $i = 0; $i < $iflevel; $i++) { + for (my $i = 0; $i <= $iflevel; $i++) { if ($i) { $depends{$config} .= " " . $ifdeps[$i]; } else { @@ -221,6 +221,10 @@ sub read_kconfig { $depends{$config} = $1; } elsif ($state eq "DEP" && /^\s*depends\s+on\s+(.*)$/) { $depends{$config} .= " " . $1; + } elsif ($state eq "NONE" && /^\s*depends\s+on\s+(.*)$/) { + # "depends on" in the "NONE" state is from a choice block. + # Propagate the dependency to its member config options. + $ifdeps[$iflevel] .= ':' . $ifdeps[$iflevel]; } elsif ($state ne "NONE" && /^\s*def(_(bool|tristate)|ault)\s+(\S.*)$/) { my $dep = $3; $defaults{$config} = 1; @@ -253,11 +258,16 @@ sub read_kconfig { my @deps = split /[^a-zA-Z0-9_]+/, $deps; - $ifdeps[$iflevel++] = join ':', @deps; + $ifdeps[++$iflevel] = join ':', @deps; - } elsif (/^endif/) { + } elsif (/^\s*choice\s*$/) { - $iflevel-- if ($iflevel); + $state = "NONE"; + $ifdeps[++$iflevel] = ''; + + } elsif (/^(endif|endchoice)/) { + + --$iflevel if ($iflevel > -1); # stop on "help" and keywords that end a menu entry } elsif (/^\s*(---)?help(---)?\s*$/ || /^(comment|choice|menu)\b/) {