ext,scons: Make kconfiglib available for use in SCons.

Change-Id: Ie9c902819ed0750a04f8318911fa914701c2a0fe
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/56755
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
This commit is contained in:
Gabe Black
2022-02-08 19:22:17 -08:00
parent f847b4a5e9
commit 443067253c
104 changed files with 21884 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
config MODULES
def_bool y
config BOOL
bool "bool 1"
config STRING
string "string"
config IGNOREME
bool "ignore me"
default y

View File

@@ -0,0 +1,230 @@
config MODULES
bool "modules"
option modules
# Things that should never be .assignable
if UNDEFINED && "const"
endif
config NO_PROMPT
bool
config STRING
string "string"
config INT
int "int"
config HEX
hex "hex"
# Non-selected symbols
config Y_VIS_BOOL
bool "y-vis bool"
config M_VIS_BOOL
bool "m-vis bool" if m
config N_VIS_BOOL
bool "n-vis bool" if n
config Y_VIS_TRI
tristate "y-vis tri"
config M_VIS_TRI
tristate "m-vis tri" if m
config N_VIS_TRI
tristate "n-vis tri" if n
# Symbols selected to y
config Y_SELECTOR
def_tristate y
select Y_SEL_Y_VIS_BOOL
select Y_SEL_M_VIS_BOOL
select Y_SEL_N_VIS_BOOL
select Y_SEL_Y_VIS_TRI
select Y_SEL_M_VIS_TRI
select Y_SEL_N_VIS_TRI
config Y_SEL_Y_VIS_BOOL
bool "y-sel y-vis bool"
config Y_SEL_M_VIS_BOOL
bool "y-sel m-vis bool" if m
config Y_SEL_N_VIS_BOOL
bool "y-sel n-vis bool" if n
config Y_SEL_Y_VIS_TRI
tristate "y-sel y-vis tri"
config Y_SEL_M_VIS_TRI
tristate "y-sel m-vis tri" if m
config Y_SEL_N_VIS_TRI
tristate "y-sel n-vis tri" if n
# Symbols selected to m
config M_SELECTOR
def_tristate m
select M_SEL_Y_VIS_BOOL
select M_SEL_M_VIS_BOOL
select M_SEL_N_VIS_BOOL
select M_SEL_Y_VIS_TRI
select M_SEL_M_VIS_TRI
select M_SEL_N_VIS_TRI
config M_SEL_Y_VIS_BOOL
bool "m-sel y-vis bool"
config M_SEL_M_VIS_BOOL
bool "m-sel m-vis bool" if m
config M_SEL_N_VIS_BOOL
bool "m-sel n-vis bool" if n
config M_SEL_Y_VIS_TRI
tristate "m-sel y-vis tri"
config M_SEL_M_VIS_TRI
tristate "m-sel m-vis tri" if m
config M_SEL_N_VIS_TRI
tristate "m-sel n-vis tri" if n
# Symbols implied to y
config Y_IMPLIER
def_tristate y
imply Y_IMP_Y_VIS_BOOL
imply Y_IMP_M_VIS_BOOL
imply Y_IMP_N_VIS_BOOL
imply Y_IMP_Y_VIS_TRI
imply Y_IMP_M_VIS_TRI
imply Y_IMP_N_VIS_TRI
config Y_IMP_Y_VIS_BOOL
bool "y-imp y-vis bool"
config Y_IMP_M_VIS_BOOL
bool "y-imp m-vis bool" if m
config Y_IMP_N_VIS_BOOL
bool "y-imp n-vis bool" if n
config Y_IMP_Y_VIS_TRI
tristate "y-imp y-vis tri"
config Y_IMP_M_VIS_TRI
tristate "y-imp m-vis tri" if m
config Y_IMP_N_VIS_TRI
tristate "y-imp n-vis tri" if n
# Symbols implied to m (never affects assignable values)
config M_IMPLIER
def_tristate m
imply M_IMP_Y_VIS_BOOL
imply M_IMP_M_VIS_BOOL
imply M_IMP_N_VIS_BOOL
imply M_IMP_Y_VIS_TRI
imply M_IMP_M_VIS_TRI
imply M_IMP_N_VIS_TRI
config M_IMP_Y_VIS_BOOL
bool "m-imp y-vis bool"
config M_IMP_M_VIS_BOOL
bool "m-imp m-vis bool" if m
config M_IMP_N_VIS_BOOL
bool "m-imp n-vis bool" if n
config M_IMP_Y_VIS_TRI
tristate "m-imp y-vis tri"
config M_IMP_M_VIS_TRI
tristate "m-imp m-vis tri" if m
config M_IMP_N_VIS_TRI
tristate "m-imp n-vis tri" if n
# Symbols in y-mode choice
choice Y_CHOICE
bool "y-mode choice"
config Y_CHOICE_BOOL
bool "y-mode choice bool"
config Y_CHOICE_TRISTATE
tristate "y-mode choice tristate"
config Y_CHOICE_N_VIS_TRISTATE
tristate "y-mode choice tristate invisible" if n
endchoice
# Symbols in m/y-mode choice
choice MY_CHOICE
tristate "m/y-mode choice"
config MY_CHOICE_BOOL
bool "m/y-mode choice bool"
config MY_CHOICE_TRISTATE
tristate "m/y-mode choice tristate"
config MY_CHOICE_N_VIS_TRISTATE
tristate "m/y-mode choice tristate invisible" if n
endchoice
# Choices with some other possible modes
choice NMY_CHOICE
tristate "n/m/y-mode choice"
optional
endchoice
choice NY_CHOICE
bool "n/y-mode choice"
optional
endchoice
choice NM_CHOICE
tristate "n/m-mode choice" if m
optional
endchoice
choice M_CHOICE
tristate "m-mode choice" if m
endchoice
choice N_CHOICE
tristate "n-mode choice" if n
endchoice

View File

