From 7b66ff8921f4e4c2e878739380d9a0496f52b112 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 11 Mar 2017 12:25:22 +0200 Subject: [PATCH] Create unity files with the VS backend. --- mesonbuild/backend/backends.py | 14 +++++++++++--- mesonbuild/backend/ninjabackend.py | 12 +++++------- mesonbuild/backend/vs2010backend.py | 2 ++ mesonbuild/mesonlib.py | 2 ++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 99be17240..b2682222a 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -103,6 +103,12 @@ class Backend: def get_target_filename_abs(self, target): return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target)) + def get_option_for_target(self, option_name, target): + if option_name in target.option_overrides: + override = target.option_overrides[option_name] + return self.environment.coredata.validate_option_value(option_name, override) + return self.environment.coredata.get_builtin_option('unity') + def get_target_filename_for_linking(self, target): # On some platforms (msvc for instance), the file that is used for # dynamic linking is not the same as the dynamic library itself. This @@ -152,8 +158,10 @@ class Backend: compsrcs = classify_unity_sources(target.compilers.values(), unity_src) def init_language_file(suffix): - outfilename = os.path.join(self.get_target_private_dir_abs(target), - self.get_unity_source_filename(target, suffix)) + unity_src_name = self.get_unity_source_filename(target, suffix) + unity_src_subdir = self.get_target_private_dir_abs(target) + outfilename = os.path.join(unity_src_subdir, + unity_src_name) outfileabs = os.path.join(self.environment.get_build_dir(), outfilename) outfileabs_tmp = outfileabs + '.tmp' @@ -161,7 +169,7 @@ class Backend: outfileabs_tmp_dir = os.path.dirname(outfileabs_tmp) if not os.path.exists(outfileabs_tmp_dir): os.makedirs(outfileabs_tmp_dir) - result.append(outfilename) + result.append(mesonlib.File(True, unity_src_subdir, unity_src_name)) return open(outfileabs_tmp, 'w') # For each language, generate a unity source file and return the list diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 738d1857e..76492fcfa 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -283,12 +283,6 @@ int dummy; return False return True - def get_option_for_target(self, option_name, target): - if option_name in target.option_overrides: - override = target.option_overrides[option_name] - return self.environment.coredata.validate_option_value(option_name, override) - return self.environment.coredata.get_builtin_option('unity') - def generate_target(self, target, outfile): if isinstance(target, build.CustomTarget): self.generate_custom_target(target, outfile) @@ -439,7 +433,7 @@ int dummy; obj_list += self.flatten_object_list(target) if is_unity: for src in self.generate_unity_files(target, unity_src): - obj_list.append(self.generate_single_compile(target, outfile, RawFilename(src), True, unity_deps + header_deps)) + obj_list.append(self.generate_single_compile(target, outfile, src, True, unity_deps + header_deps)) linker = self.determine_linker(target) elem = self.generate_link(target, outfile, outname, obj_list, linker, pch_objects) self.generate_shlib_aliases(target, self.get_target_dir(target)) @@ -1911,6 +1905,10 @@ rule FORTRAN_DEP_HACK abs_src = src.fname else: abs_src = os.path.join(self.environment.get_build_dir(), src.fname) + elif isinstance(src, mesonlib.File): + rel_src = src.rel_to_builddir(self.build_to_src) + abs_src = src.absolute_path(self.environment.get_source_dir(), + self.environment.get_build_dir()) elif is_generated: raise AssertionError('BUG: broken generated source file handling for {!r}'.format(src)) else: diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 8c0cce69c..be9dfdd42 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -601,6 +601,8 @@ class Vs2010Backend(backends.Backend): # Prefix to use to access the source tree's subdir from the vcxproj dir proj_to_src_dir = os.path.join(proj_to_src_root, target.subdir) (sources, headers, objects, languages) = self.split_sources(target.sources) + if self.get_option_for_target('unity', target): + sources = self.generate_unity_files(target, sources) compiler = self._get_cl_compiler(target) buildtype_args = compiler.get_buildtype_args(self.buildtype) buildtype_link_args = compiler.get_buildtype_linker_args(self.buildtype) diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index c7368d577..7a5b96266 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -121,6 +121,8 @@ class File: self.is_built = is_built self.subdir = subdir self.fname = fname + assert(isinstance(self.subdir, str)) + assert(isinstance(self.fname, str)) def __str__(self): return os.path.join(self.subdir, self.fname)