ยปCore Development>Code coverage>Lib/packaging/command/build_ext.py

Python code coverage for Lib/packaging/command/build_ext.py

#countcontent
1n/a"""Build extension modules."""
2n/a
3n/aimport os
4n/aimport re
5n/aimport sys
6n/aimport site
7n/aimport sysconfig
8n/a
9n/afrom packaging.util import get_platform
10n/afrom packaging.command.cmd import Command
11n/afrom packaging.errors import (CCompilerError, CompileError, PackagingError,
12n/a PackagingPlatformError, PackagingSetupError)
13n/afrom packaging.compiler import customize_compiler, show_compilers
14n/afrom packaging.util import newer_group
15n/afrom packaging.compiler.extension import Extension
16n/afrom packaging import logger
17n/a
18n/aif os.name == 'nt':
19n/a from packaging.compiler.msvccompiler import get_build_version
20n/a MSVC_VERSION = int(get_build_version())
21n/a
22n/a# An extension name is just a dot-separated list of Python NAMEs (ie.
23n/a# the same as a fully-qualified module name).
24n/aextension_name_re = re.compile \
25n/a (r'^[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*$')
26n/a
27n/a
28n/aclass build_ext(Command):
29n/a
30n/a description = "build C/C++ extension modules (compile/link to build directory)"
31n/a
32n/a # XXX thoughts on how to deal with complex command-line options like
33n/a # these, i.e. how to make it so fancy_getopt can suck them off the
34n/a # command line and turn them into the appropriate
35n/a # lists of tuples of what-have-you.
36n/a # - each command needs a callback to process its command-line options
37n/a # - Command.__init__() needs access to its share of the whole
38n/a # command line (must ultimately come from
39n/a # Distribution.parse_command_line())
40n/a # - it then calls the current command class' option-parsing
41n/a # callback to deal with weird options like -D, which have to
42n/a # parse the option text and churn out some custom data
43n/a # structure
44n/a # - that data structure (in this case, a list of 2-tuples)
45n/a # will then be present in the command object by the time
46n/a # we get to finalize_options() (i.e. the constructor
47n/a # takes care of both command-line and client options
48n/a # in between initialize_options() and finalize_options())
49n/a
50n/a sep_by = " (separated by '%s')" % os.pathsep
51n/a user_options = [
52n/a ('build-lib=', 'b',
53n/a "directory for compiled extension modules"),
54n/a ('build-temp=', 't',
55n/a "directory for temporary files (build by-products)"),
56n/a ('plat-name=', 'p',
57n/a "platform name to cross-compile for, if supported "
58n/a "(default: %s)" % get_platform()),
59n/a ('inplace', 'i',
60n/a "ignore build-lib and put compiled extensions into the source " +
61n/a "directory alongside your pure Python modules"),
62n/a ('user', None,
63n/a "add user include, library and rpath"),
64n/a ('include-dirs=', 'I',
65n/a "list of directories to search for header files" + sep_by),
66n/a ('define=', 'D',
67n/a "C preprocessor macros to define"),
68n/a ('undef=', 'U',
69n/a "C preprocessor macros to undefine"),
70n/a ('libraries=', 'l',
71n/a "external C libraries to link with"),
72n/a ('library-dirs=', 'L',
73n/a "directories to search for external C libraries" + sep_by),
74n/a ('rpath=', 'R',
75n/a "directories to search for shared C libraries at runtime"),
76n/a ('link-objects=', 'O',
77n/a "extra explicit link objects to include in the link"),
78n/a ('debug', 'g',
79n/a "compile/link with debugging information"),
80n/a ('force', 'f',
81n/a "forcibly build everything (ignore file timestamps)"),
82n/a ('compiler=', 'c',
83n/a "specify the compiler type"),
84n/a ('swig-opts=', None,
85n/a "list of SWIG command-line options"),
86n/a ('swig=', None,
87n/a "path to the SWIG executable"),
88n/a ]
89n/a
90n/a boolean_options = ['inplace', 'debug', 'force', 'user']
91n/a
92n/a
93n/a help_options = [
94n/a ('help-compiler', None,
95n/a "list available compilers", show_compilers),
96n/a ]
97n/a
98n/a def initialize_options(self):
99n/a self.extensions = None
100n/a self.build_lib = None
101n/a self.plat_name = None
102n/a self.build_temp = None
103n/a self.inplace = False
104n/a self.package = None
105n/a
106n/a self.include_dirs = None
107n/a self.define = None
108n/a self.undef = None
109n/a self.libraries = None
110n/a self.library_dirs = None
111n/a self.rpath = None
112n/a self.link_objects = None
113n/a self.debug = None
114n/a self.force = None
115n/a self.compiler = None
116n/a self.swig = None
117n/a self.swig_opts = None
118n/a self.user = None
119n/a
120n/a def finalize_options(self):
121n/a self.set_undefined_options('build',
122n/a 'build_lib', 'build_temp', 'compiler',
123n/a 'debug', 'force', 'plat_name')
124n/a
125n/a if self.package is None:
126n/a self.package = self.distribution.ext_package
127n/a
128n/a # Ensure that the list of extensions is valid, i.e. it is a list of
129n/a # Extension objects.
130n/a self.extensions = self.distribution.ext_modules
131n/a if self.extensions:
132n/a if not isinstance(self.extensions, (list, tuple)):
133n/a type_name = (self.extensions is None and 'None'
134n/a or type(self.extensions).__name__)
135n/a raise PackagingSetupError(
136n/a "'ext_modules' must be a sequence of Extension instances,"
137n/a " not %s" % (type_name,))
138n/a for i, ext in enumerate(self.extensions):
139n/a if isinstance(ext, Extension):
140n/a continue # OK! (assume type-checking done
141n/a # by Extension constructor)
142n/a type_name = (ext is None and 'None' or type(ext).__name__)
143n/a raise PackagingSetupError(
144n/a "'ext_modules' item %d must be an Extension instance,"
145n/a " not %s" % (i, type_name))
146n/a
147n/a # Make sure Python's include directories (for Python.h, pyconfig.h,
148n/a # etc.) are in the include search path.
149n/a py_include = sysconfig.get_path('include')
150n/a plat_py_include = sysconfig.get_path('platinclude')
151n/a if self.include_dirs is None:
152n/a self.include_dirs = self.distribution.include_dirs or []
153n/a if isinstance(self.include_dirs, str):
154n/a self.include_dirs = self.include_dirs.split(os.pathsep)
155n/a
156n/a # Put the Python "system" include dir at the end, so that
157n/a # any local include dirs take precedence.
158n/a self.include_dirs.append(py_include)
159n/a if plat_py_include != py_include:
160n/a self.include_dirs.append(plat_py_include)
161n/a
162n/a self.ensure_string_list('libraries')
163n/a
164n/a # Life is easier if we're not forever checking for None, so
165n/a # simplify these options to empty lists if unset
166n/a if self.libraries is None:
167n/a self.libraries = []
168n/a if self.library_dirs is None:
169n/a self.library_dirs = []
170n/a elif isinstance(self.library_dirs, str):
171n/a self.library_dirs = self.library_dirs.split(os.pathsep)
172n/a
173n/a if self.rpath is None:
174n/a self.rpath = []
175n/a elif isinstance(self.rpath, str):
176n/a self.rpath = self.rpath.split(os.pathsep)
177n/a
178n/a # for extensions under windows use different directories
179n/a # for Release and Debug builds.
180n/a # also Python's library directory must be appended to library_dirs
181n/a if os.name == 'nt':
182n/a # the 'libs' directory is for binary installs - we assume that
183n/a # must be the *native* platform. But we don't really support
184n/a # cross-compiling via a binary install anyway, so we let it go.
185n/a # Note that we must use sys.base_exec_prefix here rather than
186n/a # exec_prefix, since the Python libs are not copied to a virtual
187n/a # environment.
188n/a self.library_dirs.append(os.path.join(sys.base_exec_prefix, 'libs'))
189n/a if self.debug:
190n/a self.build_temp = os.path.join(self.build_temp, "Debug")
191n/a else:
192n/a self.build_temp = os.path.join(self.build_temp, "Release")
193n/a
194n/a # Append the source distribution include and library directories,
195n/a # this allows distutils on windows to work in the source tree
196n/a self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
197n/a if MSVC_VERSION >= 9:
198n/a # Use the .lib files for the correct architecture
199n/a if self.plat_name == 'win32':
200n/a suffix = ''
201n/a else:
202n/a # win-amd64 or win-ia64
203n/a suffix = self.plat_name[4:]
204n/a new_lib = os.path.join(sys.exec_prefix, 'PCbuild')
205n/a if suffix:
206n/a new_lib = os.path.join(new_lib, suffix)
207n/a self.library_dirs.append(new_lib)
208n/a
209n/a elif MSVC_VERSION == 8:
210n/a self.library_dirs.append(os.path.join(sys.exec_prefix,
211n/a 'PC', 'VS8.0'))
212n/a elif MSVC_VERSION == 7:
213n/a self.library_dirs.append(os.path.join(sys.exec_prefix,
214n/a 'PC', 'VS7.1'))
215n/a else:
216n/a self.library_dirs.append(os.path.join(sys.exec_prefix,
217n/a 'PC', 'VC6'))
218n/a
219n/a # OS/2 (EMX) doesn't support Debug vs Release builds, but has the
220n/a # import libraries in its "Config" subdirectory
221n/a if os.name == 'os2':
222n/a self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
223n/a
224n/a # for extensions under Cygwin and AtheOS Python's library directory must be
225n/a # appended to library_dirs
226n/a if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
227n/a if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
228n/a # building third party extensions
229n/a self.library_dirs.append(os.path.join(sys.prefix, "lib",
230n/a "python" + sysconfig.get_python_version(),
231n/a "config"))
232n/a else:
233n/a # building python standard extensions
234n/a self.library_dirs.append(os.curdir)
235n/a
236n/a # for extensions under Linux or Solaris with a shared Python library,
237n/a # Python's library directory must be appended to library_dirs
238n/a sysconfig.get_config_var('Py_ENABLE_SHARED')
239n/a if (sys.platform.startswith(('linux', 'gnu', 'sunos'))
240n/a and sysconfig.get_config_var('Py_ENABLE_SHARED')):
241n/a if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
242n/a # building third party extensions
243n/a self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
244n/a else:
245n/a # building python standard extensions
246n/a self.library_dirs.append(os.curdir)
247n/a
248n/a # The argument parsing will result in self.define being a string, but
249n/a # it has to be a list of 2-tuples. All the preprocessor symbols
250n/a # specified by the 'define' option will be set to '1'. Multiple
251n/a # symbols can be separated with commas.
252n/a
253n/a if self.define:
254n/a defines = self.define.split(',')
255n/a self.define = [(symbol, '1') for symbol in defines]
256n/a
257n/a # The option for macros to undefine is also a string from the
258n/a # option parsing, but has to be a list. Multiple symbols can also
259n/a # be separated with commas here.
260n/a if self.undef:
261n/a self.undef = self.undef.split(',')
262n/a
263n/a if self.swig_opts is None:
264n/a self.swig_opts = []
265n/a else:
266n/a self.swig_opts = self.swig_opts.split(' ')
267n/a
268n/a # Finally add the user include and library directories if requested
269n/a if self.user:
270n/a user_include = os.path.join(site.USER_BASE, "include")
271n/a user_lib = os.path.join(site.USER_BASE, "lib")
272n/a if os.path.isdir(user_include):
273n/a self.include_dirs.append(user_include)
274n/a if os.path.isdir(user_lib):
275n/a self.library_dirs.append(user_lib)
276n/a self.rpath.append(user_lib)
277n/a
278n/a def run(self):
279n/a from packaging.compiler import new_compiler
280n/a
281n/a if not self.extensions:
282n/a return
283n/a
284n/a # If we were asked to build any C/C++ libraries, make sure that the
285n/a # directory where we put them is in the library search path for
286n/a # linking extensions.
287n/a if self.distribution.has_c_libraries():
288n/a build_clib = self.get_finalized_command('build_clib')
289n/a self.libraries.extend(build_clib.get_library_names() or [])
290n/a self.library_dirs.append(build_clib.build_clib)
291n/a
292n/a # Setup the CCompiler object that we'll use to do all the
293n/a # compiling and linking
294n/a self.compiler_obj = new_compiler(compiler=self.compiler,
295n/a dry_run=self.dry_run,
296n/a force=self.force)
297n/a
298n/a customize_compiler(self.compiler_obj)
299n/a # If we are cross-compiling, init the compiler now (if we are not
300n/a # cross-compiling, init would not hurt, but people may rely on
301n/a # late initialization of compiler even if they shouldn't...)
302n/a if os.name == 'nt' and self.plat_name != get_platform():
303n/a self.compiler_obj.initialize(self.plat_name)
304n/a
305n/a # And make sure that any compile/link-related options (which might
306n/a # come from the command line or from the setup script) are set in
307n/a # that CCompiler object -- that way, they automatically apply to
308n/a # all compiling and linking done here.
309n/a if self.include_dirs is not None:
310n/a self.compiler_obj.set_include_dirs(self.include_dirs)
311n/a if self.define is not None:
312n/a # 'define' option is a list of (name,value) tuples
313n/a for name, value in self.define:
314n/a self.compiler_obj.define_macro(name, value)
315n/a if self.undef is not None:
316n/a for macro in self.undef:
317n/a self.compiler_obj.undefine_macro(macro)
318n/a if self.libraries is not None:
319n/a self.compiler_obj.set_libraries(self.libraries)
320n/a if self.library_dirs is not None:
321n/a self.compiler_obj.set_library_dirs(self.library_dirs)
322n/a if self.rpath is not None:
323n/a self.compiler_obj.set_runtime_library_dirs(self.rpath)
324n/a if self.link_objects is not None:
325n/a self.compiler_obj.set_link_objects(self.link_objects)
326n/a
327n/a # Now actually compile and link everything.
328n/a self.build_extensions()
329n/a
330n/a def get_source_files(self):
331n/a filenames = []
332n/a
333n/a # Wouldn't it be neat if we knew the names of header files too...
334n/a for ext in self.extensions:
335n/a filenames.extend(ext.sources)
336n/a
337n/a return filenames
338n/a
339n/a def get_outputs(self):
340n/a # And build the list of output (built) filenames. Note that this
341n/a # ignores the 'inplace' flag, and assumes everything goes in the
342n/a # "build" tree.
343n/a outputs = []
344n/a for ext in self.extensions:
345n/a outputs.append(self.get_ext_fullpath(ext.name))
346n/a return outputs
347n/a
348n/a def build_extensions(self):
349n/a for ext in self.extensions:
350n/a try:
351n/a self.build_extension(ext)
352n/a except (CCompilerError, PackagingError, CompileError) as e:
353n/a if not ext.optional:
354n/a raise
355n/a logger.warning('%s: building extension %r failed: %s',
356n/a self.get_command_name(), ext.name, e)
357n/a
358n/a def build_extension(self, ext):
359n/a sources = ext.sources
360n/a if sources is None or not isinstance(sources, (list, tuple)):
361n/a raise PackagingSetupError(("in 'ext_modules' option (extension '%s'), " +
362n/a "'sources' must be present and must be " +
363n/a "a list of source filenames") % ext.name)
364n/a sources = list(sources)
365n/a
366n/a ext_path = self.get_ext_fullpath(ext.name)
367n/a depends = sources + ext.depends
368n/a if not (self.force or newer_group(depends, ext_path, 'newer')):
369n/a logger.debug("skipping '%s' extension (up-to-date)", ext.name)
370n/a return
371n/a else:
372n/a logger.info("building '%s' extension", ext.name)
373n/a
374n/a # First, scan the sources for SWIG definition files (.i), run
375n/a # SWIG on 'em to create .c files, and modify the sources list
376n/a # accordingly.
377n/a sources = self.swig_sources(sources, ext)
378n/a
379n/a # Next, compile the source code to object files.
380n/a
381n/a # XXX not honouring 'define_macros' or 'undef_macros' -- the
382n/a # CCompiler API needs to change to accommodate this, and I
383n/a # want to do one thing at a time!
384n/a
385n/a # Two possible sources for extra compiler arguments:
386n/a # - 'extra_compile_args' in Extension object
387n/a # - CFLAGS environment variable (not particularly
388n/a # elegant, but people seem to expect it and I
389n/a # guess it's useful)
390n/a # The environment variable should take precedence, and
391n/a # any sensible compiler will give precedence to later
392n/a # command-line args. Hence we combine them in order:
393n/a extra_args = ext.extra_compile_args or []
394n/a
395n/a macros = ext.define_macros[:]
396n/a for undef in ext.undef_macros:
397n/a macros.append((undef,))
398n/a
399n/a objects = self.compiler_obj.compile(sources,
400n/a output_dir=self.build_temp,
401n/a macros=macros,
402n/a include_dirs=ext.include_dirs,
403n/a debug=self.debug,
404n/a extra_postargs=extra_args,
405n/a depends=ext.depends)
406n/a
407n/a # XXX -- this is a Vile HACK!
408n/a #
409n/a # The setup.py script for Python on Unix needs to be able to
410n/a # get this list so it can perform all the clean up needed to
411n/a # avoid keeping object files around when cleaning out a failed
412n/a # build of an extension module. Since Packaging does not
413n/a # track dependencies, we have to get rid of intermediates to
414n/a # ensure all the intermediates will be properly re-built.
415n/a #
416n/a self._built_objects = objects[:]
417n/a
418n/a # Now link the object files together into a "shared object" --
419n/a # of course, first we have to figure out all the other things
420n/a # that go into the mix.
421n/a if ext.extra_objects:
422n/a objects.extend(ext.extra_objects)
423n/a extra_args = ext.extra_link_args or []
424n/a
425n/a # Detect target language, if not provided
426n/a language = ext.language or self.compiler_obj.detect_language(sources)
427n/a
428n/a self.compiler_obj.link_shared_object(
429n/a objects, ext_path,
430n/a libraries=self.get_libraries(ext),
431n/a library_dirs=ext.library_dirs,
432n/a runtime_library_dirs=ext.runtime_library_dirs,
433n/a extra_postargs=extra_args,
434n/a export_symbols=self.get_export_symbols(ext),
435n/a debug=self.debug,
436n/a build_temp=self.build_temp,
437n/a target_lang=language)
438n/a
439n/a
440n/a def swig_sources(self, sources, extension):
441n/a """Walk the list of source files in 'sources', looking for SWIG
442n/a interface (.i) files. Run SWIG on all that are found, and
443n/a return a modified 'sources' list with SWIG source files replaced
444n/a by the generated C (or C++) files.
445n/a """
446n/a new_sources = []
447n/a swig_sources = []
448n/a swig_targets = {}
449n/a
450n/a # XXX this drops generated C/C++ files into the source tree, which
451n/a # is fine for developers who want to distribute the generated
452n/a # source -- but there should be an option to put SWIG output in
453n/a # the temp dir.
454n/a
455n/a if ('-c++' in self.swig_opts or '-c++' in extension.swig_opts):
456n/a target_ext = '.cpp'
457n/a else:
458n/a target_ext = '.c'
459n/a
460n/a for source in sources:
461n/a base, ext = os.path.splitext(source)
462n/a if ext == ".i": # SWIG interface file
463n/a new_sources.append(base + '_wrap' + target_ext)
464n/a swig_sources.append(source)
465n/a swig_targets[source] = new_sources[-1]
466n/a else:
467n/a new_sources.append(source)
468n/a
469n/a if not swig_sources:
470n/a return new_sources
471n/a
472n/a swig = self.swig or self.find_swig()
473n/a swig_cmd = [swig, "-python"]
474n/a swig_cmd.extend(self.swig_opts)
475n/a
476n/a # Do not override commandline arguments
477n/a if not self.swig_opts:
478n/a for o in extension.swig_opts:
479n/a swig_cmd.append(o)
480n/a
481n/a for source in swig_sources:
482n/a target = swig_targets[source]
483n/a logger.info("swigging %s to %s", source, target)
484n/a self.spawn(swig_cmd + ["-o", target, source])
485n/a
486n/a return new_sources
487n/a
488n/a def find_swig(self):
489n/a """Return the name of the SWIG executable. On Unix, this is
490n/a just "swig" -- it should be in the PATH. Tries a bit harder on
491n/a Windows.
492n/a """
493n/a
494n/a if os.name == "posix":
495n/a return "swig"
496n/a elif os.name == "nt":
497n/a
498n/a # Look for SWIG in its standard installation directory on
499n/a # Windows (or so I presume!). If we find it there, great;
500n/a # if not, act like Unix and assume it's in the PATH.
501n/a for vers in ("1.3", "1.2", "1.1"):
502n/a fn = os.path.join("c:\\swig%s" % vers, "swig.exe")
503n/a if os.path.isfile(fn):
504n/a return fn
505n/a else:
506n/a return "swig.exe"
507n/a
508n/a elif os.name == "os2":
509n/a # assume swig available in the PATH.
510n/a return "swig.exe"
511n/a
512n/a else:
513n/a raise PackagingPlatformError(("I don't know how to find (much less run) SWIG "
514n/a "on platform '%s'") % os.name)
515n/a
516n/a # -- Name generators -----------------------------------------------
517n/a # (extension names, filenames, whatever)
518n/a def get_ext_fullpath(self, ext_name):
519n/a """Returns the path of the filename for a given extension.
520n/a
521n/a The file is located in `build_lib` or directly in the package
522n/a (inplace option).
523n/a """
524n/a fullname = self.get_ext_fullname(ext_name)
525n/a modpath = fullname.split('.')
526n/a filename = self.get_ext_filename(modpath[-1])
527n/a
528n/a if not self.inplace:
529n/a # no further work needed
530n/a # returning :
531n/a # build_dir/package/path/filename
532n/a filename = os.path.join(*modpath[:-1]+[filename])
533n/a return os.path.join(self.build_lib, filename)
534n/a
535n/a # the inplace option requires to find the package directory
536n/a # using the build_py command for that
537n/a package = '.'.join(modpath[0:-1])
538n/a build_py = self.get_finalized_command('build_py')
539n/a package_dir = os.path.abspath(build_py.get_package_dir(package))
540n/a
541n/a # returning
542n/a # package_dir/filename
543n/a return os.path.join(package_dir, filename)
544n/a
545n/a def get_ext_fullname(self, ext_name):
546n/a """Returns the fullname of a given extension name.
547n/a
548n/a Adds the `package.` prefix"""
549n/a if self.package is None:
550n/a return ext_name
551n/a else:
552n/a return self.package + '.' + ext_name
553n/a
554n/a def get_ext_filename(self, ext_name):
555n/a r"""Convert the name of an extension (eg. "foo.bar") into the name
556n/a of the file from which it will be loaded (eg. "foo/bar.so", or
557n/a "foo\bar.pyd").
558n/a """
559n/a ext_path = ext_name.split('.')
560n/a # OS/2 has an 8 character module (extension) limit :-(
561n/a if os.name == "os2":
562n/a ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
563n/a # extensions in debug_mode are named 'module_d.pyd' under windows
564n/a so_ext = sysconfig.get_config_var('SO')
565n/a if os.name == 'nt' and self.debug:
566n/a return os.path.join(*ext_path) + '_d' + so_ext
567n/a return os.path.join(*ext_path) + so_ext
568n/a
569n/a def get_export_symbols(self, ext):
570n/a """Return the list of symbols that a shared extension has to
571n/a export. This either uses 'ext.export_symbols' or, if it's not
572n/a provided, "init" + module_name. Only relevant on Windows, where
573n/a the .pyd file (DLL) must export the module "init" function.
574n/a """
575n/a initfunc_name = "PyInit_" + ext.name.split('.')[-1]
576n/a if initfunc_name not in ext.export_symbols:
577n/a ext.export_symbols.append(initfunc_name)
578n/a return ext.export_symbols
579n/a
580n/a def get_libraries(self, ext):
581n/a """Return the list of libraries to link against when building a
582n/a shared extension. On most platforms, this is just 'ext.libraries';
583n/a on Windows and OS/2, we add the Python library (eg. python20.dll).
584n/a """
585n/a # The python library is always needed on Windows. For MSVC, this
586n/a # is redundant, since the library is mentioned in a pragma in
587n/a # pyconfig.h that MSVC groks. The other Windows compilers all seem
588n/a # to need it mentioned explicitly, though, so that's what we do.
589n/a # Append '_d' to the python import library on debug builds.
590n/a if sys.platform == "win32":
591n/a from packaging.compiler.msvccompiler import MSVCCompiler
592n/a if not isinstance(self.compiler_obj, MSVCCompiler):
593n/a template = "python%d%d"
594n/a if self.debug:
595n/a template = template + '_d'
596n/a pythonlib = template % sys.version_info[:2]
597n/a # don't extend ext.libraries, it may be shared with other
598n/a # extensions, it is a reference to the original list
599n/a return ext.libraries + [pythonlib]
600n/a else:
601n/a return ext.libraries
602n/a elif sys.platform == "os2emx":
603n/a # EMX/GCC requires the python library explicitly, and I
604n/a # believe VACPP does as well (though not confirmed) - AIM Apr01
605n/a template = "python%d%d"
606n/a # debug versions of the main DLL aren't supported, at least
607n/a # not at this time - AIM Apr01
608n/a #if self.debug:
609n/a # template = template + '_d'
610n/a pythonlib = template % sys.version_info[:2]
611n/a # don't extend ext.libraries, it may be shared with other
612n/a # extensions, it is a reference to the original list
613n/a return ext.libraries + [pythonlib]
614n/a elif sys.platform[:6] == "cygwin":
615n/a template = "python%d.%d"
616n/a pythonlib = template % sys.version_info[:2]
617n/a # don't extend ext.libraries, it may be shared with other
618n/a # extensions, it is a reference to the original list
619n/a return ext.libraries + [pythonlib]
620n/a elif sys.platform[:6] == "atheos":
621n/a template = "python%d.%d"
622n/a pythonlib = template % sys.version_info[:2]
623n/a # Get SHLIBS from Makefile
624n/a extra = []
625n/a for lib in sysconfig.get_config_var('SHLIBS').split():
626n/a if lib.startswith('-l'):
627n/a extra.append(lib[2:])
628n/a else:
629n/a extra.append(lib)
630n/a # don't extend ext.libraries, it may be shared with other
631n/a # extensions, it is a reference to the original list
632n/a return ext.libraries + [pythonlib, "m"] + extra
633n/a
634n/a elif sys.platform == 'darwin':
635n/a # Don't use the default code below
636n/a return ext.libraries
637n/a
638n/a else:
639n/a if sysconfig.get_config_var('Py_ENABLE_SHARED'):
640n/a template = 'python%d.%d' + sys.abiflags
641n/a pythonlib = template % sys.version_info[:2]
642n/a return ext.libraries + [pythonlib]
643n/a else:
644n/a return ext.libraries