Added custom_target[i] support for link_with and link_whole

pull/5161/head
TheQwertiest 6 years ago
parent ccc4ce28cc
commit 8c9a25456d
  1. 4
      mesonbuild/backend/backends.py
  2. 6
      mesonbuild/backend/vs2010backend.py
  3. 32
      mesonbuild/build.py

@ -171,6 +171,8 @@ class Backend:
mlog.warning('custom_target {!r} has more than one output! ' mlog.warning('custom_target {!r} has more than one output! '
'Using the first one.'.format(t.name)) 'Using the first one.'.format(t.name))
filename = t.get_outputs()[0] filename = t.get_outputs()[0]
elif isinstance(t, build.CustomTargetIndex):
filename = t.get_outputs()[0]
else: else:
assert(isinstance(t, build.BuildTarget)) assert(isinstance(t, build.BuildTarget))
filename = t.get_filename() filename = t.get_filename()
@ -214,7 +216,7 @@ class Backend:
return os.path.join(self.get_target_dir(target), link_lib) return os.path.join(self.get_target_dir(target), link_lib)
elif isinstance(target, build.StaticLibrary): elif isinstance(target, build.StaticLibrary):
return os.path.join(self.get_target_dir(target), target.get_filename()) return os.path.join(self.get_target_dir(target), target.get_filename())
elif isinstance(target, build.CustomTarget): elif isinstance(target, build.CustomTarget) or isinstance(target, build.CustomTargetIndex):
if not target.is_linkable_target(): if not target.is_linkable_target():
raise MesonException('Tried to link against custom target "%s", which is not linkable.' % target.name) raise MesonException('Tried to link against custom target "%s", which is not linkable.' % target.name)
return os.path.join(self.get_target_dir(target), target.get_filename()) return os.path.join(self.get_target_dir(target), target.get_filename())

@ -249,8 +249,14 @@ class Vs2010Backend(backends.Backend):
all_deps[d.get_id()] = d all_deps[d.get_id()] = d
elif isinstance(target, build.BuildTarget): elif isinstance(target, build.BuildTarget):
for ldep in target.link_targets: for ldep in target.link_targets:
if isinstance(ldep, build.CustomTargetIndex):
all_deps[ldep.get_id()] = ldep.target
else:
all_deps[ldep.get_id()] = ldep all_deps[ldep.get_id()] = ldep
for ldep in target.link_whole_targets: for ldep in target.link_whole_targets:
if isinstance(ldep, build.CustomTargetIndex):
all_deps[ldep.get_id()] = ldep.target
else:
all_deps[ldep.get_id()] = ldep all_deps[ldep.get_id()] = ldep
for obj_id, objdep in self.get_obj_target_deps(target.objects): for obj_id, objdep in self.get_obj_target_deps(target.objects):
all_deps[obj_id] = objdep all_deps[obj_id] = objdep

@ -576,7 +576,7 @@ class BuildTarget(Target):
if self.link_targets or self.link_whole_targets: if self.link_targets or self.link_whole_targets:
extra = set() extra = set()
for t in itertools.chain(self.link_targets, self.link_whole_targets): for t in itertools.chain(self.link_targets, self.link_whole_targets):
if isinstance(t, CustomTarget): if isinstance(t, CustomTarget) or isinstance(t, CustomTargetIndex):
continue # We can't know anything about these. continue # We can't know anything about these.
for name, compiler in t.compilers.items(): for name, compiler in t.compilers.items():
if name in clink_langs: if name in clink_langs:
@ -1066,7 +1066,7 @@ You probably should put it in link_with instead.''')
def link(self, target): def link(self, target):
for t in listify(target, unholder=True): for t in listify(target, unholder=True):
if not isinstance(t, Target): if not isinstance(t, Target) and not isinstance(t, CustomTargetIndex):
raise InvalidArguments('{!r} is not a target.'.format(t)) raise InvalidArguments('{!r} is not a target.'.format(t))
if not t.is_linkable_target(): if not t.is_linkable_target():
raise InvalidArguments('Link target {!r} is not linkable.'.format(t)) raise InvalidArguments('Link target {!r} is not linkable.'.format(t))
@ -1074,13 +1074,13 @@ You probably should put it in link_with instead.''')
msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name) msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name)
msg += "Use the 'pic' option to static_library to build with PIC." msg += "Use the 'pic' option to static_library to build with PIC."
raise InvalidArguments(msg) raise InvalidArguments(msg)
if not isinstance(t, CustomTarget) and self.is_cross != t.is_cross: if not isinstance(t, CustomTarget) and not isinstance(t, CustomTargetIndex) and self.is_cross != t.is_cross:
raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name)) raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name))
self.link_targets.append(t) self.link_targets.append(t)
def link_whole(self, target): def link_whole(self, target):
for t in listify(target, unholder=True): for t in listify(target, unholder=True):
if isinstance(t, CustomTarget): if isinstance(t, CustomTarget) or isinstance(t, CustomTargetIndex):
if not t.is_linkable_target(): if not t.is_linkable_target():
raise InvalidArguments('Custom target {!r} is not linkable.'.format(t)) raise InvalidArguments('Custom target {!r} is not linkable.'.format(t))
if not t.get_filename().endswith('.a'): if not t.get_filename().endswith('.a'):
@ -1091,7 +1091,7 @@ You probably should put it in link_with instead.''')
msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name) msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name)
msg += "Use the 'pic' option to static_library to build with PIC." msg += "Use the 'pic' option to static_library to build with PIC."
raise InvalidArguments(msg) raise InvalidArguments(msg)
if not isinstance(t, CustomTarget) and self.is_cross != t.is_cross: if not isinstance(t, CustomTarget) and not isinstance(t, CustomTargetIndex) and self.is_cross != t.is_cross:
raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name)) raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name))
self.link_whole_targets.append(t) self.link_whole_targets.append(t)
@ -1168,7 +1168,7 @@ You probably should put it in link_with instead.''')
# Check if any of the internal libraries this target links to were # Check if any of the internal libraries this target links to were
# written in this language # written in this language
for link_target in itertools.chain(self.link_targets, self.link_whole_targets): for link_target in itertools.chain(self.link_targets, self.link_whole_targets):
if isinstance(link_target, CustomTarget): if isinstance(link_target, CustomTarget) or isinstance(link_target, CustomTargetIndex):
continue continue
for language in link_target.compilers: for language in link_target.compilers:
if language not in langs: if language not in langs:
@ -2259,6 +2259,26 @@ class CustomTargetIndex:
def get_subdir(self): def get_subdir(self):
return self.target.get_subdir() return self.target.get_subdir()
def get_filename(self):
return self.output
def get_id(self):
return self.target.get_id()
def get_all_link_deps(self):
return []
def get_link_deps_mapping(self, prefix, environment):
return self.target.get_link_deps_mapping(prefix, environment)
def get_link_dep_subdirs(self):
return self.target.get_link_dep_subdirs()
def is_linkable_target(self):
suf = os.path.splitext(self.output)[-1]
if suf == '.a' or suf == '.dll' or suf == '.lib' or suf == '.so':
return True
class ConfigureFile: class ConfigureFile:
def __init__(self, subdir, sourcename, targetname, configuration_data): def __init__(self, subdir, sourcename, targetname, configuration_data):

Loading…
Cancel
Save