Repository: mesonbuild/meson

Issue:
mesonintrospect: Expose install_dir for targets
Mentioned on the [gnome-builder issue](https://bugzilla.gnome.org/show_bug.cgi?id=743280) this would be useful information.



Discussion:

Resolving patch:
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1267,6 +1267,9 @@ def get_subdir(self):
     def get_outputs(self):
         return self.output
 
+    def get_filename(self):
+        return self.output[0]
+
     def get_sources(self):
         return self.sources
 
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -20,7 +20,7 @@
 project files and don't need this info."""
 
 import json, pickle
-from . import coredata, build, mesonlib
+from . import coredata, build
 import argparse
 import sys, os
 
@@ -41,7 +41,20 @@
                     help='list external dependencies.')
 parser.add_argument('args', nargs='+')
 
-def list_targets(coredata, builddata):
+def determine_installed_path(target, installdata):
+    install_target = None
+    for i in installdata.targets:
+        if os.path.split(i[0])[1] == target.get_filename(): # FIXME, might clash due to subprojects.
+            install_target = i
+            break
+    if install_target is None:
+        raise RuntimeError('Something weird happened. File a bug.')
+    fname = i[0]
+    outdir = i[1]
+    outname = os.path.join(installdata.prefix, outdir, os.path.split(fname)[-1])
+    return outname
+
+def list_targets(coredata, builddata, installdata):
     tlist = []
     for (idname, target) in builddata.get_targets().items():
         t = {}
@@ -68,6 +81,7 @@ def list_targets(coredata, builddata):
         t['type'] = typename
         if target.should_install():
             t['installed'] = True
+            t['install_filename'] = determine_installed_path(target, installdata)
         else:
             t['installed'] = False
         tlist.append(t)
@@ -173,6 +187,7 @@ def run(args):
         bdir = ''
     corefile = os.path.join(bdir, 'meson-private/coredata.dat')
     buildfile = os.path.join(bdir, 'meson-private/build.dat')
+    installfile = os.path.join(bdir, 'meson-private/install.dat')
     testfile = os.path.join(bdir, 'meson-private/meson_test_setup.dat')
     benchmarkfile = os.path.join(bdir, 'meson-private/meson_benchmark_setup.dat')
     with open(corefile, 'rb') as f:
@@ -180,11 +195,13 @@ def run(args):
     with open(buildfile, 'rb') as f:
         builddata = pickle.load(f)
     with open(testfile, 'rb') as f:
-       testdata = pickle.load(f)
+        testdata = pickle.load(f)
     with open(benchmarkfile, 'rb') as f:
-       benchmarkdata = pickle.load(f)
+        benchmarkdata = pickle.load(f)
+    with open(installfile, 'rb') as f:
+        installdata = pickle.load(f)
     if options.list_targets:
-        list_targets(coredata, builddata)
+        list_targets(coredata, builddata, installdata)
     elif options.target_files is not None:
         list_target_files(options.target_files, coredata, builddata)
     elif options.buildsystem_files:
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -43,6 +43,7 @@ def setUp(self):
         self.builddir = tempfile.mkdtemp()
         self.meson_command = [sys.executable, os.path.join(src_root, 'meson.py')]
         self.mconf_command = [sys.executable, os.path.join(src_root, 'mesonconf.py')]
+        self.mintro_command = [sys.executable, os.path.join(src_root, 'mesonintrospect.py')]
         self.ninja_command = [detect_ninja(), '-C', self.builddir]
         self.common_test_dir = os.path.join(src_root, 'test cases/common')
         self.vala_test_dir = os.path.join(src_root, 'test cases/vala')
@@ -67,6 +68,10 @@ def get_compdb(self):
         with open(os.path.join(self.builddir, 'compile_commands.json')) as ifile:
             return json.load(ifile)
 
+    def introspect(self, arg):
+        out = subprocess.check_output(self.mintro_command + [arg, self.builddir])
+        return json.loads(out.decode('utf-8'))
+
     def test_basic_soname(self):
         testdir = os.path.join(self.common_test_dir, '4 shared')
         self.init(testdir)
@@ -147,5 +152,14 @@ def test_static_compile_order(self):
         self.assertTrue(compdb[3]['file'].endswith("libfile4.c"))
         # FIXME: We don't have access to the linker command
 
+    def test_install_introspection(self):
+        testdir = os.path.join(self.common_test_dir, '8 install')
+        self.init(testdir)
+        intro = self.introspect('--targets')
+        if intro[0]['type'] == 'executable':
+            intro = intro[::-1]
+        self.assertEqual(intro[0]['install_filename'], '/usr/local/libtest/libstat.a')
+        self.assertEqual(intro[1]['install_filename'], '/usr/local/bin/prog')
+
 if __name__ == '__main__':
     unittest.main()


Test patch: