Path: blob/main/test/lib/python3.9/site-packages/setuptools/command/build_clib.py
4799 views
import distutils.command.build_clib as orig1from distutils.errors import DistutilsSetupError2from distutils import log3from setuptools.dep_util import newer_pairwise_group456class build_clib(orig.build_clib):7"""8Override the default build_clib behaviour to do the following:9101. Implement a rudimentary timestamp-based dependency system11so 'compile()' doesn't run every time.122. Add more keys to the 'build_info' dictionary:13* obj_deps - specify dependencies for each object compiled.14this should be a dictionary mapping a key15with the source filename to a list of16dependencies. Use an empty string for global17dependencies.18* cflags - specify a list of additional flags to pass to19the compiler.20"""2122def build_libraries(self, libraries):23for (lib_name, build_info) in libraries:24sources = build_info.get('sources')25if sources is None or not isinstance(sources, (list, tuple)):26raise DistutilsSetupError(27"in 'libraries' option (library '%s'), "28"'sources' must be present and must be "29"a list of source filenames" % lib_name)30sources = list(sources)3132log.info("building '%s' library", lib_name)3334# Make sure everything is the correct type.35# obj_deps should be a dictionary of keys as sources36# and a list/tuple of files that are its dependencies.37obj_deps = build_info.get('obj_deps', dict())38if not isinstance(obj_deps, dict):39raise DistutilsSetupError(40"in 'libraries' option (library '%s'), "41"'obj_deps' must be a dictionary of "42"type 'source: list'" % lib_name)43dependencies = []4445# Get the global dependencies that are specified by the '' key.46# These will go into every source's dependency list.47global_deps = obj_deps.get('', list())48if not isinstance(global_deps, (list, tuple)):49raise DistutilsSetupError(50"in 'libraries' option (library '%s'), "51"'obj_deps' must be a dictionary of "52"type 'source: list'" % lib_name)5354# Build the list to be used by newer_pairwise_group55# each source will be auto-added to its dependencies.56for source in sources:57src_deps = [source]58src_deps.extend(global_deps)59extra_deps = obj_deps.get(source, list())60if not isinstance(extra_deps, (list, tuple)):61raise DistutilsSetupError(62"in 'libraries' option (library '%s'), "63"'obj_deps' must be a dictionary of "64"type 'source: list'" % lib_name)65src_deps.extend(extra_deps)66dependencies.append(src_deps)6768expected_objects = self.compiler.object_filenames(69sources,70output_dir=self.build_temp,71)7273if (74newer_pairwise_group(dependencies, expected_objects)75!= ([], [])76):77# First, compile the source code to object files in the library78# directory. (This should probably change to putting object79# files in a temporary build directory.)80macros = build_info.get('macros')81include_dirs = build_info.get('include_dirs')82cflags = build_info.get('cflags')83self.compiler.compile(84sources,85output_dir=self.build_temp,86macros=macros,87include_dirs=include_dirs,88extra_postargs=cflags,89debug=self.debug90)9192# Now "link" the object files together into a static library.93# (On Unix at least, this isn't really linking -- it just94# builds an archive. Whatever.)95self.compiler.create_static_lib(96expected_objects,97lib_name,98output_dir=self.build_clib,99debug=self.debug100)101102103