Repository: mesonbuild/meson

Issue:
Introspection API: missing info about `install_subdir`
`meson-info/intro-installed.json` does not contain any information about files/directories installed via `install_subdir`.

PS: `meson-logs/install-log.txt` contains such info, so it probably could be used as a reference.


Discussion:
I am not sure how we should handle this, because the complete file list is not known for subdirs at configure time. It is only when `meson install` is executed that the directories are scanned.

The install data known at configure time only stores the source and destination directory. Adding this to the introspection output would be trivial, however, this would not contain the content of the directory.

Do you need the full install information, or would the source and destination directory be enough?
> would the source and destination directory be enough?

Folder itself would be enough for my case, and, IMO, it would be the correct behaviour as well: `install_subdir` means "install everything that is there and I don't care what it is".

Resolving patch:
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -123,6 +123,8 @@ def list_installed(installdata):
             res[path] = os.path.join(installdata.prefix, installdir, os.path.basename(path))
         for path, installpath, _ in installdata.man:
             res[path] = os.path.join(installdata.prefix, installpath)
+        for path, installpath, _, _ in installdata.install_subdirs:
+            res[path] = os.path.join(installdata.prefix, installpath)
     return res
 
 def list_targets_from_source(intr: IntrospectionInterpreter):
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1695,6 +1695,34 @@ def test_install_introspection(self):
         self.assertPathListEqual(intro[0]['install_filename'], ['/usr/lib/libstat.a'])
         self.assertPathListEqual(intro[1]['install_filename'], ['/usr/bin/prog' + exe_suffix])
 
+    def test_install_subdir_introspection(self):
+        '''
+        Test that the Meson introspection API also contains subdir install information
+        https://github.com/mesonbuild/meson/issues/5556
+        '''
+        testdir = os.path.join(self.common_test_dir, '63 install subdir')
+        self.init(testdir)
+        intro = self.introspect('--installed')
+        expected = {
+            'sub2': 'share/sub2',
+            'subdir/sub1': 'share/sub1',
+            'subdir/sub_elided': 'share',
+            'sub1': 'share/sub1',
+            'sub/sub1': 'share/sub1',
+            'sub_elided': 'share',
+            'nested_elided/sub': 'share',
+        }
+
+        self.assertEqual(len(intro), len(expected))
+
+        # Convert expected to PurePath
+        expected_converted = {PurePath(os.path.join(testdir, key)): PurePath(os.path.join(self.prefix, val)) for key, val in expected.items()}
+        intro_converted = {PurePath(key): PurePath(val) for key, val in intro.items()}
+
+        for src, dst in expected_converted.items():
+            self.assertIn(src, intro_converted)
+            self.assertEqual(dst, intro_converted[src])
+
     def test_install_introspection_multiple_outputs(self):
         '''
         Tests that the Meson introspection API exposes multiple install filenames correctly without crashing


Test patch: