Skip to content

Commit 6762d30

Browse files
committed
Exposes the install names of targets in introspection. Closes #829.
1 parent 43a8ef7 commit 6762d30

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎mesonbuild/build.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,9 @@ def get_subdir(self):
12671267
def get_outputs(self):
12681268
return self.output
12691269

1270+
def get_filename(self):
1271+
return self.output[0]
1272+
12701273
def get_sources(self):
12711274
return self.sources
12721275

‎mesonbuild/mintro.py‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
project files and don't need this info."""
2121

2222
import json, pickle
23-
from . import coredata, build, mesonlib
23+
from . import coredata, build
2424
import argparse
2525
import sys, os
2626

@@ -41,7 +41,20 @@
4141
help='list external dependencies.')
4242
parser.add_argument('args', nargs='+')
4343

44-
def list_targets(coredata, builddata):
44+
def determine_installed_path(target, installdata):
45+
install_target = None
46+
for i in installdata.targets:
47+
if os.path.split(i[0])[1] == target.get_filename(): # FIXME, might clash due to subprojects.
48+
install_target = i
49+
break
50+
if install_target is None:
51+
raise RuntimeError('Something weird happened. File a bug.')
52+
fname = i[0]
53+
outdir = i[1]
54+
outname = os.path.join(installdata.prefix, outdir, os.path.split(fname)[-1])
55+
return outname
56+
57+
def list_targets(coredata, builddata, installdata):
4558
tlist = []
4659
for (idname, target) in builddata.get_targets().items():
4760
t = {}
@@ -68,6 +81,7 @@ def list_targets(coredata, builddata):
6881
t['type'] = typename
6982
if target.should_install():
7083
t['installed'] = True
84+
t['install_filename'] = determine_installed_path(target, installdata)
7185
else:
7286
t['installed'] = False
7387
tlist.append(t)
@@ -173,18 +187,21 @@ def run(args):
173187
bdir = ''
174188
corefile = os.path.join(bdir, 'meson-private/coredata.dat')
175189
buildfile = os.path.join(bdir, 'meson-private/build.dat')
190+
installfile = os.path.join(bdir, 'meson-private/install.dat')
176191
testfile = os.path.join(bdir, 'meson-private/meson_test_setup.dat')
177192
benchmarkfile = os.path.join(bdir, 'meson-private/meson_benchmark_setup.dat')
178193
with open(corefile, 'rb') as f:
179194
coredata = pickle.load(f)
180195
with open(buildfile, 'rb') as f:
181196
builddata = pickle.load(f)
182197
with open(testfile, 'rb') as f:
183-
testdata = pickle.load(f)
198+
testdata = pickle.load(f)
184199
with open(benchmarkfile, 'rb') as f:
185-
benchmarkdata = pickle.load(f)
200+
benchmarkdata = pickle.load(f)
201+
with open(installfile, 'rb') as f:
202+
installdata = pickle.load(f)
186203
if options.list_targets:
187-
list_targets(coredata, builddata)
204+
list_targets(coredata, builddata, installdata)
188205
elif options.target_files is not None:
189206
list_target_files(options.target_files, coredata, builddata)
190207
elif options.buildsystem_files:

‎run_unittests.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def setUp(self):
4343
self.builddir = tempfile.mkdtemp()
4444
self.meson_command = [sys.executable, os.path.join(src_root, 'meson.py')]
4545
self.mconf_command = [sys.executable, os.path.join(src_root, 'mesonconf.py')]
46+
self.mintro_command = [sys.executable, os.path.join(src_root, 'mesonintrospect.py')]
4647
self.ninja_command = [detect_ninja(), '-C', self.builddir]
4748
self.common_test_dir = os.path.join(src_root, 'test cases/common')
4849
self.vala_test_dir = os.path.join(src_root, 'test cases/vala')
@@ -67,6 +68,10 @@ def get_compdb(self):
6768
with open(os.path.join(self.builddir, 'compile_commands.json')) as ifile:
6869
return json.load(ifile)
6970

71+
def introspect(self, arg):
72+
out = subprocess.check_output(self.mintro_command + [arg, self.builddir])
73+
return json.loads(out.decode('utf-8'))
74+
7075
def test_basic_soname(self):
7176
testdir = os.path.join(self.common_test_dir, '4 shared')
7277
self.init(testdir)
@@ -147,5 +152,14 @@ def test_static_compile_order(self):
147152
self.assertTrue(compdb[3]['file'].endswith("libfile4.c"))
148153
# FIXME: We don't have access to the linker command
149154

155+
def test_install_introspection(self):
156+
testdir = os.path.join(self.common_test_dir, '8 install')
157+
self.init(testdir)
158+
intro = self.introspect('--targets')
159+
if intro[0]['type'] == 'executable':
160+
intro = intro[::-1]
161+
self.assertEqual(intro[0]['install_filename'], '/usr/local/libtest/libstat.a')
162+
self.assertEqual(intro[1]['install_filename'], '/usr/local/bin/prog')
163+
150164
if __name__ == '__main__':
151165
unittest.main()

0 commit comments

Comments
 (0)