Add build_rpath as new property allowing people to specify rpath entries that are used in the build tree but will be removed on install.

pull/2063/head
Jussi Pakkanen 7 years ago
parent 381e8313ed
commit 2269b7f60b
  1. 2
      mesonbuild/backend/ninjabackend.py
  2. 4
      mesonbuild/build.py
  3. 6
      mesonbuild/compilers/c.py
  4. 7
      mesonbuild/compilers/compilers.py
  5. 2
      mesonbuild/compilers/cs.py
  6. 8
      mesonbuild/compilers/d.py
  7. 4
      mesonbuild/compilers/fortran.py
  8. 2
      mesonbuild/compilers/java.py
  9. 4
      mesonbuild/compilers/rust.py
  10. 1
      mesonbuild/interpreter.py
  11. 4
      mesonbuild/linkers.py
  12. 11
      run_unittests.py
  13. 9
      test cases/unit/11 build_rpath/meson.build
  14. 5
      test cases/unit/11 build_rpath/prog.c
  15. 1
      test cases/unit/11 build_rpath/sub/meson.build
  16. 3
      test cases/unit/11 build_rpath/sub/stuff.c

@ -1211,6 +1211,7 @@ int dummy;
rpath_args = rustc.build_rpath_args(self.environment.get_build_dir(),
target_slashname_workaround_dir,
self.determine_rpath_dirs(target),
target.build_rpath,
target.install_rpath)
# ... but then add rustc's sysroot to account for rustup
# installations
@ -2387,6 +2388,7 @@ rule FORTRAN_DEP_HACK
commands += linker.build_rpath_args(self.environment.get_build_dir(),
target_slashname_workaround_dir,
self.determine_rpath_dirs(target),
target.build_rpath,
target.install_rpath)
# Add libraries generated by custom targets
custom_target_libraries = self.get_custom_target_provided_libraries(target)

@ -49,6 +49,7 @@ known_basic_kwargs = {'install': True,
'gui_app': True,
'extra_files': True,
'install_rpath': True,
'build_rpath': True,
'resources': True,
'sources': True,
'objects': True,
@ -707,6 +708,9 @@ class BuildTarget(Target):
self.install_rpath = kwargs.get('install_rpath', '')
if not isinstance(self.install_rpath, str):
raise InvalidArguments('Install_rpath is not a string.')
self.build_rpath = kwargs.get('build_rpath', '')
if not isinstance(self.build_rpath, str):
raise InvalidArguments('Build_rpath is not a string.')
resources = kwargs.get('resources', [])
if not isinstance(resources, list):
resources = [resources]

@ -87,8 +87,8 @@ class CCompiler(Compiler):
return None, fname
# The default behavior is this, override in MSVC
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, install_rpath)
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
def get_dependency_gen_args(self, outtarget, outfile):
return ['-MMD', '-MQ', outtarget, '-MF', outfile]
@ -909,7 +909,7 @@ class VisualStudioCCompiler(CCompiler):
"The name of the outputted import library"
return ['/IMPLIB:' + implibname]
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return []
# FIXME, no idea what these should be.

@ -798,8 +798,8 @@ class Compiler:
def get_instruction_set_args(self, instruction_set):
return None
def build_unix_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
if not rpath_paths and not install_rpath:
def build_unix_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
if not rpath_paths and not install_rpath and not build_rpath:
return []
# The rpaths we write must be relative, because otherwise
# they have different length depending on the build
@ -812,6 +812,9 @@ class Compiler:
relative = os.path.relpath(os.path.join(build_dir, p), os.path.join(build_dir, from_dir))
rel_rpaths.append(relative)
paths = ':'.join([os.path.join('$ORIGIN', p) for p in rel_rpaths])
# Build_rpath is used as-is (it is usually absolute).
if build_rpath != '':
paths += ':' + build_rpath
if len(paths) < len(install_rpath):
padding = 'X' * (len(install_rpath) - len(paths))
if not paths:

@ -43,7 +43,7 @@ class MonoCompiler(Compiler):
def split_shlib_to_parts(self, fname):
return None, fname
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return []
def get_dependency_gen_args(self, outtarget, outfile):

@ -88,12 +88,14 @@ class DCompiler(Compiler):
def get_std_exe_link_args(self):
return []
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
# This method is to be used by LDC and DMD.
# GDC can deal with the verbatim flags.
if not rpath_paths and not install_rpath:
return []
paths = ':'.join([os.path.join(build_dir, p) for p in rpath_paths])
if build_rpath != '':
paths += ':' + build_rpath
if len(paths) < len(install_rpath):
padding = 'X' * (len(install_rpath) - len(paths))
if not paths:
@ -212,8 +214,8 @@ class GnuDCompiler(DCompiler):
def get_buildtype_args(self, buildtype):
return d_gdc_buildtype_args[buildtype]
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, install_rpath)
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
def get_unittest_args(self):
return ['-funittest']

@ -132,8 +132,8 @@ end program prog
def get_std_exe_link_args(self):
return []
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, install_rpath)
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
def module_name_to_filename(self, module_name):
return module_name.lower() + '.mod'

@ -34,7 +34,7 @@ class JavaCompiler(Compiler):
def split_shlib_to_parts(self, fname):
return None, fname
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return []
def get_dependency_gen_args(self, outtarget, outfile):

@ -50,8 +50,8 @@ class RustCompiler(Compiler):
def get_buildtype_args(self, buildtype):
return rust_buildtype_args[buildtype]
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, install_rpath)
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
def get_sysroot(self):
cmd = self.exelist + ['--print', 'sysroot']

@ -1241,6 +1241,7 @@ rust_kwargs = set(['rust_crate_type'])
cs_kwargs = set(['resources'])
buildtarget_kwargs = set(['build_by_default',
'build_rpath',
'dependencies',
'extra_files',
'gui_app',

@ -45,7 +45,7 @@ class VisualStudioLinker(StaticLinker):
def get_linker_always_args(self):
return VisualStudioLinker.always_args
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return []
def thread_link_flags(self):
@ -76,7 +76,7 @@ class ArLinker(StaticLinker):
else:
self.std_args = ['csr']
def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath):
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
return []
def get_exelist(self):

@ -1850,6 +1850,17 @@ class LinuxlikeTests(BasePlatformTests):
self.assertTrue(glib_found)
self.assertTrue(gobject_found)
def test_build_rpath(self):
testdir = os.path.join(self.unit_test_dir, '11 build_rpath')
self.init(testdir)
self.build()
build_rpath = get_rpath(os.path.join(self.builddir, 'prog'))
self.assertEqual(build_rpath, '$ORIGIN/sub:/foo/bar')
self.install()
install_rpath = get_rpath(os.path.join(self.installdir, 'usr/bin/prog'))
self.assertEqual(install_rpath, '/baz')
class LinuxArmCrossCompileTests(BasePlatformTests):
'''
Tests that verify cross-compilation to Linux/ARM

@ -0,0 +1,9 @@
project('build rpath', 'c')
subdir('sub')
executable('prog', 'prog.c',
link_with : l,
build_rpath : '/foo/bar',
install_rpath : '/baz',
install : true,
)

@ -0,0 +1,5 @@
int get_stuff();
int main(int argc, char **argv) {
return get_stuff();
}

@ -0,0 +1 @@
l = shared_library('stuff', 'stuff.c')

@ -0,0 +1,3 @@
int get_stuff() {
return 0;
}
Loading…
Cancel
Save