summaryrefslogtreecommitdiff
path: root/setuptools/_distutils/bcppcompiler.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/_distutils/bcppcompiler.py')
-rw-r--r--setuptools/_distutils/bcppcompiler.py245
1 files changed, 130 insertions, 115 deletions
diff --git a/setuptools/_distutils/bcppcompiler.py b/setuptools/_distutils/bcppcompiler.py
index 2eb6d2e9..5d6b8653 100644
--- a/setuptools/_distutils/bcppcompiler.py
+++ b/setuptools/_distutils/bcppcompiler.py
@@ -13,16 +13,30 @@ for the Borland C++ compiler.
import os
-from distutils.errors import \
- DistutilsExecError, \
- CompileError, LibError, LinkError, UnknownFileError
-from distutils.ccompiler import \
- CCompiler, gen_preprocess_options
-from distutils.file_util import write_file
-from distutils.dep_util import newer
-from distutils import log
-
-class BCPPCompiler(CCompiler) :
+import warnings
+
+from .errors import (
+ DistutilsExecError,
+ CompileError,
+ LibError,
+ LinkError,
+ UnknownFileError,
+)
+from .ccompiler import CCompiler, gen_preprocess_options
+from .file_util import write_file
+from .dep_util import newer
+from ._log import log
+
+
+warnings.warn(
+ "bcppcompiler is deprecated and slated to be removed "
+ "in the future. Please discontinue use or file an issue "
+ "with pypa/distutils describing your use case.",
+ DeprecationWarning,
+)
+
+
+class BCPPCompiler(CCompiler):
"""Concrete class that implements an interface to the Borland C/C++
compiler, as defined by the CCompiler abstract class.
"""
@@ -49,11 +63,7 @@ class BCPPCompiler(CCompiler) :
static_lib_format = shared_lib_format = '%s%s'
exe_extension = '.exe'
-
- def __init__ (self,
- verbose=0,
- dry_run=0,
- force=0):
+ def __init__(self, verbose=0, dry_run=0, force=0):
super().__init__(verbose, dry_run, force)
@@ -73,24 +83,31 @@ class BCPPCompiler(CCompiler) :
self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']
self.ldflags_static = []
self.ldflags_exe = ['/Gn', '/q', '/x']
- self.ldflags_exe_debug = ['/Gn', '/q', '/x','/r']
-
+ self.ldflags_exe_debug = ['/Gn', '/q', '/x', '/r']
# -- Worker methods ------------------------------------------------
- def compile(self, sources,
- output_dir=None, macros=None, include_dirs=None, debug=0,
- extra_preargs=None, extra_postargs=None, depends=None):
-
- macros, objects, extra_postargs, pp_opts, build = \
- self._setup_compile(output_dir, macros, include_dirs, sources,
- depends, extra_postargs)
+ def compile( # noqa: C901
+ self,
+ sources,
+ output_dir=None,
+ macros=None,
+ include_dirs=None,
+ debug=0,
+ extra_preargs=None,
+ extra_postargs=None,
+ depends=None,
+ ):
+
+ macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
+ output_dir, macros, include_dirs, sources, depends, extra_postargs
+ )
compile_opts = extra_preargs or []
- compile_opts.append ('-c')
+ compile_opts.append('-c')
if debug:
- compile_opts.extend (self.compile_options_debug)
+ compile_opts.extend(self.compile_options_debug)
else:
- compile_opts.extend (self.compile_options)
+ compile_opts.extend(self.compile_options)
for obj in objects:
try:
@@ -106,14 +123,14 @@ class BCPPCompiler(CCompiler) :
if ext == '.res':
# This is already a binary file -- skip it.
- continue # the 'for' loop
+ continue # the 'for' loop
if ext == '.rc':
# This needs to be compiled to a .res file -- do it now.
try:
- self.spawn (["brcc32", "-fo", obj, src])
+ self.spawn(["brcc32", "-fo", obj, src])
except DistutilsExecError as msg:
raise CompileError(msg)
- continue # the 'for' loop
+ continue # the 'for' loop
# The next two are both for the real compiler.
if ext in self._c_extensions:
@@ -132,9 +149,14 @@ class BCPPCompiler(CCompiler) :
# Note that the source file names must appear at the end of
# the command line.
try:
- self.spawn ([self.cc] + compile_opts + pp_opts +
- [input_opt, output_opt] +
- extra_postargs + [src])
+ self.spawn(
+ [self.cc]
+ + compile_opts
+ + pp_opts
+ + [input_opt, output_opt]
+ + extra_postargs
+ + [src]
+ )
except DistutilsExecError as msg:
raise CompileError(msg)
@@ -142,24 +164,19 @@ class BCPPCompiler(CCompiler) :
# compile ()
+ def create_static_lib(
+ self, objects, output_libname, output_dir=None, debug=0, target_lang=None
+ ):
- def create_static_lib (self,
- objects,
- output_libname,
- output_dir=None,
- debug=0,
- target_lang=None):
+ (objects, output_dir) = self._fix_object_args(objects, output_dir)
+ output_filename = self.library_filename(output_libname, output_dir=output_dir)
- (objects, output_dir) = self._fix_object_args (objects, output_dir)
- output_filename = \
- self.library_filename (output_libname, output_dir=output_dir)
-
- if self._need_link (objects, output_filename):
+ if self._need_link(objects, output_filename):
lib_args = [output_filename, '/u'] + objects
if debug:
- pass # XXX what goes here?
+ pass # XXX what goes here?
try:
- self.spawn ([self.lib] + lib_args)
+ self.spawn([self.lib] + lib_args)
except DistutilsExecError as msg:
raise LibError(msg)
else:
@@ -167,37 +184,41 @@ class BCPPCompiler(CCompiler) :
# create_static_lib ()
-
- def link (self,
- target_desc,
- objects,
- output_filename,
- output_dir=None,
- libraries=None,
- library_dirs=None,
- runtime_library_dirs=None,
- export_symbols=None,
- debug=0,
- extra_preargs=None,
- extra_postargs=None,
- build_temp=None,
- target_lang=None):
+ def link( # noqa: C901
+ self,
+ target_desc,
+ objects,
+ output_filename,
+ output_dir=None,
+ libraries=None,
+ library_dirs=None,
+ runtime_library_dirs=None,
+ export_symbols=None,
+ debug=0,
+ extra_preargs=None,
+ extra_postargs=None,
+ build_temp=None,
+ target_lang=None,
+ ):
# XXX this ignores 'build_temp'! should follow the lead of
# msvccompiler.py
- (objects, output_dir) = self._fix_object_args (objects, output_dir)
- (libraries, library_dirs, runtime_library_dirs) = \
- self._fix_lib_args (libraries, library_dirs, runtime_library_dirs)
+ (objects, output_dir) = self._fix_object_args(objects, output_dir)
+ (libraries, library_dirs, runtime_library_dirs) = self._fix_lib_args(
+ libraries, library_dirs, runtime_library_dirs
+ )
if runtime_library_dirs:
- log.warn("I don't know what to do with 'runtime_library_dirs': %s",
- str(runtime_library_dirs))
+ log.warning(
+ "I don't know what to do with 'runtime_library_dirs': %s",
+ str(runtime_library_dirs),
+ )
if output_dir is not None:
- output_filename = os.path.join (output_dir, output_filename)
+ output_filename = os.path.join(output_dir, output_filename)
- if self._need_link (objects, output_filename):
+ if self._need_link(objects, output_filename):
# Figure out linker args based on type of target.
if target_desc == CCompiler.EXECUTABLE:
@@ -213,20 +234,18 @@ class BCPPCompiler(CCompiler) :
else:
ld_args = self.ldflags_shared[:]
-
# Create a temporary exports file for use by the linker
if export_symbols is None:
def_file = ''
else:
- head, tail = os.path.split (output_filename)
- modname, ext = os.path.splitext (tail)
- temp_dir = os.path.dirname(objects[0]) # preserve tree structure
- def_file = os.path.join (temp_dir, '%s.def' % modname)
+ head, tail = os.path.split(output_filename)
+ modname, ext = os.path.splitext(tail)
+ temp_dir = os.path.dirname(objects[0]) # preserve tree structure
+ def_file = os.path.join(temp_dir, '%s.def' % modname)
contents = ['EXPORTS']
- for sym in (export_symbols or []):
- contents.append(' %s=_%s' % (sym, sym))
- self.execute(write_file, (def_file, contents),
- "writing %s" % def_file)
+ for sym in export_symbols or []:
+ contents.append(' {}=_{}'.format(sym, sym))
+ self.execute(write_file, (def_file, contents), "writing %s" % def_file)
# Borland C++ has problems with '/' in paths
objects2 = map(os.path.normpath, objects)
@@ -241,10 +260,9 @@ class BCPPCompiler(CCompiler) :
else:
objects.append(file)
-
- for l in library_dirs:
- ld_args.append("/L%s" % os.path.normpath(l))
- ld_args.append("/L.") # we sometimes use relative paths
+ for ell in library_dirs:
+ ld_args.append("/L%s" % os.path.normpath(ell))
+ ld_args.append("/L.") # we sometimes use relative paths
# list of object files
ld_args.extend(objects)
@@ -260,7 +278,7 @@ class BCPPCompiler(CCompiler) :
# them. Arghghh!. Apparently it works fine as coded...
# name of dll/exe file
- ld_args.extend([',',output_filename])
+ ld_args.extend([',', output_filename])
# no map file and start libraries
ld_args.append(',,')
@@ -276,24 +294,23 @@ class BCPPCompiler(CCompiler) :
ld_args.append(libfile)
# some default libraries
- ld_args.append ('import32')
- ld_args.append ('cw32mt')
+ ld_args.append('import32')
+ ld_args.append('cw32mt')
# def file for export symbols
- ld_args.extend([',',def_file])
+ ld_args.extend([',', def_file])
# add resource files
ld_args.append(',')
ld_args.extend(resources)
-
if extra_preargs:
ld_args[:0] = extra_preargs
if extra_postargs:
ld_args.extend(extra_postargs)
- self.mkpath (os.path.dirname (output_filename))
+ self.mkpath(os.path.dirname(output_filename))
try:
- self.spawn ([self.linker] + ld_args)
+ self.spawn([self.linker] + ld_args)
except DistutilsExecError as msg:
raise LinkError(msg)
@@ -304,8 +321,7 @@ class BCPPCompiler(CCompiler) :
# -- Miscellaneous methods -----------------------------------------
-
- def find_library_file (self, dirs, lib, debug=0):
+ def find_library_file(self, dirs, lib, debug=0):
# List of effective library names to try, in order of preference:
# xxx_bcpp.lib is better than xxx.lib
# and xxx_d.lib is better than xxx.lib if debug is set
@@ -316,7 +332,7 @@ class BCPPCompiler(CCompiler) :
# compiler they care about, since (almost?) every Windows compiler
# seems to have a different format for static libraries.
if debug:
- dlib = (lib + "_d")
+ dlib = lib + "_d"
try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib)
else:
try_names = (lib + "_bcpp", lib)
@@ -331,43 +347,42 @@ class BCPPCompiler(CCompiler) :
return None
# overwrite the one from CCompiler to support rc and res-files
- def object_filenames (self,
- source_filenames,
- strip_dir=0,
- output_dir=''):
- if output_dir is None: output_dir = ''
+ def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
+ if output_dir is None:
+ output_dir = ''
obj_names = []
for src_name in source_filenames:
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
- (base, ext) = os.path.splitext (os.path.normcase(src_name))
- if ext not in (self.src_extensions + ['.rc','.res']):
- raise UnknownFileError("unknown file type '%s' (from '%s')" % \
- (ext, src_name))
+ (base, ext) = os.path.splitext(os.path.normcase(src_name))
+ if ext not in (self.src_extensions + ['.rc', '.res']):
+ raise UnknownFileError(
+ "unknown file type '{}' (from '{}')".format(ext, src_name)
+ )
if strip_dir:
- base = os.path.basename (base)
+ base = os.path.basename(base)
if ext == '.res':
# these can go unchanged
- obj_names.append (os.path.join (output_dir, base + ext))
+ obj_names.append(os.path.join(output_dir, base + ext))
elif ext == '.rc':
# these need to be compiled to .res-files
- obj_names.append (os.path.join (output_dir, base + '.res'))
+ obj_names.append(os.path.join(output_dir, base + '.res'))
else:
- obj_names.append (os.path.join (output_dir,
- base + self.obj_extension))
+ obj_names.append(os.path.join(output_dir, base + self.obj_extension))
return obj_names
# object_filenames ()
- def preprocess (self,
- source,
- output_file=None,
- macros=None,
- include_dirs=None,
- extra_preargs=None,
- extra_postargs=None):
-
- (_, macros, include_dirs) = \
- self._fix_compile_args(None, macros, include_dirs)
+ def preprocess(
+ self,
+ source,
+ output_file=None,
+ macros=None,
+ include_dirs=None,
+ extra_preargs=None,
+ extra_postargs=None,
+ ):
+
+ (_, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = ['cpp32.exe'] + pp_opts
if output_file is not None: