Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(10)

Delta Between Two Patch Sets: Lib/distutils/ccompiler.py

Issue 3871: cross and native build of python for mingw32 with distutils
Left Patch Set: Created 9 years, 6 months ago
Right Patch Set: Created 7 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/ctypes/util.py ('k') | Lib/distutils/command/build_ext.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """distutils.ccompiler 1 """distutils.ccompiler
2 2
3 Contains CCompiler, an abstract base class that defines the interface 3 Contains CCompiler, an abstract base class that defines the interface
4 for the Distutils compiler abstraction model.""" 4 for the Distutils compiler abstraction model."""
5
6 __revision__ = "$Id$"
7 5
8 import sys, os, re 6 import sys, os, re
9 from distutils.errors import * 7 from distutils.errors import *
10 from distutils.spawn import spawn 8 from distutils.spawn import spawn
11 from distutils.file_util import move_file 9 from distutils.file_util import move_file
12 from distutils.dir_util import mkpath 10 from distutils.dir_util import mkpath
13 from distutils.dep_util import newer_pairwise, newer_group 11 from distutils.dep_util import newer_pairwise, newer_group
14 from distutils.util import split_quoted, execute 12 from distutils.util import split_quoted, execute
15 from distutils import log 13 from distutils import log
16 14
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 supports dependency tracking, but only at a coarse 557 supports dependency tracking, but only at a coarse
560 granularity. 558 granularity.
561 559
562 Raises CompileError on failure. 560 Raises CompileError on failure.
563 """ 561 """
564 # A concrete compiler class can either override this method 562 # A concrete compiler class can either override this method
565 # entirely or implement _compile(). 563 # entirely or implement _compile().
566 macros, objects, extra_postargs, pp_opts, build = \ 564 macros, objects, extra_postargs, pp_opts, build = \
567 self._setup_compile(output_dir, macros, include_dirs, sources, 565 self._setup_compile(output_dir, macros, include_dirs, sources,
568 depends, extra_postargs) 566 depends, extra_postargs)
567
569 cc_args = self._get_cc_args(pp_opts, debug, extra_preargs) 568 cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
570 569
571 for obj in objects: 570 for obj in objects:
572 try: 571 try:
573 src, ext = build[obj] 572 src, ext = build[obj]
574 except KeyError: 573 except KeyError:
575 continue 574 continue
576 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) 575 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
577 576
578 # Return *all* object filenames, not just the ones we just built. 577 # Return *all* object filenames, not just the ones we just built.
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 if includes is None: 771 if includes is None:
773 includes = [] 772 includes = []
774 if include_dirs is None: 773 if include_dirs is None:
775 include_dirs = [] 774 include_dirs = []
776 if libraries is None: 775 if libraries is None:
777 libraries = [] 776 libraries = []
778 if library_dirs is None: 777 if library_dirs is None:
779 library_dirs = [] 778 library_dirs = []
780 fd, fname = tempfile.mkstemp(".c", funcname, text=True) 779 fd, fname = tempfile.mkstemp(".c", funcname, text=True)
781 f = os.fdopen(fd, "w") 780 f = os.fdopen(fd, "w")
782 for incl in includes: 781 try:
783 f.write("""#include "%s"\n""" % incl) 782 for incl in includes:
784 f.write("""\ 783 f.write("""#include "%s"\n""" % incl)
784 f.write("""\
785 main (int argc, char **argv) { 785 main (int argc, char **argv) {
786 %s(); 786 %s();
787 } 787 }
788 """ % funcname) 788 """ % funcname)
789 f.close() 789 finally:
790 f.close()
790 try: 791 try:
791 objects = self.compile([fname], include_dirs=include_dirs) 792 objects = self.compile([fname], include_dirs=include_dirs)
792 except CompileError: 793 except CompileError:
793 return False 794 return False
794 795
795 try: 796 try:
796 self.link_executable(objects, "a.out", 797 self.link_executable(objects, "a.out",
797 libraries=libraries, 798 libraries=libraries,
798 library_dirs=library_dirs) 799 library_dirs=library_dirs)
799 except (LinkError, TypeError): 800 except (LinkError, TypeError):
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 ones returned by os.name) and platform the common value 942 ones returned by os.name) and platform the common value
942 returned by sys.platform for the platform in question. 943 returned by sys.platform for the platform in question.
943 944
944 The default values are os.name and sys.platform in case the 945 The default values are os.name and sys.platform in case the
945 parameters are not given. 946 parameters are not given.
946 """ 947 """
947 if osname is None: 948 if osname is None:
948 osname = os.name 949 osname = os.name
949 if platform is None: 950 if platform is None:
950 platform = sys.platform 951 platform = sys.platform
951 if 'msys' in sys.builtin_module_names: 952 if osname == "nt" and sys.version.find('GCC') >= 0:
952 # MSys implies that gcc is used, even though we're on NT 953 return 'mingw32'
953 return 'unix'
954 for pattern, compiler in _default_compilers: 954 for pattern, compiler in _default_compilers:
955 if re.match(pattern, platform) is not None or \ 955 if re.match(pattern, platform) is not None or \
956 re.match(pattern, osname) is not None: 956 re.match(pattern, osname) is not None:
957 return compiler 957 return compiler
958 # Default to Unix compiler 958 # Default to Unix compiler
959 return 'unix' 959 return 'unix'
960 960
961 # Map compiler types to (module_name, class_name) pairs -- ie. where to 961 # Map compiler types to (module_name, class_name) pairs -- ie. where to
962 # find the code that implements an interface to this compiler. (The module 962 # find the code that implements an interface to this compiler. (The module
963 # is assumed to be in the 'distutils' package.) 963 # is assumed to be in the 'distutils' package.)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 if lib_dir: 1112 if lib_dir:
1113 lib_file = compiler.find_library_file([lib_dir], lib_name) 1113 lib_file = compiler.find_library_file([lib_dir], lib_name)
1114 if lib_file: 1114 if lib_file:
1115 lib_opts.append(lib_file) 1115 lib_opts.append(lib_file)
1116 else: 1116 else:
1117 compiler.warn("no library file corresponding to " 1117 compiler.warn("no library file corresponding to "
1118 "'%s' found (skipping)" % lib) 1118 "'%s' found (skipping)" % lib)
1119 else: 1119 else:
1120 lib_opts.append(compiler.library_option (lib)) 1120 lib_opts.append(compiler.library_option (lib))
1121 return lib_opts 1121 return lib_opts
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+