aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/build.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2016-10-21 07:38:32 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2016-10-21 08:00:39 +0530
commit57ce7d461877b2ad8da4f4712879880148759bc6 (patch)
treef6fcf145a32ad4f7cdc1022e5c441c5b91db9ddb /mesonbuild/build.py
parent9c9c5ab2a878a32c7f1e2855596caac1122b5bf5 (diff)
downloadmeson-57ce7d461877b2ad8da4f4712879880148759bc6.zip
meson-57ce7d461877b2ad8da4f4712879880148759bc6.tar.gz
meson-57ce7d461877b2ad8da4f4712879880148759bc6.tar.bz2
Add support for extracting objects in unity builds
Not only does extract_all_objects() now work properly again, extract_objects() also works if you specify a subset of sources all of which have been compiled into a single unified object. So, for instance, this allows you to extract all the objects corresponding to the C sources compiled into a target consisting of C and C++ sources.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r--mesonbuild/build.py54
1 files changed, 42 insertions, 12 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 20b4425..f40df17 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -17,7 +17,7 @@ from . import environment
from . import dependencies
from . import mlog
import copy, os, re
-from .mesonlib import File, flatten, MesonException, stringlistify
+from .mesonlib import File, flatten, MesonException, stringlistify, classify_unity_sources
from .environment import for_windows, for_darwin
known_basic_kwargs = {'install' : True,
@@ -176,9 +176,42 @@ class IncludeDirs():
return self.extra_build_dirs
class ExtractedObjects():
+ '''
+ Holds a list of sources for which the objects must be extracted
+ '''
def __init__(self, target, srclist):
self.target = target
self.srclist = srclist
+ self.check_unity_compatible()
+
+ def check_unity_compatible(self):
+ # Figure out if the extracted object list is compatible with a Unity
+ # build. When we're doing a Unified build, we go through the sources,
+ # and create a single source file from each subset of the sources that
+ # can be compiled with a specific compiler. Then we create one object
+ # from each unified source file.
+ # If the list of sources for which we want objects is the same as the
+ # list of sources that go into each unified build, we're good.
+ self.unity_compatible = False
+ srclist_set = set(self.srclist)
+ # Objects for all the sources are required, so we're compatible
+ if srclist_set == set(self.target.sources):
+ self.unity_compatible = True
+ return
+ # Check if the srclist is a subset (of the target's sources) that is
+ # going to form a unified source file and a single object
+ compsrcs = classify_unity_sources(self.target.compilers.values(),
+ self.target.sources)
+ for srcs in compsrcs.values():
+ if srclist_set == set(srcs):
+ self.unity_compatible = True
+ return
+ msg = 'Single object files can not be extracted in Unity builds. ' \
+ 'You can only extract all the object files at once.'
+ raise MesonException(msg)
+
+ def get_want_all_objects(self):
+ return self.want_all_objects
class EnvironmentVariables():
def __init__(self):
@@ -397,18 +430,15 @@ class BuildTarget():
if 'link_with' in self.kwargs:
self.kwargs['link_with'] = self.unpack_holder(self.kwargs['link_with'])
- def extract_objects(self, srcargs):
+ def extract_objects(self, srclist):
obj_src = []
- for srclist in srcargs:
- if not isinstance(srclist, list):
- srclist = [srclist]
- for src in srclist:
- if not isinstance(src, str):
- raise MesonException('Extraction arguments must be strings.')
- src = File(False, self.subdir, src)
- if src not in self.sources:
- raise MesonException('Tried to extract unknown source %s.' % src)
- obj_src.append(src)
+ for src in srclist:
+ if not isinstance(src, str):
+ raise MesonException('Object extraction arguments must be strings.')
+ src = File(False, self.subdir, src)
+ if src not in self.sources:
+ raise MesonException('Tried to extract unknown source %s.' % src)
+ obj_src.append(src)
return ExtractedObjects(self, obj_src)
def extract_all_objects(self):