Repository: mesonbuild/meson

Issue:
get_option(localstatedir,, sharedstatedir and sysconfdir) are relative
Those options should be `/var` and `/etc` according to existing/closed issues, merge requests and documentation, but i've had for ages relative values `var` and `etc`.

I need to pass the absolute paths to configuration_data(), but i can neither pass the value given by get_option(), nor concatenate with get_option('prefix').

What should be done ?


Discussion:
Also, my prefix is `/usr/local` so I expected to get at least localstatedir=var/local, and that's not the case.
Yeah, this seems to have broken somewhere between #2511 and now:

``` meson
project('o')
foreach o : ['prefix', 'localstatedir', 'sharedstatedir']
  message('@0@ is @1@'.format(o, get_option(o)))
endforeach
```
```
$ rm -r _build ; meson setup _build
[...]
Message: prefix is /usr/local
Message: localstatedir is var
Message: sharedstatedir is com
```

works as expected when prefix is explicitly specified, though:

```
$ rm -r _build ; meson setup _build --prefix=/usr/local
[...]
Message: prefix is /usr/local
Message: localstatedir is /var/local
Message: sharedstatedir is /var/local/lib
```

bisecting lands on d778a371ac3eb0bdb2bfde84d753722b576d5f14 as the first bad commit.

Resolving patch:
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -501,7 +501,7 @@ def init_builtins(self):
         # Create builtin options with default values
         self.builtins = {}
         for key, opt in builtin_options.items():
-            self.builtins[key] = opt.init_option()
+            self.builtins[key] = opt.init_option(key, default_prefix())
         self.builtins_per_machine = PerMachine({}, {})
         for for_machine in iter(MachineChoice):
             for key, opt in builtin_options_per_machine.items():
@@ -959,9 +959,9 @@ def __init__(self, opt_type: T.Type[_U], description: str, default: T.Any, yield
         self.choices = choices
         self.yielding = yielding
 
-    def init_option(self) -> _U:
+    def init_option(self, name: str = 'prefix', prefix: str = '') -> _U:
         """Create an instance of opt_type and return it."""
-        keywords = {'yielding': self.yielding, 'value': self.default}
+        keywords = {'yielding': self.yielding, 'value': self.prefixed_default(name, prefix)}
         if self.choices:
             keywords['choices'] = self.choices
         return self.opt_type(self.description, **keywords)
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1857,8 +1857,14 @@ def test_prefix_dependent_defaults(self):
             # N.B. We don't check 'libdir' as it's platform dependent, see
             # default_libdir():
         }
+
+        if mesonbuild.mesonlib.default_prefix() == '/usr/local':
+            expected[None] = expected['/usr/local']
+
         for prefix in expected:
-            args = ['--prefix', prefix]
+            args = []
+            if prefix:
+                args += ['--prefix', prefix]
             self.init(testdir, extra_args=args, default_args=False)
             opts = self.introspect('--buildoptions')
             for opt in opts:


Test patch: