From bcd076276ec1648c0aa30ce0c81fe1822d2687d0 Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Tue, 6 Mar 2018 23:55:07 +0000 Subject: [PATCH 1/3] Add 'common/180 generator link whole' test case This test covers usage of generated files in static_library that is later linked into shared_library. --- .../common/180 generator link whole/export.h | 18 ++++++ .../180 generator link whole/generator.py | 30 ++++++++++ .../common/180 generator link whole/main.c | 11 ++++ .../180 generator link whole/meson.build | 58 +++++++++++++++++++ .../meson_test_function.tmpl | 0 .../pull_meson_test_function.c | 6 ++ 6 files changed, 123 insertions(+) create mode 100644 test cases/common/180 generator link whole/export.h create mode 100755 test cases/common/180 generator link whole/generator.py create mode 100644 test cases/common/180 generator link whole/main.c create mode 100644 test cases/common/180 generator link whole/meson.build create mode 100644 test cases/common/180 generator link whole/meson_test_function.tmpl create mode 100644 test cases/common/180 generator link whole/pull_meson_test_function.c diff --git a/test cases/common/180 generator link whole/export.h b/test cases/common/180 generator link whole/export.h new file mode 100644 index 000000000..f4f6f451b --- /dev/null +++ b/test cases/common/180 generator link whole/export.h @@ -0,0 +1,18 @@ +#pragma once + +#if defined BUILDING_EMBEDDED + #define DLL_PUBLIC +#elif defined _WIN32 || defined __CYGWIN__ + #if defined BUILDING_DLL + #define DLL_PUBLIC __declspec(dllexport) + #else + #define DLL_PUBLIC __declspec(dllimport) + #endif +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif diff --git a/test cases/common/180 generator link whole/generator.py b/test cases/common/180 generator link whole/generator.py new file mode 100755 index 000000000..0076b7499 --- /dev/null +++ b/test cases/common/180 generator link whole/generator.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import os +import os.path +import sys + + +def main(): + name = os.path.splitext(os.path.basename(sys.argv[1]))[0] + out = sys.argv[2] + hname = os.path.join(out, name + '.h') + cname = os.path.join(out, name + '.c') + print(os.getcwd(), hname) + with open(hname, 'w') as hfile: + hfile.write(''' +#pragma once +#include "export.h" +int DLL_PUBLIC {name}(); +'''.format(name=name)) + with open(cname, 'w') as cfile: + cfile.write(''' +#include "{name}.h" +int {name}() {{ + return {size}; +}} +'''.format(name=name, size=len(name))) + + +if __name__ == '__main__': + main() diff --git a/test cases/common/180 generator link whole/main.c b/test cases/common/180 generator link whole/main.c new file mode 100644 index 000000000..acf871782 --- /dev/null +++ b/test cases/common/180 generator link whole/main.c @@ -0,0 +1,11 @@ +#include "meson_test_function.h" + +#include + +int main() { + if (meson_test_function() != 19) { + printf("Bad meson_test_function()\n"); + return 1; + } + return 0; +} diff --git a/test cases/common/180 generator link whole/meson.build b/test cases/common/180 generator link whole/meson.build new file mode 100644 index 000000000..f43e7cd0d --- /dev/null +++ b/test cases/common/180 generator link whole/meson.build @@ -0,0 +1,58 @@ +project('generator link_whole', 'c') + +# This just generates foo.h and foo.c with int foo() defined. +gen_py = find_program('generator.py') +gen = generator(gen_py, + output: ['@BASENAME@.h', '@BASENAME@.c'], + arguments : ['@INPUT@', '@BUILD_DIR@']) + +# Test 1: link directly into executable +srcs = gen.process('meson_test_function.tmpl') +exe = executable('exe1', [srcs, 'main.c'], c_args : '-DBUILDING_EMBEDDED') +test('test1', exe) + +# Test 2: link into shared library and access from executable +srcs = gen.process('meson_test_function.tmpl') +shlib2 = shared_library('shlib2', [srcs], c_args : '-DBUILDING_DLL') +exe = executable('exe2', 'main.c', + link_with : shlib2, + include_directories : shlib2.private_dir_include(), +) +test('test2', exe) + +# Test 3: link into static library and access from executable +srcs = gen.process('meson_test_function.tmpl') +stlib3 = static_library('stlib3', [srcs], c_args : '-DBUILDING_EMBEDDED') +exe = executable('exe3', 'main.c', + c_args : '-DBUILDING_EMBEDDED', + link_with : stlib3, + include_directories : stlib3.private_dir_include(), +) +test('test3', exe) + +# Test 4: link into static library, link into shared +# and access from executable. To make sure static_library +# is not dropped use pull_meson_test_function helper. +srcs = gen.process('meson_test_function.tmpl') +stlib4 = static_library('stlib4', [srcs], c_args : '-DBUILDING_DLL') +shlib4 = shared_library('shlib4', 'pull_meson_test_function.c', + c_args : '-DBUILDING_DLL', + link_with : stlib4, + include_directories : stlib4.private_dir_include(), +) +exe = executable('exe4', 'main.c', + link_with : shlib4, + include_directories : stlib4.private_dir_include(), +) +test('test4', exe) + +# Test 5: link into static library, link_whole into shared +# and access from executable +srcs = gen.process('meson_test_function.tmpl') +stlib5 = static_library('stlib5', [srcs], c_args : '-DBUILDING_DLL') +shlib5 = shared_library('shlib5', link_whole : stlib5) +exe = executable('exe5', 'main.c', + link_with : shlib5, + include_directories : stlib5.private_dir_include(), +) +test('test5', exe) diff --git a/test cases/common/180 generator link whole/meson_test_function.tmpl b/test cases/common/180 generator link whole/meson_test_function.tmpl new file mode 100644 index 000000000..e69de29bb diff --git a/test cases/common/180 generator link whole/pull_meson_test_function.c b/test cases/common/180 generator link whole/pull_meson_test_function.c new file mode 100644 index 000000000..c54dda6d7 --- /dev/null +++ b/test cases/common/180 generator link whole/pull_meson_test_function.c @@ -0,0 +1,6 @@ +#include "export.h" +#include "meson_test_function.h" + +int DLL_PUBLIC function_puller() { + return meson_test_function(); +} From bf0e01d779445a260d9e4145714ba6bbf3f6197c Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Wed, 7 Mar 2018 12:48:35 +0000 Subject: [PATCH 2/3] Get generated headers from link_whole_targets as meson does for link_targets --- mesonbuild/backend/ninjabackend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 660b1a595..376d32ccd 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -14,6 +14,7 @@ import os, pickle, re, shlex, subprocess from collections import OrderedDict +import itertools from pathlib import PurePath from . import backends @@ -263,7 +264,7 @@ int dummy; vala_header = File.from_built_file(self.get_target_dir(target), target.vala_header) header_deps.append(vala_header) # Recurse and find generated headers - for dep in target.link_targets: + for dep in itertools.chain(target.link_targets, target.link_whole_targets): if isinstance(dep, (build.StaticLibrary, build.SharedLibrary)): header_deps += self.get_generated_headers(dep) return header_deps From 9b6d2f8a25f94cb5cdc04986e72d0eaaeaec0591 Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Wed, 7 Mar 2018 14:47:35 +0000 Subject: [PATCH 3/3] Skip whole_archive test for VS older than 2015 --- test cases/common/180 generator link whole/meson.build | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test cases/common/180 generator link whole/meson.build b/test cases/common/180 generator link whole/meson.build index f43e7cd0d..30ae9c62c 100644 --- a/test cases/common/180 generator link whole/meson.build +++ b/test cases/common/180 generator link whole/meson.build @@ -1,5 +1,12 @@ project('generator link_whole', 'c') +cc = meson.get_compiler('c') +if cc.get_id() == 'msvc' + if cc.version().version_compare('<19') + error('MESON_SKIP_TEST link_whole only works on VS2015 or newer.') + endif +endif + # This just generates foo.h and foo.c with int foo() defined. gen_py = find_program('generator.py') gen = generator(gen_py,