| 1 |
--- |
| 2 |
short-description: Keyval module |
| 3 |
authors: |
| 4 |
- name: Mark Schulte, Paolo Bonzini |
| 5 |
years: [2017, 2019] |
| 6 |
has-copyright: false |
| 7 |
... |
| 8 |
|
| 9 |
# keyval module |
| 10 |
|
| 11 |
This module parses files consisting of a series of `key=value` lines. |
| 12 |
One use of this module is to load kconfig configurations in Meson |
| 13 |
projects. |
| 14 |
|
| 15 |
**Note**: this does not provide kconfig frontend tooling to generate a |
| 16 |
configuration. You still need something such as kconfig frontends (see |
| 17 |
link below) to parse your Kconfig files, and then (after you've chosen |
| 18 |
the configuration options), output a ".config" file. |
| 19 |
|
| 20 |
[kconfig-frontends]: http://ymorin.is-a-geek.org/projects/kconfig-frontends |
| 21 |
|
| 22 |
## Usage |
| 23 |
|
| 24 |
The module may be imported as follows: |
| 25 |
|
| 26 |
``` meson |
| 27 |
keyval = import('keyval') |
| 28 |
``` |
| 29 |
|
| 30 |
The following functions will then be available as methods on the object |
| 31 |
with the name `keyval`. You can, of course, replace the name |
| 32 |
`keyval` with anything else. |
| 33 |
|
| 34 |
### keyval.load() |
| 35 |
|
| 36 |
This function loads a file consisting of a series of `key=value` lines |
| 37 |
and returns a dictionary object. |
| 38 |
|
| 39 |
`keyval.load()` makes no attempt at parsing the values in the file. In |
| 40 |
particular boolean and integer values will be represented as strings, |
| 41 |
and strings will keep any quoting that is present in the input file. |
| 42 |
It can be useful to create a |
| 43 |
[`configuration_data()`](#configuration_data) object from the |
| 44 |
dictionary and use methods such as `get_unquoted()`. |
| 45 |
|
| 46 |
Kconfig frontends usually have ".config" as the default name for the |
| 47 |
configuration file. However, placing the configuration file in the |
| 48 |
source directory limits the user to one configuration per source |
| 49 |
directory. In order to allow separate configurations for each build |
| 50 |
directory, as is the Meson standard, `meson.build` should not hardcode |
| 51 |
".config" as the argument to `kconfig.load()`, and should instead make |
| 52 |
the argument to `kconfig.load()` a [project build |
| 53 |
option](Build-options.md). |
| 54 |
|
| 55 |
* The first (and only) argument is the path to the configuration file to |
| 56 |
load (usually ".config"). |
| 57 |
|
| 58 |
**Returns**: a [[@dict]] object. |