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:
TingPing: ```python
  File "/home/tingping/.local/bin/mesonintrospect", line 4, in <module>
    __import__('pkg_resources').run_script('meson==0.36.0.dev1', 'mesonintrospect')
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 746, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 1501, in run_script
    exec(code, namespace, namespace)
  File "/home/tingping/.local/lib/python3.5/site-packages/meson-0.36.0.dev1-py3.5.egg/EGG-INFO/scripts/mesonintrospect", line 20, in <module>
    sys.exit(mintro.run(sys.argv[1:]))
  File "/home/tingping/.local/lib/python3.5/site-packages/meson-0.36.0.dev1-py3.5.egg/mesonbuild/mintro.py", line 204, in run
    list_targets(coredata, builddata, installdata)
  File "/home/tingping/.local/lib/python3.5/site-packages/meson-0.36.0.dev1-py3.5.egg/mesonbuild/mintro.py", line 84, in list_targets
    t['install_filename'] = determine_installed_path(target, installdata)
  File "/home/tingping/.local/lib/python3.5/site-packages/meson-0.36.0.dev1-py3.5.egg/mesonbuild/mintro.py", line 51, in determine_installed_path
    raise RuntimeError('Something weird happened. File a bug.')
RuntimeError: Something weird happened. File a bug.
```
jpakkane: Which project did this happen on?
TingPing: gnome-builder, it has quite a few targets and worked with current master.

Patch:
diff --git a/authors.txt b/authors.txt
index 5931481af..f591d13db 100644
--- a/authors.txt
+++ b/authors.txt
@@ -53,3 +53,4 @@ Gautier Pelloux-Prayer
 Alexandre Foley
 Jouni Kosonen
 Aurelien Jarno
+Mark Schulte
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index fd719241e..e91b44b8d 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -200,11 +200,15 @@ class Backend():
         with open(exe_data, 'wb') as f:
             if isinstance(exe, dependencies.ExternalProgram):
                 exe_fullpath = exe.fullpath
+                exe_needs_wrapper = False
             elif isinstance(exe, (build.BuildTarget, build.CustomTarget)):
                 exe_fullpath = [self.get_target_filename_abs(exe)]
+                exe_needs_wrapper = exe.is_cross
             else:
                 exe_fullpath = [exe]
-            is_cross = self.environment.is_cross_build() and \
+                exe_needs_wrapper = False
+            is_cross = exe_needs_wrapper and \
+                self.environment.is_cross_build() and \
                 self.environment.cross_info.need_cross_compiler() and \
                 self.environment.cross_info.need_exe_wrapper()
             if is_cross:
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 1d687d825..c3867e0ab 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1267,6 +1267,9 @@ class CustomTarget:
     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/compilers.py b/mesonbuild/compilers.py
index 2d7a08079..d7cd1f78e 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -1950,7 +1950,8 @@ class GnuCCompiler(GnuCompiler, CCompiler):
 
     def get_options(self):
         opts = {'c_std' : coredata.UserComboOption('c_std', 'C language standard to use',
-                                                   ['none', 'c89', 'c99', 'c11', 'gnu89', 'gnu99', 'gnu11'],
+                                                   ['none', 'c89', 'c99', 'c11',
+                                                    'gnu89', 'gnu99', 'gnu11'],
                                                    'none')}
         if self.gcc_type == GCC_MINGW:
             opts.update({
@@ -2084,7 +2085,8 @@ class ClangCCompiler(ClangCompiler, CCompiler):
 
     def get_options(self):
         return {'c_std' : coredata.UserComboOption('c_std', 'C language standard to use',
-                                                   ['none', 'c89', 'c99', 'c11'],
+                                                   ['none', 'c89', 'c99', 'c11',
+                                                    'gnu89', 'gnu99', 'gnu11',],
                                                    'none')}
 
     def get_option_compile_args(self, options):
@@ -2111,8 +2113,9 @@ class ClangCPPCompiler(ClangCompiler,   CPPCompiler):
 
     def get_options(self):
         return {'cpp_std' : coredata.UserComboOption('cpp_std', 'C++ language standard to use',
-                                                   ['none', 'c++03', 'c++11', 'c++14', 'c++1z'],
-                                                   'none')}
+                                                     ['none', 'c++03', 'c++11', 'c++14', 'c++1z',
+                                                      'gnu++03', 'gnu++11', 'gnu++14', 'gnu++1z'],
+                                                     'none')}
 
     def get_option_compile_args(self, options):
         args = []
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index a18912eb1..492bf3f0e 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -20,7 +20,7 @@ Currently only works for the Ninja backend. Others use generated
 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 @@ parser.add_argument('--dependencies', action='store_true', dest='dependencies',
                     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:


Test patch:
diff --git a/run_unittests.py b/run_unittests.py
index 9391eaef7..0e3b7d5be 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -43,6 +43,7 @@ class LinuxlikeTests(unittest.TestCase):
         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 @@ class LinuxlikeTests(unittest.TestCase):
         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 @@ class LinuxlikeTests(unittest.TestCase):
         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()