Repository: mesonbuild/meson

Issue:
Regression: 'meson introspect --projectinfo' doesn't list subprojects with 0.49.0
Running `meson introspect --projectinfo build/` in [gst-build](https://gitlab.freedesktop.org/gstreamer/gst-build) no longers lists the subprojects with 0.49.0 while it does with 0.48.2

```
# meson introspect --projectinfo build/
{"version": "1.15.0.1", "descriptive_name": "All GStreamer modules", "subprojects": []}
[root@zynq gst-build]# meson --version
0.49.0

# meson introspect --projectinfo build/
{"name": "All GStreamer modules", "version": "1.15.0.1", "subprojects": [{"name": "gstreamer", "version": "1.15.0.1"}, {"name": "gl-headers", "version": "0.0.0"}, {"name": "gst-plugins-base", "version": "1.15.0.1"}, {"name": "gst-plugins-good", "version": "1.15.0.1"}, {"name": "dssim", "version": "1.3.2.1"}, {"name": "gst-plugins-bad", "version": "1.15.0.1"}, {"name": "gst-plugins-ugly", "version": "1.15.0.1"}, {"name": "gst-omx", "version": "1.15.0.1"}, {"name": "gst-rtsp-server", "version": "1.15.0.1"}, {"name": "gst-devtools", "version": "1.15.0.1"}, {"name": "gst-editing-services", "version": "1.15.0.1"}]}
[root@zynq gst-build]# 
[root@zynq gst-build]# meson --version
0.48.2
```
This breaks https://gitlab.freedesktop.org/gstreamer/gst-build/blob/master/checkout-branch-worktree which relies on this output.


Discussion:
@mensinda could this be caused by one of the introspect refactorings?
I am currently looking into it but I doubt it (most of it is not merged). The introspection code itself does not seem to be broken, but `Build.subprojects` (or `builddata.subprojects`) is an empty dict [here](https://github.com/mesonbuild/meson/blob/master/mesonbuild/mintro.py#L232).

Resolving patch:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2359,11 +2359,11 @@ def do_subproject(self, dirname, kwargs):
             if pv == 'undefined' or not mesonlib.version_compare_many(pv, wanted)[0]:
                 raise InterpreterException('Subproject %s version is %s but %s required.' % (dirname, pv, wanted))
         self.active_projectname = current_active
-        self.build.subprojects[dirname] = subi.project_version
         self.subprojects.update(subi.subprojects)
         self.subprojects[dirname] = SubprojectHolder(subi, self.subproject_dir, dirname)
         self.build_def_files += subi.build_def_files
         self.build.merge(subi.build)
+        self.build.subprojects[dirname] = subi.project_version
         return self.subprojects[dirname]
 
     def get_option_internal(self, optname):
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -2995,6 +2995,23 @@ def test_introspect_projectinfo_without_configured_build(self):
         self.assertEqual(res['subprojects'][0]['version'], 'undefined')
         self.assertEqual(res['subprojects'][0]['descriptive_name'], 'subproject')
 
+    def test_introspect_projectinfo_subprojects(self):
+        testdir = os.path.join(self.common_test_dir, '103 subproject subdir')
+        self.init(testdir)
+        res = self.introspect('--projectinfo')
+        expected = {
+            'descriptive_name': 'proj',
+            'version': 'undefined',
+            'subprojects': [
+                {
+                    'descriptive_name': 'sub',
+                    'name': 'sub',
+                    'version': 'undefined'
+                }
+            ]
+        }
+        self.assertDictEqual(res, expected)
+
 
 class FailureTests(BasePlatformTests):
     '''


Test patch: