diff options
author | Nicolas Schneider <nioncode+git@gmail.com> | 2016-03-25 09:49:30 +0100 |
---|---|---|
committer | Nicolas Schneider <nioncode+git@gmail.com> | 2016-03-25 09:49:30 +0100 |
commit | 8787ec3ea2aa2b06c48ef917a396e8912ad05303 (patch) | |
tree | 841c1d3b1de894709a1a1a0ff170c81b0e5597c7 | |
parent | 3de7c3471406b3e800b4b87c15febb49e73a9d53 (diff) | |
download | meson-8787ec3ea2aa2b06c48ef917a396e8912ad05303.zip meson-8787ec3ea2aa2b06c48ef917a396e8912ad05303.tar.gz meson-8787ec3ea2aa2b06c48ef917a396e8912ad05303.tar.bz2 |
vs2010: fix object extraction with same source file name
This also refactors determine_ext_objs() to use inheritance instead of a
method flag for determining the object output name.
-rw-r--r-- | mesonbuild/backend/backends.py | 23 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 1 | ||||
-rw-r--r-- | mesonbuild/backend/vs2010backend.py | 17 |
3 files changed, 19 insertions, 22 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 8d0b0f6..af3f9f2 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -142,7 +142,7 @@ class Backend(): return os.path.relpath(os.path.join('dummyprefixdir', todir),\ os.path.join('dummyprefixdir', fromdir)) - def flatten_object_list(self, target, proj_dir_to_build_root='', include_dir_names=True): + def flatten_object_list(self, target, proj_dir_to_build_root=''): obj_list = [] for obj in target.get_objects(): if isinstance(obj, str): @@ -150,7 +150,7 @@ class Backend(): self.build_to_src, target.get_subdir(), obj) obj_list.append(o) elif isinstance(obj, build.ExtractedObjects): - obj_list += self.determine_ext_objs(obj, proj_dir_to_build_root, include_dir_names) + obj_list += self.determine_ext_objs(obj, proj_dir_to_build_root) else: raise MesonException('Unknown data type in object list.') return obj_list @@ -210,28 +210,21 @@ class Backend(): return c raise RuntimeError('Unreachable code') - def determine_ext_objs(self, extobj, proj_dir_to_build_root='', include_dir_names=True): + def object_filename_from_source(self, target, source): + return source.fname.replace('/', '_').replace('\\', '_') + '.' + self.environment.get_object_suffix() + + def determine_ext_objs(self, extobj, proj_dir_to_build_root=''): result = [] targetdir = self.get_target_private_dir(extobj.target) - suffix = '.' + self.environment.get_object_suffix() for osrc in extobj.srclist: - osrc_base = osrc.fname - if not self.source_suffix_in_objs: - osrc_base = '.'.join(osrc.split('.')[:-1]) # If extracting in a subproject, the subproject # name gets duplicated in the file name. pathsegs = osrc.subdir.split(os.sep) if pathsegs[0] == 'subprojects': pathsegs = pathsegs[2:] fixedpath = os.sep.join(pathsegs) - if include_dir_names: - objbase = osrc_base.replace('/', '_').replace('\\', '_') - else: - # vs2010 backend puts all obj files without directory prefixes into build dir, so just - # use the file name without a directory (will be stripped by os.path.basename() below). - objbase = osrc_base - objname = os.path.join(proj_dir_to_build_root, - targetdir, os.path.basename(objbase) + suffix) + objname = os.path.join(proj_dir_to_build_root, targetdir, + self.object_filename_from_source(extobj.target, osrc)) result.append(objname) return result diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 8e8fa42..7c430bf 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -129,7 +129,6 @@ class NinjaBackend(backends.Backend): def __init__(self, build): super().__init__(build) - self.source_suffix_in_objs = True self.ninja_filename = 'build.ninja' self.fortran_deps = {} self.all_outputs = {} diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index fac7358..e6b0056 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -35,8 +35,15 @@ class Vs2010Backend(backends.Backend): def __init__(self, build): super().__init__(build) self.project_file_version = '10.0.30319.1' - # foo.c compiles to foo.obj, not foo.c.obj - self.source_suffix_in_objs = False + + def object_filename_from_source(self, target, source): + basename = os.path.basename(source.fname) + filename_without_extension = '.'.join(basename.split('.')[:-1]) + if basename in target.sources_conflicts: + # If there are multiple source files with the same basename, we must resolve the conflict + # by giving each a unique object output file. + filename_without_extension = '.'.join(source.fname.split('.')[:-1]).replace('/', '_').replace('\\', '_') + return filename_without_extension + '.' + self.environment.get_object_suffix() def generate_custom_generator_commands(self, target, parent_node): all_output_files = [] @@ -525,7 +532,7 @@ class Vs2010Backend(backends.Backend): linkname = os.path.join(rel_path, lobj.get_import_filename()) additional_links.append(linkname) additional_objects = [] - for o in self.flatten_object_list(target, down, include_dir_names=False): + for o in self.flatten_object_list(target, down): assert(isinstance(o, str)) additional_objects.append(o) if len(additional_links) > 0: @@ -568,9 +575,7 @@ class Vs2010Backend(backends.Backend): self.add_additional_options(s, inc_cl, extra_args, additional_options_set) basename = os.path.basename(s.fname) if basename in target.sources_conflicts: - obj_name = '.'.join(s.split('.')[:-1]).replace('/', '_')\ - + '.' + self.environment.get_object_suffix() - ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + obj_name + ET.SubElement(inc_cl, 'ObjectFileName').text = "$(IntDir)" + self.object_filename_from_source(target, s) for s in gen_src: relpath = self.relpath(s, target.subdir) inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=relpath) |