Repository: mesonbuild/meson

Issue:
Wrong option printing regarding default values
#3739 added a new feature to print options that are different from the default.

However, this seems to never have worked or maybe I'm failing to understand how it is supposed to work.

1) Given a `meson.build` with `project('demo', 'c', default_options : ['b_pch=true'])` and configuring the project prints: `Option b_pch is: true [default: true]`

2) Given a `meson.build` without `default_options`, configuring with either `-Db_pch=false` or `-Db_pch=true` does not print anything.

@NickeZ: since you implemented the initial patch, could you maybe chime in and tell me if this is expected behavior?

What should actually be printed during configuration?

- a) Options that are not the MESON default (either being overwritten by `default_options` or on the command line, or
- b) Options that are not the PROJECT default and thus could have only been overwritten on the command line


Discussion:
Hey,

1. Sounds like a bug. I think the intention was to not print anything if your current setting is the same as default.

2. Also sounds like bugs, configuring with `-Db_pch=false` in this case should print that it is different from `true`.

Both 1 and 2 works for me with when I use `c_std` and `warning_level` as examples. Maybe something is different with b_pch?

The purpose of this feature is primarily the reverse to what you are testing though. Having an already configured project and then changing the `default_values` in the build file should now hint that your current settings != the default settings.

```
$ cat meson.build
project('mini', 'c',
  version : '0.1',
  default_options : ['warning_level=3'])

exe = executable('mini', 'mini.c',
  install : true)

test('basic a', exe)
niklas @ niklas-ThinkPad-T480s : ~/projects/c++-tests/mini
$ meson _build
The Meson build system
Version: 0.49.999
Source dir: /home/niklas/projects/c++-tests/mini
Build dir: /home/niklas/projects/c++-tests/mini/_build
Build type: native build
Project name: mini
Project version: 0.1
Native C compiler: ccache cc (gcc 7.3.0 "cc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Build targets in project: 1
Found ninja-1.8.2 at /usr/bin/ninja
niklas @ niklas-ThinkPad-T480s : ~/projects/c++-tests/mini
$ vim meson.build
niklas @ niklas-ThinkPad-T480s : ~/projects/c++-tests/mini
$ cat meson.build
project('mini', 'c',
  version : '0.1',
  default_options : ['warning_level=3', 'c_std=c99'])

exe = executable('mini', 'mini.c',
  install : true)

test('basic a', exe)
niklas @ niklas-ThinkPad-T480s : ~/projects/c++-tests/mini
$ ninja -C _build
ninja: Entering directory `_build'
[0/1] Regenerating build files.
The Meson build system
Version: 0.49.999
Source dir: /home/niklas/projects/c++-tests/mini
Build dir: /home/niklas/projects/c++-tests/mini/_build
Build type: native build
Project name: mini
Project version: 0.1
Native C compiler: ccache cc (gcc 7.3.0 "cc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Build targets in project: 1
Option c_std is: none [default: c99]
Found ninja-1.8.2 at /usr/bin/ninja
[2/2] Linking target mini.
```

```
$ meson -Dc_std=c89 _build
The Meson build system
Version: 0.49.999
Source dir: /home/niklas/projects/c++-tests/mini
Build dir: /home/niklas/projects/c++-tests/mini/_build
Build type: native build
Project name: mini
Project version: 0.1
Native C compiler: ccache cc (gcc 7.3.0 "cc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0")
Build machine cpu family: x86_64
Build machine cpu: x86_64
Build targets in project: 1
Option c_std is: c89 [default: c99]
Found ninja-1.8.2 at /usr/bin/ninja
```
btw, why would you enable pch in the build configuration by default? This sounds to me like something that the end-user should enable if they want to use?
This is a bug. The objects are not properly recreated so two things end up pointing to global constants and they get altered. Someone (forgot who) was going to submit a fix for that but apparently not.

> btw, why would you enable pch in the build configuration by default

Because by itself it does nothing. Things only happen if you explicitly add a pch declaration to a target. And if you do that, you probably want it enabled by default.
I only used b_pch as an example. It happens with a few other options as well.
I think I have a fix for this already, but wanted to make sure there is actually something to fix. 

So the behavior should be like b) in my in my initial post right? I.e. the project default is what matters, not the meson one. This also makes more sense to me. Will post a PR for this soonish. 

Resolving patch:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2033,9 +2033,10 @@ def get_non_matching_default_options(self):
         for def_opt_name, def_opt_value in self.project_default_options.items():
             for option_type in env.coredata.get_all_options():
                 for cur_opt_name, cur_opt_value in option_type.items():
-                    if (def_opt_name == cur_opt_name and
-                            def_opt_value != cur_opt_value.value):
-                        yield (def_opt_name, def_opt_value, cur_opt_value)
+                    if def_opt_name == cur_opt_name:
+                        def_opt_value = env.coredata.validate_option_value(def_opt_name, def_opt_value)
+                        if def_opt_value != cur_opt_value.value:
+                            yield (def_opt_name, def_opt_value, cur_opt_value)
 
     def build_func_dict(self):
         self.funcs.update({'add_global_arguments': self.func_add_global_arguments,


Test patch: