From c49f5aefd81808d5f9eb4fd06edd225ff11a5476 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 10 Apr 2017 15:02:56 -0700 Subject: Allow using generated files to shared_library vs_module_defs. Closes #1605 This detects and allows passing a generated file as a vs_module_def, it also adds a testcase that tests using configure_file to generate the .def file. --- mesonbuild/build.py | 18 ++++++++++++------ .../windows/10 vs module defs generated/meson.build | 7 +++++++ test cases/windows/10 vs module defs generated/prog.c | 5 +++++ .../10 vs module defs generated/subdir/meson.build | 9 +++++++++ .../10 vs module defs generated/subdir/somedll.c | 5 +++++ .../10 vs module defs generated/subdir/somedll.def.in | 2 ++ 6 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 test cases/windows/10 vs module defs generated/meson.build create mode 100644 test cases/windows/10 vs module defs generated/prog.c create mode 100644 test cases/windows/10 vs module defs generated/subdir/meson.build create mode 100644 test cases/windows/10 vs module defs generated/subdir/somedll.c create mode 100644 test cases/windows/10 vs module defs generated/subdir/somedll.def.in diff --git a/mesonbuild/build.py b/mesonbuild/build.py index df3f37b..5c382a5 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1191,12 +1191,18 @@ class SharedLibrary(BuildTarget): # Visual Studio module-definitions file if 'vs_module_defs' in kwargs: path = kwargs['vs_module_defs'] - if os.path.isabs(path): - self.vs_module_defs = File.from_absolute_file(path) - else: - self.vs_module_defs = File.from_source_file(environment.source_dir, self.subdir, path) - # link_depends can be an absolute path or relative to self.subdir - self.link_depends.append(path) + if isinstance(path, str): + if os.path.isabs(path): + self.vs_module_defs = File.from_absolute_file(path) + else: + self.vs_module_defs = File.from_source_file(environment.source_dir, self.subdir, path) + # link_depends can be an absolute path or relative to self.subdir + self.link_depends.append(path) + elif isinstance(path, File): + # When passing a generated file. + self.vs_module_defs = path + # link_depends can be an absolute path or relative to self.subdir + self.link_depends.append(path.absolute_path(environment.source_dir, environment.build_dir)) def check_unknown_kwargs(self, kwargs): self.check_unknown_kwargs_int(kwargs, known_lib_kwargs) diff --git a/test cases/windows/10 vs module defs generated/meson.build b/test cases/windows/10 vs module defs generated/meson.build new file mode 100644 index 0000000..5ce1a20 --- /dev/null +++ b/test cases/windows/10 vs module defs generated/meson.build @@ -0,0 +1,7 @@ +project('generated_dll_module_defs', 'c') + +if meson.get_compiler('c').get_id() == 'msvc' + subdir('subdir') + exe = executable('prog', 'prog.c', link_with : shlib) + test('runtest', exe) +endif diff --git a/test cases/windows/10 vs module defs generated/prog.c b/test cases/windows/10 vs module defs generated/prog.c new file mode 100644 index 0000000..f35f4a0 --- /dev/null +++ b/test cases/windows/10 vs module defs generated/prog.c @@ -0,0 +1,5 @@ +int somedllfunc(); + +int main(int argc, char **argv) { + return somedllfunc() == 42 ? 0 : 1; +} diff --git a/test cases/windows/10 vs module defs generated/subdir/meson.build b/test cases/windows/10 vs module defs generated/subdir/meson.build new file mode 100644 index 0000000..5d390a0 --- /dev/null +++ b/test cases/windows/10 vs module defs generated/subdir/meson.build @@ -0,0 +1,9 @@ +conf = configuration_data() +conf.set('func', 'somedllfunc') +def_file = configure_file( + input: 'somedll.def.in', + output: 'somedll.def', + configuration : conf, +) + +shlib = shared_library('somedll', 'somedll.c', vs_module_defs : def_file) diff --git a/test cases/windows/10 vs module defs generated/subdir/somedll.c b/test cases/windows/10 vs module defs generated/subdir/somedll.c new file mode 100644 index 0000000..df255e3 --- /dev/null +++ b/test cases/windows/10 vs module defs generated/subdir/somedll.c @@ -0,0 +1,5 @@ +#ifdef _MSC_VER +int somedllfunc() { + return 42; +} +#endif diff --git a/test cases/windows/10 vs module defs generated/subdir/somedll.def.in b/test cases/windows/10 vs module defs generated/subdir/somedll.def.in new file mode 100644 index 0000000..c29207c --- /dev/null +++ b/test cases/windows/10 vs module defs generated/subdir/somedll.def.in @@ -0,0 +1,2 @@ +EXPORTS + @func@ -- cgit v1.1 From 6402a8193a1f42a833456d525da8af2946f0c9b8 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 10 Apr 2017 15:40:38 -0700 Subject: Provide nice error for invalid types to shared_library vs_module_defs This just provides a nice error message for passing invalid types. --- mesonbuild/build.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 5c382a5..4df7ef5 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1203,6 +1203,10 @@ class SharedLibrary(BuildTarget): self.vs_module_defs = path # link_depends can be an absolute path or relative to self.subdir self.link_depends.append(path.absolute_path(environment.source_dir, environment.build_dir)) + else: + raise InvalidArguments( + 'Shared library vs_module_defs must be either a string, ' + 'or a file object') def check_unknown_kwargs(self, kwargs): self.check_unknown_kwargs_int(kwargs, known_lib_kwargs) -- cgit v1.1