@@ -0,0 +1,198 @@
config MODULES
bool "modules"
# bool/tristate and optional
choice BOOL
bool "bool"
config B_1
tristate "B_1"
config B_2
tristate "B_2"
endchoice
choice BOOL_OPT
bool "bool optional"
optional
config BO_1
tristate "BO_1"
config BO_2
tristate "BO_2"
endchoice
choice TRISTATE
tristate "tristate"
config T_1
tristate "T_1"
config T_2
tristate "T_2"
endchoice
choice TRISTATE_OPT
tristate "tristate optional"
optional
config TO_1
tristate "TO_1"
config TO_2
tristate "TO_2"
endchoice
# m-visibility
choice BOOL_M
bool "bool m" if m
config BM_1
tristate "BM_1"
config BM_2
tristate "BM_2"
endchoice
choice TRISTATE_M
tristate "tristate m" if m
config TM_1
tristate "TM_1"
config TM_2
tristate "TM_2"
endchoice
# Defaults
config TRISTATE_SYM
tristate "tristate"
choice DEFAULTS
bool "defaults"
default OPT_1 if n
default OPT_2 if TRISTATE_SYM
default OPT_4
config OPT_1
tristate "OPT_1"
config OPT_2
tristate "OPT_2"
config OPT_3
tristate "OPT_3"
config OPT_4
tristate "OPT_4"
endchoice
choice DEFAULTS_NOT_VISIBLE
bool "defaults not visible"
# Skipped due to condition
default OPT_6 if n
# Skipped because OPT_7 is not visible
default OPT_7
# This one should apply
default OPT_8
config OPT_5
tristate "OPT_5"
config OPT_6
tristate "OPT_6"
config OPT_7
tristate "OPT_7" if n
config OPT_8
tristate "OPT_8"
config OPT_9
tristate "OPT_9"
endchoice
# Choices without an explicitly specified type should get the type of the first
# symbol with a type
choice NO_TYPE_BOOL
prompt "no type bool"
config NTB_1
bool "NTB_1"
config NTB_2
tristate "NTB_2"
endchoice
choice NO_TYPE_TRISTATE
prompt "no type tristate"
config NTT_1
config NTT_2
tristate "NTB_2"
config NTT_3
bool "NTT_3"
endchoice
# Choice items without an explicitly specified type should get the type of the
# choice
choice MISSING_MEMBER_TYPES_1
bool "missing member types"
config MMT_1
config MMT_2
config MMT_3
tristate
endchoice
choice MISSING_MEMBER_TYPES_2
config MMT_4
config MMT_5
bool
endchoice
# Choice where the default selection (the first symbol) depends on another
# symbol. If that symbol becomes 'n', the default selection should change to
# the first visible symbol in the choice.
choice DEFAULT_WITH_DEP
bool "default with dep"
config A
bool "A"
depends on DEP
config B
bool "B"
endchoice
config DEP
bool "dep"
# Choice with symbols that shouldn't be considered choice symbols because they
# depend on the preceding symbol. This might be a kconfig bug, but some things
# use it, so we need to emulate it.
choice WEIRD_SYMS
bool "weird symbols that aren't considered part of the choice"
# Only WS1 is part of the choice
config WS1
bool "WS1"
config WS2
bool "WS2"
depends on WS1
config WS3
bool
depends on WS2
config WS4
bool
depends on WS1
config WS5
bool "WS5" if WS1
# 'if' has the same effect, so only WS6 is part of the choice
config WS6
bool "WS6"
if WS6
config WS7
bool
config WS8
bool "WS8"
endif
# Should also be part of the choice
config WS9
bool "WS9"
endchoice

View File

@@ -0,0 +1,8 @@
# $FOO is "defconfig_2"
config A
string
option defconfig_list
default "Kconfiglib/tests/defconfig_1" if y && !n && n
default "Kconfiglib/tests/$FOO"
default "Kconfiglib/tests/defconfig_1"

View File

@@ -0,0 +1,10 @@
# $FOO is "defconfig_2"
# Should produce None due to the "depends on n"
config A
string
depends on n
option defconfig_list
default "Kconfiglib/tests/defconfig_1" if y && !n && n
default "Kconfiglib/tests/$FOO"
default "Kconfiglib/tests/defconfig_1"

View File

@@ -0,0 +1,5 @@
config A
string
option defconfig_list
default "Kconfiglib/tests/non_existent_1"
default "Kconfiglib/tests/non_existent_2"

View File

@@ -0,0 +1,5 @@
config A
string
option defconfig_list
default "sub/defconfig_in_sub" # Assume this doesn't exist
default "Kconfiglib/tests/defconfig_2"

View File

@@ -0,0 +1,173 @@
# We verify that the properties below end up in definition order
config MULTIDEF
bool
default A
default B
select AA
imply AA
if FOO
config MULTIDEF
default C
default D
select BB
imply BB
if BAR
config MULTIDEF
default E
default F
select CC
imply CC
menu "menu"
config MULTIDEF
default G
default H
select DD
imply DD
config MULTIDEF
default I
default J
select EE
imply EE
endmenu
config MULTIDEF
default K
default L
select FF
imply FF
config MULTIDEF
default M
default N
select GG
imply GG
endif
config MULTIDEF
default O
default P
select HH
select II
imply HH
imply II
endif
config MULTIDEF
default Q
default R
select JJ
imply JJ
# Same test with choice symbols involved
config MULTIDEF_CHOICE
bool
select A
choice
bool "choice"
config MULTIDEF_CHOICE
bool "multidef choice"
select B
endchoice
config MULTIDEF_CHOICE
bool
select C
# Same test with ranges involved
config MULTIDEF_RANGE
int
range A _
menu "menu"
config MULTIDEF_RANGE
int
range B _
if FOO
config MULTIDEF_RANGE
int
range C _
endif
config MULTIDEF_RANGE
int
range D _
endmenu
config MULTIDEF_RANGE
int
range E _
config MULTIDEF_RANGE
int
range F _
# Same test for a choice
choice MULTICHOICE
bool "choice"
default A
config A
bool "A"
config B
bool "B"
config C
bool "C"
config D
bool "C"
config E
bool "C"
endchoice
if FOO
choice MULTICHOICE
default B
endchoice
menu "menu"
choice MULTICHOICE
default C
endchoice
endmenu
choice MULTICHOICE
default D
endchoice
endif
choice MULTICHOICE
default E
endchoice

