aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/build.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-09-15 16:29:59 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-09-20 08:59:26 -0700
commitd5003c2190d32d46ab7e1d40e5f9ee1169ef93b0 (patch)
treec7c44957c7a2602790b7bca05cf10989c9de820f /mesonbuild/build.py
parent59a90309aba460df33dd6624601295355c7eb4e9 (diff)
downloadmeson-d5003c2190d32d46ab7e1d40e5f9ee1169ef93b0.zip
meson-d5003c2190d32d46ab7e1d40e5f9ee1169ef93b0.tar.gz
meson-d5003c2190d32d46ab7e1d40e5f9ee1169ef93b0.tar.bz2
Consider compilers used in static_library parents
Currently meson only considers what compiler/linker were used by a Target's immediate sources or objects, not the sources of libraries it's linked with by the link_with and link_while keywords. This means that if given 3 libraries: libA which is C++, libB which is C, and libC which is also C, and libC links with libB which links with libA then linking libC will be attempted with the C linker, and will fail. This patch corrects that by adding the compilers used by sub libraries to the collection of compilers considered by meson when picking a linker. This adds a new process_compilers_late method to the BuildTarget class, which is evaluated after process_kwargs is called. This is needed because some D options need to be evaluated after compilers are selected, while for C-like languages we need to check the link* targets for language requirements, and link* targets are passed by kwargs. This implementation is recursive, since each Target adds it's parent's dependencies.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r--mesonbuild/build.py43
1 files changed, 35 insertions, 8 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 281b060..e2bc262 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -359,6 +359,7 @@ class BuildTarget(Target):
self.check_unknown_kwargs(kwargs)
if not self.sources and not self.generated and not self.objects:
raise InvalidArguments('Build target %s has no sources.' % name)
+ self.process_compilers_late()
self.validate_sources()
self.validate_cross_install(environment)
@@ -439,6 +440,39 @@ class BuildTarget(Target):
removed = True
return removed
+ def process_compilers_late(self):
+ """Processes additional compilers after kwargs have been evaluated.
+
+ This can add extra compilers that might be required by keyword
+ arguments, such as link_with or dependencies. It will also try to guess
+ which compiler to use if one hasn't been selected already.
+ """
+ # Populate list of compilers
+ if self.is_cross:
+ compilers = self.environment.coredata.cross_compilers
+ else:
+ compilers = self.environment.coredata.compilers
+
+ # If this library is linked against another library we need to consider
+ # the languages of those libraries as well.
+ if self.link_targets or self.link_whole_targets:
+ extra = set()
+ for t in itertools.chain(self.link_targets, self.link_whole_targets):
+ for name, compiler in t.compilers.items():
+ if name in clike_langs:
+ extra.add((name, compiler))
+ for name, compiler in sorted(extra, key=lambda p: sort_clike(p[0])):
+ self.compilers[name] = compiler
+
+ if not self.compilers:
+ # No source files or parent targets, target consists of only object
+ # files of unknown origin. Just add the first clike compiler
+ # that we have and hope that it can link these objects
+ for lang in clike_langs:
+ if lang in compilers:
+ self.compilers[lang] = compilers[lang]
+ break
+
def process_compilers(self):
'''
Populate self.compilers, which is the list of compilers that this
@@ -487,14 +521,7 @@ class BuildTarget(Target):
# Re-sort according to clike_langs
self.compilers = OrderedDict(sorted(self.compilers.items(),
key=lambda t: sort_clike(t[0])))
- else:
- # No source files, target consists of only object files of unknown
- # origin. Just add the first clike compiler that we have and hope
- # that it can link these objects
- for lang in clike_langs:
- if lang in compilers:
- self.compilers[lang] = compilers[lang]
- break
+
# If all our sources are Vala, our target also needs the C compiler but
# it won't get added above.
if 'vala' in self.compilers and 'c' not in self.compilers: