Repository: mesonbuild/meson

Issue:
get_option('b_xxx') inconsistent on reconfigure
`get_option('b_xxx')` returns the provided value on initial configure, but the default one on reconfigure (when `meson.build` has been modified). The option affects the build in both cases.

```patch
+++ a/mesonbuild/interpreter.py
--- b/mesonbuild/interpreter.py
@@ -1669,11 +1669,11 @@
             raise InterpreterException('Argument required for get_option.')
         optname = args[0]
         try:
-            return compilers.base_options[optname].value
+            return self.environment.get_coredata().base_options[optname].value
         except KeyError:
             pass
         try:
-            return self.environment.get_coredata().get_builtin_option(optname)
+            return self.environment.coredata.get_builtin_option(optname)
         except RuntimeError:
             pass
         try:
```



Discussion:
Please file a merge request so it will go through CI an all that.

Resolving patch:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1692,11 +1692,11 @@ def func_get_option(self, nodes, args, kwargs):
             raise InterpreterException('Argument required for get_option.')
         optname = args[0]
         try:
-            return compilers.base_options[optname].value
+            return self.environment.get_coredata().base_options[optname].value
         except KeyError:
             pass
         try:
-            return self.environment.get_coredata().get_builtin_option(optname)
+            return self.environment.coredata.get_builtin_option(optname)
         except RuntimeError:
             pass
         try:
@@ -1721,6 +1721,11 @@ def func_get_option(self, nodes, args, kwargs):
                 return self.coredata.external_args[lang]
             except KeyError:
                 pass
+        # Some base options are not defined in some environments, return the default value.
+        try:
+            return compilers.base_options[optname].value
+        except KeyError:
+            pass
         raise InterpreterException('Tried to access unknown option "%s".' % optname)
 
     @noKwargs
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1948,6 +1948,11 @@ def test_cross_find_program(self):
         crossfile.flush()
         self.init(testdir, ['--cross-file='+crossfile.name])
 
+    def test_reconfigure(self):
+        testdir = os.path.join(self.unit_test_dir, '13 reconfigure')
+        self.init(testdir, ['-Db_lto=true'], default_args=False)
+        self.build('reconfigure')
+
 
 class LinuxArmCrossCompileTests(BasePlatformTests):
     '''


Test patch:
diff --git a/test cases/common/47 options/meson.build b/test cases/common/47 options/meson.build
--- a/test cases/common/47 options/meson.build	
+++ b/test cases/common/47 options/meson.build	
@@ -12,6 +12,7 @@ if get_option('combo_opt') != 'combo'
   error('Incorrect value to combo option.')
 endif
 
+# If the default changes, update test cases/unit/13 reconfigure
 if get_option('b_lto') != false
   error('Incorrect value in base option.')
 endif
diff --git a/test cases/unit/13 reconfigure/meson.build b/test cases/unit/13 reconfigure/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/unit/13 reconfigure/meson.build	
@@ -0,0 +1,5 @@
+project('reconfigure test', ['c'])
+
+if get_option('b_lto') != true
+  error('b_lto not set')
+endif