diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index dedd69873e9..3f014aedbbc 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -251,16 +251,22 @@ def get_export_symbols(self, ext): return ext.export_symbols return _build_ext.get_export_symbols(self, ext) - def _preprocess_and_build(self, ext): + def _preprocess(self, ext): if isinstance(ext, PreprocessedExtension): target = ext.preprocess(self) # may be missing build info updates = self._update_ext_info(target) target.__dict__.update(updates) ext.__dict__.update(updates) # ... for the sake of consistency ... - else: - target = ext + return target + + return ext - _build_ext.build_extension(self, target) + def build_extensions(self): + self.extensions[:] = [self._preprocess(ext) for ext in self.extensions] + # ^-- We may have to pre-process all the extensions first, before proceeding + # to the compilation step, since they may generate files that depend + # at at other during compile-time (e.g. headers). + super().build_extensions() def build_extension(self, ext): ext._convert_pyx_sources_to_lang() @@ -268,9 +274,7 @@ def build_extension(self, ext): try: if isinstance(ext, Library): self.compiler = self.shlib_compiler - - self._preprocess_and_build(ext) - + _build_ext.build_extension(self, ext) if ext._needs_stub: build_lib = self.get_finalized_command('build_py').build_lib self.write_stub(build_lib, ext) diff --git a/setuptools/extension.py b/setuptools/extension.py index 68318d22ff1..06679022b69 100644 --- a/setuptools/extension.py +++ b/setuptools/extension.py @@ -169,8 +169,8 @@ def preprocess(self, build_ext: BuildExt) -> Extension: # pragma: no cover If necessary, a temporary directory **name** can be accessed via ``build_ext.build_temp`` (this directory might not have been created yet). - You can also access other attributes like ``build_ext.inplace`` or - ``build_ext.editable_mode``. + You can also access other attributes like ``build_ext.parallel``, + ``build_ext.inplace`` or ``build_ext.editable_mode``. """ raise NotImplementedError # needs to be implemented by the relevant plugin.