diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-07-03 18:30:06 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-07-10 07:56:37 +0200 |
| commit | 2433deba7889931c4bae679f116887fe49a2ce04 (patch) | |
| tree | 83aef26c03999becc6df6e7d37bf6880a190d36d /tests/Kpreprocess | |
| parent | 4200e25c24a4441b36d6ac2d3d30987d88515eb2 (diff) | |
Add Kconfig preprocessor
Implement the Kconfig preprocessor described in
https://github.com/torvalds/linux/blob/master/Documentation/kbuild/kconfig-macro-language.txt
(which is now in linux-next and will appear in Linux 4.18).
A new Kconfig.variables property holds all the preprocessor variables so
that they can be inspected programmatically. Preprocessor variables are
represented by a new Variable class.
With the preprocessor, environment variables are referenced with $(FOO)
instead of $FOO. For backwards compatibility, $FOO is accepted as well
for now (and leaves "$FOO" as-is if FOO doesn't exist). The $FOO syntax
might be dropped at some point in the future (together with a major
version increase). It should be supported for a few months at least.
Some internals were cleaned up too, mostly related to parsing. Some
outdated documentation was fixed as well.
Diffstat (limited to 'tests/Kpreprocess')
| -rw-r--r-- | tests/Kpreprocess | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/Kpreprocess b/tests/Kpreprocess new file mode 100644 index 0000000..73053fe --- /dev/null +++ b/tests/Kpreprocess @@ -0,0 +1,130 @@ +# 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) + +config PRINT_ME + string "$(ENV_VAR)" if ($(echo,FOO) && $(echo,BAR)) || !$(echo,BAZ) || !(($(qaz))) + default "$(echo,"foo")" if "foo $(echo,"bar") baz" = "$(undefined)" + + +# 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) + +# 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) |
