Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__init__.py +24 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/bcppcompiler.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/config.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/debug.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/msvc9compiler.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/_msvccompiler.py +561 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/archive_util.py +256 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/bcppcompiler.py +393 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/ccompiler.py +1123 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/cmd.py +403 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__init__.py +31 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_clib.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/clean.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_headers.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/bdist.py +143 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_dumb.py +123 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_rpm.py +579 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_wininst.py +377 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build.py +157 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build_clib.py +209 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py +755 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build_py.py +392 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build_scripts.py +152 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/check.py +148 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/config.py +344 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/install_data.py +79 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/install_headers.py +47 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/install_lib.py +217 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/install_scripts.py +60 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/sdist.py +494 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/config.py +130 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/core.py +249 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/cygwinccompiler.py +425 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/debug.py +5 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/dep_util.py +92 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/dir_util.py +210 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/errors.py +97 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/file_util.py +238 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/filelist.py +355 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/msvc9compiler.py +788 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/msvccompiler.py +643 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/py35compat.py +19 -0
- llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/py38compat.py +7 -0
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__init__.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils
|
2 |
+
|
3 |
+
The main package for the Python Module Distribution Utilities. Normally
|
4 |
+
used from a setup script as
|
5 |
+
|
6 |
+
from distutils.core import setup
|
7 |
+
|
8 |
+
setup (...)
|
9 |
+
"""
|
10 |
+
|
11 |
+
import sys
|
12 |
+
import importlib
|
13 |
+
|
14 |
+
__version__ = sys.version[:sys.version.index(' ')]
|
15 |
+
|
16 |
+
|
17 |
+
try:
|
18 |
+
# Allow Debian and pkgsrc (only) to customize system
|
19 |
+
# behavior. Ref pypa/distutils#2 and pypa/distutils#16.
|
20 |
+
# This hook is deprecated and no other environments
|
21 |
+
# should use it.
|
22 |
+
importlib.import_module('_distutils_system_mod')
|
23 |
+
except ImportError:
|
24 |
+
pass
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/_msvccompiler.cpython-310.pyc
ADDED
Binary file (13.8 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/archive_util.cpython-310.pyc
ADDED
Binary file (6.57 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/bcppcompiler.cpython-310.pyc
ADDED
Binary file (6.56 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/ccompiler.cpython-310.pyc
ADDED
Binary file (33.3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/config.cpython-310.pyc
ADDED
Binary file (3.59 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/cygwinccompiler.cpython-310.pyc
ADDED
Binary file (9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/debug.cpython-310.pyc
ADDED
Binary file (257 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/msvc9compiler.cpython-310.pyc
ADDED
Binary file (17.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/sysconfig.cpython-310.pyc
ADDED
Binary file (12.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/__pycache__/versionpredicate.cpython-310.pyc
ADDED
Binary file (5.34 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/_msvccompiler.py
ADDED
@@ -0,0 +1,561 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils._msvccompiler
|
2 |
+
|
3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
4 |
+
for Microsoft Visual Studio 2015.
|
5 |
+
|
6 |
+
The module is compatible with VS 2015 and later. You can find legacy support
|
7 |
+
for older versions in distutils.msvc9compiler and distutils.msvccompiler.
|
8 |
+
"""
|
9 |
+
|
10 |
+
# Written by Perry Stoll
|
11 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
12 |
+
# finding DevStudio (through the registry)
|
13 |
+
# ported to VS 2005 and VS 2008 by Christian Heimes
|
14 |
+
# ported to VS 2015 by Steve Dower
|
15 |
+
|
16 |
+
import os
|
17 |
+
import subprocess
|
18 |
+
import contextlib
|
19 |
+
import warnings
|
20 |
+
import unittest.mock
|
21 |
+
with contextlib.suppress(ImportError):
|
22 |
+
import winreg
|
23 |
+
|
24 |
+
from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
|
25 |
+
CompileError, LibError, LinkError
|
26 |
+
from distutils.ccompiler import CCompiler, gen_lib_options
|
27 |
+
from distutils import log
|
28 |
+
from distutils.util import get_platform
|
29 |
+
|
30 |
+
from itertools import count
|
31 |
+
|
32 |
+
def _find_vc2015():
|
33 |
+
try:
|
34 |
+
key = winreg.OpenKeyEx(
|
35 |
+
winreg.HKEY_LOCAL_MACHINE,
|
36 |
+
r"Software\Microsoft\VisualStudio\SxS\VC7",
|
37 |
+
access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
|
38 |
+
)
|
39 |
+
except OSError:
|
40 |
+
log.debug("Visual C++ is not registered")
|
41 |
+
return None, None
|
42 |
+
|
43 |
+
best_version = 0
|
44 |
+
best_dir = None
|
45 |
+
with key:
|
46 |
+
for i in count():
|
47 |
+
try:
|
48 |
+
v, vc_dir, vt = winreg.EnumValue(key, i)
|
49 |
+
except OSError:
|
50 |
+
break
|
51 |
+
if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
|
52 |
+
try:
|
53 |
+
version = int(float(v))
|
54 |
+
except (ValueError, TypeError):
|
55 |
+
continue
|
56 |
+
if version >= 14 and version > best_version:
|
57 |
+
best_version, best_dir = version, vc_dir
|
58 |
+
return best_version, best_dir
|
59 |
+
|
60 |
+
def _find_vc2017():
|
61 |
+
"""Returns "15, path" based on the result of invoking vswhere.exe
|
62 |
+
If no install is found, returns "None, None"
|
63 |
+
|
64 |
+
The version is returned to avoid unnecessarily changing the function
|
65 |
+
result. It may be ignored when the path is not None.
|
66 |
+
|
67 |
+
If vswhere.exe is not available, by definition, VS 2017 is not
|
68 |
+
installed.
|
69 |
+
"""
|
70 |
+
root = os.environ.get("ProgramFiles(x86)") or os.environ.get("ProgramFiles")
|
71 |
+
if not root:
|
72 |
+
return None, None
|
73 |
+
|
74 |
+
try:
|
75 |
+
path = subprocess.check_output([
|
76 |
+
os.path.join(root, "Microsoft Visual Studio", "Installer", "vswhere.exe"),
|
77 |
+
"-latest",
|
78 |
+
"-prerelease",
|
79 |
+
"-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
|
80 |
+
"-property", "installationPath",
|
81 |
+
"-products", "*",
|
82 |
+
], encoding="mbcs", errors="strict").strip()
|
83 |
+
except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
|
84 |
+
return None, None
|
85 |
+
|
86 |
+
path = os.path.join(path, "VC", "Auxiliary", "Build")
|
87 |
+
if os.path.isdir(path):
|
88 |
+
return 15, path
|
89 |
+
|
90 |
+
return None, None
|
91 |
+
|
92 |
+
PLAT_SPEC_TO_RUNTIME = {
|
93 |
+
'x86' : 'x86',
|
94 |
+
'x86_amd64' : 'x64',
|
95 |
+
'x86_arm' : 'arm',
|
96 |
+
'x86_arm64' : 'arm64'
|
97 |
+
}
|
98 |
+
|
99 |
+
def _find_vcvarsall(plat_spec):
|
100 |
+
# bpo-38597: Removed vcruntime return value
|
101 |
+
_, best_dir = _find_vc2017()
|
102 |
+
|
103 |
+
if not best_dir:
|
104 |
+
best_version, best_dir = _find_vc2015()
|
105 |
+
|
106 |
+
if not best_dir:
|
107 |
+
log.debug("No suitable Visual C++ version found")
|
108 |
+
return None, None
|
109 |
+
|
110 |
+
vcvarsall = os.path.join(best_dir, "vcvarsall.bat")
|
111 |
+
if not os.path.isfile(vcvarsall):
|
112 |
+
log.debug("%s cannot be found", vcvarsall)
|
113 |
+
return None, None
|
114 |
+
|
115 |
+
return vcvarsall, None
|
116 |
+
|
117 |
+
def _get_vc_env(plat_spec):
|
118 |
+
if os.getenv("DISTUTILS_USE_SDK"):
|
119 |
+
return {
|
120 |
+
key.lower(): value
|
121 |
+
for key, value in os.environ.items()
|
122 |
+
}
|
123 |
+
|
124 |
+
vcvarsall, _ = _find_vcvarsall(plat_spec)
|
125 |
+
if not vcvarsall:
|
126 |
+
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
|
127 |
+
|
128 |
+
try:
|
129 |
+
out = subprocess.check_output(
|
130 |
+
'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
|
131 |
+
stderr=subprocess.STDOUT,
|
132 |
+
).decode('utf-16le', errors='replace')
|
133 |
+
except subprocess.CalledProcessError as exc:
|
134 |
+
log.error(exc.output)
|
135 |
+
raise DistutilsPlatformError("Error executing {}"
|
136 |
+
.format(exc.cmd))
|
137 |
+
|
138 |
+
env = {
|
139 |
+
key.lower(): value
|
140 |
+
for key, _, value in
|
141 |
+
(line.partition('=') for line in out.splitlines())
|
142 |
+
if key and value
|
143 |
+
}
|
144 |
+
|
145 |
+
return env
|
146 |
+
|
147 |
+
def _find_exe(exe, paths=None):
|
148 |
+
"""Return path to an MSVC executable program.
|
149 |
+
|
150 |
+
Tries to find the program in several places: first, one of the
|
151 |
+
MSVC program search paths from the registry; next, the directories
|
152 |
+
in the PATH environment variable. If any of those work, return an
|
153 |
+
absolute path that is known to exist. If none of them work, just
|
154 |
+
return the original program name, 'exe'.
|
155 |
+
"""
|
156 |
+
if not paths:
|
157 |
+
paths = os.getenv('path').split(os.pathsep)
|
158 |
+
for p in paths:
|
159 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
160 |
+
if os.path.isfile(fn):
|
161 |
+
return fn
|
162 |
+
return exe
|
163 |
+
|
164 |
+
# A map keyed by get_platform() return values to values accepted by
|
165 |
+
# 'vcvarsall.bat'. Always cross-compile from x86 to work with the
|
166 |
+
# lighter-weight MSVC installs that do not include native 64-bit tools.
|
167 |
+
PLAT_TO_VCVARS = {
|
168 |
+
'win32' : 'x86',
|
169 |
+
'win-amd64' : 'x86_amd64',
|
170 |
+
'win-arm32' : 'x86_arm',
|
171 |
+
'win-arm64' : 'x86_arm64'
|
172 |
+
}
|
173 |
+
|
174 |
+
class MSVCCompiler(CCompiler) :
|
175 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
176 |
+
as defined by the CCompiler abstract class."""
|
177 |
+
|
178 |
+
compiler_type = 'msvc'
|
179 |
+
|
180 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
181 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
182 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
183 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
184 |
+
# though, so it's worth thinking about.
|
185 |
+
executables = {}
|
186 |
+
|
187 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
188 |
+
_c_extensions = ['.c']
|
189 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
190 |
+
_rc_extensions = ['.rc']
|
191 |
+
_mc_extensions = ['.mc']
|
192 |
+
|
193 |
+
# Needed for the filename generation methods provided by the
|
194 |
+
# base class, CCompiler.
|
195 |
+
src_extensions = (_c_extensions + _cpp_extensions +
|
196 |
+
_rc_extensions + _mc_extensions)
|
197 |
+
res_extension = '.res'
|
198 |
+
obj_extension = '.obj'
|
199 |
+
static_lib_extension = '.lib'
|
200 |
+
shared_lib_extension = '.dll'
|
201 |
+
static_lib_format = shared_lib_format = '%s%s'
|
202 |
+
exe_extension = '.exe'
|
203 |
+
|
204 |
+
|
205 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
206 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
207 |
+
# target platform (.plat_name is consistent with 'bdist')
|
208 |
+
self.plat_name = None
|
209 |
+
self.initialized = False
|
210 |
+
|
211 |
+
def initialize(self, plat_name=None):
|
212 |
+
# multi-init means we would need to check platform same each time...
|
213 |
+
assert not self.initialized, "don't init multiple times"
|
214 |
+
if plat_name is None:
|
215 |
+
plat_name = get_platform()
|
216 |
+
# sanity check for platforms to prevent obscure errors later.
|
217 |
+
if plat_name not in PLAT_TO_VCVARS:
|
218 |
+
raise DistutilsPlatformError("--plat-name must be one of {}"
|
219 |
+
.format(tuple(PLAT_TO_VCVARS)))
|
220 |
+
|
221 |
+
# Get the vcvarsall.bat spec for the requested platform.
|
222 |
+
plat_spec = PLAT_TO_VCVARS[plat_name]
|
223 |
+
|
224 |
+
vc_env = _get_vc_env(plat_spec)
|
225 |
+
if not vc_env:
|
226 |
+
raise DistutilsPlatformError("Unable to find a compatible "
|
227 |
+
"Visual Studio installation.")
|
228 |
+
|
229 |
+
self._paths = vc_env.get('path', '')
|
230 |
+
paths = self._paths.split(os.pathsep)
|
231 |
+
self.cc = _find_exe("cl.exe", paths)
|
232 |
+
self.linker = _find_exe("link.exe", paths)
|
233 |
+
self.lib = _find_exe("lib.exe", paths)
|
234 |
+
self.rc = _find_exe("rc.exe", paths) # resource compiler
|
235 |
+
self.mc = _find_exe("mc.exe", paths) # message compiler
|
236 |
+
self.mt = _find_exe("mt.exe", paths) # message compiler
|
237 |
+
|
238 |
+
for dir in vc_env.get('include', '').split(os.pathsep):
|
239 |
+
if dir:
|
240 |
+
self.add_include_dir(dir.rstrip(os.sep))
|
241 |
+
|
242 |
+
for dir in vc_env.get('lib', '').split(os.pathsep):
|
243 |
+
if dir:
|
244 |
+
self.add_library_dir(dir.rstrip(os.sep))
|
245 |
+
|
246 |
+
self.preprocess_options = None
|
247 |
+
# bpo-38597: Always compile with dynamic linking
|
248 |
+
# Future releases of Python 3.x will include all past
|
249 |
+
# versions of vcruntime*.dll for compatibility.
|
250 |
+
self.compile_options = [
|
251 |
+
'/nologo', '/O2', '/W3', '/GL', '/DNDEBUG', '/MD'
|
252 |
+
]
|
253 |
+
|
254 |
+
self.compile_options_debug = [
|
255 |
+
'/nologo', '/Od', '/MDd', '/Zi', '/W3', '/D_DEBUG'
|
256 |
+
]
|
257 |
+
|
258 |
+
ldflags = [
|
259 |
+
'/nologo', '/INCREMENTAL:NO', '/LTCG'
|
260 |
+
]
|
261 |
+
|
262 |
+
ldflags_debug = [
|
263 |
+
'/nologo', '/INCREMENTAL:NO', '/LTCG', '/DEBUG:FULL'
|
264 |
+
]
|
265 |
+
|
266 |
+
self.ldflags_exe = [*ldflags, '/MANIFEST:EMBED,ID=1']
|
267 |
+
self.ldflags_exe_debug = [*ldflags_debug, '/MANIFEST:EMBED,ID=1']
|
268 |
+
self.ldflags_shared = [*ldflags, '/DLL', '/MANIFEST:EMBED,ID=2', '/MANIFESTUAC:NO']
|
269 |
+
self.ldflags_shared_debug = [*ldflags_debug, '/DLL', '/MANIFEST:EMBED,ID=2', '/MANIFESTUAC:NO']
|
270 |
+
self.ldflags_static = [*ldflags]
|
271 |
+
self.ldflags_static_debug = [*ldflags_debug]
|
272 |
+
|
273 |
+
self._ldflags = {
|
274 |
+
(CCompiler.EXECUTABLE, None): self.ldflags_exe,
|
275 |
+
(CCompiler.EXECUTABLE, False): self.ldflags_exe,
|
276 |
+
(CCompiler.EXECUTABLE, True): self.ldflags_exe_debug,
|
277 |
+
(CCompiler.SHARED_OBJECT, None): self.ldflags_shared,
|
278 |
+
(CCompiler.SHARED_OBJECT, False): self.ldflags_shared,
|
279 |
+
(CCompiler.SHARED_OBJECT, True): self.ldflags_shared_debug,
|
280 |
+
(CCompiler.SHARED_LIBRARY, None): self.ldflags_static,
|
281 |
+
(CCompiler.SHARED_LIBRARY, False): self.ldflags_static,
|
282 |
+
(CCompiler.SHARED_LIBRARY, True): self.ldflags_static_debug,
|
283 |
+
}
|
284 |
+
|
285 |
+
self.initialized = True
|
286 |
+
|
287 |
+
# -- Worker methods ------------------------------------------------
|
288 |
+
|
289 |
+
def object_filenames(self,
|
290 |
+
source_filenames,
|
291 |
+
strip_dir=0,
|
292 |
+
output_dir=''):
|
293 |
+
ext_map = {
|
294 |
+
**{ext: self.obj_extension for ext in self.src_extensions},
|
295 |
+
**{ext: self.res_extension for ext in self._rc_extensions + self._mc_extensions},
|
296 |
+
}
|
297 |
+
|
298 |
+
output_dir = output_dir or ''
|
299 |
+
|
300 |
+
def make_out_path(p):
|
301 |
+
base, ext = os.path.splitext(p)
|
302 |
+
if strip_dir:
|
303 |
+
base = os.path.basename(base)
|
304 |
+
else:
|
305 |
+
_, base = os.path.splitdrive(base)
|
306 |
+
if base.startswith((os.path.sep, os.path.altsep)):
|
307 |
+
base = base[1:]
|
308 |
+
try:
|
309 |
+
# XXX: This may produce absurdly long paths. We should check
|
310 |
+
# the length of the result and trim base until we fit within
|
311 |
+
# 260 characters.
|
312 |
+
return os.path.join(output_dir, base + ext_map[ext])
|
313 |
+
except LookupError:
|
314 |
+
# Better to raise an exception instead of silently continuing
|
315 |
+
# and later complain about sources and targets having
|
316 |
+
# different lengths
|
317 |
+
raise CompileError("Don't know how to compile {}".format(p))
|
318 |
+
|
319 |
+
return list(map(make_out_path, source_filenames))
|
320 |
+
|
321 |
+
|
322 |
+
def compile(self, sources,
|
323 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
324 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
325 |
+
|
326 |
+
if not self.initialized:
|
327 |
+
self.initialize()
|
328 |
+
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
329 |
+
sources, depends, extra_postargs)
|
330 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
331 |
+
|
332 |
+
compile_opts = extra_preargs or []
|
333 |
+
compile_opts.append('/c')
|
334 |
+
if debug:
|
335 |
+
compile_opts.extend(self.compile_options_debug)
|
336 |
+
else:
|
337 |
+
compile_opts.extend(self.compile_options)
|
338 |
+
|
339 |
+
|
340 |
+
add_cpp_opts = False
|
341 |
+
|
342 |
+
for obj in objects:
|
343 |
+
try:
|
344 |
+
src, ext = build[obj]
|
345 |
+
except KeyError:
|
346 |
+
continue
|
347 |
+
if debug:
|
348 |
+
# pass the full pathname to MSVC in debug mode,
|
349 |
+
# this allows the debugger to find the source file
|
350 |
+
# without asking the user to browse for it
|
351 |
+
src = os.path.abspath(src)
|
352 |
+
|
353 |
+
if ext in self._c_extensions:
|
354 |
+
input_opt = "/Tc" + src
|
355 |
+
elif ext in self._cpp_extensions:
|
356 |
+
input_opt = "/Tp" + src
|
357 |
+
add_cpp_opts = True
|
358 |
+
elif ext in self._rc_extensions:
|
359 |
+
# compile .RC to .RES file
|
360 |
+
input_opt = src
|
361 |
+
output_opt = "/fo" + obj
|
362 |
+
try:
|
363 |
+
self.spawn([self.rc] + pp_opts + [output_opt, input_opt])
|
364 |
+
except DistutilsExecError as msg:
|
365 |
+
raise CompileError(msg)
|
366 |
+
continue
|
367 |
+
elif ext in self._mc_extensions:
|
368 |
+
# Compile .MC to .RC file to .RES file.
|
369 |
+
# * '-h dir' specifies the directory for the
|
370 |
+
# generated include file
|
371 |
+
# * '-r dir' specifies the target directory of the
|
372 |
+
# generated RC file and the binary message resource
|
373 |
+
# it includes
|
374 |
+
#
|
375 |
+
# For now (since there are no options to change this),
|
376 |
+
# we use the source-directory for the include file and
|
377 |
+
# the build directory for the RC file and message
|
378 |
+
# resources. This works at least for win32all.
|
379 |
+
h_dir = os.path.dirname(src)
|
380 |
+
rc_dir = os.path.dirname(obj)
|
381 |
+
try:
|
382 |
+
# first compile .MC to .RC and .H file
|
383 |
+
self.spawn([self.mc, '-h', h_dir, '-r', rc_dir, src])
|
384 |
+
base, _ = os.path.splitext(os.path.basename (src))
|
385 |
+
rc_file = os.path.join(rc_dir, base + '.rc')
|
386 |
+
# then compile .RC to .RES file
|
387 |
+
self.spawn([self.rc, "/fo" + obj, rc_file])
|
388 |
+
|
389 |
+
except DistutilsExecError as msg:
|
390 |
+
raise CompileError(msg)
|
391 |
+
continue
|
392 |
+
else:
|
393 |
+
# how to handle this file?
|
394 |
+
raise CompileError("Don't know how to compile {} to {}"
|
395 |
+
.format(src, obj))
|
396 |
+
|
397 |
+
args = [self.cc] + compile_opts + pp_opts
|
398 |
+
if add_cpp_opts:
|
399 |
+
args.append('/EHsc')
|
400 |
+
args.append(input_opt)
|
401 |
+
args.append("/Fo" + obj)
|
402 |
+
args.extend(extra_postargs)
|
403 |
+
|
404 |
+
try:
|
405 |
+
self.spawn(args)
|
406 |
+
except DistutilsExecError as msg:
|
407 |
+
raise CompileError(msg)
|
408 |
+
|
409 |
+
return objects
|
410 |
+
|
411 |
+
|
412 |
+
def create_static_lib(self,
|
413 |
+
objects,
|
414 |
+
output_libname,
|
415 |
+
output_dir=None,
|
416 |
+
debug=0,
|
417 |
+
target_lang=None):
|
418 |
+
|
419 |
+
if not self.initialized:
|
420 |
+
self.initialize()
|
421 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
422 |
+
output_filename = self.library_filename(output_libname,
|
423 |
+
output_dir=output_dir)
|
424 |
+
|
425 |
+
if self._need_link(objects, output_filename):
|
426 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
427 |
+
if debug:
|
428 |
+
pass # XXX what goes here?
|
429 |
+
try:
|
430 |
+
log.debug('Executing "%s" %s', self.lib, ' '.join(lib_args))
|
431 |
+
self.spawn([self.lib] + lib_args)
|
432 |
+
except DistutilsExecError as msg:
|
433 |
+
raise LibError(msg)
|
434 |
+
else:
|
435 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
436 |
+
|
437 |
+
|
438 |
+
def link(self,
|
439 |
+
target_desc,
|
440 |
+
objects,
|
441 |
+
output_filename,
|
442 |
+
output_dir=None,
|
443 |
+
libraries=None,
|
444 |
+
library_dirs=None,
|
445 |
+
runtime_library_dirs=None,
|
446 |
+
export_symbols=None,
|
447 |
+
debug=0,
|
448 |
+
extra_preargs=None,
|
449 |
+
extra_postargs=None,
|
450 |
+
build_temp=None,
|
451 |
+
target_lang=None):
|
452 |
+
|
453 |
+
if not self.initialized:
|
454 |
+
self.initialize()
|
455 |
+
objects, output_dir = self._fix_object_args(objects, output_dir)
|
456 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
457 |
+
runtime_library_dirs)
|
458 |
+
libraries, library_dirs, runtime_library_dirs = fixed_args
|
459 |
+
|
460 |
+
if runtime_library_dirs:
|
461 |
+
self.warn("I don't know what to do with 'runtime_library_dirs': "
|
462 |
+
+ str(runtime_library_dirs))
|
463 |
+
|
464 |
+
lib_opts = gen_lib_options(self,
|
465 |
+
library_dirs, runtime_library_dirs,
|
466 |
+
libraries)
|
467 |
+
if output_dir is not None:
|
468 |
+
output_filename = os.path.join(output_dir, output_filename)
|
469 |
+
|
470 |
+
if self._need_link(objects, output_filename):
|
471 |
+
ldflags = self._ldflags[target_desc, debug]
|
472 |
+
|
473 |
+
export_opts = ["/EXPORT:" + sym for sym in (export_symbols or [])]
|
474 |
+
|
475 |
+
ld_args = (ldflags + lib_opts + export_opts +
|
476 |
+
objects + ['/OUT:' + output_filename])
|
477 |
+
|
478 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
479 |
+
# suppressed by any linker switches. The .lib files may even be
|
480 |
+
# needed! Make sure they are generated in the temporary build
|
481 |
+
# directory. Since they have different names for debug and release
|
482 |
+
# builds, they can go into the same directory.
|
483 |
+
build_temp = os.path.dirname(objects[0])
|
484 |
+
if export_symbols is not None:
|
485 |
+
(dll_name, dll_ext) = os.path.splitext(
|
486 |
+
os.path.basename(output_filename))
|
487 |
+
implib_file = os.path.join(
|
488 |
+
build_temp,
|
489 |
+
self.library_filename(dll_name))
|
490 |
+
ld_args.append ('/IMPLIB:' + implib_file)
|
491 |
+
|
492 |
+
if extra_preargs:
|
493 |
+
ld_args[:0] = extra_preargs
|
494 |
+
if extra_postargs:
|
495 |
+
ld_args.extend(extra_postargs)
|
496 |
+
|
497 |
+
output_dir = os.path.dirname(os.path.abspath(output_filename))
|
498 |
+
self.mkpath(output_dir)
|
499 |
+
try:
|
500 |
+
log.debug('Executing "%s" %s', self.linker, ' '.join(ld_args))
|
501 |
+
self.spawn([self.linker] + ld_args)
|
502 |
+
except DistutilsExecError as msg:
|
503 |
+
raise LinkError(msg)
|
504 |
+
else:
|
505 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
506 |
+
|
507 |
+
def spawn(self, cmd):
|
508 |
+
env = dict(os.environ, PATH=self._paths)
|
509 |
+
with self._fallback_spawn(cmd, env) as fallback:
|
510 |
+
return super().spawn(cmd, env=env)
|
511 |
+
return fallback.value
|
512 |
+
|
513 |
+
@contextlib.contextmanager
|
514 |
+
def _fallback_spawn(self, cmd, env):
|
515 |
+
"""
|
516 |
+
Discovered in pypa/distutils#15, some tools monkeypatch the compiler,
|
517 |
+
so the 'env' kwarg causes a TypeError. Detect this condition and
|
518 |
+
restore the legacy, unsafe behavior.
|
519 |
+
"""
|
520 |
+
bag = type('Bag', (), {})()
|
521 |
+
try:
|
522 |
+
yield bag
|
523 |
+
except TypeError as exc:
|
524 |
+
if "unexpected keyword argument 'env'" not in str(exc):
|
525 |
+
raise
|
526 |
+
else:
|
527 |
+
return
|
528 |
+
warnings.warn(
|
529 |
+
"Fallback spawn triggered. Please update distutils monkeypatch.")
|
530 |
+
with unittest.mock.patch('os.environ', env):
|
531 |
+
bag.value = super().spawn(cmd)
|
532 |
+
|
533 |
+
# -- Miscellaneous methods -----------------------------------------
|
534 |
+
# These are all used by the 'gen_lib_options() function, in
|
535 |
+
# ccompiler.py.
|
536 |
+
|
537 |
+
def library_dir_option(self, dir):
|
538 |
+
return "/LIBPATH:" + dir
|
539 |
+
|
540 |
+
def runtime_library_dir_option(self, dir):
|
541 |
+
raise DistutilsPlatformError(
|
542 |
+
"don't know how to set runtime library search path for MSVC")
|
543 |
+
|
544 |
+
def library_option(self, lib):
|
545 |
+
return self.library_filename(lib)
|
546 |
+
|
547 |
+
def find_library_file(self, dirs, lib, debug=0):
|
548 |
+
# Prefer a debugging library if found (and requested), but deal
|
549 |
+
# with it if we don't have one.
|
550 |
+
if debug:
|
551 |
+
try_names = [lib + "_d", lib]
|
552 |
+
else:
|
553 |
+
try_names = [lib]
|
554 |
+
for dir in dirs:
|
555 |
+
for name in try_names:
|
556 |
+
libfile = os.path.join(dir, self.library_filename(name))
|
557 |
+
if os.path.isfile(libfile):
|
558 |
+
return libfile
|
559 |
+
else:
|
560 |
+
# Oops, didn't find it in *any* of 'dirs'
|
561 |
+
return None
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/archive_util.py
ADDED
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.archive_util
|
2 |
+
|
3 |
+
Utility functions for creating archive files (tarballs, zip files,
|
4 |
+
that sort of thing)."""
|
5 |
+
|
6 |
+
import os
|
7 |
+
from warnings import warn
|
8 |
+
import sys
|
9 |
+
|
10 |
+
try:
|
11 |
+
import zipfile
|
12 |
+
except ImportError:
|
13 |
+
zipfile = None
|
14 |
+
|
15 |
+
|
16 |
+
from distutils.errors import DistutilsExecError
|
17 |
+
from distutils.spawn import spawn
|
18 |
+
from distutils.dir_util import mkpath
|
19 |
+
from distutils import log
|
20 |
+
|
21 |
+
try:
|
22 |
+
from pwd import getpwnam
|
23 |
+
except ImportError:
|
24 |
+
getpwnam = None
|
25 |
+
|
26 |
+
try:
|
27 |
+
from grp import getgrnam
|
28 |
+
except ImportError:
|
29 |
+
getgrnam = None
|
30 |
+
|
31 |
+
def _get_gid(name):
|
32 |
+
"""Returns a gid, given a group name."""
|
33 |
+
if getgrnam is None or name is None:
|
34 |
+
return None
|
35 |
+
try:
|
36 |
+
result = getgrnam(name)
|
37 |
+
except KeyError:
|
38 |
+
result = None
|
39 |
+
if result is not None:
|
40 |
+
return result[2]
|
41 |
+
return None
|
42 |
+
|
43 |
+
def _get_uid(name):
|
44 |
+
"""Returns an uid, given a user name."""
|
45 |
+
if getpwnam is None or name is None:
|
46 |
+
return None
|
47 |
+
try:
|
48 |
+
result = getpwnam(name)
|
49 |
+
except KeyError:
|
50 |
+
result = None
|
51 |
+
if result is not None:
|
52 |
+
return result[2]
|
53 |
+
return None
|
54 |
+
|
55 |
+
def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
|
56 |
+
owner=None, group=None):
|
57 |
+
"""Create a (possibly compressed) tar file from all the files under
|
58 |
+
'base_dir'.
|
59 |
+
|
60 |
+
'compress' must be "gzip" (the default), "bzip2", "xz", "compress", or
|
61 |
+
None. ("compress" will be deprecated in Python 3.2)
|
62 |
+
|
63 |
+
'owner' and 'group' can be used to define an owner and a group for the
|
64 |
+
archive that is being built. If not provided, the current owner and group
|
65 |
+
will be used.
|
66 |
+
|
67 |
+
The output tar file will be named 'base_dir' + ".tar", possibly plus
|
68 |
+
the appropriate compression extension (".gz", ".bz2", ".xz" or ".Z").
|
69 |
+
|
70 |
+
Returns the output filename.
|
71 |
+
"""
|
72 |
+
tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', 'xz': 'xz', None: '',
|
73 |
+
'compress': ''}
|
74 |
+
compress_ext = {'gzip': '.gz', 'bzip2': '.bz2', 'xz': '.xz',
|
75 |
+
'compress': '.Z'}
|
76 |
+
|
77 |
+
# flags for compression program, each element of list will be an argument
|
78 |
+
if compress is not None and compress not in compress_ext.keys():
|
79 |
+
raise ValueError(
|
80 |
+
"bad value for 'compress': must be None, 'gzip', 'bzip2', "
|
81 |
+
"'xz' or 'compress'")
|
82 |
+
|
83 |
+
archive_name = base_name + '.tar'
|
84 |
+
if compress != 'compress':
|
85 |
+
archive_name += compress_ext.get(compress, '')
|
86 |
+
|
87 |
+
mkpath(os.path.dirname(archive_name), dry_run=dry_run)
|
88 |
+
|
89 |
+
# creating the tarball
|
90 |
+
import tarfile # late import so Python build itself doesn't break
|
91 |
+
|
92 |
+
log.info('Creating tar archive')
|
93 |
+
|
94 |
+
uid = _get_uid(owner)
|
95 |
+
gid = _get_gid(group)
|
96 |
+
|
97 |
+
def _set_uid_gid(tarinfo):
|
98 |
+
if gid is not None:
|
99 |
+
tarinfo.gid = gid
|
100 |
+
tarinfo.gname = group
|
101 |
+
if uid is not None:
|
102 |
+
tarinfo.uid = uid
|
103 |
+
tarinfo.uname = owner
|
104 |
+
return tarinfo
|
105 |
+
|
106 |
+
if not dry_run:
|
107 |
+
tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress])
|
108 |
+
try:
|
109 |
+
tar.add(base_dir, filter=_set_uid_gid)
|
110 |
+
finally:
|
111 |
+
tar.close()
|
112 |
+
|
113 |
+
# compression using `compress`
|
114 |
+
if compress == 'compress':
|
115 |
+
warn("'compress' will be deprecated.", PendingDeprecationWarning)
|
116 |
+
# the option varies depending on the platform
|
117 |
+
compressed_name = archive_name + compress_ext[compress]
|
118 |
+
if sys.platform == 'win32':
|
119 |
+
cmd = [compress, archive_name, compressed_name]
|
120 |
+
else:
|
121 |
+
cmd = [compress, '-f', archive_name]
|
122 |
+
spawn(cmd, dry_run=dry_run)
|
123 |
+
return compressed_name
|
124 |
+
|
125 |
+
return archive_name
|
126 |
+
|
127 |
+
def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
|
128 |
+
"""Create a zip file from all the files under 'base_dir'.
|
129 |
+
|
130 |
+
The output zip file will be named 'base_name' + ".zip". Uses either the
|
131 |
+
"zipfile" Python module (if available) or the InfoZIP "zip" utility
|
132 |
+
(if installed and found on the default search path). If neither tool is
|
133 |
+
available, raises DistutilsExecError. Returns the name of the output zip
|
134 |
+
file.
|
135 |
+
"""
|
136 |
+
zip_filename = base_name + ".zip"
|
137 |
+
mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
|
138 |
+
|
139 |
+
# If zipfile module is not available, try spawning an external
|
140 |
+
# 'zip' command.
|
141 |
+
if zipfile is None:
|
142 |
+
if verbose:
|
143 |
+
zipoptions = "-r"
|
144 |
+
else:
|
145 |
+
zipoptions = "-rq"
|
146 |
+
|
147 |
+
try:
|
148 |
+
spawn(["zip", zipoptions, zip_filename, base_dir],
|
149 |
+
dry_run=dry_run)
|
150 |
+
except DistutilsExecError:
|
151 |
+
# XXX really should distinguish between "couldn't find
|
152 |
+
# external 'zip' command" and "zip failed".
|
153 |
+
raise DistutilsExecError(("unable to create zip file '%s': "
|
154 |
+
"could neither import the 'zipfile' module nor "
|
155 |
+
"find a standalone zip utility") % zip_filename)
|
156 |
+
|
157 |
+
else:
|
158 |
+
log.info("creating '%s' and adding '%s' to it",
|
159 |
+
zip_filename, base_dir)
|
160 |
+
|
161 |
+
if not dry_run:
|
162 |
+
try:
|
163 |
+
zip = zipfile.ZipFile(zip_filename, "w",
|
164 |
+
compression=zipfile.ZIP_DEFLATED)
|
165 |
+
except RuntimeError:
|
166 |
+
zip = zipfile.ZipFile(zip_filename, "w",
|
167 |
+
compression=zipfile.ZIP_STORED)
|
168 |
+
|
169 |
+
with zip:
|
170 |
+
if base_dir != os.curdir:
|
171 |
+
path = os.path.normpath(os.path.join(base_dir, ''))
|
172 |
+
zip.write(path, path)
|
173 |
+
log.info("adding '%s'", path)
|
174 |
+
for dirpath, dirnames, filenames in os.walk(base_dir):
|
175 |
+
for name in dirnames:
|
176 |
+
path = os.path.normpath(os.path.join(dirpath, name, ''))
|
177 |
+
zip.write(path, path)
|
178 |
+
log.info("adding '%s'", path)
|
179 |
+
for name in filenames:
|
180 |
+
path = os.path.normpath(os.path.join(dirpath, name))
|
181 |
+
if os.path.isfile(path):
|
182 |
+
zip.write(path, path)
|
183 |
+
log.info("adding '%s'", path)
|
184 |
+
|
185 |
+
return zip_filename
|
186 |
+
|
187 |
+
ARCHIVE_FORMATS = {
|
188 |
+
'gztar': (make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
|
189 |
+
'bztar': (make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file"),
|
190 |
+
'xztar': (make_tarball, [('compress', 'xz')], "xz'ed tar-file"),
|
191 |
+
'ztar': (make_tarball, [('compress', 'compress')], "compressed tar file"),
|
192 |
+
'tar': (make_tarball, [('compress', None)], "uncompressed tar file"),
|
193 |
+
'zip': (make_zipfile, [],"ZIP file")
|
194 |
+
}
|
195 |
+
|
196 |
+
def check_archive_formats(formats):
|
197 |
+
"""Returns the first format from the 'format' list that is unknown.
|
198 |
+
|
199 |
+
If all formats are known, returns None
|
200 |
+
"""
|
201 |
+
for format in formats:
|
202 |
+
if format not in ARCHIVE_FORMATS:
|
203 |
+
return format
|
204 |
+
return None
|
205 |
+
|
206 |
+
def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
|
207 |
+
dry_run=0, owner=None, group=None):
|
208 |
+
"""Create an archive file (eg. zip or tar).
|
209 |
+
|
210 |
+
'base_name' is the name of the file to create, minus any format-specific
|
211 |
+
extension; 'format' is the archive format: one of "zip", "tar", "gztar",
|
212 |
+
"bztar", "xztar", or "ztar".
|
213 |
+
|
214 |
+
'root_dir' is a directory that will be the root directory of the
|
215 |
+
archive; ie. we typically chdir into 'root_dir' before creating the
|
216 |
+
archive. 'base_dir' is the directory where we start archiving from;
|
217 |
+
ie. 'base_dir' will be the common prefix of all files and
|
218 |
+
directories in the archive. 'root_dir' and 'base_dir' both default
|
219 |
+
to the current directory. Returns the name of the archive file.
|
220 |
+
|
221 |
+
'owner' and 'group' are used when creating a tar archive. By default,
|
222 |
+
uses the current owner and group.
|
223 |
+
"""
|
224 |
+
save_cwd = os.getcwd()
|
225 |
+
if root_dir is not None:
|
226 |
+
log.debug("changing into '%s'", root_dir)
|
227 |
+
base_name = os.path.abspath(base_name)
|
228 |
+
if not dry_run:
|
229 |
+
os.chdir(root_dir)
|
230 |
+
|
231 |
+
if base_dir is None:
|
232 |
+
base_dir = os.curdir
|
233 |
+
|
234 |
+
kwargs = {'dry_run': dry_run}
|
235 |
+
|
236 |
+
try:
|
237 |
+
format_info = ARCHIVE_FORMATS[format]
|
238 |
+
except KeyError:
|
239 |
+
raise ValueError("unknown archive format '%s'" % format)
|
240 |
+
|
241 |
+
func = format_info[0]
|
242 |
+
for arg, val in format_info[1]:
|
243 |
+
kwargs[arg] = val
|
244 |
+
|
245 |
+
if format != 'zip':
|
246 |
+
kwargs['owner'] = owner
|
247 |
+
kwargs['group'] = group
|
248 |
+
|
249 |
+
try:
|
250 |
+
filename = func(base_name, base_dir, **kwargs)
|
251 |
+
finally:
|
252 |
+
if root_dir is not None:
|
253 |
+
log.debug("changing back to '%s'", save_cwd)
|
254 |
+
os.chdir(save_cwd)
|
255 |
+
|
256 |
+
return filename
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/bcppcompiler.py
ADDED
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.bcppcompiler
|
2 |
+
|
3 |
+
Contains BorlandCCompiler, an implementation of the abstract CCompiler class
|
4 |
+
for the Borland C++ compiler.
|
5 |
+
"""
|
6 |
+
|
7 |
+
# This implementation by Lyle Johnson, based on the original msvccompiler.py
|
8 |
+
# module and using the directions originally published by Gordon Williams.
|
9 |
+
|
10 |
+
# XXX looks like there's a LOT of overlap between these two classes:
|
11 |
+
# someone should sit down and factor out the common code as
|
12 |
+
# WindowsCCompiler! --GPW
|
13 |
+
|
14 |
+
|
15 |
+
import os
|
16 |
+
from distutils.errors import \
|
17 |
+
DistutilsExecError, \
|
18 |
+
CompileError, LibError, LinkError, UnknownFileError
|
19 |
+
from distutils.ccompiler import \
|
20 |
+
CCompiler, gen_preprocess_options
|
21 |
+
from distutils.file_util import write_file
|
22 |
+
from distutils.dep_util import newer
|
23 |
+
from distutils import log
|
24 |
+
|
25 |
+
class BCPPCompiler(CCompiler) :
|
26 |
+
"""Concrete class that implements an interface to the Borland C/C++
|
27 |
+
compiler, as defined by the CCompiler abstract class.
|
28 |
+
"""
|
29 |
+
|
30 |
+
compiler_type = 'bcpp'
|
31 |
+
|
32 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
33 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
34 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
35 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
36 |
+
# though, so it's worth thinking about.
|
37 |
+
executables = {}
|
38 |
+
|
39 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
40 |
+
_c_extensions = ['.c']
|
41 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
42 |
+
|
43 |
+
# Needed for the filename generation methods provided by the
|
44 |
+
# base class, CCompiler.
|
45 |
+
src_extensions = _c_extensions + _cpp_extensions
|
46 |
+
obj_extension = '.obj'
|
47 |
+
static_lib_extension = '.lib'
|
48 |
+
shared_lib_extension = '.dll'
|
49 |
+
static_lib_format = shared_lib_format = '%s%s'
|
50 |
+
exe_extension = '.exe'
|
51 |
+
|
52 |
+
|
53 |
+
def __init__ (self,
|
54 |
+
verbose=0,
|
55 |
+
dry_run=0,
|
56 |
+
force=0):
|
57 |
+
|
58 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
59 |
+
|
60 |
+
# These executables are assumed to all be in the path.
|
61 |
+
# Borland doesn't seem to use any special registry settings to
|
62 |
+
# indicate their installation locations.
|
63 |
+
|
64 |
+
self.cc = "bcc32.exe"
|
65 |
+
self.linker = "ilink32.exe"
|
66 |
+
self.lib = "tlib.exe"
|
67 |
+
|
68 |
+
self.preprocess_options = None
|
69 |
+
self.compile_options = ['/tWM', '/O2', '/q', '/g0']
|
70 |
+
self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0']
|
71 |
+
|
72 |
+
self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x']
|
73 |
+
self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']
|
74 |
+
self.ldflags_static = []
|
75 |
+
self.ldflags_exe = ['/Gn', '/q', '/x']
|
76 |
+
self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r']
|
77 |
+
|
78 |
+
|
79 |
+
# -- Worker methods ------------------------------------------------
|
80 |
+
|
81 |
+
def compile(self, sources,
|
82 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
83 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
84 |
+
|
85 |
+
macros, objects, extra_postargs, pp_opts, build = \
|
86 |
+
self._setup_compile(output_dir, macros, include_dirs, sources,
|
87 |
+
depends, extra_postargs)
|
88 |
+
compile_opts = extra_preargs or []
|
89 |
+
compile_opts.append ('-c')
|
90 |
+
if debug:
|
91 |
+
compile_opts.extend (self.compile_options_debug)
|
92 |
+
else:
|
93 |
+
compile_opts.extend (self.compile_options)
|
94 |
+
|
95 |
+
for obj in objects:
|
96 |
+
try:
|
97 |
+
src, ext = build[obj]
|
98 |
+
except KeyError:
|
99 |
+
continue
|
100 |
+
# XXX why do the normpath here?
|
101 |
+
src = os.path.normpath(src)
|
102 |
+
obj = os.path.normpath(obj)
|
103 |
+
# XXX _setup_compile() did a mkpath() too but before the normpath.
|
104 |
+
# Is it possible to skip the normpath?
|
105 |
+
self.mkpath(os.path.dirname(obj))
|
106 |
+
|
107 |
+
if ext == '.res':
|
108 |
+
# This is already a binary file -- skip it.
|
109 |
+
continue # the 'for' loop
|
110 |
+
if ext == '.rc':
|
111 |
+
# This needs to be compiled to a .res file -- do it now.
|
112 |
+
try:
|
113 |
+
self.spawn (["brcc32", "-fo", obj, src])
|
114 |
+
except DistutilsExecError as msg:
|
115 |
+
raise CompileError(msg)
|
116 |
+
continue # the 'for' loop
|
117 |
+
|
118 |
+
# The next two are both for the real compiler.
|
119 |
+
if ext in self._c_extensions:
|
120 |
+
input_opt = ""
|
121 |
+
elif ext in self._cpp_extensions:
|
122 |
+
input_opt = "-P"
|
123 |
+
else:
|
124 |
+
# Unknown file type -- no extra options. The compiler
|
125 |
+
# will probably fail, but let it just in case this is a
|
126 |
+
# file the compiler recognizes even if we don't.
|
127 |
+
input_opt = ""
|
128 |
+
|
129 |
+
output_opt = "-o" + obj
|
130 |
+
|
131 |
+
# Compiler command line syntax is: "bcc32 [options] file(s)".
|
132 |
+
# Note that the source file names must appear at the end of
|
133 |
+
# the command line.
|
134 |
+
try:
|
135 |
+
self.spawn ([self.cc] + compile_opts + pp_opts +
|
136 |
+
[input_opt, output_opt] +
|
137 |
+
extra_postargs + [src])
|
138 |
+
except DistutilsExecError as msg:
|
139 |
+
raise CompileError(msg)
|
140 |
+
|
141 |
+
return objects
|
142 |
+
|
143 |
+
# compile ()
|
144 |
+
|
145 |
+
|
146 |
+
def create_static_lib (self,
|
147 |
+
objects,
|
148 |
+
output_libname,
|
149 |
+
output_dir=None,
|
150 |
+
debug=0,
|
151 |
+
target_lang=None):
|
152 |
+
|
153 |
+
(objects, output_dir) = self._fix_object_args (objects, output_dir)
|
154 |
+
output_filename = \
|
155 |
+
self.library_filename (output_libname, output_dir=output_dir)
|
156 |
+
|
157 |
+
if self._need_link (objects, output_filename):
|
158 |
+
lib_args = [output_filename, '/u'] + objects
|
159 |
+
if debug:
|
160 |
+
pass # XXX what goes here?
|
161 |
+
try:
|
162 |
+
self.spawn ([self.lib] + lib_args)
|
163 |
+
except DistutilsExecError as msg:
|
164 |
+
raise LibError(msg)
|
165 |
+
else:
|
166 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
167 |
+
|
168 |
+
# create_static_lib ()
|
169 |
+
|
170 |
+
|
171 |
+
def link (self,
|
172 |
+
target_desc,
|
173 |
+
objects,
|
174 |
+
output_filename,
|
175 |
+
output_dir=None,
|
176 |
+
libraries=None,
|
177 |
+
library_dirs=None,
|
178 |
+
runtime_library_dirs=None,
|
179 |
+
export_symbols=None,
|
180 |
+
debug=0,
|
181 |
+
extra_preargs=None,
|
182 |
+
extra_postargs=None,
|
183 |
+
build_temp=None,
|
184 |
+
target_lang=None):
|
185 |
+
|
186 |
+
# XXX this ignores 'build_temp'! should follow the lead of
|
187 |
+
# msvccompiler.py
|
188 |
+
|
189 |
+
(objects, output_dir) = self._fix_object_args (objects, output_dir)
|
190 |
+
(libraries, library_dirs, runtime_library_dirs) = \
|
191 |
+
self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
|
192 |
+
|
193 |
+
if runtime_library_dirs:
|
194 |
+
log.warn("I don't know what to do with 'runtime_library_dirs': %s",
|
195 |
+
str(runtime_library_dirs))
|
196 |
+
|
197 |
+
if output_dir is not None:
|
198 |
+
output_filename = os.path.join (output_dir, output_filename)
|
199 |
+
|
200 |
+
if self._need_link (objects, output_filename):
|
201 |
+
|
202 |
+
# Figure out linker args based on type of target.
|
203 |
+
if target_desc == CCompiler.EXECUTABLE:
|
204 |
+
startup_obj = 'c0w32'
|
205 |
+
if debug:
|
206 |
+
ld_args = self.ldflags_exe_debug[:]
|
207 |
+
else:
|
208 |
+
ld_args = self.ldflags_exe[:]
|
209 |
+
else:
|
210 |
+
startup_obj = 'c0d32'
|
211 |
+
if debug:
|
212 |
+
ld_args = self.ldflags_shared_debug[:]
|
213 |
+
else:
|
214 |
+
ld_args = self.ldflags_shared[:]
|
215 |
+
|
216 |
+
|
217 |
+
# Create a temporary exports file for use by the linker
|
218 |
+
if export_symbols is None:
|
219 |
+
def_file = ''
|
220 |
+
else:
|
221 |
+
head, tail = os.path.split (output_filename)
|
222 |
+
modname, ext = os.path.splitext (tail)
|
223 |
+
temp_dir = os.path.dirname(objects[0]) # preserve tree structure
|
224 |
+
def_file = os.path.join (temp_dir, '%s.def' % modname)
|
225 |
+
contents = ['EXPORTS']
|
226 |
+
for sym in (export_symbols or []):
|
227 |
+
contents.append(' %s=_%s' % (sym, sym))
|
228 |
+
self.execute(write_file, (def_file, contents),
|
229 |
+
"writing %s" % def_file)
|
230 |
+
|
231 |
+
# Borland C++ has problems with '/' in paths
|
232 |
+
objects2 = map(os.path.normpath, objects)
|
233 |
+
# split objects in .obj and .res files
|
234 |
+
# Borland C++ needs them at different positions in the command line
|
235 |
+
objects = [startup_obj]
|
236 |
+
resources = []
|
237 |
+
for file in objects2:
|
238 |
+
(base, ext) = os.path.splitext(os.path.normcase(file))
|
239 |
+
if ext == '.res':
|
240 |
+
resources.append(file)
|
241 |
+
else:
|
242 |
+
objects.append(file)
|
243 |
+
|
244 |
+
|
245 |
+
for l in library_dirs:
|
246 |
+
ld_args.append("/L%s" % os.path.normpath(l))
|
247 |
+
ld_args.append("/L.") # we sometimes use relative paths
|
248 |
+
|
249 |
+
# list of object files
|
250 |
+
ld_args.extend(objects)
|
251 |
+
|
252 |
+
# XXX the command-line syntax for Borland C++ is a bit wonky;
|
253 |
+
# certain filenames are jammed together in one big string, but
|
254 |
+
# comma-delimited. This doesn't mesh too well with the
|
255 |
+
# Unix-centric attitude (with a DOS/Windows quoting hack) of
|
256 |
+
# 'spawn()', so constructing the argument list is a bit
|
257 |
+
# awkward. Note that doing the obvious thing and jamming all
|
258 |
+
# the filenames and commas into one argument would be wrong,
|
259 |
+
# because 'spawn()' would quote any filenames with spaces in
|
260 |
+
# them. Arghghh!. Apparently it works fine as coded...
|
261 |
+
|
262 |
+
# name of dll/exe file
|
263 |
+
ld_args.extend([',',output_filename])
|
264 |
+
# no map file and start libraries
|
265 |
+
ld_args.append(',,')
|
266 |
+
|
267 |
+
for lib in libraries:
|
268 |
+
# see if we find it and if there is a bcpp specific lib
|
269 |
+
# (xxx_bcpp.lib)
|
270 |
+
libfile = self.find_library_file(library_dirs, lib, debug)
|
271 |
+
if libfile is None:
|
272 |
+
ld_args.append(lib)
|
273 |
+
# probably a BCPP internal library -- don't warn
|
274 |
+
else:
|
275 |
+
# full name which prefers bcpp_xxx.lib over xxx.lib
|
276 |
+
ld_args.append(libfile)
|
277 |
+
|
278 |
+
# some default libraries
|
279 |
+
ld_args.append ('import32')
|
280 |
+
ld_args.append ('cw32mt')
|
281 |
+
|
282 |
+
# def file for export symbols
|
283 |
+
ld_args.extend([',',def_file])
|
284 |
+
# add resource files
|
285 |
+
ld_args.append(',')
|
286 |
+
ld_args.extend(resources)
|
287 |
+
|
288 |
+
|
289 |
+
if extra_preargs:
|
290 |
+
ld_args[:0] = extra_preargs
|
291 |
+
if extra_postargs:
|
292 |
+
ld_args.extend(extra_postargs)
|
293 |
+
|
294 |
+
self.mkpath (os.path.dirname (output_filename))
|
295 |
+
try:
|
296 |
+
self.spawn ([self.linker] + ld_args)
|
297 |
+
except DistutilsExecError as msg:
|
298 |
+
raise LinkError(msg)
|
299 |
+
|
300 |
+
else:
|
301 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
302 |
+
|
303 |
+
# link ()
|
304 |
+
|
305 |
+
# -- Miscellaneous methods -----------------------------------------
|
306 |
+
|
307 |
+
|
308 |
+
def find_library_file (self, dirs, lib, debug=0):
|
309 |
+
# List of effective library names to try, in order of preference:
|
310 |
+
# xxx_bcpp.lib is better than xxx.lib
|
311 |
+
# and xxx_d.lib is better than xxx.lib if debug is set
|
312 |
+
#
|
313 |
+
# The "_bcpp" suffix is to handle a Python installation for people
|
314 |
+
# with multiple compilers (primarily Distutils hackers, I suspect
|
315 |
+
# ;-). The idea is they'd have one static library for each
|
316 |
+
# compiler they care about, since (almost?) every Windows compiler
|
317 |
+
# seems to have a different format for static libraries.
|
318 |
+
if debug:
|
319 |
+
dlib = (lib + "_d")
|
320 |
+
try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib)
|
321 |
+
else:
|
322 |
+
try_names = (lib + "_bcpp", lib)
|
323 |
+
|
324 |
+
for dir in dirs:
|
325 |
+
for name in try_names:
|
326 |
+
libfile = os.path.join(dir, self.library_filename(name))
|
327 |
+
if os.path.exists(libfile):
|
328 |
+
return libfile
|
329 |
+
else:
|
330 |
+
# Oops, didn't find it in *any* of 'dirs'
|
331 |
+
return None
|
332 |
+
|
333 |
+
# overwrite the one from CCompiler to support rc and res-files
|
334 |
+
def object_filenames (self,
|
335 |
+
source_filenames,
|
336 |
+
strip_dir=0,
|
337 |
+
output_dir=''):
|
338 |
+
if output_dir is None: output_dir = ''
|
339 |
+
obj_names = []
|
340 |
+
for src_name in source_filenames:
|
341 |
+
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
342 |
+
(base, ext) = os.path.splitext (os.path.normcase(src_name))
|
343 |
+
if ext not in (self.src_extensions + ['.rc','.res']):
|
344 |
+
raise UnknownFileError("unknown file type '%s' (from '%s')" % \
|
345 |
+
(ext, src_name))
|
346 |
+
if strip_dir:
|
347 |
+
base = os.path.basename (base)
|
348 |
+
if ext == '.res':
|
349 |
+
# these can go unchanged
|
350 |
+
obj_names.append (os.path.join (output_dir, base + ext))
|
351 |
+
elif ext == '.rc':
|
352 |
+
# these need to be compiled to .res-files
|
353 |
+
obj_names.append (os.path.join (output_dir, base + '.res'))
|
354 |
+
else:
|
355 |
+
obj_names.append (os.path.join (output_dir,
|
356 |
+
base + self.obj_extension))
|
357 |
+
return obj_names
|
358 |
+
|
359 |
+
# object_filenames ()
|
360 |
+
|
361 |
+
def preprocess (self,
|
362 |
+
source,
|
363 |
+
output_file=None,
|
364 |
+
macros=None,
|
365 |
+
include_dirs=None,
|
366 |
+
extra_preargs=None,
|
367 |
+
extra_postargs=None):
|
368 |
+
|
369 |
+
(_, macros, include_dirs) = \
|
370 |
+
self._fix_compile_args(None, macros, include_dirs)
|
371 |
+
pp_opts = gen_preprocess_options(macros, include_dirs)
|
372 |
+
pp_args = ['cpp32.exe'] + pp_opts
|
373 |
+
if output_file is not None:
|
374 |
+
pp_args.append('-o' + output_file)
|
375 |
+
if extra_preargs:
|
376 |
+
pp_args[:0] = extra_preargs
|
377 |
+
if extra_postargs:
|
378 |
+
pp_args.extend(extra_postargs)
|
379 |
+
pp_args.append(source)
|
380 |
+
|
381 |
+
# We need to preprocess: either we're being forced to, or the
|
382 |
+
# source file is newer than the target (or the target doesn't
|
383 |
+
# exist).
|
384 |
+
if self.force or output_file is None or newer(source, output_file):
|
385 |
+
if output_file:
|
386 |
+
self.mkpath(os.path.dirname(output_file))
|
387 |
+
try:
|
388 |
+
self.spawn(pp_args)
|
389 |
+
except DistutilsExecError as msg:
|
390 |
+
print(msg)
|
391 |
+
raise CompileError(msg)
|
392 |
+
|
393 |
+
# preprocess()
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/ccompiler.py
ADDED
@@ -0,0 +1,1123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.ccompiler
|
2 |
+
|
3 |
+
Contains CCompiler, an abstract base class that defines the interface
|
4 |
+
for the Distutils compiler abstraction model."""
|
5 |
+
|
6 |
+
import sys, os, re
|
7 |
+
from distutils.errors import *
|
8 |
+
from distutils.spawn import spawn
|
9 |
+
from distutils.file_util import move_file
|
10 |
+
from distutils.dir_util import mkpath
|
11 |
+
from distutils.dep_util import newer_group
|
12 |
+
from distutils.util import split_quoted, execute
|
13 |
+
from distutils import log
|
14 |
+
|
15 |
+
class CCompiler:
|
16 |
+
"""Abstract base class to define the interface that must be implemented
|
17 |
+
by real compiler classes. Also has some utility methods used by
|
18 |
+
several compiler classes.
|
19 |
+
|
20 |
+
The basic idea behind a compiler abstraction class is that each
|
21 |
+
instance can be used for all the compile/link steps in building a
|
22 |
+
single project. Thus, attributes common to all of those compile and
|
23 |
+
link steps -- include directories, macros to define, libraries to link
|
24 |
+
against, etc. -- are attributes of the compiler instance. To allow for
|
25 |
+
variability in how individual files are treated, most of those
|
26 |
+
attributes may be varied on a per-compilation or per-link basis.
|
27 |
+
"""
|
28 |
+
|
29 |
+
# 'compiler_type' is a class attribute that identifies this class. It
|
30 |
+
# keeps code that wants to know what kind of compiler it's dealing with
|
31 |
+
# from having to import all possible compiler classes just to do an
|
32 |
+
# 'isinstance'. In concrete CCompiler subclasses, 'compiler_type'
|
33 |
+
# should really, really be one of the keys of the 'compiler_class'
|
34 |
+
# dictionary (see below -- used by the 'new_compiler()' factory
|
35 |
+
# function) -- authors of new compiler interface classes are
|
36 |
+
# responsible for updating 'compiler_class'!
|
37 |
+
compiler_type = None
|
38 |
+
|
39 |
+
# XXX things not handled by this compiler abstraction model:
|
40 |
+
# * client can't provide additional options for a compiler,
|
41 |
+
# e.g. warning, optimization, debugging flags. Perhaps this
|
42 |
+
# should be the domain of concrete compiler abstraction classes
|
43 |
+
# (UnixCCompiler, MSVCCompiler, etc.) -- or perhaps the base
|
44 |
+
# class should have methods for the common ones.
|
45 |
+
# * can't completely override the include or library searchg
|
46 |
+
# path, ie. no "cc -I -Idir1 -Idir2" or "cc -L -Ldir1 -Ldir2".
|
47 |
+
# I'm not sure how widely supported this is even by Unix
|
48 |
+
# compilers, much less on other platforms. And I'm even less
|
49 |
+
# sure how useful it is; maybe for cross-compiling, but
|
50 |
+
# support for that is a ways off. (And anyways, cross
|
51 |
+
# compilers probably have a dedicated binary with the
|
52 |
+
# right paths compiled in. I hope.)
|
53 |
+
# * can't do really freaky things with the library list/library
|
54 |
+
# dirs, e.g. "-Ldir1 -lfoo -Ldir2 -lfoo" to link against
|
55 |
+
# different versions of libfoo.a in different locations. I
|
56 |
+
# think this is useless without the ability to null out the
|
57 |
+
# library search path anyways.
|
58 |
+
|
59 |
+
|
60 |
+
# Subclasses that rely on the standard filename generation methods
|
61 |
+
# implemented below should override these; see the comment near
|
62 |
+
# those methods ('object_filenames()' et. al.) for details:
|
63 |
+
src_extensions = None # list of strings
|
64 |
+
obj_extension = None # string
|
65 |
+
static_lib_extension = None
|
66 |
+
shared_lib_extension = None # string
|
67 |
+
static_lib_format = None # format string
|
68 |
+
shared_lib_format = None # prob. same as static_lib_format
|
69 |
+
exe_extension = None # string
|
70 |
+
|
71 |
+
# Default language settings. language_map is used to detect a source
|
72 |
+
# file or Extension target language, checking source filenames.
|
73 |
+
# language_order is used to detect the language precedence, when deciding
|
74 |
+
# what language to use when mixing source types. For example, if some
|
75 |
+
# extension has two files with ".c" extension, and one with ".cpp", it
|
76 |
+
# is still linked as c++.
|
77 |
+
language_map = {".c" : "c",
|
78 |
+
".cc" : "c++",
|
79 |
+
".cpp" : "c++",
|
80 |
+
".cxx" : "c++",
|
81 |
+
".m" : "objc",
|
82 |
+
}
|
83 |
+
language_order = ["c++", "objc", "c"]
|
84 |
+
|
85 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
86 |
+
self.dry_run = dry_run
|
87 |
+
self.force = force
|
88 |
+
self.verbose = verbose
|
89 |
+
|
90 |
+
# 'output_dir': a common output directory for object, library,
|
91 |
+
# shared object, and shared library files
|
92 |
+
self.output_dir = None
|
93 |
+
|
94 |
+
# 'macros': a list of macro definitions (or undefinitions). A
|
95 |
+
# macro definition is a 2-tuple (name, value), where the value is
|
96 |
+
# either a string or None (no explicit value). A macro
|
97 |
+
# undefinition is a 1-tuple (name,).
|
98 |
+
self.macros = []
|
99 |
+
|
100 |
+
# 'include_dirs': a list of directories to search for include files
|
101 |
+
self.include_dirs = []
|
102 |
+
|
103 |
+
# 'libraries': a list of libraries to include in any link
|
104 |
+
# (library names, not filenames: eg. "foo" not "libfoo.a")
|
105 |
+
self.libraries = []
|
106 |
+
|
107 |
+
# 'library_dirs': a list of directories to search for libraries
|
108 |
+
self.library_dirs = []
|
109 |
+
|
110 |
+
# 'runtime_library_dirs': a list of directories to search for
|
111 |
+
# shared libraries/objects at runtime
|
112 |
+
self.runtime_library_dirs = []
|
113 |
+
|
114 |
+
# 'objects': a list of object files (or similar, such as explicitly
|
115 |
+
# named library files) to include on any link
|
116 |
+
self.objects = []
|
117 |
+
|
118 |
+
for key in self.executables.keys():
|
119 |
+
self.set_executable(key, self.executables[key])
|
120 |
+
|
121 |
+
def set_executables(self, **kwargs):
|
122 |
+
"""Define the executables (and options for them) that will be run
|
123 |
+
to perform the various stages of compilation. The exact set of
|
124 |
+
executables that may be specified here depends on the compiler
|
125 |
+
class (via the 'executables' class attribute), but most will have:
|
126 |
+
compiler the C/C++ compiler
|
127 |
+
linker_so linker used to create shared objects and libraries
|
128 |
+
linker_exe linker used to create binary executables
|
129 |
+
archiver static library creator
|
130 |
+
|
131 |
+
On platforms with a command-line (Unix, DOS/Windows), each of these
|
132 |
+
is a string that will be split into executable name and (optional)
|
133 |
+
list of arguments. (Splitting the string is done similarly to how
|
134 |
+
Unix shells operate: words are delimited by spaces, but quotes and
|
135 |
+
backslashes can override this. See
|
136 |
+
'distutils.util.split_quoted()'.)
|
137 |
+
"""
|
138 |
+
|
139 |
+
# Note that some CCompiler implementation classes will define class
|
140 |
+
# attributes 'cpp', 'cc', etc. with hard-coded executable names;
|
141 |
+
# this is appropriate when a compiler class is for exactly one
|
142 |
+
# compiler/OS combination (eg. MSVCCompiler). Other compiler
|
143 |
+
# classes (UnixCCompiler, in particular) are driven by information
|
144 |
+
# discovered at run-time, since there are many different ways to do
|
145 |
+
# basically the same things with Unix C compilers.
|
146 |
+
|
147 |
+
for key in kwargs:
|
148 |
+
if key not in self.executables:
|
149 |
+
raise ValueError("unknown executable '%s' for class %s" %
|
150 |
+
(key, self.__class__.__name__))
|
151 |
+
self.set_executable(key, kwargs[key])
|
152 |
+
|
153 |
+
def set_executable(self, key, value):
|
154 |
+
if isinstance(value, str):
|
155 |
+
setattr(self, key, split_quoted(value))
|
156 |
+
else:
|
157 |
+
setattr(self, key, value)
|
158 |
+
|
159 |
+
def _find_macro(self, name):
|
160 |
+
i = 0
|
161 |
+
for defn in self.macros:
|
162 |
+
if defn[0] == name:
|
163 |
+
return i
|
164 |
+
i += 1
|
165 |
+
return None
|
166 |
+
|
167 |
+
def _check_macro_definitions(self, definitions):
|
168 |
+
"""Ensures that every element of 'definitions' is a valid macro
|
169 |
+
definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
|
170 |
+
nothing if all definitions are OK, raise TypeError otherwise.
|
171 |
+
"""
|
172 |
+
for defn in definitions:
|
173 |
+
if not (isinstance(defn, tuple) and
|
174 |
+
(len(defn) in (1, 2) and
|
175 |
+
(isinstance (defn[1], str) or defn[1] is None)) and
|
176 |
+
isinstance (defn[0], str)):
|
177 |
+
raise TypeError(("invalid macro definition '%s': " % defn) + \
|
178 |
+
"must be tuple (string,), (string, string), or " + \
|
179 |
+
"(string, None)")
|
180 |
+
|
181 |
+
|
182 |
+
# -- Bookkeeping methods -------------------------------------------
|
183 |
+
|
184 |
+
def define_macro(self, name, value=None):
|
185 |
+
"""Define a preprocessor macro for all compilations driven by this
|
186 |
+
compiler object. The optional parameter 'value' should be a
|
187 |
+
string; if it is not supplied, then the macro will be defined
|
188 |
+
without an explicit value and the exact outcome depends on the
|
189 |
+
compiler used (XXX true? does ANSI say anything about this?)
|
190 |
+
"""
|
191 |
+
# Delete from the list of macro definitions/undefinitions if
|
192 |
+
# already there (so that this one will take precedence).
|
193 |
+
i = self._find_macro (name)
|
194 |
+
if i is not None:
|
195 |
+
del self.macros[i]
|
196 |
+
|
197 |
+
self.macros.append((name, value))
|
198 |
+
|
199 |
+
def undefine_macro(self, name):
|
200 |
+
"""Undefine a preprocessor macro for all compilations driven by
|
201 |
+
this compiler object. If the same macro is defined by
|
202 |
+
'define_macro()' and undefined by 'undefine_macro()' the last call
|
203 |
+
takes precedence (including multiple redefinitions or
|
204 |
+
undefinitions). If the macro is redefined/undefined on a
|
205 |
+
per-compilation basis (ie. in the call to 'compile()'), then that
|
206 |
+
takes precedence.
|
207 |
+
"""
|
208 |
+
# Delete from the list of macro definitions/undefinitions if
|
209 |
+
# already there (so that this one will take precedence).
|
210 |
+
i = self._find_macro (name)
|
211 |
+
if i is not None:
|
212 |
+
del self.macros[i]
|
213 |
+
|
214 |
+
undefn = (name,)
|
215 |
+
self.macros.append(undefn)
|
216 |
+
|
217 |
+
def add_include_dir(self, dir):
|
218 |
+
"""Add 'dir' to the list of directories that will be searched for
|
219 |
+
header files. The compiler is instructed to search directories in
|
220 |
+
the order in which they are supplied by successive calls to
|
221 |
+
'add_include_dir()'.
|
222 |
+
"""
|
223 |
+
self.include_dirs.append(dir)
|
224 |
+
|
225 |
+
def set_include_dirs(self, dirs):
|
226 |
+
"""Set the list of directories that will be searched to 'dirs' (a
|
227 |
+
list of strings). Overrides any preceding calls to
|
228 |
+
'add_include_dir()'; subsequence calls to 'add_include_dir()' add
|
229 |
+
to the list passed to 'set_include_dirs()'. This does not affect
|
230 |
+
any list of standard include directories that the compiler may
|
231 |
+
search by default.
|
232 |
+
"""
|
233 |
+
self.include_dirs = dirs[:]
|
234 |
+
|
235 |
+
def add_library(self, libname):
|
236 |
+
"""Add 'libname' to the list of libraries that will be included in
|
237 |
+
all links driven by this compiler object. Note that 'libname'
|
238 |
+
should *not* be the name of a file containing a library, but the
|
239 |
+
name of the library itself: the actual filename will be inferred by
|
240 |
+
the linker, the compiler, or the compiler class (depending on the
|
241 |
+
platform).
|
242 |
+
|
243 |
+
The linker will be instructed to link against libraries in the
|
244 |
+
order they were supplied to 'add_library()' and/or
|
245 |
+
'set_libraries()'. It is perfectly valid to duplicate library
|
246 |
+
names; the linker will be instructed to link against libraries as
|
247 |
+
many times as they are mentioned.
|
248 |
+
"""
|
249 |
+
self.libraries.append(libname)
|
250 |
+
|
251 |
+
def set_libraries(self, libnames):
|
252 |
+
"""Set the list of libraries to be included in all links driven by
|
253 |
+
this compiler object to 'libnames' (a list of strings). This does
|
254 |
+
not affect any standard system libraries that the linker may
|
255 |
+
include by default.
|
256 |
+
"""
|
257 |
+
self.libraries = libnames[:]
|
258 |
+
|
259 |
+
def add_library_dir(self, dir):
|
260 |
+
"""Add 'dir' to the list of directories that will be searched for
|
261 |
+
libraries specified to 'add_library()' and 'set_libraries()'. The
|
262 |
+
linker will be instructed to search for libraries in the order they
|
263 |
+
are supplied to 'add_library_dir()' and/or 'set_library_dirs()'.
|
264 |
+
"""
|
265 |
+
self.library_dirs.append(dir)
|
266 |
+
|
267 |
+
def set_library_dirs(self, dirs):
|
268 |
+
"""Set the list of library search directories to 'dirs' (a list of
|
269 |
+
strings). This does not affect any standard library search path
|
270 |
+
that the linker may search by default.
|
271 |
+
"""
|
272 |
+
self.library_dirs = dirs[:]
|
273 |
+
|
274 |
+
def add_runtime_library_dir(self, dir):
|
275 |
+
"""Add 'dir' to the list of directories that will be searched for
|
276 |
+
shared libraries at runtime.
|
277 |
+
"""
|
278 |
+
self.runtime_library_dirs.append(dir)
|
279 |
+
|
280 |
+
def set_runtime_library_dirs(self, dirs):
|
281 |
+
"""Set the list of directories to search for shared libraries at
|
282 |
+
runtime to 'dirs' (a list of strings). This does not affect any
|
283 |
+
standard search path that the runtime linker may search by
|
284 |
+
default.
|
285 |
+
"""
|
286 |
+
self.runtime_library_dirs = dirs[:]
|
287 |
+
|
288 |
+
def add_link_object(self, object):
|
289 |
+
"""Add 'object' to the list of object files (or analogues, such as
|
290 |
+
explicitly named library files or the output of "resource
|
291 |
+
compilers") to be included in every link driven by this compiler
|
292 |
+
object.
|
293 |
+
"""
|
294 |
+
self.objects.append(object)
|
295 |
+
|
296 |
+
def set_link_objects(self, objects):
|
297 |
+
"""Set the list of object files (or analogues) to be included in
|
298 |
+
every link to 'objects'. This does not affect any standard object
|
299 |
+
files that the linker may include by default (such as system
|
300 |
+
libraries).
|
301 |
+
"""
|
302 |
+
self.objects = objects[:]
|
303 |
+
|
304 |
+
|
305 |
+
# -- Private utility methods --------------------------------------
|
306 |
+
# (here for the convenience of subclasses)
|
307 |
+
|
308 |
+
# Helper method to prep compiler in subclass compile() methods
|
309 |
+
|
310 |
+
def _setup_compile(self, outdir, macros, incdirs, sources, depends,
|
311 |
+
extra):
|
312 |
+
"""Process arguments and decide which source files to compile."""
|
313 |
+
if outdir is None:
|
314 |
+
outdir = self.output_dir
|
315 |
+
elif not isinstance(outdir, str):
|
316 |
+
raise TypeError("'output_dir' must be a string or None")
|
317 |
+
|
318 |
+
if macros is None:
|
319 |
+
macros = self.macros
|
320 |
+
elif isinstance(macros, list):
|
321 |
+
macros = macros + (self.macros or [])
|
322 |
+
else:
|
323 |
+
raise TypeError("'macros' (if supplied) must be a list of tuples")
|
324 |
+
|
325 |
+
if incdirs is None:
|
326 |
+
incdirs = self.include_dirs
|
327 |
+
elif isinstance(incdirs, (list, tuple)):
|
328 |
+
incdirs = list(incdirs) + (self.include_dirs or [])
|
329 |
+
else:
|
330 |
+
raise TypeError(
|
331 |
+
"'include_dirs' (if supplied) must be a list of strings")
|
332 |
+
|
333 |
+
if extra is None:
|
334 |
+
extra = []
|
335 |
+
|
336 |
+
# Get the list of expected output (object) files
|
337 |
+
objects = self.object_filenames(sources, strip_dir=0,
|
338 |
+
output_dir=outdir)
|
339 |
+
assert len(objects) == len(sources)
|
340 |
+
|
341 |
+
pp_opts = gen_preprocess_options(macros, incdirs)
|
342 |
+
|
343 |
+
build = {}
|
344 |
+
for i in range(len(sources)):
|
345 |
+
src = sources[i]
|
346 |
+
obj = objects[i]
|
347 |
+
ext = os.path.splitext(src)[1]
|
348 |
+
self.mkpath(os.path.dirname(obj))
|
349 |
+
build[obj] = (src, ext)
|
350 |
+
|
351 |
+
return macros, objects, extra, pp_opts, build
|
352 |
+
|
353 |
+
def _get_cc_args(self, pp_opts, debug, before):
|
354 |
+
# works for unixccompiler, cygwinccompiler
|
355 |
+
cc_args = pp_opts + ['-c']
|
356 |
+
if debug:
|
357 |
+
cc_args[:0] = ['-g']
|
358 |
+
if before:
|
359 |
+
cc_args[:0] = before
|
360 |
+
return cc_args
|
361 |
+
|
362 |
+
def _fix_compile_args(self, output_dir, macros, include_dirs):
|
363 |
+
"""Typecheck and fix-up some of the arguments to the 'compile()'
|
364 |
+
method, and return fixed-up values. Specifically: if 'output_dir'
|
365 |
+
is None, replaces it with 'self.output_dir'; ensures that 'macros'
|
366 |
+
is a list, and augments it with 'self.macros'; ensures that
|
367 |
+
'include_dirs' is a list, and augments it with 'self.include_dirs'.
|
368 |
+
Guarantees that the returned values are of the correct type,
|
369 |
+
i.e. for 'output_dir' either string or None, and for 'macros' and
|
370 |
+
'include_dirs' either list or None.
|
371 |
+
"""
|
372 |
+
if output_dir is None:
|
373 |
+
output_dir = self.output_dir
|
374 |
+
elif not isinstance(output_dir, str):
|
375 |
+
raise TypeError("'output_dir' must be a string or None")
|
376 |
+
|
377 |
+
if macros is None:
|
378 |
+
macros = self.macros
|
379 |
+
elif isinstance(macros, list):
|
380 |
+
macros = macros + (self.macros or [])
|
381 |
+
else:
|
382 |
+
raise TypeError("'macros' (if supplied) must be a list of tuples")
|
383 |
+
|
384 |
+
if include_dirs is None:
|
385 |
+
include_dirs = self.include_dirs
|
386 |
+
elif isinstance(include_dirs, (list, tuple)):
|
387 |
+
include_dirs = list(include_dirs) + (self.include_dirs or [])
|
388 |
+
else:
|
389 |
+
raise TypeError(
|
390 |
+
"'include_dirs' (if supplied) must be a list of strings")
|
391 |
+
|
392 |
+
return output_dir, macros, include_dirs
|
393 |
+
|
394 |
+
def _prep_compile(self, sources, output_dir, depends=None):
|
395 |
+
"""Decide which source files must be recompiled.
|
396 |
+
|
397 |
+
Determine the list of object files corresponding to 'sources',
|
398 |
+
and figure out which ones really need to be recompiled.
|
399 |
+
Return a list of all object files and a dictionary telling
|
400 |
+
which source files can be skipped.
|
401 |
+
"""
|
402 |
+
# Get the list of expected output (object) files
|
403 |
+
objects = self.object_filenames(sources, output_dir=output_dir)
|
404 |
+
assert len(objects) == len(sources)
|
405 |
+
|
406 |
+
# Return an empty dict for the "which source files can be skipped"
|
407 |
+
# return value to preserve API compatibility.
|
408 |
+
return objects, {}
|
409 |
+
|
410 |
+
def _fix_object_args(self, objects, output_dir):
|
411 |
+
"""Typecheck and fix up some arguments supplied to various methods.
|
412 |
+
Specifically: ensure that 'objects' is a list; if output_dir is
|
413 |
+
None, replace with self.output_dir. Return fixed versions of
|
414 |
+
'objects' and 'output_dir'.
|
415 |
+
"""
|
416 |
+
if not isinstance(objects, (list, tuple)):
|
417 |
+
raise TypeError("'objects' must be a list or tuple of strings")
|
418 |
+
objects = list(objects)
|
419 |
+
|
420 |
+
if output_dir is None:
|
421 |
+
output_dir = self.output_dir
|
422 |
+
elif not isinstance(output_dir, str):
|
423 |
+
raise TypeError("'output_dir' must be a string or None")
|
424 |
+
|
425 |
+
return (objects, output_dir)
|
426 |
+
|
427 |
+
def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
|
428 |
+
"""Typecheck and fix up some of the arguments supplied to the
|
429 |
+
'link_*' methods. Specifically: ensure that all arguments are
|
430 |
+
lists, and augment them with their permanent versions
|
431 |
+
(eg. 'self.libraries' augments 'libraries'). Return a tuple with
|
432 |
+
fixed versions of all arguments.
|
433 |
+
"""
|
434 |
+
if libraries is None:
|
435 |
+
libraries = self.libraries
|
436 |
+
elif isinstance(libraries, (list, tuple)):
|
437 |
+
libraries = list (libraries) + (self.libraries or [])
|
438 |
+
else:
|
439 |
+
raise TypeError(
|
440 |
+
"'libraries' (if supplied) must be a list of strings")
|
441 |
+
|
442 |
+
if library_dirs is None:
|
443 |
+
library_dirs = self.library_dirs
|
444 |
+
elif isinstance(library_dirs, (list, tuple)):
|
445 |
+
library_dirs = list (library_dirs) + (self.library_dirs or [])
|
446 |
+
else:
|
447 |
+
raise TypeError(
|
448 |
+
"'library_dirs' (if supplied) must be a list of strings")
|
449 |
+
|
450 |
+
if runtime_library_dirs is None:
|
451 |
+
runtime_library_dirs = self.runtime_library_dirs
|
452 |
+
elif isinstance(runtime_library_dirs, (list, tuple)):
|
453 |
+
runtime_library_dirs = (list(runtime_library_dirs) +
|
454 |
+
(self.runtime_library_dirs or []))
|
455 |
+
else:
|
456 |
+
raise TypeError("'runtime_library_dirs' (if supplied) "
|
457 |
+
"must be a list of strings")
|
458 |
+
|
459 |
+
return (libraries, library_dirs, runtime_library_dirs)
|
460 |
+
|
461 |
+
def _need_link(self, objects, output_file):
|
462 |
+
"""Return true if we need to relink the files listed in 'objects'
|
463 |
+
to recreate 'output_file'.
|
464 |
+
"""
|
465 |
+
if self.force:
|
466 |
+
return True
|
467 |
+
else:
|
468 |
+
if self.dry_run:
|
469 |
+
newer = newer_group (objects, output_file, missing='newer')
|
470 |
+
else:
|
471 |
+
newer = newer_group (objects, output_file)
|
472 |
+
return newer
|
473 |
+
|
474 |
+
def detect_language(self, sources):
|
475 |
+
"""Detect the language of a given file, or list of files. Uses
|
476 |
+
language_map, and language_order to do the job.
|
477 |
+
"""
|
478 |
+
if not isinstance(sources, list):
|
479 |
+
sources = [sources]
|
480 |
+
lang = None
|
481 |
+
index = len(self.language_order)
|
482 |
+
for source in sources:
|
483 |
+
base, ext = os.path.splitext(source)
|
484 |
+
extlang = self.language_map.get(ext)
|
485 |
+
try:
|
486 |
+
extindex = self.language_order.index(extlang)
|
487 |
+
if extindex < index:
|
488 |
+
lang = extlang
|
489 |
+
index = extindex
|
490 |
+
except ValueError:
|
491 |
+
pass
|
492 |
+
return lang
|
493 |
+
|
494 |
+
|
495 |
+
# -- Worker methods ------------------------------------------------
|
496 |
+
# (must be implemented by subclasses)
|
497 |
+
|
498 |
+
def preprocess(self, source, output_file=None, macros=None,
|
499 |
+
include_dirs=None, extra_preargs=None, extra_postargs=None):
|
500 |
+
"""Preprocess a single C/C++ source file, named in 'source'.
|
501 |
+
Output will be written to file named 'output_file', or stdout if
|
502 |
+
'output_file' not supplied. 'macros' is a list of macro
|
503 |
+
definitions as for 'compile()', which will augment the macros set
|
504 |
+
with 'define_macro()' and 'undefine_macro()'. 'include_dirs' is a
|
505 |
+
list of directory names that will be added to the default list.
|
506 |
+
|
507 |
+
Raises PreprocessError on failure.
|
508 |
+
"""
|
509 |
+
pass
|
510 |
+
|
511 |
+
def compile(self, sources, output_dir=None, macros=None,
|
512 |
+
include_dirs=None, debug=0, extra_preargs=None,
|
513 |
+
extra_postargs=None, depends=None):
|
514 |
+
"""Compile one or more source files.
|
515 |
+
|
516 |
+
'sources' must be a list of filenames, most likely C/C++
|
517 |
+
files, but in reality anything that can be handled by a
|
518 |
+
particular compiler and compiler class (eg. MSVCCompiler can
|
519 |
+
handle resource files in 'sources'). Return a list of object
|
520 |
+
filenames, one per source filename in 'sources'. Depending on
|
521 |
+
the implementation, not all source files will necessarily be
|
522 |
+
compiled, but all corresponding object filenames will be
|
523 |
+
returned.
|
524 |
+
|
525 |
+
If 'output_dir' is given, object files will be put under it, while
|
526 |
+
retaining their original path component. That is, "foo/bar.c"
|
527 |
+
normally compiles to "foo/bar.o" (for a Unix implementation); if
|
528 |
+
'output_dir' is "build", then it would compile to
|
529 |
+
"build/foo/bar.o".
|
530 |
+
|
531 |
+
'macros', if given, must be a list of macro definitions. A macro
|
532 |
+
definition is either a (name, value) 2-tuple or a (name,) 1-tuple.
|
533 |
+
The former defines a macro; if the value is None, the macro is
|
534 |
+
defined without an explicit value. The 1-tuple case undefines a
|
535 |
+
macro. Later definitions/redefinitions/ undefinitions take
|
536 |
+
precedence.
|
537 |
+
|
538 |
+
'include_dirs', if given, must be a list of strings, the
|
539 |
+
directories to add to the default include file search path for this
|
540 |
+
compilation only.
|
541 |
+
|
542 |
+
'debug' is a boolean; if true, the compiler will be instructed to
|
543 |
+
output debug symbols in (or alongside) the object file(s).
|
544 |
+
|
545 |
+
'extra_preargs' and 'extra_postargs' are implementation- dependent.
|
546 |
+
On platforms that have the notion of a command-line (e.g. Unix,
|
547 |
+
DOS/Windows), they are most likely lists of strings: extra
|
548 |
+
command-line arguments to prepend/append to the compiler command
|
549 |
+
line. On other platforms, consult the implementation class
|
550 |
+
documentation. In any event, they are intended as an escape hatch
|
551 |
+
for those occasions when the abstract compiler framework doesn't
|
552 |
+
cut the mustard.
|
553 |
+
|
554 |
+
'depends', if given, is a list of filenames that all targets
|
555 |
+
depend on. If a source file is older than any file in
|
556 |
+
depends, then the source file will be recompiled. This
|
557 |
+
supports dependency tracking, but only at a coarse
|
558 |
+
granularity.
|
559 |
+
|
560 |
+
Raises CompileError on failure.
|
561 |
+
"""
|
562 |
+
# A concrete compiler class can either override this method
|
563 |
+
# entirely or implement _compile().
|
564 |
+
macros, objects, extra_postargs, pp_opts, build = \
|
565 |
+
self._setup_compile(output_dir, macros, include_dirs, sources,
|
566 |
+
depends, extra_postargs)
|
567 |
+
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
|
568 |
+
|
569 |
+
for obj in objects:
|
570 |
+
try:
|
571 |
+
src, ext = build[obj]
|
572 |
+
except KeyError:
|
573 |
+
continue
|
574 |
+
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
|
575 |
+
|
576 |
+
# Return *all* object filenames, not just the ones we just built.
|
577 |
+
return objects
|
578 |
+
|
579 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
580 |
+
"""Compile 'src' to product 'obj'."""
|
581 |
+
# A concrete compiler class that does not override compile()
|
582 |
+
# should implement _compile().
|
583 |
+
pass
|
584 |
+
|
585 |
+
def create_static_lib(self, objects, output_libname, output_dir=None,
|
586 |
+
debug=0, target_lang=None):
|
587 |
+
"""Link a bunch of stuff together to create a static library file.
|
588 |
+
The "bunch of stuff" consists of the list of object files supplied
|
589 |
+
as 'objects', the extra object files supplied to
|
590 |
+
'add_link_object()' and/or 'set_link_objects()', the libraries
|
591 |
+
supplied to 'add_library()' and/or 'set_libraries()', and the
|
592 |
+
libraries supplied as 'libraries' (if any).
|
593 |
+
|
594 |
+
'output_libname' should be a library name, not a filename; the
|
595 |
+
filename will be inferred from the library name. 'output_dir' is
|
596 |
+
the directory where the library file will be put.
|
597 |
+
|
598 |
+
'debug' is a boolean; if true, debugging information will be
|
599 |
+
included in the library (note that on most platforms, it is the
|
600 |
+
compile step where this matters: the 'debug' flag is included here
|
601 |
+
just for consistency).
|
602 |
+
|
603 |
+
'target_lang' is the target language for which the given objects
|
604 |
+
are being compiled. This allows specific linkage time treatment of
|
605 |
+
certain languages.
|
606 |
+
|
607 |
+
Raises LibError on failure.
|
608 |
+
"""
|
609 |
+
pass
|
610 |
+
|
611 |
+
|
612 |
+
# values for target_desc parameter in link()
|
613 |
+
SHARED_OBJECT = "shared_object"
|
614 |
+
SHARED_LIBRARY = "shared_library"
|
615 |
+
EXECUTABLE = "executable"
|
616 |
+
|
617 |
+
def link(self,
|
618 |
+
target_desc,
|
619 |
+
objects,
|
620 |
+
output_filename,
|
621 |
+
output_dir=None,
|
622 |
+
libraries=None,
|
623 |
+
library_dirs=None,
|
624 |
+
runtime_library_dirs=None,
|
625 |
+
export_symbols=None,
|
626 |
+
debug=0,
|
627 |
+
extra_preargs=None,
|
628 |
+
extra_postargs=None,
|
629 |
+
build_temp=None,
|
630 |
+
target_lang=None):
|
631 |
+
"""Link a bunch of stuff together to create an executable or
|
632 |
+
shared library file.
|
633 |
+
|
634 |
+
The "bunch of stuff" consists of the list of object files supplied
|
635 |
+
as 'objects'. 'output_filename' should be a filename. If
|
636 |
+
'output_dir' is supplied, 'output_filename' is relative to it
|
637 |
+
(i.e. 'output_filename' can provide directory components if
|
638 |
+
needed).
|
639 |
+
|
640 |
+
'libraries' is a list of libraries to link against. These are
|
641 |
+
library names, not filenames, since they're translated into
|
642 |
+
filenames in a platform-specific way (eg. "foo" becomes "libfoo.a"
|
643 |
+
on Unix and "foo.lib" on DOS/Windows). However, they can include a
|
644 |
+
directory component, which means the linker will look in that
|
645 |
+
specific directory rather than searching all the normal locations.
|
646 |
+
|
647 |
+
'library_dirs', if supplied, should be a list of directories to
|
648 |
+
search for libraries that were specified as bare library names
|
649 |
+
(ie. no directory component). These are on top of the system
|
650 |
+
default and those supplied to 'add_library_dir()' and/or
|
651 |
+
'set_library_dirs()'. 'runtime_library_dirs' is a list of
|
652 |
+
directories that will be embedded into the shared library and used
|
653 |
+
to search for other shared libraries that *it* depends on at
|
654 |
+
run-time. (This may only be relevant on Unix.)
|
655 |
+
|
656 |
+
'export_symbols' is a list of symbols that the shared library will
|
657 |
+
export. (This appears to be relevant only on Windows.)
|
658 |
+
|
659 |
+
'debug' is as for 'compile()' and 'create_static_lib()', with the
|
660 |
+
slight distinction that it actually matters on most platforms (as
|
661 |
+
opposed to 'create_static_lib()', which includes a 'debug' flag
|
662 |
+
mostly for form's sake).
|
663 |
+
|
664 |
+
'extra_preargs' and 'extra_postargs' are as for 'compile()' (except
|
665 |
+
of course that they supply command-line arguments for the
|
666 |
+
particular linker being used).
|
667 |
+
|
668 |
+
'target_lang' is the target language for which the given objects
|
669 |
+
are being compiled. This allows specific linkage time treatment of
|
670 |
+
certain languages.
|
671 |
+
|
672 |
+
Raises LinkError on failure.
|
673 |
+
"""
|
674 |
+
raise NotImplementedError
|
675 |
+
|
676 |
+
|
677 |
+
# Old 'link_*()' methods, rewritten to use the new 'link()' method.
|
678 |
+
|
679 |
+
def link_shared_lib(self,
|
680 |
+
objects,
|
681 |
+
output_libname,
|
682 |
+
output_dir=None,
|
683 |
+
libraries=None,
|
684 |
+
library_dirs=None,
|
685 |
+
runtime_library_dirs=None,
|
686 |
+
export_symbols=None,
|
687 |
+
debug=0,
|
688 |
+
extra_preargs=None,
|
689 |
+
extra_postargs=None,
|
690 |
+
build_temp=None,
|
691 |
+
target_lang=None):
|
692 |
+
self.link(CCompiler.SHARED_LIBRARY, objects,
|
693 |
+
self.library_filename(output_libname, lib_type='shared'),
|
694 |
+
output_dir,
|
695 |
+
libraries, library_dirs, runtime_library_dirs,
|
696 |
+
export_symbols, debug,
|
697 |
+
extra_preargs, extra_postargs, build_temp, target_lang)
|
698 |
+
|
699 |
+
|
700 |
+
def link_shared_object(self,
|
701 |
+
objects,
|
702 |
+
output_filename,
|
703 |
+
output_dir=None,
|
704 |
+
libraries=None,
|
705 |
+
library_dirs=None,
|
706 |
+
runtime_library_dirs=None,
|
707 |
+
export_symbols=None,
|
708 |
+
debug=0,
|
709 |
+
extra_preargs=None,
|
710 |
+
extra_postargs=None,
|
711 |
+
build_temp=None,
|
712 |
+
target_lang=None):
|
713 |
+
self.link(CCompiler.SHARED_OBJECT, objects,
|
714 |
+
output_filename, output_dir,
|
715 |
+
libraries, library_dirs, runtime_library_dirs,
|
716 |
+
export_symbols, debug,
|
717 |
+
extra_preargs, extra_postargs, build_temp, target_lang)
|
718 |
+
|
719 |
+
|
720 |
+
def link_executable(self,
|
721 |
+
objects,
|
722 |
+
output_progname,
|
723 |
+
output_dir=None,
|
724 |
+
libraries=None,
|
725 |
+
library_dirs=None,
|
726 |
+
runtime_library_dirs=None,
|
727 |
+
debug=0,
|
728 |
+
extra_preargs=None,
|
729 |
+
extra_postargs=None,
|
730 |
+
target_lang=None):
|
731 |
+
self.link(CCompiler.EXECUTABLE, objects,
|
732 |
+
self.executable_filename(output_progname), output_dir,
|
733 |
+
libraries, library_dirs, runtime_library_dirs, None,
|
734 |
+
debug, extra_preargs, extra_postargs, None, target_lang)
|
735 |
+
|
736 |
+
|
737 |
+
# -- Miscellaneous methods -----------------------------------------
|
738 |
+
# These are all used by the 'gen_lib_options() function; there is
|
739 |
+
# no appropriate default implementation so subclasses should
|
740 |
+
# implement all of these.
|
741 |
+
|
742 |
+
def library_dir_option(self, dir):
|
743 |
+
"""Return the compiler option to add 'dir' to the list of
|
744 |
+
directories searched for libraries.
|
745 |
+
"""
|
746 |
+
raise NotImplementedError
|
747 |
+
|
748 |
+
def runtime_library_dir_option(self, dir):
|
749 |
+
"""Return the compiler option to add 'dir' to the list of
|
750 |
+
directories searched for runtime libraries.
|
751 |
+
"""
|
752 |
+
raise NotImplementedError
|
753 |
+
|
754 |
+
def library_option(self, lib):
|
755 |
+
"""Return the compiler option to add 'lib' to the list of libraries
|
756 |
+
linked into the shared library or executable.
|
757 |
+
"""
|
758 |
+
raise NotImplementedError
|
759 |
+
|
760 |
+
def has_function(self, funcname, includes=None, include_dirs=None,
|
761 |
+
libraries=None, library_dirs=None):
|
762 |
+
"""Return a boolean indicating whether funcname is supported on
|
763 |
+
the current platform. The optional arguments can be used to
|
764 |
+
augment the compilation environment.
|
765 |
+
"""
|
766 |
+
# this can't be included at module scope because it tries to
|
767 |
+
# import math which might not be available at that point - maybe
|
768 |
+
# the necessary logic should just be inlined?
|
769 |
+
import tempfile
|
770 |
+
if includes is None:
|
771 |
+
includes = []
|
772 |
+
if include_dirs is None:
|
773 |
+
include_dirs = []
|
774 |
+
if libraries is None:
|
775 |
+
libraries = []
|
776 |
+
if library_dirs is None:
|
777 |
+
library_dirs = []
|
778 |
+
fd, fname = tempfile.mkstemp(".c", funcname, text=True)
|
779 |
+
f = os.fdopen(fd, "w")
|
780 |
+
try:
|
781 |
+
for incl in includes:
|
782 |
+
f.write("""#include "%s"\n""" % incl)
|
783 |
+
f.write("""\
|
784 |
+
int main (int argc, char **argv) {
|
785 |
+
%s();
|
786 |
+
return 0;
|
787 |
+
}
|
788 |
+
""" % funcname)
|
789 |
+
finally:
|
790 |
+
f.close()
|
791 |
+
try:
|
792 |
+
objects = self.compile([fname], include_dirs=include_dirs)
|
793 |
+
except CompileError:
|
794 |
+
return False
|
795 |
+
finally:
|
796 |
+
os.remove(fname)
|
797 |
+
|
798 |
+
try:
|
799 |
+
self.link_executable(objects, "a.out",
|
800 |
+
libraries=libraries,
|
801 |
+
library_dirs=library_dirs)
|
802 |
+
except (LinkError, TypeError):
|
803 |
+
return False
|
804 |
+
else:
|
805 |
+
os.remove(os.path.join(self.output_dir or '', "a.out"))
|
806 |
+
finally:
|
807 |
+
for fn in objects:
|
808 |
+
os.remove(fn)
|
809 |
+
return True
|
810 |
+
|
811 |
+
def find_library_file (self, dirs, lib, debug=0):
|
812 |
+
"""Search the specified list of directories for a static or shared
|
813 |
+
library file 'lib' and return the full path to that file. If
|
814 |
+
'debug' true, look for a debugging version (if that makes sense on
|
815 |
+
the current platform). Return None if 'lib' wasn't found in any of
|
816 |
+
the specified directories.
|
817 |
+
"""
|
818 |
+
raise NotImplementedError
|
819 |
+
|
820 |
+
# -- Filename generation methods -----------------------------------
|
821 |
+
|
822 |
+
# The default implementation of the filename generating methods are
|
823 |
+
# prejudiced towards the Unix/DOS/Windows view of the world:
|
824 |
+
# * object files are named by replacing the source file extension
|
825 |
+
# (eg. .c/.cpp -> .o/.obj)
|
826 |
+
# * library files (shared or static) are named by plugging the
|
827 |
+
# library name and extension into a format string, eg.
|
828 |
+
# "lib%s.%s" % (lib_name, ".a") for Unix static libraries
|
829 |
+
# * executables are named by appending an extension (possibly
|
830 |
+
# empty) to the program name: eg. progname + ".exe" for
|
831 |
+
# Windows
|
832 |
+
#
|
833 |
+
# To reduce redundant code, these methods expect to find
|
834 |
+
# several attributes in the current object (presumably defined
|
835 |
+
# as class attributes):
|
836 |
+
# * src_extensions -
|
837 |
+
# list of C/C++ source file extensions, eg. ['.c', '.cpp']
|
838 |
+
# * obj_extension -
|
839 |
+
# object file extension, eg. '.o' or '.obj'
|
840 |
+
# * static_lib_extension -
|
841 |
+
# extension for static library files, eg. '.a' or '.lib'
|
842 |
+
# * shared_lib_extension -
|
843 |
+
# extension for shared library/object files, eg. '.so', '.dll'
|
844 |
+
# * static_lib_format -
|
845 |
+
# format string for generating static library filenames,
|
846 |
+
# eg. 'lib%s.%s' or '%s.%s'
|
847 |
+
# * shared_lib_format
|
848 |
+
# format string for generating shared library filenames
|
849 |
+
# (probably same as static_lib_format, since the extension
|
850 |
+
# is one of the intended parameters to the format string)
|
851 |
+
# * exe_extension -
|
852 |
+
# extension for executable files, eg. '' or '.exe'
|
853 |
+
|
854 |
+
def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
|
855 |
+
if output_dir is None:
|
856 |
+
output_dir = ''
|
857 |
+
obj_names = []
|
858 |
+
for src_name in source_filenames:
|
859 |
+
base, ext = os.path.splitext(src_name)
|
860 |
+
base = os.path.splitdrive(base)[1] # Chop off the drive
|
861 |
+
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
862 |
+
if ext not in self.src_extensions:
|
863 |
+
raise UnknownFileError(
|
864 |
+
"unknown file type '%s' (from '%s')" % (ext, src_name))
|
865 |
+
if strip_dir:
|
866 |
+
base = os.path.basename(base)
|
867 |
+
obj_names.append(os.path.join(output_dir,
|
868 |
+
base + self.obj_extension))
|
869 |
+
return obj_names
|
870 |
+
|
871 |
+
def shared_object_filename(self, basename, strip_dir=0, output_dir=''):
|
872 |
+
assert output_dir is not None
|
873 |
+
if strip_dir:
|
874 |
+
basename = os.path.basename(basename)
|
875 |
+
return os.path.join(output_dir, basename + self.shared_lib_extension)
|
876 |
+
|
877 |
+
def executable_filename(self, basename, strip_dir=0, output_dir=''):
|
878 |
+
assert output_dir is not None
|
879 |
+
if strip_dir:
|
880 |
+
basename = os.path.basename(basename)
|
881 |
+
return os.path.join(output_dir, basename + (self.exe_extension or ''))
|
882 |
+
|
883 |
+
def library_filename(self, libname, lib_type='static', # or 'shared'
|
884 |
+
strip_dir=0, output_dir=''):
|
885 |
+
assert output_dir is not None
|
886 |
+
if lib_type not in ("static", "shared", "dylib", "xcode_stub"):
|
887 |
+
raise ValueError(
|
888 |
+
"'lib_type' must be \"static\", \"shared\", \"dylib\", or \"xcode_stub\"")
|
889 |
+
fmt = getattr(self, lib_type + "_lib_format")
|
890 |
+
ext = getattr(self, lib_type + "_lib_extension")
|
891 |
+
|
892 |
+
dir, base = os.path.split(libname)
|
893 |
+
filename = fmt % (base, ext)
|
894 |
+
if strip_dir:
|
895 |
+
dir = ''
|
896 |
+
|
897 |
+
return os.path.join(output_dir, dir, filename)
|
898 |
+
|
899 |
+
|
900 |
+
# -- Utility methods -----------------------------------------------
|
901 |
+
|
902 |
+
def announce(self, msg, level=1):
|
903 |
+
log.debug(msg)
|
904 |
+
|
905 |
+
def debug_print(self, msg):
|
906 |
+
from distutils.debug import DEBUG
|
907 |
+
if DEBUG:
|
908 |
+
print(msg)
|
909 |
+
|
910 |
+
def warn(self, msg):
|
911 |
+
sys.stderr.write("warning: %s\n" % msg)
|
912 |
+
|
913 |
+
def execute(self, func, args, msg=None, level=1):
|
914 |
+
execute(func, args, msg, self.dry_run)
|
915 |
+
|
916 |
+
def spawn(self, cmd, **kwargs):
|
917 |
+
spawn(cmd, dry_run=self.dry_run, **kwargs)
|
918 |
+
|
919 |
+
def move_file(self, src, dst):
|
920 |
+
return move_file(src, dst, dry_run=self.dry_run)
|
921 |
+
|
922 |
+
def mkpath (self, name, mode=0o777):
|
923 |
+
mkpath(name, mode, dry_run=self.dry_run)
|
924 |
+
|
925 |
+
|
926 |
+
# Map a sys.platform/os.name ('posix', 'nt') to the default compiler
|
927 |
+
# type for that platform. Keys are interpreted as re match
|
928 |
+
# patterns. Order is important; platform mappings are preferred over
|
929 |
+
# OS names.
|
930 |
+
_default_compilers = (
|
931 |
+
|
932 |
+
# Platform string mappings
|
933 |
+
|
934 |
+
# on a cygwin built python we can use gcc like an ordinary UNIXish
|
935 |
+
# compiler
|
936 |
+
('cygwin.*', 'unix'),
|
937 |
+
|
938 |
+
# OS name mappings
|
939 |
+
('posix', 'unix'),
|
940 |
+
('nt', 'msvc'),
|
941 |
+
|
942 |
+
)
|
943 |
+
|
944 |
+
def get_default_compiler(osname=None, platform=None):
|
945 |
+
"""Determine the default compiler to use for the given platform.
|
946 |
+
|
947 |
+
osname should be one of the standard Python OS names (i.e. the
|
948 |
+
ones returned by os.name) and platform the common value
|
949 |
+
returned by sys.platform for the platform in question.
|
950 |
+
|
951 |
+
The default values are os.name and sys.platform in case the
|
952 |
+
parameters are not given.
|
953 |
+
"""
|
954 |
+
if osname is None:
|
955 |
+
osname = os.name
|
956 |
+
if platform is None:
|
957 |
+
platform = sys.platform
|
958 |
+
for pattern, compiler in _default_compilers:
|
959 |
+
if re.match(pattern, platform) is not None or \
|
960 |
+
re.match(pattern, osname) is not None:
|
961 |
+
return compiler
|
962 |
+
# Default to Unix compiler
|
963 |
+
return 'unix'
|
964 |
+
|
965 |
+
# Map compiler types to (module_name, class_name) pairs -- ie. where to
|
966 |
+
# find the code that implements an interface to this compiler. (The module
|
967 |
+
# is assumed to be in the 'distutils' package.)
|
968 |
+
compiler_class = { 'unix': ('unixccompiler', 'UnixCCompiler',
|
969 |
+
"standard UNIX-style compiler"),
|
970 |
+
'msvc': ('_msvccompiler', 'MSVCCompiler',
|
971 |
+
"Microsoft Visual C++"),
|
972 |
+
'cygwin': ('cygwinccompiler', 'CygwinCCompiler',
|
973 |
+
"Cygwin port of GNU C Compiler for Win32"),
|
974 |
+
'mingw32': ('cygwinccompiler', 'Mingw32CCompiler',
|
975 |
+
"Mingw32 port of GNU C Compiler for Win32"),
|
976 |
+
'bcpp': ('bcppcompiler', 'BCPPCompiler',
|
977 |
+
"Borland C++ Compiler"),
|
978 |
+
}
|
979 |
+
|
980 |
+
def show_compilers():
|
981 |
+
"""Print list of available compilers (used by the "--help-compiler"
|
982 |
+
options to "build", "build_ext", "build_clib").
|
983 |
+
"""
|
984 |
+
# XXX this "knows" that the compiler option it's describing is
|
985 |
+
# "--compiler", which just happens to be the case for the three
|
986 |
+
# commands that use it.
|
987 |
+
from distutils.fancy_getopt import FancyGetopt
|
988 |
+
compilers = []
|
989 |
+
for compiler in compiler_class.keys():
|
990 |
+
compilers.append(("compiler="+compiler, None,
|
991 |
+
compiler_class[compiler][2]))
|
992 |
+
compilers.sort()
|
993 |
+
pretty_printer = FancyGetopt(compilers)
|
994 |
+
pretty_printer.print_help("List of available compilers:")
|
995 |
+
|
996 |
+
|
997 |
+
def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
|
998 |
+
"""Generate an instance of some CCompiler subclass for the supplied
|
999 |
+
platform/compiler combination. 'plat' defaults to 'os.name'
|
1000 |
+
(eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler
|
1001 |
+
for that platform. Currently only 'posix' and 'nt' are supported, and
|
1002 |
+
the default compilers are "traditional Unix interface" (UnixCCompiler
|
1003 |
+
class) and Visual C++ (MSVCCompiler class). Note that it's perfectly
|
1004 |
+
possible to ask for a Unix compiler object under Windows, and a
|
1005 |
+
Microsoft compiler object under Unix -- if you supply a value for
|
1006 |
+
'compiler', 'plat' is ignored.
|
1007 |
+
"""
|
1008 |
+
if plat is None:
|
1009 |
+
plat = os.name
|
1010 |
+
|
1011 |
+
try:
|
1012 |
+
if compiler is None:
|
1013 |
+
compiler = get_default_compiler(plat)
|
1014 |
+
|
1015 |
+
(module_name, class_name, long_description) = compiler_class[compiler]
|
1016 |
+
except KeyError:
|
1017 |
+
msg = "don't know how to compile C/C++ code on platform '%s'" % plat
|
1018 |
+
if compiler is not None:
|
1019 |
+
msg = msg + " with '%s' compiler" % compiler
|
1020 |
+
raise DistutilsPlatformError(msg)
|
1021 |
+
|
1022 |
+
try:
|
1023 |
+
module_name = "distutils." + module_name
|
1024 |
+
__import__ (module_name)
|
1025 |
+
module = sys.modules[module_name]
|
1026 |
+
klass = vars(module)[class_name]
|
1027 |
+
except ImportError:
|
1028 |
+
raise DistutilsModuleError(
|
1029 |
+
"can't compile C/C++ code: unable to load module '%s'" % \
|
1030 |
+
module_name)
|
1031 |
+
except KeyError:
|
1032 |
+
raise DistutilsModuleError(
|
1033 |
+
"can't compile C/C++ code: unable to find class '%s' "
|
1034 |
+
"in module '%s'" % (class_name, module_name))
|
1035 |
+
|
1036 |
+
# XXX The None is necessary to preserve backwards compatibility
|
1037 |
+
# with classes that expect verbose to be the first positional
|
1038 |
+
# argument.
|
1039 |
+
return klass(None, dry_run, force)
|
1040 |
+
|
1041 |
+
|
1042 |
+
def gen_preprocess_options(macros, include_dirs):
|
1043 |
+
"""Generate C pre-processor options (-D, -U, -I) as used by at least
|
1044 |
+
two types of compilers: the typical Unix compiler and Visual C++.
|
1045 |
+
'macros' is the usual thing, a list of 1- or 2-tuples, where (name,)
|
1046 |
+
means undefine (-U) macro 'name', and (name,value) means define (-D)
|
1047 |
+
macro 'name' to 'value'. 'include_dirs' is just a list of directory
|
1048 |
+
names to be added to the header file search path (-I). Returns a list
|
1049 |
+
of command-line options suitable for either Unix compilers or Visual
|
1050 |
+
C++.
|
1051 |
+
"""
|
1052 |
+
# XXX it would be nice (mainly aesthetic, and so we don't generate
|
1053 |
+
# stupid-looking command lines) to go over 'macros' and eliminate
|
1054 |
+
# redundant definitions/undefinitions (ie. ensure that only the
|
1055 |
+
# latest mention of a particular macro winds up on the command
|
1056 |
+
# line). I don't think it's essential, though, since most (all?)
|
1057 |
+
# Unix C compilers only pay attention to the latest -D or -U
|
1058 |
+
# mention of a macro on their command line. Similar situation for
|
1059 |
+
# 'include_dirs'. I'm punting on both for now. Anyways, weeding out
|
1060 |
+
# redundancies like this should probably be the province of
|
1061 |
+
# CCompiler, since the data structures used are inherited from it
|
1062 |
+
# and therefore common to all CCompiler classes.
|
1063 |
+
pp_opts = []
|
1064 |
+
for macro in macros:
|
1065 |
+
if not (isinstance(macro, tuple) and 1 <= len(macro) <= 2):
|
1066 |
+
raise TypeError(
|
1067 |
+
"bad macro definition '%s': "
|
1068 |
+
"each element of 'macros' list must be a 1- or 2-tuple"
|
1069 |
+
% macro)
|
1070 |
+
|
1071 |
+
if len(macro) == 1: # undefine this macro
|
1072 |
+
pp_opts.append("-U%s" % macro[0])
|
1073 |
+
elif len(macro) == 2:
|
1074 |
+
if macro[1] is None: # define with no explicit value
|
1075 |
+
pp_opts.append("-D%s" % macro[0])
|
1076 |
+
else:
|
1077 |
+
# XXX *don't* need to be clever about quoting the
|
1078 |
+
# macro value here, because we're going to avoid the
|
1079 |
+
# shell at all costs when we spawn the command!
|
1080 |
+
pp_opts.append("-D%s=%s" % macro)
|
1081 |
+
|
1082 |
+
for dir in include_dirs:
|
1083 |
+
pp_opts.append("-I%s" % dir)
|
1084 |
+
return pp_opts
|
1085 |
+
|
1086 |
+
|
1087 |
+
def gen_lib_options (compiler, library_dirs, runtime_library_dirs, libraries):
|
1088 |
+
"""Generate linker options for searching library directories and
|
1089 |
+
linking with specific libraries. 'libraries' and 'library_dirs' are,
|
1090 |
+
respectively, lists of library names (not filenames!) and search
|
1091 |
+
directories. Returns a list of command-line options suitable for use
|
1092 |
+
with some compiler (depending on the two format strings passed in).
|
1093 |
+
"""
|
1094 |
+
lib_opts = []
|
1095 |
+
|
1096 |
+
for dir in library_dirs:
|
1097 |
+
lib_opts.append(compiler.library_dir_option(dir))
|
1098 |
+
|
1099 |
+
for dir in runtime_library_dirs:
|
1100 |
+
opt = compiler.runtime_library_dir_option(dir)
|
1101 |
+
if isinstance(opt, list):
|
1102 |
+
lib_opts = lib_opts + opt
|
1103 |
+
else:
|
1104 |
+
lib_opts.append(opt)
|
1105 |
+
|
1106 |
+
# XXX it's important that we *not* remove redundant library mentions!
|
1107 |
+
# sometimes you really do have to say "-lfoo -lbar -lfoo" in order to
|
1108 |
+
# resolve all symbols. I just hope we never have to say "-lfoo obj.o
|
1109 |
+
# -lbar" to get things to work -- that's certainly a possibility, but a
|
1110 |
+
# pretty nasty way to arrange your C code.
|
1111 |
+
|
1112 |
+
for lib in libraries:
|
1113 |
+
(lib_dir, lib_name) = os.path.split(lib)
|
1114 |
+
if lib_dir:
|
1115 |
+
lib_file = compiler.find_library_file([lib_dir], lib_name)
|
1116 |
+
if lib_file:
|
1117 |
+
lib_opts.append(lib_file)
|
1118 |
+
else:
|
1119 |
+
compiler.warn("no library file corresponding to "
|
1120 |
+
"'%s' found (skipping)" % lib)
|
1121 |
+
else:
|
1122 |
+
lib_opts.append(compiler.library_option (lib))
|
1123 |
+
return lib_opts
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/cmd.py
ADDED
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.cmd
|
2 |
+
|
3 |
+
Provides the Command class, the base class for the command classes
|
4 |
+
in the distutils.command package.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import sys, os, re
|
8 |
+
from distutils.errors import DistutilsOptionError
|
9 |
+
from distutils import util, dir_util, file_util, archive_util, dep_util
|
10 |
+
from distutils import log
|
11 |
+
|
12 |
+
class Command:
|
13 |
+
"""Abstract base class for defining command classes, the "worker bees"
|
14 |
+
of the Distutils. A useful analogy for command classes is to think of
|
15 |
+
them as subroutines with local variables called "options". The options
|
16 |
+
are "declared" in 'initialize_options()' and "defined" (given their
|
17 |
+
final values, aka "finalized") in 'finalize_options()', both of which
|
18 |
+
must be defined by every command class. The distinction between the
|
19 |
+
two is necessary because option values might come from the outside
|
20 |
+
world (command line, config file, ...), and any options dependent on
|
21 |
+
other options must be computed *after* these outside influences have
|
22 |
+
been processed -- hence 'finalize_options()'. The "body" of the
|
23 |
+
subroutine, where it does all its work based on the values of its
|
24 |
+
options, is the 'run()' method, which must also be implemented by every
|
25 |
+
command class.
|
26 |
+
"""
|
27 |
+
|
28 |
+
# 'sub_commands' formalizes the notion of a "family" of commands,
|
29 |
+
# eg. "install" as the parent with sub-commands "install_lib",
|
30 |
+
# "install_headers", etc. The parent of a family of commands
|
31 |
+
# defines 'sub_commands' as a class attribute; it's a list of
|
32 |
+
# (command_name : string, predicate : unbound_method | string | None)
|
33 |
+
# tuples, where 'predicate' is a method of the parent command that
|
34 |
+
# determines whether the corresponding command is applicable in the
|
35 |
+
# current situation. (Eg. we "install_headers" is only applicable if
|
36 |
+
# we have any C header files to install.) If 'predicate' is None,
|
37 |
+
# that command is always applicable.
|
38 |
+
#
|
39 |
+
# 'sub_commands' is usually defined at the *end* of a class, because
|
40 |
+
# predicates can be unbound methods, so they must already have been
|
41 |
+
# defined. The canonical example is the "install" command.
|
42 |
+
sub_commands = []
|
43 |
+
|
44 |
+
|
45 |
+
# -- Creation/initialization methods -------------------------------
|
46 |
+
|
47 |
+
def __init__(self, dist):
|
48 |
+
"""Create and initialize a new Command object. Most importantly,
|
49 |
+
invokes the 'initialize_options()' method, which is the real
|
50 |
+
initializer and depends on the actual command being
|
51 |
+
instantiated.
|
52 |
+
"""
|
53 |
+
# late import because of mutual dependence between these classes
|
54 |
+
from distutils.dist import Distribution
|
55 |
+
|
56 |
+
if not isinstance(dist, Distribution):
|
57 |
+
raise TypeError("dist must be a Distribution instance")
|
58 |
+
if self.__class__ is Command:
|
59 |
+
raise RuntimeError("Command is an abstract class")
|
60 |
+
|
61 |
+
self.distribution = dist
|
62 |
+
self.initialize_options()
|
63 |
+
|
64 |
+
# Per-command versions of the global flags, so that the user can
|
65 |
+
# customize Distutils' behaviour command-by-command and let some
|
66 |
+
# commands fall back on the Distribution's behaviour. None means
|
67 |
+
# "not defined, check self.distribution's copy", while 0 or 1 mean
|
68 |
+
# false and true (duh). Note that this means figuring out the real
|
69 |
+
# value of each flag is a touch complicated -- hence "self._dry_run"
|
70 |
+
# will be handled by __getattr__, below.
|
71 |
+
# XXX This needs to be fixed.
|
72 |
+
self._dry_run = None
|
73 |
+
|
74 |
+
# verbose is largely ignored, but needs to be set for
|
75 |
+
# backwards compatibility (I think)?
|
76 |
+
self.verbose = dist.verbose
|
77 |
+
|
78 |
+
# Some commands define a 'self.force' option to ignore file
|
79 |
+
# timestamps, but methods defined *here* assume that
|
80 |
+
# 'self.force' exists for all commands. So define it here
|
81 |
+
# just to be safe.
|
82 |
+
self.force = None
|
83 |
+
|
84 |
+
# The 'help' flag is just used for command-line parsing, so
|
85 |
+
# none of that complicated bureaucracy is needed.
|
86 |
+
self.help = 0
|
87 |
+
|
88 |
+
# 'finalized' records whether or not 'finalize_options()' has been
|
89 |
+
# called. 'finalize_options()' itself should not pay attention to
|
90 |
+
# this flag: it is the business of 'ensure_finalized()', which
|
91 |
+
# always calls 'finalize_options()', to respect/update it.
|
92 |
+
self.finalized = 0
|
93 |
+
|
94 |
+
# XXX A more explicit way to customize dry_run would be better.
|
95 |
+
def __getattr__(self, attr):
|
96 |
+
if attr == 'dry_run':
|
97 |
+
myval = getattr(self, "_" + attr)
|
98 |
+
if myval is None:
|
99 |
+
return getattr(self.distribution, attr)
|
100 |
+
else:
|
101 |
+
return myval
|
102 |
+
else:
|
103 |
+
raise AttributeError(attr)
|
104 |
+
|
105 |
+
def ensure_finalized(self):
|
106 |
+
if not self.finalized:
|
107 |
+
self.finalize_options()
|
108 |
+
self.finalized = 1
|
109 |
+
|
110 |
+
# Subclasses must define:
|
111 |
+
# initialize_options()
|
112 |
+
# provide default values for all options; may be customized by
|
113 |
+
# setup script, by options from config file(s), or by command-line
|
114 |
+
# options
|
115 |
+
# finalize_options()
|
116 |
+
# decide on the final values for all options; this is called
|
117 |
+
# after all possible intervention from the outside world
|
118 |
+
# (command-line, option file, etc.) has been processed
|
119 |
+
# run()
|
120 |
+
# run the command: do whatever it is we're here to do,
|
121 |
+
# controlled by the command's various option values
|
122 |
+
|
123 |
+
def initialize_options(self):
|
124 |
+
"""Set default values for all the options that this command
|
125 |
+
supports. Note that these defaults may be overridden by other
|
126 |
+
commands, by the setup script, by config files, or by the
|
127 |
+
command-line. Thus, this is not the place to code dependencies
|
128 |
+
between options; generally, 'initialize_options()' implementations
|
129 |
+
are just a bunch of "self.foo = None" assignments.
|
130 |
+
|
131 |
+
This method must be implemented by all command classes.
|
132 |
+
"""
|
133 |
+
raise RuntimeError("abstract method -- subclass %s must override"
|
134 |
+
% self.__class__)
|
135 |
+
|
136 |
+
def finalize_options(self):
|
137 |
+
"""Set final values for all the options that this command supports.
|
138 |
+
This is always called as late as possible, ie. after any option
|
139 |
+
assignments from the command-line or from other commands have been
|
140 |
+
done. Thus, this is the place to code option dependencies: if
|
141 |
+
'foo' depends on 'bar', then it is safe to set 'foo' from 'bar' as
|
142 |
+
long as 'foo' still has the same value it was assigned in
|
143 |
+
'initialize_options()'.
|
144 |
+
|
145 |
+
This method must be implemented by all command classes.
|
146 |
+
"""
|
147 |
+
raise RuntimeError("abstract method -- subclass %s must override"
|
148 |
+
% self.__class__)
|
149 |
+
|
150 |
+
|
151 |
+
def dump_options(self, header=None, indent=""):
|
152 |
+
from distutils.fancy_getopt import longopt_xlate
|
153 |
+
if header is None:
|
154 |
+
header = "command options for '%s':" % self.get_command_name()
|
155 |
+
self.announce(indent + header, level=log.INFO)
|
156 |
+
indent = indent + " "
|
157 |
+
for (option, _, _) in self.user_options:
|
158 |
+
option = option.translate(longopt_xlate)
|
159 |
+
if option[-1] == "=":
|
160 |
+
option = option[:-1]
|
161 |
+
value = getattr(self, option)
|
162 |
+
self.announce(indent + "%s = %s" % (option, value),
|
163 |
+
level=log.INFO)
|
164 |
+
|
165 |
+
def run(self):
|
166 |
+
"""A command's raison d'etre: carry out the action it exists to
|
167 |
+
perform, controlled by the options initialized in
|
168 |
+
'initialize_options()', customized by other commands, the setup
|
169 |
+
script, the command-line, and config files, and finalized in
|
170 |
+
'finalize_options()'. All terminal output and filesystem
|
171 |
+
interaction should be done by 'run()'.
|
172 |
+
|
173 |
+
This method must be implemented by all command classes.
|
174 |
+
"""
|
175 |
+
raise RuntimeError("abstract method -- subclass %s must override"
|
176 |
+
% self.__class__)
|
177 |
+
|
178 |
+
def announce(self, msg, level=1):
|
179 |
+
"""If the current verbosity level is of greater than or equal to
|
180 |
+
'level' print 'msg' to stdout.
|
181 |
+
"""
|
182 |
+
log.log(level, msg)
|
183 |
+
|
184 |
+
def debug_print(self, msg):
|
185 |
+
"""Print 'msg' to stdout if the global DEBUG (taken from the
|
186 |
+
DISTUTILS_DEBUG environment variable) flag is true.
|
187 |
+
"""
|
188 |
+
from distutils.debug import DEBUG
|
189 |
+
if DEBUG:
|
190 |
+
print(msg)
|
191 |
+
sys.stdout.flush()
|
192 |
+
|
193 |
+
|
194 |
+
# -- Option validation methods -------------------------------------
|
195 |
+
# (these are very handy in writing the 'finalize_options()' method)
|
196 |
+
#
|
197 |
+
# NB. the general philosophy here is to ensure that a particular option
|
198 |
+
# value meets certain type and value constraints. If not, we try to
|
199 |
+
# force it into conformance (eg. if we expect a list but have a string,
|
200 |
+
# split the string on comma and/or whitespace). If we can't force the
|
201 |
+
# option into conformance, raise DistutilsOptionError. Thus, command
|
202 |
+
# classes need do nothing more than (eg.)
|
203 |
+
# self.ensure_string_list('foo')
|
204 |
+
# and they can be guaranteed that thereafter, self.foo will be
|
205 |
+
# a list of strings.
|
206 |
+
|
207 |
+
def _ensure_stringlike(self, option, what, default=None):
|
208 |
+
val = getattr(self, option)
|
209 |
+
if val is None:
|
210 |
+
setattr(self, option, default)
|
211 |
+
return default
|
212 |
+
elif not isinstance(val, str):
|
213 |
+
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
|
214 |
+
% (option, what, val))
|
215 |
+
return val
|
216 |
+
|
217 |
+
def ensure_string(self, option, default=None):
|
218 |
+
"""Ensure that 'option' is a string; if not defined, set it to
|
219 |
+
'default'.
|
220 |
+
"""
|
221 |
+
self._ensure_stringlike(option, "string", default)
|
222 |
+
|
223 |
+
def ensure_string_list(self, option):
|
224 |
+
r"""Ensure that 'option' is a list of strings. If 'option' is
|
225 |
+
currently a string, we split it either on /,\s*/ or /\s+/, so
|
226 |
+
"foo bar baz", "foo,bar,baz", and "foo, bar baz" all become
|
227 |
+
["foo", "bar", "baz"].
|
228 |
+
"""
|
229 |
+
val = getattr(self, option)
|
230 |
+
if val is None:
|
231 |
+
return
|
232 |
+
elif isinstance(val, str):
|
233 |
+
setattr(self, option, re.split(r',\s*|\s+', val))
|
234 |
+
else:
|
235 |
+
if isinstance(val, list):
|
236 |
+
ok = all(isinstance(v, str) for v in val)
|
237 |
+
else:
|
238 |
+
ok = False
|
239 |
+
if not ok:
|
240 |
+
raise DistutilsOptionError(
|
241 |
+
"'%s' must be a list of strings (got %r)"
|
242 |
+
% (option, val))
|
243 |
+
|
244 |
+
def _ensure_tested_string(self, option, tester, what, error_fmt,
|
245 |
+
default=None):
|
246 |
+
val = self._ensure_stringlike(option, what, default)
|
247 |
+
if val is not None and not tester(val):
|
248 |
+
raise DistutilsOptionError(("error in '%s' option: " + error_fmt)
|
249 |
+
% (option, val))
|
250 |
+
|
251 |
+
def ensure_filename(self, option):
|
252 |
+
"""Ensure that 'option' is the name of an existing file."""
|
253 |
+
self._ensure_tested_string(option, os.path.isfile,
|
254 |
+
"filename",
|
255 |
+
"'%s' does not exist or is not a file")
|
256 |
+
|
257 |
+
def ensure_dirname(self, option):
|
258 |
+
self._ensure_tested_string(option, os.path.isdir,
|
259 |
+
"directory name",
|
260 |
+
"'%s' does not exist or is not a directory")
|
261 |
+
|
262 |
+
|
263 |
+
# -- Convenience methods for commands ------------------------------
|
264 |
+
|
265 |
+
def get_command_name(self):
|
266 |
+
if hasattr(self, 'command_name'):
|
267 |
+
return self.command_name
|
268 |
+
else:
|
269 |
+
return self.__class__.__name__
|
270 |
+
|
271 |
+
def set_undefined_options(self, src_cmd, *option_pairs):
|
272 |
+
"""Set the values of any "undefined" options from corresponding
|
273 |
+
option values in some other command object. "Undefined" here means
|
274 |
+
"is None", which is the convention used to indicate that an option
|
275 |
+
has not been changed between 'initialize_options()' and
|
276 |
+
'finalize_options()'. Usually called from 'finalize_options()' for
|
277 |
+
options that depend on some other command rather than another
|
278 |
+
option of the same command. 'src_cmd' is the other command from
|
279 |
+
which option values will be taken (a command object will be created
|
280 |
+
for it if necessary); the remaining arguments are
|
281 |
+
'(src_option,dst_option)' tuples which mean "take the value of
|
282 |
+
'src_option' in the 'src_cmd' command object, and copy it to
|
283 |
+
'dst_option' in the current command object".
|
284 |
+
"""
|
285 |
+
# Option_pairs: list of (src_option, dst_option) tuples
|
286 |
+
src_cmd_obj = self.distribution.get_command_obj(src_cmd)
|
287 |
+
src_cmd_obj.ensure_finalized()
|
288 |
+
for (src_option, dst_option) in option_pairs:
|
289 |
+
if getattr(self, dst_option) is None:
|
290 |
+
setattr(self, dst_option, getattr(src_cmd_obj, src_option))
|
291 |
+
|
292 |
+
def get_finalized_command(self, command, create=1):
|
293 |
+
"""Wrapper around Distribution's 'get_command_obj()' method: find
|
294 |
+
(create if necessary and 'create' is true) the command object for
|
295 |
+
'command', call its 'ensure_finalized()' method, and return the
|
296 |
+
finalized command object.
|
297 |
+
"""
|
298 |
+
cmd_obj = self.distribution.get_command_obj(command, create)
|
299 |
+
cmd_obj.ensure_finalized()
|
300 |
+
return cmd_obj
|
301 |
+
|
302 |
+
# XXX rename to 'get_reinitialized_command()'? (should do the
|
303 |
+
# same in dist.py, if so)
|
304 |
+
def reinitialize_command(self, command, reinit_subcommands=0):
|
305 |
+
return self.distribution.reinitialize_command(command,
|
306 |
+
reinit_subcommands)
|
307 |
+
|
308 |
+
def run_command(self, command):
|
309 |
+
"""Run some other command: uses the 'run_command()' method of
|
310 |
+
Distribution, which creates and finalizes the command object if
|
311 |
+
necessary and then invokes its 'run()' method.
|
312 |
+
"""
|
313 |
+
self.distribution.run_command(command)
|
314 |
+
|
315 |
+
def get_sub_commands(self):
|
316 |
+
"""Determine the sub-commands that are relevant in the current
|
317 |
+
distribution (ie., that need to be run). This is based on the
|
318 |
+
'sub_commands' class attribute: each tuple in that list may include
|
319 |
+
a method that we call to determine if the subcommand needs to be
|
320 |
+
run for the current distribution. Return a list of command names.
|
321 |
+
"""
|
322 |
+
commands = []
|
323 |
+
for (cmd_name, method) in self.sub_commands:
|
324 |
+
if method is None or method(self):
|
325 |
+
commands.append(cmd_name)
|
326 |
+
return commands
|
327 |
+
|
328 |
+
|
329 |
+
# -- External world manipulation -----------------------------------
|
330 |
+
|
331 |
+
def warn(self, msg):
|
332 |
+
log.warn("warning: %s: %s\n", self.get_command_name(), msg)
|
333 |
+
|
334 |
+
def execute(self, func, args, msg=None, level=1):
|
335 |
+
util.execute(func, args, msg, dry_run=self.dry_run)
|
336 |
+
|
337 |
+
def mkpath(self, name, mode=0o777):
|
338 |
+
dir_util.mkpath(name, mode, dry_run=self.dry_run)
|
339 |
+
|
340 |
+
def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1,
|
341 |
+
link=None, level=1):
|
342 |
+
"""Copy a file respecting verbose, dry-run and force flags. (The
|
343 |
+
former two default to whatever is in the Distribution object, and
|
344 |
+
the latter defaults to false for commands that don't define it.)"""
|
345 |
+
return file_util.copy_file(infile, outfile, preserve_mode,
|
346 |
+
preserve_times, not self.force, link,
|
347 |
+
dry_run=self.dry_run)
|
348 |
+
|
349 |
+
def copy_tree(self, infile, outfile, preserve_mode=1, preserve_times=1,
|
350 |
+
preserve_symlinks=0, level=1):
|
351 |
+
"""Copy an entire directory tree respecting verbose, dry-run,
|
352 |
+
and force flags.
|
353 |
+
"""
|
354 |
+
return dir_util.copy_tree(infile, outfile, preserve_mode,
|
355 |
+
preserve_times, preserve_symlinks,
|
356 |
+
not self.force, dry_run=self.dry_run)
|
357 |
+
|
358 |
+
def move_file (self, src, dst, level=1):
|
359 |
+
"""Move a file respecting dry-run flag."""
|
360 |
+
return file_util.move_file(src, dst, dry_run=self.dry_run)
|
361 |
+
|
362 |
+
def spawn(self, cmd, search_path=1, level=1):
|
363 |
+
"""Spawn an external command respecting dry-run flag."""
|
364 |
+
from distutils.spawn import spawn
|
365 |
+
spawn(cmd, search_path, dry_run=self.dry_run)
|
366 |
+
|
367 |
+
def make_archive(self, base_name, format, root_dir=None, base_dir=None,
|
368 |
+
owner=None, group=None):
|
369 |
+
return archive_util.make_archive(base_name, format, root_dir, base_dir,
|
370 |
+
dry_run=self.dry_run,
|
371 |
+
owner=owner, group=group)
|
372 |
+
|
373 |
+
def make_file(self, infiles, outfile, func, args,
|
374 |
+
exec_msg=None, skip_msg=None, level=1):
|
375 |
+
"""Special case of 'execute()' for operations that process one or
|
376 |
+
more input files and generate one output file. Works just like
|
377 |
+
'execute()', except the operation is skipped and a different
|
378 |
+
message printed if 'outfile' already exists and is newer than all
|
379 |
+
files listed in 'infiles'. If the command defined 'self.force',
|
380 |
+
and it is true, then the command is unconditionally run -- does no
|
381 |
+
timestamp checks.
|
382 |
+
"""
|
383 |
+
if skip_msg is None:
|
384 |
+
skip_msg = "skipping %s (inputs unchanged)" % outfile
|
385 |
+
|
386 |
+
# Allow 'infiles' to be a single string
|
387 |
+
if isinstance(infiles, str):
|
388 |
+
infiles = (infiles,)
|
389 |
+
elif not isinstance(infiles, (list, tuple)):
|
390 |
+
raise TypeError(
|
391 |
+
"'infiles' must be a string, or a list or tuple of strings")
|
392 |
+
|
393 |
+
if exec_msg is None:
|
394 |
+
exec_msg = "generating %s from %s" % (outfile, ', '.join(infiles))
|
395 |
+
|
396 |
+
# If 'outfile' must be regenerated (either because it doesn't
|
397 |
+
# exist, is out-of-date, or the 'force' flag is true) then
|
398 |
+
# perform the action that presumably regenerates it
|
399 |
+
if self.force or dep_util.newer_group(infiles, outfile):
|
400 |
+
self.execute(func, args, exec_msg, level)
|
401 |
+
# Otherwise, print the "skip" message
|
402 |
+
else:
|
403 |
+
log.debug(skip_msg)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__init__.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command
|
2 |
+
|
3 |
+
Package containing implementation of all the standard Distutils
|
4 |
+
commands."""
|
5 |
+
|
6 |
+
__all__ = ['build',
|
7 |
+
'build_py',
|
8 |
+
'build_ext',
|
9 |
+
'build_clib',
|
10 |
+
'build_scripts',
|
11 |
+
'clean',
|
12 |
+
'install',
|
13 |
+
'install_lib',
|
14 |
+
'install_headers',
|
15 |
+
'install_scripts',
|
16 |
+
'install_data',
|
17 |
+
'sdist',
|
18 |
+
'register',
|
19 |
+
'bdist',
|
20 |
+
'bdist_dumb',
|
21 |
+
'bdist_rpm',
|
22 |
+
'bdist_wininst',
|
23 |
+
'check',
|
24 |
+
'upload',
|
25 |
+
# These two are reserved for future use:
|
26 |
+
#'bdist_sdux',
|
27 |
+
#'bdist_pkgtool',
|
28 |
+
# Note:
|
29 |
+
# bdist_packager is not included because it only provides
|
30 |
+
# an abstract base class
|
31 |
+
]
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (536 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/build_clib.cpython-310.pyc
ADDED
Binary file (4.88 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/clean.cpython-310.pyc
ADDED
Binary file (2.15 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/__pycache__/install_headers.cpython-310.pyc
ADDED
Binary file (1.78 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/bdist.py
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.bdist
|
2 |
+
|
3 |
+
Implements the Distutils 'bdist' command (create a built [binary]
|
4 |
+
distribution)."""
|
5 |
+
|
6 |
+
import os
|
7 |
+
from distutils.core import Command
|
8 |
+
from distutils.errors import *
|
9 |
+
from distutils.util import get_platform
|
10 |
+
|
11 |
+
|
12 |
+
def show_formats():
|
13 |
+
"""Print list of available formats (arguments to "--format" option).
|
14 |
+
"""
|
15 |
+
from distutils.fancy_getopt import FancyGetopt
|
16 |
+
formats = []
|
17 |
+
for format in bdist.format_commands:
|
18 |
+
formats.append(("formats=" + format, None,
|
19 |
+
bdist.format_command[format][1]))
|
20 |
+
pretty_printer = FancyGetopt(formats)
|
21 |
+
pretty_printer.print_help("List of available distribution formats:")
|
22 |
+
|
23 |
+
|
24 |
+
class bdist(Command):
|
25 |
+
|
26 |
+
description = "create a built (binary) distribution"
|
27 |
+
|
28 |
+
user_options = [('bdist-base=', 'b',
|
29 |
+
"temporary directory for creating built distributions"),
|
30 |
+
('plat-name=', 'p',
|
31 |
+
"platform name to embed in generated filenames "
|
32 |
+
"(default: %s)" % get_platform()),
|
33 |
+
('formats=', None,
|
34 |
+
"formats for distribution (comma-separated list)"),
|
35 |
+
('dist-dir=', 'd',
|
36 |
+
"directory to put final built distributions in "
|
37 |
+
"[default: dist]"),
|
38 |
+
('skip-build', None,
|
39 |
+
"skip rebuilding everything (for testing/debugging)"),
|
40 |
+
('owner=', 'u',
|
41 |
+
"Owner name used when creating a tar file"
|
42 |
+
" [default: current user]"),
|
43 |
+
('group=', 'g',
|
44 |
+
"Group name used when creating a tar file"
|
45 |
+
" [default: current group]"),
|
46 |
+
]
|
47 |
+
|
48 |
+
boolean_options = ['skip-build']
|
49 |
+
|
50 |
+
help_options = [
|
51 |
+
('help-formats', None,
|
52 |
+
"lists available distribution formats", show_formats),
|
53 |
+
]
|
54 |
+
|
55 |
+
# The following commands do not take a format option from bdist
|
56 |
+
no_format_option = ('bdist_rpm',)
|
57 |
+
|
58 |
+
# This won't do in reality: will need to distinguish RPM-ish Linux,
|
59 |
+
# Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
|
60 |
+
default_format = {'posix': 'gztar',
|
61 |
+
'nt': 'zip'}
|
62 |
+
|
63 |
+
# Establish the preferred order (for the --help-formats option).
|
64 |
+
format_commands = ['rpm', 'gztar', 'bztar', 'xztar', 'ztar', 'tar',
|
65 |
+
'wininst', 'zip', 'msi']
|
66 |
+
|
67 |
+
# And the real information.
|
68 |
+
format_command = {'rpm': ('bdist_rpm', "RPM distribution"),
|
69 |
+
'gztar': ('bdist_dumb', "gzip'ed tar file"),
|
70 |
+
'bztar': ('bdist_dumb', "bzip2'ed tar file"),
|
71 |
+
'xztar': ('bdist_dumb', "xz'ed tar file"),
|
72 |
+
'ztar': ('bdist_dumb', "compressed tar file"),
|
73 |
+
'tar': ('bdist_dumb', "tar file"),
|
74 |
+
'wininst': ('bdist_wininst',
|
75 |
+
"Windows executable installer"),
|
76 |
+
'zip': ('bdist_dumb', "ZIP file"),
|
77 |
+
'msi': ('bdist_msi', "Microsoft Installer")
|
78 |
+
}
|
79 |
+
|
80 |
+
|
81 |
+
def initialize_options(self):
|
82 |
+
self.bdist_base = None
|
83 |
+
self.plat_name = None
|
84 |
+
self.formats = None
|
85 |
+
self.dist_dir = None
|
86 |
+
self.skip_build = 0
|
87 |
+
self.group = None
|
88 |
+
self.owner = None
|
89 |
+
|
90 |
+
def finalize_options(self):
|
91 |
+
# have to finalize 'plat_name' before 'bdist_base'
|
92 |
+
if self.plat_name is None:
|
93 |
+
if self.skip_build:
|
94 |
+
self.plat_name = get_platform()
|
95 |
+
else:
|
96 |
+
self.plat_name = self.get_finalized_command('build').plat_name
|
97 |
+
|
98 |
+
# 'bdist_base' -- parent of per-built-distribution-format
|
99 |
+
# temporary directories (eg. we'll probably have
|
100 |
+
# "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
|
101 |
+
if self.bdist_base is None:
|
102 |
+
build_base = self.get_finalized_command('build').build_base
|
103 |
+
self.bdist_base = os.path.join(build_base,
|
104 |
+
'bdist.' + self.plat_name)
|
105 |
+
|
106 |
+
self.ensure_string_list('formats')
|
107 |
+
if self.formats is None:
|
108 |
+
try:
|
109 |
+
self.formats = [self.default_format[os.name]]
|
110 |
+
except KeyError:
|
111 |
+
raise DistutilsPlatformError(
|
112 |
+
"don't know how to create built distributions "
|
113 |
+
"on platform %s" % os.name)
|
114 |
+
|
115 |
+
if self.dist_dir is None:
|
116 |
+
self.dist_dir = "dist"
|
117 |
+
|
118 |
+
def run(self):
|
119 |
+
# Figure out which sub-commands we need to run.
|
120 |
+
commands = []
|
121 |
+
for format in self.formats:
|
122 |
+
try:
|
123 |
+
commands.append(self.format_command[format][0])
|
124 |
+
except KeyError:
|
125 |
+
raise DistutilsOptionError("invalid format '%s'" % format)
|
126 |
+
|
127 |
+
# Reinitialize and run each command.
|
128 |
+
for i in range(len(self.formats)):
|
129 |
+
cmd_name = commands[i]
|
130 |
+
sub_cmd = self.reinitialize_command(cmd_name)
|
131 |
+
if cmd_name not in self.no_format_option:
|
132 |
+
sub_cmd.format = self.formats[i]
|
133 |
+
|
134 |
+
# passing the owner and group names for tar archiving
|
135 |
+
if cmd_name == 'bdist_dumb':
|
136 |
+
sub_cmd.owner = self.owner
|
137 |
+
sub_cmd.group = self.group
|
138 |
+
|
139 |
+
# If we're going to need to run this command again, tell it to
|
140 |
+
# keep its temporary files around so subsequent runs go faster.
|
141 |
+
if cmd_name in commands[i+1:]:
|
142 |
+
sub_cmd.keep_temp = 1
|
143 |
+
self.run_command(cmd_name)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_dumb.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.bdist_dumb
|
2 |
+
|
3 |
+
Implements the Distutils 'bdist_dumb' command (create a "dumb" built
|
4 |
+
distribution -- i.e., just an archive to be unpacked under $prefix or
|
5 |
+
$exec_prefix)."""
|
6 |
+
|
7 |
+
import os
|
8 |
+
from distutils.core import Command
|
9 |
+
from distutils.util import get_platform
|
10 |
+
from distutils.dir_util import remove_tree, ensure_relative
|
11 |
+
from distutils.errors import *
|
12 |
+
from distutils.sysconfig import get_python_version
|
13 |
+
from distutils import log
|
14 |
+
|
15 |
+
class bdist_dumb(Command):
|
16 |
+
|
17 |
+
description = "create a \"dumb\" built distribution"
|
18 |
+
|
19 |
+
user_options = [('bdist-dir=', 'd',
|
20 |
+
"temporary directory for creating the distribution"),
|
21 |
+
('plat-name=', 'p',
|
22 |
+
"platform name to embed in generated filenames "
|
23 |
+
"(default: %s)" % get_platform()),
|
24 |
+
('format=', 'f',
|
25 |
+
"archive format to create (tar, gztar, bztar, xztar, "
|
26 |
+
"ztar, zip)"),
|
27 |
+
('keep-temp', 'k',
|
28 |
+
"keep the pseudo-installation tree around after " +
|
29 |
+
"creating the distribution archive"),
|
30 |
+
('dist-dir=', 'd',
|
31 |
+
"directory to put final built distributions in"),
|
32 |
+
('skip-build', None,
|
33 |
+
"skip rebuilding everything (for testing/debugging)"),
|
34 |
+
('relative', None,
|
35 |
+
"build the archive using relative paths "
|
36 |
+
"(default: false)"),
|
37 |
+
('owner=', 'u',
|
38 |
+
"Owner name used when creating a tar file"
|
39 |
+
" [default: current user]"),
|
40 |
+
('group=', 'g',
|
41 |
+
"Group name used when creating a tar file"
|
42 |
+
" [default: current group]"),
|
43 |
+
]
|
44 |
+
|
45 |
+
boolean_options = ['keep-temp', 'skip-build', 'relative']
|
46 |
+
|
47 |
+
default_format = { 'posix': 'gztar',
|
48 |
+
'nt': 'zip' }
|
49 |
+
|
50 |
+
def initialize_options(self):
|
51 |
+
self.bdist_dir = None
|
52 |
+
self.plat_name = None
|
53 |
+
self.format = None
|
54 |
+
self.keep_temp = 0
|
55 |
+
self.dist_dir = None
|
56 |
+
self.skip_build = None
|
57 |
+
self.relative = 0
|
58 |
+
self.owner = None
|
59 |
+
self.group = None
|
60 |
+
|
61 |
+
def finalize_options(self):
|
62 |
+
if self.bdist_dir is None:
|
63 |
+
bdist_base = self.get_finalized_command('bdist').bdist_base
|
64 |
+
self.bdist_dir = os.path.join(bdist_base, 'dumb')
|
65 |
+
|
66 |
+
if self.format is None:
|
67 |
+
try:
|
68 |
+
self.format = self.default_format[os.name]
|
69 |
+
except KeyError:
|
70 |
+
raise DistutilsPlatformError(
|
71 |
+
"don't know how to create dumb built distributions "
|
72 |
+
"on platform %s" % os.name)
|
73 |
+
|
74 |
+
self.set_undefined_options('bdist',
|
75 |
+
('dist_dir', 'dist_dir'),
|
76 |
+
('plat_name', 'plat_name'),
|
77 |
+
('skip_build', 'skip_build'))
|
78 |
+
|
79 |
+
def run(self):
|
80 |
+
if not self.skip_build:
|
81 |
+
self.run_command('build')
|
82 |
+
|
83 |
+
install = self.reinitialize_command('install', reinit_subcommands=1)
|
84 |
+
install.root = self.bdist_dir
|
85 |
+
install.skip_build = self.skip_build
|
86 |
+
install.warn_dir = 0
|
87 |
+
|
88 |
+
log.info("installing to %s", self.bdist_dir)
|
89 |
+
self.run_command('install')
|
90 |
+
|
91 |
+
# And make an archive relative to the root of the
|
92 |
+
# pseudo-installation tree.
|
93 |
+
archive_basename = "%s.%s" % (self.distribution.get_fullname(),
|
94 |
+
self.plat_name)
|
95 |
+
|
96 |
+
pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
|
97 |
+
if not self.relative:
|
98 |
+
archive_root = self.bdist_dir
|
99 |
+
else:
|
100 |
+
if (self.distribution.has_ext_modules() and
|
101 |
+
(install.install_base != install.install_platbase)):
|
102 |
+
raise DistutilsPlatformError(
|
103 |
+
"can't make a dumb built distribution where "
|
104 |
+
"base and platbase are different (%s, %s)"
|
105 |
+
% (repr(install.install_base),
|
106 |
+
repr(install.install_platbase)))
|
107 |
+
else:
|
108 |
+
archive_root = os.path.join(self.bdist_dir,
|
109 |
+
ensure_relative(install.install_base))
|
110 |
+
|
111 |
+
# Make the archive
|
112 |
+
filename = self.make_archive(pseudoinstall_root,
|
113 |
+
self.format, root_dir=archive_root,
|
114 |
+
owner=self.owner, group=self.group)
|
115 |
+
if self.distribution.has_ext_modules():
|
116 |
+
pyversion = get_python_version()
|
117 |
+
else:
|
118 |
+
pyversion = 'any'
|
119 |
+
self.distribution.dist_files.append(('bdist_dumb', pyversion,
|
120 |
+
filename))
|
121 |
+
|
122 |
+
if not self.keep_temp:
|
123 |
+
remove_tree(self.bdist_dir, dry_run=self.dry_run)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_rpm.py
ADDED
@@ -0,0 +1,579 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.bdist_rpm
|
2 |
+
|
3 |
+
Implements the Distutils 'bdist_rpm' command (create RPM source and binary
|
4 |
+
distributions)."""
|
5 |
+
|
6 |
+
import subprocess, sys, os
|
7 |
+
from distutils.core import Command
|
8 |
+
from distutils.debug import DEBUG
|
9 |
+
from distutils.file_util import write_file
|
10 |
+
from distutils.errors import *
|
11 |
+
from distutils.sysconfig import get_python_version
|
12 |
+
from distutils import log
|
13 |
+
|
14 |
+
class bdist_rpm(Command):
|
15 |
+
|
16 |
+
description = "create an RPM distribution"
|
17 |
+
|
18 |
+
user_options = [
|
19 |
+
('bdist-base=', None,
|
20 |
+
"base directory for creating built distributions"),
|
21 |
+
('rpm-base=', None,
|
22 |
+
"base directory for creating RPMs (defaults to \"rpm\" under "
|
23 |
+
"--bdist-base; must be specified for RPM 2)"),
|
24 |
+
('dist-dir=', 'd',
|
25 |
+
"directory to put final RPM files in "
|
26 |
+
"(and .spec files if --spec-only)"),
|
27 |
+
('python=', None,
|
28 |
+
"path to Python interpreter to hard-code in the .spec file "
|
29 |
+
"(default: \"python\")"),
|
30 |
+
('fix-python', None,
|
31 |
+
"hard-code the exact path to the current Python interpreter in "
|
32 |
+
"the .spec file"),
|
33 |
+
('spec-only', None,
|
34 |
+
"only regenerate spec file"),
|
35 |
+
('source-only', None,
|
36 |
+
"only generate source RPM"),
|
37 |
+
('binary-only', None,
|
38 |
+
"only generate binary RPM"),
|
39 |
+
('use-bzip2', None,
|
40 |
+
"use bzip2 instead of gzip to create source distribution"),
|
41 |
+
|
42 |
+
# More meta-data: too RPM-specific to put in the setup script,
|
43 |
+
# but needs to go in the .spec file -- so we make these options
|
44 |
+
# to "bdist_rpm". The idea is that packagers would put this
|
45 |
+
# info in setup.cfg, although they are of course free to
|
46 |
+
# supply it on the command line.
|
47 |
+
('distribution-name=', None,
|
48 |
+
"name of the (Linux) distribution to which this "
|
49 |
+
"RPM applies (*not* the name of the module distribution!)"),
|
50 |
+
('group=', None,
|
51 |
+
"package classification [default: \"Development/Libraries\"]"),
|
52 |
+
('release=', None,
|
53 |
+
"RPM release number"),
|
54 |
+
('serial=', None,
|
55 |
+
"RPM serial number"),
|
56 |
+
('vendor=', None,
|
57 |
+
"RPM \"vendor\" (eg. \"Joe Blow <[email protected]>\") "
|
58 |
+
"[default: maintainer or author from setup script]"),
|
59 |
+
('packager=', None,
|
60 |
+
"RPM packager (eg. \"Jane Doe <[email protected]>\") "
|
61 |
+
"[default: vendor]"),
|
62 |
+
('doc-files=', None,
|
63 |
+
"list of documentation files (space or comma-separated)"),
|
64 |
+
('changelog=', None,
|
65 |
+
"RPM changelog"),
|
66 |
+
('icon=', None,
|
67 |
+
"name of icon file"),
|
68 |
+
('provides=', None,
|
69 |
+
"capabilities provided by this package"),
|
70 |
+
('requires=', None,
|
71 |
+
"capabilities required by this package"),
|
72 |
+
('conflicts=', None,
|
73 |
+
"capabilities which conflict with this package"),
|
74 |
+
('build-requires=', None,
|
75 |
+
"capabilities required to build this package"),
|
76 |
+
('obsoletes=', None,
|
77 |
+
"capabilities made obsolete by this package"),
|
78 |
+
('no-autoreq', None,
|
79 |
+
"do not automatically calculate dependencies"),
|
80 |
+
|
81 |
+
# Actions to take when building RPM
|
82 |
+
('keep-temp', 'k',
|
83 |
+
"don't clean up RPM build directory"),
|
84 |
+
('no-keep-temp', None,
|
85 |
+
"clean up RPM build directory [default]"),
|
86 |
+
('use-rpm-opt-flags', None,
|
87 |
+
"compile with RPM_OPT_FLAGS when building from source RPM"),
|
88 |
+
('no-rpm-opt-flags', None,
|
89 |
+
"do not pass any RPM CFLAGS to compiler"),
|
90 |
+
('rpm3-mode', None,
|
91 |
+
"RPM 3 compatibility mode (default)"),
|
92 |
+
('rpm2-mode', None,
|
93 |
+
"RPM 2 compatibility mode"),
|
94 |
+
|
95 |
+
# Add the hooks necessary for specifying custom scripts
|
96 |
+
('prep-script=', None,
|
97 |
+
"Specify a script for the PREP phase of RPM building"),
|
98 |
+
('build-script=', None,
|
99 |
+
"Specify a script for the BUILD phase of RPM building"),
|
100 |
+
|
101 |
+
('pre-install=', None,
|
102 |
+
"Specify a script for the pre-INSTALL phase of RPM building"),
|
103 |
+
('install-script=', None,
|
104 |
+
"Specify a script for the INSTALL phase of RPM building"),
|
105 |
+
('post-install=', None,
|
106 |
+
"Specify a script for the post-INSTALL phase of RPM building"),
|
107 |
+
|
108 |
+
('pre-uninstall=', None,
|
109 |
+
"Specify a script for the pre-UNINSTALL phase of RPM building"),
|
110 |
+
('post-uninstall=', None,
|
111 |
+
"Specify a script for the post-UNINSTALL phase of RPM building"),
|
112 |
+
|
113 |
+
('clean-script=', None,
|
114 |
+
"Specify a script for the CLEAN phase of RPM building"),
|
115 |
+
|
116 |
+
('verify-script=', None,
|
117 |
+
"Specify a script for the VERIFY phase of the RPM build"),
|
118 |
+
|
119 |
+
# Allow a packager to explicitly force an architecture
|
120 |
+
('force-arch=', None,
|
121 |
+
"Force an architecture onto the RPM build process"),
|
122 |
+
|
123 |
+
('quiet', 'q',
|
124 |
+
"Run the INSTALL phase of RPM building in quiet mode"),
|
125 |
+
]
|
126 |
+
|
127 |
+
boolean_options = ['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode',
|
128 |
+
'no-autoreq', 'quiet']
|
129 |
+
|
130 |
+
negative_opt = {'no-keep-temp': 'keep-temp',
|
131 |
+
'no-rpm-opt-flags': 'use-rpm-opt-flags',
|
132 |
+
'rpm2-mode': 'rpm3-mode'}
|
133 |
+
|
134 |
+
|
135 |
+
def initialize_options(self):
|
136 |
+
self.bdist_base = None
|
137 |
+
self.rpm_base = None
|
138 |
+
self.dist_dir = None
|
139 |
+
self.python = None
|
140 |
+
self.fix_python = None
|
141 |
+
self.spec_only = None
|
142 |
+
self.binary_only = None
|
143 |
+
self.source_only = None
|
144 |
+
self.use_bzip2 = None
|
145 |
+
|
146 |
+
self.distribution_name = None
|
147 |
+
self.group = None
|
148 |
+
self.release = None
|
149 |
+
self.serial = None
|
150 |
+
self.vendor = None
|
151 |
+
self.packager = None
|
152 |
+
self.doc_files = None
|
153 |
+
self.changelog = None
|
154 |
+
self.icon = None
|
155 |
+
|
156 |
+
self.prep_script = None
|
157 |
+
self.build_script = None
|
158 |
+
self.install_script = None
|
159 |
+
self.clean_script = None
|
160 |
+
self.verify_script = None
|
161 |
+
self.pre_install = None
|
162 |
+
self.post_install = None
|
163 |
+
self.pre_uninstall = None
|
164 |
+
self.post_uninstall = None
|
165 |
+
self.prep = None
|
166 |
+
self.provides = None
|
167 |
+
self.requires = None
|
168 |
+
self.conflicts = None
|
169 |
+
self.build_requires = None
|
170 |
+
self.obsoletes = None
|
171 |
+
|
172 |
+
self.keep_temp = 0
|
173 |
+
self.use_rpm_opt_flags = 1
|
174 |
+
self.rpm3_mode = 1
|
175 |
+
self.no_autoreq = 0
|
176 |
+
|
177 |
+
self.force_arch = None
|
178 |
+
self.quiet = 0
|
179 |
+
|
180 |
+
def finalize_options(self):
|
181 |
+
self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
|
182 |
+
if self.rpm_base is None:
|
183 |
+
if not self.rpm3_mode:
|
184 |
+
raise DistutilsOptionError(
|
185 |
+
"you must specify --rpm-base in RPM 2 mode")
|
186 |
+
self.rpm_base = os.path.join(self.bdist_base, "rpm")
|
187 |
+
|
188 |
+
if self.python is None:
|
189 |
+
if self.fix_python:
|
190 |
+
self.python = sys.executable
|
191 |
+
else:
|
192 |
+
self.python = "python3"
|
193 |
+
elif self.fix_python:
|
194 |
+
raise DistutilsOptionError(
|
195 |
+
"--python and --fix-python are mutually exclusive options")
|
196 |
+
|
197 |
+
if os.name != 'posix':
|
198 |
+
raise DistutilsPlatformError("don't know how to create RPM "
|
199 |
+
"distributions on platform %s" % os.name)
|
200 |
+
if self.binary_only and self.source_only:
|
201 |
+
raise DistutilsOptionError(
|
202 |
+
"cannot supply both '--source-only' and '--binary-only'")
|
203 |
+
|
204 |
+
# don't pass CFLAGS to pure python distributions
|
205 |
+
if not self.distribution.has_ext_modules():
|
206 |
+
self.use_rpm_opt_flags = 0
|
207 |
+
|
208 |
+
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
|
209 |
+
self.finalize_package_data()
|
210 |
+
|
211 |
+
def finalize_package_data(self):
|
212 |
+
self.ensure_string('group', "Development/Libraries")
|
213 |
+
self.ensure_string('vendor',
|
214 |
+
"%s <%s>" % (self.distribution.get_contact(),
|
215 |
+
self.distribution.get_contact_email()))
|
216 |
+
self.ensure_string('packager')
|
217 |
+
self.ensure_string_list('doc_files')
|
218 |
+
if isinstance(self.doc_files, list):
|
219 |
+
for readme in ('README', 'README.txt'):
|
220 |
+
if os.path.exists(readme) and readme not in self.doc_files:
|
221 |
+
self.doc_files.append(readme)
|
222 |
+
|
223 |
+
self.ensure_string('release', "1")
|
224 |
+
self.ensure_string('serial') # should it be an int?
|
225 |
+
|
226 |
+
self.ensure_string('distribution_name')
|
227 |
+
|
228 |
+
self.ensure_string('changelog')
|
229 |
+
# Format changelog correctly
|
230 |
+
self.changelog = self._format_changelog(self.changelog)
|
231 |
+
|
232 |
+
self.ensure_filename('icon')
|
233 |
+
|
234 |
+
self.ensure_filename('prep_script')
|
235 |
+
self.ensure_filename('build_script')
|
236 |
+
self.ensure_filename('install_script')
|
237 |
+
self.ensure_filename('clean_script')
|
238 |
+
self.ensure_filename('verify_script')
|
239 |
+
self.ensure_filename('pre_install')
|
240 |
+
self.ensure_filename('post_install')
|
241 |
+
self.ensure_filename('pre_uninstall')
|
242 |
+
self.ensure_filename('post_uninstall')
|
243 |
+
|
244 |
+
# XXX don't forget we punted on summaries and descriptions -- they
|
245 |
+
# should be handled here eventually!
|
246 |
+
|
247 |
+
# Now *this* is some meta-data that belongs in the setup script...
|
248 |
+
self.ensure_string_list('provides')
|
249 |
+
self.ensure_string_list('requires')
|
250 |
+
self.ensure_string_list('conflicts')
|
251 |
+
self.ensure_string_list('build_requires')
|
252 |
+
self.ensure_string_list('obsoletes')
|
253 |
+
|
254 |
+
self.ensure_string('force_arch')
|
255 |
+
|
256 |
+
def run(self):
|
257 |
+
if DEBUG:
|
258 |
+
print("before _get_package_data():")
|
259 |
+
print("vendor =", self.vendor)
|
260 |
+
print("packager =", self.packager)
|
261 |
+
print("doc_files =", self.doc_files)
|
262 |
+
print("changelog =", self.changelog)
|
263 |
+
|
264 |
+
# make directories
|
265 |
+
if self.spec_only:
|
266 |
+
spec_dir = self.dist_dir
|
267 |
+
self.mkpath(spec_dir)
|
268 |
+
else:
|
269 |
+
rpm_dir = {}
|
270 |
+
for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
|
271 |
+
rpm_dir[d] = os.path.join(self.rpm_base, d)
|
272 |
+
self.mkpath(rpm_dir[d])
|
273 |
+
spec_dir = rpm_dir['SPECS']
|
274 |
+
|
275 |
+
# Spec file goes into 'dist_dir' if '--spec-only specified',
|
276 |
+
# build/rpm.<plat> otherwise.
|
277 |
+
spec_path = os.path.join(spec_dir,
|
278 |
+
"%s.spec" % self.distribution.get_name())
|
279 |
+
self.execute(write_file,
|
280 |
+
(spec_path,
|
281 |
+
self._make_spec_file()),
|
282 |
+
"writing '%s'" % spec_path)
|
283 |
+
|
284 |
+
if self.spec_only: # stop if requested
|
285 |
+
return
|
286 |
+
|
287 |
+
# Make a source distribution and copy to SOURCES directory with
|
288 |
+
# optional icon.
|
289 |
+
saved_dist_files = self.distribution.dist_files[:]
|
290 |
+
sdist = self.reinitialize_command('sdist')
|
291 |
+
if self.use_bzip2:
|
292 |
+
sdist.formats = ['bztar']
|
293 |
+
else:
|
294 |
+
sdist.formats = ['gztar']
|
295 |
+
self.run_command('sdist')
|
296 |
+
self.distribution.dist_files = saved_dist_files
|
297 |
+
|
298 |
+
source = sdist.get_archive_files()[0]
|
299 |
+
source_dir = rpm_dir['SOURCES']
|
300 |
+
self.copy_file(source, source_dir)
|
301 |
+
|
302 |
+
if self.icon:
|
303 |
+
if os.path.exists(self.icon):
|
304 |
+
self.copy_file(self.icon, source_dir)
|
305 |
+
else:
|
306 |
+
raise DistutilsFileError(
|
307 |
+
"icon file '%s' does not exist" % self.icon)
|
308 |
+
|
309 |
+
# build package
|
310 |
+
log.info("building RPMs")
|
311 |
+
rpm_cmd = ['rpmbuild']
|
312 |
+
|
313 |
+
if self.source_only: # what kind of RPMs?
|
314 |
+
rpm_cmd.append('-bs')
|
315 |
+
elif self.binary_only:
|
316 |
+
rpm_cmd.append('-bb')
|
317 |
+
else:
|
318 |
+
rpm_cmd.append('-ba')
|
319 |
+
rpm_cmd.extend(['--define', '__python %s' % self.python])
|
320 |
+
if self.rpm3_mode:
|
321 |
+
rpm_cmd.extend(['--define',
|
322 |
+
'_topdir %s' % os.path.abspath(self.rpm_base)])
|
323 |
+
if not self.keep_temp:
|
324 |
+
rpm_cmd.append('--clean')
|
325 |
+
|
326 |
+
if self.quiet:
|
327 |
+
rpm_cmd.append('--quiet')
|
328 |
+
|
329 |
+
rpm_cmd.append(spec_path)
|
330 |
+
# Determine the binary rpm names that should be built out of this spec
|
331 |
+
# file
|
332 |
+
# Note that some of these may not be really built (if the file
|
333 |
+
# list is empty)
|
334 |
+
nvr_string = "%{name}-%{version}-%{release}"
|
335 |
+
src_rpm = nvr_string + ".src.rpm"
|
336 |
+
non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
|
337 |
+
q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % (
|
338 |
+
src_rpm, non_src_rpm, spec_path)
|
339 |
+
|
340 |
+
out = os.popen(q_cmd)
|
341 |
+
try:
|
342 |
+
binary_rpms = []
|
343 |
+
source_rpm = None
|
344 |
+
while True:
|
345 |
+
line = out.readline()
|
346 |
+
if not line:
|
347 |
+
break
|
348 |
+
l = line.strip().split()
|
349 |
+
assert(len(l) == 2)
|
350 |
+
binary_rpms.append(l[1])
|
351 |
+
# The source rpm is named after the first entry in the spec file
|
352 |
+
if source_rpm is None:
|
353 |
+
source_rpm = l[0]
|
354 |
+
|
355 |
+
status = out.close()
|
356 |
+
if status:
|
357 |
+
raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
|
358 |
+
|
359 |
+
finally:
|
360 |
+
out.close()
|
361 |
+
|
362 |
+
self.spawn(rpm_cmd)
|
363 |
+
|
364 |
+
if not self.dry_run:
|
365 |
+
if self.distribution.has_ext_modules():
|
366 |
+
pyversion = get_python_version()
|
367 |
+
else:
|
368 |
+
pyversion = 'any'
|
369 |
+
|
370 |
+
if not self.binary_only:
|
371 |
+
srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
|
372 |
+
assert(os.path.exists(srpm))
|
373 |
+
self.move_file(srpm, self.dist_dir)
|
374 |
+
filename = os.path.join(self.dist_dir, source_rpm)
|
375 |
+
self.distribution.dist_files.append(
|
376 |
+
('bdist_rpm', pyversion, filename))
|
377 |
+
|
378 |
+
if not self.source_only:
|
379 |
+
for rpm in binary_rpms:
|
380 |
+
rpm = os.path.join(rpm_dir['RPMS'], rpm)
|
381 |
+
if os.path.exists(rpm):
|
382 |
+
self.move_file(rpm, self.dist_dir)
|
383 |
+
filename = os.path.join(self.dist_dir,
|
384 |
+
os.path.basename(rpm))
|
385 |
+
self.distribution.dist_files.append(
|
386 |
+
('bdist_rpm', pyversion, filename))
|
387 |
+
|
388 |
+
def _dist_path(self, path):
|
389 |
+
return os.path.join(self.dist_dir, os.path.basename(path))
|
390 |
+
|
391 |
+
def _make_spec_file(self):
|
392 |
+
"""Generate the text of an RPM spec file and return it as a
|
393 |
+
list of strings (one per line).
|
394 |
+
"""
|
395 |
+
# definitions and headers
|
396 |
+
spec_file = [
|
397 |
+
'%define name ' + self.distribution.get_name(),
|
398 |
+
'%define version ' + self.distribution.get_version().replace('-','_'),
|
399 |
+
'%define unmangled_version ' + self.distribution.get_version(),
|
400 |
+
'%define release ' + self.release.replace('-','_'),
|
401 |
+
'',
|
402 |
+
'Summary: ' + self.distribution.get_description(),
|
403 |
+
]
|
404 |
+
|
405 |
+
# Workaround for #14443 which affects some RPM based systems such as
|
406 |
+
# RHEL6 (and probably derivatives)
|
407 |
+
vendor_hook = subprocess.getoutput('rpm --eval %{__os_install_post}')
|
408 |
+
# Generate a potential replacement value for __os_install_post (whilst
|
409 |
+
# normalizing the whitespace to simplify the test for whether the
|
410 |
+
# invocation of brp-python-bytecompile passes in __python):
|
411 |
+
vendor_hook = '\n'.join([' %s \\' % line.strip()
|
412 |
+
for line in vendor_hook.splitlines()])
|
413 |
+
problem = "brp-python-bytecompile \\\n"
|
414 |
+
fixed = "brp-python-bytecompile %{__python} \\\n"
|
415 |
+
fixed_hook = vendor_hook.replace(problem, fixed)
|
416 |
+
if fixed_hook != vendor_hook:
|
417 |
+
spec_file.append('# Workaround for http://bugs.python.org/issue14443')
|
418 |
+
spec_file.append('%define __os_install_post ' + fixed_hook + '\n')
|
419 |
+
|
420 |
+
# put locale summaries into spec file
|
421 |
+
# XXX not supported for now (hard to put a dictionary
|
422 |
+
# in a config file -- arg!)
|
423 |
+
#for locale in self.summaries.keys():
|
424 |
+
# spec_file.append('Summary(%s): %s' % (locale,
|
425 |
+
# self.summaries[locale]))
|
426 |
+
|
427 |
+
spec_file.extend([
|
428 |
+
'Name: %{name}',
|
429 |
+
'Version: %{version}',
|
430 |
+
'Release: %{release}',])
|
431 |
+
|
432 |
+
# XXX yuck! this filename is available from the "sdist" command,
|
433 |
+
# but only after it has run: and we create the spec file before
|
434 |
+
# running "sdist", in case of --spec-only.
|
435 |
+
if self.use_bzip2:
|
436 |
+
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2')
|
437 |
+
else:
|
438 |
+
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz')
|
439 |
+
|
440 |
+
spec_file.extend([
|
441 |
+
'License: ' + self.distribution.get_license(),
|
442 |
+
'Group: ' + self.group,
|
443 |
+
'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
|
444 |
+
'Prefix: %{_prefix}', ])
|
445 |
+
|
446 |
+
if not self.force_arch:
|
447 |
+
# noarch if no extension modules
|
448 |
+
if not self.distribution.has_ext_modules():
|
449 |
+
spec_file.append('BuildArch: noarch')
|
450 |
+
else:
|
451 |
+
spec_file.append( 'BuildArch: %s' % self.force_arch )
|
452 |
+
|
453 |
+
for field in ('Vendor',
|
454 |
+
'Packager',
|
455 |
+
'Provides',
|
456 |
+
'Requires',
|
457 |
+
'Conflicts',
|
458 |
+
'Obsoletes',
|
459 |
+
):
|
460 |
+
val = getattr(self, field.lower())
|
461 |
+
if isinstance(val, list):
|
462 |
+
spec_file.append('%s: %s' % (field, ' '.join(val)))
|
463 |
+
elif val is not None:
|
464 |
+
spec_file.append('%s: %s' % (field, val))
|
465 |
+
|
466 |
+
|
467 |
+
if self.distribution.get_url() != 'UNKNOWN':
|
468 |
+
spec_file.append('Url: ' + self.distribution.get_url())
|
469 |
+
|
470 |
+
if self.distribution_name:
|
471 |
+
spec_file.append('Distribution: ' + self.distribution_name)
|
472 |
+
|
473 |
+
if self.build_requires:
|
474 |
+
spec_file.append('BuildRequires: ' +
|
475 |
+
' '.join(self.build_requires))
|
476 |
+
|
477 |
+
if self.icon:
|
478 |
+
spec_file.append('Icon: ' + os.path.basename(self.icon))
|
479 |
+
|
480 |
+
if self.no_autoreq:
|
481 |
+
spec_file.append('AutoReq: 0')
|
482 |
+
|
483 |
+
spec_file.extend([
|
484 |
+
'',
|
485 |
+
'%description',
|
486 |
+
self.distribution.get_long_description()
|
487 |
+
])
|
488 |
+
|
489 |
+
# put locale descriptions into spec file
|
490 |
+
# XXX again, suppressed because config file syntax doesn't
|
491 |
+
# easily support this ;-(
|
492 |
+
#for locale in self.descriptions.keys():
|
493 |
+
# spec_file.extend([
|
494 |
+
# '',
|
495 |
+
# '%description -l ' + locale,
|
496 |
+
# self.descriptions[locale],
|
497 |
+
# ])
|
498 |
+
|
499 |
+
# rpm scripts
|
500 |
+
# figure out default build script
|
501 |
+
def_setup_call = "%s %s" % (self.python,os.path.basename(sys.argv[0]))
|
502 |
+
def_build = "%s build" % def_setup_call
|
503 |
+
if self.use_rpm_opt_flags:
|
504 |
+
def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build
|
505 |
+
|
506 |
+
# insert contents of files
|
507 |
+
|
508 |
+
# XXX this is kind of misleading: user-supplied options are files
|
509 |
+
# that we open and interpolate into the spec file, but the defaults
|
510 |
+
# are just text that we drop in as-is. Hmmm.
|
511 |
+
|
512 |
+
install_cmd = ('%s install -O1 --root=$RPM_BUILD_ROOT '
|
513 |
+
'--record=INSTALLED_FILES') % def_setup_call
|
514 |
+
|
515 |
+
script_options = [
|
516 |
+
('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"),
|
517 |
+
('build', 'build_script', def_build),
|
518 |
+
('install', 'install_script', install_cmd),
|
519 |
+
('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"),
|
520 |
+
('verifyscript', 'verify_script', None),
|
521 |
+
('pre', 'pre_install', None),
|
522 |
+
('post', 'post_install', None),
|
523 |
+
('preun', 'pre_uninstall', None),
|
524 |
+
('postun', 'post_uninstall', None),
|
525 |
+
]
|
526 |
+
|
527 |
+
for (rpm_opt, attr, default) in script_options:
|
528 |
+
# Insert contents of file referred to, if no file is referred to
|
529 |
+
# use 'default' as contents of script
|
530 |
+
val = getattr(self, attr)
|
531 |
+
if val or default:
|
532 |
+
spec_file.extend([
|
533 |
+
'',
|
534 |
+
'%' + rpm_opt,])
|
535 |
+
if val:
|
536 |
+
with open(val) as f:
|
537 |
+
spec_file.extend(f.read().split('\n'))
|
538 |
+
else:
|
539 |
+
spec_file.append(default)
|
540 |
+
|
541 |
+
|
542 |
+
# files section
|
543 |
+
spec_file.extend([
|
544 |
+
'',
|
545 |
+
'%files -f INSTALLED_FILES',
|
546 |
+
'%defattr(-,root,root)',
|
547 |
+
])
|
548 |
+
|
549 |
+
if self.doc_files:
|
550 |
+
spec_file.append('%doc ' + ' '.join(self.doc_files))
|
551 |
+
|
552 |
+
if self.changelog:
|
553 |
+
spec_file.extend([
|
554 |
+
'',
|
555 |
+
'%changelog',])
|
556 |
+
spec_file.extend(self.changelog)
|
557 |
+
|
558 |
+
return spec_file
|
559 |
+
|
560 |
+
def _format_changelog(self, changelog):
|
561 |
+
"""Format the changelog correctly and convert it to a list of strings
|
562 |
+
"""
|
563 |
+
if not changelog:
|
564 |
+
return changelog
|
565 |
+
new_changelog = []
|
566 |
+
for line in changelog.strip().split('\n'):
|
567 |
+
line = line.strip()
|
568 |
+
if line[0] == '*':
|
569 |
+
new_changelog.extend(['', line])
|
570 |
+
elif line[0] == '-':
|
571 |
+
new_changelog.append(line)
|
572 |
+
else:
|
573 |
+
new_changelog.append(' ' + line)
|
574 |
+
|
575 |
+
# strip trailing newline inserted by first changelog entry
|
576 |
+
if not new_changelog[0]:
|
577 |
+
del new_changelog[0]
|
578 |
+
|
579 |
+
return new_changelog
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/bdist_wininst.py
ADDED
@@ -0,0 +1,377 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.bdist_wininst
|
2 |
+
|
3 |
+
Implements the Distutils 'bdist_wininst' command: create a windows installer
|
4 |
+
exe-program."""
|
5 |
+
|
6 |
+
import os
|
7 |
+
import sys
|
8 |
+
import warnings
|
9 |
+
from distutils.core import Command
|
10 |
+
from distutils.util import get_platform
|
11 |
+
from distutils.dir_util import remove_tree
|
12 |
+
from distutils.errors import *
|
13 |
+
from distutils.sysconfig import get_python_version
|
14 |
+
from distutils import log
|
15 |
+
|
16 |
+
class bdist_wininst(Command):
|
17 |
+
|
18 |
+
description = "create an executable installer for MS Windows"
|
19 |
+
|
20 |
+
user_options = [('bdist-dir=', None,
|
21 |
+
"temporary directory for creating the distribution"),
|
22 |
+
('plat-name=', 'p',
|
23 |
+
"platform name to embed in generated filenames "
|
24 |
+
"(default: %s)" % get_platform()),
|
25 |
+
('keep-temp', 'k',
|
26 |
+
"keep the pseudo-installation tree around after " +
|
27 |
+
"creating the distribution archive"),
|
28 |
+
('target-version=', None,
|
29 |
+
"require a specific python version" +
|
30 |
+
" on the target system"),
|
31 |
+
('no-target-compile', 'c',
|
32 |
+
"do not compile .py to .pyc on the target system"),
|
33 |
+
('no-target-optimize', 'o',
|
34 |
+
"do not compile .py to .pyo (optimized) "
|
35 |
+
"on the target system"),
|
36 |
+
('dist-dir=', 'd',
|
37 |
+
"directory to put final built distributions in"),
|
38 |
+
('bitmap=', 'b',
|
39 |
+
"bitmap to use for the installer instead of python-powered logo"),
|
40 |
+
('title=', 't',
|
41 |
+
"title to display on the installer background instead of default"),
|
42 |
+
('skip-build', None,
|
43 |
+
"skip rebuilding everything (for testing/debugging)"),
|
44 |
+
('install-script=', None,
|
45 |
+
"basename of installation script to be run after "
|
46 |
+
"installation or before deinstallation"),
|
47 |
+
('pre-install-script=', None,
|
48 |
+
"Fully qualified filename of a script to be run before "
|
49 |
+
"any files are installed. This script need not be in the "
|
50 |
+
"distribution"),
|
51 |
+
('user-access-control=', None,
|
52 |
+
"specify Vista's UAC handling - 'none'/default=no "
|
53 |
+
"handling, 'auto'=use UAC if target Python installed for "
|
54 |
+
"all users, 'force'=always use UAC"),
|
55 |
+
]
|
56 |
+
|
57 |
+
boolean_options = ['keep-temp', 'no-target-compile', 'no-target-optimize',
|
58 |
+
'skip-build']
|
59 |
+
|
60 |
+
# bpo-10945: bdist_wininst requires mbcs encoding only available on Windows
|
61 |
+
_unsupported = (sys.platform != "win32")
|
62 |
+
|
63 |
+
def __init__(self, *args, **kw):
|
64 |
+
super().__init__(*args, **kw)
|
65 |
+
warnings.warn("bdist_wininst command is deprecated since Python 3.8, "
|
66 |
+
"use bdist_wheel (wheel packages) instead",
|
67 |
+
DeprecationWarning, 2)
|
68 |
+
|
69 |
+
def initialize_options(self):
|
70 |
+
self.bdist_dir = None
|
71 |
+
self.plat_name = None
|
72 |
+
self.keep_temp = 0
|
73 |
+
self.no_target_compile = 0
|
74 |
+
self.no_target_optimize = 0
|
75 |
+
self.target_version = None
|
76 |
+
self.dist_dir = None
|
77 |
+
self.bitmap = None
|
78 |
+
self.title = None
|
79 |
+
self.skip_build = None
|
80 |
+
self.install_script = None
|
81 |
+
self.pre_install_script = None
|
82 |
+
self.user_access_control = None
|
83 |
+
|
84 |
+
|
85 |
+
def finalize_options(self):
|
86 |
+
self.set_undefined_options('bdist', ('skip_build', 'skip_build'))
|
87 |
+
|
88 |
+
if self.bdist_dir is None:
|
89 |
+
if self.skip_build and self.plat_name:
|
90 |
+
# If build is skipped and plat_name is overridden, bdist will
|
91 |
+
# not see the correct 'plat_name' - so set that up manually.
|
92 |
+
bdist = self.distribution.get_command_obj('bdist')
|
93 |
+
bdist.plat_name = self.plat_name
|
94 |
+
# next the command will be initialized using that name
|
95 |
+
bdist_base = self.get_finalized_command('bdist').bdist_base
|
96 |
+
self.bdist_dir = os.path.join(bdist_base, 'wininst')
|
97 |
+
|
98 |
+
if not self.target_version:
|
99 |
+
self.target_version = ""
|
100 |
+
|
101 |
+
if not self.skip_build and self.distribution.has_ext_modules():
|
102 |
+
short_version = get_python_version()
|
103 |
+
if self.target_version and self.target_version != short_version:
|
104 |
+
raise DistutilsOptionError(
|
105 |
+
"target version can only be %s, or the '--skip-build'" \
|
106 |
+
" option must be specified" % (short_version,))
|
107 |
+
self.target_version = short_version
|
108 |
+
|
109 |
+
self.set_undefined_options('bdist',
|
110 |
+
('dist_dir', 'dist_dir'),
|
111 |
+
('plat_name', 'plat_name'),
|
112 |
+
)
|
113 |
+
|
114 |
+
if self.install_script:
|
115 |
+
for script in self.distribution.scripts:
|
116 |
+
if self.install_script == os.path.basename(script):
|
117 |
+
break
|
118 |
+
else:
|
119 |
+
raise DistutilsOptionError(
|
120 |
+
"install_script '%s' not found in scripts"
|
121 |
+
% self.install_script)
|
122 |
+
|
123 |
+
def run(self):
|
124 |
+
if (sys.platform != "win32" and
|
125 |
+
(self.distribution.has_ext_modules() or
|
126 |
+
self.distribution.has_c_libraries())):
|
127 |
+
raise DistutilsPlatformError \
|
128 |
+
("distribution contains extensions and/or C libraries; "
|
129 |
+
"must be compiled on a Windows 32 platform")
|
130 |
+
|
131 |
+
if not self.skip_build:
|
132 |
+
self.run_command('build')
|
133 |
+
|
134 |
+
install = self.reinitialize_command('install', reinit_subcommands=1)
|
135 |
+
install.root = self.bdist_dir
|
136 |
+
install.skip_build = self.skip_build
|
137 |
+
install.warn_dir = 0
|
138 |
+
install.plat_name = self.plat_name
|
139 |
+
|
140 |
+
install_lib = self.reinitialize_command('install_lib')
|
141 |
+
# we do not want to include pyc or pyo files
|
142 |
+
install_lib.compile = 0
|
143 |
+
install_lib.optimize = 0
|
144 |
+
|
145 |
+
if self.distribution.has_ext_modules():
|
146 |
+
# If we are building an installer for a Python version other
|
147 |
+
# than the one we are currently running, then we need to ensure
|
148 |
+
# our build_lib reflects the other Python version rather than ours.
|
149 |
+
# Note that for target_version!=sys.version, we must have skipped the
|
150 |
+
# build step, so there is no issue with enforcing the build of this
|
151 |
+
# version.
|
152 |
+
target_version = self.target_version
|
153 |
+
if not target_version:
|
154 |
+
assert self.skip_build, "Should have already checked this"
|
155 |
+
target_version = '%d.%d' % sys.version_info[:2]
|
156 |
+
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
|
157 |
+
build = self.get_finalized_command('build')
|
158 |
+
build.build_lib = os.path.join(build.build_base,
|
159 |
+
'lib' + plat_specifier)
|
160 |
+
|
161 |
+
# Use a custom scheme for the zip-file, because we have to decide
|
162 |
+
# at installation time which scheme to use.
|
163 |
+
for key in ('purelib', 'platlib', 'headers', 'scripts', 'data'):
|
164 |
+
value = key.upper()
|
165 |
+
if key == 'headers':
|
166 |
+
value = value + '/Include/$dist_name'
|
167 |
+
setattr(install,
|
168 |
+
'install_' + key,
|
169 |
+
value)
|
170 |
+
|
171 |
+
log.info("installing to %s", self.bdist_dir)
|
172 |
+
install.ensure_finalized()
|
173 |
+
|
174 |
+
# avoid warning of 'install_lib' about installing
|
175 |
+
# into a directory not in sys.path
|
176 |
+
sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB'))
|
177 |
+
|
178 |
+
install.run()
|
179 |
+
|
180 |
+
del sys.path[0]
|
181 |
+
|
182 |
+
# And make an archive relative to the root of the
|
183 |
+
# pseudo-installation tree.
|
184 |
+
from tempfile import mktemp
|
185 |
+
archive_basename = mktemp()
|
186 |
+
fullname = self.distribution.get_fullname()
|
187 |
+
arcname = self.make_archive(archive_basename, "zip",
|
188 |
+
root_dir=self.bdist_dir)
|
189 |
+
# create an exe containing the zip-file
|
190 |
+
self.create_exe(arcname, fullname, self.bitmap)
|
191 |
+
if self.distribution.has_ext_modules():
|
192 |
+
pyversion = get_python_version()
|
193 |
+
else:
|
194 |
+
pyversion = 'any'
|
195 |
+
self.distribution.dist_files.append(('bdist_wininst', pyversion,
|
196 |
+
self.get_installer_filename(fullname)))
|
197 |
+
# remove the zip-file again
|
198 |
+
log.debug("removing temporary file '%s'", arcname)
|
199 |
+
os.remove(arcname)
|
200 |
+
|
201 |
+
if not self.keep_temp:
|
202 |
+
remove_tree(self.bdist_dir, dry_run=self.dry_run)
|
203 |
+
|
204 |
+
def get_inidata(self):
|
205 |
+
# Return data describing the installation.
|
206 |
+
lines = []
|
207 |
+
metadata = self.distribution.metadata
|
208 |
+
|
209 |
+
# Write the [metadata] section.
|
210 |
+
lines.append("[metadata]")
|
211 |
+
|
212 |
+
# 'info' will be displayed in the installer's dialog box,
|
213 |
+
# describing the items to be installed.
|
214 |
+
info = (metadata.long_description or '') + '\n'
|
215 |
+
|
216 |
+
# Escape newline characters
|
217 |
+
def escape(s):
|
218 |
+
return s.replace("\n", "\\n")
|
219 |
+
|
220 |
+
for name in ["author", "author_email", "description", "maintainer",
|
221 |
+
"maintainer_email", "name", "url", "version"]:
|
222 |
+
data = getattr(metadata, name, "")
|
223 |
+
if data:
|
224 |
+
info = info + ("\n %s: %s" % \
|
225 |
+
(name.capitalize(), escape(data)))
|
226 |
+
lines.append("%s=%s" % (name, escape(data)))
|
227 |
+
|
228 |
+
# The [setup] section contains entries controlling
|
229 |
+
# the installer runtime.
|
230 |
+
lines.append("\n[Setup]")
|
231 |
+
if self.install_script:
|
232 |
+
lines.append("install_script=%s" % self.install_script)
|
233 |
+
lines.append("info=%s" % escape(info))
|
234 |
+
lines.append("target_compile=%d" % (not self.no_target_compile))
|
235 |
+
lines.append("target_optimize=%d" % (not self.no_target_optimize))
|
236 |
+
if self.target_version:
|
237 |
+
lines.append("target_version=%s" % self.target_version)
|
238 |
+
if self.user_access_control:
|
239 |
+
lines.append("user_access_control=%s" % self.user_access_control)
|
240 |
+
|
241 |
+
title = self.title or self.distribution.get_fullname()
|
242 |
+
lines.append("title=%s" % escape(title))
|
243 |
+
import time
|
244 |
+
import distutils
|
245 |
+
build_info = "Built %s with distutils-%s" % \
|
246 |
+
(time.ctime(time.time()), distutils.__version__)
|
247 |
+
lines.append("build_info=%s" % build_info)
|
248 |
+
return "\n".join(lines)
|
249 |
+
|
250 |
+
def create_exe(self, arcname, fullname, bitmap=None):
|
251 |
+
import struct
|
252 |
+
|
253 |
+
self.mkpath(self.dist_dir)
|
254 |
+
|
255 |
+
cfgdata = self.get_inidata()
|
256 |
+
|
257 |
+
installer_name = self.get_installer_filename(fullname)
|
258 |
+
self.announce("creating %s" % installer_name)
|
259 |
+
|
260 |
+
if bitmap:
|
261 |
+
with open(bitmap, "rb") as f:
|
262 |
+
bitmapdata = f.read()
|
263 |
+
bitmaplen = len(bitmapdata)
|
264 |
+
else:
|
265 |
+
bitmaplen = 0
|
266 |
+
|
267 |
+
with open(installer_name, "wb") as file:
|
268 |
+
file.write(self.get_exe_bytes())
|
269 |
+
if bitmap:
|
270 |
+
file.write(bitmapdata)
|
271 |
+
|
272 |
+
# Convert cfgdata from unicode to ascii, mbcs encoded
|
273 |
+
if isinstance(cfgdata, str):
|
274 |
+
cfgdata = cfgdata.encode("mbcs")
|
275 |
+
|
276 |
+
# Append the pre-install script
|
277 |
+
cfgdata = cfgdata + b"\0"
|
278 |
+
if self.pre_install_script:
|
279 |
+
# We need to normalize newlines, so we open in text mode and
|
280 |
+
# convert back to bytes. "latin-1" simply avoids any possible
|
281 |
+
# failures.
|
282 |
+
with open(self.pre_install_script, "r",
|
283 |
+
encoding="latin-1") as script:
|
284 |
+
script_data = script.read().encode("latin-1")
|
285 |
+
cfgdata = cfgdata + script_data + b"\n\0"
|
286 |
+
else:
|
287 |
+
# empty pre-install script
|
288 |
+
cfgdata = cfgdata + b"\0"
|
289 |
+
file.write(cfgdata)
|
290 |
+
|
291 |
+
# The 'magic number' 0x1234567B is used to make sure that the
|
292 |
+
# binary layout of 'cfgdata' is what the wininst.exe binary
|
293 |
+
# expects. If the layout changes, increment that number, make
|
294 |
+
# the corresponding changes to the wininst.exe sources, and
|
295 |
+
# recompile them.
|
296 |
+
header = struct.pack("<iii",
|
297 |
+
0x1234567B, # tag
|
298 |
+
len(cfgdata), # length
|
299 |
+
bitmaplen, # number of bytes in bitmap
|
300 |
+
)
|
301 |
+
file.write(header)
|
302 |
+
with open(arcname, "rb") as f:
|
303 |
+
file.write(f.read())
|
304 |
+
|
305 |
+
def get_installer_filename(self, fullname):
|
306 |
+
# Factored out to allow overriding in subclasses
|
307 |
+
if self.target_version:
|
308 |
+
# if we create an installer for a specific python version,
|
309 |
+
# it's better to include this in the name
|
310 |
+
installer_name = os.path.join(self.dist_dir,
|
311 |
+
"%s.%s-py%s.exe" %
|
312 |
+
(fullname, self.plat_name, self.target_version))
|
313 |
+
else:
|
314 |
+
installer_name = os.path.join(self.dist_dir,
|
315 |
+
"%s.%s.exe" % (fullname, self.plat_name))
|
316 |
+
return installer_name
|
317 |
+
|
318 |
+
def get_exe_bytes(self):
|
319 |
+
# If a target-version other than the current version has been
|
320 |
+
# specified, then using the MSVC version from *this* build is no good.
|
321 |
+
# Without actually finding and executing the target version and parsing
|
322 |
+
# its sys.version, we just hard-code our knowledge of old versions.
|
323 |
+
# NOTE: Possible alternative is to allow "--target-version" to
|
324 |
+
# specify a Python executable rather than a simple version string.
|
325 |
+
# We can then execute this program to obtain any info we need, such
|
326 |
+
# as the real sys.version string for the build.
|
327 |
+
cur_version = get_python_version()
|
328 |
+
|
329 |
+
# If the target version is *later* than us, then we assume they
|
330 |
+
# use what we use
|
331 |
+
# string compares seem wrong, but are what sysconfig.py itself uses
|
332 |
+
if self.target_version and self.target_version < cur_version:
|
333 |
+
if self.target_version < "2.4":
|
334 |
+
bv = '6.0'
|
335 |
+
elif self.target_version == "2.4":
|
336 |
+
bv = '7.1'
|
337 |
+
elif self.target_version == "2.5":
|
338 |
+
bv = '8.0'
|
339 |
+
elif self.target_version <= "3.2":
|
340 |
+
bv = '9.0'
|
341 |
+
elif self.target_version <= "3.4":
|
342 |
+
bv = '10.0'
|
343 |
+
else:
|
344 |
+
bv = '14.0'
|
345 |
+
else:
|
346 |
+
# for current version - use authoritative check.
|
347 |
+
try:
|
348 |
+
from msvcrt import CRT_ASSEMBLY_VERSION
|
349 |
+
except ImportError:
|
350 |
+
# cross-building, so assume the latest version
|
351 |
+
bv = '14.0'
|
352 |
+
else:
|
353 |
+
# as far as we know, CRT is binary compatible based on
|
354 |
+
# the first field, so assume 'x.0' until proven otherwise
|
355 |
+
major = CRT_ASSEMBLY_VERSION.partition('.')[0]
|
356 |
+
bv = major + '.0'
|
357 |
+
|
358 |
+
|
359 |
+
# wininst-x.y.exe is in the same directory as this file
|
360 |
+
directory = os.path.dirname(__file__)
|
361 |
+
# we must use a wininst-x.y.exe built with the same C compiler
|
362 |
+
# used for python. XXX What about mingw, borland, and so on?
|
363 |
+
|
364 |
+
# if plat_name starts with "win" but is not "win32"
|
365 |
+
# we want to strip "win" and leave the rest (e.g. -amd64)
|
366 |
+
# for all other cases, we don't want any suffix
|
367 |
+
if self.plat_name != 'win32' and self.plat_name[:3] == 'win':
|
368 |
+
sfix = self.plat_name[3:]
|
369 |
+
else:
|
370 |
+
sfix = ''
|
371 |
+
|
372 |
+
filename = os.path.join(directory, "wininst-%s%s.exe" % (bv, sfix))
|
373 |
+
f = open(filename, "rb")
|
374 |
+
try:
|
375 |
+
return f.read()
|
376 |
+
finally:
|
377 |
+
f.close()
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build.py
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.build
|
2 |
+
|
3 |
+
Implements the Distutils 'build' command."""
|
4 |
+
|
5 |
+
import sys, os
|
6 |
+
from distutils.core import Command
|
7 |
+
from distutils.errors import DistutilsOptionError
|
8 |
+
from distutils.util import get_platform
|
9 |
+
|
10 |
+
|
11 |
+
def show_compilers():
|
12 |
+
from distutils.ccompiler import show_compilers
|
13 |
+
show_compilers()
|
14 |
+
|
15 |
+
|
16 |
+
class build(Command):
|
17 |
+
|
18 |
+
description = "build everything needed to install"
|
19 |
+
|
20 |
+
user_options = [
|
21 |
+
('build-base=', 'b',
|
22 |
+
"base directory for build library"),
|
23 |
+
('build-purelib=', None,
|
24 |
+
"build directory for platform-neutral distributions"),
|
25 |
+
('build-platlib=', None,
|
26 |
+
"build directory for platform-specific distributions"),
|
27 |
+
('build-lib=', None,
|
28 |
+
"build directory for all distribution (defaults to either " +
|
29 |
+
"build-purelib or build-platlib"),
|
30 |
+
('build-scripts=', None,
|
31 |
+
"build directory for scripts"),
|
32 |
+
('build-temp=', 't',
|
33 |
+
"temporary build directory"),
|
34 |
+
('plat-name=', 'p',
|
35 |
+
"platform name to build for, if supported "
|
36 |
+
"(default: %s)" % get_platform()),
|
37 |
+
('compiler=', 'c',
|
38 |
+
"specify the compiler type"),
|
39 |
+
('parallel=', 'j',
|
40 |
+
"number of parallel build jobs"),
|
41 |
+
('debug', 'g',
|
42 |
+
"compile extensions and libraries with debugging information"),
|
43 |
+
('force', 'f',
|
44 |
+
"forcibly build everything (ignore file timestamps)"),
|
45 |
+
('executable=', 'e',
|
46 |
+
"specify final destination interpreter path (build.py)"),
|
47 |
+
]
|
48 |
+
|
49 |
+
boolean_options = ['debug', 'force']
|
50 |
+
|
51 |
+
help_options = [
|
52 |
+
('help-compiler', None,
|
53 |
+
"list available compilers", show_compilers),
|
54 |
+
]
|
55 |
+
|
56 |
+
def initialize_options(self):
|
57 |
+
self.build_base = 'build'
|
58 |
+
# these are decided only after 'build_base' has its final value
|
59 |
+
# (unless overridden by the user or client)
|
60 |
+
self.build_purelib = None
|
61 |
+
self.build_platlib = None
|
62 |
+
self.build_lib = None
|
63 |
+
self.build_temp = None
|
64 |
+
self.build_scripts = None
|
65 |
+
self.compiler = None
|
66 |
+
self.plat_name = None
|
67 |
+
self.debug = None
|
68 |
+
self.force = 0
|
69 |
+
self.executable = None
|
70 |
+
self.parallel = None
|
71 |
+
|
72 |
+
def finalize_options(self):
|
73 |
+
if self.plat_name is None:
|
74 |
+
self.plat_name = get_platform()
|
75 |
+
else:
|
76 |
+
# plat-name only supported for windows (other platforms are
|
77 |
+
# supported via ./configure flags, if at all). Avoid misleading
|
78 |
+
# other platforms.
|
79 |
+
if os.name != 'nt':
|
80 |
+
raise DistutilsOptionError(
|
81 |
+
"--plat-name only supported on Windows (try "
|
82 |
+
"using './configure --help' on your platform)")
|
83 |
+
|
84 |
+
plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
|
85 |
+
|
86 |
+
# Make it so Python 2.x and Python 2.x with --with-pydebug don't
|
87 |
+
# share the same build directories. Doing so confuses the build
|
88 |
+
# process for C modules
|
89 |
+
if hasattr(sys, 'gettotalrefcount'):
|
90 |
+
plat_specifier += '-pydebug'
|
91 |
+
|
92 |
+
# 'build_purelib' and 'build_platlib' just default to 'lib' and
|
93 |
+
# 'lib.<plat>' under the base build directory. We only use one of
|
94 |
+
# them for a given distribution, though --
|
95 |
+
if self.build_purelib is None:
|
96 |
+
self.build_purelib = os.path.join(self.build_base, 'lib')
|
97 |
+
if self.build_platlib is None:
|
98 |
+
self.build_platlib = os.path.join(self.build_base,
|
99 |
+
'lib' + plat_specifier)
|
100 |
+
|
101 |
+
# 'build_lib' is the actual directory that we will use for this
|
102 |
+
# particular module distribution -- if user didn't supply it, pick
|
103 |
+
# one of 'build_purelib' or 'build_platlib'.
|
104 |
+
if self.build_lib is None:
|
105 |
+
if self.distribution.has_ext_modules():
|
106 |
+
self.build_lib = self.build_platlib
|
107 |
+
else:
|
108 |
+
self.build_lib = self.build_purelib
|
109 |
+
|
110 |
+
# 'build_temp' -- temporary directory for compiler turds,
|
111 |
+
# "build/temp.<plat>"
|
112 |
+
if self.build_temp is None:
|
113 |
+
self.build_temp = os.path.join(self.build_base,
|
114 |
+
'temp' + plat_specifier)
|
115 |
+
if self.build_scripts is None:
|
116 |
+
self.build_scripts = os.path.join(self.build_base,
|
117 |
+
'scripts-%d.%d' % sys.version_info[:2])
|
118 |
+
|
119 |
+
if self.executable is None and sys.executable:
|
120 |
+
self.executable = os.path.normpath(sys.executable)
|
121 |
+
|
122 |
+
if isinstance(self.parallel, str):
|
123 |
+
try:
|
124 |
+
self.parallel = int(self.parallel)
|
125 |
+
except ValueError:
|
126 |
+
raise DistutilsOptionError("parallel should be an integer")
|
127 |
+
|
128 |
+
def run(self):
|
129 |
+
# Run all relevant sub-commands. This will be some subset of:
|
130 |
+
# - build_py - pure Python modules
|
131 |
+
# - build_clib - standalone C libraries
|
132 |
+
# - build_ext - Python extensions
|
133 |
+
# - build_scripts - (Python) scripts
|
134 |
+
for cmd_name in self.get_sub_commands():
|
135 |
+
self.run_command(cmd_name)
|
136 |
+
|
137 |
+
|
138 |
+
# -- Predicates for the sub-command list ---------------------------
|
139 |
+
|
140 |
+
def has_pure_modules(self):
|
141 |
+
return self.distribution.has_pure_modules()
|
142 |
+
|
143 |
+
def has_c_libraries(self):
|
144 |
+
return self.distribution.has_c_libraries()
|
145 |
+
|
146 |
+
def has_ext_modules(self):
|
147 |
+
return self.distribution.has_ext_modules()
|
148 |
+
|
149 |
+
def has_scripts(self):
|
150 |
+
return self.distribution.has_scripts()
|
151 |
+
|
152 |
+
|
153 |
+
sub_commands = [('build_py', has_pure_modules),
|
154 |
+
('build_clib', has_c_libraries),
|
155 |
+
('build_ext', has_ext_modules),
|
156 |
+
('build_scripts', has_scripts),
|
157 |
+
]
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build_clib.py
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.build_clib
|
2 |
+
|
3 |
+
Implements the Distutils 'build_clib' command, to build a C/C++ library
|
4 |
+
that is included in the module distribution and needed by an extension
|
5 |
+
module."""
|
6 |
+
|
7 |
+
|
8 |
+
# XXX this module has *lots* of code ripped-off quite transparently from
|
9 |
+
# build_ext.py -- not surprisingly really, as the work required to build
|
10 |
+
# a static library from a collection of C source files is not really all
|
11 |
+
# that different from what's required to build a shared object file from
|
12 |
+
# a collection of C source files. Nevertheless, I haven't done the
|
13 |
+
# necessary refactoring to account for the overlap in code between the
|
14 |
+
# two modules, mainly because a number of subtle details changed in the
|
15 |
+
# cut 'n paste. Sigh.
|
16 |
+
|
17 |
+
import os
|
18 |
+
from distutils.core import Command
|
19 |
+
from distutils.errors import *
|
20 |
+
from distutils.sysconfig import customize_compiler
|
21 |
+
from distutils import log
|
22 |
+
|
23 |
+
def show_compilers():
|
24 |
+
from distutils.ccompiler import show_compilers
|
25 |
+
show_compilers()
|
26 |
+
|
27 |
+
|
28 |
+
class build_clib(Command):
|
29 |
+
|
30 |
+
description = "build C/C++ libraries used by Python extensions"
|
31 |
+
|
32 |
+
user_options = [
|
33 |
+
('build-clib=', 'b',
|
34 |
+
"directory to build C/C++ libraries to"),
|
35 |
+
('build-temp=', 't',
|
36 |
+
"directory to put temporary build by-products"),
|
37 |
+
('debug', 'g',
|
38 |
+
"compile with debugging information"),
|
39 |
+
('force', 'f',
|
40 |
+
"forcibly build everything (ignore file timestamps)"),
|
41 |
+
('compiler=', 'c',
|
42 |
+
"specify the compiler type"),
|
43 |
+
]
|
44 |
+
|
45 |
+
boolean_options = ['debug', 'force']
|
46 |
+
|
47 |
+
help_options = [
|
48 |
+
('help-compiler', None,
|
49 |
+
"list available compilers", show_compilers),
|
50 |
+
]
|
51 |
+
|
52 |
+
def initialize_options(self):
|
53 |
+
self.build_clib = None
|
54 |
+
self.build_temp = None
|
55 |
+
|
56 |
+
# List of libraries to build
|
57 |
+
self.libraries = None
|
58 |
+
|
59 |
+
# Compilation options for all libraries
|
60 |
+
self.include_dirs = None
|
61 |
+
self.define = None
|
62 |
+
self.undef = None
|
63 |
+
self.debug = None
|
64 |
+
self.force = 0
|
65 |
+
self.compiler = None
|
66 |
+
|
67 |
+
|
68 |
+
def finalize_options(self):
|
69 |
+
# This might be confusing: both build-clib and build-temp default
|
70 |
+
# to build-temp as defined by the "build" command. This is because
|
71 |
+
# I think that C libraries are really just temporary build
|
72 |
+
# by-products, at least from the point of view of building Python
|
73 |
+
# extensions -- but I want to keep my options open.
|
74 |
+
self.set_undefined_options('build',
|
75 |
+
('build_temp', 'build_clib'),
|
76 |
+
('build_temp', 'build_temp'),
|
77 |
+
('compiler', 'compiler'),
|
78 |
+
('debug', 'debug'),
|
79 |
+
('force', 'force'))
|
80 |
+
|
81 |
+
self.libraries = self.distribution.libraries
|
82 |
+
if self.libraries:
|
83 |
+
self.check_library_list(self.libraries)
|
84 |
+
|
85 |
+
if self.include_dirs is None:
|
86 |
+
self.include_dirs = self.distribution.include_dirs or []
|
87 |
+
if isinstance(self.include_dirs, str):
|
88 |
+
self.include_dirs = self.include_dirs.split(os.pathsep)
|
89 |
+
|
90 |
+
# XXX same as for build_ext -- what about 'self.define' and
|
91 |
+
# 'self.undef' ?
|
92 |
+
|
93 |
+
|
94 |
+
def run(self):
|
95 |
+
if not self.libraries:
|
96 |
+
return
|
97 |
+
|
98 |
+
# Yech -- this is cut 'n pasted from build_ext.py!
|
99 |
+
from distutils.ccompiler import new_compiler
|
100 |
+
self.compiler = new_compiler(compiler=self.compiler,
|
101 |
+
dry_run=self.dry_run,
|
102 |
+
force=self.force)
|
103 |
+
customize_compiler(self.compiler)
|
104 |
+
|
105 |
+
if self.include_dirs is not None:
|
106 |
+
self.compiler.set_include_dirs(self.include_dirs)
|
107 |
+
if self.define is not None:
|
108 |
+
# 'define' option is a list of (name,value) tuples
|
109 |
+
for (name,value) in self.define:
|
110 |
+
self.compiler.define_macro(name, value)
|
111 |
+
if self.undef is not None:
|
112 |
+
for macro in self.undef:
|
113 |
+
self.compiler.undefine_macro(macro)
|
114 |
+
|
115 |
+
self.build_libraries(self.libraries)
|
116 |
+
|
117 |
+
|
118 |
+
def check_library_list(self, libraries):
|
119 |
+
"""Ensure that the list of libraries is valid.
|
120 |
+
|
121 |
+
`library` is presumably provided as a command option 'libraries'.
|
122 |
+
This method checks that it is a list of 2-tuples, where the tuples
|
123 |
+
are (library_name, build_info_dict).
|
124 |
+
|
125 |
+
Raise DistutilsSetupError if the structure is invalid anywhere;
|
126 |
+
just returns otherwise.
|
127 |
+
"""
|
128 |
+
if not isinstance(libraries, list):
|
129 |
+
raise DistutilsSetupError(
|
130 |
+
"'libraries' option must be a list of tuples")
|
131 |
+
|
132 |
+
for lib in libraries:
|
133 |
+
if not isinstance(lib, tuple) and len(lib) != 2:
|
134 |
+
raise DistutilsSetupError(
|
135 |
+
"each element of 'libraries' must a 2-tuple")
|
136 |
+
|
137 |
+
name, build_info = lib
|
138 |
+
|
139 |
+
if not isinstance(name, str):
|
140 |
+
raise DistutilsSetupError(
|
141 |
+
"first element of each tuple in 'libraries' "
|
142 |
+
"must be a string (the library name)")
|
143 |
+
|
144 |
+
if '/' in name or (os.sep != '/' and os.sep in name):
|
145 |
+
raise DistutilsSetupError("bad library name '%s': "
|
146 |
+
"may not contain directory separators" % lib[0])
|
147 |
+
|
148 |
+
if not isinstance(build_info, dict):
|
149 |
+
raise DistutilsSetupError(
|
150 |
+
"second element of each tuple in 'libraries' "
|
151 |
+
"must be a dictionary (build info)")
|
152 |
+
|
153 |
+
|
154 |
+
def get_library_names(self):
|
155 |
+
# Assume the library list is valid -- 'check_library_list()' is
|
156 |
+
# called from 'finalize_options()', so it should be!
|
157 |
+
if not self.libraries:
|
158 |
+
return None
|
159 |
+
|
160 |
+
lib_names = []
|
161 |
+
for (lib_name, build_info) in self.libraries:
|
162 |
+
lib_names.append(lib_name)
|
163 |
+
return lib_names
|
164 |
+
|
165 |
+
|
166 |
+
def get_source_files(self):
|
167 |
+
self.check_library_list(self.libraries)
|
168 |
+
filenames = []
|
169 |
+
for (lib_name, build_info) in self.libraries:
|
170 |
+
sources = build_info.get('sources')
|
171 |
+
if sources is None or not isinstance(sources, (list, tuple)):
|
172 |
+
raise DistutilsSetupError(
|
173 |
+
"in 'libraries' option (library '%s'), "
|
174 |
+
"'sources' must be present and must be "
|
175 |
+
"a list of source filenames" % lib_name)
|
176 |
+
|
177 |
+
filenames.extend(sources)
|
178 |
+
return filenames
|
179 |
+
|
180 |
+
|
181 |
+
def build_libraries(self, libraries):
|
182 |
+
for (lib_name, build_info) in libraries:
|
183 |
+
sources = build_info.get('sources')
|
184 |
+
if sources is None or not isinstance(sources, (list, tuple)):
|
185 |
+
raise DistutilsSetupError(
|
186 |
+
"in 'libraries' option (library '%s'), "
|
187 |
+
"'sources' must be present and must be "
|
188 |
+
"a list of source filenames" % lib_name)
|
189 |
+
sources = list(sources)
|
190 |
+
|
191 |
+
log.info("building '%s' library", lib_name)
|
192 |
+
|
193 |
+
# First, compile the source code to object files in the library
|
194 |
+
# directory. (This should probably change to putting object
|
195 |
+
# files in a temporary build directory.)
|
196 |
+
macros = build_info.get('macros')
|
197 |
+
include_dirs = build_info.get('include_dirs')
|
198 |
+
objects = self.compiler.compile(sources,
|
199 |
+
output_dir=self.build_temp,
|
200 |
+
macros=macros,
|
201 |
+
include_dirs=include_dirs,
|
202 |
+
debug=self.debug)
|
203 |
+
|
204 |
+
# Now "link" the object files together into a static library.
|
205 |
+
# (On Unix at least, this isn't really linking -- it just
|
206 |
+
# builds an archive. Whatever.)
|
207 |
+
self.compiler.create_static_lib(objects, lib_name,
|
208 |
+
output_dir=self.build_clib,
|
209 |
+
debug=self.debug)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build_ext.py
ADDED
@@ -0,0 +1,755 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.build_ext
|
2 |
+
|
3 |
+
Implements the Distutils 'build_ext' command, for building extension
|
4 |
+
modules (currently limited to C extensions, should accommodate C++
|
5 |
+
extensions ASAP)."""
|
6 |
+
|
7 |
+
import contextlib
|
8 |
+
import os
|
9 |
+
import re
|
10 |
+
import sys
|
11 |
+
from distutils.core import Command
|
12 |
+
from distutils.errors import *
|
13 |
+
from distutils.sysconfig import customize_compiler, get_python_version
|
14 |
+
from distutils.sysconfig import get_config_h_filename
|
15 |
+
from distutils.dep_util import newer_group
|
16 |
+
from distutils.extension import Extension
|
17 |
+
from distutils.util import get_platform
|
18 |
+
from distutils import log
|
19 |
+
from . import py37compat
|
20 |
+
|
21 |
+
from site import USER_BASE
|
22 |
+
|
23 |
+
# An extension name is just a dot-separated list of Python NAMEs (ie.
|
24 |
+
# the same as a fully-qualified module name).
|
25 |
+
extension_name_re = re.compile \
|
26 |
+
(r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
|
27 |
+
|
28 |
+
|
29 |
+
def show_compilers ():
|
30 |
+
from distutils.ccompiler import show_compilers
|
31 |
+
show_compilers()
|
32 |
+
|
33 |
+
|
34 |
+
class build_ext(Command):
|
35 |
+
|
36 |
+
description = "build C/C++ extensions (compile/link to build directory)"
|
37 |
+
|
38 |
+
# XXX thoughts on how to deal with complex command-line options like
|
39 |
+
# these, i.e. how to make it so fancy_getopt can suck them off the
|
40 |
+
# command line and make it look like setup.py defined the appropriate
|
41 |
+
# lists of tuples of what-have-you.
|
42 |
+
# - each command needs a callback to process its command-line options
|
43 |
+
# - Command.__init__() needs access to its share of the whole
|
44 |
+
# command line (must ultimately come from
|
45 |
+
# Distribution.parse_command_line())
|
46 |
+
# - it then calls the current command class' option-parsing
|
47 |
+
# callback to deal with weird options like -D, which have to
|
48 |
+
# parse the option text and churn out some custom data
|
49 |
+
# structure
|
50 |
+
# - that data structure (in this case, a list of 2-tuples)
|
51 |
+
# will then be present in the command object by the time
|
52 |
+
# we get to finalize_options() (i.e. the constructor
|
53 |
+
# takes care of both command-line and client options
|
54 |
+
# in between initialize_options() and finalize_options())
|
55 |
+
|
56 |
+
sep_by = " (separated by '%s')" % os.pathsep
|
57 |
+
user_options = [
|
58 |
+
('build-lib=', 'b',
|
59 |
+
"directory for compiled extension modules"),
|
60 |
+
('build-temp=', 't',
|
61 |
+
"directory for temporary files (build by-products)"),
|
62 |
+
('plat-name=', 'p',
|
63 |
+
"platform name to cross-compile for, if supported "
|
64 |
+
"(default: %s)" % get_platform()),
|
65 |
+
('inplace', 'i',
|
66 |
+
"ignore build-lib and put compiled extensions into the source " +
|
67 |
+
"directory alongside your pure Python modules"),
|
68 |
+
('include-dirs=', 'I',
|
69 |
+
"list of directories to search for header files" + sep_by),
|
70 |
+
('define=', 'D',
|
71 |
+
"C preprocessor macros to define"),
|
72 |
+
('undef=', 'U',
|
73 |
+
"C preprocessor macros to undefine"),
|
74 |
+
('libraries=', 'l',
|
75 |
+
"external C libraries to link with"),
|
76 |
+
('library-dirs=', 'L',
|
77 |
+
"directories to search for external C libraries" + sep_by),
|
78 |
+
('rpath=', 'R',
|
79 |
+
"directories to search for shared C libraries at runtime"),
|
80 |
+
('link-objects=', 'O',
|
81 |
+
"extra explicit link objects to include in the link"),
|
82 |
+
('debug', 'g',
|
83 |
+
"compile/link with debugging information"),
|
84 |
+
('force', 'f',
|
85 |
+
"forcibly build everything (ignore file timestamps)"),
|
86 |
+
('compiler=', 'c',
|
87 |
+
"specify the compiler type"),
|
88 |
+
('parallel=', 'j',
|
89 |
+
"number of parallel build jobs"),
|
90 |
+
('swig-cpp', None,
|
91 |
+
"make SWIG create C++ files (default is C)"),
|
92 |
+
('swig-opts=', None,
|
93 |
+
"list of SWIG command line options"),
|
94 |
+
('swig=', None,
|
95 |
+
"path to the SWIG executable"),
|
96 |
+
('user', None,
|
97 |
+
"add user include, library and rpath")
|
98 |
+
]
|
99 |
+
|
100 |
+
boolean_options = ['inplace', 'debug', 'force', 'swig-cpp', 'user']
|
101 |
+
|
102 |
+
help_options = [
|
103 |
+
('help-compiler', None,
|
104 |
+
"list available compilers", show_compilers),
|
105 |
+
]
|
106 |
+
|
107 |
+
def initialize_options(self):
|
108 |
+
self.extensions = None
|
109 |
+
self.build_lib = None
|
110 |
+
self.plat_name = None
|
111 |
+
self.build_temp = None
|
112 |
+
self.inplace = 0
|
113 |
+
self.package = None
|
114 |
+
|
115 |
+
self.include_dirs = None
|
116 |
+
self.define = None
|
117 |
+
self.undef = None
|
118 |
+
self.libraries = None
|
119 |
+
self.library_dirs = None
|
120 |
+
self.rpath = None
|
121 |
+
self.link_objects = None
|
122 |
+
self.debug = None
|
123 |
+
self.force = None
|
124 |
+
self.compiler = None
|
125 |
+
self.swig = None
|
126 |
+
self.swig_cpp = None
|
127 |
+
self.swig_opts = None
|
128 |
+
self.user = None
|
129 |
+
self.parallel = None
|
130 |
+
|
131 |
+
def finalize_options(self):
|
132 |
+
from distutils import sysconfig
|
133 |
+
|
134 |
+
self.set_undefined_options('build',
|
135 |
+
('build_lib', 'build_lib'),
|
136 |
+
('build_temp', 'build_temp'),
|
137 |
+
('compiler', 'compiler'),
|
138 |
+
('debug', 'debug'),
|
139 |
+
('force', 'force'),
|
140 |
+
('parallel', 'parallel'),
|
141 |
+
('plat_name', 'plat_name'),
|
142 |
+
)
|
143 |
+
|
144 |
+
if self.package is None:
|
145 |
+
self.package = self.distribution.ext_package
|
146 |
+
|
147 |
+
self.extensions = self.distribution.ext_modules
|
148 |
+
|
149 |
+
# Make sure Python's include directories (for Python.h, pyconfig.h,
|
150 |
+
# etc.) are in the include search path.
|
151 |
+
py_include = sysconfig.get_python_inc()
|
152 |
+
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
|
153 |
+
if self.include_dirs is None:
|
154 |
+
self.include_dirs = self.distribution.include_dirs or []
|
155 |
+
if isinstance(self.include_dirs, str):
|
156 |
+
self.include_dirs = self.include_dirs.split(os.pathsep)
|
157 |
+
|
158 |
+
# If in a virtualenv, add its include directory
|
159 |
+
# Issue 16116
|
160 |
+
if sys.exec_prefix != sys.base_exec_prefix:
|
161 |
+
self.include_dirs.append(os.path.join(sys.exec_prefix, 'include'))
|
162 |
+
|
163 |
+
# Put the Python "system" include dir at the end, so that
|
164 |
+
# any local include dirs take precedence.
|
165 |
+
self.include_dirs.extend(py_include.split(os.path.pathsep))
|
166 |
+
if plat_py_include != py_include:
|
167 |
+
self.include_dirs.extend(
|
168 |
+
plat_py_include.split(os.path.pathsep))
|
169 |
+
|
170 |
+
self.ensure_string_list('libraries')
|
171 |
+
self.ensure_string_list('link_objects')
|
172 |
+
|
173 |
+
# Life is easier if we're not forever checking for None, so
|
174 |
+
# simplify these options to empty lists if unset
|
175 |
+
if self.libraries is None:
|
176 |
+
self.libraries = []
|
177 |
+
if self.library_dirs is None:
|
178 |
+
self.library_dirs = []
|
179 |
+
elif isinstance(self.library_dirs, str):
|
180 |
+
self.library_dirs = self.library_dirs.split(os.pathsep)
|
181 |
+
|
182 |
+
if self.rpath is None:
|
183 |
+
self.rpath = []
|
184 |
+
elif isinstance(self.rpath, str):
|
185 |
+
self.rpath = self.rpath.split(os.pathsep)
|
186 |
+
|
187 |
+
# for extensions under windows use different directories
|
188 |
+
# for Release and Debug builds.
|
189 |
+
# also Python's library directory must be appended to library_dirs
|
190 |
+
if os.name == 'nt':
|
191 |
+
# the 'libs' directory is for binary installs - we assume that
|
192 |
+
# must be the *native* platform. But we don't really support
|
193 |
+
# cross-compiling via a binary install anyway, so we let it go.
|
194 |
+
self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
|
195 |
+
if sys.base_exec_prefix != sys.prefix: # Issue 16116
|
196 |
+
self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
|
197 |
+
if self.debug:
|
198 |
+
self.build_temp = os.path.join(self.build_temp, "Debug")
|
199 |
+
else:
|
200 |
+
self.build_temp = os.path.join(self.build_temp, "Release")
|
201 |
+
|
202 |
+
# Append the source distribution include and library directories,
|
203 |
+
# this allows distutils on windows to work in the source tree
|
204 |
+
self.include_dirs.append(os.path.dirname(get_config_h_filename()))
|
205 |
+
self.library_dirs.append(sys.base_exec_prefix)
|
206 |
+
|
207 |
+
# Use the .lib files for the correct architecture
|
208 |
+
if self.plat_name == 'win32':
|
209 |
+
suffix = 'win32'
|
210 |
+
else:
|
211 |
+
# win-amd64
|
212 |
+
suffix = self.plat_name[4:]
|
213 |
+
new_lib = os.path.join(sys.exec_prefix, 'PCbuild')
|
214 |
+
if suffix:
|
215 |
+
new_lib = os.path.join(new_lib, suffix)
|
216 |
+
self.library_dirs.append(new_lib)
|
217 |
+
|
218 |
+
# For extensions under Cygwin, Python's library directory must be
|
219 |
+
# appended to library_dirs
|
220 |
+
if sys.platform[:6] == 'cygwin':
|
221 |
+
if not sysconfig.python_build:
|
222 |
+
# building third party extensions
|
223 |
+
self.library_dirs.append(os.path.join(sys.prefix, "lib",
|
224 |
+
"python" + get_python_version(),
|
225 |
+
"config"))
|
226 |
+
else:
|
227 |
+
# building python standard extensions
|
228 |
+
self.library_dirs.append('.')
|
229 |
+
|
230 |
+
# For building extensions with a shared Python library,
|
231 |
+
# Python's library directory must be appended to library_dirs
|
232 |
+
# See Issues: #1600860, #4366
|
233 |
+
if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
|
234 |
+
if not sysconfig.python_build:
|
235 |
+
# building third party extensions
|
236 |
+
self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
|
237 |
+
else:
|
238 |
+
# building python standard extensions
|
239 |
+
self.library_dirs.append('.')
|
240 |
+
|
241 |
+
# The argument parsing will result in self.define being a string, but
|
242 |
+
# it has to be a list of 2-tuples. All the preprocessor symbols
|
243 |
+
# specified by the 'define' option will be set to '1'. Multiple
|
244 |
+
# symbols can be separated with commas.
|
245 |
+
|
246 |
+
if self.define:
|
247 |
+
defines = self.define.split(',')
|
248 |
+
self.define = [(symbol, '1') for symbol in defines]
|
249 |
+
|
250 |
+
# The option for macros to undefine is also a string from the
|
251 |
+
# option parsing, but has to be a list. Multiple symbols can also
|
252 |
+
# be separated with commas here.
|
253 |
+
if self.undef:
|
254 |
+
self.undef = self.undef.split(',')
|
255 |
+
|
256 |
+
if self.swig_opts is None:
|
257 |
+
self.swig_opts = []
|
258 |
+
else:
|
259 |
+
self.swig_opts = self.swig_opts.split(' ')
|
260 |
+
|
261 |
+
# Finally add the user include and library directories if requested
|
262 |
+
if self.user:
|
263 |
+
user_include = os.path.join(USER_BASE, "include")
|
264 |
+
user_lib = os.path.join(USER_BASE, "lib")
|
265 |
+
if os.path.isdir(user_include):
|
266 |
+
self.include_dirs.append(user_include)
|
267 |
+
if os.path.isdir(user_lib):
|
268 |
+
self.library_dirs.append(user_lib)
|
269 |
+
self.rpath.append(user_lib)
|
270 |
+
|
271 |
+
if isinstance(self.parallel, str):
|
272 |
+
try:
|
273 |
+
self.parallel = int(self.parallel)
|
274 |
+
except ValueError:
|
275 |
+
raise DistutilsOptionError("parallel should be an integer")
|
276 |
+
|
277 |
+
def run(self):
|
278 |
+
from distutils.ccompiler import new_compiler
|
279 |
+
|
280 |
+
# 'self.extensions', as supplied by setup.py, is a list of
|
281 |
+
# Extension instances. See the documentation for Extension (in
|
282 |
+
# distutils.extension) for details.
|
283 |
+
#
|
284 |
+
# For backwards compatibility with Distutils 0.8.2 and earlier, we
|
285 |
+
# also allow the 'extensions' list to be a list of tuples:
|
286 |
+
# (ext_name, build_info)
|
287 |
+
# where build_info is a dictionary containing everything that
|
288 |
+
# Extension instances do except the name, with a few things being
|
289 |
+
# differently named. We convert these 2-tuples to Extension
|
290 |
+
# instances as needed.
|
291 |
+
|
292 |
+
if not self.extensions:
|
293 |
+
return
|
294 |
+
|
295 |
+
# If we were asked to build any C/C++ libraries, make sure that the
|
296 |
+
# directory where we put them is in the library search path for
|
297 |
+
# linking extensions.
|
298 |
+
if self.distribution.has_c_libraries():
|
299 |
+
build_clib = self.get_finalized_command('build_clib')
|
300 |
+
self.libraries.extend(build_clib.get_library_names() or [])
|
301 |
+
self.library_dirs.append(build_clib.build_clib)
|
302 |
+
|
303 |
+
# Setup the CCompiler object that we'll use to do all the
|
304 |
+
# compiling and linking
|
305 |
+
self.compiler = new_compiler(compiler=self.compiler,
|
306 |
+
verbose=self.verbose,
|
307 |
+
dry_run=self.dry_run,
|
308 |
+
force=self.force)
|
309 |
+
customize_compiler(self.compiler)
|
310 |
+
# If we are cross-compiling, init the compiler now (if we are not
|
311 |
+
# cross-compiling, init would not hurt, but people may rely on
|
312 |
+
# late initialization of compiler even if they shouldn't...)
|
313 |
+
if os.name == 'nt' and self.plat_name != get_platform():
|
314 |
+
self.compiler.initialize(self.plat_name)
|
315 |
+
|
316 |
+
# And make sure that any compile/link-related options (which might
|
317 |
+
# come from the command-line or from the setup script) are set in
|
318 |
+
# that CCompiler object -- that way, they automatically apply to
|
319 |
+
# all compiling and linking done here.
|
320 |
+
if self.include_dirs is not None:
|
321 |
+
self.compiler.set_include_dirs(self.include_dirs)
|
322 |
+
if self.define is not None:
|
323 |
+
# 'define' option is a list of (name,value) tuples
|
324 |
+
for (name, value) in self.define:
|
325 |
+
self.compiler.define_macro(name, value)
|
326 |
+
if self.undef is not None:
|
327 |
+
for macro in self.undef:
|
328 |
+
self.compiler.undefine_macro(macro)
|
329 |
+
if self.libraries is not None:
|
330 |
+
self.compiler.set_libraries(self.libraries)
|
331 |
+
if self.library_dirs is not None:
|
332 |
+
self.compiler.set_library_dirs(self.library_dirs)
|
333 |
+
if self.rpath is not None:
|
334 |
+
self.compiler.set_runtime_library_dirs(self.rpath)
|
335 |
+
if self.link_objects is not None:
|
336 |
+
self.compiler.set_link_objects(self.link_objects)
|
337 |
+
|
338 |
+
# Now actually compile and link everything.
|
339 |
+
self.build_extensions()
|
340 |
+
|
341 |
+
def check_extensions_list(self, extensions):
|
342 |
+
"""Ensure that the list of extensions (presumably provided as a
|
343 |
+
command option 'extensions') is valid, i.e. it is a list of
|
344 |
+
Extension objects. We also support the old-style list of 2-tuples,
|
345 |
+
where the tuples are (ext_name, build_info), which are converted to
|
346 |
+
Extension instances here.
|
347 |
+
|
348 |
+
Raise DistutilsSetupError if the structure is invalid anywhere;
|
349 |
+
just returns otherwise.
|
350 |
+
"""
|
351 |
+
if not isinstance(extensions, list):
|
352 |
+
raise DistutilsSetupError(
|
353 |
+
"'ext_modules' option must be a list of Extension instances")
|
354 |
+
|
355 |
+
for i, ext in enumerate(extensions):
|
356 |
+
if isinstance(ext, Extension):
|
357 |
+
continue # OK! (assume type-checking done
|
358 |
+
# by Extension constructor)
|
359 |
+
|
360 |
+
if not isinstance(ext, tuple) or len(ext) != 2:
|
361 |
+
raise DistutilsSetupError(
|
362 |
+
"each element of 'ext_modules' option must be an "
|
363 |
+
"Extension instance or 2-tuple")
|
364 |
+
|
365 |
+
ext_name, build_info = ext
|
366 |
+
|
367 |
+
log.warn("old-style (ext_name, build_info) tuple found in "
|
368 |
+
"ext_modules for extension '%s' "
|
369 |
+
"-- please convert to Extension instance", ext_name)
|
370 |
+
|
371 |
+
if not (isinstance(ext_name, str) and
|
372 |
+
extension_name_re.match(ext_name)):
|
373 |
+
raise DistutilsSetupError(
|
374 |
+
"first element of each tuple in 'ext_modules' "
|
375 |
+
"must be the extension name (a string)")
|
376 |
+
|
377 |
+
if not isinstance(build_info, dict):
|
378 |
+
raise DistutilsSetupError(
|
379 |
+
"second element of each tuple in 'ext_modules' "
|
380 |
+
"must be a dictionary (build info)")
|
381 |
+
|
382 |
+
# OK, the (ext_name, build_info) dict is type-safe: convert it
|
383 |
+
# to an Extension instance.
|
384 |
+
ext = Extension(ext_name, build_info['sources'])
|
385 |
+
|
386 |
+
# Easy stuff: one-to-one mapping from dict elements to
|
387 |
+
# instance attributes.
|
388 |
+
for key in ('include_dirs', 'library_dirs', 'libraries',
|
389 |
+
'extra_objects', 'extra_compile_args',
|
390 |
+
'extra_link_args'):
|
391 |
+
val = build_info.get(key)
|
392 |
+
if val is not None:
|
393 |
+
setattr(ext, key, val)
|
394 |
+
|
395 |
+
# Medium-easy stuff: same syntax/semantics, different names.
|
396 |
+
ext.runtime_library_dirs = build_info.get('rpath')
|
397 |
+
if 'def_file' in build_info:
|
398 |
+
log.warn("'def_file' element of build info dict "
|
399 |
+
"no longer supported")
|
400 |
+
|
401 |
+
# Non-trivial stuff: 'macros' split into 'define_macros'
|
402 |
+
# and 'undef_macros'.
|
403 |
+
macros = build_info.get('macros')
|
404 |
+
if macros:
|
405 |
+
ext.define_macros = []
|
406 |
+
ext.undef_macros = []
|
407 |
+
for macro in macros:
|
408 |
+
if not (isinstance(macro, tuple) and len(macro) in (1, 2)):
|
409 |
+
raise DistutilsSetupError(
|
410 |
+
"'macros' element of build info dict "
|
411 |
+
"must be 1- or 2-tuple")
|
412 |
+
if len(macro) == 1:
|
413 |
+
ext.undef_macros.append(macro[0])
|
414 |
+
elif len(macro) == 2:
|
415 |
+
ext.define_macros.append(macro)
|
416 |
+
|
417 |
+
extensions[i] = ext
|
418 |
+
|
419 |
+
def get_source_files(self):
|
420 |
+
self.check_extensions_list(self.extensions)
|
421 |
+
filenames = []
|
422 |
+
|
423 |
+
# Wouldn't it be neat if we knew the names of header files too...
|
424 |
+
for ext in self.extensions:
|
425 |
+
filenames.extend(ext.sources)
|
426 |
+
return filenames
|
427 |
+
|
428 |
+
def get_outputs(self):
|
429 |
+
# Sanity check the 'extensions' list -- can't assume this is being
|
430 |
+
# done in the same run as a 'build_extensions()' call (in fact, we
|
431 |
+
# can probably assume that it *isn't*!).
|
432 |
+
self.check_extensions_list(self.extensions)
|
433 |
+
|
434 |
+
# And build the list of output (built) filenames. Note that this
|
435 |
+
# ignores the 'inplace' flag, and assumes everything goes in the
|
436 |
+
# "build" tree.
|
437 |
+
outputs = []
|
438 |
+
for ext in self.extensions:
|
439 |
+
outputs.append(self.get_ext_fullpath(ext.name))
|
440 |
+
return outputs
|
441 |
+
|
442 |
+
def build_extensions(self):
|
443 |
+
# First, sanity-check the 'extensions' list
|
444 |
+
self.check_extensions_list(self.extensions)
|
445 |
+
if self.parallel:
|
446 |
+
self._build_extensions_parallel()
|
447 |
+
else:
|
448 |
+
self._build_extensions_serial()
|
449 |
+
|
450 |
+
def _build_extensions_parallel(self):
|
451 |
+
workers = self.parallel
|
452 |
+
if self.parallel is True:
|
453 |
+
workers = os.cpu_count() # may return None
|
454 |
+
try:
|
455 |
+
from concurrent.futures import ThreadPoolExecutor
|
456 |
+
except ImportError:
|
457 |
+
workers = None
|
458 |
+
|
459 |
+
if workers is None:
|
460 |
+
self._build_extensions_serial()
|
461 |
+
return
|
462 |
+
|
463 |
+
with ThreadPoolExecutor(max_workers=workers) as executor:
|
464 |
+
futures = [executor.submit(self.build_extension, ext)
|
465 |
+
for ext in self.extensions]
|
466 |
+
for ext, fut in zip(self.extensions, futures):
|
467 |
+
with self._filter_build_errors(ext):
|
468 |
+
fut.result()
|
469 |
+
|
470 |
+
def _build_extensions_serial(self):
|
471 |
+
for ext in self.extensions:
|
472 |
+
with self._filter_build_errors(ext):
|
473 |
+
self.build_extension(ext)
|
474 |
+
|
475 |
+
@contextlib.contextmanager
|
476 |
+
def _filter_build_errors(self, ext):
|
477 |
+
try:
|
478 |
+
yield
|
479 |
+
except (CCompilerError, DistutilsError, CompileError) as e:
|
480 |
+
if not ext.optional:
|
481 |
+
raise
|
482 |
+
self.warn('building extension "%s" failed: %s' %
|
483 |
+
(ext.name, e))
|
484 |
+
|
485 |
+
def build_extension(self, ext):
|
486 |
+
sources = ext.sources
|
487 |
+
if sources is None or not isinstance(sources, (list, tuple)):
|
488 |
+
raise DistutilsSetupError(
|
489 |
+
"in 'ext_modules' option (extension '%s'), "
|
490 |
+
"'sources' must be present and must be "
|
491 |
+
"a list of source filenames" % ext.name)
|
492 |
+
# sort to make the resulting .so file build reproducible
|
493 |
+
sources = sorted(sources)
|
494 |
+
|
495 |
+
ext_path = self.get_ext_fullpath(ext.name)
|
496 |
+
depends = sources + ext.depends
|
497 |
+
if not (self.force or newer_group(depends, ext_path, 'newer')):
|
498 |
+
log.debug("skipping '%s' extension (up-to-date)", ext.name)
|
499 |
+
return
|
500 |
+
else:
|
501 |
+
log.info("building '%s' extension", ext.name)
|
502 |
+
|
503 |
+
# First, scan the sources for SWIG definition files (.i), run
|
504 |
+
# SWIG on 'em to create .c files, and modify the sources list
|
505 |
+
# accordingly.
|
506 |
+
sources = self.swig_sources(sources, ext)
|
507 |
+
|
508 |
+
# Next, compile the source code to object files.
|
509 |
+
|
510 |
+
# XXX not honouring 'define_macros' or 'undef_macros' -- the
|
511 |
+
# CCompiler API needs to change to accommodate this, and I
|
512 |
+
# want to do one thing at a time!
|
513 |
+
|
514 |
+
# Two possible sources for extra compiler arguments:
|
515 |
+
# - 'extra_compile_args' in Extension object
|
516 |
+
# - CFLAGS environment variable (not particularly
|
517 |
+
# elegant, but people seem to expect it and I
|
518 |
+
# guess it's useful)
|
519 |
+
# The environment variable should take precedence, and
|
520 |
+
# any sensible compiler will give precedence to later
|
521 |
+
# command line args. Hence we combine them in order:
|
522 |
+
extra_args = ext.extra_compile_args or []
|
523 |
+
|
524 |
+
macros = ext.define_macros[:]
|
525 |
+
for undef in ext.undef_macros:
|
526 |
+
macros.append((undef,))
|
527 |
+
|
528 |
+
objects = self.compiler.compile(sources,
|
529 |
+
output_dir=self.build_temp,
|
530 |
+
macros=macros,
|
531 |
+
include_dirs=ext.include_dirs,
|
532 |
+
debug=self.debug,
|
533 |
+
extra_postargs=extra_args,
|
534 |
+
depends=ext.depends)
|
535 |
+
|
536 |
+
# XXX outdated variable, kept here in case third-part code
|
537 |
+
# needs it.
|
538 |
+
self._built_objects = objects[:]
|
539 |
+
|
540 |
+
# Now link the object files together into a "shared object" --
|
541 |
+
# of course, first we have to figure out all the other things
|
542 |
+
# that go into the mix.
|
543 |
+
if ext.extra_objects:
|
544 |
+
objects.extend(ext.extra_objects)
|
545 |
+
extra_args = ext.extra_link_args or []
|
546 |
+
|
547 |
+
# Detect target language, if not provided
|
548 |
+
language = ext.language or self.compiler.detect_language(sources)
|
549 |
+
|
550 |
+
self.compiler.link_shared_object(
|
551 |
+
objects, ext_path,
|
552 |
+
libraries=self.get_libraries(ext),
|
553 |
+
library_dirs=ext.library_dirs,
|
554 |
+
runtime_library_dirs=ext.runtime_library_dirs,
|
555 |
+
extra_postargs=extra_args,
|
556 |
+
export_symbols=self.get_export_symbols(ext),
|
557 |
+
debug=self.debug,
|
558 |
+
build_temp=self.build_temp,
|
559 |
+
target_lang=language)
|
560 |
+
|
561 |
+
def swig_sources(self, sources, extension):
|
562 |
+
"""Walk the list of source files in 'sources', looking for SWIG
|
563 |
+
interface (.i) files. Run SWIG on all that are found, and
|
564 |
+
return a modified 'sources' list with SWIG source files replaced
|
565 |
+
by the generated C (or C++) files.
|
566 |
+
"""
|
567 |
+
new_sources = []
|
568 |
+
swig_sources = []
|
569 |
+
swig_targets = {}
|
570 |
+
|
571 |
+
# XXX this drops generated C/C++ files into the source tree, which
|
572 |
+
# is fine for developers who want to distribute the generated
|
573 |
+
# source -- but there should be an option to put SWIG output in
|
574 |
+
# the temp dir.
|
575 |
+
|
576 |
+
if self.swig_cpp:
|
577 |
+
log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
|
578 |
+
|
579 |
+
if self.swig_cpp or ('-c++' in self.swig_opts) or \
|
580 |
+
('-c++' in extension.swig_opts):
|
581 |
+
target_ext = '.cpp'
|
582 |
+
else:
|
583 |
+
target_ext = '.c'
|
584 |
+
|
585 |
+
for source in sources:
|
586 |
+
(base, ext) = os.path.splitext(source)
|
587 |
+
if ext == ".i": # SWIG interface file
|
588 |
+
new_sources.append(base + '_wrap' + target_ext)
|
589 |
+
swig_sources.append(source)
|
590 |
+
swig_targets[source] = new_sources[-1]
|
591 |
+
else:
|
592 |
+
new_sources.append(source)
|
593 |
+
|
594 |
+
if not swig_sources:
|
595 |
+
return new_sources
|
596 |
+
|
597 |
+
swig = self.swig or self.find_swig()
|
598 |
+
swig_cmd = [swig, "-python"]
|
599 |
+
swig_cmd.extend(self.swig_opts)
|
600 |
+
if self.swig_cpp:
|
601 |
+
swig_cmd.append("-c++")
|
602 |
+
|
603 |
+
# Do not override commandline arguments
|
604 |
+
if not self.swig_opts:
|
605 |
+
for o in extension.swig_opts:
|
606 |
+
swig_cmd.append(o)
|
607 |
+
|
608 |
+
for source in swig_sources:
|
609 |
+
target = swig_targets[source]
|
610 |
+
log.info("swigging %s to %s", source, target)
|
611 |
+
self.spawn(swig_cmd + ["-o", target, source])
|
612 |
+
|
613 |
+
return new_sources
|
614 |
+
|
615 |
+
def find_swig(self):
|
616 |
+
"""Return the name of the SWIG executable. On Unix, this is
|
617 |
+
just "swig" -- it should be in the PATH. Tries a bit harder on
|
618 |
+
Windows.
|
619 |
+
"""
|
620 |
+
if os.name == "posix":
|
621 |
+
return "swig"
|
622 |
+
elif os.name == "nt":
|
623 |
+
# Look for SWIG in its standard installation directory on
|
624 |
+
# Windows (or so I presume!). If we find it there, great;
|
625 |
+
# if not, act like Unix and assume it's in the PATH.
|
626 |
+
for vers in ("1.3", "1.2", "1.1"):
|
627 |
+
fn = os.path.join("c:\\swig%s" % vers, "swig.exe")
|
628 |
+
if os.path.isfile(fn):
|
629 |
+
return fn
|
630 |
+
else:
|
631 |
+
return "swig.exe"
|
632 |
+
else:
|
633 |
+
raise DistutilsPlatformError(
|
634 |
+
"I don't know how to find (much less run) SWIG "
|
635 |
+
"on platform '%s'" % os.name)
|
636 |
+
|
637 |
+
# -- Name generators -----------------------------------------------
|
638 |
+
# (extension names, filenames, whatever)
|
639 |
+
def get_ext_fullpath(self, ext_name):
|
640 |
+
"""Returns the path of the filename for a given extension.
|
641 |
+
|
642 |
+
The file is located in `build_lib` or directly in the package
|
643 |
+
(inplace option).
|
644 |
+
"""
|
645 |
+
fullname = self.get_ext_fullname(ext_name)
|
646 |
+
modpath = fullname.split('.')
|
647 |
+
filename = self.get_ext_filename(modpath[-1])
|
648 |
+
|
649 |
+
if not self.inplace:
|
650 |
+
# no further work needed
|
651 |
+
# returning :
|
652 |
+
# build_dir/package/path/filename
|
653 |
+
filename = os.path.join(*modpath[:-1]+[filename])
|
654 |
+
return os.path.join(self.build_lib, filename)
|
655 |
+
|
656 |
+
# the inplace option requires to find the package directory
|
657 |
+
# using the build_py command for that
|
658 |
+
package = '.'.join(modpath[0:-1])
|
659 |
+
build_py = self.get_finalized_command('build_py')
|
660 |
+
package_dir = os.path.abspath(build_py.get_package_dir(package))
|
661 |
+
|
662 |
+
# returning
|
663 |
+
# package_dir/filename
|
664 |
+
return os.path.join(package_dir, filename)
|
665 |
+
|
666 |
+
def get_ext_fullname(self, ext_name):
|
667 |
+
"""Returns the fullname of a given extension name.
|
668 |
+
|
669 |
+
Adds the `package.` prefix"""
|
670 |
+
if self.package is None:
|
671 |
+
return ext_name
|
672 |
+
else:
|
673 |
+
return self.package + '.' + ext_name
|
674 |
+
|
675 |
+
def get_ext_filename(self, ext_name):
|
676 |
+
r"""Convert the name of an extension (eg. "foo.bar") into the name
|
677 |
+
of the file from which it will be loaded (eg. "foo/bar.so", or
|
678 |
+
"foo\bar.pyd").
|
679 |
+
"""
|
680 |
+
from distutils.sysconfig import get_config_var
|
681 |
+
ext_path = ext_name.split('.')
|
682 |
+
ext_suffix = get_config_var('EXT_SUFFIX')
|
683 |
+
return os.path.join(*ext_path) + ext_suffix
|
684 |
+
|
685 |
+
def get_export_symbols(self, ext):
|
686 |
+
"""Return the list of symbols that a shared extension has to
|
687 |
+
export. This either uses 'ext.export_symbols' or, if it's not
|
688 |
+
provided, "PyInit_" + module_name. Only relevant on Windows, where
|
689 |
+
the .pyd file (DLL) must export the module "PyInit_" function.
|
690 |
+
"""
|
691 |
+
name = ext.name.split('.')[-1]
|
692 |
+
try:
|
693 |
+
# Unicode module name support as defined in PEP-489
|
694 |
+
# https://www.python.org/dev/peps/pep-0489/#export-hook-name
|
695 |
+
name.encode('ascii')
|
696 |
+
except UnicodeEncodeError:
|
697 |
+
suffix = 'U_' + name.encode('punycode').replace(b'-', b'_').decode('ascii')
|
698 |
+
else:
|
699 |
+
suffix = "_" + name
|
700 |
+
|
701 |
+
initfunc_name = "PyInit" + suffix
|
702 |
+
if initfunc_name not in ext.export_symbols:
|
703 |
+
ext.export_symbols.append(initfunc_name)
|
704 |
+
return ext.export_symbols
|
705 |
+
|
706 |
+
def get_libraries(self, ext):
|
707 |
+
"""Return the list of libraries to link against when building a
|
708 |
+
shared extension. On most platforms, this is just 'ext.libraries';
|
709 |
+
on Windows, we add the Python library (eg. python20.dll).
|
710 |
+
"""
|
711 |
+
# The python library is always needed on Windows. For MSVC, this
|
712 |
+
# is redundant, since the library is mentioned in a pragma in
|
713 |
+
# pyconfig.h that MSVC groks. The other Windows compilers all seem
|
714 |
+
# to need it mentioned explicitly, though, so that's what we do.
|
715 |
+
# Append '_d' to the python import library on debug builds.
|
716 |
+
if sys.platform == "win32":
|
717 |
+
from distutils._msvccompiler import MSVCCompiler
|
718 |
+
if not isinstance(self.compiler, MSVCCompiler):
|
719 |
+
template = "python%d%d"
|
720 |
+
if self.debug:
|
721 |
+
template = template + '_d'
|
722 |
+
pythonlib = (template %
|
723 |
+
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
|
724 |
+
# don't extend ext.libraries, it may be shared with other
|
725 |
+
# extensions, it is a reference to the original list
|
726 |
+
return ext.libraries + [pythonlib]
|
727 |
+
else:
|
728 |
+
# On Android only the main executable and LD_PRELOADs are considered
|
729 |
+
# to be RTLD_GLOBAL, all the dependencies of the main executable
|
730 |
+
# remain RTLD_LOCAL and so the shared libraries must be linked with
|
731 |
+
# libpython when python is built with a shared python library (issue
|
732 |
+
# bpo-21536).
|
733 |
+
# On Cygwin (and if required, other POSIX-like platforms based on
|
734 |
+
# Windows like MinGW) it is simply necessary that all symbols in
|
735 |
+
# shared libraries are resolved at link time.
|
736 |
+
from distutils.sysconfig import get_config_var
|
737 |
+
link_libpython = False
|
738 |
+
if get_config_var('Py_ENABLE_SHARED'):
|
739 |
+
# A native build on an Android device or on Cygwin
|
740 |
+
if hasattr(sys, 'getandroidapilevel'):
|
741 |
+
link_libpython = True
|
742 |
+
elif sys.platform == 'cygwin':
|
743 |
+
link_libpython = True
|
744 |
+
elif '_PYTHON_HOST_PLATFORM' in os.environ:
|
745 |
+
# We are cross-compiling for one of the relevant platforms
|
746 |
+
if get_config_var('ANDROID_API_LEVEL') != 0:
|
747 |
+
link_libpython = True
|
748 |
+
elif get_config_var('MACHDEP') == 'cygwin':
|
749 |
+
link_libpython = True
|
750 |
+
|
751 |
+
if link_libpython:
|
752 |
+
ldversion = get_config_var('LDVERSION')
|
753 |
+
return ext.libraries + ['python' + ldversion]
|
754 |
+
|
755 |
+
return ext.libraries + py37compat.pythonlib()
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build_py.py
ADDED
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.build_py
|
2 |
+
|
3 |
+
Implements the Distutils 'build_py' command."""
|
4 |
+
|
5 |
+
import os
|
6 |
+
import importlib.util
|
7 |
+
import sys
|
8 |
+
import glob
|
9 |
+
|
10 |
+
from distutils.core import Command
|
11 |
+
from distutils.errors import *
|
12 |
+
from distutils.util import convert_path
|
13 |
+
from distutils import log
|
14 |
+
|
15 |
+
class build_py (Command):
|
16 |
+
|
17 |
+
description = "\"build\" pure Python modules (copy to build directory)"
|
18 |
+
|
19 |
+
user_options = [
|
20 |
+
('build-lib=', 'd', "directory to \"build\" (copy) to"),
|
21 |
+
('compile', 'c', "compile .py to .pyc"),
|
22 |
+
('no-compile', None, "don't compile .py files [default]"),
|
23 |
+
('optimize=', 'O',
|
24 |
+
"also compile with optimization: -O1 for \"python -O\", "
|
25 |
+
"-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
|
26 |
+
('force', 'f', "forcibly build everything (ignore file timestamps)"),
|
27 |
+
]
|
28 |
+
|
29 |
+
boolean_options = ['compile', 'force']
|
30 |
+
negative_opt = {'no-compile' : 'compile'}
|
31 |
+
|
32 |
+
def initialize_options(self):
|
33 |
+
self.build_lib = None
|
34 |
+
self.py_modules = None
|
35 |
+
self.package = None
|
36 |
+
self.package_data = None
|
37 |
+
self.package_dir = None
|
38 |
+
self.compile = 0
|
39 |
+
self.optimize = 0
|
40 |
+
self.force = None
|
41 |
+
|
42 |
+
def finalize_options(self):
|
43 |
+
self.set_undefined_options('build',
|
44 |
+
('build_lib', 'build_lib'),
|
45 |
+
('force', 'force'))
|
46 |
+
|
47 |
+
# Get the distribution options that are aliases for build_py
|
48 |
+
# options -- list of packages and list of modules.
|
49 |
+
self.packages = self.distribution.packages
|
50 |
+
self.py_modules = self.distribution.py_modules
|
51 |
+
self.package_data = self.distribution.package_data
|
52 |
+
self.package_dir = {}
|
53 |
+
if self.distribution.package_dir:
|
54 |
+
for name, path in self.distribution.package_dir.items():
|
55 |
+
self.package_dir[name] = convert_path(path)
|
56 |
+
self.data_files = self.get_data_files()
|
57 |
+
|
58 |
+
# Ick, copied straight from install_lib.py (fancy_getopt needs a
|
59 |
+
# type system! Hell, *everything* needs a type system!!!)
|
60 |
+
if not isinstance(self.optimize, int):
|
61 |
+
try:
|
62 |
+
self.optimize = int(self.optimize)
|
63 |
+
assert 0 <= self.optimize <= 2
|
64 |
+
except (ValueError, AssertionError):
|
65 |
+
raise DistutilsOptionError("optimize must be 0, 1, or 2")
|
66 |
+
|
67 |
+
def run(self):
|
68 |
+
# XXX copy_file by default preserves atime and mtime. IMHO this is
|
69 |
+
# the right thing to do, but perhaps it should be an option -- in
|
70 |
+
# particular, a site administrator might want installed files to
|
71 |
+
# reflect the time of installation rather than the last
|
72 |
+
# modification time before the installed release.
|
73 |
+
|
74 |
+
# XXX copy_file by default preserves mode, which appears to be the
|
75 |
+
# wrong thing to do: if a file is read-only in the working
|
76 |
+
# directory, we want it to be installed read/write so that the next
|
77 |
+
# installation of the same module distribution can overwrite it
|
78 |
+
# without problems. (This might be a Unix-specific issue.) Thus
|
79 |
+
# we turn off 'preserve_mode' when copying to the build directory,
|
80 |
+
# since the build directory is supposed to be exactly what the
|
81 |
+
# installation will look like (ie. we preserve mode when
|
82 |
+
# installing).
|
83 |
+
|
84 |
+
# Two options control which modules will be installed: 'packages'
|
85 |
+
# and 'py_modules'. The former lets us work with whole packages, not
|
86 |
+
# specifying individual modules at all; the latter is for
|
87 |
+
# specifying modules one-at-a-time.
|
88 |
+
|
89 |
+
if self.py_modules:
|
90 |
+
self.build_modules()
|
91 |
+
if self.packages:
|
92 |
+
self.build_packages()
|
93 |
+
self.build_package_data()
|
94 |
+
|
95 |
+
self.byte_compile(self.get_outputs(include_bytecode=0))
|
96 |
+
|
97 |
+
def get_data_files(self):
|
98 |
+
"""Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
|
99 |
+
data = []
|
100 |
+
if not self.packages:
|
101 |
+
return data
|
102 |
+
for package in self.packages:
|
103 |
+
# Locate package source directory
|
104 |
+
src_dir = self.get_package_dir(package)
|
105 |
+
|
106 |
+
# Compute package build directory
|
107 |
+
build_dir = os.path.join(*([self.build_lib] + package.split('.')))
|
108 |
+
|
109 |
+
# Length of path to strip from found files
|
110 |
+
plen = 0
|
111 |
+
if src_dir:
|
112 |
+
plen = len(src_dir)+1
|
113 |
+
|
114 |
+
# Strip directory from globbed filenames
|
115 |
+
filenames = [
|
116 |
+
file[plen:] for file in self.find_data_files(package, src_dir)
|
117 |
+
]
|
118 |
+
data.append((package, src_dir, build_dir, filenames))
|
119 |
+
return data
|
120 |
+
|
121 |
+
def find_data_files(self, package, src_dir):
|
122 |
+
"""Return filenames for package's data files in 'src_dir'"""
|
123 |
+
globs = (self.package_data.get('', [])
|
124 |
+
+ self.package_data.get(package, []))
|
125 |
+
files = []
|
126 |
+
for pattern in globs:
|
127 |
+
# Each pattern has to be converted to a platform-specific path
|
128 |
+
filelist = glob.glob(os.path.join(glob.escape(src_dir), convert_path(pattern)))
|
129 |
+
# Files that match more than one pattern are only added once
|
130 |
+
files.extend([fn for fn in filelist if fn not in files
|
131 |
+
and os.path.isfile(fn)])
|
132 |
+
return files
|
133 |
+
|
134 |
+
def build_package_data(self):
|
135 |
+
"""Copy data files into build directory"""
|
136 |
+
lastdir = None
|
137 |
+
for package, src_dir, build_dir, filenames in self.data_files:
|
138 |
+
for filename in filenames:
|
139 |
+
target = os.path.join(build_dir, filename)
|
140 |
+
self.mkpath(os.path.dirname(target))
|
141 |
+
self.copy_file(os.path.join(src_dir, filename), target,
|
142 |
+
preserve_mode=False)
|
143 |
+
|
144 |
+
def get_package_dir(self, package):
|
145 |
+
"""Return the directory, relative to the top of the source
|
146 |
+
distribution, where package 'package' should be found
|
147 |
+
(at least according to the 'package_dir' option, if any)."""
|
148 |
+
path = package.split('.')
|
149 |
+
|
150 |
+
if not self.package_dir:
|
151 |
+
if path:
|
152 |
+
return os.path.join(*path)
|
153 |
+
else:
|
154 |
+
return ''
|
155 |
+
else:
|
156 |
+
tail = []
|
157 |
+
while path:
|
158 |
+
try:
|
159 |
+
pdir = self.package_dir['.'.join(path)]
|
160 |
+
except KeyError:
|
161 |
+
tail.insert(0, path[-1])
|
162 |
+
del path[-1]
|
163 |
+
else:
|
164 |
+
tail.insert(0, pdir)
|
165 |
+
return os.path.join(*tail)
|
166 |
+
else:
|
167 |
+
# Oops, got all the way through 'path' without finding a
|
168 |
+
# match in package_dir. If package_dir defines a directory
|
169 |
+
# for the root (nameless) package, then fallback on it;
|
170 |
+
# otherwise, we might as well have not consulted
|
171 |
+
# package_dir at all, as we just use the directory implied
|
172 |
+
# by 'tail' (which should be the same as the original value
|
173 |
+
# of 'path' at this point).
|
174 |
+
pdir = self.package_dir.get('')
|
175 |
+
if pdir is not None:
|
176 |
+
tail.insert(0, pdir)
|
177 |
+
|
178 |
+
if tail:
|
179 |
+
return os.path.join(*tail)
|
180 |
+
else:
|
181 |
+
return ''
|
182 |
+
|
183 |
+
def check_package(self, package, package_dir):
|
184 |
+
# Empty dir name means current directory, which we can probably
|
185 |
+
# assume exists. Also, os.path.exists and isdir don't know about
|
186 |
+
# my "empty string means current dir" convention, so we have to
|
187 |
+
# circumvent them.
|
188 |
+
if package_dir != "":
|
189 |
+
if not os.path.exists(package_dir):
|
190 |
+
raise DistutilsFileError(
|
191 |
+
"package directory '%s' does not exist" % package_dir)
|
192 |
+
if not os.path.isdir(package_dir):
|
193 |
+
raise DistutilsFileError(
|
194 |
+
"supposed package directory '%s' exists, "
|
195 |
+
"but is not a directory" % package_dir)
|
196 |
+
|
197 |
+
# Require __init__.py for all but the "root package"
|
198 |
+
if package:
|
199 |
+
init_py = os.path.join(package_dir, "__init__.py")
|
200 |
+
if os.path.isfile(init_py):
|
201 |
+
return init_py
|
202 |
+
else:
|
203 |
+
log.warn(("package init file '%s' not found " +
|
204 |
+
"(or not a regular file)"), init_py)
|
205 |
+
|
206 |
+
# Either not in a package at all (__init__.py not expected), or
|
207 |
+
# __init__.py doesn't exist -- so don't return the filename.
|
208 |
+
return None
|
209 |
+
|
210 |
+
def check_module(self, module, module_file):
|
211 |
+
if not os.path.isfile(module_file):
|
212 |
+
log.warn("file %s (for module %s) not found", module_file, module)
|
213 |
+
return False
|
214 |
+
else:
|
215 |
+
return True
|
216 |
+
|
217 |
+
def find_package_modules(self, package, package_dir):
|
218 |
+
self.check_package(package, package_dir)
|
219 |
+
module_files = glob.glob(os.path.join(glob.escape(package_dir), "*.py"))
|
220 |
+
modules = []
|
221 |
+
setup_script = os.path.abspath(self.distribution.script_name)
|
222 |
+
|
223 |
+
for f in module_files:
|
224 |
+
abs_f = os.path.abspath(f)
|
225 |
+
if abs_f != setup_script:
|
226 |
+
module = os.path.splitext(os.path.basename(f))[0]
|
227 |
+
modules.append((package, module, f))
|
228 |
+
else:
|
229 |
+
self.debug_print("excluding %s" % setup_script)
|
230 |
+
return modules
|
231 |
+
|
232 |
+
def find_modules(self):
|
233 |
+
"""Finds individually-specified Python modules, ie. those listed by
|
234 |
+
module name in 'self.py_modules'. Returns a list of tuples (package,
|
235 |
+
module_base, filename): 'package' is a tuple of the path through
|
236 |
+
package-space to the module; 'module_base' is the bare (no
|
237 |
+
packages, no dots) module name, and 'filename' is the path to the
|
238 |
+
".py" file (relative to the distribution root) that implements the
|
239 |
+
module.
|
240 |
+
"""
|
241 |
+
# Map package names to tuples of useful info about the package:
|
242 |
+
# (package_dir, checked)
|
243 |
+
# package_dir - the directory where we'll find source files for
|
244 |
+
# this package
|
245 |
+
# checked - true if we have checked that the package directory
|
246 |
+
# is valid (exists, contains __init__.py, ... ?)
|
247 |
+
packages = {}
|
248 |
+
|
249 |
+
# List of (package, module, filename) tuples to return
|
250 |
+
modules = []
|
251 |
+
|
252 |
+
# We treat modules-in-packages almost the same as toplevel modules,
|
253 |
+
# just the "package" for a toplevel is empty (either an empty
|
254 |
+
# string or empty list, depending on context). Differences:
|
255 |
+
# - don't check for __init__.py in directory for empty package
|
256 |
+
for module in self.py_modules:
|
257 |
+
path = module.split('.')
|
258 |
+
package = '.'.join(path[0:-1])
|
259 |
+
module_base = path[-1]
|
260 |
+
|
261 |
+
try:
|
262 |
+
(package_dir, checked) = packages[package]
|
263 |
+
except KeyError:
|
264 |
+
package_dir = self.get_package_dir(package)
|
265 |
+
checked = 0
|
266 |
+
|
267 |
+
if not checked:
|
268 |
+
init_py = self.check_package(package, package_dir)
|
269 |
+
packages[package] = (package_dir, 1)
|
270 |
+
if init_py:
|
271 |
+
modules.append((package, "__init__", init_py))
|
272 |
+
|
273 |
+
# XXX perhaps we should also check for just .pyc files
|
274 |
+
# (so greedy closed-source bastards can distribute Python
|
275 |
+
# modules too)
|
276 |
+
module_file = os.path.join(package_dir, module_base + ".py")
|
277 |
+
if not self.check_module(module, module_file):
|
278 |
+
continue
|
279 |
+
|
280 |
+
modules.append((package, module_base, module_file))
|
281 |
+
|
282 |
+
return modules
|
283 |
+
|
284 |
+
def find_all_modules(self):
|
285 |
+
"""Compute the list of all modules that will be built, whether
|
286 |
+
they are specified one-module-at-a-time ('self.py_modules') or
|
287 |
+
by whole packages ('self.packages'). Return a list of tuples
|
288 |
+
(package, module, module_file), just like 'find_modules()' and
|
289 |
+
'find_package_modules()' do."""
|
290 |
+
modules = []
|
291 |
+
if self.py_modules:
|
292 |
+
modules.extend(self.find_modules())
|
293 |
+
if self.packages:
|
294 |
+
for package in self.packages:
|
295 |
+
package_dir = self.get_package_dir(package)
|
296 |
+
m = self.find_package_modules(package, package_dir)
|
297 |
+
modules.extend(m)
|
298 |
+
return modules
|
299 |
+
|
300 |
+
def get_source_files(self):
|
301 |
+
return [module[-1] for module in self.find_all_modules()]
|
302 |
+
|
303 |
+
def get_module_outfile(self, build_dir, package, module):
|
304 |
+
outfile_path = [build_dir] + list(package) + [module + ".py"]
|
305 |
+
return os.path.join(*outfile_path)
|
306 |
+
|
307 |
+
def get_outputs(self, include_bytecode=1):
|
308 |
+
modules = self.find_all_modules()
|
309 |
+
outputs = []
|
310 |
+
for (package, module, module_file) in modules:
|
311 |
+
package = package.split('.')
|
312 |
+
filename = self.get_module_outfile(self.build_lib, package, module)
|
313 |
+
outputs.append(filename)
|
314 |
+
if include_bytecode:
|
315 |
+
if self.compile:
|
316 |
+
outputs.append(importlib.util.cache_from_source(
|
317 |
+
filename, optimization=''))
|
318 |
+
if self.optimize > 0:
|
319 |
+
outputs.append(importlib.util.cache_from_source(
|
320 |
+
filename, optimization=self.optimize))
|
321 |
+
|
322 |
+
outputs += [
|
323 |
+
os.path.join(build_dir, filename)
|
324 |
+
for package, src_dir, build_dir, filenames in self.data_files
|
325 |
+
for filename in filenames
|
326 |
+
]
|
327 |
+
|
328 |
+
return outputs
|
329 |
+
|
330 |
+
def build_module(self, module, module_file, package):
|
331 |
+
if isinstance(package, str):
|
332 |
+
package = package.split('.')
|
333 |
+
elif not isinstance(package, (list, tuple)):
|
334 |
+
raise TypeError(
|
335 |
+
"'package' must be a string (dot-separated), list, or tuple")
|
336 |
+
|
337 |
+
# Now put the module source file into the "build" area -- this is
|
338 |
+
# easy, we just copy it somewhere under self.build_lib (the build
|
339 |
+
# directory for Python source).
|
340 |
+
outfile = self.get_module_outfile(self.build_lib, package, module)
|
341 |
+
dir = os.path.dirname(outfile)
|
342 |
+
self.mkpath(dir)
|
343 |
+
return self.copy_file(module_file, outfile, preserve_mode=0)
|
344 |
+
|
345 |
+
def build_modules(self):
|
346 |
+
modules = self.find_modules()
|
347 |
+
for (package, module, module_file) in modules:
|
348 |
+
# Now "build" the module -- ie. copy the source file to
|
349 |
+
# self.build_lib (the build directory for Python source).
|
350 |
+
# (Actually, it gets copied to the directory for this package
|
351 |
+
# under self.build_lib.)
|
352 |
+
self.build_module(module, module_file, package)
|
353 |
+
|
354 |
+
def build_packages(self):
|
355 |
+
for package in self.packages:
|
356 |
+
# Get list of (package, module, module_file) tuples based on
|
357 |
+
# scanning the package directory. 'package' is only included
|
358 |
+
# in the tuple so that 'find_modules()' and
|
359 |
+
# 'find_package_tuples()' have a consistent interface; it's
|
360 |
+
# ignored here (apart from a sanity check). Also, 'module' is
|
361 |
+
# the *unqualified* module name (ie. no dots, no package -- we
|
362 |
+
# already know its package!), and 'module_file' is the path to
|
363 |
+
# the .py file, relative to the current directory
|
364 |
+
# (ie. including 'package_dir').
|
365 |
+
package_dir = self.get_package_dir(package)
|
366 |
+
modules = self.find_package_modules(package, package_dir)
|
367 |
+
|
368 |
+
# Now loop over the modules we found, "building" each one (just
|
369 |
+
# copy it to self.build_lib).
|
370 |
+
for (package_, module, module_file) in modules:
|
371 |
+
assert package == package_
|
372 |
+
self.build_module(module, module_file, package)
|
373 |
+
|
374 |
+
def byte_compile(self, files):
|
375 |
+
if sys.dont_write_bytecode:
|
376 |
+
self.warn('byte-compiling is disabled, skipping.')
|
377 |
+
return
|
378 |
+
|
379 |
+
from distutils.util import byte_compile
|
380 |
+
prefix = self.build_lib
|
381 |
+
if prefix[-1] != os.sep:
|
382 |
+
prefix = prefix + os.sep
|
383 |
+
|
384 |
+
# XXX this code is essentially the same as the 'byte_compile()
|
385 |
+
# method of the "install_lib" command, except for the determination
|
386 |
+
# of the 'prefix' string. Hmmm.
|
387 |
+
if self.compile:
|
388 |
+
byte_compile(files, optimize=0,
|
389 |
+
force=self.force, prefix=prefix, dry_run=self.dry_run)
|
390 |
+
if self.optimize > 0:
|
391 |
+
byte_compile(files, optimize=self.optimize,
|
392 |
+
force=self.force, prefix=prefix, dry_run=self.dry_run)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/build_scripts.py
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.build_scripts
|
2 |
+
|
3 |
+
Implements the Distutils 'build_scripts' command."""
|
4 |
+
|
5 |
+
import os, re
|
6 |
+
from stat import ST_MODE
|
7 |
+
from distutils import sysconfig
|
8 |
+
from distutils.core import Command
|
9 |
+
from distutils.dep_util import newer
|
10 |
+
from distutils.util import convert_path
|
11 |
+
from distutils import log
|
12 |
+
import tokenize
|
13 |
+
|
14 |
+
# check if Python is called on the first line with this expression
|
15 |
+
first_line_re = re.compile(b'^#!.*python[0-9.]*([ \t].*)?$')
|
16 |
+
|
17 |
+
class build_scripts(Command):
|
18 |
+
|
19 |
+
description = "\"build\" scripts (copy and fixup #! line)"
|
20 |
+
|
21 |
+
user_options = [
|
22 |
+
('build-dir=', 'd', "directory to \"build\" (copy) to"),
|
23 |
+
('force', 'f', "forcibly build everything (ignore file timestamps"),
|
24 |
+
('executable=', 'e', "specify final destination interpreter path"),
|
25 |
+
]
|
26 |
+
|
27 |
+
boolean_options = ['force']
|
28 |
+
|
29 |
+
|
30 |
+
def initialize_options(self):
|
31 |
+
self.build_dir = None
|
32 |
+
self.scripts = None
|
33 |
+
self.force = None
|
34 |
+
self.executable = None
|
35 |
+
self.outfiles = None
|
36 |
+
|
37 |
+
def finalize_options(self):
|
38 |
+
self.set_undefined_options('build',
|
39 |
+
('build_scripts', 'build_dir'),
|
40 |
+
('force', 'force'),
|
41 |
+
('executable', 'executable'))
|
42 |
+
self.scripts = self.distribution.scripts
|
43 |
+
|
44 |
+
def get_source_files(self):
|
45 |
+
return self.scripts
|
46 |
+
|
47 |
+
def run(self):
|
48 |
+
if not self.scripts:
|
49 |
+
return
|
50 |
+
self.copy_scripts()
|
51 |
+
|
52 |
+
|
53 |
+
def copy_scripts(self):
|
54 |
+
r"""Copy each script listed in 'self.scripts'; if it's marked as a
|
55 |
+
Python script in the Unix way (first line matches 'first_line_re',
|
56 |
+
ie. starts with "\#!" and contains "python"), then adjust the first
|
57 |
+
line to refer to the current Python interpreter as we copy.
|
58 |
+
"""
|
59 |
+
self.mkpath(self.build_dir)
|
60 |
+
outfiles = []
|
61 |
+
updated_files = []
|
62 |
+
for script in self.scripts:
|
63 |
+
adjust = False
|
64 |
+
script = convert_path(script)
|
65 |
+
outfile = os.path.join(self.build_dir, os.path.basename(script))
|
66 |
+
outfiles.append(outfile)
|
67 |
+
|
68 |
+
if not self.force and not newer(script, outfile):
|
69 |
+
log.debug("not copying %s (up-to-date)", script)
|
70 |
+
continue
|
71 |
+
|
72 |
+
# Always open the file, but ignore failures in dry-run mode --
|
73 |
+
# that way, we'll get accurate feedback if we can read the
|
74 |
+
# script.
|
75 |
+
try:
|
76 |
+
f = open(script, "rb")
|
77 |
+
except OSError:
|
78 |
+
if not self.dry_run:
|
79 |
+
raise
|
80 |
+
f = None
|
81 |
+
else:
|
82 |
+
encoding, lines = tokenize.detect_encoding(f.readline)
|
83 |
+
f.seek(0)
|
84 |
+
first_line = f.readline()
|
85 |
+
if not first_line:
|
86 |
+
self.warn("%s is an empty file (skipping)" % script)
|
87 |
+
continue
|
88 |
+
|
89 |
+
match = first_line_re.match(first_line)
|
90 |
+
if match:
|
91 |
+
adjust = True
|
92 |
+
post_interp = match.group(1) or b''
|
93 |
+
|
94 |
+
if adjust:
|
95 |
+
log.info("copying and adjusting %s -> %s", script,
|
96 |
+
self.build_dir)
|
97 |
+
updated_files.append(outfile)
|
98 |
+
if not self.dry_run:
|
99 |
+
if not sysconfig.python_build:
|
100 |
+
executable = self.executable
|
101 |
+
else:
|
102 |
+
executable = os.path.join(
|
103 |
+
sysconfig.get_config_var("BINDIR"),
|
104 |
+
"python%s%s" % (sysconfig.get_config_var("VERSION"),
|
105 |
+
sysconfig.get_config_var("EXE")))
|
106 |
+
executable = os.fsencode(executable)
|
107 |
+
shebang = b"#!" + executable + post_interp + b"\n"
|
108 |
+
# Python parser starts to read a script using UTF-8 until
|
109 |
+
# it gets a #coding:xxx cookie. The shebang has to be the
|
110 |
+
# first line of a file, the #coding:xxx cookie cannot be
|
111 |
+
# written before. So the shebang has to be decodable from
|
112 |
+
# UTF-8.
|
113 |
+
try:
|
114 |
+
shebang.decode('utf-8')
|
115 |
+
except UnicodeDecodeError:
|
116 |
+
raise ValueError(
|
117 |
+
"The shebang ({!r}) is not decodable "
|
118 |
+
"from utf-8".format(shebang))
|
119 |
+
# If the script is encoded to a custom encoding (use a
|
120 |
+
# #coding:xxx cookie), the shebang has to be decodable from
|
121 |
+
# the script encoding too.
|
122 |
+
try:
|
123 |
+
shebang.decode(encoding)
|
124 |
+
except UnicodeDecodeError:
|
125 |
+
raise ValueError(
|
126 |
+
"The shebang ({!r}) is not decodable "
|
127 |
+
"from the script encoding ({})"
|
128 |
+
.format(shebang, encoding))
|
129 |
+
with open(outfile, "wb") as outf:
|
130 |
+
outf.write(shebang)
|
131 |
+
outf.writelines(f.readlines())
|
132 |
+
if f:
|
133 |
+
f.close()
|
134 |
+
else:
|
135 |
+
if f:
|
136 |
+
f.close()
|
137 |
+
updated_files.append(outfile)
|
138 |
+
self.copy_file(script, outfile)
|
139 |
+
|
140 |
+
if os.name == 'posix':
|
141 |
+
for file in outfiles:
|
142 |
+
if self.dry_run:
|
143 |
+
log.info("changing mode of %s", file)
|
144 |
+
else:
|
145 |
+
oldmode = os.stat(file)[ST_MODE] & 0o7777
|
146 |
+
newmode = (oldmode | 0o555) & 0o7777
|
147 |
+
if newmode != oldmode:
|
148 |
+
log.info("changing mode of %s from %o to %o",
|
149 |
+
file, oldmode, newmode)
|
150 |
+
os.chmod(file, newmode)
|
151 |
+
# XXX should we modify self.outfiles?
|
152 |
+
return outfiles, updated_files
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/check.py
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.check
|
2 |
+
|
3 |
+
Implements the Distutils 'check' command.
|
4 |
+
"""
|
5 |
+
from distutils.core import Command
|
6 |
+
from distutils.errors import DistutilsSetupError
|
7 |
+
|
8 |
+
try:
|
9 |
+
# docutils is installed
|
10 |
+
from docutils.utils import Reporter
|
11 |
+
from docutils.parsers.rst import Parser
|
12 |
+
from docutils import frontend
|
13 |
+
from docutils import nodes
|
14 |
+
|
15 |
+
class SilentReporter(Reporter):
|
16 |
+
|
17 |
+
def __init__(self, source, report_level, halt_level, stream=None,
|
18 |
+
debug=0, encoding='ascii', error_handler='replace'):
|
19 |
+
self.messages = []
|
20 |
+
Reporter.__init__(self, source, report_level, halt_level, stream,
|
21 |
+
debug, encoding, error_handler)
|
22 |
+
|
23 |
+
def system_message(self, level, message, *children, **kwargs):
|
24 |
+
self.messages.append((level, message, children, kwargs))
|
25 |
+
return nodes.system_message(message, level=level,
|
26 |
+
type=self.levels[level],
|
27 |
+
*children, **kwargs)
|
28 |
+
|
29 |
+
HAS_DOCUTILS = True
|
30 |
+
except Exception:
|
31 |
+
# Catch all exceptions because exceptions besides ImportError probably
|
32 |
+
# indicate that docutils is not ported to Py3k.
|
33 |
+
HAS_DOCUTILS = False
|
34 |
+
|
35 |
+
class check(Command):
|
36 |
+
"""This command checks the meta-data of the package.
|
37 |
+
"""
|
38 |
+
description = ("perform some checks on the package")
|
39 |
+
user_options = [('metadata', 'm', 'Verify meta-data'),
|
40 |
+
('restructuredtext', 'r',
|
41 |
+
('Checks if long string meta-data syntax '
|
42 |
+
'are reStructuredText-compliant')),
|
43 |
+
('strict', 's',
|
44 |
+
'Will exit with an error if a check fails')]
|
45 |
+
|
46 |
+
boolean_options = ['metadata', 'restructuredtext', 'strict']
|
47 |
+
|
48 |
+
def initialize_options(self):
|
49 |
+
"""Sets default values for options."""
|
50 |
+
self.restructuredtext = 0
|
51 |
+
self.metadata = 1
|
52 |
+
self.strict = 0
|
53 |
+
self._warnings = 0
|
54 |
+
|
55 |
+
def finalize_options(self):
|
56 |
+
pass
|
57 |
+
|
58 |
+
def warn(self, msg):
|
59 |
+
"""Counts the number of warnings that occurs."""
|
60 |
+
self._warnings += 1
|
61 |
+
return Command.warn(self, msg)
|
62 |
+
|
63 |
+
def run(self):
|
64 |
+
"""Runs the command."""
|
65 |
+
# perform the various tests
|
66 |
+
if self.metadata:
|
67 |
+
self.check_metadata()
|
68 |
+
if self.restructuredtext:
|
69 |
+
if HAS_DOCUTILS:
|
70 |
+
self.check_restructuredtext()
|
71 |
+
elif self.strict:
|
72 |
+
raise DistutilsSetupError('The docutils package is needed.')
|
73 |
+
|
74 |
+
# let's raise an error in strict mode, if we have at least
|
75 |
+
# one warning
|
76 |
+
if self.strict and self._warnings > 0:
|
77 |
+
raise DistutilsSetupError('Please correct your package.')
|
78 |
+
|
79 |
+
def check_metadata(self):
|
80 |
+
"""Ensures that all required elements of meta-data are supplied.
|
81 |
+
|
82 |
+
Required fields:
|
83 |
+
name, version, URL
|
84 |
+
|
85 |
+
Recommended fields:
|
86 |
+
(author and author_email) or (maintainer and maintainer_email))
|
87 |
+
|
88 |
+
Warns if any are missing.
|
89 |
+
"""
|
90 |
+
metadata = self.distribution.metadata
|
91 |
+
|
92 |
+
missing = []
|
93 |
+
for attr in ('name', 'version', 'url'):
|
94 |
+
if not (hasattr(metadata, attr) and getattr(metadata, attr)):
|
95 |
+
missing.append(attr)
|
96 |
+
|
97 |
+
if missing:
|
98 |
+
self.warn("missing required meta-data: %s" % ', '.join(missing))
|
99 |
+
if metadata.author:
|
100 |
+
if not metadata.author_email:
|
101 |
+
self.warn("missing meta-data: if 'author' supplied, " +
|
102 |
+
"'author_email' should be supplied too")
|
103 |
+
elif metadata.maintainer:
|
104 |
+
if not metadata.maintainer_email:
|
105 |
+
self.warn("missing meta-data: if 'maintainer' supplied, " +
|
106 |
+
"'maintainer_email' should be supplied too")
|
107 |
+
else:
|
108 |
+
self.warn("missing meta-data: either (author and author_email) " +
|
109 |
+
"or (maintainer and maintainer_email) " +
|
110 |
+
"should be supplied")
|
111 |
+
|
112 |
+
def check_restructuredtext(self):
|
113 |
+
"""Checks if the long string fields are reST-compliant."""
|
114 |
+
data = self.distribution.get_long_description()
|
115 |
+
for warning in self._check_rst_data(data):
|
116 |
+
line = warning[-1].get('line')
|
117 |
+
if line is None:
|
118 |
+
warning = warning[1]
|
119 |
+
else:
|
120 |
+
warning = '%s (line %s)' % (warning[1], line)
|
121 |
+
self.warn(warning)
|
122 |
+
|
123 |
+
def _check_rst_data(self, data):
|
124 |
+
"""Returns warnings when the provided data doesn't compile."""
|
125 |
+
# the include and csv_table directives need this to be a path
|
126 |
+
source_path = self.distribution.script_name or 'setup.py'
|
127 |
+
parser = Parser()
|
128 |
+
settings = frontend.OptionParser(components=(Parser,)).get_default_values()
|
129 |
+
settings.tab_width = 4
|
130 |
+
settings.pep_references = None
|
131 |
+
settings.rfc_references = None
|
132 |
+
reporter = SilentReporter(source_path,
|
133 |
+
settings.report_level,
|
134 |
+
settings.halt_level,
|
135 |
+
stream=settings.warning_stream,
|
136 |
+
debug=settings.debug,
|
137 |
+
encoding=settings.error_encoding,
|
138 |
+
error_handler=settings.error_encoding_error_handler)
|
139 |
+
|
140 |
+
document = nodes.document(settings, reporter, source=source_path)
|
141 |
+
document.note_source(source_path, -1)
|
142 |
+
try:
|
143 |
+
parser.parse(data, document)
|
144 |
+
except AttributeError as e:
|
145 |
+
reporter.messages.append(
|
146 |
+
(-1, 'Could not finish the parsing: %s.' % e, '', {}))
|
147 |
+
|
148 |
+
return reporter.messages
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/config.py
ADDED
@@ -0,0 +1,344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.config
|
2 |
+
|
3 |
+
Implements the Distutils 'config' command, a (mostly) empty command class
|
4 |
+
that exists mainly to be sub-classed by specific module distributions and
|
5 |
+
applications. The idea is that while every "config" command is different,
|
6 |
+
at least they're all named the same, and users always see "config" in the
|
7 |
+
list of standard commands. Also, this is a good place to put common
|
8 |
+
configure-like tasks: "try to compile this C code", or "figure out where
|
9 |
+
this header file lives".
|
10 |
+
"""
|
11 |
+
|
12 |
+
import os, re
|
13 |
+
|
14 |
+
from distutils.core import Command
|
15 |
+
from distutils.errors import DistutilsExecError
|
16 |
+
from distutils.sysconfig import customize_compiler
|
17 |
+
from distutils import log
|
18 |
+
|
19 |
+
LANG_EXT = {"c": ".c", "c++": ".cxx"}
|
20 |
+
|
21 |
+
class config(Command):
|
22 |
+
|
23 |
+
description = "prepare to build"
|
24 |
+
|
25 |
+
user_options = [
|
26 |
+
('compiler=', None,
|
27 |
+
"specify the compiler type"),
|
28 |
+
('cc=', None,
|
29 |
+
"specify the compiler executable"),
|
30 |
+
('include-dirs=', 'I',
|
31 |
+
"list of directories to search for header files"),
|
32 |
+
('define=', 'D',
|
33 |
+
"C preprocessor macros to define"),
|
34 |
+
('undef=', 'U',
|
35 |
+
"C preprocessor macros to undefine"),
|
36 |
+
('libraries=', 'l',
|
37 |
+
"external C libraries to link with"),
|
38 |
+
('library-dirs=', 'L',
|
39 |
+
"directories to search for external C libraries"),
|
40 |
+
|
41 |
+
('noisy', None,
|
42 |
+
"show every action (compile, link, run, ...) taken"),
|
43 |
+
('dump-source', None,
|
44 |
+
"dump generated source files before attempting to compile them"),
|
45 |
+
]
|
46 |
+
|
47 |
+
|
48 |
+
# The three standard command methods: since the "config" command
|
49 |
+
# does nothing by default, these are empty.
|
50 |
+
|
51 |
+
def initialize_options(self):
|
52 |
+
self.compiler = None
|
53 |
+
self.cc = None
|
54 |
+
self.include_dirs = None
|
55 |
+
self.libraries = None
|
56 |
+
self.library_dirs = None
|
57 |
+
|
58 |
+
# maximal output for now
|
59 |
+
self.noisy = 1
|
60 |
+
self.dump_source = 1
|
61 |
+
|
62 |
+
# list of temporary files generated along-the-way that we have
|
63 |
+
# to clean at some point
|
64 |
+
self.temp_files = []
|
65 |
+
|
66 |
+
def finalize_options(self):
|
67 |
+
if self.include_dirs is None:
|
68 |
+
self.include_dirs = self.distribution.include_dirs or []
|
69 |
+
elif isinstance(self.include_dirs, str):
|
70 |
+
self.include_dirs = self.include_dirs.split(os.pathsep)
|
71 |
+
|
72 |
+
if self.libraries is None:
|
73 |
+
self.libraries = []
|
74 |
+
elif isinstance(self.libraries, str):
|
75 |
+
self.libraries = [self.libraries]
|
76 |
+
|
77 |
+
if self.library_dirs is None:
|
78 |
+
self.library_dirs = []
|
79 |
+
elif isinstance(self.library_dirs, str):
|
80 |
+
self.library_dirs = self.library_dirs.split(os.pathsep)
|
81 |
+
|
82 |
+
def run(self):
|
83 |
+
pass
|
84 |
+
|
85 |
+
# Utility methods for actual "config" commands. The interfaces are
|
86 |
+
# loosely based on Autoconf macros of similar names. Sub-classes
|
87 |
+
# may use these freely.
|
88 |
+
|
89 |
+
def _check_compiler(self):
|
90 |
+
"""Check that 'self.compiler' really is a CCompiler object;
|
91 |
+
if not, make it one.
|
92 |
+
"""
|
93 |
+
# We do this late, and only on-demand, because this is an expensive
|
94 |
+
# import.
|
95 |
+
from distutils.ccompiler import CCompiler, new_compiler
|
96 |
+
if not isinstance(self.compiler, CCompiler):
|
97 |
+
self.compiler = new_compiler(compiler=self.compiler,
|
98 |
+
dry_run=self.dry_run, force=1)
|
99 |
+
customize_compiler(self.compiler)
|
100 |
+
if self.include_dirs:
|
101 |
+
self.compiler.set_include_dirs(self.include_dirs)
|
102 |
+
if self.libraries:
|
103 |
+
self.compiler.set_libraries(self.libraries)
|
104 |
+
if self.library_dirs:
|
105 |
+
self.compiler.set_library_dirs(self.library_dirs)
|
106 |
+
|
107 |
+
def _gen_temp_sourcefile(self, body, headers, lang):
|
108 |
+
filename = "_configtest" + LANG_EXT[lang]
|
109 |
+
with open(filename, "w") as file:
|
110 |
+
if headers:
|
111 |
+
for header in headers:
|
112 |
+
file.write("#include <%s>\n" % header)
|
113 |
+
file.write("\n")
|
114 |
+
file.write(body)
|
115 |
+
if body[-1] != "\n":
|
116 |
+
file.write("\n")
|
117 |
+
return filename
|
118 |
+
|
119 |
+
def _preprocess(self, body, headers, include_dirs, lang):
|
120 |
+
src = self._gen_temp_sourcefile(body, headers, lang)
|
121 |
+
out = "_configtest.i"
|
122 |
+
self.temp_files.extend([src, out])
|
123 |
+
self.compiler.preprocess(src, out, include_dirs=include_dirs)
|
124 |
+
return (src, out)
|
125 |
+
|
126 |
+
def _compile(self, body, headers, include_dirs, lang):
|
127 |
+
src = self._gen_temp_sourcefile(body, headers, lang)
|
128 |
+
if self.dump_source:
|
129 |
+
dump_file(src, "compiling '%s':" % src)
|
130 |
+
(obj,) = self.compiler.object_filenames([src])
|
131 |
+
self.temp_files.extend([src, obj])
|
132 |
+
self.compiler.compile([src], include_dirs=include_dirs)
|
133 |
+
return (src, obj)
|
134 |
+
|
135 |
+
def _link(self, body, headers, include_dirs, libraries, library_dirs,
|
136 |
+
lang):
|
137 |
+
(src, obj) = self._compile(body, headers, include_dirs, lang)
|
138 |
+
prog = os.path.splitext(os.path.basename(src))[0]
|
139 |
+
self.compiler.link_executable([obj], prog,
|
140 |
+
libraries=libraries,
|
141 |
+
library_dirs=library_dirs,
|
142 |
+
target_lang=lang)
|
143 |
+
|
144 |
+
if self.compiler.exe_extension is not None:
|
145 |
+
prog = prog + self.compiler.exe_extension
|
146 |
+
self.temp_files.append(prog)
|
147 |
+
|
148 |
+
return (src, obj, prog)
|
149 |
+
|
150 |
+
def _clean(self, *filenames):
|
151 |
+
if not filenames:
|
152 |
+
filenames = self.temp_files
|
153 |
+
self.temp_files = []
|
154 |
+
log.info("removing: %s", ' '.join(filenames))
|
155 |
+
for filename in filenames:
|
156 |
+
try:
|
157 |
+
os.remove(filename)
|
158 |
+
except OSError:
|
159 |
+
pass
|
160 |
+
|
161 |
+
|
162 |
+
# XXX these ignore the dry-run flag: what to do, what to do? even if
|
163 |
+
# you want a dry-run build, you still need some sort of configuration
|
164 |
+
# info. My inclination is to make it up to the real config command to
|
165 |
+
# consult 'dry_run', and assume a default (minimal) configuration if
|
166 |
+
# true. The problem with trying to do it here is that you'd have to
|
167 |
+
# return either true or false from all the 'try' methods, neither of
|
168 |
+
# which is correct.
|
169 |
+
|
170 |
+
# XXX need access to the header search path and maybe default macros.
|
171 |
+
|
172 |
+
def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"):
|
173 |
+
"""Construct a source file from 'body' (a string containing lines
|
174 |
+
of C/C++ code) and 'headers' (a list of header files to include)
|
175 |
+
and run it through the preprocessor. Return true if the
|
176 |
+
preprocessor succeeded, false if there were any errors.
|
177 |
+
('body' probably isn't of much use, but what the heck.)
|
178 |
+
"""
|
179 |
+
from distutils.ccompiler import CompileError
|
180 |
+
self._check_compiler()
|
181 |
+
ok = True
|
182 |
+
try:
|
183 |
+
self._preprocess(body, headers, include_dirs, lang)
|
184 |
+
except CompileError:
|
185 |
+
ok = False
|
186 |
+
|
187 |
+
self._clean()
|
188 |
+
return ok
|
189 |
+
|
190 |
+
def search_cpp(self, pattern, body=None, headers=None, include_dirs=None,
|
191 |
+
lang="c"):
|
192 |
+
"""Construct a source file (just like 'try_cpp()'), run it through
|
193 |
+
the preprocessor, and return true if any line of the output matches
|
194 |
+
'pattern'. 'pattern' should either be a compiled regex object or a
|
195 |
+
string containing a regex. If both 'body' and 'headers' are None,
|
196 |
+
preprocesses an empty file -- which can be useful to determine the
|
197 |
+
symbols the preprocessor and compiler set by default.
|
198 |
+
"""
|
199 |
+
self._check_compiler()
|
200 |
+
src, out = self._preprocess(body, headers, include_dirs, lang)
|
201 |
+
|
202 |
+
if isinstance(pattern, str):
|
203 |
+
pattern = re.compile(pattern)
|
204 |
+
|
205 |
+
with open(out) as file:
|
206 |
+
match = False
|
207 |
+
while True:
|
208 |
+
line = file.readline()
|
209 |
+
if line == '':
|
210 |
+
break
|
211 |
+
if pattern.search(line):
|
212 |
+
match = True
|
213 |
+
break
|
214 |
+
|
215 |
+
self._clean()
|
216 |
+
return match
|
217 |
+
|
218 |
+
def try_compile(self, body, headers=None, include_dirs=None, lang="c"):
|
219 |
+
"""Try to compile a source file built from 'body' and 'headers'.
|
220 |
+
Return true on success, false otherwise.
|
221 |
+
"""
|
222 |
+
from distutils.ccompiler import CompileError
|
223 |
+
self._check_compiler()
|
224 |
+
try:
|
225 |
+
self._compile(body, headers, include_dirs, lang)
|
226 |
+
ok = True
|
227 |
+
except CompileError:
|
228 |
+
ok = False
|
229 |
+
|
230 |
+
log.info(ok and "success!" or "failure.")
|
231 |
+
self._clean()
|
232 |
+
return ok
|
233 |
+
|
234 |
+
def try_link(self, body, headers=None, include_dirs=None, libraries=None,
|
235 |
+
library_dirs=None, lang="c"):
|
236 |
+
"""Try to compile and link a source file, built from 'body' and
|
237 |
+
'headers', to executable form. Return true on success, false
|
238 |
+
otherwise.
|
239 |
+
"""
|
240 |
+
from distutils.ccompiler import CompileError, LinkError
|
241 |
+
self._check_compiler()
|
242 |
+
try:
|
243 |
+
self._link(body, headers, include_dirs,
|
244 |
+
libraries, library_dirs, lang)
|
245 |
+
ok = True
|
246 |
+
except (CompileError, LinkError):
|
247 |
+
ok = False
|
248 |
+
|
249 |
+
log.info(ok and "success!" or "failure.")
|
250 |
+
self._clean()
|
251 |
+
return ok
|
252 |
+
|
253 |
+
def try_run(self, body, headers=None, include_dirs=None, libraries=None,
|
254 |
+
library_dirs=None, lang="c"):
|
255 |
+
"""Try to compile, link to an executable, and run a program
|
256 |
+
built from 'body' and 'headers'. Return true on success, false
|
257 |
+
otherwise.
|
258 |
+
"""
|
259 |
+
from distutils.ccompiler import CompileError, LinkError
|
260 |
+
self._check_compiler()
|
261 |
+
try:
|
262 |
+
src, obj, exe = self._link(body, headers, include_dirs,
|
263 |
+
libraries, library_dirs, lang)
|
264 |
+
self.spawn([exe])
|
265 |
+
ok = True
|
266 |
+
except (CompileError, LinkError, DistutilsExecError):
|
267 |
+
ok = False
|
268 |
+
|
269 |
+
log.info(ok and "success!" or "failure.")
|
270 |
+
self._clean()
|
271 |
+
return ok
|
272 |
+
|
273 |
+
|
274 |
+
# -- High-level methods --------------------------------------------
|
275 |
+
# (these are the ones that are actually likely to be useful
|
276 |
+
# when implementing a real-world config command!)
|
277 |
+
|
278 |
+
def check_func(self, func, headers=None, include_dirs=None,
|
279 |
+
libraries=None, library_dirs=None, decl=0, call=0):
|
280 |
+
"""Determine if function 'func' is available by constructing a
|
281 |
+
source file that refers to 'func', and compiles and links it.
|
282 |
+
If everything succeeds, returns true; otherwise returns false.
|
283 |
+
|
284 |
+
The constructed source file starts out by including the header
|
285 |
+
files listed in 'headers'. If 'decl' is true, it then declares
|
286 |
+
'func' (as "int func()"); you probably shouldn't supply 'headers'
|
287 |
+
and set 'decl' true in the same call, or you might get errors about
|
288 |
+
a conflicting declarations for 'func'. Finally, the constructed
|
289 |
+
'main()' function either references 'func' or (if 'call' is true)
|
290 |
+
calls it. 'libraries' and 'library_dirs' are used when
|
291 |
+
linking.
|
292 |
+
"""
|
293 |
+
self._check_compiler()
|
294 |
+
body = []
|
295 |
+
if decl:
|
296 |
+
body.append("int %s ();" % func)
|
297 |
+
body.append("int main () {")
|
298 |
+
if call:
|
299 |
+
body.append(" %s();" % func)
|
300 |
+
else:
|
301 |
+
body.append(" %s;" % func)
|
302 |
+
body.append("}")
|
303 |
+
body = "\n".join(body) + "\n"
|
304 |
+
|
305 |
+
return self.try_link(body, headers, include_dirs,
|
306 |
+
libraries, library_dirs)
|
307 |
+
|
308 |
+
def check_lib(self, library, library_dirs=None, headers=None,
|
309 |
+
include_dirs=None, other_libraries=[]):
|
310 |
+
"""Determine if 'library' is available to be linked against,
|
311 |
+
without actually checking that any particular symbols are provided
|
312 |
+
by it. 'headers' will be used in constructing the source file to
|
313 |
+
be compiled, but the only effect of this is to check if all the
|
314 |
+
header files listed are available. Any libraries listed in
|
315 |
+
'other_libraries' will be included in the link, in case 'library'
|
316 |
+
has symbols that depend on other libraries.
|
317 |
+
"""
|
318 |
+
self._check_compiler()
|
319 |
+
return self.try_link("int main (void) { }", headers, include_dirs,
|
320 |
+
[library] + other_libraries, library_dirs)
|
321 |
+
|
322 |
+
def check_header(self, header, include_dirs=None, library_dirs=None,
|
323 |
+
lang="c"):
|
324 |
+
"""Determine if the system header file named by 'header_file'
|
325 |
+
exists and can be found by the preprocessor; return true if so,
|
326 |
+
false otherwise.
|
327 |
+
"""
|
328 |
+
return self.try_cpp(body="/* No body */", headers=[header],
|
329 |
+
include_dirs=include_dirs)
|
330 |
+
|
331 |
+
def dump_file(filename, head=None):
|
332 |
+
"""Dumps a file content into log.info.
|
333 |
+
|
334 |
+
If head is not None, will be dumped before the file content.
|
335 |
+
"""
|
336 |
+
if head is None:
|
337 |
+
log.info('%s', filename)
|
338 |
+
else:
|
339 |
+
log.info(head)
|
340 |
+
file = open(filename)
|
341 |
+
try:
|
342 |
+
log.info(file.read())
|
343 |
+
finally:
|
344 |
+
file.close()
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/install_data.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.install_data
|
2 |
+
|
3 |
+
Implements the Distutils 'install_data' command, for installing
|
4 |
+
platform-independent data files."""
|
5 |
+
|
6 |
+
# contributed by Bastian Kleineidam
|
7 |
+
|
8 |
+
import os
|
9 |
+
from distutils.core import Command
|
10 |
+
from distutils.util import change_root, convert_path
|
11 |
+
|
12 |
+
class install_data(Command):
|
13 |
+
|
14 |
+
description = "install data files"
|
15 |
+
|
16 |
+
user_options = [
|
17 |
+
('install-dir=', 'd',
|
18 |
+
"base directory for installing data files "
|
19 |
+
"(default: installation base dir)"),
|
20 |
+
('root=', None,
|
21 |
+
"install everything relative to this alternate root directory"),
|
22 |
+
('force', 'f', "force installation (overwrite existing files)"),
|
23 |
+
]
|
24 |
+
|
25 |
+
boolean_options = ['force']
|
26 |
+
|
27 |
+
def initialize_options(self):
|
28 |
+
self.install_dir = None
|
29 |
+
self.outfiles = []
|
30 |
+
self.root = None
|
31 |
+
self.force = 0
|
32 |
+
self.data_files = self.distribution.data_files
|
33 |
+
self.warn_dir = 1
|
34 |
+
|
35 |
+
def finalize_options(self):
|
36 |
+
self.set_undefined_options('install',
|
37 |
+
('install_data', 'install_dir'),
|
38 |
+
('root', 'root'),
|
39 |
+
('force', 'force'),
|
40 |
+
)
|
41 |
+
|
42 |
+
def run(self):
|
43 |
+
self.mkpath(self.install_dir)
|
44 |
+
for f in self.data_files:
|
45 |
+
if isinstance(f, str):
|
46 |
+
# it's a simple file, so copy it
|
47 |
+
f = convert_path(f)
|
48 |
+
if self.warn_dir:
|
49 |
+
self.warn("setup script did not provide a directory for "
|
50 |
+
"'%s' -- installing right in '%s'" %
|
51 |
+
(f, self.install_dir))
|
52 |
+
(out, _) = self.copy_file(f, self.install_dir)
|
53 |
+
self.outfiles.append(out)
|
54 |
+
else:
|
55 |
+
# it's a tuple with path to install to and a list of files
|
56 |
+
dir = convert_path(f[0])
|
57 |
+
if not os.path.isabs(dir):
|
58 |
+
dir = os.path.join(self.install_dir, dir)
|
59 |
+
elif self.root:
|
60 |
+
dir = change_root(self.root, dir)
|
61 |
+
self.mkpath(dir)
|
62 |
+
|
63 |
+
if f[1] == []:
|
64 |
+
# If there are no files listed, the user must be
|
65 |
+
# trying to create an empty directory, so add the
|
66 |
+
# directory to the list of output files.
|
67 |
+
self.outfiles.append(dir)
|
68 |
+
else:
|
69 |
+
# Copy files, adding them to the list of output files.
|
70 |
+
for data in f[1]:
|
71 |
+
data = convert_path(data)
|
72 |
+
(out, _) = self.copy_file(data, dir)
|
73 |
+
self.outfiles.append(out)
|
74 |
+
|
75 |
+
def get_inputs(self):
|
76 |
+
return self.data_files or []
|
77 |
+
|
78 |
+
def get_outputs(self):
|
79 |
+
return self.outfiles
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/install_headers.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.install_headers
|
2 |
+
|
3 |
+
Implements the Distutils 'install_headers' command, to install C/C++ header
|
4 |
+
files to the Python include directory."""
|
5 |
+
|
6 |
+
from distutils.core import Command
|
7 |
+
|
8 |
+
|
9 |
+
# XXX force is never used
|
10 |
+
class install_headers(Command):
|
11 |
+
|
12 |
+
description = "install C/C++ header files"
|
13 |
+
|
14 |
+
user_options = [('install-dir=', 'd',
|
15 |
+
"directory to install header files to"),
|
16 |
+
('force', 'f',
|
17 |
+
"force installation (overwrite existing files)"),
|
18 |
+
]
|
19 |
+
|
20 |
+
boolean_options = ['force']
|
21 |
+
|
22 |
+
def initialize_options(self):
|
23 |
+
self.install_dir = None
|
24 |
+
self.force = 0
|
25 |
+
self.outfiles = []
|
26 |
+
|
27 |
+
def finalize_options(self):
|
28 |
+
self.set_undefined_options('install',
|
29 |
+
('install_headers', 'install_dir'),
|
30 |
+
('force', 'force'))
|
31 |
+
|
32 |
+
|
33 |
+
def run(self):
|
34 |
+
headers = self.distribution.headers
|
35 |
+
if not headers:
|
36 |
+
return
|
37 |
+
|
38 |
+
self.mkpath(self.install_dir)
|
39 |
+
for header in headers:
|
40 |
+
(out, _) = self.copy_file(header, self.install_dir)
|
41 |
+
self.outfiles.append(out)
|
42 |
+
|
43 |
+
def get_inputs(self):
|
44 |
+
return self.distribution.headers or []
|
45 |
+
|
46 |
+
def get_outputs(self):
|
47 |
+
return self.outfiles
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/install_lib.py
ADDED
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.install_lib
|
2 |
+
|
3 |
+
Implements the Distutils 'install_lib' command
|
4 |
+
(install all Python modules)."""
|
5 |
+
|
6 |
+
import os
|
7 |
+
import importlib.util
|
8 |
+
import sys
|
9 |
+
|
10 |
+
from distutils.core import Command
|
11 |
+
from distutils.errors import DistutilsOptionError
|
12 |
+
|
13 |
+
|
14 |
+
# Extension for Python source files.
|
15 |
+
PYTHON_SOURCE_EXTENSION = ".py"
|
16 |
+
|
17 |
+
class install_lib(Command):
|
18 |
+
|
19 |
+
description = "install all Python modules (extensions and pure Python)"
|
20 |
+
|
21 |
+
# The byte-compilation options are a tad confusing. Here are the
|
22 |
+
# possible scenarios:
|
23 |
+
# 1) no compilation at all (--no-compile --no-optimize)
|
24 |
+
# 2) compile .pyc only (--compile --no-optimize; default)
|
25 |
+
# 3) compile .pyc and "opt-1" .pyc (--compile --optimize)
|
26 |
+
# 4) compile "opt-1" .pyc only (--no-compile --optimize)
|
27 |
+
# 5) compile .pyc and "opt-2" .pyc (--compile --optimize-more)
|
28 |
+
# 6) compile "opt-2" .pyc only (--no-compile --optimize-more)
|
29 |
+
#
|
30 |
+
# The UI for this is two options, 'compile' and 'optimize'.
|
31 |
+
# 'compile' is strictly boolean, and only decides whether to
|
32 |
+
# generate .pyc files. 'optimize' is three-way (0, 1, or 2), and
|
33 |
+
# decides both whether to generate .pyc files and what level of
|
34 |
+
# optimization to use.
|
35 |
+
|
36 |
+
user_options = [
|
37 |
+
('install-dir=', 'd', "directory to install to"),
|
38 |
+
('build-dir=','b', "build directory (where to install from)"),
|
39 |
+
('force', 'f', "force installation (overwrite existing files)"),
|
40 |
+
('compile', 'c', "compile .py to .pyc [default]"),
|
41 |
+
('no-compile', None, "don't compile .py files"),
|
42 |
+
('optimize=', 'O',
|
43 |
+
"also compile with optimization: -O1 for \"python -O\", "
|
44 |
+
"-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
|
45 |
+
('skip-build', None, "skip the build steps"),
|
46 |
+
]
|
47 |
+
|
48 |
+
boolean_options = ['force', 'compile', 'skip-build']
|
49 |
+
negative_opt = {'no-compile' : 'compile'}
|
50 |
+
|
51 |
+
def initialize_options(self):
|
52 |
+
# let the 'install' command dictate our installation directory
|
53 |
+
self.install_dir = None
|
54 |
+
self.build_dir = None
|
55 |
+
self.force = 0
|
56 |
+
self.compile = None
|
57 |
+
self.optimize = None
|
58 |
+
self.skip_build = None
|
59 |
+
|
60 |
+
def finalize_options(self):
|
61 |
+
# Get all the information we need to install pure Python modules
|
62 |
+
# from the umbrella 'install' command -- build (source) directory,
|
63 |
+
# install (target) directory, and whether to compile .py files.
|
64 |
+
self.set_undefined_options('install',
|
65 |
+
('build_lib', 'build_dir'),
|
66 |
+
('install_lib', 'install_dir'),
|
67 |
+
('force', 'force'),
|
68 |
+
('compile', 'compile'),
|
69 |
+
('optimize', 'optimize'),
|
70 |
+
('skip_build', 'skip_build'),
|
71 |
+
)
|
72 |
+
|
73 |
+
if self.compile is None:
|
74 |
+
self.compile = True
|
75 |
+
if self.optimize is None:
|
76 |
+
self.optimize = False
|
77 |
+
|
78 |
+
if not isinstance(self.optimize, int):
|
79 |
+
try:
|
80 |
+
self.optimize = int(self.optimize)
|
81 |
+
if self.optimize not in (0, 1, 2):
|
82 |
+
raise AssertionError
|
83 |
+
except (ValueError, AssertionError):
|
84 |
+
raise DistutilsOptionError("optimize must be 0, 1, or 2")
|
85 |
+
|
86 |
+
def run(self):
|
87 |
+
# Make sure we have built everything we need first
|
88 |
+
self.build()
|
89 |
+
|
90 |
+
# Install everything: simply dump the entire contents of the build
|
91 |
+
# directory to the installation directory (that's the beauty of
|
92 |
+
# having a build directory!)
|
93 |
+
outfiles = self.install()
|
94 |
+
|
95 |
+
# (Optionally) compile .py to .pyc
|
96 |
+
if outfiles is not None and self.distribution.has_pure_modules():
|
97 |
+
self.byte_compile(outfiles)
|
98 |
+
|
99 |
+
# -- Top-level worker functions ------------------------------------
|
100 |
+
# (called from 'run()')
|
101 |
+
|
102 |
+
def build(self):
|
103 |
+
if not self.skip_build:
|
104 |
+
if self.distribution.has_pure_modules():
|
105 |
+
self.run_command('build_py')
|
106 |
+
if self.distribution.has_ext_modules():
|
107 |
+
self.run_command('build_ext')
|
108 |
+
|
109 |
+
def install(self):
|
110 |
+
if os.path.isdir(self.build_dir):
|
111 |
+
outfiles = self.copy_tree(self.build_dir, self.install_dir)
|
112 |
+
else:
|
113 |
+
self.warn("'%s' does not exist -- no Python modules to install" %
|
114 |
+
self.build_dir)
|
115 |
+
return
|
116 |
+
return outfiles
|
117 |
+
|
118 |
+
def byte_compile(self, files):
|
119 |
+
if sys.dont_write_bytecode:
|
120 |
+
self.warn('byte-compiling is disabled, skipping.')
|
121 |
+
return
|
122 |
+
|
123 |
+
from distutils.util import byte_compile
|
124 |
+
|
125 |
+
# Get the "--root" directory supplied to the "install" command,
|
126 |
+
# and use it as a prefix to strip off the purported filename
|
127 |
+
# encoded in bytecode files. This is far from complete, but it
|
128 |
+
# should at least generate usable bytecode in RPM distributions.
|
129 |
+
install_root = self.get_finalized_command('install').root
|
130 |
+
|
131 |
+
if self.compile:
|
132 |
+
byte_compile(files, optimize=0,
|
133 |
+
force=self.force, prefix=install_root,
|
134 |
+
dry_run=self.dry_run)
|
135 |
+
if self.optimize > 0:
|
136 |
+
byte_compile(files, optimize=self.optimize,
|
137 |
+
force=self.force, prefix=install_root,
|
138 |
+
verbose=self.verbose, dry_run=self.dry_run)
|
139 |
+
|
140 |
+
|
141 |
+
# -- Utility methods -----------------------------------------------
|
142 |
+
|
143 |
+
def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir):
|
144 |
+
if not has_any:
|
145 |
+
return []
|
146 |
+
|
147 |
+
build_cmd = self.get_finalized_command(build_cmd)
|
148 |
+
build_files = build_cmd.get_outputs()
|
149 |
+
build_dir = getattr(build_cmd, cmd_option)
|
150 |
+
|
151 |
+
prefix_len = len(build_dir) + len(os.sep)
|
152 |
+
outputs = []
|
153 |
+
for file in build_files:
|
154 |
+
outputs.append(os.path.join(output_dir, file[prefix_len:]))
|
155 |
+
|
156 |
+
return outputs
|
157 |
+
|
158 |
+
def _bytecode_filenames(self, py_filenames):
|
159 |
+
bytecode_files = []
|
160 |
+
for py_file in py_filenames:
|
161 |
+
# Since build_py handles package data installation, the
|
162 |
+
# list of outputs can contain more than just .py files.
|
163 |
+
# Make sure we only report bytecode for the .py files.
|
164 |
+
ext = os.path.splitext(os.path.normcase(py_file))[1]
|
165 |
+
if ext != PYTHON_SOURCE_EXTENSION:
|
166 |
+
continue
|
167 |
+
if self.compile:
|
168 |
+
bytecode_files.append(importlib.util.cache_from_source(
|
169 |
+
py_file, optimization=''))
|
170 |
+
if self.optimize > 0:
|
171 |
+
bytecode_files.append(importlib.util.cache_from_source(
|
172 |
+
py_file, optimization=self.optimize))
|
173 |
+
|
174 |
+
return bytecode_files
|
175 |
+
|
176 |
+
|
177 |
+
# -- External interface --------------------------------------------
|
178 |
+
# (called by outsiders)
|
179 |
+
|
180 |
+
def get_outputs(self):
|
181 |
+
"""Return the list of files that would be installed if this command
|
182 |
+
were actually run. Not affected by the "dry-run" flag or whether
|
183 |
+
modules have actually been built yet.
|
184 |
+
"""
|
185 |
+
pure_outputs = \
|
186 |
+
self._mutate_outputs(self.distribution.has_pure_modules(),
|
187 |
+
'build_py', 'build_lib',
|
188 |
+
self.install_dir)
|
189 |
+
if self.compile:
|
190 |
+
bytecode_outputs = self._bytecode_filenames(pure_outputs)
|
191 |
+
else:
|
192 |
+
bytecode_outputs = []
|
193 |
+
|
194 |
+
ext_outputs = \
|
195 |
+
self._mutate_outputs(self.distribution.has_ext_modules(),
|
196 |
+
'build_ext', 'build_lib',
|
197 |
+
self.install_dir)
|
198 |
+
|
199 |
+
return pure_outputs + bytecode_outputs + ext_outputs
|
200 |
+
|
201 |
+
def get_inputs(self):
|
202 |
+
"""Get the list of files that are input to this command, ie. the
|
203 |
+
files that get installed as they are named in the build tree.
|
204 |
+
The files in this list correspond one-to-one to the output
|
205 |
+
filenames returned by 'get_outputs()'.
|
206 |
+
"""
|
207 |
+
inputs = []
|
208 |
+
|
209 |
+
if self.distribution.has_pure_modules():
|
210 |
+
build_py = self.get_finalized_command('build_py')
|
211 |
+
inputs.extend(build_py.get_outputs())
|
212 |
+
|
213 |
+
if self.distribution.has_ext_modules():
|
214 |
+
build_ext = self.get_finalized_command('build_ext')
|
215 |
+
inputs.extend(build_ext.get_outputs())
|
216 |
+
|
217 |
+
return inputs
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/install_scripts.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.install_scripts
|
2 |
+
|
3 |
+
Implements the Distutils 'install_scripts' command, for installing
|
4 |
+
Python scripts."""
|
5 |
+
|
6 |
+
# contributed by Bastian Kleineidam
|
7 |
+
|
8 |
+
import os
|
9 |
+
from distutils.core import Command
|
10 |
+
from distutils import log
|
11 |
+
from stat import ST_MODE
|
12 |
+
|
13 |
+
|
14 |
+
class install_scripts(Command):
|
15 |
+
|
16 |
+
description = "install scripts (Python or otherwise)"
|
17 |
+
|
18 |
+
user_options = [
|
19 |
+
('install-dir=', 'd', "directory to install scripts to"),
|
20 |
+
('build-dir=','b', "build directory (where to install from)"),
|
21 |
+
('force', 'f', "force installation (overwrite existing files)"),
|
22 |
+
('skip-build', None, "skip the build steps"),
|
23 |
+
]
|
24 |
+
|
25 |
+
boolean_options = ['force', 'skip-build']
|
26 |
+
|
27 |
+
def initialize_options(self):
|
28 |
+
self.install_dir = None
|
29 |
+
self.force = 0
|
30 |
+
self.build_dir = None
|
31 |
+
self.skip_build = None
|
32 |
+
|
33 |
+
def finalize_options(self):
|
34 |
+
self.set_undefined_options('build', ('build_scripts', 'build_dir'))
|
35 |
+
self.set_undefined_options('install',
|
36 |
+
('install_scripts', 'install_dir'),
|
37 |
+
('force', 'force'),
|
38 |
+
('skip_build', 'skip_build'),
|
39 |
+
)
|
40 |
+
|
41 |
+
def run(self):
|
42 |
+
if not self.skip_build:
|
43 |
+
self.run_command('build_scripts')
|
44 |
+
self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
|
45 |
+
if os.name == 'posix':
|
46 |
+
# Set the executable bits (owner, group, and world) on
|
47 |
+
# all the scripts we just installed.
|
48 |
+
for file in self.get_outputs():
|
49 |
+
if self.dry_run:
|
50 |
+
log.info("changing mode of %s", file)
|
51 |
+
else:
|
52 |
+
mode = ((os.stat(file)[ST_MODE]) | 0o555) & 0o7777
|
53 |
+
log.info("changing mode of %s to %o", file, mode)
|
54 |
+
os.chmod(file, mode)
|
55 |
+
|
56 |
+
def get_inputs(self):
|
57 |
+
return self.distribution.scripts or []
|
58 |
+
|
59 |
+
def get_outputs(self):
|
60 |
+
return self.outfiles or []
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/command/sdist.py
ADDED
@@ -0,0 +1,494 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.command.sdist
|
2 |
+
|
3 |
+
Implements the Distutils 'sdist' command (create a source distribution)."""
|
4 |
+
|
5 |
+
import os
|
6 |
+
import sys
|
7 |
+
from glob import glob
|
8 |
+
from warnings import warn
|
9 |
+
|
10 |
+
from distutils.core import Command
|
11 |
+
from distutils import dir_util
|
12 |
+
from distutils import file_util
|
13 |
+
from distutils import archive_util
|
14 |
+
from distutils.text_file import TextFile
|
15 |
+
from distutils.filelist import FileList
|
16 |
+
from distutils import log
|
17 |
+
from distutils.util import convert_path
|
18 |
+
from distutils.errors import DistutilsTemplateError, DistutilsOptionError
|
19 |
+
|
20 |
+
|
21 |
+
def show_formats():
|
22 |
+
"""Print all possible values for the 'formats' option (used by
|
23 |
+
the "--help-formats" command-line option).
|
24 |
+
"""
|
25 |
+
from distutils.fancy_getopt import FancyGetopt
|
26 |
+
from distutils.archive_util import ARCHIVE_FORMATS
|
27 |
+
formats = []
|
28 |
+
for format in ARCHIVE_FORMATS.keys():
|
29 |
+
formats.append(("formats=" + format, None,
|
30 |
+
ARCHIVE_FORMATS[format][2]))
|
31 |
+
formats.sort()
|
32 |
+
FancyGetopt(formats).print_help(
|
33 |
+
"List of available source distribution formats:")
|
34 |
+
|
35 |
+
|
36 |
+
class sdist(Command):
|
37 |
+
|
38 |
+
description = "create a source distribution (tarball, zip file, etc.)"
|
39 |
+
|
40 |
+
def checking_metadata(self):
|
41 |
+
"""Callable used for the check sub-command.
|
42 |
+
|
43 |
+
Placed here so user_options can view it"""
|
44 |
+
return self.metadata_check
|
45 |
+
|
46 |
+
user_options = [
|
47 |
+
('template=', 't',
|
48 |
+
"name of manifest template file [default: MANIFEST.in]"),
|
49 |
+
('manifest=', 'm',
|
50 |
+
"name of manifest file [default: MANIFEST]"),
|
51 |
+
('use-defaults', None,
|
52 |
+
"include the default file set in the manifest "
|
53 |
+
"[default; disable with --no-defaults]"),
|
54 |
+
('no-defaults', None,
|
55 |
+
"don't include the default file set"),
|
56 |
+
('prune', None,
|
57 |
+
"specifically exclude files/directories that should not be "
|
58 |
+
"distributed (build tree, RCS/CVS dirs, etc.) "
|
59 |
+
"[default; disable with --no-prune]"),
|
60 |
+
('no-prune', None,
|
61 |
+
"don't automatically exclude anything"),
|
62 |
+
('manifest-only', 'o',
|
63 |
+
"just regenerate the manifest and then stop "
|
64 |
+
"(implies --force-manifest)"),
|
65 |
+
('force-manifest', 'f',
|
66 |
+
"forcibly regenerate the manifest and carry on as usual. "
|
67 |
+
"Deprecated: now the manifest is always regenerated."),
|
68 |
+
('formats=', None,
|
69 |
+
"formats for source distribution (comma-separated list)"),
|
70 |
+
('keep-temp', 'k',
|
71 |
+
"keep the distribution tree around after creating " +
|
72 |
+
"archive file(s)"),
|
73 |
+
('dist-dir=', 'd',
|
74 |
+
"directory to put the source distribution archive(s) in "
|
75 |
+
"[default: dist]"),
|
76 |
+
('metadata-check', None,
|
77 |
+
"Ensure that all required elements of meta-data "
|
78 |
+
"are supplied. Warn if any missing. [default]"),
|
79 |
+
('owner=', 'u',
|
80 |
+
"Owner name used when creating a tar file [default: current user]"),
|
81 |
+
('group=', 'g',
|
82 |
+
"Group name used when creating a tar file [default: current group]"),
|
83 |
+
]
|
84 |
+
|
85 |
+
boolean_options = ['use-defaults', 'prune',
|
86 |
+
'manifest-only', 'force-manifest',
|
87 |
+
'keep-temp', 'metadata-check']
|
88 |
+
|
89 |
+
help_options = [
|
90 |
+
('help-formats', None,
|
91 |
+
"list available distribution formats", show_formats),
|
92 |
+
]
|
93 |
+
|
94 |
+
negative_opt = {'no-defaults': 'use-defaults',
|
95 |
+
'no-prune': 'prune' }
|
96 |
+
|
97 |
+
sub_commands = [('check', checking_metadata)]
|
98 |
+
|
99 |
+
READMES = ('README', 'README.txt', 'README.rst')
|
100 |
+
|
101 |
+
def initialize_options(self):
|
102 |
+
# 'template' and 'manifest' are, respectively, the names of
|
103 |
+
# the manifest template and manifest file.
|
104 |
+
self.template = None
|
105 |
+
self.manifest = None
|
106 |
+
|
107 |
+
# 'use_defaults': if true, we will include the default file set
|
108 |
+
# in the manifest
|
109 |
+
self.use_defaults = 1
|
110 |
+
self.prune = 1
|
111 |
+
|
112 |
+
self.manifest_only = 0
|
113 |
+
self.force_manifest = 0
|
114 |
+
|
115 |
+
self.formats = ['gztar']
|
116 |
+
self.keep_temp = 0
|
117 |
+
self.dist_dir = None
|
118 |
+
|
119 |
+
self.archive_files = None
|
120 |
+
self.metadata_check = 1
|
121 |
+
self.owner = None
|
122 |
+
self.group = None
|
123 |
+
|
124 |
+
def finalize_options(self):
|
125 |
+
if self.manifest is None:
|
126 |
+
self.manifest = "MANIFEST"
|
127 |
+
if self.template is None:
|
128 |
+
self.template = "MANIFEST.in"
|
129 |
+
|
130 |
+
self.ensure_string_list('formats')
|
131 |
+
|
132 |
+
bad_format = archive_util.check_archive_formats(self.formats)
|
133 |
+
if bad_format:
|
134 |
+
raise DistutilsOptionError(
|
135 |
+
"unknown archive format '%s'" % bad_format)
|
136 |
+
|
137 |
+
if self.dist_dir is None:
|
138 |
+
self.dist_dir = "dist"
|
139 |
+
|
140 |
+
def run(self):
|
141 |
+
# 'filelist' contains the list of files that will make up the
|
142 |
+
# manifest
|
143 |
+
self.filelist = FileList()
|
144 |
+
|
145 |
+
# Run sub commands
|
146 |
+
for cmd_name in self.get_sub_commands():
|
147 |
+
self.run_command(cmd_name)
|
148 |
+
|
149 |
+
# Do whatever it takes to get the list of files to process
|
150 |
+
# (process the manifest template, read an existing manifest,
|
151 |
+
# whatever). File list is accumulated in 'self.filelist'.
|
152 |
+
self.get_file_list()
|
153 |
+
|
154 |
+
# If user just wanted us to regenerate the manifest, stop now.
|
155 |
+
if self.manifest_only:
|
156 |
+
return
|
157 |
+
|
158 |
+
# Otherwise, go ahead and create the source distribution tarball,
|
159 |
+
# or zipfile, or whatever.
|
160 |
+
self.make_distribution()
|
161 |
+
|
162 |
+
def check_metadata(self):
|
163 |
+
"""Deprecated API."""
|
164 |
+
warn("distutils.command.sdist.check_metadata is deprecated, \
|
165 |
+
use the check command instead", PendingDeprecationWarning)
|
166 |
+
check = self.distribution.get_command_obj('check')
|
167 |
+
check.ensure_finalized()
|
168 |
+
check.run()
|
169 |
+
|
170 |
+
def get_file_list(self):
|
171 |
+
"""Figure out the list of files to include in the source
|
172 |
+
distribution, and put it in 'self.filelist'. This might involve
|
173 |
+
reading the manifest template (and writing the manifest), or just
|
174 |
+
reading the manifest, or just using the default file set -- it all
|
175 |
+
depends on the user's options.
|
176 |
+
"""
|
177 |
+
# new behavior when using a template:
|
178 |
+
# the file list is recalculated every time because
|
179 |
+
# even if MANIFEST.in or setup.py are not changed
|
180 |
+
# the user might have added some files in the tree that
|
181 |
+
# need to be included.
|
182 |
+
#
|
183 |
+
# This makes --force the default and only behavior with templates.
|
184 |
+
template_exists = os.path.isfile(self.template)
|
185 |
+
if not template_exists and self._manifest_is_not_generated():
|
186 |
+
self.read_manifest()
|
187 |
+
self.filelist.sort()
|
188 |
+
self.filelist.remove_duplicates()
|
189 |
+
return
|
190 |
+
|
191 |
+
if not template_exists:
|
192 |
+
self.warn(("manifest template '%s' does not exist " +
|
193 |
+
"(using default file list)") %
|
194 |
+
self.template)
|
195 |
+
self.filelist.findall()
|
196 |
+
|
197 |
+
if self.use_defaults:
|
198 |
+
self.add_defaults()
|
199 |
+
|
200 |
+
if template_exists:
|
201 |
+
self.read_template()
|
202 |
+
|
203 |
+
if self.prune:
|
204 |
+
self.prune_file_list()
|
205 |
+
|
206 |
+
self.filelist.sort()
|
207 |
+
self.filelist.remove_duplicates()
|
208 |
+
self.write_manifest()
|
209 |
+
|
210 |
+
def add_defaults(self):
|
211 |
+
"""Add all the default files to self.filelist:
|
212 |
+
- README or README.txt
|
213 |
+
- setup.py
|
214 |
+
- test/test*.py
|
215 |
+
- all pure Python modules mentioned in setup script
|
216 |
+
- all files pointed by package_data (build_py)
|
217 |
+
- all files defined in data_files.
|
218 |
+
- all files defined as scripts.
|
219 |
+
- all C sources listed as part of extensions or C libraries
|
220 |
+
in the setup script (doesn't catch C headers!)
|
221 |
+
Warns if (README or README.txt) or setup.py are missing; everything
|
222 |
+
else is optional.
|
223 |
+
"""
|
224 |
+
self._add_defaults_standards()
|
225 |
+
self._add_defaults_optional()
|
226 |
+
self._add_defaults_python()
|
227 |
+
self._add_defaults_data_files()
|
228 |
+
self._add_defaults_ext()
|
229 |
+
self._add_defaults_c_libs()
|
230 |
+
self._add_defaults_scripts()
|
231 |
+
|
232 |
+
@staticmethod
|
233 |
+
def _cs_path_exists(fspath):
|
234 |
+
"""
|
235 |
+
Case-sensitive path existence check
|
236 |
+
|
237 |
+
>>> sdist._cs_path_exists(__file__)
|
238 |
+
True
|
239 |
+
>>> sdist._cs_path_exists(__file__.upper())
|
240 |
+
False
|
241 |
+
"""
|
242 |
+
if not os.path.exists(fspath):
|
243 |
+
return False
|
244 |
+
# make absolute so we always have a directory
|
245 |
+
abspath = os.path.abspath(fspath)
|
246 |
+
directory, filename = os.path.split(abspath)
|
247 |
+
return filename in os.listdir(directory)
|
248 |
+
|
249 |
+
def _add_defaults_standards(self):
|
250 |
+
standards = [self.READMES, self.distribution.script_name]
|
251 |
+
for fn in standards:
|
252 |
+
if isinstance(fn, tuple):
|
253 |
+
alts = fn
|
254 |
+
got_it = False
|
255 |
+
for fn in alts:
|
256 |
+
if self._cs_path_exists(fn):
|
257 |
+
got_it = True
|
258 |
+
self.filelist.append(fn)
|
259 |
+
break
|
260 |
+
|
261 |
+
if not got_it:
|
262 |
+
self.warn("standard file not found: should have one of " +
|
263 |
+
', '.join(alts))
|
264 |
+
else:
|
265 |
+
if self._cs_path_exists(fn):
|
266 |
+
self.filelist.append(fn)
|
267 |
+
else:
|
268 |
+
self.warn("standard file '%s' not found" % fn)
|
269 |
+
|
270 |
+
def _add_defaults_optional(self):
|
271 |
+
optional = ['test/test*.py', 'setup.cfg']
|
272 |
+
for pattern in optional:
|
273 |
+
files = filter(os.path.isfile, glob(pattern))
|
274 |
+
self.filelist.extend(files)
|
275 |
+
|
276 |
+
def _add_defaults_python(self):
|
277 |
+
# build_py is used to get:
|
278 |
+
# - python modules
|
279 |
+
# - files defined in package_data
|
280 |
+
build_py = self.get_finalized_command('build_py')
|
281 |
+
|
282 |
+
# getting python files
|
283 |
+
if self.distribution.has_pure_modules():
|
284 |
+
self.filelist.extend(build_py.get_source_files())
|
285 |
+
|
286 |
+
# getting package_data files
|
287 |
+
# (computed in build_py.data_files by build_py.finalize_options)
|
288 |
+
for pkg, src_dir, build_dir, filenames in build_py.data_files:
|
289 |
+
for filename in filenames:
|
290 |
+
self.filelist.append(os.path.join(src_dir, filename))
|
291 |
+
|
292 |
+
def _add_defaults_data_files(self):
|
293 |
+
# getting distribution.data_files
|
294 |
+
if self.distribution.has_data_files():
|
295 |
+
for item in self.distribution.data_files:
|
296 |
+
if isinstance(item, str):
|
297 |
+
# plain file
|
298 |
+
item = convert_path(item)
|
299 |
+
if os.path.isfile(item):
|
300 |
+
self.filelist.append(item)
|
301 |
+
else:
|
302 |
+
# a (dirname, filenames) tuple
|
303 |
+
dirname, filenames = item
|
304 |
+
for f in filenames:
|
305 |
+
f = convert_path(f)
|
306 |
+
if os.path.isfile(f):
|
307 |
+
self.filelist.append(f)
|
308 |
+
|
309 |
+
def _add_defaults_ext(self):
|
310 |
+
if self.distribution.has_ext_modules():
|
311 |
+
build_ext = self.get_finalized_command('build_ext')
|
312 |
+
self.filelist.extend(build_ext.get_source_files())
|
313 |
+
|
314 |
+
def _add_defaults_c_libs(self):
|
315 |
+
if self.distribution.has_c_libraries():
|
316 |
+
build_clib = self.get_finalized_command('build_clib')
|
317 |
+
self.filelist.extend(build_clib.get_source_files())
|
318 |
+
|
319 |
+
def _add_defaults_scripts(self):
|
320 |
+
if self.distribution.has_scripts():
|
321 |
+
build_scripts = self.get_finalized_command('build_scripts')
|
322 |
+
self.filelist.extend(build_scripts.get_source_files())
|
323 |
+
|
324 |
+
def read_template(self):
|
325 |
+
"""Read and parse manifest template file named by self.template.
|
326 |
+
|
327 |
+
(usually "MANIFEST.in") The parsing and processing is done by
|
328 |
+
'self.filelist', which updates itself accordingly.
|
329 |
+
"""
|
330 |
+
log.info("reading manifest template '%s'", self.template)
|
331 |
+
template = TextFile(self.template, strip_comments=1, skip_blanks=1,
|
332 |
+
join_lines=1, lstrip_ws=1, rstrip_ws=1,
|
333 |
+
collapse_join=1)
|
334 |
+
|
335 |
+
try:
|
336 |
+
while True:
|
337 |
+
line = template.readline()
|
338 |
+
if line is None: # end of file
|
339 |
+
break
|
340 |
+
|
341 |
+
try:
|
342 |
+
self.filelist.process_template_line(line)
|
343 |
+
# the call above can raise a DistutilsTemplateError for
|
344 |
+
# malformed lines, or a ValueError from the lower-level
|
345 |
+
# convert_path function
|
346 |
+
except (DistutilsTemplateError, ValueError) as msg:
|
347 |
+
self.warn("%s, line %d: %s" % (template.filename,
|
348 |
+
template.current_line,
|
349 |
+
msg))
|
350 |
+
finally:
|
351 |
+
template.close()
|
352 |
+
|
353 |
+
def prune_file_list(self):
|
354 |
+
"""Prune off branches that might slip into the file list as created
|
355 |
+
by 'read_template()', but really don't belong there:
|
356 |
+
* the build tree (typically "build")
|
357 |
+
* the release tree itself (only an issue if we ran "sdist"
|
358 |
+
previously with --keep-temp, or it aborted)
|
359 |
+
* any RCS, CVS, .svn, .hg, .git, .bzr, _darcs directories
|
360 |
+
"""
|
361 |
+
build = self.get_finalized_command('build')
|
362 |
+
base_dir = self.distribution.get_fullname()
|
363 |
+
|
364 |
+
self.filelist.exclude_pattern(None, prefix=build.build_base)
|
365 |
+
self.filelist.exclude_pattern(None, prefix=base_dir)
|
366 |
+
|
367 |
+
if sys.platform == 'win32':
|
368 |
+
seps = r'/|\\'
|
369 |
+
else:
|
370 |
+
seps = '/'
|
371 |
+
|
372 |
+
vcs_dirs = ['RCS', 'CVS', r'\.svn', r'\.hg', r'\.git', r'\.bzr',
|
373 |
+
'_darcs']
|
374 |
+
vcs_ptrn = r'(^|%s)(%s)(%s).*' % (seps, '|'.join(vcs_dirs), seps)
|
375 |
+
self.filelist.exclude_pattern(vcs_ptrn, is_regex=1)
|
376 |
+
|
377 |
+
def write_manifest(self):
|
378 |
+
"""Write the file list in 'self.filelist' (presumably as filled in
|
379 |
+
by 'add_defaults()' and 'read_template()') to the manifest file
|
380 |
+
named by 'self.manifest'.
|
381 |
+
"""
|
382 |
+
if self._manifest_is_not_generated():
|
383 |
+
log.info("not writing to manually maintained "
|
384 |
+
"manifest file '%s'" % self.manifest)
|
385 |
+
return
|
386 |
+
|
387 |
+
content = self.filelist.files[:]
|
388 |
+
content.insert(0, '# file GENERATED by distutils, do NOT edit')
|
389 |
+
self.execute(file_util.write_file, (self.manifest, content),
|
390 |
+
"writing manifest file '%s'" % self.manifest)
|
391 |
+
|
392 |
+
def _manifest_is_not_generated(self):
|
393 |
+
# check for special comment used in 3.1.3 and higher
|
394 |
+
if not os.path.isfile(self.manifest):
|
395 |
+
return False
|
396 |
+
|
397 |
+
fp = open(self.manifest)
|
398 |
+
try:
|
399 |
+
first_line = fp.readline()
|
400 |
+
finally:
|
401 |
+
fp.close()
|
402 |
+
return first_line != '# file GENERATED by distutils, do NOT edit\n'
|
403 |
+
|
404 |
+
def read_manifest(self):
|
405 |
+
"""Read the manifest file (named by 'self.manifest') and use it to
|
406 |
+
fill in 'self.filelist', the list of files to include in the source
|
407 |
+
distribution.
|
408 |
+
"""
|
409 |
+
log.info("reading manifest file '%s'", self.manifest)
|
410 |
+
with open(self.manifest) as manifest:
|
411 |
+
for line in manifest:
|
412 |
+
# ignore comments and blank lines
|
413 |
+
line = line.strip()
|
414 |
+
if line.startswith('#') or not line:
|
415 |
+
continue
|
416 |
+
self.filelist.append(line)
|
417 |
+
|
418 |
+
def make_release_tree(self, base_dir, files):
|
419 |
+
"""Create the directory tree that will become the source
|
420 |
+
distribution archive. All directories implied by the filenames in
|
421 |
+
'files' are created under 'base_dir', and then we hard link or copy
|
422 |
+
(if hard linking is unavailable) those files into place.
|
423 |
+
Essentially, this duplicates the developer's source tree, but in a
|
424 |
+
directory named after the distribution, containing only the files
|
425 |
+
to be distributed.
|
426 |
+
"""
|
427 |
+
# Create all the directories under 'base_dir' necessary to
|
428 |
+
# put 'files' there; the 'mkpath()' is just so we don't die
|
429 |
+
# if the manifest happens to be empty.
|
430 |
+
self.mkpath(base_dir)
|
431 |
+
dir_util.create_tree(base_dir, files, dry_run=self.dry_run)
|
432 |
+
|
433 |
+
# And walk over the list of files, either making a hard link (if
|
434 |
+
# os.link exists) to each one that doesn't already exist in its
|
435 |
+
# corresponding location under 'base_dir', or copying each file
|
436 |
+
# that's out-of-date in 'base_dir'. (Usually, all files will be
|
437 |
+
# out-of-date, because by default we blow away 'base_dir' when
|
438 |
+
# we're done making the distribution archives.)
|
439 |
+
|
440 |
+
if hasattr(os, 'link'): # can make hard links on this system
|
441 |
+
link = 'hard'
|
442 |
+
msg = "making hard links in %s..." % base_dir
|
443 |
+
else: # nope, have to copy
|
444 |
+
link = None
|
445 |
+
msg = "copying files to %s..." % base_dir
|
446 |
+
|
447 |
+
if not files:
|
448 |
+
log.warn("no files to distribute -- empty manifest?")
|
449 |
+
else:
|
450 |
+
log.info(msg)
|
451 |
+
for file in files:
|
452 |
+
if not os.path.isfile(file):
|
453 |
+
log.warn("'%s' not a regular file -- skipping", file)
|
454 |
+
else:
|
455 |
+
dest = os.path.join(base_dir, file)
|
456 |
+
self.copy_file(file, dest, link=link)
|
457 |
+
|
458 |
+
self.distribution.metadata.write_pkg_info(base_dir)
|
459 |
+
|
460 |
+
def make_distribution(self):
|
461 |
+
"""Create the source distribution(s). First, we create the release
|
462 |
+
tree with 'make_release_tree()'; then, we create all required
|
463 |
+
archive files (according to 'self.formats') from the release tree.
|
464 |
+
Finally, we clean up by blowing away the release tree (unless
|
465 |
+
'self.keep_temp' is true). The list of archive files created is
|
466 |
+
stored so it can be retrieved later by 'get_archive_files()'.
|
467 |
+
"""
|
468 |
+
# Don't warn about missing meta-data here -- should be (and is!)
|
469 |
+
# done elsewhere.
|
470 |
+
base_dir = self.distribution.get_fullname()
|
471 |
+
base_name = os.path.join(self.dist_dir, base_dir)
|
472 |
+
|
473 |
+
self.make_release_tree(base_dir, self.filelist.files)
|
474 |
+
archive_files = [] # remember names of files we create
|
475 |
+
# tar archive must be created last to avoid overwrite and remove
|
476 |
+
if 'tar' in self.formats:
|
477 |
+
self.formats.append(self.formats.pop(self.formats.index('tar')))
|
478 |
+
|
479 |
+
for fmt in self.formats:
|
480 |
+
file = self.make_archive(base_name, fmt, base_dir=base_dir,
|
481 |
+
owner=self.owner, group=self.group)
|
482 |
+
archive_files.append(file)
|
483 |
+
self.distribution.dist_files.append(('sdist', '', file))
|
484 |
+
|
485 |
+
self.archive_files = archive_files
|
486 |
+
|
487 |
+
if not self.keep_temp:
|
488 |
+
dir_util.remove_tree(base_dir, dry_run=self.dry_run)
|
489 |
+
|
490 |
+
def get_archive_files(self):
|
491 |
+
"""Return the list of archive files created when the command
|
492 |
+
was run, or None if the command hasn't run yet.
|
493 |
+
"""
|
494 |
+
return self.archive_files
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/config.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.pypirc
|
2 |
+
|
3 |
+
Provides the PyPIRCCommand class, the base class for the command classes
|
4 |
+
that uses .pypirc in the distutils.command package.
|
5 |
+
"""
|
6 |
+
import os
|
7 |
+
from configparser import RawConfigParser
|
8 |
+
|
9 |
+
from distutils.cmd import Command
|
10 |
+
|
11 |
+
DEFAULT_PYPIRC = """\
|
12 |
+
[distutils]
|
13 |
+
index-servers =
|
14 |
+
pypi
|
15 |
+
|
16 |
+
[pypi]
|
17 |
+
username:%s
|
18 |
+
password:%s
|
19 |
+
"""
|
20 |
+
|
21 |
+
class PyPIRCCommand(Command):
|
22 |
+
"""Base command that knows how to handle the .pypirc file
|
23 |
+
"""
|
24 |
+
DEFAULT_REPOSITORY = 'https://upload.pypi.org/legacy/'
|
25 |
+
DEFAULT_REALM = 'pypi'
|
26 |
+
repository = None
|
27 |
+
realm = None
|
28 |
+
|
29 |
+
user_options = [
|
30 |
+
('repository=', 'r',
|
31 |
+
"url of repository [default: %s]" % \
|
32 |
+
DEFAULT_REPOSITORY),
|
33 |
+
('show-response', None,
|
34 |
+
'display full response text from server')]
|
35 |
+
|
36 |
+
boolean_options = ['show-response']
|
37 |
+
|
38 |
+
def _get_rc_file(self):
|
39 |
+
"""Returns rc file path."""
|
40 |
+
return os.path.join(os.path.expanduser('~'), '.pypirc')
|
41 |
+
|
42 |
+
def _store_pypirc(self, username, password):
|
43 |
+
"""Creates a default .pypirc file."""
|
44 |
+
rc = self._get_rc_file()
|
45 |
+
with os.fdopen(os.open(rc, os.O_CREAT | os.O_WRONLY, 0o600), 'w') as f:
|
46 |
+
f.write(DEFAULT_PYPIRC % (username, password))
|
47 |
+
|
48 |
+
def _read_pypirc(self):
|
49 |
+
"""Reads the .pypirc file."""
|
50 |
+
rc = self._get_rc_file()
|
51 |
+
if os.path.exists(rc):
|
52 |
+
self.announce('Using PyPI login from %s' % rc)
|
53 |
+
repository = self.repository or self.DEFAULT_REPOSITORY
|
54 |
+
|
55 |
+
config = RawConfigParser()
|
56 |
+
config.read(rc)
|
57 |
+
sections = config.sections()
|
58 |
+
if 'distutils' in sections:
|
59 |
+
# let's get the list of servers
|
60 |
+
index_servers = config.get('distutils', 'index-servers')
|
61 |
+
_servers = [server.strip() for server in
|
62 |
+
index_servers.split('\n')
|
63 |
+
if server.strip() != '']
|
64 |
+
if _servers == []:
|
65 |
+
# nothing set, let's try to get the default pypi
|
66 |
+
if 'pypi' in sections:
|
67 |
+
_servers = ['pypi']
|
68 |
+
else:
|
69 |
+
# the file is not properly defined, returning
|
70 |
+
# an empty dict
|
71 |
+
return {}
|
72 |
+
for server in _servers:
|
73 |
+
current = {'server': server}
|
74 |
+
current['username'] = config.get(server, 'username')
|
75 |
+
|
76 |
+
# optional params
|
77 |
+
for key, default in (('repository',
|
78 |
+
self.DEFAULT_REPOSITORY),
|
79 |
+
('realm', self.DEFAULT_REALM),
|
80 |
+
('password', None)):
|
81 |
+
if config.has_option(server, key):
|
82 |
+
current[key] = config.get(server, key)
|
83 |
+
else:
|
84 |
+
current[key] = default
|
85 |
+
|
86 |
+
# work around people having "repository" for the "pypi"
|
87 |
+
# section of their config set to the HTTP (rather than
|
88 |
+
# HTTPS) URL
|
89 |
+
if (server == 'pypi' and
|
90 |
+
repository in (self.DEFAULT_REPOSITORY, 'pypi')):
|
91 |
+
current['repository'] = self.DEFAULT_REPOSITORY
|
92 |
+
return current
|
93 |
+
|
94 |
+
if (current['server'] == repository or
|
95 |
+
current['repository'] == repository):
|
96 |
+
return current
|
97 |
+
elif 'server-login' in sections:
|
98 |
+
# old format
|
99 |
+
server = 'server-login'
|
100 |
+
if config.has_option(server, 'repository'):
|
101 |
+
repository = config.get(server, 'repository')
|
102 |
+
else:
|
103 |
+
repository = self.DEFAULT_REPOSITORY
|
104 |
+
return {'username': config.get(server, 'username'),
|
105 |
+
'password': config.get(server, 'password'),
|
106 |
+
'repository': repository,
|
107 |
+
'server': server,
|
108 |
+
'realm': self.DEFAULT_REALM}
|
109 |
+
|
110 |
+
return {}
|
111 |
+
|
112 |
+
def _read_pypi_response(self, response):
|
113 |
+
"""Read and decode a PyPI HTTP response."""
|
114 |
+
import cgi
|
115 |
+
content_type = response.getheader('content-type', 'text/plain')
|
116 |
+
encoding = cgi.parse_header(content_type)[1].get('charset', 'ascii')
|
117 |
+
return response.read().decode(encoding)
|
118 |
+
|
119 |
+
def initialize_options(self):
|
120 |
+
"""Initialize options."""
|
121 |
+
self.repository = None
|
122 |
+
self.realm = None
|
123 |
+
self.show_response = 0
|
124 |
+
|
125 |
+
def finalize_options(self):
|
126 |
+
"""Finalizes options."""
|
127 |
+
if self.repository is None:
|
128 |
+
self.repository = self.DEFAULT_REPOSITORY
|
129 |
+
if self.realm is None:
|
130 |
+
self.realm = self.DEFAULT_REALM
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/core.py
ADDED
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.core
|
2 |
+
|
3 |
+
The only module that needs to be imported to use the Distutils; provides
|
4 |
+
the 'setup' function (which is to be called from the setup script). Also
|
5 |
+
indirectly provides the Distribution and Command classes, although they are
|
6 |
+
really defined in distutils.dist and distutils.cmd.
|
7 |
+
"""
|
8 |
+
|
9 |
+
import os
|
10 |
+
import sys
|
11 |
+
import tokenize
|
12 |
+
|
13 |
+
from distutils.debug import DEBUG
|
14 |
+
from distutils.errors import *
|
15 |
+
|
16 |
+
# Mainly import these so setup scripts can "from distutils.core import" them.
|
17 |
+
from distutils.dist import Distribution
|
18 |
+
from distutils.cmd import Command
|
19 |
+
from distutils.config import PyPIRCCommand
|
20 |
+
from distutils.extension import Extension
|
21 |
+
|
22 |
+
# This is a barebones help message generated displayed when the user
|
23 |
+
# runs the setup script with no arguments at all. More useful help
|
24 |
+
# is generated with various --help options: global help, list commands,
|
25 |
+
# and per-command help.
|
26 |
+
USAGE = """\
|
27 |
+
usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
|
28 |
+
or: %(script)s --help [cmd1 cmd2 ...]
|
29 |
+
or: %(script)s --help-commands
|
30 |
+
or: %(script)s cmd --help
|
31 |
+
"""
|
32 |
+
|
33 |
+
def gen_usage (script_name):
|
34 |
+
script = os.path.basename(script_name)
|
35 |
+
return USAGE % vars()
|
36 |
+
|
37 |
+
|
38 |
+
# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
|
39 |
+
_setup_stop_after = None
|
40 |
+
_setup_distribution = None
|
41 |
+
|
42 |
+
# Legal keyword arguments for the setup() function
|
43 |
+
setup_keywords = ('distclass', 'script_name', 'script_args', 'options',
|
44 |
+
'name', 'version', 'author', 'author_email',
|
45 |
+
'maintainer', 'maintainer_email', 'url', 'license',
|
46 |
+
'description', 'long_description', 'keywords',
|
47 |
+
'platforms', 'classifiers', 'download_url',
|
48 |
+
'requires', 'provides', 'obsoletes',
|
49 |
+
)
|
50 |
+
|
51 |
+
# Legal keyword arguments for the Extension constructor
|
52 |
+
extension_keywords = ('name', 'sources', 'include_dirs',
|
53 |
+
'define_macros', 'undef_macros',
|
54 |
+
'library_dirs', 'libraries', 'runtime_library_dirs',
|
55 |
+
'extra_objects', 'extra_compile_args', 'extra_link_args',
|
56 |
+
'swig_opts', 'export_symbols', 'depends', 'language')
|
57 |
+
|
58 |
+
def setup (**attrs):
|
59 |
+
"""The gateway to the Distutils: do everything your setup script needs
|
60 |
+
to do, in a highly flexible and user-driven way. Briefly: create a
|
61 |
+
Distribution instance; find and parse config files; parse the command
|
62 |
+
line; run each Distutils command found there, customized by the options
|
63 |
+
supplied to 'setup()' (as keyword arguments), in config files, and on
|
64 |
+
the command line.
|
65 |
+
|
66 |
+
The Distribution instance might be an instance of a class supplied via
|
67 |
+
the 'distclass' keyword argument to 'setup'; if no such class is
|
68 |
+
supplied, then the Distribution class (in dist.py) is instantiated.
|
69 |
+
All other arguments to 'setup' (except for 'cmdclass') are used to set
|
70 |
+
attributes of the Distribution instance.
|
71 |
+
|
72 |
+
The 'cmdclass' argument, if supplied, is a dictionary mapping command
|
73 |
+
names to command classes. Each command encountered on the command line
|
74 |
+
will be turned into a command class, which is in turn instantiated; any
|
75 |
+
class found in 'cmdclass' is used in place of the default, which is
|
76 |
+
(for command 'foo_bar') class 'foo_bar' in module
|
77 |
+
'distutils.command.foo_bar'. The command class must provide a
|
78 |
+
'user_options' attribute which is a list of option specifiers for
|
79 |
+
'distutils.fancy_getopt'. Any command-line options between the current
|
80 |
+
and the next command are used to set attributes of the current command
|
81 |
+
object.
|
82 |
+
|
83 |
+
When the entire command-line has been successfully parsed, calls the
|
84 |
+
'run()' method on each command object in turn. This method will be
|
85 |
+
driven entirely by the Distribution object (which each command object
|
86 |
+
has a reference to, thanks to its constructor), and the
|
87 |
+
command-specific options that became attributes of each command
|
88 |
+
object.
|
89 |
+
"""
|
90 |
+
|
91 |
+
global _setup_stop_after, _setup_distribution
|
92 |
+
|
93 |
+
# Determine the distribution class -- either caller-supplied or
|
94 |
+
# our Distribution (see below).
|
95 |
+
klass = attrs.get('distclass')
|
96 |
+
if klass:
|
97 |
+
del attrs['distclass']
|
98 |
+
else:
|
99 |
+
klass = Distribution
|
100 |
+
|
101 |
+
if 'script_name' not in attrs:
|
102 |
+
attrs['script_name'] = os.path.basename(sys.argv[0])
|
103 |
+
if 'script_args' not in attrs:
|
104 |
+
attrs['script_args'] = sys.argv[1:]
|
105 |
+
|
106 |
+
# Create the Distribution instance, using the remaining arguments
|
107 |
+
# (ie. everything except distclass) to initialize it
|
108 |
+
try:
|
109 |
+
_setup_distribution = dist = klass(attrs)
|
110 |
+
except DistutilsSetupError as msg:
|
111 |
+
if 'name' not in attrs:
|
112 |
+
raise SystemExit("error in setup command: %s" % msg)
|
113 |
+
else:
|
114 |
+
raise SystemExit("error in %s setup command: %s" % \
|
115 |
+
(attrs['name'], msg))
|
116 |
+
|
117 |
+
if _setup_stop_after == "init":
|
118 |
+
return dist
|
119 |
+
|
120 |
+
# Find and parse the config file(s): they will override options from
|
121 |
+
# the setup script, but be overridden by the command line.
|
122 |
+
dist.parse_config_files()
|
123 |
+
|
124 |
+
if DEBUG:
|
125 |
+
print("options (after parsing config files):")
|
126 |
+
dist.dump_option_dicts()
|
127 |
+
|
128 |
+
if _setup_stop_after == "config":
|
129 |
+
return dist
|
130 |
+
|
131 |
+
# Parse the command line and override config files; any
|
132 |
+
# command-line errors are the end user's fault, so turn them into
|
133 |
+
# SystemExit to suppress tracebacks.
|
134 |
+
try:
|
135 |
+
ok = dist.parse_command_line()
|
136 |
+
except DistutilsArgError as msg:
|
137 |
+
raise SystemExit(gen_usage(dist.script_name) + "\nerror: %s" % msg)
|
138 |
+
|
139 |
+
if DEBUG:
|
140 |
+
print("options (after parsing command line):")
|
141 |
+
dist.dump_option_dicts()
|
142 |
+
|
143 |
+
if _setup_stop_after == "commandline":
|
144 |
+
return dist
|
145 |
+
|
146 |
+
# And finally, run all the commands found on the command line.
|
147 |
+
if ok:
|
148 |
+
return run_commands(dist)
|
149 |
+
|
150 |
+
return dist
|
151 |
+
|
152 |
+
# setup ()
|
153 |
+
|
154 |
+
|
155 |
+
def run_commands (dist):
|
156 |
+
"""Given a Distribution object run all the commands,
|
157 |
+
raising ``SystemExit`` errors in the case of failure.
|
158 |
+
|
159 |
+
This function assumes that either ``sys.argv`` or ``dist.script_args``
|
160 |
+
is already set accordingly.
|
161 |
+
"""
|
162 |
+
try:
|
163 |
+
dist.run_commands()
|
164 |
+
except KeyboardInterrupt:
|
165 |
+
raise SystemExit("interrupted")
|
166 |
+
except OSError as exc:
|
167 |
+
if DEBUG:
|
168 |
+
sys.stderr.write("error: %s\n" % (exc,))
|
169 |
+
raise
|
170 |
+
else:
|
171 |
+
raise SystemExit("error: %s" % (exc,))
|
172 |
+
|
173 |
+
except (DistutilsError,
|
174 |
+
CCompilerError) as msg:
|
175 |
+
if DEBUG:
|
176 |
+
raise
|
177 |
+
else:
|
178 |
+
raise SystemExit("error: " + str(msg))
|
179 |
+
|
180 |
+
return dist
|
181 |
+
|
182 |
+
|
183 |
+
def run_setup (script_name, script_args=None, stop_after="run"):
|
184 |
+
"""Run a setup script in a somewhat controlled environment, and
|
185 |
+
return the Distribution instance that drives things. This is useful
|
186 |
+
if you need to find out the distribution meta-data (passed as
|
187 |
+
keyword args from 'script' to 'setup()', or the contents of the
|
188 |
+
config files or command-line.
|
189 |
+
|
190 |
+
'script_name' is a file that will be read and run with 'exec()';
|
191 |
+
'sys.argv[0]' will be replaced with 'script' for the duration of the
|
192 |
+
call. 'script_args' is a list of strings; if supplied,
|
193 |
+
'sys.argv[1:]' will be replaced by 'script_args' for the duration of
|
194 |
+
the call.
|
195 |
+
|
196 |
+
'stop_after' tells 'setup()' when to stop processing; possible
|
197 |
+
values:
|
198 |
+
init
|
199 |
+
stop after the Distribution instance has been created and
|
200 |
+
populated with the keyword arguments to 'setup()'
|
201 |
+
config
|
202 |
+
stop after config files have been parsed (and their data
|
203 |
+
stored in the Distribution instance)
|
204 |
+
commandline
|
205 |
+
stop after the command-line ('sys.argv[1:]' or 'script_args')
|
206 |
+
have been parsed (and the data stored in the Distribution)
|
207 |
+
run [default]
|
208 |
+
stop after all commands have been run (the same as if 'setup()'
|
209 |
+
had been called in the usual way
|
210 |
+
|
211 |
+
Returns the Distribution instance, which provides all information
|
212 |
+
used to drive the Distutils.
|
213 |
+
"""
|
214 |
+
if stop_after not in ('init', 'config', 'commandline', 'run'):
|
215 |
+
raise ValueError("invalid value for 'stop_after': %r" % (stop_after,))
|
216 |
+
|
217 |
+
global _setup_stop_after, _setup_distribution
|
218 |
+
_setup_stop_after = stop_after
|
219 |
+
|
220 |
+
save_argv = sys.argv.copy()
|
221 |
+
g = {'__file__': script_name, '__name__': '__main__'}
|
222 |
+
try:
|
223 |
+
try:
|
224 |
+
sys.argv[0] = script_name
|
225 |
+
if script_args is not None:
|
226 |
+
sys.argv[1:] = script_args
|
227 |
+
# tokenize.open supports automatic encoding detection
|
228 |
+
with tokenize.open(script_name) as f:
|
229 |
+
code = f.read().replace(r'\r\n', r'\n')
|
230 |
+
exec(code, g)
|
231 |
+
finally:
|
232 |
+
sys.argv = save_argv
|
233 |
+
_setup_stop_after = None
|
234 |
+
except SystemExit:
|
235 |
+
# Hmm, should we do something if exiting with a non-zero code
|
236 |
+
# (ie. error)?
|
237 |
+
pass
|
238 |
+
|
239 |
+
if _setup_distribution is None:
|
240 |
+
raise RuntimeError(("'distutils.core.setup()' was never called -- "
|
241 |
+
"perhaps '%s' is not a Distutils setup script?") % \
|
242 |
+
script_name)
|
243 |
+
|
244 |
+
# I wonder if the setup script's namespace -- g and l -- would be of
|
245 |
+
# any interest to callers?
|
246 |
+
#print "_setup_distribution:", _setup_distribution
|
247 |
+
return _setup_distribution
|
248 |
+
|
249 |
+
# run_setup ()
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/cygwinccompiler.py
ADDED
@@ -0,0 +1,425 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.cygwinccompiler
|
2 |
+
|
3 |
+
Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
|
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 |
+
# problems:
|
10 |
+
#
|
11 |
+
# * if you use a msvc compiled python version (1.5.2)
|
12 |
+
# 1. you have to insert a __GNUC__ section in its config.h
|
13 |
+
# 2. you have to generate an import library for its dll
|
14 |
+
# - create a def-file for python??.dll
|
15 |
+
# - create an import library using
|
16 |
+
# dlltool --dllname python15.dll --def python15.def \
|
17 |
+
# --output-lib libpython15.a
|
18 |
+
#
|
19 |
+
# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
|
20 |
+
#
|
21 |
+
# * We put export_symbols in a def-file, and don't use
|
22 |
+
# --export-all-symbols because it doesn't worked reliable in some
|
23 |
+
# tested configurations. And because other windows compilers also
|
24 |
+
# need their symbols specified this no serious problem.
|
25 |
+
#
|
26 |
+
# tested configurations:
|
27 |
+
#
|
28 |
+
# * cygwin gcc 2.91.57/ld 2.9.4/dllwrap 0.2.4 works
|
29 |
+
# (after patching python's config.h and for C++ some other include files)
|
30 |
+
# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
|
31 |
+
# * mingw32 gcc 2.95.2/ld 2.9.4/dllwrap 0.2.4 works
|
32 |
+
# (ld doesn't support -shared, so we use dllwrap)
|
33 |
+
# * cygwin gcc 2.95.2/ld 2.10.90/dllwrap 2.10.90 works now
|
34 |
+
# - its dllwrap doesn't work, there is a bug in binutils 2.10.90
|
35 |
+
# see also http://sources.redhat.com/ml/cygwin/2000-06/msg01274.html
|
36 |
+
# - using gcc -mdll instead dllwrap doesn't work without -static because
|
37 |
+
# it tries to link against dlls instead their import libraries. (If
|
38 |
+
# it finds the dll first.)
|
39 |
+
# By specifying -static we force ld to link against the import libraries,
|
40 |
+
# this is windows standard and there are normally not the necessary symbols
|
41 |
+
# in the dlls.
|
42 |
+
# *** only the version of June 2000 shows these problems
|
43 |
+
# * cygwin gcc 3.2/ld 2.13.90 works
|
44 |
+
# (ld supports -shared)
|
45 |
+
# * mingw gcc 3.2/ld 2.13 works
|
46 |
+
# (ld supports -shared)
|
47 |
+
# * llvm-mingw with Clang 11 works
|
48 |
+
# (lld supports -shared)
|
49 |
+
|
50 |
+
import os
|
51 |
+
import sys
|
52 |
+
import copy
|
53 |
+
from subprocess import Popen, PIPE, check_output
|
54 |
+
import re
|
55 |
+
|
56 |
+
import distutils.version
|
57 |
+
from distutils.unixccompiler import UnixCCompiler
|
58 |
+
from distutils.file_util import write_file
|
59 |
+
from distutils.errors import (DistutilsExecError, CCompilerError,
|
60 |
+
CompileError, UnknownFileError)
|
61 |
+
from distutils.version import LooseVersion
|
62 |
+
from distutils.spawn import find_executable
|
63 |
+
|
64 |
+
def get_msvcr():
|
65 |
+
"""Include the appropriate MSVC runtime library if Python was built
|
66 |
+
with MSVC 7.0 or later.
|
67 |
+
"""
|
68 |
+
msc_pos = sys.version.find('MSC v.')
|
69 |
+
if msc_pos != -1:
|
70 |
+
msc_ver = sys.version[msc_pos+6:msc_pos+10]
|
71 |
+
if msc_ver == '1300':
|
72 |
+
# MSVC 7.0
|
73 |
+
return ['msvcr70']
|
74 |
+
elif msc_ver == '1310':
|
75 |
+
# MSVC 7.1
|
76 |
+
return ['msvcr71']
|
77 |
+
elif msc_ver == '1400':
|
78 |
+
# VS2005 / MSVC 8.0
|
79 |
+
return ['msvcr80']
|
80 |
+
elif msc_ver == '1500':
|
81 |
+
# VS2008 / MSVC 9.0
|
82 |
+
return ['msvcr90']
|
83 |
+
elif msc_ver == '1600':
|
84 |
+
# VS2010 / MSVC 10.0
|
85 |
+
return ['msvcr100']
|
86 |
+
elif msc_ver == '1700':
|
87 |
+
# VS2012 / MSVC 11.0
|
88 |
+
return ['msvcr110']
|
89 |
+
elif msc_ver == '1800':
|
90 |
+
# VS2013 / MSVC 12.0
|
91 |
+
return ['msvcr120']
|
92 |
+
elif 1900 <= int(msc_ver) < 2000:
|
93 |
+
# VS2015 / MSVC 14.0
|
94 |
+
return ['ucrt', 'vcruntime140']
|
95 |
+
else:
|
96 |
+
raise ValueError("Unknown MS Compiler version %s " % msc_ver)
|
97 |
+
|
98 |
+
|
99 |
+
class CygwinCCompiler(UnixCCompiler):
|
100 |
+
""" Handles the Cygwin port of the GNU C compiler to Windows.
|
101 |
+
"""
|
102 |
+
compiler_type = 'cygwin'
|
103 |
+
obj_extension = ".o"
|
104 |
+
static_lib_extension = ".a"
|
105 |
+
shared_lib_extension = ".dll"
|
106 |
+
static_lib_format = "lib%s%s"
|
107 |
+
shared_lib_format = "%s%s"
|
108 |
+
exe_extension = ".exe"
|
109 |
+
|
110 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
111 |
+
|
112 |
+
UnixCCompiler.__init__(self, verbose, dry_run, force)
|
113 |
+
|
114 |
+
status, details = check_config_h()
|
115 |
+
self.debug_print("Python's GCC status: %s (details: %s)" %
|
116 |
+
(status, details))
|
117 |
+
if status is not CONFIG_H_OK:
|
118 |
+
self.warn(
|
119 |
+
"Python's pyconfig.h doesn't seem to support your compiler. "
|
120 |
+
"Reason: %s. "
|
121 |
+
"Compiling may fail because of undefined preprocessor macros."
|
122 |
+
% details)
|
123 |
+
|
124 |
+
self.cc = os.environ.get('CC', 'gcc')
|
125 |
+
self.cxx = os.environ.get('CXX', 'g++')
|
126 |
+
|
127 |
+
if ('gcc' in self.cc): # Start gcc workaround
|
128 |
+
self.gcc_version, self.ld_version, self.dllwrap_version = \
|
129 |
+
get_versions()
|
130 |
+
self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
|
131 |
+
(self.gcc_version,
|
132 |
+
self.ld_version,
|
133 |
+
self.dllwrap_version) )
|
134 |
+
|
135 |
+
# ld_version >= "2.10.90" and < "2.13" should also be able to use
|
136 |
+
# gcc -mdll instead of dllwrap
|
137 |
+
# Older dllwraps had own version numbers, newer ones use the
|
138 |
+
# same as the rest of binutils ( also ld )
|
139 |
+
# dllwrap 2.10.90 is buggy
|
140 |
+
if self.ld_version >= "2.10.90":
|
141 |
+
self.linker_dll = self.cc
|
142 |
+
else:
|
143 |
+
self.linker_dll = "dllwrap"
|
144 |
+
|
145 |
+
# ld_version >= "2.13" support -shared so use it instead of
|
146 |
+
# -mdll -static
|
147 |
+
if self.ld_version >= "2.13":
|
148 |
+
shared_option = "-shared"
|
149 |
+
else:
|
150 |
+
shared_option = "-mdll -static"
|
151 |
+
else: # Assume linker is up to date
|
152 |
+
self.linker_dll = self.cc
|
153 |
+
shared_option = "-shared"
|
154 |
+
|
155 |
+
self.set_executables(compiler='%s -mcygwin -O -Wall' % self.cc,
|
156 |
+
compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc,
|
157 |
+
compiler_cxx='%s -mcygwin -O -Wall' % self.cxx,
|
158 |
+
linker_exe='%s -mcygwin' % self.cc,
|
159 |
+
linker_so=('%s -mcygwin %s' %
|
160 |
+
(self.linker_dll, shared_option)))
|
161 |
+
|
162 |
+
# cygwin and mingw32 need different sets of libraries
|
163 |
+
if ('gcc' in self.cc and self.gcc_version == "2.91.57"):
|
164 |
+
# cygwin shouldn't need msvcrt, but without the dlls will crash
|
165 |
+
# (gcc version 2.91.57) -- perhaps something about initialization
|
166 |
+
self.dll_libraries=["msvcrt"]
|
167 |
+
self.warn(
|
168 |
+
"Consider upgrading to a newer version of gcc")
|
169 |
+
else:
|
170 |
+
# Include the appropriate MSVC runtime library if Python was built
|
171 |
+
# with MSVC 7.0 or later.
|
172 |
+
self.dll_libraries = get_msvcr()
|
173 |
+
|
174 |
+
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
|
175 |
+
"""Compiles the source by spawning GCC and windres if needed."""
|
176 |
+
if ext == '.rc' or ext == '.res':
|
177 |
+
# gcc needs '.res' and '.rc' compiled to object files !!!
|
178 |
+
try:
|
179 |
+
self.spawn(["windres", "-i", src, "-o", obj])
|
180 |
+
except DistutilsExecError as msg:
|
181 |
+
raise CompileError(msg)
|
182 |
+
else: # for other files use the C-compiler
|
183 |
+
try:
|
184 |
+
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
|
185 |
+
extra_postargs)
|
186 |
+
except DistutilsExecError as msg:
|
187 |
+
raise CompileError(msg)
|
188 |
+
|
189 |
+
def link(self, target_desc, objects, output_filename, output_dir=None,
|
190 |
+
libraries=None, library_dirs=None, runtime_library_dirs=None,
|
191 |
+
export_symbols=None, debug=0, extra_preargs=None,
|
192 |
+
extra_postargs=None, build_temp=None, target_lang=None):
|
193 |
+
"""Link the objects."""
|
194 |
+
# use separate copies, so we can modify the lists
|
195 |
+
extra_preargs = copy.copy(extra_preargs or [])
|
196 |
+
libraries = copy.copy(libraries or [])
|
197 |
+
objects = copy.copy(objects or [])
|
198 |
+
|
199 |
+
# Additional libraries
|
200 |
+
libraries.extend(self.dll_libraries)
|
201 |
+
|
202 |
+
# handle export symbols by creating a def-file
|
203 |
+
# with executables this only works with gcc/ld as linker
|
204 |
+
if ((export_symbols is not None) and
|
205 |
+
(target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
206 |
+
# (The linker doesn't do anything if output is up-to-date.
|
207 |
+
# So it would probably better to check if we really need this,
|
208 |
+
# but for this we had to insert some unchanged parts of
|
209 |
+
# UnixCCompiler, and this is not what we want.)
|
210 |
+
|
211 |
+
# we want to put some files in the same directory as the
|
212 |
+
# object files are, build_temp doesn't help much
|
213 |
+
# where are the object files
|
214 |
+
temp_dir = os.path.dirname(objects[0])
|
215 |
+
# name of dll to give the helper files the same base name
|
216 |
+
(dll_name, dll_extension) = os.path.splitext(
|
217 |
+
os.path.basename(output_filename))
|
218 |
+
|
219 |
+
# generate the filenames for these files
|
220 |
+
def_file = os.path.join(temp_dir, dll_name + ".def")
|
221 |
+
lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
|
222 |
+
|
223 |
+
# Generate .def file
|
224 |
+
contents = [
|
225 |
+
"LIBRARY %s" % os.path.basename(output_filename),
|
226 |
+
"EXPORTS"]
|
227 |
+
for sym in export_symbols:
|
228 |
+
contents.append(sym)
|
229 |
+
self.execute(write_file, (def_file, contents),
|
230 |
+
"writing %s" % def_file)
|
231 |
+
|
232 |
+
# next add options for def-file and to creating import libraries
|
233 |
+
|
234 |
+
# dllwrap uses different options than gcc/ld
|
235 |
+
if self.linker_dll == "dllwrap":
|
236 |
+
extra_preargs.extend(["--output-lib", lib_file])
|
237 |
+
# for dllwrap we have to use a special option
|
238 |
+
extra_preargs.extend(["--def", def_file])
|
239 |
+
# we use gcc/ld here and can be sure ld is >= 2.9.10
|
240 |
+
else:
|
241 |
+
# doesn't work: bfd_close build\...\libfoo.a: Invalid operation
|
242 |
+
#extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
|
243 |
+
# for gcc/ld the def-file is specified as any object files
|
244 |
+
objects.append(def_file)
|
245 |
+
|
246 |
+
#end: if ((export_symbols is not None) and
|
247 |
+
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
248 |
+
|
249 |
+
# who wants symbols and a many times larger output file
|
250 |
+
# should explicitly switch the debug mode on
|
251 |
+
# otherwise we let dllwrap/ld strip the output file
|
252 |
+
# (On my machine: 10KiB < stripped_file < ??100KiB
|
253 |
+
# unstripped_file = stripped_file + XXX KiB
|
254 |
+
# ( XXX=254 for a typical python extension))
|
255 |
+
if not debug:
|
256 |
+
extra_preargs.append("-s")
|
257 |
+
|
258 |
+
UnixCCompiler.link(self, target_desc, objects, output_filename,
|
259 |
+
output_dir, libraries, library_dirs,
|
260 |
+
runtime_library_dirs,
|
261 |
+
None, # export_symbols, we do this in our def-file
|
262 |
+
debug, extra_preargs, extra_postargs, build_temp,
|
263 |
+
target_lang)
|
264 |
+
|
265 |
+
# -- Miscellaneous methods -----------------------------------------
|
266 |
+
|
267 |
+
def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
|
268 |
+
"""Adds supports for rc and res files."""
|
269 |
+
if output_dir is None:
|
270 |
+
output_dir = ''
|
271 |
+
obj_names = []
|
272 |
+
for src_name in source_filenames:
|
273 |
+
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
274 |
+
base, ext = os.path.splitext(os.path.normcase(src_name))
|
275 |
+
if ext not in (self.src_extensions + ['.rc','.res']):
|
276 |
+
raise UnknownFileError("unknown file type '%s' (from '%s')" % \
|
277 |
+
(ext, src_name))
|
278 |
+
if strip_dir:
|
279 |
+
base = os.path.basename (base)
|
280 |
+
if ext in ('.res', '.rc'):
|
281 |
+
# these need to be compiled to object files
|
282 |
+
obj_names.append (os.path.join(output_dir,
|
283 |
+
base + ext + self.obj_extension))
|
284 |
+
else:
|
285 |
+
obj_names.append (os.path.join(output_dir,
|
286 |
+
base + self.obj_extension))
|
287 |
+
return obj_names
|
288 |
+
|
289 |
+
# the same as cygwin plus some additional parameters
|
290 |
+
class Mingw32CCompiler(CygwinCCompiler):
|
291 |
+
""" Handles the Mingw32 port of the GNU C compiler to Windows.
|
292 |
+
"""
|
293 |
+
compiler_type = 'mingw32'
|
294 |
+
|
295 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
296 |
+
|
297 |
+
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
|
298 |
+
|
299 |
+
# ld_version >= "2.13" support -shared so use it instead of
|
300 |
+
# -mdll -static
|
301 |
+
if ('gcc' in self.cc and self.ld_version < "2.13"):
|
302 |
+
shared_option = "-mdll -static"
|
303 |
+
else:
|
304 |
+
shared_option = "-shared"
|
305 |
+
|
306 |
+
# A real mingw32 doesn't need to specify a different entry point,
|
307 |
+
# but cygwin 2.91.57 in no-cygwin-mode needs it.
|
308 |
+
if ('gcc' in self.cc and self.gcc_version <= "2.91.57"):
|
309 |
+
entry_point = '--entry _DllMain@12'
|
310 |
+
else:
|
311 |
+
entry_point = ''
|
312 |
+
|
313 |
+
if is_cygwincc(self.cc):
|
314 |
+
raise CCompilerError(
|
315 |
+
'Cygwin gcc cannot be used with --compiler=mingw32')
|
316 |
+
|
317 |
+
self.set_executables(compiler='%s -O -Wall' % self.cc,
|
318 |
+
compiler_so='%s -mdll -O -Wall' % self.cc,
|
319 |
+
compiler_cxx='%s -O -Wall' % self.cxx,
|
320 |
+
linker_exe='%s' % self.cc,
|
321 |
+
linker_so='%s %s %s'
|
322 |
+
% (self.linker_dll, shared_option,
|
323 |
+
entry_point))
|
324 |
+
# Maybe we should also append -mthreads, but then the finished
|
325 |
+
# dlls need another dll (mingwm10.dll see Mingw32 docs)
|
326 |
+
# (-mthreads: Support thread-safe exception handling on `Mingw32')
|
327 |
+
|
328 |
+
# no additional libraries needed
|
329 |
+
self.dll_libraries=[]
|
330 |
+
|
331 |
+
# Include the appropriate MSVC runtime library if Python was built
|
332 |
+
# with MSVC 7.0 or later.
|
333 |
+
self.dll_libraries = get_msvcr()
|
334 |
+
|
335 |
+
# Because these compilers aren't configured in Python's pyconfig.h file by
|
336 |
+
# default, we should at least warn the user if he is using an unmodified
|
337 |
+
# version.
|
338 |
+
|
339 |
+
CONFIG_H_OK = "ok"
|
340 |
+
CONFIG_H_NOTOK = "not ok"
|
341 |
+
CONFIG_H_UNCERTAIN = "uncertain"
|
342 |
+
|
343 |
+
def check_config_h():
|
344 |
+
"""Check if the current Python installation appears amenable to building
|
345 |
+
extensions with GCC.
|
346 |
+
|
347 |
+
Returns a tuple (status, details), where 'status' is one of the following
|
348 |
+
constants:
|
349 |
+
|
350 |
+
- CONFIG_H_OK: all is well, go ahead and compile
|
351 |
+
- CONFIG_H_NOTOK: doesn't look good
|
352 |
+
- CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h
|
353 |
+
|
354 |
+
'details' is a human-readable string explaining the situation.
|
355 |
+
|
356 |
+
Note there are two ways to conclude "OK": either 'sys.version' contains
|
357 |
+
the string "GCC" (implying that this Python was built with GCC), or the
|
358 |
+
installed "pyconfig.h" contains the string "__GNUC__".
|
359 |
+
"""
|
360 |
+
|
361 |
+
# XXX since this function also checks sys.version, it's not strictly a
|
362 |
+
# "pyconfig.h" check -- should probably be renamed...
|
363 |
+
|
364 |
+
from distutils import sysconfig
|
365 |
+
|
366 |
+
# if sys.version contains GCC then python was compiled with GCC, and the
|
367 |
+
# pyconfig.h file should be OK
|
368 |
+
if "GCC" in sys.version:
|
369 |
+
return CONFIG_H_OK, "sys.version mentions 'GCC'"
|
370 |
+
|
371 |
+
# Clang would also work
|
372 |
+
if "Clang" in sys.version:
|
373 |
+
return CONFIG_H_OK, "sys.version mentions 'Clang'"
|
374 |
+
|
375 |
+
# let's see if __GNUC__ is mentioned in python.h
|
376 |
+
fn = sysconfig.get_config_h_filename()
|
377 |
+
try:
|
378 |
+
config_h = open(fn)
|
379 |
+
try:
|
380 |
+
if "__GNUC__" in config_h.read():
|
381 |
+
return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn
|
382 |
+
else:
|
383 |
+
return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn
|
384 |
+
finally:
|
385 |
+
config_h.close()
|
386 |
+
except OSError as exc:
|
387 |
+
return (CONFIG_H_UNCERTAIN,
|
388 |
+
"couldn't read '%s': %s" % (fn, exc.strerror))
|
389 |
+
|
390 |
+
RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
|
391 |
+
|
392 |
+
def _find_exe_version(cmd):
|
393 |
+
"""Find the version of an executable by running `cmd` in the shell.
|
394 |
+
|
395 |
+
If the command is not found, or the output does not match
|
396 |
+
`RE_VERSION`, returns None.
|
397 |
+
"""
|
398 |
+
executable = cmd.split()[0]
|
399 |
+
if find_executable(executable) is None:
|
400 |
+
return None
|
401 |
+
out = Popen(cmd, shell=True, stdout=PIPE).stdout
|
402 |
+
try:
|
403 |
+
out_string = out.read()
|
404 |
+
finally:
|
405 |
+
out.close()
|
406 |
+
result = RE_VERSION.search(out_string)
|
407 |
+
if result is None:
|
408 |
+
return None
|
409 |
+
# LooseVersion works with strings; decode
|
410 |
+
ver_str = result.group(1).decode()
|
411 |
+
with distutils.version.suppress_known_deprecation():
|
412 |
+
return LooseVersion(ver_str)
|
413 |
+
|
414 |
+
def get_versions():
|
415 |
+
""" Try to find out the versions of gcc, ld and dllwrap.
|
416 |
+
|
417 |
+
If not possible it returns None for it.
|
418 |
+
"""
|
419 |
+
commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
|
420 |
+
return tuple([_find_exe_version(cmd) for cmd in commands])
|
421 |
+
|
422 |
+
def is_cygwincc(cc):
|
423 |
+
'''Try to determine if the compiler that would be used is from cygwin.'''
|
424 |
+
out_string = check_output([cc, '-dumpmachine'])
|
425 |
+
return out_string.strip().endswith(b'cygwin')
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/debug.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
# If DISTUTILS_DEBUG is anything other than the empty string, we run in
|
4 |
+
# debug mode.
|
5 |
+
DEBUG = os.environ.get('DISTUTILS_DEBUG')
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/dep_util.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.dep_util
|
2 |
+
|
3 |
+
Utility functions for simple, timestamp-based dependency of files
|
4 |
+
and groups of files; also, function based entirely on such
|
5 |
+
timestamp dependency analysis."""
|
6 |
+
|
7 |
+
import os
|
8 |
+
from distutils.errors import DistutilsFileError
|
9 |
+
|
10 |
+
|
11 |
+
def newer (source, target):
|
12 |
+
"""Return true if 'source' exists and is more recently modified than
|
13 |
+
'target', or if 'source' exists and 'target' doesn't. Return false if
|
14 |
+
both exist and 'target' is the same age or younger than 'source'.
|
15 |
+
Raise DistutilsFileError if 'source' does not exist.
|
16 |
+
"""
|
17 |
+
if not os.path.exists(source):
|
18 |
+
raise DistutilsFileError("file '%s' does not exist" %
|
19 |
+
os.path.abspath(source))
|
20 |
+
if not os.path.exists(target):
|
21 |
+
return 1
|
22 |
+
|
23 |
+
from stat import ST_MTIME
|
24 |
+
mtime1 = os.stat(source)[ST_MTIME]
|
25 |
+
mtime2 = os.stat(target)[ST_MTIME]
|
26 |
+
|
27 |
+
return mtime1 > mtime2
|
28 |
+
|
29 |
+
# newer ()
|
30 |
+
|
31 |
+
|
32 |
+
def newer_pairwise (sources, targets):
|
33 |
+
"""Walk two filename lists in parallel, testing if each source is newer
|
34 |
+
than its corresponding target. Return a pair of lists (sources,
|
35 |
+
targets) where source is newer than target, according to the semantics
|
36 |
+
of 'newer()'.
|
37 |
+
"""
|
38 |
+
if len(sources) != len(targets):
|
39 |
+
raise ValueError("'sources' and 'targets' must be same length")
|
40 |
+
|
41 |
+
# build a pair of lists (sources, targets) where source is newer
|
42 |
+
n_sources = []
|
43 |
+
n_targets = []
|
44 |
+
for i in range(len(sources)):
|
45 |
+
if newer(sources[i], targets[i]):
|
46 |
+
n_sources.append(sources[i])
|
47 |
+
n_targets.append(targets[i])
|
48 |
+
|
49 |
+
return (n_sources, n_targets)
|
50 |
+
|
51 |
+
# newer_pairwise ()
|
52 |
+
|
53 |
+
|
54 |
+
def newer_group (sources, target, missing='error'):
|
55 |
+
"""Return true if 'target' is out-of-date with respect to any file
|
56 |
+
listed in 'sources'. In other words, if 'target' exists and is newer
|
57 |
+
than every file in 'sources', return false; otherwise return true.
|
58 |
+
'missing' controls what we do when a source file is missing; the
|
59 |
+
default ("error") is to blow up with an OSError from inside 'stat()';
|
60 |
+
if it is "ignore", we silently drop any missing source files; if it is
|
61 |
+
"newer", any missing source files make us assume that 'target' is
|
62 |
+
out-of-date (this is handy in "dry-run" mode: it'll make you pretend to
|
63 |
+
carry out commands that wouldn't work because inputs are missing, but
|
64 |
+
that doesn't matter because you're not actually going to run the
|
65 |
+
commands).
|
66 |
+
"""
|
67 |
+
# If the target doesn't even exist, then it's definitely out-of-date.
|
68 |
+
if not os.path.exists(target):
|
69 |
+
return 1
|
70 |
+
|
71 |
+
# Otherwise we have to find out the hard way: if *any* source file
|
72 |
+
# is more recent than 'target', then 'target' is out-of-date and
|
73 |
+
# we can immediately return true. If we fall through to the end
|
74 |
+
# of the loop, then 'target' is up-to-date and we return false.
|
75 |
+
from stat import ST_MTIME
|
76 |
+
target_mtime = os.stat(target)[ST_MTIME]
|
77 |
+
for source in sources:
|
78 |
+
if not os.path.exists(source):
|
79 |
+
if missing == 'error': # blow up when we stat() the file
|
80 |
+
pass
|
81 |
+
elif missing == 'ignore': # missing source dropped from
|
82 |
+
continue # target's dependency list
|
83 |
+
elif missing == 'newer': # missing source means target is
|
84 |
+
return 1 # out-of-date
|
85 |
+
|
86 |
+
source_mtime = os.stat(source)[ST_MTIME]
|
87 |
+
if source_mtime > target_mtime:
|
88 |
+
return 1
|
89 |
+
else:
|
90 |
+
return 0
|
91 |
+
|
92 |
+
# newer_group ()
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/dir_util.py
ADDED
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.dir_util
|
2 |
+
|
3 |
+
Utility functions for manipulating directories and directory trees."""
|
4 |
+
|
5 |
+
import os
|
6 |
+
import errno
|
7 |
+
from distutils.errors import DistutilsFileError, DistutilsInternalError
|
8 |
+
from distutils import log
|
9 |
+
|
10 |
+
# cache for by mkpath() -- in addition to cheapening redundant calls,
|
11 |
+
# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
|
12 |
+
_path_created = {}
|
13 |
+
|
14 |
+
# I don't use os.makedirs because a) it's new to Python 1.5.2, and
|
15 |
+
# b) it blows up if the directory already exists (I want to silently
|
16 |
+
# succeed in that case).
|
17 |
+
def mkpath(name, mode=0o777, verbose=1, dry_run=0):
|
18 |
+
"""Create a directory and any missing ancestor directories.
|
19 |
+
|
20 |
+
If the directory already exists (or if 'name' is the empty string, which
|
21 |
+
means the current directory, which of course exists), then do nothing.
|
22 |
+
Raise DistutilsFileError if unable to create some directory along the way
|
23 |
+
(eg. some sub-path exists, but is a file rather than a directory).
|
24 |
+
If 'verbose' is true, print a one-line summary of each mkdir to stdout.
|
25 |
+
Return the list of directories actually created.
|
26 |
+
"""
|
27 |
+
|
28 |
+
global _path_created
|
29 |
+
|
30 |
+
# Detect a common bug -- name is None
|
31 |
+
if not isinstance(name, str):
|
32 |
+
raise DistutilsInternalError(
|
33 |
+
"mkpath: 'name' must be a string (got %r)" % (name,))
|
34 |
+
|
35 |
+
# XXX what's the better way to handle verbosity? print as we create
|
36 |
+
# each directory in the path (the current behaviour), or only announce
|
37 |
+
# the creation of the whole path? (quite easy to do the latter since
|
38 |
+
# we're not using a recursive algorithm)
|
39 |
+
|
40 |
+
name = os.path.normpath(name)
|
41 |
+
created_dirs = []
|
42 |
+
if os.path.isdir(name) or name == '':
|
43 |
+
return created_dirs
|
44 |
+
if _path_created.get(os.path.abspath(name)):
|
45 |
+
return created_dirs
|
46 |
+
|
47 |
+
(head, tail) = os.path.split(name)
|
48 |
+
tails = [tail] # stack of lone dirs to create
|
49 |
+
|
50 |
+
while head and tail and not os.path.isdir(head):
|
51 |
+
(head, tail) = os.path.split(head)
|
52 |
+
tails.insert(0, tail) # push next higher dir onto stack
|
53 |
+
|
54 |
+
# now 'head' contains the deepest directory that already exists
|
55 |
+
# (that is, the child of 'head' in 'name' is the highest directory
|
56 |
+
# that does *not* exist)
|
57 |
+
for d in tails:
|
58 |
+
#print "head = %s, d = %s: " % (head, d),
|
59 |
+
head = os.path.join(head, d)
|
60 |
+
abs_head = os.path.abspath(head)
|
61 |
+
|
62 |
+
if _path_created.get(abs_head):
|
63 |
+
continue
|
64 |
+
|
65 |
+
if verbose >= 1:
|
66 |
+
log.info("creating %s", head)
|
67 |
+
|
68 |
+
if not dry_run:
|
69 |
+
try:
|
70 |
+
os.mkdir(head, mode)
|
71 |
+
except OSError as exc:
|
72 |
+
if not (exc.errno == errno.EEXIST and os.path.isdir(head)):
|
73 |
+
raise DistutilsFileError(
|
74 |
+
"could not create '%s': %s" % (head, exc.args[-1]))
|
75 |
+
created_dirs.append(head)
|
76 |
+
|
77 |
+
_path_created[abs_head] = 1
|
78 |
+
return created_dirs
|
79 |
+
|
80 |
+
def create_tree(base_dir, files, mode=0o777, verbose=1, dry_run=0):
|
81 |
+
"""Create all the empty directories under 'base_dir' needed to put 'files'
|
82 |
+
there.
|
83 |
+
|
84 |
+
'base_dir' is just the name of a directory which doesn't necessarily
|
85 |
+
exist yet; 'files' is a list of filenames to be interpreted relative to
|
86 |
+
'base_dir'. 'base_dir' + the directory portion of every file in 'files'
|
87 |
+
will be created if it doesn't already exist. 'mode', 'verbose' and
|
88 |
+
'dry_run' flags are as for 'mkpath()'.
|
89 |
+
"""
|
90 |
+
# First get the list of directories to create
|
91 |
+
need_dir = set()
|
92 |
+
for file in files:
|
93 |
+
need_dir.add(os.path.join(base_dir, os.path.dirname(file)))
|
94 |
+
|
95 |
+
# Now create them
|
96 |
+
for dir in sorted(need_dir):
|
97 |
+
mkpath(dir, mode, verbose=verbose, dry_run=dry_run)
|
98 |
+
|
99 |
+
def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
|
100 |
+
preserve_symlinks=0, update=0, verbose=1, dry_run=0):
|
101 |
+
"""Copy an entire directory tree 'src' to a new location 'dst'.
|
102 |
+
|
103 |
+
Both 'src' and 'dst' must be directory names. If 'src' is not a
|
104 |
+
directory, raise DistutilsFileError. If 'dst' does not exist, it is
|
105 |
+
created with 'mkpath()'. The end result of the copy is that every
|
106 |
+
file in 'src' is copied to 'dst', and directories under 'src' are
|
107 |
+
recursively copied to 'dst'. Return the list of files that were
|
108 |
+
copied or might have been copied, using their output name. The
|
109 |
+
return value is unaffected by 'update' or 'dry_run': it is simply
|
110 |
+
the list of all files under 'src', with the names changed to be
|
111 |
+
under 'dst'.
|
112 |
+
|
113 |
+
'preserve_mode' and 'preserve_times' are the same as for
|
114 |
+
'copy_file'; note that they only apply to regular files, not to
|
115 |
+
directories. If 'preserve_symlinks' is true, symlinks will be
|
116 |
+
copied as symlinks (on platforms that support them!); otherwise
|
117 |
+
(the default), the destination of the symlink will be copied.
|
118 |
+
'update' and 'verbose' are the same as for 'copy_file'.
|
119 |
+
"""
|
120 |
+
from distutils.file_util import copy_file
|
121 |
+
|
122 |
+
if not dry_run and not os.path.isdir(src):
|
123 |
+
raise DistutilsFileError(
|
124 |
+
"cannot copy tree '%s': not a directory" % src)
|
125 |
+
try:
|
126 |
+
names = os.listdir(src)
|
127 |
+
except OSError as e:
|
128 |
+
if dry_run:
|
129 |
+
names = []
|
130 |
+
else:
|
131 |
+
raise DistutilsFileError(
|
132 |
+
"error listing files in '%s': %s" % (src, e.strerror))
|
133 |
+
|
134 |
+
if not dry_run:
|
135 |
+
mkpath(dst, verbose=verbose)
|
136 |
+
|
137 |
+
outputs = []
|
138 |
+
|
139 |
+
for n in names:
|
140 |
+
src_name = os.path.join(src, n)
|
141 |
+
dst_name = os.path.join(dst, n)
|
142 |
+
|
143 |
+
if n.startswith('.nfs'):
|
144 |
+
# skip NFS rename files
|
145 |
+
continue
|
146 |
+
|
147 |
+
if preserve_symlinks and os.path.islink(src_name):
|
148 |
+
link_dest = os.readlink(src_name)
|
149 |
+
if verbose >= 1:
|
150 |
+
log.info("linking %s -> %s", dst_name, link_dest)
|
151 |
+
if not dry_run:
|
152 |
+
os.symlink(link_dest, dst_name)
|
153 |
+
outputs.append(dst_name)
|
154 |
+
|
155 |
+
elif os.path.isdir(src_name):
|
156 |
+
outputs.extend(
|
157 |
+
copy_tree(src_name, dst_name, preserve_mode,
|
158 |
+
preserve_times, preserve_symlinks, update,
|
159 |
+
verbose=verbose, dry_run=dry_run))
|
160 |
+
else:
|
161 |
+
copy_file(src_name, dst_name, preserve_mode,
|
162 |
+
preserve_times, update, verbose=verbose,
|
163 |
+
dry_run=dry_run)
|
164 |
+
outputs.append(dst_name)
|
165 |
+
|
166 |
+
return outputs
|
167 |
+
|
168 |
+
def _build_cmdtuple(path, cmdtuples):
|
169 |
+
"""Helper for remove_tree()."""
|
170 |
+
for f in os.listdir(path):
|
171 |
+
real_f = os.path.join(path,f)
|
172 |
+
if os.path.isdir(real_f) and not os.path.islink(real_f):
|
173 |
+
_build_cmdtuple(real_f, cmdtuples)
|
174 |
+
else:
|
175 |
+
cmdtuples.append((os.remove, real_f))
|
176 |
+
cmdtuples.append((os.rmdir, path))
|
177 |
+
|
178 |
+
def remove_tree(directory, verbose=1, dry_run=0):
|
179 |
+
"""Recursively remove an entire directory tree.
|
180 |
+
|
181 |
+
Any errors are ignored (apart from being reported to stdout if 'verbose'
|
182 |
+
is true).
|
183 |
+
"""
|
184 |
+
global _path_created
|
185 |
+
|
186 |
+
if verbose >= 1:
|
187 |
+
log.info("removing '%s' (and everything under it)", directory)
|
188 |
+
if dry_run:
|
189 |
+
return
|
190 |
+
cmdtuples = []
|
191 |
+
_build_cmdtuple(directory, cmdtuples)
|
192 |
+
for cmd in cmdtuples:
|
193 |
+
try:
|
194 |
+
cmd[0](cmd[1])
|
195 |
+
# remove dir from cache if it's already there
|
196 |
+
abspath = os.path.abspath(cmd[1])
|
197 |
+
if abspath in _path_created:
|
198 |
+
del _path_created[abspath]
|
199 |
+
except OSError as exc:
|
200 |
+
log.warn("error removing %s: %s", directory, exc)
|
201 |
+
|
202 |
+
def ensure_relative(path):
|
203 |
+
"""Take the full path 'path', and make it a relative path.
|
204 |
+
|
205 |
+
This is useful to make 'path' the second argument to os.path.join().
|
206 |
+
"""
|
207 |
+
drive, path = os.path.splitdrive(path)
|
208 |
+
if path[0:1] == os.sep:
|
209 |
+
path = drive + path[1:]
|
210 |
+
return path
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/errors.py
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.errors
|
2 |
+
|
3 |
+
Provides exceptions used by the Distutils modules. Note that Distutils
|
4 |
+
modules may raise standard exceptions; in particular, SystemExit is
|
5 |
+
usually raised for errors that are obviously the end-user's fault
|
6 |
+
(eg. bad command-line arguments).
|
7 |
+
|
8 |
+
This module is safe to use in "from ... import *" mode; it only exports
|
9 |
+
symbols whose names start with "Distutils" and end with "Error"."""
|
10 |
+
|
11 |
+
class DistutilsError (Exception):
|
12 |
+
"""The root of all Distutils evil."""
|
13 |
+
pass
|
14 |
+
|
15 |
+
class DistutilsModuleError (DistutilsError):
|
16 |
+
"""Unable to load an expected module, or to find an expected class
|
17 |
+
within some module (in particular, command modules and classes)."""
|
18 |
+
pass
|
19 |
+
|
20 |
+
class DistutilsClassError (DistutilsError):
|
21 |
+
"""Some command class (or possibly distribution class, if anyone
|
22 |
+
feels a need to subclass Distribution) is found not to be holding
|
23 |
+
up its end of the bargain, ie. implementing some part of the
|
24 |
+
"command "interface."""
|
25 |
+
pass
|
26 |
+
|
27 |
+
class DistutilsGetoptError (DistutilsError):
|
28 |
+
"""The option table provided to 'fancy_getopt()' is bogus."""
|
29 |
+
pass
|
30 |
+
|
31 |
+
class DistutilsArgError (DistutilsError):
|
32 |
+
"""Raised by fancy_getopt in response to getopt.error -- ie. an
|
33 |
+
error in the command line usage."""
|
34 |
+
pass
|
35 |
+
|
36 |
+
class DistutilsFileError (DistutilsError):
|
37 |
+
"""Any problems in the filesystem: expected file not found, etc.
|
38 |
+
Typically this is for problems that we detect before OSError
|
39 |
+
could be raised."""
|
40 |
+
pass
|
41 |
+
|
42 |
+
class DistutilsOptionError (DistutilsError):
|
43 |
+
"""Syntactic/semantic errors in command options, such as use of
|
44 |
+
mutually conflicting options, or inconsistent options,
|
45 |
+
badly-spelled values, etc. No distinction is made between option
|
46 |
+
values originating in the setup script, the command line, config
|
47 |
+
files, or what-have-you -- but if we *know* something originated in
|
48 |
+
the setup script, we'll raise DistutilsSetupError instead."""
|
49 |
+
pass
|
50 |
+
|
51 |
+
class DistutilsSetupError (DistutilsError):
|
52 |
+
"""For errors that can be definitely blamed on the setup script,
|
53 |
+
such as invalid keyword arguments to 'setup()'."""
|
54 |
+
pass
|
55 |
+
|
56 |
+
class DistutilsPlatformError (DistutilsError):
|
57 |
+
"""We don't know how to do something on the current platform (but
|
58 |
+
we do know how to do it on some platform) -- eg. trying to compile
|
59 |
+
C files on a platform not supported by a CCompiler subclass."""
|
60 |
+
pass
|
61 |
+
|
62 |
+
class DistutilsExecError (DistutilsError):
|
63 |
+
"""Any problems executing an external program (such as the C
|
64 |
+
compiler, when compiling C files)."""
|
65 |
+
pass
|
66 |
+
|
67 |
+
class DistutilsInternalError (DistutilsError):
|
68 |
+
"""Internal inconsistencies or impossibilities (obviously, this
|
69 |
+
should never be seen if the code is working!)."""
|
70 |
+
pass
|
71 |
+
|
72 |
+
class DistutilsTemplateError (DistutilsError):
|
73 |
+
"""Syntax error in a file list template."""
|
74 |
+
|
75 |
+
class DistutilsByteCompileError(DistutilsError):
|
76 |
+
"""Byte compile error."""
|
77 |
+
|
78 |
+
# Exception classes used by the CCompiler implementation classes
|
79 |
+
class CCompilerError (Exception):
|
80 |
+
"""Some compile/link operation failed."""
|
81 |
+
|
82 |
+
class PreprocessError (CCompilerError):
|
83 |
+
"""Failure to preprocess one or more C/C++ files."""
|
84 |
+
|
85 |
+
class CompileError (CCompilerError):
|
86 |
+
"""Failure to compile one or more C/C++ source files."""
|
87 |
+
|
88 |
+
class LibError (CCompilerError):
|
89 |
+
"""Failure to create a static library from one or more C/C++ object
|
90 |
+
files."""
|
91 |
+
|
92 |
+
class LinkError (CCompilerError):
|
93 |
+
"""Failure to link one or more C/C++ object files into an executable
|
94 |
+
or shared library file."""
|
95 |
+
|
96 |
+
class UnknownFileError (CCompilerError):
|
97 |
+
"""Attempt to process an unknown file type."""
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/file_util.py
ADDED
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.file_util
|
2 |
+
|
3 |
+
Utility functions for operating on single files.
|
4 |
+
"""
|
5 |
+
|
6 |
+
import os
|
7 |
+
from distutils.errors import DistutilsFileError
|
8 |
+
from distutils import log
|
9 |
+
|
10 |
+
# for generating verbose output in 'copy_file()'
|
11 |
+
_copy_action = { None: 'copying',
|
12 |
+
'hard': 'hard linking',
|
13 |
+
'sym': 'symbolically linking' }
|
14 |
+
|
15 |
+
|
16 |
+
def _copy_file_contents(src, dst, buffer_size=16*1024):
|
17 |
+
"""Copy the file 'src' to 'dst'; both must be filenames. Any error
|
18 |
+
opening either file, reading from 'src', or writing to 'dst', raises
|
19 |
+
DistutilsFileError. Data is read/written in chunks of 'buffer_size'
|
20 |
+
bytes (default 16k). No attempt is made to handle anything apart from
|
21 |
+
regular files.
|
22 |
+
"""
|
23 |
+
# Stolen from shutil module in the standard library, but with
|
24 |
+
# custom error-handling added.
|
25 |
+
fsrc = None
|
26 |
+
fdst = None
|
27 |
+
try:
|
28 |
+
try:
|
29 |
+
fsrc = open(src, 'rb')
|
30 |
+
except OSError as e:
|
31 |
+
raise DistutilsFileError("could not open '%s': %s" % (src, e.strerror))
|
32 |
+
|
33 |
+
if os.path.exists(dst):
|
34 |
+
try:
|
35 |
+
os.unlink(dst)
|
36 |
+
except OSError as e:
|
37 |
+
raise DistutilsFileError(
|
38 |
+
"could not delete '%s': %s" % (dst, e.strerror))
|
39 |
+
|
40 |
+
try:
|
41 |
+
fdst = open(dst, 'wb')
|
42 |
+
except OSError as e:
|
43 |
+
raise DistutilsFileError(
|
44 |
+
"could not create '%s': %s" % (dst, e.strerror))
|
45 |
+
|
46 |
+
while True:
|
47 |
+
try:
|
48 |
+
buf = fsrc.read(buffer_size)
|
49 |
+
except OSError as e:
|
50 |
+
raise DistutilsFileError(
|
51 |
+
"could not read from '%s': %s" % (src, e.strerror))
|
52 |
+
|
53 |
+
if not buf:
|
54 |
+
break
|
55 |
+
|
56 |
+
try:
|
57 |
+
fdst.write(buf)
|
58 |
+
except OSError as e:
|
59 |
+
raise DistutilsFileError(
|
60 |
+
"could not write to '%s': %s" % (dst, e.strerror))
|
61 |
+
finally:
|
62 |
+
if fdst:
|
63 |
+
fdst.close()
|
64 |
+
if fsrc:
|
65 |
+
fsrc.close()
|
66 |
+
|
67 |
+
def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0,
|
68 |
+
link=None, verbose=1, dry_run=0):
|
69 |
+
"""Copy a file 'src' to 'dst'. If 'dst' is a directory, then 'src' is
|
70 |
+
copied there with the same name; otherwise, it must be a filename. (If
|
71 |
+
the file exists, it will be ruthlessly clobbered.) If 'preserve_mode'
|
72 |
+
is true (the default), the file's mode (type and permission bits, or
|
73 |
+
whatever is analogous on the current platform) is copied. If
|
74 |
+
'preserve_times' is true (the default), the last-modified and
|
75 |
+
last-access times are copied as well. If 'update' is true, 'src' will
|
76 |
+
only be copied if 'dst' does not exist, or if 'dst' does exist but is
|
77 |
+
older than 'src'.
|
78 |
+
|
79 |
+
'link' allows you to make hard links (os.link) or symbolic links
|
80 |
+
(os.symlink) instead of copying: set it to "hard" or "sym"; if it is
|
81 |
+
None (the default), files are copied. Don't set 'link' on systems that
|
82 |
+
don't support it: 'copy_file()' doesn't check if hard or symbolic
|
83 |
+
linking is available. If hardlink fails, falls back to
|
84 |
+
_copy_file_contents().
|
85 |
+
|
86 |
+
Under Mac OS, uses the native file copy function in macostools; on
|
87 |
+
other systems, uses '_copy_file_contents()' to copy file contents.
|
88 |
+
|
89 |
+
Return a tuple (dest_name, copied): 'dest_name' is the actual name of
|
90 |
+
the output file, and 'copied' is true if the file was copied (or would
|
91 |
+
have been copied, if 'dry_run' true).
|
92 |
+
"""
|
93 |
+
# XXX if the destination file already exists, we clobber it if
|
94 |
+
# copying, but blow up if linking. Hmmm. And I don't know what
|
95 |
+
# macostools.copyfile() does. Should definitely be consistent, and
|
96 |
+
# should probably blow up if destination exists and we would be
|
97 |
+
# changing it (ie. it's not already a hard/soft link to src OR
|
98 |
+
# (not update) and (src newer than dst).
|
99 |
+
|
100 |
+
from distutils.dep_util import newer
|
101 |
+
from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE
|
102 |
+
|
103 |
+
if not os.path.isfile(src):
|
104 |
+
raise DistutilsFileError(
|
105 |
+
"can't copy '%s': doesn't exist or not a regular file" % src)
|
106 |
+
|
107 |
+
if os.path.isdir(dst):
|
108 |
+
dir = dst
|
109 |
+
dst = os.path.join(dst, os.path.basename(src))
|
110 |
+
else:
|
111 |
+
dir = os.path.dirname(dst)
|
112 |
+
|
113 |
+
if update and not newer(src, dst):
|
114 |
+
if verbose >= 1:
|
115 |
+
log.debug("not copying %s (output up-to-date)", src)
|
116 |
+
return (dst, 0)
|
117 |
+
|
118 |
+
try:
|
119 |
+
action = _copy_action[link]
|
120 |
+
except KeyError:
|
121 |
+
raise ValueError("invalid value '%s' for 'link' argument" % link)
|
122 |
+
|
123 |
+
if verbose >= 1:
|
124 |
+
if os.path.basename(dst) == os.path.basename(src):
|
125 |
+
log.info("%s %s -> %s", action, src, dir)
|
126 |
+
else:
|
127 |
+
log.info("%s %s -> %s", action, src, dst)
|
128 |
+
|
129 |
+
if dry_run:
|
130 |
+
return (dst, 1)
|
131 |
+
|
132 |
+
# If linking (hard or symbolic), use the appropriate system call
|
133 |
+
# (Unix only, of course, but that's the caller's responsibility)
|
134 |
+
elif link == 'hard':
|
135 |
+
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
|
136 |
+
try:
|
137 |
+
os.link(src, dst)
|
138 |
+
return (dst, 1)
|
139 |
+
except OSError:
|
140 |
+
# If hard linking fails, fall back on copying file
|
141 |
+
# (some special filesystems don't support hard linking
|
142 |
+
# even under Unix, see issue #8876).
|
143 |
+
pass
|
144 |
+
elif link == 'sym':
|
145 |
+
if not (os.path.exists(dst) and os.path.samefile(src, dst)):
|
146 |
+
os.symlink(src, dst)
|
147 |
+
return (dst, 1)
|
148 |
+
|
149 |
+
# Otherwise (non-Mac, not linking), copy the file contents and
|
150 |
+
# (optionally) copy the times and mode.
|
151 |
+
_copy_file_contents(src, dst)
|
152 |
+
if preserve_mode or preserve_times:
|
153 |
+
st = os.stat(src)
|
154 |
+
|
155 |
+
# According to David Ascher <[email protected]>, utime() should be done
|
156 |
+
# before chmod() (at least under NT).
|
157 |
+
if preserve_times:
|
158 |
+
os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
|
159 |
+
if preserve_mode:
|
160 |
+
os.chmod(dst, S_IMODE(st[ST_MODE]))
|
161 |
+
|
162 |
+
return (dst, 1)
|
163 |
+
|
164 |
+
|
165 |
+
# XXX I suspect this is Unix-specific -- need porting help!
|
166 |
+
def move_file (src, dst,
|
167 |
+
verbose=1,
|
168 |
+
dry_run=0):
|
169 |
+
|
170 |
+
"""Move a file 'src' to 'dst'. If 'dst' is a directory, the file will
|
171 |
+
be moved into it with the same name; otherwise, 'src' is just renamed
|
172 |
+
to 'dst'. Return the new full name of the file.
|
173 |
+
|
174 |
+
Handles cross-device moves on Unix using 'copy_file()'. What about
|
175 |
+
other systems???
|
176 |
+
"""
|
177 |
+
from os.path import exists, isfile, isdir, basename, dirname
|
178 |
+
import errno
|
179 |
+
|
180 |
+
if verbose >= 1:
|
181 |
+
log.info("moving %s -> %s", src, dst)
|
182 |
+
|
183 |
+
if dry_run:
|
184 |
+
return dst
|
185 |
+
|
186 |
+
if not isfile(src):
|
187 |
+
raise DistutilsFileError("can't move '%s': not a regular file" % src)
|
188 |
+
|
189 |
+
if isdir(dst):
|
190 |
+
dst = os.path.join(dst, basename(src))
|
191 |
+
elif exists(dst):
|
192 |
+
raise DistutilsFileError(
|
193 |
+
"can't move '%s': destination '%s' already exists" %
|
194 |
+
(src, dst))
|
195 |
+
|
196 |
+
if not isdir(dirname(dst)):
|
197 |
+
raise DistutilsFileError(
|
198 |
+
"can't move '%s': destination '%s' not a valid path" %
|
199 |
+
(src, dst))
|
200 |
+
|
201 |
+
copy_it = False
|
202 |
+
try:
|
203 |
+
os.rename(src, dst)
|
204 |
+
except OSError as e:
|
205 |
+
(num, msg) = e.args
|
206 |
+
if num == errno.EXDEV:
|
207 |
+
copy_it = True
|
208 |
+
else:
|
209 |
+
raise DistutilsFileError(
|
210 |
+
"couldn't move '%s' to '%s': %s" % (src, dst, msg))
|
211 |
+
|
212 |
+
if copy_it:
|
213 |
+
copy_file(src, dst, verbose=verbose)
|
214 |
+
try:
|
215 |
+
os.unlink(src)
|
216 |
+
except OSError as e:
|
217 |
+
(num, msg) = e.args
|
218 |
+
try:
|
219 |
+
os.unlink(dst)
|
220 |
+
except OSError:
|
221 |
+
pass
|
222 |
+
raise DistutilsFileError(
|
223 |
+
"couldn't move '%s' to '%s' by copy/delete: "
|
224 |
+
"delete '%s' failed: %s"
|
225 |
+
% (src, dst, src, msg))
|
226 |
+
return dst
|
227 |
+
|
228 |
+
|
229 |
+
def write_file (filename, contents):
|
230 |
+
"""Create a file with the specified name and write 'contents' (a
|
231 |
+
sequence of strings without line terminators) to it.
|
232 |
+
"""
|
233 |
+
f = open(filename, "w")
|
234 |
+
try:
|
235 |
+
for line in contents:
|
236 |
+
f.write(line + "\n")
|
237 |
+
finally:
|
238 |
+
f.close()
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/filelist.py
ADDED
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.filelist
|
2 |
+
|
3 |
+
Provides the FileList class, used for poking about the filesystem
|
4 |
+
and building lists of files.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import os
|
8 |
+
import re
|
9 |
+
import fnmatch
|
10 |
+
import functools
|
11 |
+
|
12 |
+
from distutils.util import convert_path
|
13 |
+
from distutils.errors import DistutilsTemplateError, DistutilsInternalError
|
14 |
+
from distutils import log
|
15 |
+
|
16 |
+
|
17 |
+
class FileList:
|
18 |
+
"""A list of files built by on exploring the filesystem and filtered by
|
19 |
+
applying various patterns to what we find there.
|
20 |
+
|
21 |
+
Instance attributes:
|
22 |
+
dir
|
23 |
+
directory from which files will be taken -- only used if
|
24 |
+
'allfiles' not supplied to constructor
|
25 |
+
files
|
26 |
+
list of filenames currently being built/filtered/manipulated
|
27 |
+
allfiles
|
28 |
+
complete list of files under consideration (ie. without any
|
29 |
+
filtering applied)
|
30 |
+
"""
|
31 |
+
|
32 |
+
def __init__(self, warn=None, debug_print=None):
|
33 |
+
# ignore argument to FileList, but keep them for backwards
|
34 |
+
# compatibility
|
35 |
+
self.allfiles = None
|
36 |
+
self.files = []
|
37 |
+
|
38 |
+
def set_allfiles(self, allfiles):
|
39 |
+
self.allfiles = allfiles
|
40 |
+
|
41 |
+
def findall(self, dir=os.curdir):
|
42 |
+
self.allfiles = findall(dir)
|
43 |
+
|
44 |
+
def debug_print(self, msg):
|
45 |
+
"""Print 'msg' to stdout if the global DEBUG (taken from the
|
46 |
+
DISTUTILS_DEBUG environment variable) flag is true.
|
47 |
+
"""
|
48 |
+
from distutils.debug import DEBUG
|
49 |
+
if DEBUG:
|
50 |
+
print(msg)
|
51 |
+
|
52 |
+
# Collection methods
|
53 |
+
|
54 |
+
def append(self, item):
|
55 |
+
self.files.append(item)
|
56 |
+
|
57 |
+
def extend(self, items):
|
58 |
+
self.files.extend(items)
|
59 |
+
|
60 |
+
def sort(self):
|
61 |
+
# Not a strict lexical sort!
|
62 |
+
sortable_files = sorted(map(os.path.split, self.files))
|
63 |
+
self.files = []
|
64 |
+
for sort_tuple in sortable_files:
|
65 |
+
self.files.append(os.path.join(*sort_tuple))
|
66 |
+
|
67 |
+
# Other miscellaneous utility methods
|
68 |
+
|
69 |
+
def remove_duplicates(self):
|
70 |
+
# Assumes list has been sorted!
|
71 |
+
for i in range(len(self.files) - 1, 0, -1):
|
72 |
+
if self.files[i] == self.files[i - 1]:
|
73 |
+
del self.files[i]
|
74 |
+
|
75 |
+
# "File template" methods
|
76 |
+
|
77 |
+
def _parse_template_line(self, line):
|
78 |
+
words = line.split()
|
79 |
+
action = words[0]
|
80 |
+
|
81 |
+
patterns = dir = dir_pattern = None
|
82 |
+
|
83 |
+
if action in ('include', 'exclude',
|
84 |
+
'global-include', 'global-exclude'):
|
85 |
+
if len(words) < 2:
|
86 |
+
raise DistutilsTemplateError(
|
87 |
+
"'%s' expects <pattern1> <pattern2> ..." % action)
|
88 |
+
patterns = [convert_path(w) for w in words[1:]]
|
89 |
+
elif action in ('recursive-include', 'recursive-exclude'):
|
90 |
+
if len(words) < 3:
|
91 |
+
raise DistutilsTemplateError(
|
92 |
+
"'%s' expects <dir> <pattern1> <pattern2> ..." % action)
|
93 |
+
dir = convert_path(words[1])
|
94 |
+
patterns = [convert_path(w) for w in words[2:]]
|
95 |
+
elif action in ('graft', 'prune'):
|
96 |
+
if len(words) != 2:
|
97 |
+
raise DistutilsTemplateError(
|
98 |
+
"'%s' expects a single <dir_pattern>" % action)
|
99 |
+
dir_pattern = convert_path(words[1])
|
100 |
+
else:
|
101 |
+
raise DistutilsTemplateError("unknown action '%s'" % action)
|
102 |
+
|
103 |
+
return (action, patterns, dir, dir_pattern)
|
104 |
+
|
105 |
+
def process_template_line(self, line):
|
106 |
+
# Parse the line: split it up, make sure the right number of words
|
107 |
+
# is there, and return the relevant words. 'action' is always
|
108 |
+
# defined: it's the first word of the line. Which of the other
|
109 |
+
# three are defined depends on the action; it'll be either
|
110 |
+
# patterns, (dir and patterns), or (dir_pattern).
|
111 |
+
(action, patterns, dir, dir_pattern) = self._parse_template_line(line)
|
112 |
+
|
113 |
+
# OK, now we know that the action is valid and we have the
|
114 |
+
# right number of words on the line for that action -- so we
|
115 |
+
# can proceed with minimal error-checking.
|
116 |
+
if action == 'include':
|
117 |
+
self.debug_print("include " + ' '.join(patterns))
|
118 |
+
for pattern in patterns:
|
119 |
+
if not self.include_pattern(pattern, anchor=1):
|
120 |
+
log.warn("warning: no files found matching '%s'",
|
121 |
+
pattern)
|
122 |
+
|
123 |
+
elif action == 'exclude':
|
124 |
+
self.debug_print("exclude " + ' '.join(patterns))
|
125 |
+
for pattern in patterns:
|
126 |
+
if not self.exclude_pattern(pattern, anchor=1):
|
127 |
+
log.warn(("warning: no previously-included files "
|
128 |
+
"found matching '%s'"), pattern)
|
129 |
+
|
130 |
+
elif action == 'global-include':
|
131 |
+
self.debug_print("global-include " + ' '.join(patterns))
|
132 |
+
for pattern in patterns:
|
133 |
+
if not self.include_pattern(pattern, anchor=0):
|
134 |
+
log.warn(("warning: no files found matching '%s' "
|
135 |
+
"anywhere in distribution"), pattern)
|
136 |
+
|
137 |
+
elif action == 'global-exclude':
|
138 |
+
self.debug_print("global-exclude " + ' '.join(patterns))
|
139 |
+
for pattern in patterns:
|
140 |
+
if not self.exclude_pattern(pattern, anchor=0):
|
141 |
+
log.warn(("warning: no previously-included files matching "
|
142 |
+
"'%s' found anywhere in distribution"),
|
143 |
+
pattern)
|
144 |
+
|
145 |
+
elif action == 'recursive-include':
|
146 |
+
self.debug_print("recursive-include %s %s" %
|
147 |
+
(dir, ' '.join(patterns)))
|
148 |
+
for pattern in patterns:
|
149 |
+
if not self.include_pattern(pattern, prefix=dir):
|
150 |
+
msg = (
|
151 |
+
"warning: no files found matching '%s' "
|
152 |
+
"under directory '%s'"
|
153 |
+
)
|
154 |
+
log.warn(msg, pattern, dir)
|
155 |
+
|
156 |
+
elif action == 'recursive-exclude':
|
157 |
+
self.debug_print("recursive-exclude %s %s" %
|
158 |
+
(dir, ' '.join(patterns)))
|
159 |
+
for pattern in patterns:
|
160 |
+
if not self.exclude_pattern(pattern, prefix=dir):
|
161 |
+
log.warn(("warning: no previously-included files matching "
|
162 |
+
"'%s' found under directory '%s'"),
|
163 |
+
pattern, dir)
|
164 |
+
|
165 |
+
elif action == 'graft':
|
166 |
+
self.debug_print("graft " + dir_pattern)
|
167 |
+
if not self.include_pattern(None, prefix=dir_pattern):
|
168 |
+
log.warn("warning: no directories found matching '%s'",
|
169 |
+
dir_pattern)
|
170 |
+
|
171 |
+
elif action == 'prune':
|
172 |
+
self.debug_print("prune " + dir_pattern)
|
173 |
+
if not self.exclude_pattern(None, prefix=dir_pattern):
|
174 |
+
log.warn(("no previously-included directories found "
|
175 |
+
"matching '%s'"), dir_pattern)
|
176 |
+
else:
|
177 |
+
raise DistutilsInternalError(
|
178 |
+
"this cannot happen: invalid action '%s'" % action)
|
179 |
+
|
180 |
+
# Filtering/selection methods
|
181 |
+
|
182 |
+
def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
|
183 |
+
"""Select strings (presumably filenames) from 'self.files' that
|
184 |
+
match 'pattern', a Unix-style wildcard (glob) pattern. Patterns
|
185 |
+
are not quite the same as implemented by the 'fnmatch' module: '*'
|
186 |
+
and '?' match non-special characters, where "special" is platform-
|
187 |
+
dependent: slash on Unix; colon, slash, and backslash on
|
188 |
+
DOS/Windows; and colon on Mac OS.
|
189 |
+
|
190 |
+
If 'anchor' is true (the default), then the pattern match is more
|
191 |
+
stringent: "*.py" will match "foo.py" but not "foo/bar.py". If
|
192 |
+
'anchor' is false, both of these will match.
|
193 |
+
|
194 |
+
If 'prefix' is supplied, then only filenames starting with 'prefix'
|
195 |
+
(itself a pattern) and ending with 'pattern', with anything in between
|
196 |
+
them, will match. 'anchor' is ignored in this case.
|
197 |
+
|
198 |
+
If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
|
199 |
+
'pattern' is assumed to be either a string containing a regex or a
|
200 |
+
regex object -- no translation is done, the regex is just compiled
|
201 |
+
and used as-is.
|
202 |
+
|
203 |
+
Selected strings will be added to self.files.
|
204 |
+
|
205 |
+
Return True if files are found, False otherwise.
|
206 |
+
"""
|
207 |
+
# XXX docstring lying about what the special chars are?
|
208 |
+
files_found = False
|
209 |
+
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
|
210 |
+
self.debug_print("include_pattern: applying regex r'%s'" %
|
211 |
+
pattern_re.pattern)
|
212 |
+
|
213 |
+
# delayed loading of allfiles list
|
214 |
+
if self.allfiles is None:
|
215 |
+
self.findall()
|
216 |
+
|
217 |
+
for name in self.allfiles:
|
218 |
+
if pattern_re.search(name):
|
219 |
+
self.debug_print(" adding " + name)
|
220 |
+
self.files.append(name)
|
221 |
+
files_found = True
|
222 |
+
return files_found
|
223 |
+
|
224 |
+
def exclude_pattern(
|
225 |
+
self, pattern, anchor=1, prefix=None, is_regex=0):
|
226 |
+
"""Remove strings (presumably filenames) from 'files' that match
|
227 |
+
'pattern'. Other parameters are the same as for
|
228 |
+
'include_pattern()', above.
|
229 |
+
The list 'self.files' is modified in place.
|
230 |
+
Return True if files are found, False otherwise.
|
231 |
+
"""
|
232 |
+
files_found = False
|
233 |
+
pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
|
234 |
+
self.debug_print("exclude_pattern: applying regex r'%s'" %
|
235 |
+
pattern_re.pattern)
|
236 |
+
for i in range(len(self.files)-1, -1, -1):
|
237 |
+
if pattern_re.search(self.files[i]):
|
238 |
+
self.debug_print(" removing " + self.files[i])
|
239 |
+
del self.files[i]
|
240 |
+
files_found = True
|
241 |
+
return files_found
|
242 |
+
|
243 |
+
|
244 |
+
# Utility functions
|
245 |
+
|
246 |
+
def _find_all_simple(path):
|
247 |
+
"""
|
248 |
+
Find all files under 'path'
|
249 |
+
"""
|
250 |
+
all_unique = _UniqueDirs.filter(os.walk(path, followlinks=True))
|
251 |
+
results = (
|
252 |
+
os.path.join(base, file)
|
253 |
+
for base, dirs, files in all_unique
|
254 |
+
for file in files
|
255 |
+
)
|
256 |
+
return filter(os.path.isfile, results)
|
257 |
+
|
258 |
+
|
259 |
+
class _UniqueDirs(set):
|
260 |
+
"""
|
261 |
+
Exclude previously-seen dirs from walk results,
|
262 |
+
avoiding infinite recursion.
|
263 |
+
Ref https://bugs.python.org/issue44497.
|
264 |
+
"""
|
265 |
+
def __call__(self, walk_item):
|
266 |
+
"""
|
267 |
+
Given an item from an os.walk result, determine
|
268 |
+
if the item represents a unique dir for this instance
|
269 |
+
and if not, prevent further traversal.
|
270 |
+
"""
|
271 |
+
base, dirs, files = walk_item
|
272 |
+
stat = os.stat(base)
|
273 |
+
candidate = stat.st_dev, stat.st_ino
|
274 |
+
found = candidate in self
|
275 |
+
if found:
|
276 |
+
del dirs[:]
|
277 |
+
self.add(candidate)
|
278 |
+
return not found
|
279 |
+
|
280 |
+
@classmethod
|
281 |
+
def filter(cls, items):
|
282 |
+
return filter(cls(), items)
|
283 |
+
|
284 |
+
|
285 |
+
def findall(dir=os.curdir):
|
286 |
+
"""
|
287 |
+
Find all files under 'dir' and return the list of full filenames.
|
288 |
+
Unless dir is '.', return full filenames with dir prepended.
|
289 |
+
"""
|
290 |
+
files = _find_all_simple(dir)
|
291 |
+
if dir == os.curdir:
|
292 |
+
make_rel = functools.partial(os.path.relpath, start=dir)
|
293 |
+
files = map(make_rel, files)
|
294 |
+
return list(files)
|
295 |
+
|
296 |
+
|
297 |
+
def glob_to_re(pattern):
|
298 |
+
"""Translate a shell-like glob pattern to a regular expression; return
|
299 |
+
a string containing the regex. Differs from 'fnmatch.translate()' in
|
300 |
+
that '*' does not match "special characters" (which are
|
301 |
+
platform-specific).
|
302 |
+
"""
|
303 |
+
pattern_re = fnmatch.translate(pattern)
|
304 |
+
|
305 |
+
# '?' and '*' in the glob pattern become '.' and '.*' in the RE, which
|
306 |
+
# IMHO is wrong -- '?' and '*' aren't supposed to match slash in Unix,
|
307 |
+
# and by extension they shouldn't match such "special characters" under
|
308 |
+
# any OS. So change all non-escaped dots in the RE to match any
|
309 |
+
# character except the special characters (currently: just os.sep).
|
310 |
+
sep = os.sep
|
311 |
+
if os.sep == '\\':
|
312 |
+
# we're using a regex to manipulate a regex, so we need
|
313 |
+
# to escape the backslash twice
|
314 |
+
sep = r'\\\\'
|
315 |
+
escaped = r'\1[^%s]' % sep
|
316 |
+
pattern_re = re.sub(r'((?<!\\)(\\\\)*)\.', escaped, pattern_re)
|
317 |
+
return pattern_re
|
318 |
+
|
319 |
+
|
320 |
+
def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
|
321 |
+
"""Translate a shell-like wildcard pattern to a compiled regular
|
322 |
+
expression. Return the compiled regex. If 'is_regex' true,
|
323 |
+
then 'pattern' is directly compiled to a regex (if it's a string)
|
324 |
+
or just returned as-is (assumes it's a regex object).
|
325 |
+
"""
|
326 |
+
if is_regex:
|
327 |
+
if isinstance(pattern, str):
|
328 |
+
return re.compile(pattern)
|
329 |
+
else:
|
330 |
+
return pattern
|
331 |
+
|
332 |
+
# ditch start and end characters
|
333 |
+
start, _, end = glob_to_re('_').partition('_')
|
334 |
+
|
335 |
+
if pattern:
|
336 |
+
pattern_re = glob_to_re(pattern)
|
337 |
+
assert pattern_re.startswith(start) and pattern_re.endswith(end)
|
338 |
+
else:
|
339 |
+
pattern_re = ''
|
340 |
+
|
341 |
+
if prefix is not None:
|
342 |
+
prefix_re = glob_to_re(prefix)
|
343 |
+
assert prefix_re.startswith(start) and prefix_re.endswith(end)
|
344 |
+
prefix_re = prefix_re[len(start): len(prefix_re) - len(end)]
|
345 |
+
sep = os.sep
|
346 |
+
if os.sep == '\\':
|
347 |
+
sep = r'\\'
|
348 |
+
pattern_re = pattern_re[len(start): len(pattern_re) - len(end)]
|
349 |
+
pattern_re = r'%s\A%s%s.*%s%s' % (
|
350 |
+
start, prefix_re, sep, pattern_re, end)
|
351 |
+
else: # no prefix -- respect anchor flag
|
352 |
+
if anchor:
|
353 |
+
pattern_re = r'%s\A%s' % (start, pattern_re[len(start):])
|
354 |
+
|
355 |
+
return re.compile(pattern_re)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/msvc9compiler.py
ADDED
@@ -0,0 +1,788 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.msvc9compiler
|
2 |
+
|
3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
4 |
+
for the Microsoft Visual Studio 2008.
|
5 |
+
|
6 |
+
The module is compatible with VS 2005 and VS 2008. You can find legacy support
|
7 |
+
for older versions of VS in distutils.msvccompiler.
|
8 |
+
"""
|
9 |
+
|
10 |
+
# Written by Perry Stoll
|
11 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
12 |
+
# finding DevStudio (through the registry)
|
13 |
+
# ported to VS2005 and VS 2008 by Christian Heimes
|
14 |
+
|
15 |
+
import os
|
16 |
+
import subprocess
|
17 |
+
import sys
|
18 |
+
import re
|
19 |
+
|
20 |
+
from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
|
21 |
+
CompileError, LibError, LinkError
|
22 |
+
from distutils.ccompiler import CCompiler, gen_lib_options
|
23 |
+
from distutils import log
|
24 |
+
from distutils.util import get_platform
|
25 |
+
|
26 |
+
import winreg
|
27 |
+
|
28 |
+
RegOpenKeyEx = winreg.OpenKeyEx
|
29 |
+
RegEnumKey = winreg.EnumKey
|
30 |
+
RegEnumValue = winreg.EnumValue
|
31 |
+
RegError = winreg.error
|
32 |
+
|
33 |
+
HKEYS = (winreg.HKEY_USERS,
|
34 |
+
winreg.HKEY_CURRENT_USER,
|
35 |
+
winreg.HKEY_LOCAL_MACHINE,
|
36 |
+
winreg.HKEY_CLASSES_ROOT)
|
37 |
+
|
38 |
+
NATIVE_WIN64 = (sys.platform == 'win32' and sys.maxsize > 2**32)
|
39 |
+
if NATIVE_WIN64:
|
40 |
+
# Visual C++ is a 32-bit application, so we need to look in
|
41 |
+
# the corresponding registry branch, if we're running a
|
42 |
+
# 64-bit Python on Win64
|
43 |
+
VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"
|
44 |
+
WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows"
|
45 |
+
NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework"
|
46 |
+
else:
|
47 |
+
VS_BASE = r"Software\Microsoft\VisualStudio\%0.1f"
|
48 |
+
WINSDK_BASE = r"Software\Microsoft\Microsoft SDKs\Windows"
|
49 |
+
NET_BASE = r"Software\Microsoft\.NETFramework"
|
50 |
+
|
51 |
+
# A map keyed by get_platform() return values to values accepted by
|
52 |
+
# 'vcvarsall.bat'. Note a cross-compile may combine these (eg, 'x86_amd64' is
|
53 |
+
# the param to cross-compile on x86 targeting amd64.)
|
54 |
+
PLAT_TO_VCVARS = {
|
55 |
+
'win32' : 'x86',
|
56 |
+
'win-amd64' : 'amd64',
|
57 |
+
}
|
58 |
+
|
59 |
+
class Reg:
|
60 |
+
"""Helper class to read values from the registry
|
61 |
+
"""
|
62 |
+
|
63 |
+
def get_value(cls, path, key):
|
64 |
+
for base in HKEYS:
|
65 |
+
d = cls.read_values(base, path)
|
66 |
+
if d and key in d:
|
67 |
+
return d[key]
|
68 |
+
raise KeyError(key)
|
69 |
+
get_value = classmethod(get_value)
|
70 |
+
|
71 |
+
def read_keys(cls, base, key):
|
72 |
+
"""Return list of registry keys."""
|
73 |
+
try:
|
74 |
+
handle = RegOpenKeyEx(base, key)
|
75 |
+
except RegError:
|
76 |
+
return None
|
77 |
+
L = []
|
78 |
+
i = 0
|
79 |
+
while True:
|
80 |
+
try:
|
81 |
+
k = RegEnumKey(handle, i)
|
82 |
+
except RegError:
|
83 |
+
break
|
84 |
+
L.append(k)
|
85 |
+
i += 1
|
86 |
+
return L
|
87 |
+
read_keys = classmethod(read_keys)
|
88 |
+
|
89 |
+
def read_values(cls, base, key):
|
90 |
+
"""Return dict of registry keys and values.
|
91 |
+
|
92 |
+
All names are converted to lowercase.
|
93 |
+
"""
|
94 |
+
try:
|
95 |
+
handle = RegOpenKeyEx(base, key)
|
96 |
+
except RegError:
|
97 |
+
return None
|
98 |
+
d = {}
|
99 |
+
i = 0
|
100 |
+
while True:
|
101 |
+
try:
|
102 |
+
name, value, type = RegEnumValue(handle, i)
|
103 |
+
except RegError:
|
104 |
+
break
|
105 |
+
name = name.lower()
|
106 |
+
d[cls.convert_mbcs(name)] = cls.convert_mbcs(value)
|
107 |
+
i += 1
|
108 |
+
return d
|
109 |
+
read_values = classmethod(read_values)
|
110 |
+
|
111 |
+
def convert_mbcs(s):
|
112 |
+
dec = getattr(s, "decode", None)
|
113 |
+
if dec is not None:
|
114 |
+
try:
|
115 |
+
s = dec("mbcs")
|
116 |
+
except UnicodeError:
|
117 |
+
pass
|
118 |
+
return s
|
119 |
+
convert_mbcs = staticmethod(convert_mbcs)
|
120 |
+
|
121 |
+
class MacroExpander:
|
122 |
+
|
123 |
+
def __init__(self, version):
|
124 |
+
self.macros = {}
|
125 |
+
self.vsbase = VS_BASE % version
|
126 |
+
self.load_macros(version)
|
127 |
+
|
128 |
+
def set_macro(self, macro, path, key):
|
129 |
+
self.macros["$(%s)" % macro] = Reg.get_value(path, key)
|
130 |
+
|
131 |
+
def load_macros(self, version):
|
132 |
+
self.set_macro("VCInstallDir", self.vsbase + r"\Setup\VC", "productdir")
|
133 |
+
self.set_macro("VSInstallDir", self.vsbase + r"\Setup\VS", "productdir")
|
134 |
+
self.set_macro("FrameworkDir", NET_BASE, "installroot")
|
135 |
+
try:
|
136 |
+
if version >= 8.0:
|
137 |
+
self.set_macro("FrameworkSDKDir", NET_BASE,
|
138 |
+
"sdkinstallrootv2.0")
|
139 |
+
else:
|
140 |
+
raise KeyError("sdkinstallrootv2.0")
|
141 |
+
except KeyError:
|
142 |
+
raise DistutilsPlatformError(
|
143 |
+
"""Python was built with Visual Studio 2008;
|
144 |
+
extensions must be built with a compiler than can generate compatible binaries.
|
145 |
+
Visual Studio 2008 was not found on this system. If you have Cygwin installed,
|
146 |
+
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
|
147 |
+
|
148 |
+
if version >= 9.0:
|
149 |
+
self.set_macro("FrameworkVersion", self.vsbase, "clr version")
|
150 |
+
self.set_macro("WindowsSdkDir", WINSDK_BASE, "currentinstallfolder")
|
151 |
+
else:
|
152 |
+
p = r"Software\Microsoft\NET Framework Setup\Product"
|
153 |
+
for base in HKEYS:
|
154 |
+
try:
|
155 |
+
h = RegOpenKeyEx(base, p)
|
156 |
+
except RegError:
|
157 |
+
continue
|
158 |
+
key = RegEnumKey(h, 0)
|
159 |
+
d = Reg.get_value(base, r"%s\%s" % (p, key))
|
160 |
+
self.macros["$(FrameworkVersion)"] = d["version"]
|
161 |
+
|
162 |
+
def sub(self, s):
|
163 |
+
for k, v in self.macros.items():
|
164 |
+
s = s.replace(k, v)
|
165 |
+
return s
|
166 |
+
|
167 |
+
def get_build_version():
|
168 |
+
"""Return the version of MSVC that was used to build Python.
|
169 |
+
|
170 |
+
For Python 2.3 and up, the version number is included in
|
171 |
+
sys.version. For earlier versions, assume the compiler is MSVC 6.
|
172 |
+
"""
|
173 |
+
prefix = "MSC v."
|
174 |
+
i = sys.version.find(prefix)
|
175 |
+
if i == -1:
|
176 |
+
return 6
|
177 |
+
i = i + len(prefix)
|
178 |
+
s, rest = sys.version[i:].split(" ", 1)
|
179 |
+
majorVersion = int(s[:-2]) - 6
|
180 |
+
if majorVersion >= 13:
|
181 |
+
# v13 was skipped and should be v14
|
182 |
+
majorVersion += 1
|
183 |
+
minorVersion = int(s[2:3]) / 10.0
|
184 |
+
# I don't think paths are affected by minor version in version 6
|
185 |
+
if majorVersion == 6:
|
186 |
+
minorVersion = 0
|
187 |
+
if majorVersion >= 6:
|
188 |
+
return majorVersion + minorVersion
|
189 |
+
# else we don't know what version of the compiler this is
|
190 |
+
return None
|
191 |
+
|
192 |
+
def normalize_and_reduce_paths(paths):
|
193 |
+
"""Return a list of normalized paths with duplicates removed.
|
194 |
+
|
195 |
+
The current order of paths is maintained.
|
196 |
+
"""
|
197 |
+
# Paths are normalized so things like: /a and /a/ aren't both preserved.
|
198 |
+
reduced_paths = []
|
199 |
+
for p in paths:
|
200 |
+
np = os.path.normpath(p)
|
201 |
+
# XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
|
202 |
+
if np not in reduced_paths:
|
203 |
+
reduced_paths.append(np)
|
204 |
+
return reduced_paths
|
205 |
+
|
206 |
+
def removeDuplicates(variable):
|
207 |
+
"""Remove duplicate values of an environment variable.
|
208 |
+
"""
|
209 |
+
oldList = variable.split(os.pathsep)
|
210 |
+
newList = []
|
211 |
+
for i in oldList:
|
212 |
+
if i not in newList:
|
213 |
+
newList.append(i)
|
214 |
+
newVariable = os.pathsep.join(newList)
|
215 |
+
return newVariable
|
216 |
+
|
217 |
+
def find_vcvarsall(version):
|
218 |
+
"""Find the vcvarsall.bat file
|
219 |
+
|
220 |
+
At first it tries to find the productdir of VS 2008 in the registry. If
|
221 |
+
that fails it falls back to the VS90COMNTOOLS env var.
|
222 |
+
"""
|
223 |
+
vsbase = VS_BASE % version
|
224 |
+
try:
|
225 |
+
productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
|
226 |
+
"productdir")
|
227 |
+
except KeyError:
|
228 |
+
log.debug("Unable to find productdir in registry")
|
229 |
+
productdir = None
|
230 |
+
|
231 |
+
if not productdir or not os.path.isdir(productdir):
|
232 |
+
toolskey = "VS%0.f0COMNTOOLS" % version
|
233 |
+
toolsdir = os.environ.get(toolskey, None)
|
234 |
+
|
235 |
+
if toolsdir and os.path.isdir(toolsdir):
|
236 |
+
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
|
237 |
+
productdir = os.path.abspath(productdir)
|
238 |
+
if not os.path.isdir(productdir):
|
239 |
+
log.debug("%s is not a valid directory" % productdir)
|
240 |
+
return None
|
241 |
+
else:
|
242 |
+
log.debug("Env var %s is not set or invalid" % toolskey)
|
243 |
+
if not productdir:
|
244 |
+
log.debug("No productdir found")
|
245 |
+
return None
|
246 |
+
vcvarsall = os.path.join(productdir, "vcvarsall.bat")
|
247 |
+
if os.path.isfile(vcvarsall):
|
248 |
+
return vcvarsall
|
249 |
+
log.debug("Unable to find vcvarsall.bat")
|
250 |
+
return None
|
251 |
+
|
252 |
+
def query_vcvarsall(version, arch="x86"):
|
253 |
+
"""Launch vcvarsall.bat and read the settings from its environment
|
254 |
+
"""
|
255 |
+
vcvarsall = find_vcvarsall(version)
|
256 |
+
interesting = {"include", "lib", "libpath", "path"}
|
257 |
+
result = {}
|
258 |
+
|
259 |
+
if vcvarsall is None:
|
260 |
+
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
|
261 |
+
log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
|
262 |
+
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
|
263 |
+
stdout=subprocess.PIPE,
|
264 |
+
stderr=subprocess.PIPE)
|
265 |
+
try:
|
266 |
+
stdout, stderr = popen.communicate()
|
267 |
+
if popen.wait() != 0:
|
268 |
+
raise DistutilsPlatformError(stderr.decode("mbcs"))
|
269 |
+
|
270 |
+
stdout = stdout.decode("mbcs")
|
271 |
+
for line in stdout.split("\n"):
|
272 |
+
line = Reg.convert_mbcs(line)
|
273 |
+
if '=' not in line:
|
274 |
+
continue
|
275 |
+
line = line.strip()
|
276 |
+
key, value = line.split('=', 1)
|
277 |
+
key = key.lower()
|
278 |
+
if key in interesting:
|
279 |
+
if value.endswith(os.pathsep):
|
280 |
+
value = value[:-1]
|
281 |
+
result[key] = removeDuplicates(value)
|
282 |
+
|
283 |
+
finally:
|
284 |
+
popen.stdout.close()
|
285 |
+
popen.stderr.close()
|
286 |
+
|
287 |
+
if len(result) != len(interesting):
|
288 |
+
raise ValueError(str(list(result.keys())))
|
289 |
+
|
290 |
+
return result
|
291 |
+
|
292 |
+
# More globals
|
293 |
+
VERSION = get_build_version()
|
294 |
+
if VERSION < 8.0:
|
295 |
+
raise DistutilsPlatformError("VC %0.1f is not supported by this module" % VERSION)
|
296 |
+
# MACROS = MacroExpander(VERSION)
|
297 |
+
|
298 |
+
class MSVCCompiler(CCompiler) :
|
299 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
300 |
+
as defined by the CCompiler abstract class."""
|
301 |
+
|
302 |
+
compiler_type = 'msvc'
|
303 |
+
|
304 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
305 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
306 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
307 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
308 |
+
# though, so it's worth thinking about.
|
309 |
+
executables = {}
|
310 |
+
|
311 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
312 |
+
_c_extensions = ['.c']
|
313 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
314 |
+
_rc_extensions = ['.rc']
|
315 |
+
_mc_extensions = ['.mc']
|
316 |
+
|
317 |
+
# Needed for the filename generation methods provided by the
|
318 |
+
# base class, CCompiler.
|
319 |
+
src_extensions = (_c_extensions + _cpp_extensions +
|
320 |
+
_rc_extensions + _mc_extensions)
|
321 |
+
res_extension = '.res'
|
322 |
+
obj_extension = '.obj'
|
323 |
+
static_lib_extension = '.lib'
|
324 |
+
shared_lib_extension = '.dll'
|
325 |
+
static_lib_format = shared_lib_format = '%s%s'
|
326 |
+
exe_extension = '.exe'
|
327 |
+
|
328 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
329 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
330 |
+
self.__version = VERSION
|
331 |
+
self.__root = r"Software\Microsoft\VisualStudio"
|
332 |
+
# self.__macros = MACROS
|
333 |
+
self.__paths = []
|
334 |
+
# target platform (.plat_name is consistent with 'bdist')
|
335 |
+
self.plat_name = None
|
336 |
+
self.__arch = None # deprecated name
|
337 |
+
self.initialized = False
|
338 |
+
|
339 |
+
def initialize(self, plat_name=None):
|
340 |
+
# multi-init means we would need to check platform same each time...
|
341 |
+
assert not self.initialized, "don't init multiple times"
|
342 |
+
if plat_name is None:
|
343 |
+
plat_name = get_platform()
|
344 |
+
# sanity check for platforms to prevent obscure errors later.
|
345 |
+
ok_plats = 'win32', 'win-amd64'
|
346 |
+
if plat_name not in ok_plats:
|
347 |
+
raise DistutilsPlatformError("--plat-name must be one of %s" %
|
348 |
+
(ok_plats,))
|
349 |
+
|
350 |
+
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
|
351 |
+
# Assume that the SDK set up everything alright; don't try to be
|
352 |
+
# smarter
|
353 |
+
self.cc = "cl.exe"
|
354 |
+
self.linker = "link.exe"
|
355 |
+
self.lib = "lib.exe"
|
356 |
+
self.rc = "rc.exe"
|
357 |
+
self.mc = "mc.exe"
|
358 |
+
else:
|
359 |
+
# On x86, 'vcvars32.bat amd64' creates an env that doesn't work;
|
360 |
+
# to cross compile, you use 'x86_amd64'.
|
361 |
+
# On AMD64, 'vcvars32.bat amd64' is a native build env; to cross
|
362 |
+
# compile use 'x86' (ie, it runs the x86 compiler directly)
|
363 |
+
if plat_name == get_platform() or plat_name == 'win32':
|
364 |
+
# native build or cross-compile to win32
|
365 |
+
plat_spec = PLAT_TO_VCVARS[plat_name]
|
366 |
+
else:
|
367 |
+
# cross compile from win32 -> some 64bit
|
368 |
+
plat_spec = PLAT_TO_VCVARS[get_platform()] + '_' + \
|
369 |
+
PLAT_TO_VCVARS[plat_name]
|
370 |
+
|
371 |
+
vc_env = query_vcvarsall(VERSION, plat_spec)
|
372 |
+
|
373 |
+
self.__paths = vc_env['path'].split(os.pathsep)
|
374 |
+
os.environ['lib'] = vc_env['lib']
|
375 |
+
os.environ['include'] = vc_env['include']
|
376 |
+
|
377 |
+
if len(self.__paths) == 0:
|
378 |
+
raise DistutilsPlatformError("Python was built with %s, "
|
379 |
+
"and extensions need to be built with the same "
|
380 |
+
"version of the compiler, but it isn't installed."
|
381 |
+
% self.__product)
|
382 |
+
|
383 |
+
self.cc = self.find_exe("cl.exe")
|
384 |
+
self.linker = self.find_exe("link.exe")
|
385 |
+
self.lib = self.find_exe("lib.exe")
|
386 |
+
self.rc = self.find_exe("rc.exe") # resource compiler
|
387 |
+
self.mc = self.find_exe("mc.exe") # message compiler
|
388 |
+
#self.set_path_env_var('lib')
|
389 |
+
#self.set_path_env_var('include')
|
390 |
+
|
391 |
+
# extend the MSVC path with the current path
|
392 |
+
try:
|
393 |
+
for p in os.environ['path'].split(';'):
|
394 |
+
self.__paths.append(p)
|
395 |
+
except KeyError:
|
396 |
+
pass
|
397 |
+
self.__paths = normalize_and_reduce_paths(self.__paths)
|
398 |
+
os.environ['path'] = ";".join(self.__paths)
|
399 |
+
|
400 |
+
self.preprocess_options = None
|
401 |
+
if self.__arch == "x86":
|
402 |
+
self.compile_options = [ '/nologo', '/O2', '/MD', '/W3',
|
403 |
+
'/DNDEBUG']
|
404 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3',
|
405 |
+
'/Z7', '/D_DEBUG']
|
406 |
+
else:
|
407 |
+
# Win64
|
408 |
+
self.compile_options = [ '/nologo', '/O2', '/MD', '/W3', '/GS-' ,
|
409 |
+
'/DNDEBUG']
|
410 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
|
411 |
+
'/Z7', '/D_DEBUG']
|
412 |
+
|
413 |
+
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
414 |
+
if self.__version >= 7:
|
415 |
+
self.ldflags_shared_debug = [
|
416 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
|
417 |
+
]
|
418 |
+
self.ldflags_static = [ '/nologo']
|
419 |
+
|
420 |
+
self.initialized = True
|
421 |
+
|
422 |
+
# -- Worker methods ------------------------------------------------
|
423 |
+
|
424 |
+
def object_filenames(self,
|
425 |
+
source_filenames,
|
426 |
+
strip_dir=0,
|
427 |
+
output_dir=''):
|
428 |
+
# Copied from ccompiler.py, extended to return .res as 'object'-file
|
429 |
+
# for .rc input file
|
430 |
+
if output_dir is None: output_dir = ''
|
431 |
+
obj_names = []
|
432 |
+
for src_name in source_filenames:
|
433 |
+
(base, ext) = os.path.splitext (src_name)
|
434 |
+
base = os.path.splitdrive(base)[1] # Chop off the drive
|
435 |
+
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
436 |
+
if ext not in self.src_extensions:
|
437 |
+
# Better to raise an exception instead of silently continuing
|
438 |
+
# and later complain about sources and targets having
|
439 |
+
# different lengths
|
440 |
+
raise CompileError ("Don't know how to compile %s" % src_name)
|
441 |
+
if strip_dir:
|
442 |
+
base = os.path.basename (base)
|
443 |
+
if ext in self._rc_extensions:
|
444 |
+
obj_names.append (os.path.join (output_dir,
|
445 |
+
base + self.res_extension))
|
446 |
+
elif ext in self._mc_extensions:
|
447 |
+
obj_names.append (os.path.join (output_dir,
|
448 |
+
base + self.res_extension))
|
449 |
+
else:
|
450 |
+
obj_names.append (os.path.join (output_dir,
|
451 |
+
base + self.obj_extension))
|
452 |
+
return obj_names
|
453 |
+
|
454 |
+
|
455 |
+
def compile(self, sources,
|
456 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
457 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
458 |
+
|
459 |
+
if not self.initialized:
|
460 |
+
self.initialize()
|
461 |
+
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
462 |
+
sources, depends, extra_postargs)
|
463 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
464 |
+
|
465 |
+
compile_opts = extra_preargs or []
|
466 |
+
compile_opts.append ('/c')
|
467 |
+
if debug:
|
468 |
+
compile_opts.extend(self.compile_options_debug)
|
469 |
+
else:
|
470 |
+
compile_opts.extend(self.compile_options)
|
471 |
+
|
472 |
+
for obj in objects:
|
473 |
+
try:
|
474 |
+
src, ext = build[obj]
|
475 |
+
except KeyError:
|
476 |
+
continue
|
477 |
+
if debug:
|
478 |
+
# pass the full pathname to MSVC in debug mode,
|
479 |
+
# this allows the debugger to find the source file
|
480 |
+
# without asking the user to browse for it
|
481 |
+
src = os.path.abspath(src)
|
482 |
+
|
483 |
+
if ext in self._c_extensions:
|
484 |
+
input_opt = "/Tc" + src
|
485 |
+
elif ext in self._cpp_extensions:
|
486 |
+
input_opt = "/Tp" + src
|
487 |
+
elif ext in self._rc_extensions:
|
488 |
+
# compile .RC to .RES file
|
489 |
+
input_opt = src
|
490 |
+
output_opt = "/fo" + obj
|
491 |
+
try:
|
492 |
+
self.spawn([self.rc] + pp_opts +
|
493 |
+
[output_opt] + [input_opt])
|
494 |
+
except DistutilsExecError as msg:
|
495 |
+
raise CompileError(msg)
|
496 |
+
continue
|
497 |
+
elif ext in self._mc_extensions:
|
498 |
+
# Compile .MC to .RC file to .RES file.
|
499 |
+
# * '-h dir' specifies the directory for the
|
500 |
+
# generated include file
|
501 |
+
# * '-r dir' specifies the target directory of the
|
502 |
+
# generated RC file and the binary message resource
|
503 |
+
# it includes
|
504 |
+
#
|
505 |
+
# For now (since there are no options to change this),
|
506 |
+
# we use the source-directory for the include file and
|
507 |
+
# the build directory for the RC file and message
|
508 |
+
# resources. This works at least for win32all.
|
509 |
+
h_dir = os.path.dirname(src)
|
510 |
+
rc_dir = os.path.dirname(obj)
|
511 |
+
try:
|
512 |
+
# first compile .MC to .RC and .H file
|
513 |
+
self.spawn([self.mc] +
|
514 |
+
['-h', h_dir, '-r', rc_dir] + [src])
|
515 |
+
base, _ = os.path.splitext (os.path.basename (src))
|
516 |
+
rc_file = os.path.join (rc_dir, base + '.rc')
|
517 |
+
# then compile .RC to .RES file
|
518 |
+
self.spawn([self.rc] +
|
519 |
+
["/fo" + obj] + [rc_file])
|
520 |
+
|
521 |
+
except DistutilsExecError as msg:
|
522 |
+
raise CompileError(msg)
|
523 |
+
continue
|
524 |
+
else:
|
525 |
+
# how to handle this file?
|
526 |
+
raise CompileError("Don't know how to compile %s to %s"
|
527 |
+
% (src, obj))
|
528 |
+
|
529 |
+
output_opt = "/Fo" + obj
|
530 |
+
try:
|
531 |
+
self.spawn([self.cc] + compile_opts + pp_opts +
|
532 |
+
[input_opt, output_opt] +
|
533 |
+
extra_postargs)
|
534 |
+
except DistutilsExecError as msg:
|
535 |
+
raise CompileError(msg)
|
536 |
+
|
537 |
+
return objects
|
538 |
+
|
539 |
+
|
540 |
+
def create_static_lib(self,
|
541 |
+
objects,
|
542 |
+
output_libname,
|
543 |
+
output_dir=None,
|
544 |
+
debug=0,
|
545 |
+
target_lang=None):
|
546 |
+
|
547 |
+
if not self.initialized:
|
548 |
+
self.initialize()
|
549 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
550 |
+
output_filename = self.library_filename(output_libname,
|
551 |
+
output_dir=output_dir)
|
552 |
+
|
553 |
+
if self._need_link(objects, output_filename):
|
554 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
555 |
+
if debug:
|
556 |
+
pass # XXX what goes here?
|
557 |
+
try:
|
558 |
+
self.spawn([self.lib] + lib_args)
|
559 |
+
except DistutilsExecError as msg:
|
560 |
+
raise LibError(msg)
|
561 |
+
else:
|
562 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
563 |
+
|
564 |
+
|
565 |
+
def link(self,
|
566 |
+
target_desc,
|
567 |
+
objects,
|
568 |
+
output_filename,
|
569 |
+
output_dir=None,
|
570 |
+
libraries=None,
|
571 |
+
library_dirs=None,
|
572 |
+
runtime_library_dirs=None,
|
573 |
+
export_symbols=None,
|
574 |
+
debug=0,
|
575 |
+
extra_preargs=None,
|
576 |
+
extra_postargs=None,
|
577 |
+
build_temp=None,
|
578 |
+
target_lang=None):
|
579 |
+
|
580 |
+
if not self.initialized:
|
581 |
+
self.initialize()
|
582 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
583 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
584 |
+
runtime_library_dirs)
|
585 |
+
(libraries, library_dirs, runtime_library_dirs) = fixed_args
|
586 |
+
|
587 |
+
if runtime_library_dirs:
|
588 |
+
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
589 |
+
+ str (runtime_library_dirs))
|
590 |
+
|
591 |
+
lib_opts = gen_lib_options(self,
|
592 |
+
library_dirs, runtime_library_dirs,
|
593 |
+
libraries)
|
594 |
+
if output_dir is not None:
|
595 |
+
output_filename = os.path.join(output_dir, output_filename)
|
596 |
+
|
597 |
+
if self._need_link(objects, output_filename):
|
598 |
+
if target_desc == CCompiler.EXECUTABLE:
|
599 |
+
if debug:
|
600 |
+
ldflags = self.ldflags_shared_debug[1:]
|
601 |
+
else:
|
602 |
+
ldflags = self.ldflags_shared[1:]
|
603 |
+
else:
|
604 |
+
if debug:
|
605 |
+
ldflags = self.ldflags_shared_debug
|
606 |
+
else:
|
607 |
+
ldflags = self.ldflags_shared
|
608 |
+
|
609 |
+
export_opts = []
|
610 |
+
for sym in (export_symbols or []):
|
611 |
+
export_opts.append("/EXPORT:" + sym)
|
612 |
+
|
613 |
+
ld_args = (ldflags + lib_opts + export_opts +
|
614 |
+
objects + ['/OUT:' + output_filename])
|
615 |
+
|
616 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
617 |
+
# suppressed by any linker switches. The .lib files may even be
|
618 |
+
# needed! Make sure they are generated in the temporary build
|
619 |
+
# directory. Since they have different names for debug and release
|
620 |
+
# builds, they can go into the same directory.
|
621 |
+
build_temp = os.path.dirname(objects[0])
|
622 |
+
if export_symbols is not None:
|
623 |
+
(dll_name, dll_ext) = os.path.splitext(
|
624 |
+
os.path.basename(output_filename))
|
625 |
+
implib_file = os.path.join(
|
626 |
+
build_temp,
|
627 |
+
self.library_filename(dll_name))
|
628 |
+
ld_args.append ('/IMPLIB:' + implib_file)
|
629 |
+
|
630 |
+
self.manifest_setup_ldargs(output_filename, build_temp, ld_args)
|
631 |
+
|
632 |
+
if extra_preargs:
|
633 |
+
ld_args[:0] = extra_preargs
|
634 |
+
if extra_postargs:
|
635 |
+
ld_args.extend(extra_postargs)
|
636 |
+
|
637 |
+
self.mkpath(os.path.dirname(output_filename))
|
638 |
+
try:
|
639 |
+
self.spawn([self.linker] + ld_args)
|
640 |
+
except DistutilsExecError as msg:
|
641 |
+
raise LinkError(msg)
|
642 |
+
|
643 |
+
# embed the manifest
|
644 |
+
# XXX - this is somewhat fragile - if mt.exe fails, distutils
|
645 |
+
# will still consider the DLL up-to-date, but it will not have a
|
646 |
+
# manifest. Maybe we should link to a temp file? OTOH, that
|
647 |
+
# implies a build environment error that shouldn't go undetected.
|
648 |
+
mfinfo = self.manifest_get_embed_info(target_desc, ld_args)
|
649 |
+
if mfinfo is not None:
|
650 |
+
mffilename, mfid = mfinfo
|
651 |
+
out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
|
652 |
+
try:
|
653 |
+
self.spawn(['mt.exe', '-nologo', '-manifest',
|
654 |
+
mffilename, out_arg])
|
655 |
+
except DistutilsExecError as msg:
|
656 |
+
raise LinkError(msg)
|
657 |
+
else:
|
658 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
659 |
+
|
660 |
+
def manifest_setup_ldargs(self, output_filename, build_temp, ld_args):
|
661 |
+
# If we need a manifest at all, an embedded manifest is recommended.
|
662 |
+
# See MSDN article titled
|
663 |
+
# "How to: Embed a Manifest Inside a C/C++ Application"
|
664 |
+
# (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
|
665 |
+
# Ask the linker to generate the manifest in the temp dir, so
|
666 |
+
# we can check it, and possibly embed it, later.
|
667 |
+
temp_manifest = os.path.join(
|
668 |
+
build_temp,
|
669 |
+
os.path.basename(output_filename) + ".manifest")
|
670 |
+
ld_args.append('/MANIFESTFILE:' + temp_manifest)
|
671 |
+
|
672 |
+
def manifest_get_embed_info(self, target_desc, ld_args):
|
673 |
+
# If a manifest should be embedded, return a tuple of
|
674 |
+
# (manifest_filename, resource_id). Returns None if no manifest
|
675 |
+
# should be embedded. See http://bugs.python.org/issue7833 for why
|
676 |
+
# we want to avoid any manifest for extension modules if we can)
|
677 |
+
for arg in ld_args:
|
678 |
+
if arg.startswith("/MANIFESTFILE:"):
|
679 |
+
temp_manifest = arg.split(":", 1)[1]
|
680 |
+
break
|
681 |
+
else:
|
682 |
+
# no /MANIFESTFILE so nothing to do.
|
683 |
+
return None
|
684 |
+
if target_desc == CCompiler.EXECUTABLE:
|
685 |
+
# by default, executables always get the manifest with the
|
686 |
+
# CRT referenced.
|
687 |
+
mfid = 1
|
688 |
+
else:
|
689 |
+
# Extension modules try and avoid any manifest if possible.
|
690 |
+
mfid = 2
|
691 |
+
temp_manifest = self._remove_visual_c_ref(temp_manifest)
|
692 |
+
if temp_manifest is None:
|
693 |
+
return None
|
694 |
+
return temp_manifest, mfid
|
695 |
+
|
696 |
+
def _remove_visual_c_ref(self, manifest_file):
|
697 |
+
try:
|
698 |
+
# Remove references to the Visual C runtime, so they will
|
699 |
+
# fall through to the Visual C dependency of Python.exe.
|
700 |
+
# This way, when installed for a restricted user (e.g.
|
701 |
+
# runtimes are not in WinSxS folder, but in Python's own
|
702 |
+
# folder), the runtimes do not need to be in every folder
|
703 |
+
# with .pyd's.
|
704 |
+
# Returns either the filename of the modified manifest or
|
705 |
+
# None if no manifest should be embedded.
|
706 |
+
manifest_f = open(manifest_file)
|
707 |
+
try:
|
708 |
+
manifest_buf = manifest_f.read()
|
709 |
+
finally:
|
710 |
+
manifest_f.close()
|
711 |
+
pattern = re.compile(
|
712 |
+
r"""<assemblyIdentity.*?name=("|')Microsoft\."""\
|
713 |
+
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
|
714 |
+
re.DOTALL)
|
715 |
+
manifest_buf = re.sub(pattern, "", manifest_buf)
|
716 |
+
pattern = r"<dependentAssembly>\s*</dependentAssembly>"
|
717 |
+
manifest_buf = re.sub(pattern, "", manifest_buf)
|
718 |
+
# Now see if any other assemblies are referenced - if not, we
|
719 |
+
# don't want a manifest embedded.
|
720 |
+
pattern = re.compile(
|
721 |
+
r"""<assemblyIdentity.*?name=(?:"|')(.+?)(?:"|')"""
|
722 |
+
r""".*?(?:/>|</assemblyIdentity>)""", re.DOTALL)
|
723 |
+
if re.search(pattern, manifest_buf) is None:
|
724 |
+
return None
|
725 |
+
|
726 |
+
manifest_f = open(manifest_file, 'w')
|
727 |
+
try:
|
728 |
+
manifest_f.write(manifest_buf)
|
729 |
+
return manifest_file
|
730 |
+
finally:
|
731 |
+
manifest_f.close()
|
732 |
+
except OSError:
|
733 |
+
pass
|
734 |
+
|
735 |
+
# -- Miscellaneous methods -----------------------------------------
|
736 |
+
# These are all used by the 'gen_lib_options() function, in
|
737 |
+
# ccompiler.py.
|
738 |
+
|
739 |
+
def library_dir_option(self, dir):
|
740 |
+
return "/LIBPATH:" + dir
|
741 |
+
|
742 |
+
def runtime_library_dir_option(self, dir):
|
743 |
+
raise DistutilsPlatformError(
|
744 |
+
"don't know how to set runtime library search path for MSVC++")
|
745 |
+
|
746 |
+
def library_option(self, lib):
|
747 |
+
return self.library_filename(lib)
|
748 |
+
|
749 |
+
|
750 |
+
def find_library_file(self, dirs, lib, debug=0):
|
751 |
+
# Prefer a debugging library if found (and requested), but deal
|
752 |
+
# with it if we don't have one.
|
753 |
+
if debug:
|
754 |
+
try_names = [lib + "_d", lib]
|
755 |
+
else:
|
756 |
+
try_names = [lib]
|
757 |
+
for dir in dirs:
|
758 |
+
for name in try_names:
|
759 |
+
libfile = os.path.join(dir, self.library_filename (name))
|
760 |
+
if os.path.exists(libfile):
|
761 |
+
return libfile
|
762 |
+
else:
|
763 |
+
# Oops, didn't find it in *any* of 'dirs'
|
764 |
+
return None
|
765 |
+
|
766 |
+
# Helper methods for using the MSVC registry settings
|
767 |
+
|
768 |
+
def find_exe(self, exe):
|
769 |
+
"""Return path to an MSVC executable program.
|
770 |
+
|
771 |
+
Tries to find the program in several places: first, one of the
|
772 |
+
MSVC program search paths from the registry; next, the directories
|
773 |
+
in the PATH environment variable. If any of those work, return an
|
774 |
+
absolute path that is known to exist. If none of them work, just
|
775 |
+
return the original program name, 'exe'.
|
776 |
+
"""
|
777 |
+
for p in self.__paths:
|
778 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
779 |
+
if os.path.isfile(fn):
|
780 |
+
return fn
|
781 |
+
|
782 |
+
# didn't find it; try existing path
|
783 |
+
for p in os.environ['Path'].split(';'):
|
784 |
+
fn = os.path.join(os.path.abspath(p),exe)
|
785 |
+
if os.path.isfile(fn):
|
786 |
+
return fn
|
787 |
+
|
788 |
+
return exe
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/msvccompiler.py
ADDED
@@ -0,0 +1,643 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""distutils.msvccompiler
|
2 |
+
|
3 |
+
Contains MSVCCompiler, an implementation of the abstract CCompiler class
|
4 |
+
for the Microsoft Visual Studio.
|
5 |
+
"""
|
6 |
+
|
7 |
+
# Written by Perry Stoll
|
8 |
+
# hacked by Robin Becker and Thomas Heller to do a better job of
|
9 |
+
# finding DevStudio (through the registry)
|
10 |
+
|
11 |
+
import sys, os
|
12 |
+
from distutils.errors import \
|
13 |
+
DistutilsExecError, DistutilsPlatformError, \
|
14 |
+
CompileError, LibError, LinkError
|
15 |
+
from distutils.ccompiler import \
|
16 |
+
CCompiler, gen_lib_options
|
17 |
+
from distutils import log
|
18 |
+
|
19 |
+
_can_read_reg = False
|
20 |
+
try:
|
21 |
+
import winreg
|
22 |
+
|
23 |
+
_can_read_reg = True
|
24 |
+
hkey_mod = winreg
|
25 |
+
|
26 |
+
RegOpenKeyEx = winreg.OpenKeyEx
|
27 |
+
RegEnumKey = winreg.EnumKey
|
28 |
+
RegEnumValue = winreg.EnumValue
|
29 |
+
RegError = winreg.error
|
30 |
+
|
31 |
+
except ImportError:
|
32 |
+
try:
|
33 |
+
import win32api
|
34 |
+
import win32con
|
35 |
+
_can_read_reg = True
|
36 |
+
hkey_mod = win32con
|
37 |
+
|
38 |
+
RegOpenKeyEx = win32api.RegOpenKeyEx
|
39 |
+
RegEnumKey = win32api.RegEnumKey
|
40 |
+
RegEnumValue = win32api.RegEnumValue
|
41 |
+
RegError = win32api.error
|
42 |
+
except ImportError:
|
43 |
+
log.info("Warning: Can't read registry to find the "
|
44 |
+
"necessary compiler setting\n"
|
45 |
+
"Make sure that Python modules winreg, "
|
46 |
+
"win32api or win32con are installed.")
|
47 |
+
pass
|
48 |
+
|
49 |
+
if _can_read_reg:
|
50 |
+
HKEYS = (hkey_mod.HKEY_USERS,
|
51 |
+
hkey_mod.HKEY_CURRENT_USER,
|
52 |
+
hkey_mod.HKEY_LOCAL_MACHINE,
|
53 |
+
hkey_mod.HKEY_CLASSES_ROOT)
|
54 |
+
|
55 |
+
def read_keys(base, key):
|
56 |
+
"""Return list of registry keys."""
|
57 |
+
try:
|
58 |
+
handle = RegOpenKeyEx(base, key)
|
59 |
+
except RegError:
|
60 |
+
return None
|
61 |
+
L = []
|
62 |
+
i = 0
|
63 |
+
while True:
|
64 |
+
try:
|
65 |
+
k = RegEnumKey(handle, i)
|
66 |
+
except RegError:
|
67 |
+
break
|
68 |
+
L.append(k)
|
69 |
+
i += 1
|
70 |
+
return L
|
71 |
+
|
72 |
+
def read_values(base, key):
|
73 |
+
"""Return dict of registry keys and values.
|
74 |
+
|
75 |
+
All names are converted to lowercase.
|
76 |
+
"""
|
77 |
+
try:
|
78 |
+
handle = RegOpenKeyEx(base, key)
|
79 |
+
except RegError:
|
80 |
+
return None
|
81 |
+
d = {}
|
82 |
+
i = 0
|
83 |
+
while True:
|
84 |
+
try:
|
85 |
+
name, value, type = RegEnumValue(handle, i)
|
86 |
+
except RegError:
|
87 |
+
break
|
88 |
+
name = name.lower()
|
89 |
+
d[convert_mbcs(name)] = convert_mbcs(value)
|
90 |
+
i += 1
|
91 |
+
return d
|
92 |
+
|
93 |
+
def convert_mbcs(s):
|
94 |
+
dec = getattr(s, "decode", None)
|
95 |
+
if dec is not None:
|
96 |
+
try:
|
97 |
+
s = dec("mbcs")
|
98 |
+
except UnicodeError:
|
99 |
+
pass
|
100 |
+
return s
|
101 |
+
|
102 |
+
class MacroExpander:
|
103 |
+
def __init__(self, version):
|
104 |
+
self.macros = {}
|
105 |
+
self.load_macros(version)
|
106 |
+
|
107 |
+
def set_macro(self, macro, path, key):
|
108 |
+
for base in HKEYS:
|
109 |
+
d = read_values(base, path)
|
110 |
+
if d:
|
111 |
+
self.macros["$(%s)" % macro] = d[key]
|
112 |
+
break
|
113 |
+
|
114 |
+
def load_macros(self, version):
|
115 |
+
vsbase = r"Software\Microsoft\VisualStudio\%0.1f" % version
|
116 |
+
self.set_macro("VCInstallDir", vsbase + r"\Setup\VC", "productdir")
|
117 |
+
self.set_macro("VSInstallDir", vsbase + r"\Setup\VS", "productdir")
|
118 |
+
net = r"Software\Microsoft\.NETFramework"
|
119 |
+
self.set_macro("FrameworkDir", net, "installroot")
|
120 |
+
try:
|
121 |
+
if version > 7.0:
|
122 |
+
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")
|
123 |
+
else:
|
124 |
+
self.set_macro("FrameworkSDKDir", net, "sdkinstallroot")
|
125 |
+
except KeyError as exc: #
|
126 |
+
raise DistutilsPlatformError(
|
127 |
+
"""Python was built with Visual Studio 2003;
|
128 |
+
extensions must be built with a compiler than can generate compatible binaries.
|
129 |
+
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
|
130 |
+
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.""")
|
131 |
+
|
132 |
+
p = r"Software\Microsoft\NET Framework Setup\Product"
|
133 |
+
for base in HKEYS:
|
134 |
+
try:
|
135 |
+
h = RegOpenKeyEx(base, p)
|
136 |
+
except RegError:
|
137 |
+
continue
|
138 |
+
key = RegEnumKey(h, 0)
|
139 |
+
d = read_values(base, r"%s\%s" % (p, key))
|
140 |
+
self.macros["$(FrameworkVersion)"] = d["version"]
|
141 |
+
|
142 |
+
def sub(self, s):
|
143 |
+
for k, v in self.macros.items():
|
144 |
+
s = s.replace(k, v)
|
145 |
+
return s
|
146 |
+
|
147 |
+
def get_build_version():
|
148 |
+
"""Return the version of MSVC that was used to build Python.
|
149 |
+
|
150 |
+
For Python 2.3 and up, the version number is included in
|
151 |
+
sys.version. For earlier versions, assume the compiler is MSVC 6.
|
152 |
+
"""
|
153 |
+
prefix = "MSC v."
|
154 |
+
i = sys.version.find(prefix)
|
155 |
+
if i == -1:
|
156 |
+
return 6
|
157 |
+
i = i + len(prefix)
|
158 |
+
s, rest = sys.version[i:].split(" ", 1)
|
159 |
+
majorVersion = int(s[:-2]) - 6
|
160 |
+
if majorVersion >= 13:
|
161 |
+
# v13 was skipped and should be v14
|
162 |
+
majorVersion += 1
|
163 |
+
minorVersion = int(s[2:3]) / 10.0
|
164 |
+
# I don't think paths are affected by minor version in version 6
|
165 |
+
if majorVersion == 6:
|
166 |
+
minorVersion = 0
|
167 |
+
if majorVersion >= 6:
|
168 |
+
return majorVersion + minorVersion
|
169 |
+
# else we don't know what version of the compiler this is
|
170 |
+
return None
|
171 |
+
|
172 |
+
def get_build_architecture():
|
173 |
+
"""Return the processor architecture.
|
174 |
+
|
175 |
+
Possible results are "Intel" or "AMD64".
|
176 |
+
"""
|
177 |
+
|
178 |
+
prefix = " bit ("
|
179 |
+
i = sys.version.find(prefix)
|
180 |
+
if i == -1:
|
181 |
+
return "Intel"
|
182 |
+
j = sys.version.find(")", i)
|
183 |
+
return sys.version[i+len(prefix):j]
|
184 |
+
|
185 |
+
def normalize_and_reduce_paths(paths):
|
186 |
+
"""Return a list of normalized paths with duplicates removed.
|
187 |
+
|
188 |
+
The current order of paths is maintained.
|
189 |
+
"""
|
190 |
+
# Paths are normalized so things like: /a and /a/ aren't both preserved.
|
191 |
+
reduced_paths = []
|
192 |
+
for p in paths:
|
193 |
+
np = os.path.normpath(p)
|
194 |
+
# XXX(nnorwitz): O(n**2), if reduced_paths gets long perhaps use a set.
|
195 |
+
if np not in reduced_paths:
|
196 |
+
reduced_paths.append(np)
|
197 |
+
return reduced_paths
|
198 |
+
|
199 |
+
|
200 |
+
class MSVCCompiler(CCompiler) :
|
201 |
+
"""Concrete class that implements an interface to Microsoft Visual C++,
|
202 |
+
as defined by the CCompiler abstract class."""
|
203 |
+
|
204 |
+
compiler_type = 'msvc'
|
205 |
+
|
206 |
+
# Just set this so CCompiler's constructor doesn't barf. We currently
|
207 |
+
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
208 |
+
# as it really isn't necessary for this sort of single-compiler class.
|
209 |
+
# Would be nice to have a consistent interface with UnixCCompiler,
|
210 |
+
# though, so it's worth thinking about.
|
211 |
+
executables = {}
|
212 |
+
|
213 |
+
# Private class data (need to distinguish C from C++ source for compiler)
|
214 |
+
_c_extensions = ['.c']
|
215 |
+
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
216 |
+
_rc_extensions = ['.rc']
|
217 |
+
_mc_extensions = ['.mc']
|
218 |
+
|
219 |
+
# Needed for the filename generation methods provided by the
|
220 |
+
# base class, CCompiler.
|
221 |
+
src_extensions = (_c_extensions + _cpp_extensions +
|
222 |
+
_rc_extensions + _mc_extensions)
|
223 |
+
res_extension = '.res'
|
224 |
+
obj_extension = '.obj'
|
225 |
+
static_lib_extension = '.lib'
|
226 |
+
shared_lib_extension = '.dll'
|
227 |
+
static_lib_format = shared_lib_format = '%s%s'
|
228 |
+
exe_extension = '.exe'
|
229 |
+
|
230 |
+
def __init__(self, verbose=0, dry_run=0, force=0):
|
231 |
+
CCompiler.__init__ (self, verbose, dry_run, force)
|
232 |
+
self.__version = get_build_version()
|
233 |
+
self.__arch = get_build_architecture()
|
234 |
+
if self.__arch == "Intel":
|
235 |
+
# x86
|
236 |
+
if self.__version >= 7:
|
237 |
+
self.__root = r"Software\Microsoft\VisualStudio"
|
238 |
+
self.__macros = MacroExpander(self.__version)
|
239 |
+
else:
|
240 |
+
self.__root = r"Software\Microsoft\Devstudio"
|
241 |
+
self.__product = "Visual Studio version %s" % self.__version
|
242 |
+
else:
|
243 |
+
# Win64. Assume this was built with the platform SDK
|
244 |
+
self.__product = "Microsoft SDK compiler %s" % (self.__version + 6)
|
245 |
+
|
246 |
+
self.initialized = False
|
247 |
+
|
248 |
+
def initialize(self):
|
249 |
+
self.__paths = []
|
250 |
+
if "DISTUTILS_USE_SDK" in os.environ and "MSSdk" in os.environ and self.find_exe("cl.exe"):
|
251 |
+
# Assume that the SDK set up everything alright; don't try to be
|
252 |
+
# smarter
|
253 |
+
self.cc = "cl.exe"
|
254 |
+
self.linker = "link.exe"
|
255 |
+
self.lib = "lib.exe"
|
256 |
+
self.rc = "rc.exe"
|
257 |
+
self.mc = "mc.exe"
|
258 |
+
else:
|
259 |
+
self.__paths = self.get_msvc_paths("path")
|
260 |
+
|
261 |
+
if len(self.__paths) == 0:
|
262 |
+
raise DistutilsPlatformError("Python was built with %s, "
|
263 |
+
"and extensions need to be built with the same "
|
264 |
+
"version of the compiler, but it isn't installed."
|
265 |
+
% self.__product)
|
266 |
+
|
267 |
+
self.cc = self.find_exe("cl.exe")
|
268 |
+
self.linker = self.find_exe("link.exe")
|
269 |
+
self.lib = self.find_exe("lib.exe")
|
270 |
+
self.rc = self.find_exe("rc.exe") # resource compiler
|
271 |
+
self.mc = self.find_exe("mc.exe") # message compiler
|
272 |
+
self.set_path_env_var('lib')
|
273 |
+
self.set_path_env_var('include')
|
274 |
+
|
275 |
+
# extend the MSVC path with the current path
|
276 |
+
try:
|
277 |
+
for p in os.environ['path'].split(';'):
|
278 |
+
self.__paths.append(p)
|
279 |
+
except KeyError:
|
280 |
+
pass
|
281 |
+
self.__paths = normalize_and_reduce_paths(self.__paths)
|
282 |
+
os.environ['path'] = ";".join(self.__paths)
|
283 |
+
|
284 |
+
self.preprocess_options = None
|
285 |
+
if self.__arch == "Intel":
|
286 |
+
self.compile_options = [ '/nologo', '/O2', '/MD', '/W3', '/GX' ,
|
287 |
+
'/DNDEBUG']
|
288 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GX',
|
289 |
+
'/Z7', '/D_DEBUG']
|
290 |
+
else:
|
291 |
+
# Win64
|
292 |
+
self.compile_options = [ '/nologo', '/O2', '/MD', '/W3', '/GS-' ,
|
293 |
+
'/DNDEBUG']
|
294 |
+
self.compile_options_debug = ['/nologo', '/Od', '/MDd', '/W3', '/GS-',
|
295 |
+
'/Z7', '/D_DEBUG']
|
296 |
+
|
297 |
+
self.ldflags_shared = ['/DLL', '/nologo', '/INCREMENTAL:NO']
|
298 |
+
if self.__version >= 7:
|
299 |
+
self.ldflags_shared_debug = [
|
300 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/DEBUG'
|
301 |
+
]
|
302 |
+
else:
|
303 |
+
self.ldflags_shared_debug = [
|
304 |
+
'/DLL', '/nologo', '/INCREMENTAL:no', '/pdb:None', '/DEBUG'
|
305 |
+
]
|
306 |
+
self.ldflags_static = [ '/nologo']
|
307 |
+
|
308 |
+
self.initialized = True
|
309 |
+
|
310 |
+
# -- Worker methods ------------------------------------------------
|
311 |
+
|
312 |
+
def object_filenames(self,
|
313 |
+
source_filenames,
|
314 |
+
strip_dir=0,
|
315 |
+
output_dir=''):
|
316 |
+
# Copied from ccompiler.py, extended to return .res as 'object'-file
|
317 |
+
# for .rc input file
|
318 |
+
if output_dir is None: output_dir = ''
|
319 |
+
obj_names = []
|
320 |
+
for src_name in source_filenames:
|
321 |
+
(base, ext) = os.path.splitext (src_name)
|
322 |
+
base = os.path.splitdrive(base)[1] # Chop off the drive
|
323 |
+
base = base[os.path.isabs(base):] # If abs, chop off leading /
|
324 |
+
if ext not in self.src_extensions:
|
325 |
+
# Better to raise an exception instead of silently continuing
|
326 |
+
# and later complain about sources and targets having
|
327 |
+
# different lengths
|
328 |
+
raise CompileError ("Don't know how to compile %s" % src_name)
|
329 |
+
if strip_dir:
|
330 |
+
base = os.path.basename (base)
|
331 |
+
if ext in self._rc_extensions:
|
332 |
+
obj_names.append (os.path.join (output_dir,
|
333 |
+
base + self.res_extension))
|
334 |
+
elif ext in self._mc_extensions:
|
335 |
+
obj_names.append (os.path.join (output_dir,
|
336 |
+
base + self.res_extension))
|
337 |
+
else:
|
338 |
+
obj_names.append (os.path.join (output_dir,
|
339 |
+
base + self.obj_extension))
|
340 |
+
return obj_names
|
341 |
+
|
342 |
+
|
343 |
+
def compile(self, sources,
|
344 |
+
output_dir=None, macros=None, include_dirs=None, debug=0,
|
345 |
+
extra_preargs=None, extra_postargs=None, depends=None):
|
346 |
+
|
347 |
+
if not self.initialized:
|
348 |
+
self.initialize()
|
349 |
+
compile_info = self._setup_compile(output_dir, macros, include_dirs,
|
350 |
+
sources, depends, extra_postargs)
|
351 |
+
macros, objects, extra_postargs, pp_opts, build = compile_info
|
352 |
+
|
353 |
+
compile_opts = extra_preargs or []
|
354 |
+
compile_opts.append ('/c')
|
355 |
+
if debug:
|
356 |
+
compile_opts.extend(self.compile_options_debug)
|
357 |
+
else:
|
358 |
+
compile_opts.extend(self.compile_options)
|
359 |
+
|
360 |
+
for obj in objects:
|
361 |
+
try:
|
362 |
+
src, ext = build[obj]
|
363 |
+
except KeyError:
|
364 |
+
continue
|
365 |
+
if debug:
|
366 |
+
# pass the full pathname to MSVC in debug mode,
|
367 |
+
# this allows the debugger to find the source file
|
368 |
+
# without asking the user to browse for it
|
369 |
+
src = os.path.abspath(src)
|
370 |
+
|
371 |
+
if ext in self._c_extensions:
|
372 |
+
input_opt = "/Tc" + src
|
373 |
+
elif ext in self._cpp_extensions:
|
374 |
+
input_opt = "/Tp" + src
|
375 |
+
elif ext in self._rc_extensions:
|
376 |
+
# compile .RC to .RES file
|
377 |
+
input_opt = src
|
378 |
+
output_opt = "/fo" + obj
|
379 |
+
try:
|
380 |
+
self.spawn([self.rc] + pp_opts +
|
381 |
+
[output_opt] + [input_opt])
|
382 |
+
except DistutilsExecError as msg:
|
383 |
+
raise CompileError(msg)
|
384 |
+
continue
|
385 |
+
elif ext in self._mc_extensions:
|
386 |
+
# Compile .MC to .RC file to .RES file.
|
387 |
+
# * '-h dir' specifies the directory for the
|
388 |
+
# generated include file
|
389 |
+
# * '-r dir' specifies the target directory of the
|
390 |
+
# generated RC file and the binary message resource
|
391 |
+
# it includes
|
392 |
+
#
|
393 |
+
# For now (since there are no options to change this),
|
394 |
+
# we use the source-directory for the include file and
|
395 |
+
# the build directory for the RC file and message
|
396 |
+
# resources. This works at least for win32all.
|
397 |
+
h_dir = os.path.dirname(src)
|
398 |
+
rc_dir = os.path.dirname(obj)
|
399 |
+
try:
|
400 |
+
# first compile .MC to .RC and .H file
|
401 |
+
self.spawn([self.mc] +
|
402 |
+
['-h', h_dir, '-r', rc_dir] + [src])
|
403 |
+
base, _ = os.path.splitext (os.path.basename (src))
|
404 |
+
rc_file = os.path.join (rc_dir, base + '.rc')
|
405 |
+
# then compile .RC to .RES file
|
406 |
+
self.spawn([self.rc] +
|
407 |
+
["/fo" + obj] + [rc_file])
|
408 |
+
|
409 |
+
except DistutilsExecError as msg:
|
410 |
+
raise CompileError(msg)
|
411 |
+
continue
|
412 |
+
else:
|
413 |
+
# how to handle this file?
|
414 |
+
raise CompileError("Don't know how to compile %s to %s"
|
415 |
+
% (src, obj))
|
416 |
+
|
417 |
+
output_opt = "/Fo" + obj
|
418 |
+
try:
|
419 |
+
self.spawn([self.cc] + compile_opts + pp_opts +
|
420 |
+
[input_opt, output_opt] +
|
421 |
+
extra_postargs)
|
422 |
+
except DistutilsExecError as msg:
|
423 |
+
raise CompileError(msg)
|
424 |
+
|
425 |
+
return objects
|
426 |
+
|
427 |
+
|
428 |
+
def create_static_lib(self,
|
429 |
+
objects,
|
430 |
+
output_libname,
|
431 |
+
output_dir=None,
|
432 |
+
debug=0,
|
433 |
+
target_lang=None):
|
434 |
+
|
435 |
+
if not self.initialized:
|
436 |
+
self.initialize()
|
437 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
438 |
+
output_filename = self.library_filename(output_libname,
|
439 |
+
output_dir=output_dir)
|
440 |
+
|
441 |
+
if self._need_link(objects, output_filename):
|
442 |
+
lib_args = objects + ['/OUT:' + output_filename]
|
443 |
+
if debug:
|
444 |
+
pass # XXX what goes here?
|
445 |
+
try:
|
446 |
+
self.spawn([self.lib] + lib_args)
|
447 |
+
except DistutilsExecError as msg:
|
448 |
+
raise LibError(msg)
|
449 |
+
else:
|
450 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
451 |
+
|
452 |
+
|
453 |
+
def link(self,
|
454 |
+
target_desc,
|
455 |
+
objects,
|
456 |
+
output_filename,
|
457 |
+
output_dir=None,
|
458 |
+
libraries=None,
|
459 |
+
library_dirs=None,
|
460 |
+
runtime_library_dirs=None,
|
461 |
+
export_symbols=None,
|
462 |
+
debug=0,
|
463 |
+
extra_preargs=None,
|
464 |
+
extra_postargs=None,
|
465 |
+
build_temp=None,
|
466 |
+
target_lang=None):
|
467 |
+
|
468 |
+
if not self.initialized:
|
469 |
+
self.initialize()
|
470 |
+
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
471 |
+
fixed_args = self._fix_lib_args(libraries, library_dirs,
|
472 |
+
runtime_library_dirs)
|
473 |
+
(libraries, library_dirs, runtime_library_dirs) = fixed_args
|
474 |
+
|
475 |
+
if runtime_library_dirs:
|
476 |
+
self.warn ("I don't know what to do with 'runtime_library_dirs': "
|
477 |
+
+ str (runtime_library_dirs))
|
478 |
+
|
479 |
+
lib_opts = gen_lib_options(self,
|
480 |
+
library_dirs, runtime_library_dirs,
|
481 |
+
libraries)
|
482 |
+
if output_dir is not None:
|
483 |
+
output_filename = os.path.join(output_dir, output_filename)
|
484 |
+
|
485 |
+
if self._need_link(objects, output_filename):
|
486 |
+
if target_desc == CCompiler.EXECUTABLE:
|
487 |
+
if debug:
|
488 |
+
ldflags = self.ldflags_shared_debug[1:]
|
489 |
+
else:
|
490 |
+
ldflags = self.ldflags_shared[1:]
|
491 |
+
else:
|
492 |
+
if debug:
|
493 |
+
ldflags = self.ldflags_shared_debug
|
494 |
+
else:
|
495 |
+
ldflags = self.ldflags_shared
|
496 |
+
|
497 |
+
export_opts = []
|
498 |
+
for sym in (export_symbols or []):
|
499 |
+
export_opts.append("/EXPORT:" + sym)
|
500 |
+
|
501 |
+
ld_args = (ldflags + lib_opts + export_opts +
|
502 |
+
objects + ['/OUT:' + output_filename])
|
503 |
+
|
504 |
+
# The MSVC linker generates .lib and .exp files, which cannot be
|
505 |
+
# suppressed by any linker switches. The .lib files may even be
|
506 |
+
# needed! Make sure they are generated in the temporary build
|
507 |
+
# directory. Since they have different names for debug and release
|
508 |
+
# builds, they can go into the same directory.
|
509 |
+
if export_symbols is not None:
|
510 |
+
(dll_name, dll_ext) = os.path.splitext(
|
511 |
+
os.path.basename(output_filename))
|
512 |
+
implib_file = os.path.join(
|
513 |
+
os.path.dirname(objects[0]),
|
514 |
+
self.library_filename(dll_name))
|
515 |
+
ld_args.append ('/IMPLIB:' + implib_file)
|
516 |
+
|
517 |
+
if extra_preargs:
|
518 |
+
ld_args[:0] = extra_preargs
|
519 |
+
if extra_postargs:
|
520 |
+
ld_args.extend(extra_postargs)
|
521 |
+
|
522 |
+
self.mkpath(os.path.dirname(output_filename))
|
523 |
+
try:
|
524 |
+
self.spawn([self.linker] + ld_args)
|
525 |
+
except DistutilsExecError as msg:
|
526 |
+
raise LinkError(msg)
|
527 |
+
|
528 |
+
else:
|
529 |
+
log.debug("skipping %s (up-to-date)", output_filename)
|
530 |
+
|
531 |
+
|
532 |
+
# -- Miscellaneous methods -----------------------------------------
|
533 |
+
# These are all used by the 'gen_lib_options() function, in
|
534 |
+
# ccompiler.py.
|
535 |
+
|
536 |
+
def library_dir_option(self, dir):
|
537 |
+
return "/LIBPATH:" + dir
|
538 |
+
|
539 |
+
def runtime_library_dir_option(self, dir):
|
540 |
+
raise DistutilsPlatformError(
|
541 |
+
"don't know how to set runtime library search path for MSVC++")
|
542 |
+
|
543 |
+
def library_option(self, lib):
|
544 |
+
return self.library_filename(lib)
|
545 |
+
|
546 |
+
|
547 |
+
def find_library_file(self, dirs, lib, debug=0):
|
548 |
+
# Prefer a debugging library if found (and requested), but deal
|
549 |
+
# with it if we don't have one.
|
550 |
+
if debug:
|
551 |
+
try_names = [lib + "_d", lib]
|
552 |
+
else:
|
553 |
+
try_names = [lib]
|
554 |
+
for dir in dirs:
|
555 |
+
for name in try_names:
|
556 |
+
libfile = os.path.join(dir, self.library_filename (name))
|
557 |
+
if os.path.exists(libfile):
|
558 |
+
return libfile
|
559 |
+
else:
|
560 |
+
# Oops, didn't find it in *any* of 'dirs'
|
561 |
+
return None
|
562 |
+
|
563 |
+
# Helper methods for using the MSVC registry settings
|
564 |
+
|
565 |
+
def find_exe(self, exe):
|
566 |
+
"""Return path to an MSVC executable program.
|
567 |
+
|
568 |
+
Tries to find the program in several places: first, one of the
|
569 |
+
MSVC program search paths from the registry; next, the directories
|
570 |
+
in the PATH environment variable. If any of those work, return an
|
571 |
+
absolute path that is known to exist. If none of them work, just
|
572 |
+
return the original program name, 'exe'.
|
573 |
+
"""
|
574 |
+
for p in self.__paths:
|
575 |
+
fn = os.path.join(os.path.abspath(p), exe)
|
576 |
+
if os.path.isfile(fn):
|
577 |
+
return fn
|
578 |
+
|
579 |
+
# didn't find it; try existing path
|
580 |
+
for p in os.environ['Path'].split(';'):
|
581 |
+
fn = os.path.join(os.path.abspath(p),exe)
|
582 |
+
if os.path.isfile(fn):
|
583 |
+
return fn
|
584 |
+
|
585 |
+
return exe
|
586 |
+
|
587 |
+
def get_msvc_paths(self, path, platform='x86'):
|
588 |
+
"""Get a list of devstudio directories (include, lib or path).
|
589 |
+
|
590 |
+
Return a list of strings. The list will be empty if unable to
|
591 |
+
access the registry or appropriate registry keys not found.
|
592 |
+
"""
|
593 |
+
if not _can_read_reg:
|
594 |
+
return []
|
595 |
+
|
596 |
+
path = path + " dirs"
|
597 |
+
if self.__version >= 7:
|
598 |
+
key = (r"%s\%0.1f\VC\VC_OBJECTS_PLATFORM_INFO\Win32\Directories"
|
599 |
+
% (self.__root, self.__version))
|
600 |
+
else:
|
601 |
+
key = (r"%s\6.0\Build System\Components\Platforms"
|
602 |
+
r"\Win32 (%s)\Directories" % (self.__root, platform))
|
603 |
+
|
604 |
+
for base in HKEYS:
|
605 |
+
d = read_values(base, key)
|
606 |
+
if d:
|
607 |
+
if self.__version >= 7:
|
608 |
+
return self.__macros.sub(d[path]).split(";")
|
609 |
+
else:
|
610 |
+
return d[path].split(";")
|
611 |
+
# MSVC 6 seems to create the registry entries we need only when
|
612 |
+
# the GUI is run.
|
613 |
+
if self.__version == 6:
|
614 |
+
for base in HKEYS:
|
615 |
+
if read_values(base, r"%s\6.0" % self.__root) is not None:
|
616 |
+
self.warn("It seems you have Visual Studio 6 installed, "
|
617 |
+
"but the expected registry settings are not present.\n"
|
618 |
+
"You must at least run the Visual Studio GUI once "
|
619 |
+
"so that these entries are created.")
|
620 |
+
break
|
621 |
+
return []
|
622 |
+
|
623 |
+
def set_path_env_var(self, name):
|
624 |
+
"""Set environment variable 'name' to an MSVC path type value.
|
625 |
+
|
626 |
+
This is equivalent to a SET command prior to execution of spawned
|
627 |
+
commands.
|
628 |
+
"""
|
629 |
+
|
630 |
+
if name == "lib":
|
631 |
+
p = self.get_msvc_paths("library")
|
632 |
+
else:
|
633 |
+
p = self.get_msvc_paths(name)
|
634 |
+
if p:
|
635 |
+
os.environ[name] = ';'.join(p)
|
636 |
+
|
637 |
+
|
638 |
+
if get_build_version() >= 8.0:
|
639 |
+
log.debug("Importing new compiler from distutils.msvc9compiler")
|
640 |
+
OldMSVCCompiler = MSVCCompiler
|
641 |
+
from distutils.msvc9compiler import MSVCCompiler
|
642 |
+
# get_build_architecture not really relevant now we support cross-compile
|
643 |
+
from distutils.msvc9compiler import MacroExpander
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/py35compat.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import subprocess
|
3 |
+
|
4 |
+
|
5 |
+
def __optim_args_from_interpreter_flags():
|
6 |
+
"""Return a list of command-line arguments reproducing the current
|
7 |
+
optimization settings in sys.flags."""
|
8 |
+
args = []
|
9 |
+
value = sys.flags.optimize
|
10 |
+
if value > 0:
|
11 |
+
args.append("-" + "O" * value)
|
12 |
+
return args
|
13 |
+
|
14 |
+
|
15 |
+
_optim_args_from_interpreter_flags = getattr(
|
16 |
+
subprocess,
|
17 |
+
"_optim_args_from_interpreter_flags",
|
18 |
+
__optim_args_from_interpreter_flags,
|
19 |
+
)
|
llmeval-env/lib/python3.10/site-packages/setuptools/_distutils/py38compat.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def aix_platform(osname, version, release):
|
2 |
+
try:
|
3 |
+
import _aix_support
|
4 |
+
return _aix_support.aix_platform()
|
5 |
+
except ImportError:
|
6 |
+
pass
|
7 |
+
return "%s-%s.%s" % (osname, version, release)
|