xconfig: Add shell expression support and fix choice default selection - #13
Merged
Merged
Conversation
Co-authored-by: guoweikang <18571063+guoweikang@users.noreply.github.com>
Co-authored-by: guoweikang <18571063+guoweikang@users.noreply.github.com>
Co-authored-by: guoweikang <18571063+guoweikang@users.noreply.github.com>
…eaningless assertions Co-authored-by: guoweikang <18571063+guoweikang@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix xconfig parser to support shell expressions in default values
xconfig: Add shell expression support and fix choice default selection
Feb 12, 2026
guoweikang
marked this pull request as ready for review
February 12, 2026 06:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Kconfig parser failed on shell expressions in default values and didn't apply choice defaults, breaking configuration for multi-architecture builds.
Changes
Shell Expression Evaluation
Expr::ShellExprvariant to AST for$(if condition,then,else)and$(VAR)syntaxshell_expr.rshandling nested conditionalsChoice Default Selection
extract_symbols_from_entriesto process Choice entries recursivelyExample
This now parses and evaluates correctly:
Generated config:
Original prompt
Fix xconfig: Support shell expressions in default values and Choice default selection
Problem 1: Shell Expression Support in Default Values
Currently, the xconfig parser cannot handle Kconfig default values with shell-style conditional expressions like:
Root Cause:
xtask/xconfig/src/kconfig/parser.rsonly supports simple expressions (symbols, constants, numbers)$()shell command substitution and nested$(if ...)conditionalsSolution:
$(if condition,then,else)syntaxProblem 2: Choice Default Values Not Applied in TUI
When a Kconfig
choiceblock has adefaultoption specified, the TUI (menuconfig) doesn't correctly select that option by default.Root Cause:
xtask/xconfig/src/ui/app.rs, theMenuConfigApp::new()method initializes values forConfigandMenuConfigitemsChoiceitems to set their default selectionsConfigState::build_from_entries()method creates Choice items but doesn't apply the default valueSolution:
MenuConfigApp::new()after building the config statedefaultfield, set the corresponding option as selectedImplementation Details
Files to Modify:
xtask/xconfig/src/kconfig/shell_expr.rs(NEW FILE)$(if condition, then_value, else_value)syntax$(VARIABLE_NAME)xtask/xconfig/src/kconfig/lexer.rsxtask/xconfig/src/kconfig/parser.rsdefaultvalues, check if the string contains shell expressionsxtask/xconfig/src/kconfig/expr.rsExpr::ShellExpr(String)variant to the expression enumxtask/xconfig/src/ui/app.rsMenuConfigApp::new()methodxtask/xconfig/src/kconfig/mod.rsshell_exprmodulextask/xconfig/src/cli/saveconfig.rsTesting Requirements
$(if SYMBOL,yes,no)expressionsThis pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.