Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/__init__.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/_framework_compat.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/bdist.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/bdist_dumb.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/bdist_rpm.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build_clib.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build_ext.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build_py.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build_scripts.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/check.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/clean.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/config.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_data.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_egg_info.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_headers.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_lib.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_scripts.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/command/__pycache__/sdist.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compat/__pycache__/__init__.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compat/__pycache__/numpy.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compat/__pycache__/py39.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/base.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/cygwin.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/errors.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/msvc.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/unix.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/zos.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/base.py +1386 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/cygwin.py +340 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/errors.py +24 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/msvc.py +614 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_base.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_cygwin.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_mingw.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_msvc.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_unix.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_base.py +83 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_cygwin.py +76 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_mingw.py +48 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_msvc.py +136 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_unix.py +413 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/unix.py +422 -0
- python/Lib/site-packages/setuptools/_distutils/compilers/C/zos.py +230 -0
- python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/__init__.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_version.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_versionpredicate.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/unix_compat.cpython-313.pyc +0 -0
- python/Lib/site-packages/setuptools/_distutils/tests/compat/__pycache__/__init__.cpython-313.pyc +0 -0
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (496 Bytes). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/_framework_compat.cpython-313.pyc
ADDED
|
Binary file (2.68 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/bdist.cpython-313.pyc
ADDED
|
Binary file (6.6 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/bdist_dumb.cpython-313.pyc
ADDED
|
Binary file (5.68 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/bdist_rpm.cpython-313.pyc
ADDED
|
Binary file (22.3 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build.cpython-313.pyc
ADDED
|
Binary file (6.46 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build_clib.cpython-313.pyc
ADDED
|
Binary file (7.72 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build_ext.cpython-313.pyc
ADDED
|
Binary file (30.7 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build_py.cpython-313.pyc
ADDED
|
Binary file (16.4 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/build_scripts.cpython-313.pyc
ADDED
|
Binary file (6.59 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/check.cpython-313.pyc
ADDED
|
Binary file (7.28 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/clean.cpython-313.pyc
ADDED
|
Binary file (3.14 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/config.cpython-313.pyc
ADDED
|
Binary file (15 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install.cpython-313.pyc
ADDED
|
Binary file (27.7 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_data.cpython-313.pyc
ADDED
|
Binary file (4.46 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_egg_info.cpython-313.pyc
ADDED
|
Binary file (5.14 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_headers.cpython-313.pyc
ADDED
|
Binary file (2.49 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_lib.cpython-313.pyc
ADDED
|
Binary file (8.41 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/install_scripts.cpython-313.pyc
ADDED
|
Binary file (3.06 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/command/__pycache__/sdist.cpython-313.pyc
ADDED
|
Binary file (22.4 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compat/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (1.26 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compat/__pycache__/numpy.cpython-313.pyc
ADDED
|
Binary file (271 Bytes). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compat/__pycache__/py39.cpython-313.pyc
ADDED
|
Binary file (2.72 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/base.cpython-313.pyc
ADDED
|
Binary file (50.3 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/cygwin.cpython-313.pyc
ADDED
|
Binary file (11.9 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/errors.cpython-313.pyc
ADDED
|
Binary file (1.64 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/msvc.cpython-313.pyc
ADDED
|
Binary file (25.2 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/unix.cpython-313.pyc
ADDED
|
Binary file (16 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/__pycache__/zos.cpython-313.pyc
ADDED
|
Binary file (6.37 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/base.py
ADDED
|
@@ -0,0 +1,1386 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.ccompiler
|
| 2 |
+
|
| 3 |
+
Contains Compiler, an abstract base class that defines the interface
|
| 4 |
+
for the Distutils compiler abstraction model."""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import os
|
| 9 |
+
import pathlib
|
| 10 |
+
import re
|
| 11 |
+
import sys
|
| 12 |
+
import warnings
|
| 13 |
+
from collections.abc import Callable, Iterable, MutableSequence, Sequence
|
| 14 |
+
from typing import (
|
| 15 |
+
TYPE_CHECKING,
|
| 16 |
+
ClassVar,
|
| 17 |
+
Literal,
|
| 18 |
+
TypeVar,
|
| 19 |
+
Union,
|
| 20 |
+
overload,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
from more_itertools import always_iterable
|
| 24 |
+
|
| 25 |
+
from ..._log import log
|
| 26 |
+
from ..._modified import newer_group
|
| 27 |
+
from ...dir_util import mkpath
|
| 28 |
+
from ...errors import (
|
| 29 |
+
DistutilsModuleError,
|
| 30 |
+
DistutilsPlatformError,
|
| 31 |
+
)
|
| 32 |
+
from ...file_util import move_file
|
| 33 |
+
from ...spawn import spawn
|
| 34 |
+
from ...util import execute, is_mingw, split_quoted
|
| 35 |
+
from .errors import (
|
| 36 |
+
CompileError,
|
| 37 |
+
LinkError,
|
| 38 |
+
UnknownFileType,
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
if TYPE_CHECKING:
|
| 42 |
+
from typing_extensions import TypeAlias, TypeVarTuple, Unpack
|
| 43 |
+
|
| 44 |
+
_Ts = TypeVarTuple("_Ts")
|
| 45 |
+
|
| 46 |
+
_Macro: TypeAlias = Union[tuple[str], tuple[str, Union[str, None]]]
|
| 47 |
+
_StrPathT = TypeVar("_StrPathT", bound="str | os.PathLike[str]")
|
| 48 |
+
_BytesPathT = TypeVar("_BytesPathT", bound="bytes | os.PathLike[bytes]")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class Compiler:
|
| 52 |
+
"""Abstract base class to define the interface that must be implemented
|
| 53 |
+
by real compiler classes. Also has some utility methods used by
|
| 54 |
+
several compiler classes.
|
| 55 |
+
|
| 56 |
+
The basic idea behind a compiler abstraction class is that each
|
| 57 |
+
instance can be used for all the compile/link steps in building a
|
| 58 |
+
single project. Thus, attributes common to all of those compile and
|
| 59 |
+
link steps -- include directories, macros to define, libraries to link
|
| 60 |
+
against, etc. -- are attributes of the compiler instance. To allow for
|
| 61 |
+
variability in how individual files are treated, most of those
|
| 62 |
+
attributes may be varied on a per-compilation or per-link basis.
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
# 'compiler_type' is a class attribute that identifies this class. It
|
| 66 |
+
# keeps code that wants to know what kind of compiler it's dealing with
|
| 67 |
+
# from having to import all possible compiler classes just to do an
|
| 68 |
+
# 'isinstance'. In concrete CCompiler subclasses, 'compiler_type'
|
| 69 |
+
# should really, really be one of the keys of the 'compiler_class'
|
| 70 |
+
# dictionary (see below -- used by the 'new_compiler()' factory
|
| 71 |
+
# function) -- authors of new compiler interface classes are
|
| 72 |
+
# responsible for updating 'compiler_class'!
|
| 73 |
+
compiler_type: ClassVar[str] = None # type: ignore[assignment]
|
| 74 |
+
|
| 75 |
+
# XXX things not handled by this compiler abstraction model:
|
| 76 |
+
# * client can't provide additional options for a compiler,
|
| 77 |
+
# e.g. warning, optimization, debugging flags. Perhaps this
|
| 78 |
+
# should be the domain of concrete compiler abstraction classes
|
| 79 |
+
# (UnixCCompiler, MSVCCompiler, etc.) -- or perhaps the base
|
| 80 |
+
# class should have methods for the common ones.
|
| 81 |
+
# * can't completely override the include or library searchg
|
| 82 |
+
# path, ie. no "cc -I -Idir1 -Idir2" or "cc -L -Ldir1 -Ldir2".
|
| 83 |
+
# I'm not sure how widely supported this is even by Unix
|
| 84 |
+
# compilers, much less on other platforms. And I'm even less
|
| 85 |
+
# sure how useful it is; maybe for cross-compiling, but
|
| 86 |
+
# support for that is a ways off. (And anyways, cross
|
| 87 |
+
# compilers probably have a dedicated binary with the
|
| 88 |
+
# right paths compiled in. I hope.)
|
| 89 |
+
# * can't do really freaky things with the library list/library
|
| 90 |
+
# dirs, e.g. "-Ldir1 -lfoo -Ldir2 -lfoo" to link against
|
| 91 |
+
# different versions of libfoo.a in different locations. I
|
| 92 |
+
# think this is useless without the ability to null out the
|
| 93 |
+
# library search path anyways.
|
| 94 |
+
|
| 95 |
+
executables: ClassVar[dict]
|
| 96 |
+
|
| 97 |
+
# Subclasses that rely on the standard filename generation methods
|
| 98 |
+
# implemented below should override these; see the comment near
|
| 99 |
+
# those methods ('object_filenames()' et. al.) for details:
|
| 100 |
+
src_extensions: ClassVar[list[str] | None] = None
|
| 101 |
+
obj_extension: ClassVar[str | None] = None
|
| 102 |
+
static_lib_extension: ClassVar[str | None] = None
|
| 103 |
+
shared_lib_extension: ClassVar[str | None] = None
|
| 104 |
+
static_lib_format: ClassVar[str | None] = None # format string
|
| 105 |
+
shared_lib_format: ClassVar[str | None] = None # prob. same as static_lib_format
|
| 106 |
+
exe_extension: ClassVar[str | None] = None
|
| 107 |
+
|
| 108 |
+
# Default language settings. language_map is used to detect a source
|
| 109 |
+
# file or Extension target language, checking source filenames.
|
| 110 |
+
# language_order is used to detect the language precedence, when deciding
|
| 111 |
+
# what language to use when mixing source types. For example, if some
|
| 112 |
+
# extension has two files with ".c" extension, and one with ".cpp", it
|
| 113 |
+
# is still linked as c++.
|
| 114 |
+
language_map: ClassVar[dict[str, str]] = {
|
| 115 |
+
".c": "c",
|
| 116 |
+
".cc": "c++",
|
| 117 |
+
".cpp": "c++",
|
| 118 |
+
".cxx": "c++",
|
| 119 |
+
".m": "objc",
|
| 120 |
+
}
|
| 121 |
+
language_order: ClassVar[list[str]] = ["c++", "objc", "c"]
|
| 122 |
+
|
| 123 |
+
include_dirs: list[str] = []
|
| 124 |
+
"""
|
| 125 |
+
include dirs specific to this compiler class
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
library_dirs: list[str] = []
|
| 129 |
+
"""
|
| 130 |
+
library dirs specific to this compiler class
|
| 131 |
+
"""
|
| 132 |
+
|
| 133 |
+
def __init__(self, verbose: bool = False, force: bool = False) -> None:
|
| 134 |
+
self.force = force
|
| 135 |
+
self.verbose = verbose
|
| 136 |
+
|
| 137 |
+
# 'output_dir': a common output directory for object, library,
|
| 138 |
+
# shared object, and shared library files
|
| 139 |
+
self.output_dir: str | None = None
|
| 140 |
+
|
| 141 |
+
# 'macros': a list of macro definitions (or undefinitions). A
|
| 142 |
+
# macro definition is a 2-tuple (name, value), where the value is
|
| 143 |
+
# either a string or None (no explicit value). A macro
|
| 144 |
+
# undefinition is a 1-tuple (name,).
|
| 145 |
+
self.macros: list[_Macro] = []
|
| 146 |
+
|
| 147 |
+
# 'include_dirs': a list of directories to search for include files
|
| 148 |
+
self.include_dirs = []
|
| 149 |
+
|
| 150 |
+
# 'libraries': a list of libraries to include in any link
|
| 151 |
+
# (library names, not filenames: eg. "foo" not "libfoo.a")
|
| 152 |
+
self.libraries: list[str] = []
|
| 153 |
+
|
| 154 |
+
# 'library_dirs': a list of directories to search for libraries
|
| 155 |
+
self.library_dirs = []
|
| 156 |
+
|
| 157 |
+
# 'runtime_library_dirs': a list of directories to search for
|
| 158 |
+
# shared libraries/objects at runtime
|
| 159 |
+
self.runtime_library_dirs: list[str] = []
|
| 160 |
+
|
| 161 |
+
# 'objects': a list of object files (or similar, such as explicitly
|
| 162 |
+
# named library files) to include on any link
|
| 163 |
+
self.objects: list[str] = []
|
| 164 |
+
|
| 165 |
+
for key in self.executables.keys():
|
| 166 |
+
self.set_executable(key, self.executables[key])
|
| 167 |
+
|
| 168 |
+
def set_executables(self, **kwargs: str) -> None:
|
| 169 |
+
"""Define the executables (and options for them) that will be run
|
| 170 |
+
to perform the various stages of compilation. The exact set of
|
| 171 |
+
executables that may be specified here depends on the compiler
|
| 172 |
+
class (via the 'executables' class attribute), but most will have:
|
| 173 |
+
compiler the C/C++ compiler
|
| 174 |
+
linker_so linker used to create shared objects and libraries
|
| 175 |
+
linker_exe linker used to create binary executables
|
| 176 |
+
archiver static library creator
|
| 177 |
+
|
| 178 |
+
On platforms with a command-line (Unix, DOS/Windows), each of these
|
| 179 |
+
is a string that will be split into executable name and (optional)
|
| 180 |
+
list of arguments. (Splitting the string is done similarly to how
|
| 181 |
+
Unix shells operate: words are delimited by spaces, but quotes and
|
| 182 |
+
backslashes can override this. See
|
| 183 |
+
'distutils.util.split_quoted()'.)
|
| 184 |
+
"""
|
| 185 |
+
|
| 186 |
+
# Note that some CCompiler implementation classes will define class
|
| 187 |
+
# attributes 'cpp', 'cc', etc. with hard-coded executable names;
|
| 188 |
+
# this is appropriate when a compiler class is for exactly one
|
| 189 |
+
# compiler/OS combination (eg. MSVCCompiler). Other compiler
|
| 190 |
+
# classes (UnixCCompiler, in particular) are driven by information
|
| 191 |
+
# discovered at run-time, since there are many different ways to do
|
| 192 |
+
# basically the same things with Unix C compilers.
|
| 193 |
+
|
| 194 |
+
for key in kwargs:
|
| 195 |
+
if key not in self.executables:
|
| 196 |
+
raise ValueError(
|
| 197 |
+
f"unknown executable '{key}' for class {self.__class__.__name__}"
|
| 198 |
+
)
|
| 199 |
+
self.set_executable(key, kwargs[key])
|
| 200 |
+
|
| 201 |
+
def set_executable(self, key, value):
|
| 202 |
+
if isinstance(value, str):
|
| 203 |
+
setattr(self, key, split_quoted(value))
|
| 204 |
+
else:
|
| 205 |
+
setattr(self, key, value)
|
| 206 |
+
|
| 207 |
+
def _find_macro(self, name):
|
| 208 |
+
i = 0
|
| 209 |
+
for defn in self.macros:
|
| 210 |
+
if defn[0] == name:
|
| 211 |
+
return i
|
| 212 |
+
i += 1
|
| 213 |
+
return None
|
| 214 |
+
|
| 215 |
+
def _check_macro_definitions(self, definitions):
|
| 216 |
+
"""Ensure that every element of 'definitions' is valid."""
|
| 217 |
+
for defn in definitions:
|
| 218 |
+
self._check_macro_definition(*defn)
|
| 219 |
+
|
| 220 |
+
def _check_macro_definition(self, defn):
|
| 221 |
+
"""
|
| 222 |
+
Raise a TypeError if defn is not valid.
|
| 223 |
+
|
| 224 |
+
A valid definition is either a (name, value) 2-tuple or a (name,) tuple.
|
| 225 |
+
"""
|
| 226 |
+
if not isinstance(defn, tuple) or not self._is_valid_macro(*defn):
|
| 227 |
+
raise TypeError(
|
| 228 |
+
f"invalid macro definition '{defn}': "
|
| 229 |
+
"must be tuple (string,), (string, string), or (string, None)"
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
@staticmethod
|
| 233 |
+
def _is_valid_macro(name, value=None):
|
| 234 |
+
"""
|
| 235 |
+
A valid macro is a ``name : str`` and a ``value : str | None``.
|
| 236 |
+
|
| 237 |
+
>>> Compiler._is_valid_macro('foo', None)
|
| 238 |
+
True
|
| 239 |
+
"""
|
| 240 |
+
return isinstance(name, str) and isinstance(value, (str, type(None)))
|
| 241 |
+
|
| 242 |
+
# -- Bookkeeping methods -------------------------------------------
|
| 243 |
+
|
| 244 |
+
def define_macro(self, name: str, value: str | None = None) -> None:
|
| 245 |
+
"""Define a preprocessor macro for all compilations driven by this
|
| 246 |
+
compiler object. The optional parameter 'value' should be a
|
| 247 |
+
string; if it is not supplied, then the macro will be defined
|
| 248 |
+
without an explicit value and the exact outcome depends on the
|
| 249 |
+
compiler used (XXX true? does ANSI say anything about this?)
|
| 250 |
+
"""
|
| 251 |
+
# Delete from the list of macro definitions/undefinitions if
|
| 252 |
+
# already there (so that this one will take precedence).
|
| 253 |
+
i = self._find_macro(name)
|
| 254 |
+
if i is not None:
|
| 255 |
+
del self.macros[i]
|
| 256 |
+
|
| 257 |
+
self.macros.append((name, value))
|
| 258 |
+
|
| 259 |
+
def undefine_macro(self, name: str) -> None:
|
| 260 |
+
"""Undefine a preprocessor macro for all compilations driven by
|
| 261 |
+
this compiler object. If the same macro is defined by
|
| 262 |
+
'define_macro()' and undefined by 'undefine_macro()' the last call
|
| 263 |
+
takes precedence (including multiple redefinitions or
|
| 264 |
+
undefinitions). If the macro is redefined/undefined on a
|
| 265 |
+
per-compilation basis (ie. in the call to 'compile()'), then that
|
| 266 |
+
takes precedence.
|
| 267 |
+
"""
|
| 268 |
+
# Delete from the list of macro definitions/undefinitions if
|
| 269 |
+
# already there (so that this one will take precedence).
|
| 270 |
+
i = self._find_macro(name)
|
| 271 |
+
if i is not None:
|
| 272 |
+
del self.macros[i]
|
| 273 |
+
|
| 274 |
+
undefn = (name,)
|
| 275 |
+
self.macros.append(undefn)
|
| 276 |
+
|
| 277 |
+
def add_include_dir(self, dir: str) -> None:
|
| 278 |
+
"""Add 'dir' to the list of directories that will be searched for
|
| 279 |
+
header files. The compiler is instructed to search directories in
|
| 280 |
+
the order in which they are supplied by successive calls to
|
| 281 |
+
'add_include_dir()'.
|
| 282 |
+
"""
|
| 283 |
+
self.include_dirs.append(dir)
|
| 284 |
+
|
| 285 |
+
def set_include_dirs(self, dirs: list[str]) -> None:
|
| 286 |
+
"""Set the list of directories that will be searched to 'dirs' (a
|
| 287 |
+
list of strings). Overrides any preceding calls to
|
| 288 |
+
'add_include_dir()'; subsequence calls to 'add_include_dir()' add
|
| 289 |
+
to the list passed to 'set_include_dirs()'. This does not affect
|
| 290 |
+
any list of standard include directories that the compiler may
|
| 291 |
+
search by default.
|
| 292 |
+
"""
|
| 293 |
+
self.include_dirs = dirs[:]
|
| 294 |
+
|
| 295 |
+
def add_library(self, libname: str) -> None:
|
| 296 |
+
"""Add 'libname' to the list of libraries that will be included in
|
| 297 |
+
all links driven by this compiler object. Note that 'libname'
|
| 298 |
+
should *not* be the name of a file containing a library, but the
|
| 299 |
+
name of the library itself: the actual filename will be inferred by
|
| 300 |
+
the linker, the compiler, or the compiler class (depending on the
|
| 301 |
+
platform).
|
| 302 |
+
|
| 303 |
+
The linker will be instructed to link against libraries in the
|
| 304 |
+
order they were supplied to 'add_library()' and/or
|
| 305 |
+
'set_libraries()'. It is perfectly valid to duplicate library
|
| 306 |
+
names; the linker will be instructed to link against libraries as
|
| 307 |
+
many times as they are mentioned.
|
| 308 |
+
"""
|
| 309 |
+
self.libraries.append(libname)
|
| 310 |
+
|
| 311 |
+
def set_libraries(self, libnames: list[str]) -> None:
|
| 312 |
+
"""Set the list of libraries to be included in all links driven by
|
| 313 |
+
this compiler object to 'libnames' (a list of strings). This does
|
| 314 |
+
not affect any standard system libraries that the linker may
|
| 315 |
+
include by default.
|
| 316 |
+
"""
|
| 317 |
+
self.libraries = libnames[:]
|
| 318 |
+
|
| 319 |
+
def add_library_dir(self, dir: str) -> None:
|
| 320 |
+
"""Add 'dir' to the list of directories that will be searched for
|
| 321 |
+
libraries specified to 'add_library()' and 'set_libraries()'. The
|
| 322 |
+
linker will be instructed to search for libraries in the order they
|
| 323 |
+
are supplied to 'add_library_dir()' and/or 'set_library_dirs()'.
|
| 324 |
+
"""
|
| 325 |
+
self.library_dirs.append(dir)
|
| 326 |
+
|
| 327 |
+
def set_library_dirs(self, dirs: list[str]) -> None:
|
| 328 |
+
"""Set the list of library search directories to 'dirs' (a list of
|
| 329 |
+
strings). This does not affect any standard library search path
|
| 330 |
+
that the linker may search by default.
|
| 331 |
+
"""
|
| 332 |
+
self.library_dirs = dirs[:]
|
| 333 |
+
|
| 334 |
+
def add_runtime_library_dir(self, dir: str) -> None:
|
| 335 |
+
"""Add 'dir' to the list of directories that will be searched for
|
| 336 |
+
shared libraries at runtime.
|
| 337 |
+
"""
|
| 338 |
+
self.runtime_library_dirs.append(dir)
|
| 339 |
+
|
| 340 |
+
def set_runtime_library_dirs(self, dirs: list[str]) -> None:
|
| 341 |
+
"""Set the list of directories to search for shared libraries at
|
| 342 |
+
runtime to 'dirs' (a list of strings). This does not affect any
|
| 343 |
+
standard search path that the runtime linker may search by
|
| 344 |
+
default.
|
| 345 |
+
"""
|
| 346 |
+
self.runtime_library_dirs = dirs[:]
|
| 347 |
+
|
| 348 |
+
def add_link_object(self, object: str) -> None:
|
| 349 |
+
"""Add 'object' to the list of object files (or analogues, such as
|
| 350 |
+
explicitly named library files or the output of "resource
|
| 351 |
+
compilers") to be included in every link driven by this compiler
|
| 352 |
+
object.
|
| 353 |
+
"""
|
| 354 |
+
self.objects.append(object)
|
| 355 |
+
|
| 356 |
+
def set_link_objects(self, objects: list[str]) -> None:
|
| 357 |
+
"""Set the list of object files (or analogues) to be included in
|
| 358 |
+
every link to 'objects'. This does not affect any standard object
|
| 359 |
+
files that the linker may include by default (such as system
|
| 360 |
+
libraries).
|
| 361 |
+
"""
|
| 362 |
+
self.objects = objects[:]
|
| 363 |
+
|
| 364 |
+
# -- Private utility methods --------------------------------------
|
| 365 |
+
# (here for the convenience of subclasses)
|
| 366 |
+
|
| 367 |
+
# Helper method to prep compiler in subclass compile() methods
|
| 368 |
+
|
| 369 |
+
def _setup_compile(
|
| 370 |
+
self,
|
| 371 |
+
outdir: str | None,
|
| 372 |
+
macros: list[_Macro] | None,
|
| 373 |
+
incdirs: list[str] | tuple[str, ...] | None,
|
| 374 |
+
sources,
|
| 375 |
+
depends,
|
| 376 |
+
extra,
|
| 377 |
+
):
|
| 378 |
+
"""Process arguments and decide which source files to compile."""
|
| 379 |
+
outdir, macros, incdirs = self._fix_compile_args(outdir, macros, incdirs)
|
| 380 |
+
|
| 381 |
+
if extra is None:
|
| 382 |
+
extra = []
|
| 383 |
+
|
| 384 |
+
# Get the list of expected output (object) files
|
| 385 |
+
objects = self.object_filenames(sources, strip_dir=False, output_dir=outdir)
|
| 386 |
+
assert len(objects) == len(sources)
|
| 387 |
+
|
| 388 |
+
pp_opts = gen_preprocess_options(macros, incdirs)
|
| 389 |
+
|
| 390 |
+
build = {}
|
| 391 |
+
for i in range(len(sources)):
|
| 392 |
+
src = sources[i]
|
| 393 |
+
obj = objects[i]
|
| 394 |
+
ext = os.path.splitext(src)[1]
|
| 395 |
+
self.mkpath(os.path.dirname(obj))
|
| 396 |
+
build[obj] = (src, ext)
|
| 397 |
+
|
| 398 |
+
return macros, objects, extra, pp_opts, build
|
| 399 |
+
|
| 400 |
+
def _get_cc_args(self, pp_opts, debug, before):
|
| 401 |
+
# works for unixccompiler, cygwinccompiler
|
| 402 |
+
cc_args = pp_opts + ['-c']
|
| 403 |
+
if debug:
|
| 404 |
+
cc_args[:0] = ['-g']
|
| 405 |
+
if before:
|
| 406 |
+
cc_args[:0] = before
|
| 407 |
+
return cc_args
|
| 408 |
+
|
| 409 |
+
def _fix_compile_args(
|
| 410 |
+
self,
|
| 411 |
+
output_dir: str | None,
|
| 412 |
+
macros: list[_Macro] | None,
|
| 413 |
+
include_dirs: list[str] | tuple[str, ...] | None,
|
| 414 |
+
) -> tuple[str, list[_Macro], list[str]]:
|
| 415 |
+
"""Typecheck and fix-up some of the arguments to the 'compile()'
|
| 416 |
+
method, and return fixed-up values. Specifically: if 'output_dir'
|
| 417 |
+
is None, replaces it with 'self.output_dir'; ensures that 'macros'
|
| 418 |
+
is a list, and augments it with 'self.macros'; ensures that
|
| 419 |
+
'include_dirs' is a list, and augments it with 'self.include_dirs'.
|
| 420 |
+
Guarantees that the returned values are of the correct type,
|
| 421 |
+
i.e. for 'output_dir' either string or None, and for 'macros' and
|
| 422 |
+
'include_dirs' either list or None.
|
| 423 |
+
"""
|
| 424 |
+
if output_dir is None:
|
| 425 |
+
output_dir = self.output_dir
|
| 426 |
+
elif not isinstance(output_dir, str):
|
| 427 |
+
raise TypeError("'output_dir' must be a string or None")
|
| 428 |
+
|
| 429 |
+
if macros is None:
|
| 430 |
+
macros = list(self.macros)
|
| 431 |
+
elif isinstance(macros, list):
|
| 432 |
+
macros = macros + (self.macros or [])
|
| 433 |
+
else:
|
| 434 |
+
raise TypeError("'macros' (if supplied) must be a list of tuples")
|
| 435 |
+
|
| 436 |
+
if include_dirs is None:
|
| 437 |
+
include_dirs = list(self.include_dirs)
|
| 438 |
+
elif isinstance(include_dirs, (list, tuple)):
|
| 439 |
+
include_dirs = list(include_dirs) + (self.include_dirs or [])
|
| 440 |
+
else:
|
| 441 |
+
raise TypeError("'include_dirs' (if supplied) must be a list of strings")
|
| 442 |
+
|
| 443 |
+
# add include dirs for class
|
| 444 |
+
include_dirs += self.__class__.include_dirs
|
| 445 |
+
|
| 446 |
+
return output_dir, macros, include_dirs
|
| 447 |
+
|
| 448 |
+
def _prep_compile(self, sources, output_dir, depends=None):
|
| 449 |
+
"""Decide which source files must be recompiled.
|
| 450 |
+
|
| 451 |
+
Determine the list of object files corresponding to 'sources',
|
| 452 |
+
and figure out which ones really need to be recompiled.
|
| 453 |
+
Return a list of all object files and a dictionary telling
|
| 454 |
+
which source files can be skipped.
|
| 455 |
+
"""
|
| 456 |
+
# Get the list of expected output (object) files
|
| 457 |
+
objects = self.object_filenames(sources, output_dir=output_dir)
|
| 458 |
+
assert len(objects) == len(sources)
|
| 459 |
+
|
| 460 |
+
# Return an empty dict for the "which source files can be skipped"
|
| 461 |
+
# return value to preserve API compatibility.
|
| 462 |
+
return objects, {}
|
| 463 |
+
|
| 464 |
+
def _fix_object_args(
|
| 465 |
+
self, objects: list[str] | tuple[str, ...], output_dir: str | None
|
| 466 |
+
) -> tuple[list[str], str]:
|
| 467 |
+
"""Typecheck and fix up some arguments supplied to various methods.
|
| 468 |
+
Specifically: ensure that 'objects' is a list; if output_dir is
|
| 469 |
+
None, replace with self.output_dir. Return fixed versions of
|
| 470 |
+
'objects' and 'output_dir'.
|
| 471 |
+
"""
|
| 472 |
+
if not isinstance(objects, (list, tuple)):
|
| 473 |
+
raise TypeError("'objects' must be a list or tuple of strings")
|
| 474 |
+
objects = list(objects)
|
| 475 |
+
|
| 476 |
+
if output_dir is None:
|
| 477 |
+
output_dir = self.output_dir
|
| 478 |
+
elif not isinstance(output_dir, str):
|
| 479 |
+
raise TypeError("'output_dir' must be a string or None")
|
| 480 |
+
|
| 481 |
+
return (objects, output_dir)
|
| 482 |
+
|
| 483 |
+
def _fix_lib_args(
|
| 484 |
+
self,
|
| 485 |
+
libraries: list[str] | tuple[str, ...] | None,
|
| 486 |
+
library_dirs: list[str] | tuple[str, ...] | None,
|
| 487 |
+
runtime_library_dirs: list[str] | tuple[str, ...] | None,
|
| 488 |
+
) -> tuple[list[str], list[str], list[str]]:
|
| 489 |
+
"""Typecheck and fix up some of the arguments supplied to the
|
| 490 |
+
'link_*' methods. Specifically: ensure that all arguments are
|
| 491 |
+
lists, and augment them with their permanent versions
|
| 492 |
+
(eg. 'self.libraries' augments 'libraries'). Return a tuple with
|
| 493 |
+
fixed versions of all arguments.
|
| 494 |
+
"""
|
| 495 |
+
if libraries is None:
|
| 496 |
+
libraries = list(self.libraries)
|
| 497 |
+
elif isinstance(libraries, (list, tuple)):
|
| 498 |
+
libraries = list(libraries) + (self.libraries or [])
|
| 499 |
+
else:
|
| 500 |
+
raise TypeError("'libraries' (if supplied) must be a list of strings")
|
| 501 |
+
|
| 502 |
+
if library_dirs is None:
|
| 503 |
+
library_dirs = list(self.library_dirs)
|
| 504 |
+
elif isinstance(library_dirs, (list, tuple)):
|
| 505 |
+
library_dirs = list(library_dirs) + (self.library_dirs or [])
|
| 506 |
+
else:
|
| 507 |
+
raise TypeError("'library_dirs' (if supplied) must be a list of strings")
|
| 508 |
+
|
| 509 |
+
# add library dirs for class
|
| 510 |
+
library_dirs += self.__class__.library_dirs
|
| 511 |
+
|
| 512 |
+
if runtime_library_dirs is None:
|
| 513 |
+
runtime_library_dirs = list(self.runtime_library_dirs)
|
| 514 |
+
elif isinstance(runtime_library_dirs, (list, tuple)):
|
| 515 |
+
runtime_library_dirs = list(runtime_library_dirs) + (
|
| 516 |
+
self.runtime_library_dirs or []
|
| 517 |
+
)
|
| 518 |
+
else:
|
| 519 |
+
raise TypeError(
|
| 520 |
+
"'runtime_library_dirs' (if supplied) must be a list of strings"
|
| 521 |
+
)
|
| 522 |
+
|
| 523 |
+
return (libraries, library_dirs, runtime_library_dirs)
|
| 524 |
+
|
| 525 |
+
def _need_link(self, objects, output_file):
|
| 526 |
+
"""Return true if we need to relink the files listed in 'objects'
|
| 527 |
+
to recreate 'output_file'.
|
| 528 |
+
"""
|
| 529 |
+
if self.force:
|
| 530 |
+
return True
|
| 531 |
+
newer = newer_group(objects, output_file)
|
| 532 |
+
return newer
|
| 533 |
+
|
| 534 |
+
def detect_language(self, sources: str | list[str]) -> str | None:
|
| 535 |
+
"""Detect the language of a given file, or list of files. Uses
|
| 536 |
+
language_map, and language_order to do the job.
|
| 537 |
+
"""
|
| 538 |
+
if not isinstance(sources, list):
|
| 539 |
+
sources = [sources]
|
| 540 |
+
lang = None
|
| 541 |
+
index = len(self.language_order)
|
| 542 |
+
for source in sources:
|
| 543 |
+
base, ext = os.path.splitext(source)
|
| 544 |
+
extlang = self.language_map.get(ext)
|
| 545 |
+
try:
|
| 546 |
+
extindex = self.language_order.index(extlang)
|
| 547 |
+
if extindex < index:
|
| 548 |
+
lang = extlang
|
| 549 |
+
index = extindex
|
| 550 |
+
except ValueError:
|
| 551 |
+
pass
|
| 552 |
+
return lang
|
| 553 |
+
|
| 554 |
+
# -- Worker methods ------------------------------------------------
|
| 555 |
+
# (must be implemented by subclasses)
|
| 556 |
+
|
| 557 |
+
def preprocess(
|
| 558 |
+
self,
|
| 559 |
+
source: str | os.PathLike[str],
|
| 560 |
+
output_file: str | os.PathLike[str] | None = None,
|
| 561 |
+
macros: list[_Macro] | None = None,
|
| 562 |
+
include_dirs: list[str] | tuple[str, ...] | None = None,
|
| 563 |
+
extra_preargs: list[str] | None = None,
|
| 564 |
+
extra_postargs: Iterable[str] | None = None,
|
| 565 |
+
):
|
| 566 |
+
"""Preprocess a single C/C++ source file, named in 'source'.
|
| 567 |
+
Output will be written to file named 'output_file', or stdout if
|
| 568 |
+
'output_file' not supplied. 'macros' is a list of macro
|
| 569 |
+
definitions as for 'compile()', which will augment the macros set
|
| 570 |
+
with 'define_macro()' and 'undefine_macro()'. 'include_dirs' is a
|
| 571 |
+
list of directory names that will be added to the default list.
|
| 572 |
+
|
| 573 |
+
Raises PreprocessError on failure.
|
| 574 |
+
"""
|
| 575 |
+
pass
|
| 576 |
+
|
| 577 |
+
def compile(
|
| 578 |
+
self,
|
| 579 |
+
sources: Sequence[str | os.PathLike[str]],
|
| 580 |
+
output_dir: str | None = None,
|
| 581 |
+
macros: list[_Macro] | None = None,
|
| 582 |
+
include_dirs: list[str] | tuple[str, ...] | None = None,
|
| 583 |
+
debug: bool = False,
|
| 584 |
+
extra_preargs: list[str] | None = None,
|
| 585 |
+
extra_postargs: list[str] | None = None,
|
| 586 |
+
depends: list[str] | tuple[str, ...] | None = None,
|
| 587 |
+
) -> list[str]:
|
| 588 |
+
"""Compile one or more source files.
|
| 589 |
+
|
| 590 |
+
'sources' must be a list of filenames, most likely C/C++
|
| 591 |
+
files, but in reality anything that can be handled by a
|
| 592 |
+
particular compiler and compiler class (eg. MSVCCompiler can
|
| 593 |
+
handle resource files in 'sources'). Return a list of object
|
| 594 |
+
filenames, one per source filename in 'sources'. Depending on
|
| 595 |
+
the implementation, not all source files will necessarily be
|
| 596 |
+
compiled, but all corresponding object filenames will be
|
| 597 |
+
returned.
|
| 598 |
+
|
| 599 |
+
If 'output_dir' is given, object files will be put under it, while
|
| 600 |
+
retaining their original path component. That is, "foo/bar.c"
|
| 601 |
+
normally compiles to "foo/bar.o" (for a Unix implementation); if
|
| 602 |
+
'output_dir' is "build", then it would compile to
|
| 603 |
+
"build/foo/bar.o".
|
| 604 |
+
|
| 605 |
+
'macros', if given, must be a list of macro definitions. A macro
|
| 606 |
+
definition is either a (name, value) 2-tuple or a (name,) 1-tuple.
|
| 607 |
+
The former defines a macro; if the value is None, the macro is
|
| 608 |
+
defined without an explicit value. The 1-tuple case undefines a
|
| 609 |
+
macro. Later definitions/redefinitions/ undefinitions take
|
| 610 |
+
precedence.
|
| 611 |
+
|
| 612 |
+
'include_dirs', if given, must be a list of strings, the
|
| 613 |
+
directories to add to the default include file search path for this
|
| 614 |
+
compilation only.
|
| 615 |
+
|
| 616 |
+
'debug' is a boolean; if true, the compiler will be instructed to
|
| 617 |
+
output debug symbols in (or alongside) the object file(s).
|
| 618 |
+
|
| 619 |
+
'extra_preargs' and 'extra_postargs' are implementation- dependent.
|
| 620 |
+
On platforms that have the notion of a command-line (e.g. Unix,
|
| 621 |
+
DOS/Windows), they are most likely lists of strings: extra
|
| 622 |
+
command-line arguments to prepend/append to the compiler command
|
| 623 |
+
line. On other platforms, consult the implementation class
|
| 624 |
+
documentation. In any event, they are intended as an escape hatch
|
| 625 |
+
for those occasions when the abstract compiler framework doesn't
|
| 626 |
+
cut the mustard.
|
| 627 |
+
|
| 628 |
+
'depends', if given, is a list of filenames that all targets
|
| 629 |
+
depend on. If a source file is older than any file in
|
| 630 |
+
depends, then the source file will be recompiled. This
|
| 631 |
+
supports dependency tracking, but only at a coarse
|
| 632 |
+
granularity.
|
| 633 |
+
|
| 634 |
+
Raises CompileError on failure.
|
| 635 |
+
"""
|
| 636 |
+
# A concrete compiler class can either override this method
|
| 637 |
+
# entirely or implement _compile().
|
| 638 |
+
macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
|
| 639 |
+
output_dir, macros, include_dirs, sources, depends, extra_postargs
|
| 640 |
+
)
|
| 641 |
+
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
|
| 642 |
+
|
| 643 |
+
for obj in objects:
|
| 644 |
+
try:
|
| 645 |
+
src, ext = build[obj]
|
| 646 |
+
except KeyError:
|
| 647 |
+
continue
|
| 648 |
+
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
|
| 649 |
+
|
| 650 |
+
# Return *all* object filenames, not just the ones we just built.
|
| 651 |
+
return objects
|
| 652 |
+
|
| 653 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 654 |
+
"""Compile 'src' to product 'obj'."""
|
| 655 |
+
# A concrete compiler class that does not override compile()
|
| 656 |
+
# should implement _compile().
|
| 657 |
+
pass
|
| 658 |
+
|
| 659 |
+
def create_static_lib(
|
| 660 |
+
self,
|
| 661 |
+
objects: list[str] | tuple[str, ...],
|
| 662 |
+
output_libname: str,
|
| 663 |
+
output_dir: str | None = None,
|
| 664 |
+
debug: bool = False,
|
| 665 |
+
target_lang: str | None = None,
|
| 666 |
+
) -> None:
|
| 667 |
+
"""Link a bunch of stuff together to create a static library file.
|
| 668 |
+
The "bunch of stuff" consists of the list of object files supplied
|
| 669 |
+
as 'objects', the extra object files supplied to
|
| 670 |
+
'add_link_object()' and/or 'set_link_objects()', the libraries
|
| 671 |
+
supplied to 'add_library()' and/or 'set_libraries()', and the
|
| 672 |
+
libraries supplied as 'libraries' (if any).
|
| 673 |
+
|
| 674 |
+
'output_libname' should be a library name, not a filename; the
|
| 675 |
+
filename will be inferred from the library name. 'output_dir' is
|
| 676 |
+
the directory where the library file will be put.
|
| 677 |
+
|
| 678 |
+
'debug' is a boolean; if true, debugging information will be
|
| 679 |
+
included in the library (note that on most platforms, it is the
|
| 680 |
+
compile step where this matters: the 'debug' flag is included here
|
| 681 |
+
just for consistency).
|
| 682 |
+
|
| 683 |
+
'target_lang' is the target language for which the given objects
|
| 684 |
+
are being compiled. This allows specific linkage time treatment of
|
| 685 |
+
certain languages.
|
| 686 |
+
|
| 687 |
+
Raises LibError on failure.
|
| 688 |
+
"""
|
| 689 |
+
pass
|
| 690 |
+
|
| 691 |
+
# values for target_desc parameter in link()
|
| 692 |
+
SHARED_OBJECT = "shared_object"
|
| 693 |
+
SHARED_LIBRARY = "shared_library"
|
| 694 |
+
EXECUTABLE = "executable"
|
| 695 |
+
|
| 696 |
+
def link(
|
| 697 |
+
self,
|
| 698 |
+
target_desc: str,
|
| 699 |
+
objects: list[str] | tuple[str, ...],
|
| 700 |
+
output_filename: str,
|
| 701 |
+
output_dir: str | None = None,
|
| 702 |
+
libraries: list[str] | tuple[str, ...] | None = None,
|
| 703 |
+
library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 704 |
+
runtime_library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 705 |
+
export_symbols: Iterable[str] | None = None,
|
| 706 |
+
debug: bool = False,
|
| 707 |
+
extra_preargs: list[str] | None = None,
|
| 708 |
+
extra_postargs: list[str] | None = None,
|
| 709 |
+
build_temp: str | os.PathLike[str] | None = None,
|
| 710 |
+
target_lang: str | None = None,
|
| 711 |
+
):
|
| 712 |
+
"""Link a bunch of stuff together to create an executable or
|
| 713 |
+
shared library file.
|
| 714 |
+
|
| 715 |
+
The "bunch of stuff" consists of the list of object files supplied
|
| 716 |
+
as 'objects'. 'output_filename' should be a filename. If
|
| 717 |
+
'output_dir' is supplied, 'output_filename' is relative to it
|
| 718 |
+
(i.e. 'output_filename' can provide directory components if
|
| 719 |
+
needed).
|
| 720 |
+
|
| 721 |
+
'libraries' is a list of libraries to link against. These are
|
| 722 |
+
library names, not filenames, since they're translated into
|
| 723 |
+
filenames in a platform-specific way (eg. "foo" becomes "libfoo.a"
|
| 724 |
+
on Unix and "foo.lib" on DOS/Windows). However, they can include a
|
| 725 |
+
directory component, which means the linker will look in that
|
| 726 |
+
specific directory rather than searching all the normal locations.
|
| 727 |
+
|
| 728 |
+
'library_dirs', if supplied, should be a list of directories to
|
| 729 |
+
search for libraries that were specified as bare library names
|
| 730 |
+
(ie. no directory component). These are on top of the system
|
| 731 |
+
default and those supplied to 'add_library_dir()' and/or
|
| 732 |
+
'set_library_dirs()'. 'runtime_library_dirs' is a list of
|
| 733 |
+
directories that will be embedded into the shared library and used
|
| 734 |
+
to search for other shared libraries that *it* depends on at
|
| 735 |
+
run-time. (This may only be relevant on Unix.)
|
| 736 |
+
|
| 737 |
+
'export_symbols' is a list of symbols that the shared library will
|
| 738 |
+
export. (This appears to be relevant only on Windows.)
|
| 739 |
+
|
| 740 |
+
'debug' is as for 'compile()' and 'create_static_lib()', with the
|
| 741 |
+
slight distinction that it actually matters on most platforms (as
|
| 742 |
+
opposed to 'create_static_lib()', which includes a 'debug' flag
|
| 743 |
+
mostly for form's sake).
|
| 744 |
+
|
| 745 |
+
'extra_preargs' and 'extra_postargs' are as for 'compile()' (except
|
| 746 |
+
of course that they supply command-line arguments for the
|
| 747 |
+
particular linker being used).
|
| 748 |
+
|
| 749 |
+
'target_lang' is the target language for which the given objects
|
| 750 |
+
are being compiled. This allows specific linkage time treatment of
|
| 751 |
+
certain languages.
|
| 752 |
+
|
| 753 |
+
Raises LinkError on failure.
|
| 754 |
+
"""
|
| 755 |
+
raise NotImplementedError
|
| 756 |
+
|
| 757 |
+
# Old 'link_*()' methods, rewritten to use the new 'link()' method.
|
| 758 |
+
|
| 759 |
+
def link_shared_lib(
|
| 760 |
+
self,
|
| 761 |
+
objects: list[str] | tuple[str, ...],
|
| 762 |
+
output_libname: str,
|
| 763 |
+
output_dir: str | None = None,
|
| 764 |
+
libraries: list[str] | tuple[str, ...] | None = None,
|
| 765 |
+
library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 766 |
+
runtime_library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 767 |
+
export_symbols: Iterable[str] | None = None,
|
| 768 |
+
debug: bool = False,
|
| 769 |
+
extra_preargs: list[str] | None = None,
|
| 770 |
+
extra_postargs: list[str] | None = None,
|
| 771 |
+
build_temp: str | os.PathLike[str] | None = None,
|
| 772 |
+
target_lang: str | None = None,
|
| 773 |
+
):
|
| 774 |
+
self.link(
|
| 775 |
+
Compiler.SHARED_LIBRARY,
|
| 776 |
+
objects,
|
| 777 |
+
self.library_filename(output_libname, lib_type='shared'),
|
| 778 |
+
output_dir,
|
| 779 |
+
libraries,
|
| 780 |
+
library_dirs,
|
| 781 |
+
runtime_library_dirs,
|
| 782 |
+
export_symbols,
|
| 783 |
+
debug,
|
| 784 |
+
extra_preargs,
|
| 785 |
+
extra_postargs,
|
| 786 |
+
build_temp,
|
| 787 |
+
target_lang,
|
| 788 |
+
)
|
| 789 |
+
|
| 790 |
+
def link_shared_object(
|
| 791 |
+
self,
|
| 792 |
+
objects: list[str] | tuple[str, ...],
|
| 793 |
+
output_filename: str,
|
| 794 |
+
output_dir: str | None = None,
|
| 795 |
+
libraries: list[str] | tuple[str, ...] | None = None,
|
| 796 |
+
library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 797 |
+
runtime_library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 798 |
+
export_symbols: Iterable[str] | None = None,
|
| 799 |
+
debug: bool = False,
|
| 800 |
+
extra_preargs: list[str] | None = None,
|
| 801 |
+
extra_postargs: list[str] | None = None,
|
| 802 |
+
build_temp: str | os.PathLike[str] | None = None,
|
| 803 |
+
target_lang: str | None = None,
|
| 804 |
+
):
|
| 805 |
+
self.link(
|
| 806 |
+
Compiler.SHARED_OBJECT,
|
| 807 |
+
objects,
|
| 808 |
+
output_filename,
|
| 809 |
+
output_dir,
|
| 810 |
+
libraries,
|
| 811 |
+
library_dirs,
|
| 812 |
+
runtime_library_dirs,
|
| 813 |
+
export_symbols,
|
| 814 |
+
debug,
|
| 815 |
+
extra_preargs,
|
| 816 |
+
extra_postargs,
|
| 817 |
+
build_temp,
|
| 818 |
+
target_lang,
|
| 819 |
+
)
|
| 820 |
+
|
| 821 |
+
def link_executable(
|
| 822 |
+
self,
|
| 823 |
+
objects: list[str] | tuple[str, ...],
|
| 824 |
+
output_progname: str,
|
| 825 |
+
output_dir: str | None = None,
|
| 826 |
+
libraries: list[str] | tuple[str, ...] | None = None,
|
| 827 |
+
library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 828 |
+
runtime_library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 829 |
+
debug: bool = False,
|
| 830 |
+
extra_preargs: list[str] | None = None,
|
| 831 |
+
extra_postargs: list[str] | None = None,
|
| 832 |
+
target_lang: str | None = None,
|
| 833 |
+
):
|
| 834 |
+
self.link(
|
| 835 |
+
Compiler.EXECUTABLE,
|
| 836 |
+
objects,
|
| 837 |
+
self.executable_filename(output_progname),
|
| 838 |
+
output_dir,
|
| 839 |
+
libraries,
|
| 840 |
+
library_dirs,
|
| 841 |
+
runtime_library_dirs,
|
| 842 |
+
None,
|
| 843 |
+
debug,
|
| 844 |
+
extra_preargs,
|
| 845 |
+
extra_postargs,
|
| 846 |
+
None,
|
| 847 |
+
target_lang,
|
| 848 |
+
)
|
| 849 |
+
|
| 850 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 851 |
+
# These are all used by the 'gen_lib_options() function; there is
|
| 852 |
+
# no appropriate default implementation so subclasses should
|
| 853 |
+
# implement all of these.
|
| 854 |
+
|
| 855 |
+
def library_dir_option(self, dir: str) -> str:
|
| 856 |
+
"""Return the compiler option to add 'dir' to the list of
|
| 857 |
+
directories searched for libraries.
|
| 858 |
+
"""
|
| 859 |
+
raise NotImplementedError
|
| 860 |
+
|
| 861 |
+
def runtime_library_dir_option(self, dir: str) -> str:
|
| 862 |
+
"""Return the compiler option to add 'dir' to the list of
|
| 863 |
+
directories searched for runtime libraries.
|
| 864 |
+
"""
|
| 865 |
+
raise NotImplementedError
|
| 866 |
+
|
| 867 |
+
def library_option(self, lib: str) -> str:
|
| 868 |
+
"""Return the compiler option to add 'lib' to the list of libraries
|
| 869 |
+
linked into the shared library or executable.
|
| 870 |
+
"""
|
| 871 |
+
raise NotImplementedError
|
| 872 |
+
|
| 873 |
+
def has_function( # noqa: C901
|
| 874 |
+
self,
|
| 875 |
+
funcname: str,
|
| 876 |
+
includes: Iterable[str] | None = None,
|
| 877 |
+
include_dirs: list[str] | tuple[str, ...] | None = None,
|
| 878 |
+
libraries: list[str] | None = None,
|
| 879 |
+
library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 880 |
+
) -> bool:
|
| 881 |
+
"""Return a boolean indicating whether funcname is provided as
|
| 882 |
+
a symbol on the current platform. The optional arguments can
|
| 883 |
+
be used to augment the compilation environment.
|
| 884 |
+
|
| 885 |
+
The libraries argument is a list of flags to be passed to the
|
| 886 |
+
linker to make additional symbol definitions available for
|
| 887 |
+
linking.
|
| 888 |
+
|
| 889 |
+
The includes and include_dirs arguments are deprecated.
|
| 890 |
+
Usually, supplying include files with function declarations
|
| 891 |
+
will cause function detection to fail even in cases where the
|
| 892 |
+
symbol is available for linking.
|
| 893 |
+
|
| 894 |
+
"""
|
| 895 |
+
# this can't be included at module scope because it tries to
|
| 896 |
+
# import math which might not be available at that point - maybe
|
| 897 |
+
# the necessary logic should just be inlined?
|
| 898 |
+
import tempfile
|
| 899 |
+
|
| 900 |
+
if includes is None:
|
| 901 |
+
includes = []
|
| 902 |
+
else:
|
| 903 |
+
warnings.warn("includes is deprecated", DeprecationWarning)
|
| 904 |
+
if include_dirs is None:
|
| 905 |
+
include_dirs = []
|
| 906 |
+
else:
|
| 907 |
+
warnings.warn("include_dirs is deprecated", DeprecationWarning)
|
| 908 |
+
if libraries is None:
|
| 909 |
+
libraries = []
|
| 910 |
+
if library_dirs is None:
|
| 911 |
+
library_dirs = []
|
| 912 |
+
fd, fname = tempfile.mkstemp(".c", funcname, text=True)
|
| 913 |
+
with os.fdopen(fd, "w", encoding='utf-8') as f:
|
| 914 |
+
for incl in includes:
|
| 915 |
+
f.write(f"""#include "{incl}"\n""")
|
| 916 |
+
if not includes:
|
| 917 |
+
# Use "char func(void);" as the prototype to follow
|
| 918 |
+
# what autoconf does. This prototype does not match
|
| 919 |
+
# any well-known function the compiler might recognize
|
| 920 |
+
# as a builtin, so this ends up as a true link test.
|
| 921 |
+
# Without a fake prototype, the test would need to
|
| 922 |
+
# know the exact argument types, and the has_function
|
| 923 |
+
# interface does not provide that level of information.
|
| 924 |
+
f.write(
|
| 925 |
+
f"""\
|
| 926 |
+
#ifdef __cplusplus
|
| 927 |
+
extern "C"
|
| 928 |
+
#endif
|
| 929 |
+
char {funcname}(void);
|
| 930 |
+
"""
|
| 931 |
+
)
|
| 932 |
+
f.write(
|
| 933 |
+
f"""\
|
| 934 |
+
int main (int argc, char **argv) {{
|
| 935 |
+
{funcname}();
|
| 936 |
+
return 0;
|
| 937 |
+
}}
|
| 938 |
+
"""
|
| 939 |
+
)
|
| 940 |
+
|
| 941 |
+
try:
|
| 942 |
+
objects = self.compile([fname], include_dirs=include_dirs)
|
| 943 |
+
except CompileError:
|
| 944 |
+
return False
|
| 945 |
+
finally:
|
| 946 |
+
os.remove(fname)
|
| 947 |
+
|
| 948 |
+
try:
|
| 949 |
+
self.link_executable(
|
| 950 |
+
objects, "a.out", libraries=libraries, library_dirs=library_dirs
|
| 951 |
+
)
|
| 952 |
+
except (LinkError, TypeError):
|
| 953 |
+
return False
|
| 954 |
+
else:
|
| 955 |
+
os.remove(
|
| 956 |
+
self.executable_filename("a.out", output_dir=self.output_dir or '')
|
| 957 |
+
)
|
| 958 |
+
finally:
|
| 959 |
+
for fn in objects:
|
| 960 |
+
os.remove(fn)
|
| 961 |
+
return True
|
| 962 |
+
|
| 963 |
+
def find_library_file(
|
| 964 |
+
self, dirs: Iterable[str], lib: str, debug: bool = False
|
| 965 |
+
) -> str | None:
|
| 966 |
+
"""Search the specified list of directories for a static or shared
|
| 967 |
+
library file 'lib' and return the full path to that file. If
|
| 968 |
+
'debug' true, look for a debugging version (if that makes sense on
|
| 969 |
+
the current platform). Return None if 'lib' wasn't found in any of
|
| 970 |
+
the specified directories.
|
| 971 |
+
"""
|
| 972 |
+
raise NotImplementedError
|
| 973 |
+
|
| 974 |
+
# -- Filename generation methods -----------------------------------
|
| 975 |
+
|
| 976 |
+
# The default implementation of the filename generating methods are
|
| 977 |
+
# prejudiced towards the Unix/DOS/Windows view of the world:
|
| 978 |
+
# * object files are named by replacing the source file extension
|
| 979 |
+
# (eg. .c/.cpp -> .o/.obj)
|
| 980 |
+
# * library files (shared or static) are named by plugging the
|
| 981 |
+
# library name and extension into a format string, eg.
|
| 982 |
+
# "lib%s.%s" % (lib_name, ".a") for Unix static libraries
|
| 983 |
+
# * executables are named by appending an extension (possibly
|
| 984 |
+
# empty) to the program name: eg. progname + ".exe" for
|
| 985 |
+
# Windows
|
| 986 |
+
#
|
| 987 |
+
# To reduce redundant code, these methods expect to find
|
| 988 |
+
# several attributes in the current object (presumably defined
|
| 989 |
+
# as class attributes):
|
| 990 |
+
# * src_extensions -
|
| 991 |
+
# list of C/C++ source file extensions, eg. ['.c', '.cpp']
|
| 992 |
+
# * obj_extension -
|
| 993 |
+
# object file extension, eg. '.o' or '.obj'
|
| 994 |
+
# * static_lib_extension -
|
| 995 |
+
# extension for static library files, eg. '.a' or '.lib'
|
| 996 |
+
# * shared_lib_extension -
|
| 997 |
+
# extension for shared library/object files, eg. '.so', '.dll'
|
| 998 |
+
# * static_lib_format -
|
| 999 |
+
# format string for generating static library filenames,
|
| 1000 |
+
# eg. 'lib%s.%s' or '%s.%s'
|
| 1001 |
+
# * shared_lib_format
|
| 1002 |
+
# format string for generating shared library filenames
|
| 1003 |
+
# (probably same as static_lib_format, since the extension
|
| 1004 |
+
# is one of the intended parameters to the format string)
|
| 1005 |
+
# * exe_extension -
|
| 1006 |
+
# extension for executable files, eg. '' or '.exe'
|
| 1007 |
+
|
| 1008 |
+
def object_filenames(
|
| 1009 |
+
self,
|
| 1010 |
+
source_filenames: Iterable[str | os.PathLike[str]],
|
| 1011 |
+
strip_dir: bool = False,
|
| 1012 |
+
output_dir: str | os.PathLike[str] | None = '',
|
| 1013 |
+
) -> list[str]:
|
| 1014 |
+
if output_dir is None:
|
| 1015 |
+
output_dir = ''
|
| 1016 |
+
return list(
|
| 1017 |
+
self._make_out_path(output_dir, strip_dir, src_name)
|
| 1018 |
+
for src_name in source_filenames
|
| 1019 |
+
)
|
| 1020 |
+
|
| 1021 |
+
@property
|
| 1022 |
+
def out_extensions(self):
|
| 1023 |
+
return dict.fromkeys(self.src_extensions, self.obj_extension)
|
| 1024 |
+
|
| 1025 |
+
def _make_out_path(self, output_dir, strip_dir, src_name):
|
| 1026 |
+
return self._make_out_path_exts(
|
| 1027 |
+
output_dir, strip_dir, src_name, self.out_extensions
|
| 1028 |
+
)
|
| 1029 |
+
|
| 1030 |
+
@classmethod
|
| 1031 |
+
def _make_out_path_exts(cls, output_dir, strip_dir, src_name, extensions):
|
| 1032 |
+
r"""
|
| 1033 |
+
>>> exts = {'.c': '.o'}
|
| 1034 |
+
>>> Compiler._make_out_path_exts('.', False, '/foo/bar.c', exts).replace('\\', '/')
|
| 1035 |
+
'./foo/bar.o'
|
| 1036 |
+
>>> Compiler._make_out_path_exts('.', True, '/foo/bar.c', exts).replace('\\', '/')
|
| 1037 |
+
'./bar.o'
|
| 1038 |
+
"""
|
| 1039 |
+
src = pathlib.PurePath(src_name)
|
| 1040 |
+
# Ensure base is relative to honor output_dir (python/cpython#37775).
|
| 1041 |
+
base = cls._make_relative(src)
|
| 1042 |
+
try:
|
| 1043 |
+
new_ext = extensions[src.suffix]
|
| 1044 |
+
except LookupError:
|
| 1045 |
+
raise UnknownFileType(f"unknown file type '{src.suffix}' (from '{src}')")
|
| 1046 |
+
if strip_dir:
|
| 1047 |
+
base = pathlib.PurePath(base.name)
|
| 1048 |
+
return os.path.join(output_dir, base.with_suffix(new_ext))
|
| 1049 |
+
|
| 1050 |
+
@staticmethod
|
| 1051 |
+
def _make_relative(base: pathlib.Path):
|
| 1052 |
+
return base.relative_to(base.anchor)
|
| 1053 |
+
|
| 1054 |
+
@overload
|
| 1055 |
+
def shared_object_filename(
|
| 1056 |
+
self,
|
| 1057 |
+
basename: str,
|
| 1058 |
+
strip_dir: Literal[False] = False,
|
| 1059 |
+
output_dir: str | os.PathLike[str] = "",
|
| 1060 |
+
) -> str: ...
|
| 1061 |
+
@overload
|
| 1062 |
+
def shared_object_filename(
|
| 1063 |
+
self,
|
| 1064 |
+
basename: str | os.PathLike[str],
|
| 1065 |
+
strip_dir: Literal[True],
|
| 1066 |
+
output_dir: str | os.PathLike[str] = "",
|
| 1067 |
+
) -> str: ...
|
| 1068 |
+
def shared_object_filename(
|
| 1069 |
+
self,
|
| 1070 |
+
basename: str | os.PathLike[str],
|
| 1071 |
+
strip_dir: bool = False,
|
| 1072 |
+
output_dir: str | os.PathLike[str] = '',
|
| 1073 |
+
) -> str:
|
| 1074 |
+
assert output_dir is not None
|
| 1075 |
+
if strip_dir:
|
| 1076 |
+
basename = os.path.basename(basename)
|
| 1077 |
+
return os.path.join(output_dir, basename + self.shared_lib_extension)
|
| 1078 |
+
|
| 1079 |
+
@overload
|
| 1080 |
+
def executable_filename(
|
| 1081 |
+
self,
|
| 1082 |
+
basename: str,
|
| 1083 |
+
strip_dir: Literal[False] = False,
|
| 1084 |
+
output_dir: str | os.PathLike[str] = "",
|
| 1085 |
+
) -> str: ...
|
| 1086 |
+
@overload
|
| 1087 |
+
def executable_filename(
|
| 1088 |
+
self,
|
| 1089 |
+
basename: str | os.PathLike[str],
|
| 1090 |
+
strip_dir: Literal[True],
|
| 1091 |
+
output_dir: str | os.PathLike[str] = "",
|
| 1092 |
+
) -> str: ...
|
| 1093 |
+
def executable_filename(
|
| 1094 |
+
self,
|
| 1095 |
+
basename: str | os.PathLike[str],
|
| 1096 |
+
strip_dir: bool = False,
|
| 1097 |
+
output_dir: str | os.PathLike[str] = '',
|
| 1098 |
+
) -> str:
|
| 1099 |
+
assert output_dir is not None
|
| 1100 |
+
if strip_dir:
|
| 1101 |
+
basename = os.path.basename(basename)
|
| 1102 |
+
return os.path.join(output_dir, basename + (self.exe_extension or ''))
|
| 1103 |
+
|
| 1104 |
+
def library_filename(
|
| 1105 |
+
self,
|
| 1106 |
+
libname: str,
|
| 1107 |
+
lib_type: str = "static",
|
| 1108 |
+
strip_dir: bool = False,
|
| 1109 |
+
output_dir: str | os.PathLike[str] = "", # or 'shared'
|
| 1110 |
+
):
|
| 1111 |
+
assert output_dir is not None
|
| 1112 |
+
expected = '"static", "shared", "dylib", "xcode_stub"'
|
| 1113 |
+
if lib_type not in eval(expected):
|
| 1114 |
+
raise ValueError(f"'lib_type' must be {expected}")
|
| 1115 |
+
fmt = getattr(self, lib_type + "_lib_format")
|
| 1116 |
+
ext = getattr(self, lib_type + "_lib_extension")
|
| 1117 |
+
|
| 1118 |
+
dir, base = os.path.split(libname)
|
| 1119 |
+
filename = fmt % (base, ext)
|
| 1120 |
+
if strip_dir:
|
| 1121 |
+
dir = ''
|
| 1122 |
+
|
| 1123 |
+
return os.path.join(output_dir, dir, filename)
|
| 1124 |
+
|
| 1125 |
+
# -- Utility methods -----------------------------------------------
|
| 1126 |
+
|
| 1127 |
+
def announce(self, msg: object, level: int = 1) -> None:
|
| 1128 |
+
log.debug(msg)
|
| 1129 |
+
|
| 1130 |
+
def debug_print(self, msg: object) -> None:
|
| 1131 |
+
from distutils.debug import DEBUG
|
| 1132 |
+
|
| 1133 |
+
if DEBUG:
|
| 1134 |
+
print(msg)
|
| 1135 |
+
|
| 1136 |
+
def warn(self, msg: object) -> None:
|
| 1137 |
+
sys.stderr.write(f"warning: {msg}\n")
|
| 1138 |
+
|
| 1139 |
+
def execute(
|
| 1140 |
+
self,
|
| 1141 |
+
func: Callable[[Unpack[_Ts]], object],
|
| 1142 |
+
args: tuple[Unpack[_Ts]],
|
| 1143 |
+
msg: object = None,
|
| 1144 |
+
level: int = 1,
|
| 1145 |
+
) -> None:
|
| 1146 |
+
execute(func, args, msg)
|
| 1147 |
+
|
| 1148 |
+
def spawn(
|
| 1149 |
+
self, cmd: MutableSequence[bytes | str | os.PathLike[str]], **kwargs
|
| 1150 |
+
) -> None:
|
| 1151 |
+
spawn(cmd, **kwargs)
|
| 1152 |
+
|
| 1153 |
+
@overload
|
| 1154 |
+
def move_file(
|
| 1155 |
+
self, src: str | os.PathLike[str], dst: _StrPathT
|
| 1156 |
+
) -> _StrPathT | str: ...
|
| 1157 |
+
@overload
|
| 1158 |
+
def move_file(
|
| 1159 |
+
self, src: bytes | os.PathLike[bytes], dst: _BytesPathT
|
| 1160 |
+
) -> _BytesPathT | bytes: ...
|
| 1161 |
+
def move_file(
|
| 1162 |
+
self,
|
| 1163 |
+
src: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 1164 |
+
dst: str | os.PathLike[str] | bytes | os.PathLike[bytes],
|
| 1165 |
+
) -> str | os.PathLike[str] | bytes | os.PathLike[bytes]:
|
| 1166 |
+
return move_file(src, dst)
|
| 1167 |
+
|
| 1168 |
+
def mkpath(self, name, mode=0o777):
|
| 1169 |
+
mkpath(name, mode)
|
| 1170 |
+
|
| 1171 |
+
|
| 1172 |
+
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
|
| 1173 |
+
# type for that platform. Keys are interpreted as re match
|
| 1174 |
+
# patterns. Order is important; platform mappings are preferred over
|
| 1175 |
+
# OS names.
|
| 1176 |
+
_default_compilers = (
|
| 1177 |
+
# Platform string mappings
|
| 1178 |
+
# on a cygwin built python we can use gcc like an ordinary UNIXish
|
| 1179 |
+
# compiler
|
| 1180 |
+
('cygwin.*', 'unix'),
|
| 1181 |
+
('zos', 'zos'),
|
| 1182 |
+
# OS name mappings
|
| 1183 |
+
('posix', 'unix'),
|
| 1184 |
+
('nt', 'msvc'),
|
| 1185 |
+
)
|
| 1186 |
+
|
| 1187 |
+
|
| 1188 |
+
def get_default_compiler(osname: str | None = None, platform: str | None = None) -> str:
|
| 1189 |
+
"""Determine the default compiler to use for the given platform.
|
| 1190 |
+
|
| 1191 |
+
osname should be one of the standard Python OS names (i.e. the
|
| 1192 |
+
ones returned by os.name) and platform the common value
|
| 1193 |
+
returned by sys.platform for the platform in question.
|
| 1194 |
+
|
| 1195 |
+
The default values are os.name and sys.platform in case the
|
| 1196 |
+
parameters are not given.
|
| 1197 |
+
"""
|
| 1198 |
+
if osname is None:
|
| 1199 |
+
osname = os.name
|
| 1200 |
+
if platform is None:
|
| 1201 |
+
platform = sys.platform
|
| 1202 |
+
# Mingw is a special case where sys.platform is 'win32' but we
|
| 1203 |
+
# want to use the 'mingw32' compiler, so check it first
|
| 1204 |
+
if is_mingw():
|
| 1205 |
+
return 'mingw32'
|
| 1206 |
+
for pattern, compiler in _default_compilers:
|
| 1207 |
+
if (
|
| 1208 |
+
re.match(pattern, platform) is not None
|
| 1209 |
+
or re.match(pattern, osname) is not None
|
| 1210 |
+
):
|
| 1211 |
+
return compiler
|
| 1212 |
+
# Default to Unix compiler
|
| 1213 |
+
return 'unix'
|
| 1214 |
+
|
| 1215 |
+
|
| 1216 |
+
# Map compiler types to (module_name, class_name) pairs -- ie. where to
|
| 1217 |
+
# find the code that implements an interface to this compiler. (The module
|
| 1218 |
+
# is assumed to be in the 'distutils' package.)
|
| 1219 |
+
compiler_class = {
|
| 1220 |
+
'unix': ('unixccompiler', 'UnixCCompiler', "standard UNIX-style compiler"),
|
| 1221 |
+
'msvc': ('_msvccompiler', 'MSVCCompiler', "Microsoft Visual C++"),
|
| 1222 |
+
'cygwin': (
|
| 1223 |
+
'cygwinccompiler',
|
| 1224 |
+
'CygwinCCompiler',
|
| 1225 |
+
"Cygwin port of GNU C Compiler for Win32",
|
| 1226 |
+
),
|
| 1227 |
+
'mingw32': (
|
| 1228 |
+
'cygwinccompiler',
|
| 1229 |
+
'Mingw32CCompiler',
|
| 1230 |
+
"Mingw32 port of GNU C Compiler for Win32",
|
| 1231 |
+
),
|
| 1232 |
+
'bcpp': ('bcppcompiler', 'BCPPCompiler', "Borland C++ Compiler"),
|
| 1233 |
+
'zos': ('zosccompiler', 'zOSCCompiler', 'IBM XL C/C++ Compilers'),
|
| 1234 |
+
}
|
| 1235 |
+
|
| 1236 |
+
|
| 1237 |
+
def show_compilers() -> None:
|
| 1238 |
+
"""Print list of available compilers (used by the "--help-compiler"
|
| 1239 |
+
options to "build", "build_ext", "build_clib").
|
| 1240 |
+
"""
|
| 1241 |
+
# XXX this "knows" that the compiler option it's describing is
|
| 1242 |
+
# "--compiler", which just happens to be the case for the three
|
| 1243 |
+
# commands that use it.
|
| 1244 |
+
from distutils.fancy_getopt import FancyGetopt
|
| 1245 |
+
|
| 1246 |
+
compilers = sorted(
|
| 1247 |
+
("compiler=" + compiler, None, compiler_class[compiler][2])
|
| 1248 |
+
for compiler in compiler_class.keys()
|
| 1249 |
+
)
|
| 1250 |
+
pretty_printer = FancyGetopt(compilers)
|
| 1251 |
+
pretty_printer.print_help("List of available compilers:")
|
| 1252 |
+
|
| 1253 |
+
|
| 1254 |
+
def new_compiler(
|
| 1255 |
+
plat: str | None = None,
|
| 1256 |
+
compiler: str | None = None,
|
| 1257 |
+
verbose: bool = False,
|
| 1258 |
+
force: bool = False,
|
| 1259 |
+
) -> Compiler:
|
| 1260 |
+
"""Generate an instance of some CCompiler subclass for the supplied
|
| 1261 |
+
platform/compiler combination. 'plat' defaults to 'os.name'
|
| 1262 |
+
(eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler
|
| 1263 |
+
for that platform. Currently only 'posix' and 'nt' are supported, and
|
| 1264 |
+
the default compilers are "traditional Unix interface" (UnixCCompiler
|
| 1265 |
+
class) and Visual C++ (MSVCCompiler class). Note that it's perfectly
|
| 1266 |
+
possible to ask for a Unix compiler object under Windows, and a
|
| 1267 |
+
Microsoft compiler object under Unix -- if you supply a value for
|
| 1268 |
+
'compiler', 'plat' is ignored.
|
| 1269 |
+
"""
|
| 1270 |
+
if plat is None:
|
| 1271 |
+
plat = os.name
|
| 1272 |
+
|
| 1273 |
+
try:
|
| 1274 |
+
if compiler is None:
|
| 1275 |
+
compiler = get_default_compiler(plat)
|
| 1276 |
+
|
| 1277 |
+
(module_name, class_name, long_description) = compiler_class[compiler]
|
| 1278 |
+
except KeyError:
|
| 1279 |
+
msg = f"don't know how to compile C/C++ code on platform '{plat}'"
|
| 1280 |
+
if compiler is not None:
|
| 1281 |
+
msg = msg + f" with '{compiler}' compiler"
|
| 1282 |
+
raise DistutilsPlatformError(msg)
|
| 1283 |
+
|
| 1284 |
+
try:
|
| 1285 |
+
module_name = "distutils." + module_name
|
| 1286 |
+
__import__(module_name)
|
| 1287 |
+
module = sys.modules[module_name]
|
| 1288 |
+
klass = vars(module)[class_name]
|
| 1289 |
+
except ImportError:
|
| 1290 |
+
raise DistutilsModuleError(
|
| 1291 |
+
f"can't compile C/C++ code: unable to load module '{module_name}'"
|
| 1292 |
+
)
|
| 1293 |
+
except KeyError:
|
| 1294 |
+
raise DistutilsModuleError(
|
| 1295 |
+
f"can't compile C/C++ code: unable to find class '{class_name}' "
|
| 1296 |
+
f"in module '{module_name}'"
|
| 1297 |
+
)
|
| 1298 |
+
|
| 1299 |
+
# XXX The None is necessary to preserve backwards compatibility
|
| 1300 |
+
# with classes that expect verbose to be the first positional
|
| 1301 |
+
# argument.
|
| 1302 |
+
return klass(None, force=force)
|
| 1303 |
+
|
| 1304 |
+
|
| 1305 |
+
def gen_preprocess_options(
|
| 1306 |
+
macros: Iterable[_Macro], include_dirs: Iterable[str]
|
| 1307 |
+
) -> list[str]:
|
| 1308 |
+
"""Generate C pre-processor options (-D, -U, -I) as used by at least
|
| 1309 |
+
two types of compilers: the typical Unix compiler and Visual C++.
|
| 1310 |
+
'macros' is the usual thing, a list of 1- or 2-tuples, where (name,)
|
| 1311 |
+
means undefine (-U) macro 'name', and (name,value) means define (-D)
|
| 1312 |
+
macro 'name' to 'value'. 'include_dirs' is just a list of directory
|
| 1313 |
+
names to be added to the header file search path (-I). Returns a list
|
| 1314 |
+
of command-line options suitable for either Unix compilers or Visual
|
| 1315 |
+
C++.
|
| 1316 |
+
"""
|
| 1317 |
+
# XXX it would be nice (mainly aesthetic, and so we don't generate
|
| 1318 |
+
# stupid-looking command lines) to go over 'macros' and eliminate
|
| 1319 |
+
# redundant definitions/undefinitions (ie. ensure that only the
|
| 1320 |
+
# latest mention of a particular macro winds up on the command
|
| 1321 |
+
# line). I don't think it's essential, though, since most (all?)
|
| 1322 |
+
# Unix C compilers only pay attention to the latest -D or -U
|
| 1323 |
+
# mention of a macro on their command line. Similar situation for
|
| 1324 |
+
# 'include_dirs'. I'm punting on both for now. Anyways, weeding out
|
| 1325 |
+
# redundancies like this should probably be the province of
|
| 1326 |
+
# CCompiler, since the data structures used are inherited from it
|
| 1327 |
+
# and therefore common to all CCompiler classes.
|
| 1328 |
+
pp_opts = []
|
| 1329 |
+
for macro in macros:
|
| 1330 |
+
if not (isinstance(macro, tuple) and 1 <= len(macro) <= 2):
|
| 1331 |
+
raise TypeError(
|
| 1332 |
+
f"bad macro definition '{macro}': "
|
| 1333 |
+
"each element of 'macros' list must be a 1- or 2-tuple"
|
| 1334 |
+
)
|
| 1335 |
+
|
| 1336 |
+
if len(macro) == 1: # undefine this macro
|
| 1337 |
+
pp_opts.append(f"-U{macro[0]}")
|
| 1338 |
+
elif len(macro) == 2:
|
| 1339 |
+
if macro[1] is None: # define with no explicit value
|
| 1340 |
+
pp_opts.append(f"-D{macro[0]}")
|
| 1341 |
+
else:
|
| 1342 |
+
# XXX *don't* need to be clever about quoting the
|
| 1343 |
+
# macro value here, because we're going to avoid the
|
| 1344 |
+
# shell at all costs when we spawn the command!
|
| 1345 |
+
pp_opts.append("-D{}={}".format(*macro))
|
| 1346 |
+
|
| 1347 |
+
pp_opts.extend(f"-I{dir}" for dir in include_dirs)
|
| 1348 |
+
return pp_opts
|
| 1349 |
+
|
| 1350 |
+
|
| 1351 |
+
def gen_lib_options(
|
| 1352 |
+
compiler: Compiler,
|
| 1353 |
+
library_dirs: Iterable[str],
|
| 1354 |
+
runtime_library_dirs: Iterable[str],
|
| 1355 |
+
libraries: Iterable[str],
|
| 1356 |
+
) -> list[str]:
|
| 1357 |
+
"""Generate linker options for searching library directories and
|
| 1358 |
+
linking with specific libraries. 'libraries' and 'library_dirs' are,
|
| 1359 |
+
respectively, lists of library names (not filenames!) and search
|
| 1360 |
+
directories. Returns a list of command-line options suitable for use
|
| 1361 |
+
with some compiler (depending on the two format strings passed in).
|
| 1362 |
+
"""
|
| 1363 |
+
lib_opts = [compiler.library_dir_option(dir) for dir in library_dirs]
|
| 1364 |
+
|
| 1365 |
+
for dir in runtime_library_dirs:
|
| 1366 |
+
lib_opts.extend(always_iterable(compiler.runtime_library_dir_option(dir)))
|
| 1367 |
+
|
| 1368 |
+
# XXX it's important that we *not* remove redundant library mentions!
|
| 1369 |
+
# sometimes you really do have to say "-lfoo -lbar -lfoo" in order to
|
| 1370 |
+
# resolve all symbols. I just hope we never have to say "-lfoo obj.o
|
| 1371 |
+
# -lbar" to get things to work -- that's certainly a possibility, but a
|
| 1372 |
+
# pretty nasty way to arrange your C code.
|
| 1373 |
+
|
| 1374 |
+
for lib in libraries:
|
| 1375 |
+
(lib_dir, lib_name) = os.path.split(lib)
|
| 1376 |
+
if lib_dir:
|
| 1377 |
+
lib_file = compiler.find_library_file([lib_dir], lib_name)
|
| 1378 |
+
if lib_file:
|
| 1379 |
+
lib_opts.append(lib_file)
|
| 1380 |
+
else:
|
| 1381 |
+
compiler.warn(
|
| 1382 |
+
f"no library file corresponding to '{lib}' found (skipping)"
|
| 1383 |
+
)
|
| 1384 |
+
else:
|
| 1385 |
+
lib_opts.append(compiler.library_option(lib))
|
| 1386 |
+
return lib_opts
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/cygwin.py
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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| 4 |
+
handles the Cygwin port of the GNU C compiler to Windows. It also contains
|
| 5 |
+
the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
|
| 6 |
+
cygwin in no-cygwin mode).
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import copy
|
| 10 |
+
import os
|
| 11 |
+
import pathlib
|
| 12 |
+
import shlex
|
| 13 |
+
import sys
|
| 14 |
+
import warnings
|
| 15 |
+
from subprocess import check_output
|
| 16 |
+
|
| 17 |
+
from ...errors import (
|
| 18 |
+
DistutilsExecError,
|
| 19 |
+
DistutilsPlatformError,
|
| 20 |
+
)
|
| 21 |
+
from ...file_util import write_file
|
| 22 |
+
from ...sysconfig import get_config_vars
|
| 23 |
+
from ...version import LooseVersion, suppress_known_deprecation
|
| 24 |
+
from . import unix
|
| 25 |
+
from .errors import (
|
| 26 |
+
CompileError,
|
| 27 |
+
Error,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def get_msvcr():
|
| 32 |
+
"""No longer needed, but kept for backward compatibility."""
|
| 33 |
+
return []
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
_runtime_library_dirs_msg = (
|
| 37 |
+
"Unable to set runtime library search path on Windows, "
|
| 38 |
+
"usually indicated by `runtime_library_dirs` parameter to Extension"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class Compiler(unix.Compiler):
|
| 43 |
+
"""Handles the Cygwin port of the GNU C compiler to Windows."""
|
| 44 |
+
|
| 45 |
+
compiler_type = 'cygwin'
|
| 46 |
+
obj_extension = ".o"
|
| 47 |
+
static_lib_extension = ".a"
|
| 48 |
+
shared_lib_extension = ".dll.a"
|
| 49 |
+
dylib_lib_extension = ".dll"
|
| 50 |
+
static_lib_format = "lib%s%s"
|
| 51 |
+
shared_lib_format = "lib%s%s"
|
| 52 |
+
dylib_lib_format = "cyg%s%s"
|
| 53 |
+
exe_extension = ".exe"
|
| 54 |
+
|
| 55 |
+
def __init__(self, verbose=False, force=False):
|
| 56 |
+
super().__init__(verbose, force=force)
|
| 57 |
+
|
| 58 |
+
status, details = check_config_h()
|
| 59 |
+
self.debug_print(f"Python's GCC status: {status} (details: {details})")
|
| 60 |
+
if status is not CONFIG_H_OK:
|
| 61 |
+
self.warn(
|
| 62 |
+
"Python's pyconfig.h doesn't seem to support your compiler. "
|
| 63 |
+
f"Reason: {details}. "
|
| 64 |
+
"Compiling may fail because of undefined preprocessor macros."
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
self.cc, self.cxx = get_config_vars('CC', 'CXX')
|
| 68 |
+
|
| 69 |
+
# Override 'CC' and 'CXX' environment variables for
|
| 70 |
+
# building using MINGW compiler for MSVC python.
|
| 71 |
+
self.cc = os.environ.get('CC', self.cc or 'gcc')
|
| 72 |
+
self.cxx = os.environ.get('CXX', self.cxx or 'g++')
|
| 73 |
+
|
| 74 |
+
self.linker_dll = self.cc
|
| 75 |
+
self.linker_dll_cxx = self.cxx
|
| 76 |
+
shared_option = "-shared"
|
| 77 |
+
|
| 78 |
+
self.set_executables(
|
| 79 |
+
compiler=f'{self.cc} -mcygwin -O -Wall',
|
| 80 |
+
compiler_so=f'{self.cc} -mcygwin -mdll -O -Wall',
|
| 81 |
+
compiler_cxx=f'{self.cxx} -mcygwin -O -Wall',
|
| 82 |
+
compiler_so_cxx=f'{self.cxx} -mcygwin -mdll -O -Wall',
|
| 83 |
+
linker_exe=f'{self.cc} -mcygwin',
|
| 84 |
+
linker_so=f'{self.linker_dll} -mcygwin {shared_option}',
|
| 85 |
+
linker_exe_cxx=f'{self.cxx} -mcygwin',
|
| 86 |
+
linker_so_cxx=f'{self.linker_dll_cxx} -mcygwin {shared_option}',
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
self.dll_libraries = get_msvcr()
|
| 90 |
+
|
| 91 |
+
@property
|
| 92 |
+
def gcc_version(self):
|
| 93 |
+
# Older numpy depended on this existing to check for ancient
|
| 94 |
+
# gcc versions. This doesn't make much sense with clang etc so
|
| 95 |
+
# just hardcode to something recent.
|
| 96 |
+
# https://github.com/numpy/numpy/pull/20333
|
| 97 |
+
warnings.warn(
|
| 98 |
+
"gcc_version attribute of CygwinCCompiler is deprecated. "
|
| 99 |
+
"Instead of returning actual gcc version a fixed value 11.2.0 is returned.",
|
| 100 |
+
DeprecationWarning,
|
| 101 |
+
stacklevel=2,
|
| 102 |
+
)
|
| 103 |
+
with suppress_known_deprecation():
|
| 104 |
+
return LooseVersion("11.2.0")
|
| 105 |
+
|
| 106 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 107 |
+
"""Compiles the source by spawning GCC and windres if needed."""
|
| 108 |
+
if ext in ('.rc', '.res'):
|
| 109 |
+
# gcc needs '.res' and '.rc' compiled to object files !!!
|
| 110 |
+
try:
|
| 111 |
+
self.spawn(["windres", "-i", src, "-o", obj])
|
| 112 |
+
except DistutilsExecError as msg:
|
| 113 |
+
raise CompileError(msg)
|
| 114 |
+
else: # for other files use the C-compiler
|
| 115 |
+
try:
|
| 116 |
+
if self.detect_language(src) == 'c++':
|
| 117 |
+
self.spawn(
|
| 118 |
+
self.compiler_so_cxx
|
| 119 |
+
+ cc_args
|
| 120 |
+
+ [src, '-o', obj]
|
| 121 |
+
+ extra_postargs
|
| 122 |
+
)
|
| 123 |
+
else:
|
| 124 |
+
self.spawn(
|
| 125 |
+
self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs
|
| 126 |
+
)
|
| 127 |
+
except DistutilsExecError as msg:
|
| 128 |
+
raise CompileError(msg)
|
| 129 |
+
|
| 130 |
+
def link(
|
| 131 |
+
self,
|
| 132 |
+
target_desc,
|
| 133 |
+
objects,
|
| 134 |
+
output_filename,
|
| 135 |
+
output_dir=None,
|
| 136 |
+
libraries=None,
|
| 137 |
+
library_dirs=None,
|
| 138 |
+
runtime_library_dirs=None,
|
| 139 |
+
export_symbols=None,
|
| 140 |
+
debug=False,
|
| 141 |
+
extra_preargs=None,
|
| 142 |
+
extra_postargs=None,
|
| 143 |
+
build_temp=None,
|
| 144 |
+
target_lang=None,
|
| 145 |
+
):
|
| 146 |
+
"""Link the objects."""
|
| 147 |
+
# use separate copies, so we can modify the lists
|
| 148 |
+
extra_preargs = copy.copy(extra_preargs or [])
|
| 149 |
+
libraries = copy.copy(libraries or [])
|
| 150 |
+
objects = copy.copy(objects or [])
|
| 151 |
+
|
| 152 |
+
if runtime_library_dirs:
|
| 153 |
+
self.warn(_runtime_library_dirs_msg)
|
| 154 |
+
|
| 155 |
+
# Additional libraries
|
| 156 |
+
libraries.extend(self.dll_libraries)
|
| 157 |
+
|
| 158 |
+
# handle export symbols by creating a def-file
|
| 159 |
+
# with executables this only works with gcc/ld as linker
|
| 160 |
+
if (export_symbols is not None) and (
|
| 161 |
+
target_desc != self.EXECUTABLE or self.linker_dll == "gcc"
|
| 162 |
+
):
|
| 163 |
+
# (The linker doesn't do anything if output is up-to-date.
|
| 164 |
+
# So it would probably better to check if we really need this,
|
| 165 |
+
# but for this we had to insert some unchanged parts of
|
| 166 |
+
# UnixCCompiler, and this is not what we want.)
|
| 167 |
+
|
| 168 |
+
# we want to put some files in the same directory as the
|
| 169 |
+
# object files are, build_temp doesn't help much
|
| 170 |
+
# where are the object files
|
| 171 |
+
temp_dir = os.path.dirname(objects[0])
|
| 172 |
+
# name of dll to give the helper files the same base name
|
| 173 |
+
(dll_name, dll_extension) = os.path.splitext(
|
| 174 |
+
os.path.basename(output_filename)
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
# generate the filenames for these files
|
| 178 |
+
def_file = os.path.join(temp_dir, dll_name + ".def")
|
| 179 |
+
|
| 180 |
+
# Generate .def file
|
| 181 |
+
contents = [f"LIBRARY {os.path.basename(output_filename)}", "EXPORTS"]
|
| 182 |
+
contents.extend(export_symbols)
|
| 183 |
+
self.execute(write_file, (def_file, contents), f"writing {def_file}")
|
| 184 |
+
|
| 185 |
+
# next add options for def-file
|
| 186 |
+
|
| 187 |
+
# for gcc/ld the def-file is specified as any object files
|
| 188 |
+
objects.append(def_file)
|
| 189 |
+
|
| 190 |
+
# end: if ((export_symbols is not None) and
|
| 191 |
+
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
| 192 |
+
|
| 193 |
+
# who wants symbols and a many times larger output file
|
| 194 |
+
# should explicitly switch the debug mode on
|
| 195 |
+
# otherwise we let ld strip the output file
|
| 196 |
+
# (On my machine: 10KiB < stripped_file < ??100KiB
|
| 197 |
+
# unstripped_file = stripped_file + XXX KiB
|
| 198 |
+
# ( XXX=254 for a typical python extension))
|
| 199 |
+
if not debug:
|
| 200 |
+
extra_preargs.append("-s")
|
| 201 |
+
|
| 202 |
+
super().link(
|
| 203 |
+
target_desc,
|
| 204 |
+
objects,
|
| 205 |
+
output_filename,
|
| 206 |
+
output_dir,
|
| 207 |
+
libraries,
|
| 208 |
+
library_dirs,
|
| 209 |
+
runtime_library_dirs,
|
| 210 |
+
None, # export_symbols, we do this in our def-file
|
| 211 |
+
debug,
|
| 212 |
+
extra_preargs,
|
| 213 |
+
extra_postargs,
|
| 214 |
+
build_temp,
|
| 215 |
+
target_lang,
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
def runtime_library_dir_option(self, dir):
|
| 219 |
+
# cygwin doesn't support rpath. While in theory we could error
|
| 220 |
+
# out like MSVC does, code might expect it to work like on Unix, so
|
| 221 |
+
# just warn and hope for the best.
|
| 222 |
+
self.warn(_runtime_library_dirs_msg)
|
| 223 |
+
return []
|
| 224 |
+
|
| 225 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 226 |
+
|
| 227 |
+
def _make_out_path(self, output_dir, strip_dir, src_name):
|
| 228 |
+
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
| 229 |
+
norm_src_name = os.path.normcase(src_name)
|
| 230 |
+
return super()._make_out_path(output_dir, strip_dir, norm_src_name)
|
| 231 |
+
|
| 232 |
+
@property
|
| 233 |
+
def out_extensions(self):
|
| 234 |
+
"""
|
| 235 |
+
Add support for rc and res files.
|
| 236 |
+
"""
|
| 237 |
+
return {
|
| 238 |
+
**super().out_extensions,
|
| 239 |
+
**{ext: ext + self.obj_extension for ext in ('.res', '.rc')},
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
# the same as cygwin plus some additional parameters
|
| 244 |
+
class MinGW32Compiler(Compiler):
|
| 245 |
+
"""Handles the Mingw32 port of the GNU C compiler to Windows."""
|
| 246 |
+
|
| 247 |
+
compiler_type = 'mingw32'
|
| 248 |
+
|
| 249 |
+
def __init__(self, verbose=False, force=False):
|
| 250 |
+
super().__init__(verbose, force)
|
| 251 |
+
|
| 252 |
+
shared_option = "-shared"
|
| 253 |
+
|
| 254 |
+
if is_cygwincc(self.cc):
|
| 255 |
+
raise Error('Cygwin gcc cannot be used with --compiler=mingw32')
|
| 256 |
+
|
| 257 |
+
self.set_executables(
|
| 258 |
+
compiler=f'{self.cc} -O -Wall',
|
| 259 |
+
compiler_so=f'{self.cc} -shared -O -Wall',
|
| 260 |
+
compiler_so_cxx=f'{self.cxx} -shared -O -Wall',
|
| 261 |
+
compiler_cxx=f'{self.cxx} -O -Wall',
|
| 262 |
+
linker_exe=f'{self.cc}',
|
| 263 |
+
linker_so=f'{self.linker_dll} {shared_option}',
|
| 264 |
+
linker_exe_cxx=f'{self.cxx}',
|
| 265 |
+
linker_so_cxx=f'{self.linker_dll_cxx} {shared_option}',
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
def runtime_library_dir_option(self, dir):
|
| 269 |
+
raise DistutilsPlatformError(_runtime_library_dirs_msg)
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
# Because these compilers aren't configured in Python's pyconfig.h file by
|
| 273 |
+
# default, we should at least warn the user if he is using an unmodified
|
| 274 |
+
# version.
|
| 275 |
+
|
| 276 |
+
CONFIG_H_OK = "ok"
|
| 277 |
+
CONFIG_H_NOTOK = "not ok"
|
| 278 |
+
CONFIG_H_UNCERTAIN = "uncertain"
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def check_config_h():
|
| 282 |
+
"""Check if the current Python installation appears amenable to building
|
| 283 |
+
extensions with GCC.
|
| 284 |
+
|
| 285 |
+
Returns a tuple (status, details), where 'status' is one of the following
|
| 286 |
+
constants:
|
| 287 |
+
|
| 288 |
+
- CONFIG_H_OK: all is well, go ahead and compile
|
| 289 |
+
- CONFIG_H_NOTOK: doesn't look good
|
| 290 |
+
- CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h
|
| 291 |
+
|
| 292 |
+
'details' is a human-readable string explaining the situation.
|
| 293 |
+
|
| 294 |
+
Note there are two ways to conclude "OK": either 'sys.version' contains
|
| 295 |
+
the string "GCC" (implying that this Python was built with GCC), or the
|
| 296 |
+
installed "pyconfig.h" contains the string "__GNUC__".
|
| 297 |
+
"""
|
| 298 |
+
|
| 299 |
+
# XXX since this function also checks sys.version, it's not strictly a
|
| 300 |
+
# "pyconfig.h" check -- should probably be renamed...
|
| 301 |
+
|
| 302 |
+
from distutils import sysconfig
|
| 303 |
+
|
| 304 |
+
# if sys.version contains GCC then python was compiled with GCC, and the
|
| 305 |
+
# pyconfig.h file should be OK
|
| 306 |
+
if "GCC" in sys.version:
|
| 307 |
+
return CONFIG_H_OK, "sys.version mentions 'GCC'"
|
| 308 |
+
|
| 309 |
+
# Clang would also work
|
| 310 |
+
if "Clang" in sys.version:
|
| 311 |
+
return CONFIG_H_OK, "sys.version mentions 'Clang'"
|
| 312 |
+
|
| 313 |
+
# let's see if __GNUC__ is mentioned in python.h
|
| 314 |
+
fn = sysconfig.get_config_h_filename()
|
| 315 |
+
try:
|
| 316 |
+
config_h = pathlib.Path(fn).read_text(encoding='utf-8')
|
| 317 |
+
except OSError as exc:
|
| 318 |
+
return (CONFIG_H_UNCERTAIN, f"couldn't read '{fn}': {exc.strerror}")
|
| 319 |
+
else:
|
| 320 |
+
substring = '__GNUC__'
|
| 321 |
+
if substring in config_h:
|
| 322 |
+
code = CONFIG_H_OK
|
| 323 |
+
mention_inflected = 'mentions'
|
| 324 |
+
else:
|
| 325 |
+
code = CONFIG_H_NOTOK
|
| 326 |
+
mention_inflected = 'does not mention'
|
| 327 |
+
return code, f"{fn!r} {mention_inflected} {substring!r}"
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
def is_cygwincc(cc):
|
| 331 |
+
"""Try to determine if the compiler that would be used is from cygwin."""
|
| 332 |
+
out_string = check_output(shlex.split(cc) + ['-dumpmachine'])
|
| 333 |
+
return out_string.strip().endswith(b'cygwin')
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
get_versions = None
|
| 337 |
+
"""
|
| 338 |
+
A stand-in for the previous get_versions() function to prevent failures
|
| 339 |
+
when monkeypatched. See pypa/setuptools#2969.
|
| 340 |
+
"""
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/errors.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Error(Exception):
|
| 2 |
+
"""Some compile/link operation failed."""
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class PreprocessError(Error):
|
| 6 |
+
"""Failure to preprocess one or more C/C++ files."""
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class CompileError(Error):
|
| 10 |
+
"""Failure to compile one or more C/C++ source files."""
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class LibError(Error):
|
| 14 |
+
"""Failure to create a static library from one or more C/C++ object
|
| 15 |
+
files."""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class LinkError(Error):
|
| 19 |
+
"""Failure to link one or more C/C++ object files into an executable
|
| 20 |
+
or shared library file."""
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class UnknownFileType(Error):
|
| 24 |
+
"""Attempt to process an unknown file type."""
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils._msvccompiler
|
| 2 |
+
|
| 3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
| 4 |
+
for Microsoft Visual Studio 2015.
|
| 5 |
+
|
| 6 |
+
This module requires VS 2015 or later.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
# Written by Perry Stoll
|
| 10 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
| 11 |
+
# finding DevStudio (through the registry)
|
| 12 |
+
# ported to VS 2005 and VS 2008 by Christian Heimes
|
| 13 |
+
# ported to VS 2015 by Steve Dower
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import contextlib
|
| 17 |
+
import os
|
| 18 |
+
import subprocess
|
| 19 |
+
import unittest.mock as mock
|
| 20 |
+
import warnings
|
| 21 |
+
from collections.abc import Iterable
|
| 22 |
+
|
| 23 |
+
with contextlib.suppress(ImportError):
|
| 24 |
+
import winreg
|
| 25 |
+
|
| 26 |
+
from itertools import count
|
| 27 |
+
|
| 28 |
+
from ..._log import log
|
| 29 |
+
from ...errors import (
|
| 30 |
+
DistutilsExecError,
|
| 31 |
+
DistutilsPlatformError,
|
| 32 |
+
)
|
| 33 |
+
from ...util import get_host_platform, get_platform
|
| 34 |
+
from . import base
|
| 35 |
+
from .base import gen_lib_options
|
| 36 |
+
from .errors import (
|
| 37 |
+
CompileError,
|
| 38 |
+
LibError,
|
| 39 |
+
LinkError,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _find_vc2015():
|
| 44 |
+
try:
|
| 45 |
+
key = winreg.OpenKeyEx(
|
| 46 |
+
winreg.HKEY_LOCAL_MACHINE,
|
| 47 |
+
r"Software\Microsoft\VisualStudio\SxS\VC7",
|
| 48 |
+
access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY,
|
| 49 |
+
)
|
| 50 |
+
except OSError:
|
| 51 |
+
log.debug("Visual C++ is not registered")
|
| 52 |
+
return None, None
|
| 53 |
+
|
| 54 |
+
best_version = 0
|
| 55 |
+
best_dir = None
|
| 56 |
+
with key:
|
| 57 |
+
for i in count():
|
| 58 |
+
try:
|
| 59 |
+
v, vc_dir, vt = winreg.EnumValue(key, i)
|
| 60 |
+
except OSError:
|
| 61 |
+
break
|
| 62 |
+
if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
|
| 63 |
+
try:
|
| 64 |
+
version = int(float(v))
|
| 65 |
+
except (ValueError, TypeError):
|
| 66 |
+
continue
|
| 67 |
+
if version >= 14 and version > best_version:
|
| 68 |
+
best_version, best_dir = version, vc_dir
|
| 69 |
+
return best_version, best_dir
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _find_vc2017():
|
| 73 |
+
"""Returns "15, path" based on the result of invoking vswhere.exe
|
| 74 |
+
If no install is found, returns "None, None"
|
| 75 |
+
|
| 76 |
+
The version is returned to avoid unnecessarily changing the function
|
| 77 |
+
result. It may be ignored when the path is not None.
|
| 78 |
+
|
| 79 |
+
If vswhere.exe is not available, by definition, VS 2017 is not
|
| 80 |
+
installed.
|
| 81 |
+
"""
|
| 82 |
+
root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
|
| 83 |
+
if not root:
|
| 84 |
+
return None, None
|
| 85 |
+
|
| 86 |
+
variant = 'arm64' if get_platform() == 'win-arm64' else 'x86.x64'
|
| 87 |
+
suitable_components = (
|
| 88 |
+
f"Microsoft.VisualStudio.Component.VC.Tools.{variant}",
|
| 89 |
+
"Microsoft.VisualStudio.Workload.WDExpress",
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
for component in suitable_components:
|
| 93 |
+
# Workaround for `-requiresAny` (only available on VS 2017 > 15.6)
|
| 94 |
+
with contextlib.suppress(
|
| 95 |
+
subprocess.CalledProcessError, OSError, UnicodeDecodeError
|
| 96 |
+
):
|
| 97 |
+
path = (
|
| 98 |
+
subprocess.check_output([
|
| 99 |
+
os.path.join(
|
| 100 |
+
root, "Microsoft Visual Studio", "Installer", "vswhere.exe"
|
| 101 |
+
),
|
| 102 |
+
"-latest",
|
| 103 |
+
"-prerelease",
|
| 104 |
+
"-requires",
|
| 105 |
+
component,
|
| 106 |
+
"-property",
|
| 107 |
+
"installationPath",
|
| 108 |
+
"-products",
|
| 109 |
+
"*",
|
| 110 |
+
])
|
| 111 |
+
.decode(encoding="mbcs", errors="strict")
|
| 112 |
+
.strip()
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
path = os.path.join(path, "VC", "Auxiliary", "Build")
|
| 116 |
+
if os.path.isdir(path):
|
| 117 |
+
return 15, path
|
| 118 |
+
|
| 119 |
+
return None, None # no suitable component found
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
PLAT_SPEC_TO_RUNTIME = {
|
| 123 |
+
'x86': 'x86',
|
| 124 |
+
'x86_amd64': 'x64',
|
| 125 |
+
'x86_arm': 'arm',
|
| 126 |
+
'x86_arm64': 'arm64',
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def _find_vcvarsall(plat_spec):
|
| 131 |
+
# bpo-38597: Removed vcruntime return value
|
| 132 |
+
_, best_dir = _find_vc2017()
|
| 133 |
+
|
| 134 |
+
if not best_dir:
|
| 135 |
+
best_version, best_dir = _find_vc2015()
|
| 136 |
+
|
| 137 |
+
if not best_dir:
|
| 138 |
+
log.debug("No suitable Visual C++ version found")
|
| 139 |
+
return None, None
|
| 140 |
+
|
| 141 |
+
vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
|
| 142 |
+
if not os.path.isfile(vcvarsall):
|
| 143 |
+
log.debug("%s cannot be found", vcvarsall)
|
| 144 |
+
return None, None
|
| 145 |
+
|
| 146 |
+
return vcvarsall, None
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def _get_vc_env(plat_spec):
|
| 150 |
+
if os.getenv("DISTUTILS_USE_SDK"):
|
| 151 |
+
return {key.lower(): value for key, value in os.environ.items()}
|
| 152 |
+
|
| 153 |
+
vcvarsall, _ = _find_vcvarsall(plat_spec)
|
| 154 |
+
if not vcvarsall:
|
| 155 |
+
raise DistutilsPlatformError(
|
| 156 |
+
'Microsoft Visual C++ 14.0 or greater is required. '
|
| 157 |
+
'Get it with "Microsoft C++ Build Tools": '
|
| 158 |
+
'https://visualstudio.microsoft.com/visual-cpp-build-tools/'
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
try:
|
| 162 |
+
out = subprocess.check_output(
|
| 163 |
+
f'cmd /u /c "{vcvarsall}" {plat_spec} && set',
|
| 164 |
+
stderr=subprocess.STDOUT,
|
| 165 |
+
).decode('utf-16le', errors='replace')
|
| 166 |
+
except subprocess.CalledProcessError as exc:
|
| 167 |
+
log.error(exc.output)
|
| 168 |
+
raise DistutilsPlatformError(f"Error executing {exc.cmd}")
|
| 169 |
+
|
| 170 |
+
env = {
|
| 171 |
+
key.lower(): value
|
| 172 |
+
for key, _, value in (line.partition('=') for line in out.splitlines())
|
| 173 |
+
if key and value
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
return env
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def _find_exe(exe, paths=None):
|
| 180 |
+
"""Return path to an MSVC executable program.
|
| 181 |
+
|
| 182 |
+
Tries to find the program in several places: first, one of the
|
| 183 |
+
MSVC program search paths from the registry; next, the directories
|
| 184 |
+
in the PATH environment variable. If any of those work, return an
|
| 185 |
+
absolute path that is known to exist. If none of them work, just
|
| 186 |
+
return the original program name, 'exe'.
|
| 187 |
+
"""
|
| 188 |
+
if not paths:
|
| 189 |
+
paths = os.getenv('path').split(os.pathsep)
|
| 190 |
+
for p in paths:
|
| 191 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
| 192 |
+
if os.path.isfile(fn):
|
| 193 |
+
return fn
|
| 194 |
+
return exe
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
_vcvars_names = {
|
| 198 |
+
'win32': 'x86',
|
| 199 |
+
'win-amd64': 'amd64',
|
| 200 |
+
'win-arm32': 'arm',
|
| 201 |
+
'win-arm64': 'arm64',
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def _get_vcvars_spec(host_platform, platform):
|
| 206 |
+
"""
|
| 207 |
+
Given a host platform and platform, determine the spec for vcvarsall.
|
| 208 |
+
|
| 209 |
+
Uses the native MSVC host if the host platform would need expensive
|
| 210 |
+
emulation for x86.
|
| 211 |
+
|
| 212 |
+
>>> _get_vcvars_spec('win-arm64', 'win32')
|
| 213 |
+
'arm64_x86'
|
| 214 |
+
>>> _get_vcvars_spec('win-arm64', 'win-amd64')
|
| 215 |
+
'arm64_amd64'
|
| 216 |
+
|
| 217 |
+
Otherwise, always cross-compile from x86 to work with the
|
| 218 |
+
lighter-weight MSVC installs that do not include native 64-bit tools.
|
| 219 |
+
|
| 220 |
+
>>> _get_vcvars_spec('win32', 'win32')
|
| 221 |
+
'x86'
|
| 222 |
+
>>> _get_vcvars_spec('win-arm32', 'win-arm32')
|
| 223 |
+
'x86_arm'
|
| 224 |
+
>>> _get_vcvars_spec('win-amd64', 'win-arm64')
|
| 225 |
+
'x86_arm64'
|
| 226 |
+
"""
|
| 227 |
+
if host_platform != 'win-arm64':
|
| 228 |
+
host_platform = 'win32'
|
| 229 |
+
vc_hp = _vcvars_names[host_platform]
|
| 230 |
+
vc_plat = _vcvars_names[platform]
|
| 231 |
+
return vc_hp if vc_hp == vc_plat else f'{vc_hp}_{vc_plat}'
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
class Compiler(base.Compiler):
|
| 235 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
| 236 |
+
as defined by the CCompiler abstract class."""
|
| 237 |
+
|
| 238 |
+
compiler_type = 'msvc'
|
| 239 |
+
|
| 240 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
| 241 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
| 242 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
| 243 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
| 244 |
+
# though, so it's worth thinking about.
|
| 245 |
+
executables = {}
|
| 246 |
+
|
| 247 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
| 248 |
+
_c_extensions = ['.c']
|
| 249 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
| 250 |
+
_rc_extensions = ['.rc']
|
| 251 |
+
_mc_extensions = ['.mc']
|
| 252 |
+
|
| 253 |
+
# Needed for the filename generation methods provided by the
|
| 254 |
+
# base class, CCompiler.
|
| 255 |
+
src_extensions = _c_extensions + _cpp_extensions + _rc_extensions + _mc_extensions
|
| 256 |
+
res_extension = '.res'
|
| 257 |
+
obj_extension = '.obj'
|
| 258 |
+
static_lib_extension = '.lib'
|
| 259 |
+
shared_lib_extension = '.dll'
|
| 260 |
+
static_lib_format = shared_lib_format = '%s%s'
|
| 261 |
+
exe_extension = '.exe'
|
| 262 |
+
|
| 263 |
+
def __init__(self, verbose=False, force=False) -> None:
|
| 264 |
+
super().__init__(verbose, force=force)
|
| 265 |
+
# target platform (.plat_name is consistent with 'bdist')
|
| 266 |
+
self.plat_name = None
|
| 267 |
+
self.initialized = False
|
| 268 |
+
|
| 269 |
+
@classmethod
|
| 270 |
+
def _configure(cls, vc_env):
|
| 271 |
+
"""
|
| 272 |
+
Set class-level include/lib dirs.
|
| 273 |
+
"""
|
| 274 |
+
cls.include_dirs = cls._parse_path(vc_env.get('include', ''))
|
| 275 |
+
cls.library_dirs = cls._parse_path(vc_env.get('lib', ''))
|
| 276 |
+
|
| 277 |
+
@staticmethod
|
| 278 |
+
def _parse_path(val):
|
| 279 |
+
return [dir.rstrip(os.sep) for dir in val.split(os.pathsep) if dir]
|
| 280 |
+
|
| 281 |
+
def initialize(self, plat_name: str | None = None) -> None:
|
| 282 |
+
# multi-init means we would need to check platform same each time...
|
| 283 |
+
assert not self.initialized, "don't init multiple times"
|
| 284 |
+
if plat_name is None:
|
| 285 |
+
plat_name = get_platform()
|
| 286 |
+
# sanity check for platforms to prevent obscure errors later.
|
| 287 |
+
if plat_name not in _vcvars_names:
|
| 288 |
+
raise DistutilsPlatformError(
|
| 289 |
+
f"--plat-name must be one of {tuple(_vcvars_names)}"
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
plat_spec = _get_vcvars_spec(get_host_platform(), plat_name)
|
| 293 |
+
|
| 294 |
+
vc_env = _get_vc_env(plat_spec)
|
| 295 |
+
if not vc_env:
|
| 296 |
+
raise DistutilsPlatformError(
|
| 297 |
+
"Unable to find a compatible Visual Studio installation."
|
| 298 |
+
)
|
| 299 |
+
self._configure(vc_env)
|
| 300 |
+
|
| 301 |
+
self._paths = vc_env.get('path', '')
|
| 302 |
+
paths = self._paths.split(os.pathsep)
|
| 303 |
+
self.cc = _find_exe("cl.exe", paths)
|
| 304 |
+
self.linker = _find_exe("link.exe", paths)
|
| 305 |
+
self.lib = _find_exe("lib.exe", paths)
|
| 306 |
+
self.rc = _find_exe("rc.exe", paths) # resource compiler
|
| 307 |
+
self.mc = _find_exe("mc.exe", paths) # message compiler
|
| 308 |
+
self.mt = _find_exe("mt.exe", paths) # message compiler
|
| 309 |
+
|
| 310 |
+
self.preprocess_options = None
|
| 311 |
+
# bpo-38597: Always compile with dynamic linking
|
| 312 |
+
# Future releases of Python 3.x will include all past
|
| 313 |
+
# versions of vcruntime*.dll for compatibility.
|
| 314 |
+
self.compile_options = ['/nologo', '/O2', '/W3', '/GL', '/DNDEBUG', '/MD']
|
| 315 |
+
|
| 316 |
+
self.compile_options_debug = [
|
| 317 |
+
'/nologo',
|
| 318 |
+
'/Od',
|
| 319 |
+
'/MDd',
|
| 320 |
+
'/Zi',
|
| 321 |
+
'/W3',
|
| 322 |
+
'/D_DEBUG',
|
| 323 |
+
]
|
| 324 |
+
|
| 325 |
+
ldflags = ['/nologo', '/INCREMENTAL:NO', '/LTCG']
|
| 326 |
+
|
| 327 |
+
ldflags_debug = ['/nologo', '/INCREMENTAL:NO', '/LTCG', '/DEBUG:FULL']
|
| 328 |
+
|
| 329 |
+
self.ldflags_exe = [*ldflags, '/MANIFEST:EMBED,ID=1']
|
| 330 |
+
self.ldflags_exe_debug = [*ldflags_debug, '/MANIFEST:EMBED,ID=1']
|
| 331 |
+
self.ldflags_shared = [
|
| 332 |
+
*ldflags,
|
| 333 |
+
'/DLL',
|
| 334 |
+
'/MANIFEST:EMBED,ID=2',
|
| 335 |
+
'/MANIFESTUAC:NO',
|
| 336 |
+
]
|
| 337 |
+
self.ldflags_shared_debug = [
|
| 338 |
+
*ldflags_debug,
|
| 339 |
+
'/DLL',
|
| 340 |
+
'/MANIFEST:EMBED,ID=2',
|
| 341 |
+
'/MANIFESTUAC:NO',
|
| 342 |
+
]
|
| 343 |
+
self.ldflags_static = [*ldflags]
|
| 344 |
+
self.ldflags_static_debug = [*ldflags_debug]
|
| 345 |
+
|
| 346 |
+
self._ldflags = {
|
| 347 |
+
(base.Compiler.EXECUTABLE, None): self.ldflags_exe,
|
| 348 |
+
(base.Compiler.EXECUTABLE, False): self.ldflags_exe,
|
| 349 |
+
(base.Compiler.EXECUTABLE, True): self.ldflags_exe_debug,
|
| 350 |
+
(base.Compiler.SHARED_OBJECT, None): self.ldflags_shared,
|
| 351 |
+
(base.Compiler.SHARED_OBJECT, False): self.ldflags_shared,
|
| 352 |
+
(base.Compiler.SHARED_OBJECT, True): self.ldflags_shared_debug,
|
| 353 |
+
(base.Compiler.SHARED_LIBRARY, None): self.ldflags_static,
|
| 354 |
+
(base.Compiler.SHARED_LIBRARY, False): self.ldflags_static,
|
| 355 |
+
(base.Compiler.SHARED_LIBRARY, True): self.ldflags_static_debug,
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
self.initialized = True
|
| 359 |
+
|
| 360 |
+
# -- Worker methods ------------------------------------------------
|
| 361 |
+
|
| 362 |
+
@property
|
| 363 |
+
def out_extensions(self) -> dict[str, str]:
|
| 364 |
+
return {
|
| 365 |
+
**super().out_extensions,
|
| 366 |
+
**{
|
| 367 |
+
ext: self.res_extension
|
| 368 |
+
for ext in self._rc_extensions + self._mc_extensions
|
| 369 |
+
},
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
def compile( # noqa: C901
|
| 373 |
+
self,
|
| 374 |
+
sources,
|
| 375 |
+
output_dir=None,
|
| 376 |
+
macros=None,
|
| 377 |
+
include_dirs=None,
|
| 378 |
+
debug=False,
|
| 379 |
+
extra_preargs=None,
|
| 380 |
+
extra_postargs=None,
|
| 381 |
+
depends=None,
|
| 382 |
+
):
|
| 383 |
+
if not self.initialized:
|
| 384 |
+
self.initialize()
|
| 385 |
+
compile_info = self._setup_compile(
|
| 386 |
+
output_dir, macros, include_dirs, sources, depends, extra_postargs
|
| 387 |
+
)
|
| 388 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
| 389 |
+
|
| 390 |
+
compile_opts = extra_preargs or []
|
| 391 |
+
compile_opts.append('/c')
|
| 392 |
+
if debug:
|
| 393 |
+
compile_opts.extend(self.compile_options_debug)
|
| 394 |
+
else:
|
| 395 |
+
compile_opts.extend(self.compile_options)
|
| 396 |
+
|
| 397 |
+
add_cpp_opts = False
|
| 398 |
+
|
| 399 |
+
for obj in objects:
|
| 400 |
+
try:
|
| 401 |
+
src, ext = build[obj]
|
| 402 |
+
except KeyError:
|
| 403 |
+
continue
|
| 404 |
+
if debug:
|
| 405 |
+
# pass the full pathname to MSVC in debug mode,
|
| 406 |
+
# this allows the debugger to find the source file
|
| 407 |
+
# without asking the user to browse for it
|
| 408 |
+
src = os.path.abspath(src)
|
| 409 |
+
|
| 410 |
+
if ext in self._c_extensions:
|
| 411 |
+
input_opt = f"/Tc{src}"
|
| 412 |
+
elif ext in self._cpp_extensions:
|
| 413 |
+
input_opt = f"/Tp{src}"
|
| 414 |
+
add_cpp_opts = True
|
| 415 |
+
elif ext in self._rc_extensions:
|
| 416 |
+
# compile .RC to .RES file
|
| 417 |
+
input_opt = src
|
| 418 |
+
output_opt = "/fo" + obj
|
| 419 |
+
try:
|
| 420 |
+
self.spawn([self.rc] + pp_opts + [output_opt, input_opt])
|
| 421 |
+
except DistutilsExecError as msg:
|
| 422 |
+
raise CompileError(msg)
|
| 423 |
+
continue
|
| 424 |
+
elif ext in self._mc_extensions:
|
| 425 |
+
# Compile .MC to .RC file to .RES file.
|
| 426 |
+
# * '-h dir' specifies the directory for the
|
| 427 |
+
# generated include file
|
| 428 |
+
# * '-r dir' specifies the target directory of the
|
| 429 |
+
# generated RC file and the binary message resource
|
| 430 |
+
# it includes
|
| 431 |
+
#
|
| 432 |
+
# For now (since there are no options to change this),
|
| 433 |
+
# we use the source-directory for the include file and
|
| 434 |
+
# the build directory for the RC file and message
|
| 435 |
+
# resources. This works at least for win32all.
|
| 436 |
+
h_dir = os.path.dirname(src)
|
| 437 |
+
rc_dir = os.path.dirname(obj)
|
| 438 |
+
try:
|
| 439 |
+
# first compile .MC to .RC and .H file
|
| 440 |
+
self.spawn([self.mc, '-h', h_dir, '-r', rc_dir, src])
|
| 441 |
+
base, _ = os.path.splitext(os.path.basename(src))
|
| 442 |
+
rc_file = os.path.join(rc_dir, base + '.rc')
|
| 443 |
+
# then compile .RC to .RES file
|
| 444 |
+
self.spawn([self.rc, "/fo" + obj, rc_file])
|
| 445 |
+
|
| 446 |
+
except DistutilsExecError as msg:
|
| 447 |
+
raise CompileError(msg)
|
| 448 |
+
continue
|
| 449 |
+
else:
|
| 450 |
+
# how to handle this file?
|
| 451 |
+
raise CompileError(f"Don't know how to compile {src} to {obj}")
|
| 452 |
+
|
| 453 |
+
args = [self.cc] + compile_opts + pp_opts
|
| 454 |
+
if add_cpp_opts:
|
| 455 |
+
args.append('/EHsc')
|
| 456 |
+
args.extend((input_opt, "/Fo" + obj))
|
| 457 |
+
args.extend(extra_postargs)
|
| 458 |
+
|
| 459 |
+
try:
|
| 460 |
+
self.spawn(args)
|
| 461 |
+
except DistutilsExecError as msg:
|
| 462 |
+
raise CompileError(msg)
|
| 463 |
+
|
| 464 |
+
return objects
|
| 465 |
+
|
| 466 |
+
def create_static_lib(
|
| 467 |
+
self,
|
| 468 |
+
objects: list[str] | tuple[str, ...],
|
| 469 |
+
output_libname: str,
|
| 470 |
+
output_dir: str | None = None,
|
| 471 |
+
debug: bool = False,
|
| 472 |
+
target_lang: str | None = None,
|
| 473 |
+
) -> None:
|
| 474 |
+
if not self.initialized:
|
| 475 |
+
self.initialize()
|
| 476 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 477 |
+
output_filename = self.library_filename(output_libname, output_dir=output_dir)
|
| 478 |
+
|
| 479 |
+
if self._need_link(objects, output_filename):
|
| 480 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
| 481 |
+
if debug:
|
| 482 |
+
pass # XXX what goes here?
|
| 483 |
+
try:
|
| 484 |
+
log.debug('Executing "%s" %s', self.lib, ' '.join(lib_args))
|
| 485 |
+
self.spawn([self.lib] + lib_args)
|
| 486 |
+
except DistutilsExecError as msg:
|
| 487 |
+
raise LibError(msg)
|
| 488 |
+
else:
|
| 489 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 490 |
+
|
| 491 |
+
def link(
|
| 492 |
+
self,
|
| 493 |
+
target_desc: str,
|
| 494 |
+
objects: list[str] | tuple[str, ...],
|
| 495 |
+
output_filename: str,
|
| 496 |
+
output_dir: str | None = None,
|
| 497 |
+
libraries: list[str] | tuple[str, ...] | None = None,
|
| 498 |
+
library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 499 |
+
runtime_library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 500 |
+
export_symbols: Iterable[str] | None = None,
|
| 501 |
+
debug: bool = False,
|
| 502 |
+
extra_preargs: list[str] | None = None,
|
| 503 |
+
extra_postargs: Iterable[str] | None = None,
|
| 504 |
+
build_temp: str | os.PathLike[str] | None = None,
|
| 505 |
+
target_lang: str | None = None,
|
| 506 |
+
) -> None:
|
| 507 |
+
if not self.initialized:
|
| 508 |
+
self.initialize()
|
| 509 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 510 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
|
| 511 |
+
libraries, library_dirs, runtime_library_dirs = fixed_args
|
| 512 |
+
|
| 513 |
+
if runtime_library_dirs:
|
| 514 |
+
self.warn(
|
| 515 |
+
"I don't know what to do with 'runtime_library_dirs': "
|
| 516 |
+
+ str(runtime_library_dirs)
|
| 517 |
+
)
|
| 518 |
+
|
| 519 |
+
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries)
|
| 520 |
+
if output_dir is not None:
|
| 521 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 522 |
+
|
| 523 |
+
if self._need_link(objects, output_filename):
|
| 524 |
+
ldflags = self._ldflags[target_desc, debug]
|
| 525 |
+
|
| 526 |
+
export_opts = ["/EXPORT:" + sym for sym in (export_symbols or [])]
|
| 527 |
+
|
| 528 |
+
ld_args = (
|
| 529 |
+
ldflags + lib_opts + export_opts + objects + ['/OUT:' + output_filename]
|
| 530 |
+
)
|
| 531 |
+
|
| 532 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
| 533 |
+
# suppressed by any linker switches. The .lib files may even be
|
| 534 |
+
# needed! Make sure they are generated in the temporary build
|
| 535 |
+
# directory. Since they have different names for debug and release
|
| 536 |
+
# builds, they can go into the same directory.
|
| 537 |
+
build_temp = os.path.dirname(objects[0])
|
| 538 |
+
if export_symbols is not None:
|
| 539 |
+
(dll_name, dll_ext) = os.path.splitext(
|
| 540 |
+
os.path.basename(output_filename)
|
| 541 |
+
)
|
| 542 |
+
implib_file = os.path.join(build_temp, self.library_filename(dll_name))
|
| 543 |
+
ld_args.append('/IMPLIB:' + implib_file)
|
| 544 |
+
|
| 545 |
+
if extra_preargs:
|
| 546 |
+
ld_args[:0] = extra_preargs
|
| 547 |
+
if extra_postargs:
|
| 548 |
+
ld_args.extend(extra_postargs)
|
| 549 |
+
|
| 550 |
+
output_dir = os.path.dirname(os.path.abspath(output_filename))
|
| 551 |
+
self.mkpath(output_dir)
|
| 552 |
+
try:
|
| 553 |
+
log.debug('Executing "%s" %s', self.linker, ' '.join(ld_args))
|
| 554 |
+
self.spawn([self.linker] + ld_args)
|
| 555 |
+
except DistutilsExecError as msg:
|
| 556 |
+
raise LinkError(msg)
|
| 557 |
+
else:
|
| 558 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 559 |
+
|
| 560 |
+
def spawn(self, cmd):
|
| 561 |
+
env = dict(os.environ, PATH=self._paths)
|
| 562 |
+
with self._fallback_spawn(cmd, env) as fallback:
|
| 563 |
+
return super().spawn(cmd, env=env)
|
| 564 |
+
return fallback.value
|
| 565 |
+
|
| 566 |
+
@contextlib.contextmanager
|
| 567 |
+
def _fallback_spawn(self, cmd, env):
|
| 568 |
+
"""
|
| 569 |
+
Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
|
| 570 |
+
so the 'env' kwarg causes a TypeError. Detect this condition and
|
| 571 |
+
restore the legacy, unsafe behavior.
|
| 572 |
+
"""
|
| 573 |
+
bag = type('Bag', (), {})()
|
| 574 |
+
try:
|
| 575 |
+
yield bag
|
| 576 |
+
except TypeError as exc:
|
| 577 |
+
if "unexpected keyword argument 'env'" not in str(exc):
|
| 578 |
+
raise
|
| 579 |
+
else:
|
| 580 |
+
return
|
| 581 |
+
warnings.warn("Fallback spawn triggered. Please update distutils monkeypatch.")
|
| 582 |
+
with mock.patch.dict('os.environ', env):
|
| 583 |
+
bag.value = super().spawn(cmd)
|
| 584 |
+
|
| 585 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 586 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 587 |
+
# ccompiler.py.
|
| 588 |
+
|
| 589 |
+
def library_dir_option(self, dir):
|
| 590 |
+
return "/LIBPATH:" + dir
|
| 591 |
+
|
| 592 |
+
def runtime_library_dir_option(self, dir):
|
| 593 |
+
raise DistutilsPlatformError(
|
| 594 |
+
"don't know how to set runtime library search path for MSVC"
|
| 595 |
+
)
|
| 596 |
+
|
| 597 |
+
def library_option(self, lib):
|
| 598 |
+
return self.library_filename(lib)
|
| 599 |
+
|
| 600 |
+
def find_library_file(self, dirs, lib, debug=False):
|
| 601 |
+
# Prefer a debugging library if found (and requested), but deal
|
| 602 |
+
# with it if we don't have one.
|
| 603 |
+
if debug:
|
| 604 |
+
try_names = [lib + "_d", lib]
|
| 605 |
+
else:
|
| 606 |
+
try_names = [lib]
|
| 607 |
+
for dir in dirs:
|
| 608 |
+
for name in try_names:
|
| 609 |
+
libfile = os.path.join(dir, self.library_filename(name))
|
| 610 |
+
if os.path.isfile(libfile):
|
| 611 |
+
return libfile
|
| 612 |
+
else:
|
| 613 |
+
# Oops, didn't find it in *any* of 'dirs'
|
| 614 |
+
return None
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_base.cpython-313.pyc
ADDED
|
Binary file (4.06 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_cygwin.cpython-313.pyc
ADDED
|
Binary file (4.64 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_mingw.cpython-313.pyc
ADDED
|
Binary file (3.97 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_msvc.cpython-313.pyc
ADDED
|
Binary file (7.62 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/__pycache__/test_unix.cpython-313.pyc
ADDED
|
Binary file (19.2 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_base.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import platform
|
| 2 |
+
import sysconfig
|
| 3 |
+
import textwrap
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from .. import base
|
| 8 |
+
|
| 9 |
+
pytestmark = pytest.mark.usefixtures('suppress_path_mangle')
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@pytest.fixture
|
| 13 |
+
def c_file(tmp_path):
|
| 14 |
+
c_file = tmp_path / 'foo.c'
|
| 15 |
+
gen_headers = ('Python.h',)
|
| 16 |
+
is_windows = platform.system() == "Windows"
|
| 17 |
+
plat_headers = ('windows.h',) * is_windows
|
| 18 |
+
all_headers = gen_headers + plat_headers
|
| 19 |
+
headers = '\n'.join(f'#include <{header}>\n' for header in all_headers)
|
| 20 |
+
payload = (
|
| 21 |
+
textwrap.dedent(
|
| 22 |
+
"""
|
| 23 |
+
#headers
|
| 24 |
+
void PyInit_foo(void) {}
|
| 25 |
+
"""
|
| 26 |
+
)
|
| 27 |
+
.lstrip()
|
| 28 |
+
.replace('#headers', headers)
|
| 29 |
+
)
|
| 30 |
+
c_file.write_text(payload, encoding='utf-8')
|
| 31 |
+
return c_file
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def test_set_include_dirs(c_file):
|
| 35 |
+
"""
|
| 36 |
+
Extensions should build even if set_include_dirs is invoked.
|
| 37 |
+
In particular, compiler-specific paths should not be overridden.
|
| 38 |
+
"""
|
| 39 |
+
compiler = base.new_compiler()
|
| 40 |
+
python = sysconfig.get_paths()['include']
|
| 41 |
+
compiler.set_include_dirs([python])
|
| 42 |
+
compiler.compile([c_file])
|
| 43 |
+
|
| 44 |
+
# do it again, setting include dirs after any initialization
|
| 45 |
+
compiler.set_include_dirs([python])
|
| 46 |
+
compiler.compile([c_file])
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def test_has_function_prototype():
|
| 50 |
+
# Issue https://github.com/pypa/setuptools/issues/3648
|
| 51 |
+
# Test prototype-generating behavior.
|
| 52 |
+
|
| 53 |
+
compiler = base.new_compiler()
|
| 54 |
+
|
| 55 |
+
# Every C implementation should have these.
|
| 56 |
+
assert compiler.has_function('abort')
|
| 57 |
+
assert compiler.has_function('exit')
|
| 58 |
+
with pytest.deprecated_call(match='includes is deprecated'):
|
| 59 |
+
# abort() is a valid expression with the <stdlib.h> prototype.
|
| 60 |
+
assert compiler.has_function('abort', includes=['stdlib.h'])
|
| 61 |
+
with pytest.deprecated_call(match='includes is deprecated'):
|
| 62 |
+
# But exit() is not valid with the actual prototype in scope.
|
| 63 |
+
assert not compiler.has_function('exit', includes=['stdlib.h'])
|
| 64 |
+
# And setuptools_does_not_exist is not declared or defined at all.
|
| 65 |
+
assert not compiler.has_function('setuptools_does_not_exist')
|
| 66 |
+
with pytest.deprecated_call(match='includes is deprecated'):
|
| 67 |
+
assert not compiler.has_function(
|
| 68 |
+
'setuptools_does_not_exist', includes=['stdio.h']
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def test_include_dirs_after_multiple_compile_calls(c_file):
|
| 73 |
+
"""
|
| 74 |
+
Calling compile multiple times should not change the include dirs
|
| 75 |
+
(regression test for setuptools issue #3591).
|
| 76 |
+
"""
|
| 77 |
+
compiler = base.new_compiler()
|
| 78 |
+
python = sysconfig.get_paths()['include']
|
| 79 |
+
compiler.set_include_dirs([python])
|
| 80 |
+
compiler.compile([c_file])
|
| 81 |
+
assert compiler.include_dirs == [python]
|
| 82 |
+
compiler.compile([c_file])
|
| 83 |
+
assert compiler.include_dirs == [python]
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_cygwin.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.cygwinccompiler."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from distutils import sysconfig
|
| 6 |
+
from distutils.tests import support
|
| 7 |
+
|
| 8 |
+
import pytest
|
| 9 |
+
|
| 10 |
+
from .. import cygwin
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@pytest.fixture(autouse=True)
|
| 14 |
+
def stuff(request, monkeypatch, distutils_managed_tempdir):
|
| 15 |
+
self = request.instance
|
| 16 |
+
self.python_h = os.path.join(self.mkdtemp(), 'python.h')
|
| 17 |
+
monkeypatch.setattr(sysconfig, 'get_config_h_filename', self._get_config_h_filename)
|
| 18 |
+
monkeypatch.setattr(sys, 'version', sys.version)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class TestCygwinCCompiler(support.TempdirManager):
|
| 22 |
+
def _get_config_h_filename(self):
|
| 23 |
+
return self.python_h
|
| 24 |
+
|
| 25 |
+
@pytest.mark.skipif('sys.platform != "cygwin"')
|
| 26 |
+
@pytest.mark.skipif('not os.path.exists("/usr/lib/libbash.dll.a")')
|
| 27 |
+
def test_find_library_file(self):
|
| 28 |
+
from distutils.cygwinccompiler import CygwinCCompiler
|
| 29 |
+
|
| 30 |
+
compiler = CygwinCCompiler()
|
| 31 |
+
link_name = "bash"
|
| 32 |
+
linkable_file = compiler.find_library_file(["/usr/lib"], link_name)
|
| 33 |
+
assert linkable_file is not None
|
| 34 |
+
assert os.path.exists(linkable_file)
|
| 35 |
+
assert linkable_file == f"/usr/lib/lib{link_name:s}.dll.a"
|
| 36 |
+
|
| 37 |
+
@pytest.mark.skipif('sys.platform != "cygwin"')
|
| 38 |
+
def test_runtime_library_dir_option(self):
|
| 39 |
+
from distutils.cygwinccompiler import CygwinCCompiler
|
| 40 |
+
|
| 41 |
+
compiler = CygwinCCompiler()
|
| 42 |
+
assert compiler.runtime_library_dir_option('/foo') == []
|
| 43 |
+
|
| 44 |
+
def test_check_config_h(self):
|
| 45 |
+
# check_config_h looks for "GCC" in sys.version first
|
| 46 |
+
# returns CONFIG_H_OK if found
|
| 47 |
+
sys.version = (
|
| 48 |
+
'2.6.1 (r261:67515, Dec 6 2008, 16:42:21) \n[GCC '
|
| 49 |
+
'4.0.1 (Apple Computer, Inc. build 5370)]'
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
assert cygwin.check_config_h()[0] == cygwin.CONFIG_H_OK
|
| 53 |
+
|
| 54 |
+
# then it tries to see if it can find "__GNUC__" in pyconfig.h
|
| 55 |
+
sys.version = 'something without the *CC word'
|
| 56 |
+
|
| 57 |
+
# if the file doesn't exist it returns CONFIG_H_UNCERTAIN
|
| 58 |
+
assert cygwin.check_config_h()[0] == cygwin.CONFIG_H_UNCERTAIN
|
| 59 |
+
|
| 60 |
+
# if it exists but does not contain __GNUC__, it returns CONFIG_H_NOTOK
|
| 61 |
+
self.write_file(self.python_h, 'xxx')
|
| 62 |
+
assert cygwin.check_config_h()[0] == cygwin.CONFIG_H_NOTOK
|
| 63 |
+
|
| 64 |
+
# and CONFIG_H_OK if __GNUC__ is found
|
| 65 |
+
self.write_file(self.python_h, 'xxx __GNUC__ xxx')
|
| 66 |
+
assert cygwin.check_config_h()[0] == cygwin.CONFIG_H_OK
|
| 67 |
+
|
| 68 |
+
def test_get_msvcr(self):
|
| 69 |
+
assert cygwin.get_msvcr() == []
|
| 70 |
+
|
| 71 |
+
@pytest.mark.skipif('sys.platform != "cygwin"')
|
| 72 |
+
def test_dll_libraries_not_none(self):
|
| 73 |
+
from distutils.cygwinccompiler import CygwinCCompiler
|
| 74 |
+
|
| 75 |
+
compiler = CygwinCCompiler()
|
| 76 |
+
assert compiler.dll_libraries is not None
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_mingw.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from distutils import sysconfig
|
| 2 |
+
from distutils.errors import DistutilsPlatformError
|
| 3 |
+
from distutils.util import is_mingw, split_quoted
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
from .. import cygwin, errors
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class TestMinGW32Compiler:
|
| 11 |
+
@pytest.mark.skipif(not is_mingw(), reason='not on mingw')
|
| 12 |
+
def test_compiler_type(self):
|
| 13 |
+
compiler = cygwin.MinGW32Compiler()
|
| 14 |
+
assert compiler.compiler_type == 'mingw32'
|
| 15 |
+
|
| 16 |
+
@pytest.mark.skipif(not is_mingw(), reason='not on mingw')
|
| 17 |
+
def test_set_executables(self, monkeypatch):
|
| 18 |
+
monkeypatch.setenv('CC', 'cc')
|
| 19 |
+
monkeypatch.setenv('CXX', 'c++')
|
| 20 |
+
|
| 21 |
+
compiler = cygwin.MinGW32Compiler()
|
| 22 |
+
|
| 23 |
+
assert compiler.compiler == split_quoted('cc -O -Wall')
|
| 24 |
+
assert compiler.compiler_so == split_quoted('cc -shared -O -Wall')
|
| 25 |
+
assert compiler.compiler_cxx == split_quoted('c++ -O -Wall')
|
| 26 |
+
assert compiler.linker_exe == split_quoted('cc')
|
| 27 |
+
assert compiler.linker_so == split_quoted('cc -shared')
|
| 28 |
+
|
| 29 |
+
@pytest.mark.skipif(not is_mingw(), reason='not on mingw')
|
| 30 |
+
def test_runtime_library_dir_option(self):
|
| 31 |
+
compiler = cygwin.MinGW32Compiler()
|
| 32 |
+
with pytest.raises(DistutilsPlatformError):
|
| 33 |
+
compiler.runtime_library_dir_option('/usr/lib')
|
| 34 |
+
|
| 35 |
+
@pytest.mark.skipif(not is_mingw(), reason='not on mingw')
|
| 36 |
+
def test_cygwincc_error(self, monkeypatch):
|
| 37 |
+
monkeypatch.setattr(cygwin, 'is_cygwincc', lambda _: True)
|
| 38 |
+
|
| 39 |
+
with pytest.raises(errors.Error):
|
| 40 |
+
cygwin.MinGW32Compiler()
|
| 41 |
+
|
| 42 |
+
@pytest.mark.skipif('sys.platform == "cygwin"')
|
| 43 |
+
def test_customize_compiler_with_msvc_python(self):
|
| 44 |
+
# In case we have an MSVC Python build, but still want to use
|
| 45 |
+
# MinGW32Compiler, then customize_compiler() shouldn't fail at least.
|
| 46 |
+
# https://github.com/pypa/setuptools/issues/4456
|
| 47 |
+
compiler = cygwin.MinGW32Compiler()
|
| 48 |
+
sysconfig.customize_compiler(compiler)
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_msvc.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import sysconfig
|
| 4 |
+
import threading
|
| 5 |
+
import unittest.mock as mock
|
| 6 |
+
from distutils.errors import DistutilsPlatformError
|
| 7 |
+
from distutils.tests import support
|
| 8 |
+
from distutils.util import get_platform
|
| 9 |
+
|
| 10 |
+
import pytest
|
| 11 |
+
|
| 12 |
+
from .. import msvc
|
| 13 |
+
|
| 14 |
+
needs_winreg = pytest.mark.skipif('not hasattr(msvc, "winreg")')
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class Testmsvccompiler(support.TempdirManager):
|
| 18 |
+
def test_no_compiler(self, monkeypatch):
|
| 19 |
+
# makes sure query_vcvarsall raises
|
| 20 |
+
# a DistutilsPlatformError if the compiler
|
| 21 |
+
# is not found
|
| 22 |
+
def _find_vcvarsall(plat_spec):
|
| 23 |
+
return None, None
|
| 24 |
+
|
| 25 |
+
monkeypatch.setattr(msvc, '_find_vcvarsall', _find_vcvarsall)
|
| 26 |
+
|
| 27 |
+
with pytest.raises(DistutilsPlatformError):
|
| 28 |
+
msvc._get_vc_env(
|
| 29 |
+
'wont find this version',
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
@pytest.mark.skipif(
|
| 33 |
+
not sysconfig.get_platform().startswith("win"),
|
| 34 |
+
reason="Only run test for non-mingw Windows platforms",
|
| 35 |
+
)
|
| 36 |
+
@pytest.mark.parametrize(
|
| 37 |
+
"plat_name, expected",
|
| 38 |
+
[
|
| 39 |
+
("win-arm64", "win-arm64"),
|
| 40 |
+
("win-amd64", "win-amd64"),
|
| 41 |
+
(None, get_platform()),
|
| 42 |
+
],
|
| 43 |
+
)
|
| 44 |
+
def test_cross_platform_compilation_paths(self, monkeypatch, plat_name, expected):
|
| 45 |
+
"""
|
| 46 |
+
Ensure a specified target platform is passed to _get_vcvars_spec.
|
| 47 |
+
"""
|
| 48 |
+
compiler = msvc.Compiler()
|
| 49 |
+
|
| 50 |
+
def _get_vcvars_spec(host_platform, platform):
|
| 51 |
+
assert platform == expected
|
| 52 |
+
|
| 53 |
+
monkeypatch.setattr(msvc, '_get_vcvars_spec', _get_vcvars_spec)
|
| 54 |
+
compiler.initialize(plat_name)
|
| 55 |
+
|
| 56 |
+
@needs_winreg
|
| 57 |
+
def test_get_vc_env_unicode(self):
|
| 58 |
+
test_var = 'ṰḖṤṪ┅ṼẨṜ'
|
| 59 |
+
test_value = '₃⁴₅'
|
| 60 |
+
|
| 61 |
+
# Ensure we don't early exit from _get_vc_env
|
| 62 |
+
old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None)
|
| 63 |
+
os.environ[test_var] = test_value
|
| 64 |
+
try:
|
| 65 |
+
env = msvc._get_vc_env('x86')
|
| 66 |
+
assert test_var.lower() in env
|
| 67 |
+
assert test_value == env[test_var.lower()]
|
| 68 |
+
finally:
|
| 69 |
+
os.environ.pop(test_var)
|
| 70 |
+
if old_distutils_use_sdk:
|
| 71 |
+
os.environ['DISTUTILS_USE_SDK'] = old_distutils_use_sdk
|
| 72 |
+
|
| 73 |
+
@needs_winreg
|
| 74 |
+
@pytest.mark.parametrize('ver', (2015, 2017))
|
| 75 |
+
def test_get_vc(self, ver):
|
| 76 |
+
# This function cannot be mocked, so pass if VC is found
|
| 77 |
+
# and skip otherwise.
|
| 78 |
+
lookup = getattr(msvc, f'_find_vc{ver}')
|
| 79 |
+
expected_version = {2015: 14, 2017: 15}[ver]
|
| 80 |
+
version, path = lookup()
|
| 81 |
+
if not version:
|
| 82 |
+
pytest.skip(f"VS {ver} is not installed")
|
| 83 |
+
assert version >= expected_version
|
| 84 |
+
assert os.path.isdir(path)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class CheckThread(threading.Thread):
|
| 88 |
+
exc_info = None
|
| 89 |
+
|
| 90 |
+
def run(self):
|
| 91 |
+
try:
|
| 92 |
+
super().run()
|
| 93 |
+
except Exception:
|
| 94 |
+
self.exc_info = sys.exc_info()
|
| 95 |
+
|
| 96 |
+
def __bool__(self):
|
| 97 |
+
return not self.exc_info
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class TestSpawn:
|
| 101 |
+
def test_concurrent_safe(self):
|
| 102 |
+
"""
|
| 103 |
+
Concurrent calls to spawn should have consistent results.
|
| 104 |
+
"""
|
| 105 |
+
compiler = msvc.Compiler()
|
| 106 |
+
compiler._paths = "expected"
|
| 107 |
+
inner_cmd = 'import os; assert os.environ["PATH"] == "expected"'
|
| 108 |
+
command = [sys.executable, '-c', inner_cmd]
|
| 109 |
+
|
| 110 |
+
threads = [
|
| 111 |
+
CheckThread(target=compiler.spawn, args=[command]) for n in range(100)
|
| 112 |
+
]
|
| 113 |
+
for thread in threads:
|
| 114 |
+
thread.start()
|
| 115 |
+
for thread in threads:
|
| 116 |
+
thread.join()
|
| 117 |
+
assert all(threads)
|
| 118 |
+
|
| 119 |
+
def test_concurrent_safe_fallback(self):
|
| 120 |
+
"""
|
| 121 |
+
If CCompiler.spawn has been monkey-patched without support
|
| 122 |
+
for an env, it should still execute.
|
| 123 |
+
"""
|
| 124 |
+
from distutils import ccompiler
|
| 125 |
+
|
| 126 |
+
compiler = msvc.Compiler()
|
| 127 |
+
compiler._paths = "expected"
|
| 128 |
+
|
| 129 |
+
def CCompiler_spawn(self, cmd):
|
| 130 |
+
"A spawn without an env argument."
|
| 131 |
+
assert os.environ["PATH"] == "expected"
|
| 132 |
+
|
| 133 |
+
with mock.patch.object(ccompiler.CCompiler, 'spawn', CCompiler_spawn):
|
| 134 |
+
compiler.spawn(["n/a"])
|
| 135 |
+
|
| 136 |
+
assert os.environ.get("PATH") != "expected"
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/tests/test_unix.py
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for distutils.unixccompiler."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import unittest.mock as mock
|
| 6 |
+
from distutils import sysconfig
|
| 7 |
+
from distutils.compat import consolidate_linker_args
|
| 8 |
+
from distutils.errors import DistutilsPlatformError
|
| 9 |
+
from distutils.tests import support
|
| 10 |
+
from distutils.tests.compat.py39 import EnvironmentVarGuard
|
| 11 |
+
from distutils.util import _clear_cached_macosx_ver
|
| 12 |
+
|
| 13 |
+
import pytest
|
| 14 |
+
|
| 15 |
+
from .. import unix
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@pytest.fixture(autouse=True)
|
| 19 |
+
def save_values(monkeypatch):
|
| 20 |
+
monkeypatch.setattr(sys, 'platform', sys.platform)
|
| 21 |
+
monkeypatch.setattr(sysconfig, 'get_config_var', sysconfig.get_config_var)
|
| 22 |
+
monkeypatch.setattr(sysconfig, 'get_config_vars', sysconfig.get_config_vars)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@pytest.fixture(autouse=True)
|
| 26 |
+
def compiler_wrapper(request):
|
| 27 |
+
class CompilerWrapper(unix.Compiler):
|
| 28 |
+
def rpath_foo(self):
|
| 29 |
+
return self.runtime_library_dir_option('/foo')
|
| 30 |
+
|
| 31 |
+
request.instance.cc = CompilerWrapper()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class TestUnixCCompiler(support.TempdirManager):
|
| 35 |
+
@pytest.mark.skipif('platform.system == "Windows"')
|
| 36 |
+
def test_runtime_libdir_option(self): # noqa: C901
|
| 37 |
+
# Issue #5900; GitHub Issue #37
|
| 38 |
+
#
|
| 39 |
+
# Ensure RUNPATH is added to extension modules with RPATH if
|
| 40 |
+
# GNU ld is used
|
| 41 |
+
|
| 42 |
+
# darwin
|
| 43 |
+
sys.platform = 'darwin'
|
| 44 |
+
darwin_ver_var = 'MACOSX_DEPLOYMENT_TARGET'
|
| 45 |
+
darwin_rpath_flag = '-Wl,-rpath,/foo'
|
| 46 |
+
darwin_lib_flag = '-L/foo'
|
| 47 |
+
|
| 48 |
+
# (macOS version from syscfg, macOS version from env var) -> flag
|
| 49 |
+
# Version value of None generates two tests: as None and as empty string
|
| 50 |
+
# Expected flag value of None means an mismatch exception is expected
|
| 51 |
+
darwin_test_cases = [
|
| 52 |
+
((None, None), darwin_lib_flag),
|
| 53 |
+
((None, '11'), darwin_rpath_flag),
|
| 54 |
+
(('10', None), darwin_lib_flag),
|
| 55 |
+
(('10.3', None), darwin_lib_flag),
|
| 56 |
+
(('10.3.1', None), darwin_lib_flag),
|
| 57 |
+
(('10.5', None), darwin_rpath_flag),
|
| 58 |
+
(('10.5.1', None), darwin_rpath_flag),
|
| 59 |
+
(('10.3', '10.3'), darwin_lib_flag),
|
| 60 |
+
(('10.3', '10.5'), darwin_rpath_flag),
|
| 61 |
+
(('10.5', '10.3'), darwin_lib_flag),
|
| 62 |
+
(('10.5', '11'), darwin_rpath_flag),
|
| 63 |
+
(('10.4', '10'), None),
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
+
def make_darwin_gcv(syscfg_macosx_ver):
|
| 67 |
+
def gcv(var):
|
| 68 |
+
if var == darwin_ver_var:
|
| 69 |
+
return syscfg_macosx_ver
|
| 70 |
+
return "xxx"
|
| 71 |
+
|
| 72 |
+
return gcv
|
| 73 |
+
|
| 74 |
+
def do_darwin_test(syscfg_macosx_ver, env_macosx_ver, expected_flag):
|
| 75 |
+
env = os.environ
|
| 76 |
+
msg = f"macOS version = (sysconfig={syscfg_macosx_ver!r}, env={env_macosx_ver!r})"
|
| 77 |
+
|
| 78 |
+
# Save
|
| 79 |
+
old_gcv = sysconfig.get_config_var
|
| 80 |
+
old_env_macosx_ver = env.get(darwin_ver_var)
|
| 81 |
+
|
| 82 |
+
# Setup environment
|
| 83 |
+
_clear_cached_macosx_ver()
|
| 84 |
+
sysconfig.get_config_var = make_darwin_gcv(syscfg_macosx_ver)
|
| 85 |
+
if env_macosx_ver is not None:
|
| 86 |
+
env[darwin_ver_var] = env_macosx_ver
|
| 87 |
+
elif darwin_ver_var in env:
|
| 88 |
+
env.pop(darwin_ver_var)
|
| 89 |
+
|
| 90 |
+
# Run the test
|
| 91 |
+
if expected_flag is not None:
|
| 92 |
+
assert self.cc.rpath_foo() == expected_flag, msg
|
| 93 |
+
else:
|
| 94 |
+
with pytest.raises(
|
| 95 |
+
DistutilsPlatformError, match=darwin_ver_var + r' mismatch'
|
| 96 |
+
):
|
| 97 |
+
self.cc.rpath_foo()
|
| 98 |
+
|
| 99 |
+
# Restore
|
| 100 |
+
if old_env_macosx_ver is not None:
|
| 101 |
+
env[darwin_ver_var] = old_env_macosx_ver
|
| 102 |
+
elif darwin_ver_var in env:
|
| 103 |
+
env.pop(darwin_ver_var)
|
| 104 |
+
sysconfig.get_config_var = old_gcv
|
| 105 |
+
_clear_cached_macosx_ver()
|
| 106 |
+
|
| 107 |
+
for macosx_vers, expected_flag in darwin_test_cases:
|
| 108 |
+
syscfg_macosx_ver, env_macosx_ver = macosx_vers
|
| 109 |
+
do_darwin_test(syscfg_macosx_ver, env_macosx_ver, expected_flag)
|
| 110 |
+
# Bonus test cases with None interpreted as empty string
|
| 111 |
+
if syscfg_macosx_ver is None:
|
| 112 |
+
do_darwin_test("", env_macosx_ver, expected_flag)
|
| 113 |
+
if env_macosx_ver is None:
|
| 114 |
+
do_darwin_test(syscfg_macosx_ver, "", expected_flag)
|
| 115 |
+
if syscfg_macosx_ver is None and env_macosx_ver is None:
|
| 116 |
+
do_darwin_test("", "", expected_flag)
|
| 117 |
+
|
| 118 |
+
old_gcv = sysconfig.get_config_var
|
| 119 |
+
|
| 120 |
+
# hp-ux
|
| 121 |
+
sys.platform = 'hp-ux'
|
| 122 |
+
|
| 123 |
+
def gcv(v):
|
| 124 |
+
return 'xxx'
|
| 125 |
+
|
| 126 |
+
sysconfig.get_config_var = gcv
|
| 127 |
+
assert self.cc.rpath_foo() == ['+s', '-L/foo']
|
| 128 |
+
|
| 129 |
+
def gcv(v):
|
| 130 |
+
return 'gcc'
|
| 131 |
+
|
| 132 |
+
sysconfig.get_config_var = gcv
|
| 133 |
+
assert self.cc.rpath_foo() == ['-Wl,+s', '-L/foo']
|
| 134 |
+
|
| 135 |
+
def gcv(v):
|
| 136 |
+
return 'g++'
|
| 137 |
+
|
| 138 |
+
sysconfig.get_config_var = gcv
|
| 139 |
+
assert self.cc.rpath_foo() == ['-Wl,+s', '-L/foo']
|
| 140 |
+
|
| 141 |
+
sysconfig.get_config_var = old_gcv
|
| 142 |
+
|
| 143 |
+
# GCC GNULD
|
| 144 |
+
sys.platform = 'bar'
|
| 145 |
+
|
| 146 |
+
def gcv(v):
|
| 147 |
+
if v == 'CC':
|
| 148 |
+
return 'gcc'
|
| 149 |
+
elif v == 'GNULD':
|
| 150 |
+
return 'yes'
|
| 151 |
+
|
| 152 |
+
sysconfig.get_config_var = gcv
|
| 153 |
+
assert self.cc.rpath_foo() == consolidate_linker_args([
|
| 154 |
+
'-Wl,--enable-new-dtags',
|
| 155 |
+
'-Wl,-rpath,/foo',
|
| 156 |
+
])
|
| 157 |
+
|
| 158 |
+
def gcv(v):
|
| 159 |
+
if v == 'CC':
|
| 160 |
+
return 'gcc -pthread -B /bar'
|
| 161 |
+
elif v == 'GNULD':
|
| 162 |
+
return 'yes'
|
| 163 |
+
|
| 164 |
+
sysconfig.get_config_var = gcv
|
| 165 |
+
assert self.cc.rpath_foo() == consolidate_linker_args([
|
| 166 |
+
'-Wl,--enable-new-dtags',
|
| 167 |
+
'-Wl,-rpath,/foo',
|
| 168 |
+
])
|
| 169 |
+
|
| 170 |
+
# GCC non-GNULD
|
| 171 |
+
sys.platform = 'bar'
|
| 172 |
+
|
| 173 |
+
def gcv(v):
|
| 174 |
+
if v == 'CC':
|
| 175 |
+
return 'gcc'
|
| 176 |
+
elif v == 'GNULD':
|
| 177 |
+
return 'no'
|
| 178 |
+
|
| 179 |
+
sysconfig.get_config_var = gcv
|
| 180 |
+
assert self.cc.rpath_foo() == '-Wl,-R/foo'
|
| 181 |
+
|
| 182 |
+
# GCC GNULD with fully qualified configuration prefix
|
| 183 |
+
# see #7617
|
| 184 |
+
sys.platform = 'bar'
|
| 185 |
+
|
| 186 |
+
def gcv(v):
|
| 187 |
+
if v == 'CC':
|
| 188 |
+
return 'x86_64-pc-linux-gnu-gcc-4.4.2'
|
| 189 |
+
elif v == 'GNULD':
|
| 190 |
+
return 'yes'
|
| 191 |
+
|
| 192 |
+
sysconfig.get_config_var = gcv
|
| 193 |
+
assert self.cc.rpath_foo() == consolidate_linker_args([
|
| 194 |
+
'-Wl,--enable-new-dtags',
|
| 195 |
+
'-Wl,-rpath,/foo',
|
| 196 |
+
])
|
| 197 |
+
|
| 198 |
+
# non-GCC GNULD
|
| 199 |
+
sys.platform = 'bar'
|
| 200 |
+
|
| 201 |
+
def gcv(v):
|
| 202 |
+
if v == 'CC':
|
| 203 |
+
return 'cc'
|
| 204 |
+
elif v == 'GNULD':
|
| 205 |
+
return 'yes'
|
| 206 |
+
|
| 207 |
+
sysconfig.get_config_var = gcv
|
| 208 |
+
assert self.cc.rpath_foo() == consolidate_linker_args([
|
| 209 |
+
'-Wl,--enable-new-dtags',
|
| 210 |
+
'-Wl,-rpath,/foo',
|
| 211 |
+
])
|
| 212 |
+
|
| 213 |
+
# non-GCC non-GNULD
|
| 214 |
+
sys.platform = 'bar'
|
| 215 |
+
|
| 216 |
+
def gcv(v):
|
| 217 |
+
if v == 'CC':
|
| 218 |
+
return 'cc'
|
| 219 |
+
elif v == 'GNULD':
|
| 220 |
+
return 'no'
|
| 221 |
+
|
| 222 |
+
sysconfig.get_config_var = gcv
|
| 223 |
+
assert self.cc.rpath_foo() == '-Wl,-R/foo'
|
| 224 |
+
|
| 225 |
+
@pytest.mark.skipif('platform.system == "Windows"')
|
| 226 |
+
def test_cc_overrides_ldshared(self):
|
| 227 |
+
# Issue #18080:
|
| 228 |
+
# ensure that setting CC env variable also changes default linker
|
| 229 |
+
def gcv(v):
|
| 230 |
+
if v == 'LDSHARED':
|
| 231 |
+
return 'gcc-4.2 -bundle -undefined dynamic_lookup '
|
| 232 |
+
return 'gcc-4.2'
|
| 233 |
+
|
| 234 |
+
def gcvs(*args, _orig=sysconfig.get_config_vars):
|
| 235 |
+
if args:
|
| 236 |
+
return list(map(sysconfig.get_config_var, args))
|
| 237 |
+
return _orig()
|
| 238 |
+
|
| 239 |
+
sysconfig.get_config_var = gcv
|
| 240 |
+
sysconfig.get_config_vars = gcvs
|
| 241 |
+
with EnvironmentVarGuard() as env:
|
| 242 |
+
env['CC'] = 'my_cc'
|
| 243 |
+
del env['LDSHARED']
|
| 244 |
+
sysconfig.customize_compiler(self.cc)
|
| 245 |
+
assert self.cc.linker_so[0] == 'my_cc'
|
| 246 |
+
|
| 247 |
+
@pytest.mark.skipif('platform.system == "Windows"')
|
| 248 |
+
def test_cxx_commands_used_are_correct(self):
|
| 249 |
+
def gcv(v):
|
| 250 |
+
if v == 'LDSHARED':
|
| 251 |
+
return 'ccache gcc-4.2 -bundle -undefined dynamic_lookup'
|
| 252 |
+
elif v == 'LDCXXSHARED':
|
| 253 |
+
return 'ccache g++-4.2 -bundle -undefined dynamic_lookup'
|
| 254 |
+
elif v == 'CXX':
|
| 255 |
+
return 'ccache g++-4.2'
|
| 256 |
+
elif v == 'CC':
|
| 257 |
+
return 'ccache gcc-4.2'
|
| 258 |
+
return ''
|
| 259 |
+
|
| 260 |
+
def gcvs(*args, _orig=sysconfig.get_config_vars):
|
| 261 |
+
if args:
|
| 262 |
+
return list(map(sysconfig.get_config_var, args))
|
| 263 |
+
return _orig() # pragma: no cover
|
| 264 |
+
|
| 265 |
+
sysconfig.get_config_var = gcv
|
| 266 |
+
sysconfig.get_config_vars = gcvs
|
| 267 |
+
with (
|
| 268 |
+
mock.patch.object(self.cc, 'spawn', return_value=None) as mock_spawn,
|
| 269 |
+
mock.patch.object(self.cc, '_need_link', return_value=True),
|
| 270 |
+
mock.patch.object(self.cc, 'mkpath', return_value=None),
|
| 271 |
+
EnvironmentVarGuard() as env,
|
| 272 |
+
):
|
| 273 |
+
# override environment overrides in case they're specified by CI
|
| 274 |
+
del env['CXX']
|
| 275 |
+
del env['LDCXXSHARED']
|
| 276 |
+
|
| 277 |
+
sysconfig.customize_compiler(self.cc)
|
| 278 |
+
assert self.cc.linker_so_cxx[0:2] == ['ccache', 'g++-4.2']
|
| 279 |
+
assert self.cc.linker_exe_cxx[0:2] == ['ccache', 'g++-4.2']
|
| 280 |
+
self.cc.link(None, [], 'a.out', target_lang='c++')
|
| 281 |
+
call_args = mock_spawn.call_args[0][0]
|
| 282 |
+
expected = ['ccache', 'g++-4.2', '-bundle', '-undefined', 'dynamic_lookup']
|
| 283 |
+
assert call_args[:5] == expected
|
| 284 |
+
|
| 285 |
+
self.cc.link_executable([], 'a.out', target_lang='c++')
|
| 286 |
+
call_args = mock_spawn.call_args[0][0]
|
| 287 |
+
expected = ['ccache', 'g++-4.2', '-o', self.cc.executable_filename('a.out')]
|
| 288 |
+
assert call_args[:4] == expected
|
| 289 |
+
|
| 290 |
+
env['LDCXXSHARED'] = 'wrapper g++-4.2 -bundle -undefined dynamic_lookup'
|
| 291 |
+
env['CXX'] = 'wrapper g++-4.2'
|
| 292 |
+
sysconfig.customize_compiler(self.cc)
|
| 293 |
+
assert self.cc.linker_so_cxx[0:2] == ['wrapper', 'g++-4.2']
|
| 294 |
+
assert self.cc.linker_exe_cxx[0:2] == ['wrapper', 'g++-4.2']
|
| 295 |
+
self.cc.link(None, [], 'a.out', target_lang='c++')
|
| 296 |
+
call_args = mock_spawn.call_args[0][0]
|
| 297 |
+
expected = ['wrapper', 'g++-4.2', '-bundle', '-undefined', 'dynamic_lookup']
|
| 298 |
+
assert call_args[:5] == expected
|
| 299 |
+
|
| 300 |
+
self.cc.link_executable([], 'a.out', target_lang='c++')
|
| 301 |
+
call_args = mock_spawn.call_args[0][0]
|
| 302 |
+
expected = [
|
| 303 |
+
'wrapper',
|
| 304 |
+
'g++-4.2',
|
| 305 |
+
'-o',
|
| 306 |
+
self.cc.executable_filename('a.out'),
|
| 307 |
+
]
|
| 308 |
+
assert call_args[:4] == expected
|
| 309 |
+
|
| 310 |
+
@pytest.mark.skipif('platform.system == "Windows"')
|
| 311 |
+
@pytest.mark.usefixtures('disable_macos_customization')
|
| 312 |
+
def test_cc_overrides_ldshared_for_cxx_correctly(self):
|
| 313 |
+
"""
|
| 314 |
+
Ensure that setting CC env variable also changes default linker
|
| 315 |
+
correctly when building C++ extensions.
|
| 316 |
+
|
| 317 |
+
pypa/distutils#126
|
| 318 |
+
"""
|
| 319 |
+
|
| 320 |
+
def gcv(v):
|
| 321 |
+
if v == 'LDSHARED':
|
| 322 |
+
return 'gcc-4.2 -bundle -undefined dynamic_lookup '
|
| 323 |
+
elif v == 'LDCXXSHARED':
|
| 324 |
+
return 'g++-4.2 -bundle -undefined dynamic_lookup '
|
| 325 |
+
elif v == 'CXX':
|
| 326 |
+
return 'g++-4.2'
|
| 327 |
+
elif v == 'CC':
|
| 328 |
+
return 'gcc-4.2'
|
| 329 |
+
return ''
|
| 330 |
+
|
| 331 |
+
def gcvs(*args, _orig=sysconfig.get_config_vars):
|
| 332 |
+
if args:
|
| 333 |
+
return list(map(sysconfig.get_config_var, args))
|
| 334 |
+
return _orig()
|
| 335 |
+
|
| 336 |
+
sysconfig.get_config_var = gcv
|
| 337 |
+
sysconfig.get_config_vars = gcvs
|
| 338 |
+
with (
|
| 339 |
+
mock.patch.object(self.cc, 'spawn', return_value=None) as mock_spawn,
|
| 340 |
+
mock.patch.object(self.cc, '_need_link', return_value=True),
|
| 341 |
+
mock.patch.object(self.cc, 'mkpath', return_value=None),
|
| 342 |
+
EnvironmentVarGuard() as env,
|
| 343 |
+
):
|
| 344 |
+
env['CC'] = 'ccache my_cc'
|
| 345 |
+
env['CXX'] = 'my_cxx'
|
| 346 |
+
del env['LDSHARED']
|
| 347 |
+
sysconfig.customize_compiler(self.cc)
|
| 348 |
+
assert self.cc.linker_so[0:2] == ['ccache', 'my_cc']
|
| 349 |
+
self.cc.link(None, [], 'a.out', target_lang='c++')
|
| 350 |
+
call_args = mock_spawn.call_args[0][0]
|
| 351 |
+
expected = ['my_cxx', '-bundle', '-undefined', 'dynamic_lookup']
|
| 352 |
+
assert call_args[:4] == expected
|
| 353 |
+
|
| 354 |
+
@pytest.mark.skipif('platform.system == "Windows"')
|
| 355 |
+
def test_explicit_ldshared(self):
|
| 356 |
+
# Issue #18080:
|
| 357 |
+
# ensure that setting CC env variable does not change
|
| 358 |
+
# explicit LDSHARED setting for linker
|
| 359 |
+
def gcv(v):
|
| 360 |
+
if v == 'LDSHARED':
|
| 361 |
+
return 'gcc-4.2 -bundle -undefined dynamic_lookup '
|
| 362 |
+
return 'gcc-4.2'
|
| 363 |
+
|
| 364 |
+
def gcvs(*args, _orig=sysconfig.get_config_vars):
|
| 365 |
+
if args:
|
| 366 |
+
return list(map(sysconfig.get_config_var, args))
|
| 367 |
+
return _orig()
|
| 368 |
+
|
| 369 |
+
sysconfig.get_config_var = gcv
|
| 370 |
+
sysconfig.get_config_vars = gcvs
|
| 371 |
+
with EnvironmentVarGuard() as env:
|
| 372 |
+
env['CC'] = 'my_cc'
|
| 373 |
+
env['LDSHARED'] = 'my_ld -bundle -dynamic'
|
| 374 |
+
sysconfig.customize_compiler(self.cc)
|
| 375 |
+
assert self.cc.linker_so[0] == 'my_ld'
|
| 376 |
+
|
| 377 |
+
def test_has_function(self):
|
| 378 |
+
# Issue https://github.com/pypa/distutils/issues/64:
|
| 379 |
+
# ensure that setting output_dir does not raise
|
| 380 |
+
# FileNotFoundError: [Errno 2] No such file or directory: 'a.out'
|
| 381 |
+
self.cc.output_dir = 'scratch'
|
| 382 |
+
os.chdir(self.mkdtemp())
|
| 383 |
+
self.cc.has_function('abort')
|
| 384 |
+
|
| 385 |
+
def test_find_library_file(self, monkeypatch):
|
| 386 |
+
compiler = unix.Compiler()
|
| 387 |
+
compiler._library_root = lambda dir: dir
|
| 388 |
+
monkeypatch.setattr(os.path, 'exists', lambda d: 'existing' in d)
|
| 389 |
+
|
| 390 |
+
libname = 'libabc.dylib' if sys.platform != 'cygwin' else 'cygabc.dll'
|
| 391 |
+
dirs = ('/foo/bar/missing', '/foo/bar/existing')
|
| 392 |
+
assert (
|
| 393 |
+
compiler.find_library_file(dirs, 'abc').replace('\\', '/')
|
| 394 |
+
== f'/foo/bar/existing/{libname}'
|
| 395 |
+
)
|
| 396 |
+
assert (
|
| 397 |
+
compiler.find_library_file(reversed(dirs), 'abc').replace('\\', '/')
|
| 398 |
+
== f'/foo/bar/existing/{libname}'
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
monkeypatch.setattr(
|
| 402 |
+
os.path,
|
| 403 |
+
'exists',
|
| 404 |
+
lambda d: 'existing' in d and '.a' in d and '.dll.a' not in d,
|
| 405 |
+
)
|
| 406 |
+
assert (
|
| 407 |
+
compiler.find_library_file(dirs, 'abc').replace('\\', '/')
|
| 408 |
+
== '/foo/bar/existing/libabc.a'
|
| 409 |
+
)
|
| 410 |
+
assert (
|
| 411 |
+
compiler.find_library_file(reversed(dirs), 'abc').replace('\\', '/')
|
| 412 |
+
== '/foo/bar/existing/libabc.a'
|
| 413 |
+
)
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/unix.py
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ixCCompiler class, a subclass of CCompiler that handles
|
| 4 |
+
the "typical" Unix-style command-line C compiler:
|
| 5 |
+
* macros defined with -Dname[=value]
|
| 6 |
+
* macros undefined with -Uname
|
| 7 |
+
* include search directories specified with -Idir
|
| 8 |
+
* libraries specified with -lllib
|
| 9 |
+
* library search directories specified with -Ldir
|
| 10 |
+
* compile handled by 'cc' (or similar) executable with -c option:
|
| 11 |
+
compiles .c to .o
|
| 12 |
+
* link static library handled by 'ar' command (possibly with 'ranlib')
|
| 13 |
+
* link shared library handled by 'cc -shared'
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import itertools
|
| 19 |
+
import os
|
| 20 |
+
import re
|
| 21 |
+
import shlex
|
| 22 |
+
import sys
|
| 23 |
+
from collections.abc import Iterable
|
| 24 |
+
|
| 25 |
+
from ... import sysconfig
|
| 26 |
+
from ..._log import log
|
| 27 |
+
from ..._macos_compat import compiler_fixup
|
| 28 |
+
from ..._modified import newer
|
| 29 |
+
from ...compat import consolidate_linker_args
|
| 30 |
+
from ...errors import DistutilsExecError
|
| 31 |
+
from . import base
|
| 32 |
+
from .base import _Macro, gen_lib_options, gen_preprocess_options
|
| 33 |
+
from .errors import (
|
| 34 |
+
CompileError,
|
| 35 |
+
LibError,
|
| 36 |
+
LinkError,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# XXX Things not currently handled:
|
| 40 |
+
# * optimization/debug/warning flags; we just use whatever's in Python's
|
| 41 |
+
# Makefile and live with it. Is this adequate? If not, we might
|
| 42 |
+
# have to have a bunch of subclasses GNUCCompiler, SGICCompiler,
|
| 43 |
+
# SunCCompiler, and I suspect down that road lies madness.
|
| 44 |
+
# * even if we don't know a warning flag from an optimization flag,
|
| 45 |
+
# we need some way for outsiders to feed preprocessor/compiler/linker
|
| 46 |
+
# flags in to us -- eg. a sysadmin might want to mandate certain flags
|
| 47 |
+
# via a site config file, or a user might want to set something for
|
| 48 |
+
# compiling this module distribution only via the setup.py command
|
| 49 |
+
# line, whatever. As long as these options come from something on the
|
| 50 |
+
# current system, they can be as system-dependent as they like, and we
|
| 51 |
+
# should just happily stuff them into the preprocessor/compiler/linker
|
| 52 |
+
# options and carry on.
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _split_env(cmd):
|
| 56 |
+
"""
|
| 57 |
+
For macOS, split command into 'env' portion (if any)
|
| 58 |
+
and the rest of the linker command.
|
| 59 |
+
|
| 60 |
+
>>> _split_env(['a', 'b', 'c'])
|
| 61 |
+
([], ['a', 'b', 'c'])
|
| 62 |
+
>>> _split_env(['/usr/bin/env', 'A=3', 'gcc'])
|
| 63 |
+
(['/usr/bin/env', 'A=3'], ['gcc'])
|
| 64 |
+
"""
|
| 65 |
+
pivot = 0
|
| 66 |
+
if os.path.basename(cmd[0]) == "env":
|
| 67 |
+
pivot = 1
|
| 68 |
+
while '=' in cmd[pivot]:
|
| 69 |
+
pivot += 1
|
| 70 |
+
return cmd[:pivot], cmd[pivot:]
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _split_aix(cmd):
|
| 74 |
+
"""
|
| 75 |
+
AIX platforms prefix the compiler with the ld_so_aix
|
| 76 |
+
script, so split that from the linker command.
|
| 77 |
+
|
| 78 |
+
>>> _split_aix(['a', 'b', 'c'])
|
| 79 |
+
([], ['a', 'b', 'c'])
|
| 80 |
+
>>> _split_aix(['/bin/foo/ld_so_aix', 'gcc'])
|
| 81 |
+
(['/bin/foo/ld_so_aix'], ['gcc'])
|
| 82 |
+
"""
|
| 83 |
+
pivot = os.path.basename(cmd[0]) == 'ld_so_aix'
|
| 84 |
+
return cmd[:pivot], cmd[pivot:]
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def _linker_params(linker_cmd, compiler_cmd):
|
| 88 |
+
"""
|
| 89 |
+
The linker command usually begins with the compiler
|
| 90 |
+
command (possibly multiple elements), followed by zero or more
|
| 91 |
+
params for shared library building.
|
| 92 |
+
|
| 93 |
+
If the LDSHARED env variable overrides the linker command,
|
| 94 |
+
however, the commands may not match.
|
| 95 |
+
|
| 96 |
+
Return the best guess of the linker parameters by stripping
|
| 97 |
+
the linker command. If the compiler command does not
|
| 98 |
+
match the linker command, assume the linker command is
|
| 99 |
+
just the first element.
|
| 100 |
+
|
| 101 |
+
>>> _linker_params('gcc foo bar'.split(), ['gcc'])
|
| 102 |
+
['foo', 'bar']
|
| 103 |
+
>>> _linker_params('gcc foo bar'.split(), ['other'])
|
| 104 |
+
['foo', 'bar']
|
| 105 |
+
>>> _linker_params('ccache gcc foo bar'.split(), 'ccache gcc'.split())
|
| 106 |
+
['foo', 'bar']
|
| 107 |
+
>>> _linker_params(['gcc'], ['gcc'])
|
| 108 |
+
[]
|
| 109 |
+
"""
|
| 110 |
+
c_len = len(compiler_cmd)
|
| 111 |
+
pivot = c_len if linker_cmd[:c_len] == compiler_cmd else 1
|
| 112 |
+
return linker_cmd[pivot:]
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
class Compiler(base.Compiler):
|
| 116 |
+
compiler_type = 'unix'
|
| 117 |
+
|
| 118 |
+
# These are used by CCompiler in two places: the constructor sets
|
| 119 |
+
# instance attributes 'preprocessor', 'compiler', etc. from them, and
|
| 120 |
+
# 'set_executable()' allows any of these to be set. The defaults here
|
| 121 |
+
# are pretty generic; they will probably have to be set by an outsider
|
| 122 |
+
# (eg. using information discovered by the sysconfig about building
|
| 123 |
+
# Python extensions).
|
| 124 |
+
executables = {
|
| 125 |
+
'preprocessor': None,
|
| 126 |
+
'compiler': ["cc"],
|
| 127 |
+
'compiler_so': ["cc"],
|
| 128 |
+
'compiler_cxx': ["c++"],
|
| 129 |
+
'compiler_so_cxx': ["c++"],
|
| 130 |
+
'linker_so': ["cc", "-shared"],
|
| 131 |
+
'linker_so_cxx': ["c++", "-shared"],
|
| 132 |
+
'linker_exe': ["cc"],
|
| 133 |
+
'linker_exe_cxx': ["c++", "-shared"],
|
| 134 |
+
'archiver': ["ar", "-cr"],
|
| 135 |
+
'ranlib': None,
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
if sys.platform[:6] == "darwin":
|
| 139 |
+
executables['ranlib'] = ["ranlib"]
|
| 140 |
+
|
| 141 |
+
# Needed for the filename generation methods provided by the base
|
| 142 |
+
# class, CCompiler. NB. whoever instantiates/uses a particular
|
| 143 |
+
# UnixCCompiler instance should set 'shared_lib_ext' -- we set a
|
| 144 |
+
# reasonable common default here, but it's not necessarily used on all
|
| 145 |
+
# Unices!
|
| 146 |
+
|
| 147 |
+
src_extensions = [".c", ".C", ".cc", ".cxx", ".cpp", ".m"]
|
| 148 |
+
obj_extension = ".o"
|
| 149 |
+
static_lib_extension = ".a"
|
| 150 |
+
shared_lib_extension = ".so"
|
| 151 |
+
dylib_lib_extension = ".dylib"
|
| 152 |
+
xcode_stub_lib_extension = ".tbd"
|
| 153 |
+
static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
|
| 154 |
+
xcode_stub_lib_format = dylib_lib_format
|
| 155 |
+
if sys.platform == "cygwin":
|
| 156 |
+
exe_extension = ".exe"
|
| 157 |
+
shared_lib_extension = ".dll.a"
|
| 158 |
+
dylib_lib_extension = ".dll"
|
| 159 |
+
dylib_lib_format = "cyg%s%s"
|
| 160 |
+
|
| 161 |
+
def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
|
| 162 |
+
"""Remove standard library path from rpath"""
|
| 163 |
+
libraries, library_dirs, runtime_library_dirs = super()._fix_lib_args(
|
| 164 |
+
libraries, library_dirs, runtime_library_dirs
|
| 165 |
+
)
|
| 166 |
+
libdir = sysconfig.get_config_var('LIBDIR')
|
| 167 |
+
if (
|
| 168 |
+
runtime_library_dirs
|
| 169 |
+
and libdir.startswith("/usr/lib")
|
| 170 |
+
and (libdir in runtime_library_dirs)
|
| 171 |
+
):
|
| 172 |
+
runtime_library_dirs.remove(libdir)
|
| 173 |
+
return libraries, library_dirs, runtime_library_dirs
|
| 174 |
+
|
| 175 |
+
def preprocess(
|
| 176 |
+
self,
|
| 177 |
+
source: str | os.PathLike[str],
|
| 178 |
+
output_file: str | os.PathLike[str] | None = None,
|
| 179 |
+
macros: list[_Macro] | None = None,
|
| 180 |
+
include_dirs: list[str] | tuple[str, ...] | None = None,
|
| 181 |
+
extra_preargs: list[str] | None = None,
|
| 182 |
+
extra_postargs: Iterable[str] | None = None,
|
| 183 |
+
):
|
| 184 |
+
fixed_args = self._fix_compile_args(None, macros, include_dirs)
|
| 185 |
+
ignore, macros, include_dirs = fixed_args
|
| 186 |
+
pp_opts = gen_preprocess_options(macros, include_dirs)
|
| 187 |
+
pp_args = self.preprocessor + pp_opts
|
| 188 |
+
if output_file:
|
| 189 |
+
pp_args.extend(['-o', output_file])
|
| 190 |
+
if extra_preargs:
|
| 191 |
+
pp_args[:0] = extra_preargs
|
| 192 |
+
if extra_postargs:
|
| 193 |
+
pp_args.extend(extra_postargs)
|
| 194 |
+
pp_args.append(source)
|
| 195 |
+
|
| 196 |
+
# reasons to preprocess:
|
| 197 |
+
# - force is indicated
|
| 198 |
+
# - output is directed to stdout
|
| 199 |
+
# - source file is newer than the target
|
| 200 |
+
preprocess = self.force or output_file is None or newer(source, output_file)
|
| 201 |
+
if not preprocess:
|
| 202 |
+
return
|
| 203 |
+
|
| 204 |
+
if output_file:
|
| 205 |
+
self.mkpath(os.path.dirname(output_file))
|
| 206 |
+
|
| 207 |
+
try:
|
| 208 |
+
self.spawn(pp_args)
|
| 209 |
+
except DistutilsExecError as msg:
|
| 210 |
+
raise CompileError(msg)
|
| 211 |
+
|
| 212 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 213 |
+
compiler_so = compiler_fixup(self.compiler_so, cc_args + extra_postargs)
|
| 214 |
+
compiler_so_cxx = compiler_fixup(self.compiler_so_cxx, cc_args + extra_postargs)
|
| 215 |
+
try:
|
| 216 |
+
if self.detect_language(src) == 'c++':
|
| 217 |
+
self.spawn(
|
| 218 |
+
compiler_so_cxx + cc_args + [src, '-o', obj] + extra_postargs
|
| 219 |
+
)
|
| 220 |
+
else:
|
| 221 |
+
self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
|
| 222 |
+
except DistutilsExecError as msg:
|
| 223 |
+
raise CompileError(msg)
|
| 224 |
+
|
| 225 |
+
def create_static_lib(
|
| 226 |
+
self, objects, output_libname, output_dir=None, debug=False, target_lang=None
|
| 227 |
+
):
|
| 228 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 229 |
+
|
| 230 |
+
output_filename = self.library_filename(output_libname, output_dir=output_dir)
|
| 231 |
+
|
| 232 |
+
if self._need_link(objects, output_filename):
|
| 233 |
+
self.mkpath(os.path.dirname(output_filename))
|
| 234 |
+
self.spawn(self.archiver + [output_filename] + objects + self.objects)
|
| 235 |
+
|
| 236 |
+
# Not many Unices required ranlib anymore -- SunOS 4.x is, I
|
| 237 |
+
# think the only major Unix that does. Maybe we need some
|
| 238 |
+
# platform intelligence here to skip ranlib if it's not
|
| 239 |
+
# needed -- or maybe Python's configure script took care of
|
| 240 |
+
# it for us, hence the check for leading colon.
|
| 241 |
+
if self.ranlib:
|
| 242 |
+
try:
|
| 243 |
+
self.spawn(self.ranlib + [output_filename])
|
| 244 |
+
except DistutilsExecError as msg:
|
| 245 |
+
raise LibError(msg)
|
| 246 |
+
else:
|
| 247 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 248 |
+
|
| 249 |
+
def link(
|
| 250 |
+
self,
|
| 251 |
+
target_desc,
|
| 252 |
+
objects: list[str] | tuple[str, ...],
|
| 253 |
+
output_filename,
|
| 254 |
+
output_dir: str | None = None,
|
| 255 |
+
libraries: list[str] | tuple[str, ...] | None = None,
|
| 256 |
+
library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 257 |
+
runtime_library_dirs: list[str] | tuple[str, ...] | None = None,
|
| 258 |
+
export_symbols=None,
|
| 259 |
+
debug=False,
|
| 260 |
+
extra_preargs=None,
|
| 261 |
+
extra_postargs=None,
|
| 262 |
+
build_temp=None,
|
| 263 |
+
target_lang=None,
|
| 264 |
+
):
|
| 265 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
| 266 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
|
| 267 |
+
libraries, library_dirs, runtime_library_dirs = fixed_args
|
| 268 |
+
|
| 269 |
+
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries)
|
| 270 |
+
if not isinstance(output_dir, (str, type(None))):
|
| 271 |
+
raise TypeError("'output_dir' must be a string or None")
|
| 272 |
+
if output_dir is not None:
|
| 273 |
+
output_filename = os.path.join(output_dir, output_filename)
|
| 274 |
+
|
| 275 |
+
if self._need_link(objects, output_filename):
|
| 276 |
+
ld_args = objects + self.objects + lib_opts + ['-o', output_filename]
|
| 277 |
+
if debug:
|
| 278 |
+
ld_args[:0] = ['-g']
|
| 279 |
+
if extra_preargs:
|
| 280 |
+
ld_args[:0] = extra_preargs
|
| 281 |
+
if extra_postargs:
|
| 282 |
+
ld_args.extend(extra_postargs)
|
| 283 |
+
self.mkpath(os.path.dirname(output_filename))
|
| 284 |
+
try:
|
| 285 |
+
# Select a linker based on context: linker_exe when
|
| 286 |
+
# building an executable or linker_so (with shared options)
|
| 287 |
+
# when building a shared library.
|
| 288 |
+
building_exe = target_desc == base.Compiler.EXECUTABLE
|
| 289 |
+
target_cxx = target_lang == "c++"
|
| 290 |
+
linker = (
|
| 291 |
+
(self.linker_exe_cxx if target_cxx else self.linker_exe)
|
| 292 |
+
if building_exe
|
| 293 |
+
else (self.linker_so_cxx if target_cxx else self.linker_so)
|
| 294 |
+
)[:]
|
| 295 |
+
|
| 296 |
+
if target_cxx and self.compiler_cxx:
|
| 297 |
+
env, linker_ne = _split_env(linker)
|
| 298 |
+
aix, linker_na = _split_aix(linker_ne)
|
| 299 |
+
_, compiler_cxx_ne = _split_env(self.compiler_cxx)
|
| 300 |
+
_, linker_exe_ne = _split_env(self.linker_exe_cxx)
|
| 301 |
+
|
| 302 |
+
params = _linker_params(linker_na, linker_exe_ne)
|
| 303 |
+
linker = env + aix + compiler_cxx_ne + params
|
| 304 |
+
|
| 305 |
+
linker = compiler_fixup(linker, ld_args)
|
| 306 |
+
|
| 307 |
+
self.spawn(linker + ld_args)
|
| 308 |
+
except DistutilsExecError as msg:
|
| 309 |
+
raise LinkError(msg)
|
| 310 |
+
else:
|
| 311 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
| 312 |
+
|
| 313 |
+
# -- Miscellaneous methods -----------------------------------------
|
| 314 |
+
# These are all used by the 'gen_lib_options() function, in
|
| 315 |
+
# ccompiler.py.
|
| 316 |
+
|
| 317 |
+
def library_dir_option(self, dir):
|
| 318 |
+
return "-L" + dir
|
| 319 |
+
|
| 320 |
+
def _is_gcc(self):
|
| 321 |
+
cc_var = sysconfig.get_config_var("CC")
|
| 322 |
+
compiler = os.path.basename(shlex.split(cc_var)[0])
|
| 323 |
+
return "gcc" in compiler or "g++" in compiler
|
| 324 |
+
|
| 325 |
+
def runtime_library_dir_option(self, dir: str) -> str | list[str]: # type: ignore[override] # Fixed in pypa/distutils#339
|
| 326 |
+
# XXX Hackish, at the very least. See Python bug #445902:
|
| 327 |
+
# https://bugs.python.org/issue445902
|
| 328 |
+
# Linkers on different platforms need different options to
|
| 329 |
+
# specify that directories need to be added to the list of
|
| 330 |
+
# directories searched for dependencies when a dynamic library
|
| 331 |
+
# is sought. GCC on GNU systems (Linux, FreeBSD, ...) has to
|
| 332 |
+
# be told to pass the -R option through to the linker, whereas
|
| 333 |
+
# other compilers and gcc on other systems just know this.
|
| 334 |
+
# Other compilers may need something slightly different. At
|
| 335 |
+
# this time, there's no way to determine this information from
|
| 336 |
+
# the configuration data stored in the Python installation, so
|
| 337 |
+
# we use this hack.
|
| 338 |
+
if sys.platform[:6] == "darwin":
|
| 339 |
+
from distutils.util import get_macosx_target_ver, split_version
|
| 340 |
+
|
| 341 |
+
macosx_target_ver = get_macosx_target_ver()
|
| 342 |
+
if macosx_target_ver and split_version(macosx_target_ver) >= [10, 5]:
|
| 343 |
+
return "-Wl,-rpath," + dir
|
| 344 |
+
else: # no support for -rpath on earlier macOS versions
|
| 345 |
+
return "-L" + dir
|
| 346 |
+
elif sys.platform[:7] == "freebsd":
|
| 347 |
+
return "-Wl,-rpath=" + dir
|
| 348 |
+
elif sys.platform[:5] == "hp-ux":
|
| 349 |
+
return [
|
| 350 |
+
"-Wl,+s" if self._is_gcc() else "+s",
|
| 351 |
+
"-L" + dir,
|
| 352 |
+
]
|
| 353 |
+
|
| 354 |
+
# For all compilers, `-Wl` is the presumed way to pass a
|
| 355 |
+
# compiler option to the linker
|
| 356 |
+
if sysconfig.get_config_var("GNULD") == "yes":
|
| 357 |
+
return consolidate_linker_args([
|
| 358 |
+
# Force RUNPATH instead of RPATH
|
| 359 |
+
"-Wl,--enable-new-dtags",
|
| 360 |
+
"-Wl,-rpath," + dir,
|
| 361 |
+
])
|
| 362 |
+
else:
|
| 363 |
+
return "-Wl,-R" + dir
|
| 364 |
+
|
| 365 |
+
def library_option(self, lib):
|
| 366 |
+
return "-l" + lib
|
| 367 |
+
|
| 368 |
+
@staticmethod
|
| 369 |
+
def _library_root(dir):
|
| 370 |
+
"""
|
| 371 |
+
macOS users can specify an alternate SDK using'-isysroot'.
|
| 372 |
+
Calculate the SDK root if it is specified.
|
| 373 |
+
|
| 374 |
+
Note that, as of Xcode 7, Apple SDKs may contain textual stub
|
| 375 |
+
libraries with .tbd extensions rather than the normal .dylib
|
| 376 |
+
shared libraries installed in /. The Apple compiler tool
|
| 377 |
+
chain handles this transparently but it can cause problems
|
| 378 |
+
for programs that are being built with an SDK and searching
|
| 379 |
+
for specific libraries. Callers of find_library_file need to
|
| 380 |
+
keep in mind that the base filename of the returned SDK library
|
| 381 |
+
file might have a different extension from that of the library
|
| 382 |
+
file installed on the running system, for example:
|
| 383 |
+
/Applications/Xcode.app/Contents/Developer/Platforms/
|
| 384 |
+
MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
|
| 385 |
+
usr/lib/libedit.tbd
|
| 386 |
+
vs
|
| 387 |
+
/usr/lib/libedit.dylib
|
| 388 |
+
"""
|
| 389 |
+
cflags = sysconfig.get_config_var('CFLAGS')
|
| 390 |
+
match = re.search(r'-isysroot\s*(\S+)', cflags)
|
| 391 |
+
|
| 392 |
+
apply_root = (
|
| 393 |
+
sys.platform == 'darwin'
|
| 394 |
+
and match
|
| 395 |
+
and (
|
| 396 |
+
dir.startswith('/System/')
|
| 397 |
+
or (dir.startswith('/usr/') and not dir.startswith('/usr/local/'))
|
| 398 |
+
)
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
return os.path.join(match.group(1), dir[1:]) if apply_root else dir
|
| 402 |
+
|
| 403 |
+
def find_library_file(self, dirs, lib, debug=False):
|
| 404 |
+
"""
|
| 405 |
+
Second-guess the linker with not much hard
|
| 406 |
+
data to go on: GCC seems to prefer the shared library, so
|
| 407 |
+
assume that *all* Unix C compilers do,
|
| 408 |
+
ignoring even GCC's "-static" option.
|
| 409 |
+
"""
|
| 410 |
+
lib_names = (
|
| 411 |
+
self.library_filename(lib, lib_type=type)
|
| 412 |
+
for type in 'dylib xcode_stub shared static'.split()
|
| 413 |
+
)
|
| 414 |
+
|
| 415 |
+
roots = map(self._library_root, dirs)
|
| 416 |
+
|
| 417 |
+
searched = itertools.starmap(os.path.join, itertools.product(roots, lib_names))
|
| 418 |
+
|
| 419 |
+
found = filter(os.path.exists, searched)
|
| 420 |
+
|
| 421 |
+
# Return None if it could not be found in any dir.
|
| 422 |
+
return next(found, None)
|
python/Lib/site-packages/setuptools/_distutils/compilers/C/zos.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""distutils.zosccompiler
|
| 2 |
+
|
| 3 |
+
Contains the selection of the c & c++ compilers on z/OS. There are several
|
| 4 |
+
different c compilers on z/OS, all of them are optional, so the correct
|
| 5 |
+
one needs to be chosen based on the users input. This is compatible with
|
| 6 |
+
the following compilers:
|
| 7 |
+
|
| 8 |
+
IBM C/C++ For Open Enterprise Languages on z/OS 2.0
|
| 9 |
+
IBM Open XL C/C++ 1.1 for z/OS
|
| 10 |
+
IBM XL C/C++ V2.4.1 for z/OS 2.4 and 2.5
|
| 11 |
+
IBM z/OS XL C/C++
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import os
|
| 15 |
+
|
| 16 |
+
from ... import sysconfig
|
| 17 |
+
from ...errors import DistutilsExecError
|
| 18 |
+
from . import unix
|
| 19 |
+
from .errors import CompileError
|
| 20 |
+
|
| 21 |
+
_cc_args = {
|
| 22 |
+
'ibm-openxl': [
|
| 23 |
+
'-m64',
|
| 24 |
+
'-fvisibility=default',
|
| 25 |
+
'-fzos-le-char-mode=ascii',
|
| 26 |
+
'-fno-short-enums',
|
| 27 |
+
],
|
| 28 |
+
'ibm-xlclang': [
|
| 29 |
+
'-q64',
|
| 30 |
+
'-qexportall',
|
| 31 |
+
'-qascii',
|
| 32 |
+
'-qstrict',
|
| 33 |
+
'-qnocsect',
|
| 34 |
+
'-Wa,asa,goff',
|
| 35 |
+
'-Wa,xplink',
|
| 36 |
+
'-qgonumber',
|
| 37 |
+
'-qenum=int',
|
| 38 |
+
'-Wc,DLL',
|
| 39 |
+
],
|
| 40 |
+
'ibm-xlc': [
|
| 41 |
+
'-q64',
|
| 42 |
+
'-qexportall',
|
| 43 |
+
'-qascii',
|
| 44 |
+
'-qstrict',
|
| 45 |
+
'-qnocsect',
|
| 46 |
+
'-Wa,asa,goff',
|
| 47 |
+
'-Wa,xplink',
|
| 48 |
+
'-qgonumber',
|
| 49 |
+
'-qenum=int',
|
| 50 |
+
'-Wc,DLL',
|
| 51 |
+
'-qlanglvl=extc99',
|
| 52 |
+
],
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
_cxx_args = {
|
| 56 |
+
'ibm-openxl': [
|
| 57 |
+
'-m64',
|
| 58 |
+
'-fvisibility=default',
|
| 59 |
+
'-fzos-le-char-mode=ascii',
|
| 60 |
+
'-fno-short-enums',
|
| 61 |
+
],
|
| 62 |
+
'ibm-xlclang': [
|
| 63 |
+
'-q64',
|
| 64 |
+
'-qexportall',
|
| 65 |
+
'-qascii',
|
| 66 |
+
'-qstrict',
|
| 67 |
+
'-qnocsect',
|
| 68 |
+
'-Wa,asa,goff',
|
| 69 |
+
'-Wa,xplink',
|
| 70 |
+
'-qgonumber',
|
| 71 |
+
'-qenum=int',
|
| 72 |
+
'-Wc,DLL',
|
| 73 |
+
],
|
| 74 |
+
'ibm-xlc': [
|
| 75 |
+
'-q64',
|
| 76 |
+
'-qexportall',
|
| 77 |
+
'-qascii',
|
| 78 |
+
'-qstrict',
|
| 79 |
+
'-qnocsect',
|
| 80 |
+
'-Wa,asa,goff',
|
| 81 |
+
'-Wa,xplink',
|
| 82 |
+
'-qgonumber',
|
| 83 |
+
'-qenum=int',
|
| 84 |
+
'-Wc,DLL',
|
| 85 |
+
'-qlanglvl=extended0x',
|
| 86 |
+
],
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
_asm_args = {
|
| 90 |
+
'ibm-openxl': ['-fasm', '-fno-integrated-as', '-Wa,--ASA', '-Wa,--GOFF'],
|
| 91 |
+
'ibm-xlclang': [],
|
| 92 |
+
'ibm-xlc': [],
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
_ld_args = {
|
| 96 |
+
'ibm-openxl': [],
|
| 97 |
+
'ibm-xlclang': ['-Wl,dll', '-q64'],
|
| 98 |
+
'ibm-xlc': ['-Wl,dll', '-q64'],
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
# Python on z/OS is built with no compiler specific options in it's CFLAGS.
|
| 103 |
+
# But each compiler requires it's own specific options to build successfully,
|
| 104 |
+
# though some of the options are common between them
|
| 105 |
+
class Compiler(unix.Compiler):
|
| 106 |
+
src_extensions = ['.c', '.C', '.cc', '.cxx', '.cpp', '.m', '.s']
|
| 107 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx', '.C']
|
| 108 |
+
_asm_extensions = ['.s']
|
| 109 |
+
|
| 110 |
+
def _get_zos_compiler_name(self):
|
| 111 |
+
zos_compiler_names = [
|
| 112 |
+
os.path.basename(binary)
|
| 113 |
+
for envvar in ('CC', 'CXX', 'LDSHARED')
|
| 114 |
+
if (binary := os.environ.get(envvar, None))
|
| 115 |
+
]
|
| 116 |
+
if len(zos_compiler_names) == 0:
|
| 117 |
+
return 'ibm-openxl'
|
| 118 |
+
|
| 119 |
+
zos_compilers = {}
|
| 120 |
+
for compiler in (
|
| 121 |
+
'ibm-clang',
|
| 122 |
+
'ibm-clang64',
|
| 123 |
+
'ibm-clang++',
|
| 124 |
+
'ibm-clang++64',
|
| 125 |
+
'clang',
|
| 126 |
+
'clang++',
|
| 127 |
+
'clang-14',
|
| 128 |
+
):
|
| 129 |
+
zos_compilers[compiler] = 'ibm-openxl'
|
| 130 |
+
|
| 131 |
+
for compiler in ('xlclang', 'xlclang++', 'njsc', 'njsc++'):
|
| 132 |
+
zos_compilers[compiler] = 'ibm-xlclang'
|
| 133 |
+
|
| 134 |
+
for compiler in ('xlc', 'xlC', 'xlc++'):
|
| 135 |
+
zos_compilers[compiler] = 'ibm-xlc'
|
| 136 |
+
|
| 137 |
+
return zos_compilers.get(zos_compiler_names[0], 'ibm-openxl')
|
| 138 |
+
|
| 139 |
+
def __init__(self, verbose=False, force=False):
|
| 140 |
+
super().__init__(verbose, force=force)
|
| 141 |
+
self.zos_compiler = self._get_zos_compiler_name()
|
| 142 |
+
sysconfig.customize_compiler(self)
|
| 143 |
+
|
| 144 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
| 145 |
+
local_args = []
|
| 146 |
+
if ext in self._cpp_extensions:
|
| 147 |
+
compiler = self.compiler_cxx
|
| 148 |
+
local_args.extend(_cxx_args[self.zos_compiler])
|
| 149 |
+
elif ext in self._asm_extensions:
|
| 150 |
+
compiler = self.compiler_so
|
| 151 |
+
local_args.extend(_cc_args[self.zos_compiler])
|
| 152 |
+
local_args.extend(_asm_args[self.zos_compiler])
|
| 153 |
+
else:
|
| 154 |
+
compiler = self.compiler_so
|
| 155 |
+
local_args.extend(_cc_args[self.zos_compiler])
|
| 156 |
+
local_args.extend(cc_args)
|
| 157 |
+
|
| 158 |
+
try:
|
| 159 |
+
self.spawn(compiler + local_args + [src, '-o', obj] + extra_postargs)
|
| 160 |
+
except DistutilsExecError as msg:
|
| 161 |
+
raise CompileError(msg)
|
| 162 |
+
|
| 163 |
+
def runtime_library_dir_option(self, dir):
|
| 164 |
+
return '-L' + dir
|
| 165 |
+
|
| 166 |
+
def link(
|
| 167 |
+
self,
|
| 168 |
+
target_desc,
|
| 169 |
+
objects,
|
| 170 |
+
output_filename,
|
| 171 |
+
output_dir=None,
|
| 172 |
+
libraries=None,
|
| 173 |
+
library_dirs=None,
|
| 174 |
+
runtime_library_dirs=None,
|
| 175 |
+
export_symbols=None,
|
| 176 |
+
debug=False,
|
| 177 |
+
extra_preargs=None,
|
| 178 |
+
extra_postargs=None,
|
| 179 |
+
build_temp=None,
|
| 180 |
+
target_lang=None,
|
| 181 |
+
):
|
| 182 |
+
# For a built module to use functions from cpython, it needs to use Pythons
|
| 183 |
+
# side deck file. The side deck is located beside the libpython3.xx.so
|
| 184 |
+
ldversion = sysconfig.get_config_var('LDVERSION')
|
| 185 |
+
if sysconfig.python_build:
|
| 186 |
+
side_deck_path = os.path.join(
|
| 187 |
+
sysconfig.get_config_var('abs_builddir'),
|
| 188 |
+
f'libpython{ldversion}.x',
|
| 189 |
+
)
|
| 190 |
+
else:
|
| 191 |
+
side_deck_path = os.path.join(
|
| 192 |
+
sysconfig.get_config_var('installed_base'),
|
| 193 |
+
sysconfig.get_config_var('platlibdir'),
|
| 194 |
+
f'libpython{ldversion}.x',
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
if os.path.exists(side_deck_path):
|
| 198 |
+
if extra_postargs:
|
| 199 |
+
extra_postargs.append(side_deck_path)
|
| 200 |
+
else:
|
| 201 |
+
extra_postargs = [side_deck_path]
|
| 202 |
+
|
| 203 |
+
# Check and replace libraries included side deck files
|
| 204 |
+
if runtime_library_dirs:
|
| 205 |
+
for dir in runtime_library_dirs:
|
| 206 |
+
for library in libraries[:]:
|
| 207 |
+
library_side_deck = os.path.join(dir, f'{library}.x')
|
| 208 |
+
if os.path.exists(library_side_deck):
|
| 209 |
+
libraries.remove(library)
|
| 210 |
+
extra_postargs.append(library_side_deck)
|
| 211 |
+
break
|
| 212 |
+
|
| 213 |
+
# Any required ld args for the given compiler
|
| 214 |
+
extra_postargs.extend(_ld_args[self.zos_compiler])
|
| 215 |
+
|
| 216 |
+
super().link(
|
| 217 |
+
target_desc,
|
| 218 |
+
objects,
|
| 219 |
+
output_filename,
|
| 220 |
+
output_dir,
|
| 221 |
+
libraries,
|
| 222 |
+
library_dirs,
|
| 223 |
+
runtime_library_dirs,
|
| 224 |
+
export_symbols,
|
| 225 |
+
debug,
|
| 226 |
+
extra_preargs,
|
| 227 |
+
extra_postargs,
|
| 228 |
+
build_temp,
|
| 229 |
+
target_lang,
|
| 230 |
+
)
|
python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (1.92 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_version.cpython-313.pyc
ADDED
|
Binary file (3.89 kB). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/test_versionpredicate.cpython-313.pyc
ADDED
|
Binary file (196 Bytes). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/tests/__pycache__/unix_compat.cpython-313.pyc
ADDED
|
Binary file (800 Bytes). View file
|
|
|
python/Lib/site-packages/setuptools/_distutils/tests/compat/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (190 Bytes). View file
|
|
|