View File

@@ -0,0 +1,3 @@
config FOO
bool
depends on FOO

View File

@@ -0,0 +1,3 @@
config FOO
bool
select FOO

View File

@@ -0,0 +1,48 @@
config A
bool
depends on B
config B
bool
depends on C = 7
config C
int
range D 8
config D
int
default 3 if E
default 8
config E
bool
config F
bool
select E if G
config G
bool
depends on H
choice
bool "choice"
config H
bool "H"
depends on I
endchoice
choice
bool "choice" if J
config I
bool "I"
endchoice
config J
bool
depends on A

View File

@@ -0,0 +1,3 @@
config FOO
bool
default FOO

View File

@@ -0,0 +1,3 @@
config FOO
bool
default y if FOO

View File

@@ -0,0 +1,7 @@
config FOO
bool
depends on BAR
config BAR
bool
depends on FOO

View File

@@ -0,0 +1,7 @@
config FOO
bool
select BAR
config BAR
bool
select FOO

View File

@@ -0,0 +1,6 @@
config FOO
bool
config BAR
bool
select FOO if FOO

View File

@@ -0,0 +1,11 @@
choice
bool "choice"
config FOO
bool "foo"
depends on BAR
config BAR
bool "bar"
endchoice

View File

@@ -0,0 +1,8 @@
choice
bool "choice"
default FOO if FOO
config FOO
bool "foo"
endchoice

View File

@@ -0,0 +1,7 @@
choice
bool "choice" if FOO
config FOO
bool "foo"
endchoice

View File

@@ -0,0 +1,30 @@
config NO_DEP_SYM
bool
config DEP_SYM
bool
depends on A
config DEP_SYM
depends on B && C
config DEP_SYM
depends on !D
choice NO_DEP_CHOICE
bool "no dep. choice"
endchoice
choice DEP_CHOICE
bool "dep. choice"
depends on A
endchoice
choice DEP_CHOICE
depends on B
endchoice
choice DEP_CHOICE
depends on C
endchoice

View File

@@ -0,0 +1,3 @@
config STRING
string "string"
default "\"\\"

View File

@@ -0,0 +1,34 @@
# Enabled/disabled in the test
config MODULES
bool "modules"
option modules
config N
def_tristate n
config M
def_tristate m
menuconfig Y
def_tristate y
prompt "foo"
config Y_STRING
string
default "y"
config FOO_BAR_STRING
string
default "foo bar"
config INT_37
int
default 37
config HEX_0X37
hex
default 0x37
config HEX_37
hex
default 37

View File

@@ -0,0 +1,11 @@
config TEST
bool
default A && (B || !C && D = "E") || F > G || !!!H
choice CHOICE
bool "choice"
config TEST_CHOICE
bool "test choice" if A
endchoice

View File

@@ -0,0 +1,5 @@
# Used to test headers in .config and header files
config FOO
bool "foo"
default y

View File

@@ -0,0 +1,50 @@
config TWO_HELP_STRINGS
bool
help
first help string
config TWO_HELP_STRINGS
help
second help string
config NO_BLANK_AFTER_HELP
bool
help
help for
NO_BLANK_AFTER_HELP
choice CHOICE_HELP
bool "choice with help"
help
help for
CHOICE_HELP
endchoice
config HELP_TERMINATED_BY_COMMENT
bool
help
a
b
c
#
config TRICKY_HELP
bool
-help---
a
b
c
d
e
f
g
h
i
#

View File

@@ -0,0 +1,99 @@
# Test some tricky cases that give consecutive 'if' nodes even after
# flattening. Simple cases are exercised a ton elsewhere.
if X
endif
if X
endif
config A
if X
endif
if X
endif
config B
if X
endif
if X
endif
if X
endif
config C
if X
if X
if X
endif
if X
endif
endif
if X
if X
endif
if X
endif
endif
config D
endif
if X
endif
menu "E"
if X
if X
endif
endif
if X
if X
endif
endif
endmenu
menu "F"
if X
endif
if X
endif
if X
if X
endif
if X
endif
menu "G"
endmenu
endif
endmenu
choice H
if X
if X
endif
endif
if X
if X
endif
endif
endchoice
choice I
if X
endif
if X
endif
if X
if X
endif
if X
endif
config J
endif
endchoice
if X
endif
if X
endif

145
ext/Kconfiglib/tests/Kimply Normal file
View File

@@ -0,0 +1,145 @@
config MODULES
def_bool y
option modules
#
# Implied symbols with unmet and met direct dependencies
#
config IMPLY_DIRECT_DEPS
def_tristate y
imply UNMET_DIRECT_1
imply UNMET_DIRECT_2
imply UNMET_DIRECT_3
imply MET_DIRECT_1
imply MET_DIRECT_2
imply MET_DIRECT_3
imply MET_DIRECT_4
config UNMET_DIRECT_1
tristate
depends on n
if n
config UNMET_DIRECT_2
tristate
endif
menu "menu"
depends on n
config UNMET_DIRECT_3
tristate
endmenu
config MET_DIRECT_1
tristate
config MET_DIRECT_2
depends on y
tristate
if y
config MET_DIRECT_3
tristate
endif
menu "menu"
depends on y
config MET_DIRECT_4
tristate
endmenu
#
# 'imply' with condition
#
config IMPLY_COND
def_tristate y
tristate
imply IMPLIED_N_COND if n
imply IMPLIED_M_COND if m
imply IMPLIED_Y_COND if y
config IMPLIED_N_COND
tristate
config IMPLIED_M_COND
tristate
config IMPLIED_Y_COND
tristate
#
# Implying from symbol with value n
#
# Will default to 'n'
config IMPLY_N_1
tristate
imply IMPLIED_FROM_N_1
# This test also disables the imply, so it's kinda redundant, but why not
if n
config IMPLY_N_2
tristate
imply IMPLIED_FROM_N_2
endif
config IMPLIED_FROM_N_1
tristate
config IMPLIED_FROM_N_2
tristate
#
# Implying from symbol with value m
#
config IMPLY_M
def_tristate m
imply IMPLIED_M
# Implying a bool to 'm' makes it default to 'y'
imply IMPLIED_M_BOOL
config IMPLIED_M
tristate
config IMPLIED_M_BOOL
bool
#
# 'imply' which should raise an 'm' default to 'y'
#
config IMPLY_M_TO_Y
tristate
default y
imply IMPLIED_M_TO_Y
config IMPLIED_M_TO_Y
tristate
default m
#
# Used for testing user values
#
config DIRECT_DEP
tristate "direct dep"
config IMPLY
tristate "imply"
imply IMPLIED_TRISTATE
imply IMPLIED_BOOL
config IMPLIED_TRISTATE
tristate "implied tristate"
depends on DIRECT_DEP
config IMPLIED_BOOL
bool "implied bool"
depends on DIRECT_DEP

