Repository: mesonbuild/meson

Issue:
Running "meson configure" in source directory raises an exception (yet again)
Yes, it's Taisei again. Ping @mensinda.

If it helps, the taisei commit is https://github.com/taisei-project/taisei/commit/e68bfdb2ea86470fd138044af83af610de0b9d68

```
[0] [akari@navi] [master ← /data/git/taisei]
 % c
Unable to evaluate subdir([]) in AstInterpreter --> Skipping
Unable to evaluate subdir([]) in AstInterpreter --> Skipping
Unable to evaluate subdir([]) in AstInterpreter --> Skipping
WARNING: The source directory instead of the build directory was specified.
WARNING: Only the default values for the project are printed, and all command line parameters are ignored.

Core properties:
  Source dir /data/git/taisei

Core options:
  Option          Default Value Possible Values                                          Description                                             
  ------          ------------- ---------------                                          -----------                                             
  auto_features   auto          [enabled, disabled, auto]                                Override value of all 'auto' features                   
  backend         ninja         [ninja, vs, vs2010, vs2015, vs2017, vs2019, xcode]       Backend to use                                          
  buildtype       release       [plain, debug, debugoptimized, release, minsize, custom] Build type to use                                       
  debug           false         [true, false]                                            Debug                                                   
  default_library static        [shared, static, both]                                   Default library type                                    
  install_umask   0022          [preserve, 0000-0777]                                    Default umask to apply on permissions of installed files
  layout          mirror        [mirror, flat]                                           Build directory layout                                  
  optimization    3             [0, g, 1, 2, 3, s]                                       Optimization level                                      
  strip           true          [true, false]                                            Strip targets on install                                
  unity           off           [on, off, subprojects]                                   Unity build                                             
  warning_level   1             [0, 1, 2, 3]                                             Compiler warning level to use                           
  werror          false         [true, false]                                            Treat warnings as errors                                
  wrap_mode       default       [default, nofallback, nodownload, forcefallback]         Wrap mode                                               
Traceback (most recent call last):
  File "/data/git/meson/mesonbuild/mesonmain.py", line 129, in run
    return options.run_func(options)
  File "/data/git/meson/mesonbuild/mconf.py", line 216, in run
    c.print_conf()
  File "/data/git/meson/mesonbuild/mconf.py", line 184, in print_conf
    if self.build.environment.is_cross_build():
AttributeError: 'NoneType' object has no attribute 'environment'
```

Discussion:

Patch:
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index cac9d61ce..4f8014014 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -181,7 +181,7 @@ class Conf:
         core_options = {k: o for k, o in self.coredata.builtins.items() if k in core_option_names}
 
         self.print_options('Core options', core_options)
-        if self.build.environment.is_cross_build():
+        if self.default_values_only or self.build.environment.is_cross_build():
             self.print_options('Core options (for host machine)', self.coredata.builtins_per_machine.host)
             self.print_options(
                 'Core options (for build machine)',
@@ -190,7 +190,7 @@ class Conf:
             self.print_options('Core options', self.coredata.builtins_per_machine.host)
         self.print_options('Backend options', self.coredata.backend_options)
         self.print_options('Base options', self.coredata.base_options)
-        if self.build.environment.is_cross_build():
+        if self.default_values_only or self.build.environment.is_cross_build():
             self.print_options('Compiler options (for host machine)', self.coredata.compiler_options.host)
             self.print_options(
                 'Compiler options (for build machine)',


Test patch:
diff --git a/run_unittests.py b/run_unittests.py
index f06be23ae..8cc981148 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -3624,6 +3624,10 @@ recommended as it is not supported on some platforms''')
         self.maxDiff = None
         self.assertListEqual(res_nb, res_wb)
 
+    def test_meson_configure_from_source_does_not_crash(self):
+        testdir = os.path.join(self.unit_test_dir, '59 introspect buildoptions')
+        self._run(self.mconf_command + [testdir])
+
     def test_introspect_json_dump(self):
         testdir = os.path.join(self.unit_test_dir, '57 introspection')
         self.init(testdir)