Skip to content

Commit

Permalink
Merge pull request #4546 from mensinda/buildopts
Browse files Browse the repository at this point in the history
Added 'section' key to buildoptions introspection
  • Loading branch information
jpakkane committed Nov 26, 2018
2 parents 5e2dd5b + ceb5e9f commit 2fb9814
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 17 deletions.
36 changes: 36 additions & 0 deletions docs/markdown/IDE-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,48 @@ In order to make code completion work, you need the compiler flags for each comp

Note that if the target has dependencies (such as generated sources), then the commands for those show up in this list as well, so you need to do some filtering. Alternatively you can grab every command invocation in the [Clang tools db](https://clang.llvm.org/docs/JSONCompilationDatabase.html) format that is written to a file called `compile_commands.json` in the build directory.

## Build Options

The next thing to display is the list of options that can be set. These include build type and so on. Here's how to extract them.

meson introspect --buildoptions

This command returns a list of all supported buildoptions with the format:

```json
{
"name": "name of the option",
"description": "the description",
"type": "type ID",
"value": "value depends on type",
"section": "section ID"
}
```

The supported types are:

- string
- boolean
- combo
- integer
- array

For the type `combo` the key `choices` is also present. Here all valid values for the option are stored.

The possible values for `section` are:

- core
- backend
- base
- compiler
- directory
- user
- test

To set the options, use the `meson configure` command.

## Tests

Compilation and unit tests are done as usual by running the `ninja` and `ninja test` commands. A JSON formatted result log can be found in `workspace/project/builddir/meson-logs/testlog.json`.

When these tests fail, the user probably wants to run the failing test in a debugger. To make this as integrated as possible, extract the test test setups with this command.
Expand Down
14 changes: 14 additions & 0 deletions docs/markdown/snippets/buildopts_section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## New `section` key for the buildoptions introspection

Meson now has a new `section` key in each build option. This allows
IDEs to group these options similar to `meson configure`.

The possible values for `section` are:

- core
- backend
- base
- compiler
- directory
- user
- test
22 changes: 11 additions & 11 deletions mesonbuild/mconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ def print_conf(self):
print(' Source dir', self.build.environment.source_dir)
print(' Build dir ', self.build.environment.build_dir)

dir_option_names = ['prefix',
'libdir',
'libexecdir',
'bindir',
'sbindir',
'includedir',
dir_option_names = ['bindir',
'datadir',
'mandir',
'includedir',
'infodir',
'libdir',
'libexecdir',
'localedir',
'sysconfdir',
'localstatedir',
'sharedstatedir']
test_option_names = ['stdsplit',
'errorlogs']
'mandir',
'prefix',
'sbindir',
'sharedstatedir',
'sysconfdir']
test_option_names = ['errorlogs',
'stdsplit']
core_option_names = [k for k in self.coredata.builtins if k not in dir_option_names + test_option_names]

dir_options = {k: o for k, o in self.coredata.builtins.items() if k in dir_option_names}
Expand Down
37 changes: 31 additions & 6 deletions mesonbuild/mintro.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,43 @@ def list_target_files(target_name, coredata, builddata):

def list_buildoptions(coredata, builddata):
optlist = []
add_keys(optlist, coredata.user_options)
add_keys(optlist, coredata.compiler_options)
add_keys(optlist, coredata.base_options)
add_keys(optlist, coredata.builtins)

dir_option_names = ['bindir',
'datadir',
'includedir',
'infodir',
'libdir',
'libexecdir',
'localedir',
'localstatedir',
'mandir',
'prefix',
'sbindir',
'sharedstatedir',
'sysconfdir']
test_option_names = ['errorlogs',
'stdsplit']
core_option_names = [k for k in coredata.builtins if k not in dir_option_names + test_option_names]

dir_options = {k: o for k, o in coredata.builtins.items() if k in dir_option_names}
test_options = {k: o for k, o in coredata.builtins.items() if k in test_option_names}
core_options = {k: o for k, o in coredata.builtins.items() if k in core_option_names}

add_keys(optlist, core_options, 'core')
add_keys(optlist, coredata.backend_options, 'backend')
add_keys(optlist, coredata.base_options, 'base')
add_keys(optlist, coredata.compiler_options, 'compiler')
add_keys(optlist, dir_options, 'directory')
add_keys(optlist, coredata.user_options, 'user')
add_keys(optlist, test_options, 'test')
print(json.dumps(optlist))

def add_keys(optlist, options):
def add_keys(optlist, options, section):
keys = list(options.keys())
keys.sort()
for key in keys:
opt = options[key]
optdict = {'name': key, 'value': opt.value}
optdict = {'name': key, 'value': opt.value, 'section': section}
if isinstance(opt, cdata.UserStringOption):
typestr = 'string'
elif isinstance(opt, cdata.UserBooleanOption):
Expand Down
3 changes: 3 additions & 0 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,7 @@ def get_opt():
expected = {
'name': 'list',
'description': 'list',
'section': 'user',
'type': 'array',
'value': ['foo', 'bar'],
}
Expand All @@ -2277,6 +2278,7 @@ def get_opt():
expected = {
'name': 'list',
'description': 'list',
'section': 'user',
'type': 'array',
'value': ['foo', 'bar'],
}
Expand All @@ -2301,6 +2303,7 @@ def get_opt():
expected = {
'name': 'list',
'description': 'list',
'section': 'user',
'type': 'array',
'value': [],
}
Expand Down

0 comments on commit 2fb9814

Please sign in to comment.