View File

@@ -0,0 +1,12 @@
config TOP
bool
source "Kinclude_path_sourced_1"
config TOP
bool
source "Kinclude_path_sourced_1"
config TOP
bool

View File

@@ -0,0 +1,12 @@
config ONE_DOWN
bool
source "Kinclude_path_sourced_2"
config ONE_DOWN
bool
source "Kinclude_path_sourced_2"
config ONE_DOWN
bool

View File

@@ -0,0 +1,11 @@
config TWO_DOWN
bool
menu "menu"
endmenu
comment "comment"
choice
bool "choice"
endchoice

View File

@@ -0,0 +1,36 @@
comment "comment 1"
choice
bool "choice 1"
endchoice
menu "menu 1"
choice NAMED
bool "choice 2"
endchoice
menu "menu 2"
menu "menu 3"
comment "comment 2"
endmenu
choice
bool "choice 3"
endchoice
choice NAMED
bool
endchoice
endmenu
menu "menu 4"
endmenu
comment "comment 3"
endmenu
menu "menu 5"
endmenu

View File

@@ -0,0 +1,78 @@
if UNDEFINED
endif
config ONE_DEF
bool
config TWO_DEF
bool
config TWO_DEF
bool
config MANY_DEF
bool
# Throw in some line continuations too to make sure it doesn't mess up the line
# numbers
if y && \
y
if y && \
y && \
y
# Throw in some help texts too
config HELP_1
bool "help 1"
help
config HELP_2
bool "help 2"
help
foo
bar
baz
config HELP_3
help
foo
bar
bool
config \
MANY_DEF
config MANY_DEF
endif
endif
# Expands to "tests/Klocation_sourced"
source "$TESTS_DIR_FROM_ENV/Klocation$_SOURCED"
# Expands to "sub/Klocation_rsourced"
rsource "$SUB_DIR_FROM_ENV/Klocation$_RSOURCED"
# Expands to "tests/*ub/Klocation_gsourced[12]", matching
# tests/sub/Klocation_gsourced{1,2}
source "$TESTS_DIR_FROM_ENV/*ub/Klocation$_GSOURCED[12]"
# Test old syntax too
gsource "$TESTS_DIR_FROM_ENV/*ub/Klocation$_GSOURCED[12]"
# Expands to "sub/Klocation_grsourced[12]", matching
# tests/sub/Klocation_grsourced{1,2}
rsource "$SUB_DIR_FROM_ENV/Klocation$_GRSOURCED[12]"
# Test old syntax too
grsource "$SUB_DIR_FROM_ENV/Klocation$_GRSOURCED[12]"
# No-ops
osource "nonexistent"
osource "nonexistent*"
gsource "nonexistent"
gsource "nonexistent*"
orsource "nonexistent"
orsource "nonexistent*"
grsource "nonexistent"
grsource "nonexistent*"
config MANY_DEF

View File

@@ -0,0 +1,26 @@
config MANY_DEF
choice CHOICE_ONE_DEF
bool "one-def choice"
endchoice
choice CHOICE_TWO_DEF
bool "two-def choice 1"
endchoice
choice CHOICE_TWO_DEF
bool "two-def choice 2"
endchoice
config MENU_HOOK
bool
menu "menu"
endmenu
config COMMENT_HOOK
bool
comment "comment"

View File

@@ -0,0 +1,5 @@
config FOO
string
option env="FOO"
mainmenu "---$FOO---"

View File

@@ -0,0 +1,37 @@
# Menu nodes with is_menuconfig False
config NOT_MENUCONFIG_1
bool
config NOT_MENUCONFIG_2
bool "not menuconfig 2"
config MENUCONFIG_MULTI_DEF
bool "menuconfig multi def 1"
config COMMENT_HOOK
bool
comment "not menuconfig 3"
# Menu nodes with is_menuconfig True
menuconfig MENUCONFIG_1
bool "menuconfig 1"
menuconfig MENUCONFIG_MULTI_DEF
bool "menuconfig multi def 2"
config MENU_HOOK
bool
menu "menuconfig 2"
endmenu
config CHOICE_HOOK
bool
choice
bool "menuconfig 3"
endchoice

View File

@@ -0,0 +1,82 @@
# For testing various minor APIs
# optional choices
choice NOT_OPTIONAL
bool "not optional"
config A
bool "A"
config B
bool "B"
endchoice
choice OPTIONAL
tristate "optional"
optional
config C
tristate "C"
config D
tristate "D"
# Quirky symbols - not proper choice symbol
config Q1
tristate "Q1"
depends on D
config Q2
tristate "Q2"
depends on Q1
config Q3
tristate "Q3"
depends on D
endchoice
# User values
config BOOL
bool "bool" if NOT_DEFINED_1
config TRISTATE
tristate # Visibility should not affect user value
config STRING
string "string"
config INT
int # Visibility should not affect user value
config HEX
hex "hex"
depends on NOT_DEFINED_2
config COMMENT_HOOK
comment "comment"
config MENU_HOOK
menu "menu"
depends on NOT_DEFINED_3 || NOT_DEFINED_2
depends on !NOT_DEFINED_4
endmenu
config FROM_ENV
string "from env"
option env="ENV_VAR"
config FROM_ENV_MISSING
string "from env missing"
option env="MISSING_ENV_VAR"
default "missing"
config FROM_ENV_WEIRD
string
default "weird"
option env="ENV_VAR"
config NOT_ALLNOCONFIG_Y
bool "not allnoconfig_y"
config ALLNOCONFIG_Y
bool "allnoconfig_y"
option allnoconfig_y

