Skip to content

Commit

Permalink
fix2865
Browse files Browse the repository at this point in the history
  • Loading branch information
tvichii committed Mar 29, 2018
1 parent b4aee46 commit 8376631
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ def __init__(self, name, subdir, subproject, is_cross, sources, objects, environ
self.process_compilers_late()
self.validate_sources()
self.validate_cross_install(environment)
self.check_module_linking()

def __lt__(self, other):
return self.get_id() < other.get_id()
Expand Down Expand Up @@ -1027,6 +1028,13 @@ def get_using_msvc(self):
def is_linkable_target(self):
return False

def check_module_linking(self):
'''
Warn if shared modules are linked with target: (link_with) #2865
'''
for link_target in self.link_targets:
if isinstance(link_target, SharedModule):
mlog.warning('''Linking shared modules to targets is not recommended''')

class Generator:
def __init__(self, args, kwargs):
Expand Down
11 changes: 11 additions & 0 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,17 @@ def test_flock(self):
exception_raised = True
self.assertTrue(exception_raised, 'Double locking did not raise exception.')

def test_check_module_linking(self):
'''
Test that shared modules are not linked with targets(link_with:) #2865
'''
tdir = os.path.join(self.unit_test_dir, '25 shared_mod linking')
out = self.init(tdir)
for expected in [
r'WARNING: Linking shared modules to targets is not recommended'
]:
self.assertRegex(out, re.escape(expected))

def test_ndebug_if_release_disabled(self):
testdir = os.path.join(self.unit_test_dir, '25 ndebug if-release')
self.init(testdir, extra_args=['--buildtype=release', '-Db_ndebug=if-release'])
Expand Down
1 change: 1 addition & 0 deletions test cases/unit/25 shared_mod linking/installed_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/bin/prog?exe
14 changes: 14 additions & 0 deletions test cases/unit/25 shared_mod linking/libfile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#if defined _WIN32 || defined __CYGWIN__
#define DLL_PUBLIC __declspec(dllexport)
#else
#if defined __GNUC__
#define DLL_PUBLIC __attribute__ ((visibility("default")))
#else
#pragma message ("Compiler does not support symbol visibility.")
#define DLL_PUBLIC
#endif
#endif

int DLL_PUBLIC func() {
return 0;
}
11 changes: 11 additions & 0 deletions test cases/unit/25 shared_mod linking/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if defined _WIN32 || defined __CYGWIN__
#define DLL_IMPORT __declspec(dllimport)
#else
#define DLL_IMPORT
#endif

int DLL_IMPORT func();

int main(int argc, char **arg) {
return func();
}
6 changes: 6 additions & 0 deletions test cases/unit/25 shared_mod linking/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project('shared library linking test', 'c', 'cpp')

lib = shared_module('mylib',
'libfile.c' # Split to different lines before and after the comma to test parser.
, install : false) # Don't install libraries in common tests; the path is platform-specific
exe = executable('prog', 'main.c', link_with : lib, install : true)

0 comments on commit 8376631

Please sign in to comment.