Merge branch 'samename'

pull/485/head
Jussi Pakkanen 9 years ago
commit 5ea24bafdd
  1. 23
      mesonbuild/backend/backends.py
  2. 1
      mesonbuild/backend/ninjabackend.py
  3. 39
      mesonbuild/backend/vs2010backend.py
  4. 3
      test cases/common/110 extract same name/lib.c
  5. 6
      test cases/common/110 extract same name/main.c
  6. 6
      test cases/common/110 extract same name/meson.build
  7. 3
      test cases/common/110 extract same name/src/lib.c

@ -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

@ -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 = {}

@ -16,6 +16,8 @@ import os, sys
import pickle
from mesonbuild import compilers
from mesonbuild.build import BuildTarget
from mesonbuild.mesonlib import File
from . import backends
from .. import build
from .. import dependencies
@ -35,8 +37,35 @@ 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
self.sources_conflicts = {}
def object_filename_from_source(self, target, source):
basename = os.path.basename(source.fname)
filename_without_extension = '.'.join(basename.split('.')[:-1])
if basename in self.sources_conflicts[target.get_id()]:
# 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 resolve_source_conflicts(self):
for name, target in self.build.targets.items():
if not isinstance(target, BuildTarget):
continue
conflicts = {}
for s in target.get_sources():
if hasattr(s, 'held_object'):
s = s.held_object
if not isinstance(s, File):
continue
basename = os.path.basename(s.fname)
conflicting_sources = conflicts.get(basename, None)
if conflicting_sources is None:
conflicting_sources = []
conflicts[basename] = conflicting_sources
conflicting_sources.append(s)
self.sources_conflicts[target.get_id()] = {name: src_conflicts for name, src_conflicts in conflicts.items()
if len(src_conflicts) > 1}
def generate_custom_generator_commands(self, target, parent_node):
all_output_files = []
@ -86,6 +115,7 @@ class Vs2010Backend(backends.Backend):
return all_output_files
def generate(self, interp):
self.resolve_source_conflicts()
self.interpreter = interp
self.platform = 'Win32'
self.buildtype = self.environment.coredata.get_builtin_option('buildtype')
@ -525,7 +555,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:
@ -566,6 +596,9 @@ class Vs2010Backend(backends.Backend):
inc_cl = ET.SubElement(inc_src, 'CLCompile', Include=relpath)
self.add_pch(inc_cl, proj_to_src_dir, pch_sources, s)
self.add_additional_options(s, inc_cl, extra_args, additional_options_set)
basename = os.path.basename(s.fname)
if basename in self.sources_conflicts[target.get_id()]:
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)

@ -0,0 +1,3 @@
int func1() {
return 23;
}

@ -0,0 +1,6 @@
int func1();
int func2();
int main(int argc, char **argv) {
return !(func1() == 23 && func2() == 42);
}

@ -0,0 +1,6 @@
project('object extraction', 'c')
lib = shared_library('somelib', ['lib.c', 'src/lib.c'])
obj = lib.extract_objects(['lib.c', 'src/lib.c'])
exe = executable('main', 'main.c', objects: obj)
test('extraction', exe)
Loading…
Cancel
Save