View File

@@ -0,0 +1 @@
rsource "nonexistent"

View File

@@ -0,0 +1 @@
source "nonexistent"

View File

@@ -0,0 +1,35 @@
config O
int "O"
default 0
config R
int "R"
default 1
config D
int "D"
default 2
config E
int "E"
default 3
# Defined twice
config R
int "R"
config R2
int "R2"
default 4
config I
int "I"
default 5
config N
int "N"
default 6
config G
int "G"
default 7

View File

@@ -0,0 +1,151 @@
# Simple assignments (with bad formatting, as an additional test)
simple-recursive=foo
simple-immediate:=bar
# Should become recursive
simple-recursive-2+=baz
whitespaced = foo
# Simple += test. += should preserve the flavor of the variable (simple vs.
# recursive).
preserve-recursive = foo
preserve-recursive += bar
preserve-immediate := foo
preserve-immediate += bar
# Recursive substitution
recursive = $(foo) $(bar) $($(b-char)a$(z-char))
recursive += $(indir)
foo = abc
bar = def
baz = ghi
b-char = b
z-char = z
indir = jkl $(indir-2)
indir-2 = mno
# Immediate substitution
def = foo
immediate := $(undef)$(def)$(undef)$(def)
def = bar
undef = bar
# Function calls
# Chained function call
quote = "$(1)" "$(2)"
rev-quote = $(quote,$(2),$(1))
surround-rev-quote = $(0) $(rev-quote,$(1),$(2)) $(0)
surround-rev-quote-unused-arg = $(surround-rev-quote,$(1),$(2)) $(3)
# No value is passed for $(3), so it expands to nothing
fn-indir = surround-rev-quote
messy-fn-res = $($(fn-indir)-unused-arg, a b (,) , c d )
# Special characters in function call
comma = ,
right-paren = )
dollar = $
left-paren = (
fn = "$(1)"
special-chars-fn-res = $(fn,$(comma)$(dollar)$(left-paren)foo$(right-paren))
# Variable expansions in various locations (verified by checking how the symbol
# prints)
qaz = QAZ
echo = $(1)
ignore-first = $(2)
config PRINT_ME
string "$(ENV_1)" if ($(echo,FOO) && $(echo,BAR)) || !$(echo,BAZ) || !(($(qaz)))
default "$(echo,"foo")" if "foo $(echo,"bar") baz" = "$(undefined)"
# Expansion within a symbol token, with deliberate sloppiness
config PRINT_$(ignore-first, ,ME)_TOO
bool "foo"
default FOO$(ignore-first, ,BAR)BAZ$(qaz) if $(qaz)&&$(qaz)FOO&&x$(ignore-first, ,xx)
# Recursive expansion (throws an exception)
rec-1 = x $(rec-2) y
rec-2 = x $(rec-3) y
rec-3 = x $(rec-1) y
# Functions are allowed to reference themselves, but an exception is thrown if
# the function seems to be stuck (the recursion gets too deep)
safe-fn-rec = $($(1))
safe-fn-rec-2 = $(safe-fn-rec,safe-fn-rec-3)
safe-fn-rec-3 = foo
safe-fn-rec-res = $(safe-fn-rec,safe-fn-rec-2)
unsafe-fn-rec = $(unsafe-fn-rec,$(1))
# Expansion in the left-hand side of assignments
dummy-arg-fn = bar
lhs-indir-1 = lhs-indir-2
lhs-indir-2 = -baz
rhs = value
# LHS expands to foo-bar-baz
foo-$(dummy-arg-fn, ignored argument )$($(lhs-indir-1)) = $(rhs)
# Expands to empty string, accepted
$(undefined)
# Variable with a space in its name
empty =
space = $(empty) $(empty)
foo$(space)bar = value
space-var-res = $(foo bar)
# Built-in functions
# Expands to "baz qaz"
shell-res = $(shell,false && echo foo bar || echo baz qaz)
# Warns about output on stderr, expands to nothing
shell-stderr-res := $(shell,echo message on stderr >&2)
# Nested parens in macro call. Should give a single argument. Test it with
# $(shell) to get a free argument number check.
parens-res = pre-$(shell,echo '(a,$(b-char),(c,d),e)')-post
# Expands to the current location
location-res := $(filename):$(lineno)
# Adds one warning, expands to nothing
$(warning-if,,no warning)
$(warning-if,n,no warning)
warning-res := $(warning-if,y,a warning)
# Does not cause an error, expands to nothing
error-n-res := $(error-if,n,oops)
# Causes an error when expanded
error-y-res = $(error-if,y,oops)
# Environment variables (for testing Kconfig.env_vars). ENV_1 is already
# referenced above.
env_ref_1 := xxx $(ENV_2) xxx
env_ref_2 := $(shell,echo $(ENV_3))
env_ref_3 :=
env_ref_3 += $(ENV_4)
$(warning-if,$(ENV_5),$(ENV_UNDEFINED))
source "$(ENV_6)"
env_ref_4 = $(ENV_7) # Never evaluated

133
ext/Kconfiglib/tests/Krange Normal file
View File

@@ -0,0 +1,133 @@
#
# No ranges
#
config HEX_NO_RANGE
hex "hex no range"
config INT_NO_RANGE
int "int no range"
#
# Disabled ranges
#
config HEX_ALL_RANGES_DISABLED
hex "hex all ranges disabled"
range 0x10 0x20 if n
range 0x30 0x40 if n
config INT_ALL_RANGES_DISABLED
int "int all ranges disabled"
range 10 20 if n
range 30 40 if n
#
# Ranges with defaults
#
# hex
config HEX_RANGE_10_20_LOW_DEFAULT
hex "int range 10-20 low default"
range 0x10 0x20
default 0x9
config HEX_RANGE_10_20_HIGH_DEFAULT
hex "int range 10-20 high default"
range 0x10 0x20
default 0x21
config HEX_RANGE_10_20_OK_DEFAULT
hex "int range 10-20 ok default"
range 0x10 0x20
default 0x15
config HEX_RANGE_10_20_OK_DEFAULT_ALTERNATE
hex "int range 10-20 ok default alternate"
range 0x10 0x20
default 15
# int
config INT_RANGE_10_20_LOW_DEFAULT
int "int range 10-20 low default"
range 10 20
default 9
config INT_RANGE_10_20_HIGH_DEFAULT
int "int range 10-20 high default"
range 10 20
default 21
config INT_RANGE_10_20_OK_DEFAULT
int "int range 10-20 ok default"
range 10 20
default 15
#
# Ranges with no defaults (should default to low end of range if > 0)
#
config HEX_RANGE_10_20
hex "hex range 10-20"
range 0x10 0x20
config HEX_RANGE_0_10
hex "hex range 0-10"
range 0x0 0x10
config INT_RANGE_10_20
int "int range 10-20"
range 10 20
config INT_RANGE_0_10
int "int range 0-10"
range 0 10
config INT_RANGE_NEG_10_10
int "int range -10-10"
range -10 10
#
# Dependent ranges
#
config HEX_40
hex
default 40
config HEX_RANGE_10_40_DEPENDENT
hex "hex range 10-40 dependent"
range HEX_RANGE_10_20 HEX_40
config INT_40
int
default 40
config INT_RANGE_10_40_DEPENDENT
int "int range 10-40 dependent"
range INT_RANGE_10_20 INT_40
#
# Ranges on symbols defined in multiple locations
#
if n
config INACTIVE_RANGE
range 0 1
endif
config INACTIVE_RANGE
int
# Default will apply and should not get clamped,
# because the range does not apply
default 2
config ACTIVE_RANGE
range 0 1
config ACTIVE_RANGE
int
# Default will apply and should be clamped to 1
default 2

View File

@@ -0,0 +1 @@
source "tests/Krecursive2"

View File

@@ -0,0 +1 @@
source "tests/Krecursive1"

View File

@@ -0,0 +1,63 @@
config NO_REFS
bool
config JUST_DEPENDS_ON_REFS
bool
depends on A && B
if A
menu "menu"
depends on B
visible if C
visible if D
config LOTS_OF_REFS
bool "lots" if C || D
default E || F if G || H
default I || J if K || L
select M if N || O
select P if Q || R
imply S if T || U
imply V if W || X
depends on Y || Z
endmenu
endif
config INT_REFS
int "int"
range A B if C && D
range E F if G && H
choice CHOICE
bool "choice"
config CHOICE_REF
bool "choice ref"
endchoice
comment "comment"
depends on A || B
config MULTI_DEF_SYM
def_bool A && B
config MULTI_DEF_SYM
depends on C
choice MULTI_DEF_CHOICE
bool "choice"
depends on A && B
endchoice
choice MULTI_DEF_CHOICE
bool "choice"
depends on C
endchoice

View File

@@ -0,0 +1,36 @@
config A
bool
depends on UNDEFINED
choice CHOICE_1
bool "C"
config B
bool "B"
config C
bool "C" if B
config D
bool "D"
endchoice
menu "m1"
config E
bool
menu "m2"
config F
bool
choice CHOICE_2
tristate "foo"
config G
bool "g"
config H
bool "h"
endchoice
endmenu
config I
bool
endmenu
menu "m3"
endmenu
menu "m4"
endmenu

View File

@@ -0,0 +1,64 @@
config MODULES
bool
option modules
default y
if UNDEFINED
endif
config BASIC
bool
default y
---help---
config VISIBLE
bool "visible"
config STRING
string "visible"
config DIR_DEP_N
depends on n
config OPTIONS
option allnoconfig_y
option defconfig_list
option env="ENV"
config MULTI_DEF
config MULTI_DEF
menuconfig MENUCONFIG
choice CHOICE
tristate "choice"
config CHOICE_1
tristate "choice sym"
config CHOICE_2
tristate "choice sym"
endchoice
config CHOICE_HOOK
choice
tristate "optional choice" if n
optional
endchoice
config NO_VISIBLE_IF_HOOK
menu "no visible if"
endmenu
config VISIBLE_IF_HOOK
menu "visible if"
visible if m
endmenu
config COMMENT_HOOK
comment "comment"

293
ext/Kconfiglib/tests/Kstr Normal file
View File

@@ -0,0 +1,293 @@
if UNDEFINED
endif
config NO_TYPE
config BASIC_NO_PROMPT
bool
help
blah blah
blah blah blah
blah
config BASIC_PROMPT
bool "basic"
config ADVANCED
tristate "prompt" if DEP
default DEFAULT_1
default DEFAULT_2 if DEP
select SELECTED_1
select SELECTED_2 if DEP
imply IMPLIED_1
imply IMPLIED_2 if DEP
help
first help text
config ADVANCED
prompt "prompt 2"
menuconfig ADVANCED
prompt "prompt 3"
if DEP3
menu "foo"
depends on DEP4
visible if VIS
config ADVANCED
help
second help text
depends on A || !B || (C && D) || !(E && F) || G = H || \
(I && !J && (K || L) && !(M || N) && O = P)
config ADVANCED
# Used to verify that the direct dependencies appear to the right of VIS
prompt "prompt 4"
endmenu
endif
config ONLY_DIRECT_DEPS
int
depends on DEP1
depends on DEP2
config STRING
def_string "foo"
default "bar" if DEP
default STRING2
default STRING3 if DEP
config INT
def_int 7 if DEP
range 1 2
range FOO BAR
range BAZ QAZ if DEP
config HEX
def_hex 0x123
range 0x100 0x200
range FOO BAR
range BAZ QAZ if DEP
config MODULES
bool "MODULES"
option modules
config OPTIONS
option allnoconfig_y
option defconfig_list
option env="ENV"
if LOC_1
config CORRECT_PROP_LOCS_BOOL
prompt "prompt 1"
default DEFAULT_1
default DEFAULT_2
select SELECT_1
select SELECT_2
imply IMPLY_1
imply IMPLY_2
help
help 1
endif
if LOC_2
menuconfig CORRECT_PROP_LOCS_BOOL
bool "prompt 2"
default DEFAULT_3
default DEFAULT_4
select SELECT_3
select SELECT_4
imply IMPLY_3
imply IMPLY_4
help
help 2
endif
if LOC_3
config CORRECT_PROP_LOCS_BOOL
prompt "prompt 3"
default DEFAULT_5
default DEFAULT_6
select SELECT_5
select SELECT_6
imply IMPLY_5
imply IMPLY_6
help
help 2
endif
if LOC_1
config CORRECT_PROP_LOCS_INT
int
range 1 2
range 3 4
endif
if LOC_2
config CORRECT_PROP_LOCS_INT
range 5 6
range 7 8
endif
choice CHOICE
tristate "foo"
default CHOICE_1
default CHOICE_2 if dep
config CHOICE_1
tristate "choice 1"
config CHOICE_2
tristate "choice 2"
endchoice
choice
tristate "no name"
optional
endchoice
if LOC_1
choice CORRECT_PROP_LOCS_CHOICE
bool
default CHOICE_3
config CHOICE_3
bool "choice 3"
config CHOICE_4
bool "choice 3"
config CHOICE_5
bool "choice 3"
endchoice
endif
if LOC_2
choice CORRECT_PROP_LOCS_CHOICE
default CHOICE_4
endchoice
endif
if LOC_3
choice CORRECT_PROP_LOCS_CHOICE
default CHOICE_5
endchoice
endif
config SIMPLE_MENU_HOOK
menu "simple menu"
endmenu
config ADVANCED_MENU_HOOK
menu "advanced menu"
depends on A
visible if B
visible if C || D
endmenu
config SIMPLE_COMMENT_HOOK
comment "simple comment"
config ADVANCED_COMMENT_HOOK
comment "advanced comment"
depends on A
depends on B
# Corner cases when removing direct dependencies
config DEP_REM_CORNER_CASES
bool
default A
depends on n
config DEP_REM_CORNER_CASES
default B if n
config DEP_REM_CORNER_CASES
default C
depends on m
config DEP_REM_CORNER_CASES
default D if A && y
depends on y
config DEP_REM_CORNER_CASES
default E if !E1
default F if F1 = F2
default G if G1 || H1
depends on !H
config DEP_REM_CORNER_CASES
default H
depends on "foo" = "bar"
menu "menu"
visible if FOO || BAR
config DEP_REM_CORNER_CASES
prompt "prompt"
depends on BAZ && QAZ
endmenu
# Only prompt, no type
config PROMPT_ONLY
prompt "prompt only"
# {Symbol,Choice}.orig_*
if BASE_DEP
config BOOL_SYM_ORIG
bool
default D1 if DEP
default D2
select S1
select S2 if DEP
imply I1
imply I1
config BOOL_SYM_ORIG
default D3
select S3
imply I3 if DEP
config INT_SYM_ORIG
int
range 1 2 if DEP
range 3 4
config INT_SYM_ORIG
range 5 6 if DEP
choice CHOICE_ORIG
bool "choice orig"
default A
default B if DEP
config A
bool
config B
bool
endchoice
choice CHOICE_ORIG
default C if DEP
config C
bool
endchoice
endif

View File

@@ -0,0 +1,23 @@
config DEF
bool
config BOOL
bool "foo" if DEF || !UNDEF_1
default UNDEF_2
config INT
int
range UNDEF_2 8
default 10
range 5 15
config HEX
hex
range 0x123 0X456
default 0x200
menu "menu"
depends on UNDEF_1
visible if UNDEF_3
endmenu

View File

@@ -0,0 +1,14 @@
add-zero = $(add)
add-one = $(add,1)
add-three = $(add,1,-1,2,1)
one-zero = $(one)
one-one = $(one,foo bar)
one-two = $(one,foo bar,baz)
one-or-more-zero = $(one-or-more)
one-or-more-one = $(one-or-more,foo)
one-or-more-three = $(one-or-more,foo,bar,baz)
location-1 := $(location)
location-2 := $(location)

View File

@@ -0,0 +1,342 @@
config MODULES
bool "MODULES"
option modules
#
# Symbol visibility
#
config NO_PROMPT
bool
# Not rewritten, so MOD will have the value 'y' when running without modules
config MOD
def_tristate m
config BOOL_N
bool "bool n" if n
config BOOL_M
# Rewritten to m && MODULES
bool "bool m" if m
config BOOL_MOD
bool "bool MOD"
# Not rewritten
depends on MOD
config BOOL_Y
bool "bool y"
# Rewritten to m && MODULES
depends on y || m
config TRISTATE_N
tristate "tristate n" if n
config TRISTATE_M
# Rewritten to m && MODULES
tristate "tristate m" if m
config TRISTATE_MOD
tristate "tristate MOD"
# Not rewritten
depends on MOD
config TRISTATE_Y
bool "tristate y"
# Rewritten to m && MODULES
depends on y || m
# Symbols nested in 'if'
if n
config BOOL_IF_N
bool "bool if n"
config TRISTATE_IF_N
tristate "tristate if n"
endif
if m
config BOOL_IF_M
bool "bool if m"
config TRISTATE_IF_M
tristate "tristate if n"
endif
if y
config BOOL_IF_Y
bool "bool if y"
config TRISTATE_IF_Y
tristate "tristate if y"
endif
# Symbols nested in 'menu'
menu "menu 1"
depends on n
config BOOL_MENU_N
bool "bool menu n"
config TRISTATE_MENU_N
tristate "tristate menu n"
endmenu
menu "menu 2"
depends on m
config BOOL_MENU_M
bool "bool menu m"
config TRISTATE_MENU_M
tristate "tristate menu n"
endmenu
menu "menu 3"
depends on y
config BOOL_MENU_Y
bool "bool menu y"
config TRISTATE_MENU_Y
tristate "tristate menu y"
endmenu
# Symbols nested in choices
choice C1
tristate "choice n" if n
config BOOL_CHOICE_N
bool "bool choice n"
config TRISTATE_CHOICE_N
tristate "tristate choice n"
endchoice
choice C2
tristate "choice m" if m
config BOOL_CHOICE_M
bool "bool choice m"
config TRISTATE_CHOICE_M
tristate "tristate choice n"
endchoice
choice C3
tristate "choice y" if y
config BOOL_CHOICE_Y
bool "bool choice y"
config TRISTATE_CHOICE_Y
tristate "tristate choice y"
endchoice
#
# Choice visibility
#
choice BOOL_CHOICE_N
bool "bool choice n" if n
endchoice
choice BOOL_CHOICE_M
bool "bool choice m" if m
endchoice
choice BOOL_CHOICE_Y
bool "bool choice y" if y
endchoice
choice TRISTATE_CHOICE_N
tristate "tristate choice n" if n
endchoice
choice TRISTATE_CHOICE_M
tristate "tristate choice m" if m
endchoice
choice TRISTATE_CHOICE_Y
tristate "tristate choice y" if y
config K
tristate "K"
config L
tristate "L"
endchoice
if m
choice TRISTATE_CHOICE_IF_M_AND_Y
tristate "tristate choice if m and y" if y
config M
bool "M"
config N
bool "N"
endchoice
endif
menu "choice-containing menu"
depends on n && y
choice TRISTATE_CHOICE_MENU_N_AND_Y
tristate "tristate choice if n and y"
config O
tristate "O"
config P
tristate "P"
endchoice
endmenu
#
# Menu visibility
#
menu "menu n"
depends on n
endmenu
menu "menu m"
depends on m
endmenu
menu "menu y"
depends on y
endmenu
if n
menu "menu if n"
endmenu
endif
if m
menu "menu if m"
endmenu
endif
if y
menu "menu if y"
endmenu
endif
if m
menu "menu if m and y"
depends on y
endmenu
endif
#
# Comment visibility
#
comment "comment n"
depends on n
comment "comment m"
depends on m
comment "comment y"
depends on y
if n
comment "comment if n"
endif
if m
comment "comment if m"
endif
if y
comment "comment if y"
endif
if "y"
menu "menu with comment"
depends on m
comment "double-nested m comment"
depends on y
endmenu
endif
# Used to verify that string/int/hex symbols with m visibility accept a user
# value
if m
config STRING_m
string "string"
config INT_m
int "int"
config HEX_m
hex "hex"
endif
# Menu 'visible if' visibility
menu "n-visible menu"
visible if n
config VISIBLE_IF_N
tristate "visible if n"
endmenu
menu "m-visible menu"
visible if m
config VISIBLE_IF_M
tristate "visible if m"
endmenu
menu "y-visible menu"
visible if y
config VISIBLE_IF_Y
tristate "visible if m"
endmenu
menu "m-visible menu 2"
visible if y || n
visible if m && y
visible if y
if y
config VISIBLE_IF_M_2
tristate "visible if m 2"
endif
endmenu

View File

@@ -0,0 +1,3 @@
# Indented assignments should be ignored to be compatible with the C
# implementation
CONFIG_IGNOREME=n

View File

@@ -0,0 +1 @@
CONFIG_BOOL=y

View File

@@ -0,0 +1 @@
CONFIG_STRING="foo bar"

View File

View File

View File

View File

@@ -0,0 +1,22 @@
def add(kconf, name, *args):
return str(sum(map(int, args)))
def one(kconf, name, s):
return name + 2*s
def one_or_more(kconf, name, arg, *args):
return arg + " + " + ",".join(args)
def location(kconf, name):
return "{}:{}".format(kconf.filename, kconf.linenr)
functions = {
"add": (add, 0, None),
"one": (one, 1, 1),
"one-or-more": (one_or_more, 1, None),
"location": (location, 0, 0),
}

51
ext/Kconfiglib/tests/reltest Executable file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Runs the test suite and all examples scripts with Python 2 and Python 3,
# bailing immediately if anything fails. For the examples that aren't tested in
# the test suite, we just confirm that they at least run.
#
# Should be run from the kernel root with $ Kconfiglib/tests/reltest
test_script() {
echo -e "\n================= $1 with $py =================\n"
if (($# == 1)); then
make scriptconfig PYTHONCMD=$py SCRIPT=$1
else
make scriptconfig PYTHONCMD=$py SCRIPT=$1 SCRIPT_ARG="$2"
fi
if (($?)); then
echo "$1 failed to run with $py"
exit 1
fi
}
for py in python2 python3; do
echo -e "\n================= Test suite with $py =================\n"
if ! $py Kconfiglib/testsuite.py; then
echo "test suite failed for $py"
exit 1
fi
# Check that the example scripts that aren't tested by the test suite run
# at least
test_script Kconfiglib/examples/defconfig_oldconfig.py
test_script Kconfiglib/examples/eval_expr.py MODULES
test_script Kconfiglib/examples/find_symbol.py X86
test_script Kconfiglib/examples/help_grep.py general
test_script Kconfiglib/examples/print_sym_info.py MODULES
test_script Kconfiglib/examples/print_tree.py
$py Kconfiglib/examples/menuconfig_example.py Kconfiglib/examples/Kmenuconfig <<END
BOOL
n
END
if (($?)); then
echo "menuconfig_example.py failed with $py"
exit 1
fi
done
echo "everything okay"

View File

@@ -0,0 +1 @@
rsource "Kconfig_symlink_3"

View File

@@ -0,0 +1,2 @@
config FOUNDME
bool

View File

@@ -0,0 +1 @@
config MANY_DEF

View File

@@ -0,0 +1 @@
config MANY_DEF

View File

@@ -0,0 +1 @@
config MANY_DEF

View File

@@ -0,0 +1 @@
config MANY_DEF

View File

@@ -0,0 +1,2 @@
config MANY_DEF

View File

@@ -0,0 +1,2 @@
# Sources tests/sub/Kconfig_symlink_2, with an absolute path
source "$(KCONFIG_SYMLINK_2)"