From 2d0eb2cec5abc46f7152a4dfb115e816c9199b2d Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 10 Oct 2016 19:22:41 +0530 Subject: [PATCH 1/2] Warn if -fPIC is passed instead of pic to static libraries Also print the name of the static library that has PIC-related issues, print more details in exceptions, and test for all this. --- mesonbuild/build.py | 21 ++++++++++++------- .../common/62 exe static shared/meson.build | 6 +++++- .../common/62 exe static shared/shlib2.c | 3 ++- .../common/62 exe static shared/stat2.c | 3 +++ 4 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 test cases/common/62 exe static shared/stat2.c diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 3d41cda4a..838d8ad2b 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -510,18 +510,18 @@ class BuildTarget(): name_prefix = kwargs['name_prefix'] if isinstance(name_prefix, list): if len(name_prefix) != 0: - raise InvalidArguments('Array must be empty to signify null.') + raise InvalidArguments('name_prefix array must be empty to signify null.') elif not isinstance(name_prefix, str): - raise InvalidArguments('Name prefix must be a string.') + raise InvalidArguments('name_prefix must be a string.') self.prefix = name_prefix if 'name_suffix' in kwargs: name_suffix = kwargs['name_suffix'] if isinstance(name_suffix, list): if len(name_suffix) != 0: - raise InvalidArguments('Array must be empty to signify null.') + raise InvalidArguments('name_suffix array must be empty to signify null.') else: if not isinstance(name_suffix, str): - raise InvalidArguments('Name suffix must be a string.') + raise InvalidArguments('name_suffix must be a string.') self.suffix = name_suffix if isinstance(self, StaticLibrary): # You can't disable PIC on OS X. The compiler ignores -fno-PIC. @@ -529,10 +529,13 @@ class BuildTarget(): # since library loading is done differently) if for_darwin(self.is_cross, self.environment) or for_windows(self.is_cross, self.environment): self.pic = True + elif '-fPIC' in clist + cpplist: + mlog.log(mlog.red('WARNING:'), "Use the 'pic' kwarg instead of passing -fPIC manually to static library {!r}".format(self.name)) + self.pic = True else: self.pic = kwargs.get('pic', False) if not isinstance(self.pic, bool): - raise InvalidArguments('Argument pic must be boolean') + raise InvalidArguments('Argument pic to static library {!r} must be boolean'.format(self.name)) def get_subdir(self): return self.subdir @@ -634,11 +637,13 @@ by calling get_variable() on the subproject object.''') if hasattr(t, 'held_object'): t = t.held_object if not isinstance(t, (StaticLibrary, SharedLibrary)): - raise InvalidArguments('Link target is not library.') + raise InvalidArguments('Link target {!r} is not library.'.format(t.name)) if isinstance(self, SharedLibrary) and isinstance(t, StaticLibrary) and not t.pic: - raise InvalidArguments("Can't link a non-PIC static library into a shared library") + msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name) + msg += "Use the 'pic' option to static_library to build with PIC." + raise InvalidArguments(msg) if self.is_cross != t.is_cross: - raise InvalidArguments('Tried to mix cross built and native libraries in target %s.' % self.name) + raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name)) self.link_targets.append(t) def set_generated(self, genlist): diff --git a/test cases/common/62 exe static shared/meson.build b/test cases/common/62 exe static shared/meson.build index 8631e68f1..288888284 100644 --- a/test cases/common/62 exe static shared/meson.build +++ b/test cases/common/62 exe static shared/meson.build @@ -1,7 +1,11 @@ project('statchain', 'c') subdir('subdir') -statlib = static_library('stat', 'stat.c', link_with : shlib, pic : true) +# Test that -fPIC in c_args is also accepted +statlib2 = static_library('stat2', 'stat2.c', c_args : '-fPIC', pic : false) +# Test that pic is needed for both direct and indirect static library +# dependencies of shared libraries (on Linux and BSD) +statlib = static_library('stat', 'stat.c', link_with : [shlib, statlib2], pic : true) shlib2 = shared_library('shr2', 'shlib2.c', link_with : statlib) exe = executable('prog', 'prog.c', link_with : shlib2) test('runtest', exe) diff --git a/test cases/common/62 exe static shared/shlib2.c b/test cases/common/62 exe static shared/shlib2.c index e26d11c73..12bc913d7 100644 --- a/test cases/common/62 exe static shared/shlib2.c +++ b/test cases/common/62 exe static shared/shlib2.c @@ -1,7 +1,8 @@ #include "subdir/exports.h" int statlibfunc(void); +int statlibfunc2(void); int DLL_PUBLIC shlibfunc2(void) { - return statlibfunc() - 18; + return statlibfunc() - statlibfunc2(); } diff --git a/test cases/common/62 exe static shared/stat2.c b/test cases/common/62 exe static shared/stat2.c new file mode 100644 index 000000000..4ae3775f7 --- /dev/null +++ b/test cases/common/62 exe static shared/stat2.c @@ -0,0 +1,3 @@ +int statlibfunc2() { + return 18; +} From 6a002a7bea8860590fd1ad54d2e12b91c5137e1f Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 10 Oct 2016 23:27:50 +0530 Subject: [PATCH 2/2] tests/gnome: Add missing enums.h dep to enums2.c Was causing intermittent test failures --- test cases/frameworks/7 gnome/mkenums/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test cases/frameworks/7 gnome/mkenums/meson.build b/test cases/frameworks/7 gnome/mkenums/meson.build index efd6b041c..e01e9ebc5 100644 --- a/test cases/frameworks/7 gnome/mkenums/meson.build +++ b/test cases/frameworks/7 gnome/mkenums/meson.build @@ -32,7 +32,7 @@ enums_h2 = gnome.mkenums('abc2', enums_c2 = gnome.mkenums('abc2', sources : 'meson-sample.h', - depends : enums_h2, + depends : [enums_h1, enums_h2], c_template : 'enums2.c.in', ftail : '/* trailing source file info */', install_header : true,