Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/config.py @ 79691:05c8928362ee
Merge __next__ method link fixes with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 12 Oct 2012 13:46:37 +0300 |
| parents | 3e26c9033306 |
| children |
| rev | line source |
|---|---|
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
1 """distutils.command.config |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
2 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
3 Implements the Distutils 'config' command, a (mostly) empty command class |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
4 that exists mainly to be sub-classed by specific module distributions and |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
5 applications. The idea is that while every "config" command is different, |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
6 at least they're all named the same, and users always see "config" in the |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
7 list of standard commands. Also, this is a good place to put common |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
8 configure-like tasks: "try to compile this C code", or "figure out where |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
9 this header file lives". |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
10 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
11 |
|
63136
29a3eda89995
reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58558
diff
changeset
|
12 import sys, os, re |
|
53101
8c82b7c51bdd
Merged revisions 71528 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53098
diff
changeset
|
13 |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
14 from distutils.core import Command |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
15 from distutils.errors import DistutilsExecError |
|
63136
29a3eda89995
reverted distutils its 3.1 state. All new work is now happening in disutils2, and distutils is now feature-frozen.
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
58558
diff
changeset
|
16 from distutils.sysconfig import customize_compiler |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21268
diff
changeset
|
17 from distutils import log |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
18 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
19 LANG_EXT = {"c": ".c", "c++": ".cxx"} |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
20 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
21 class config(Command): |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
22 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
23 description = "prepare to build" |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
24 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
25 user_options = [ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
26 ('compiler=', None, |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
27 "specify the compiler type"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
28 ('cc=', None, |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
29 "specify the compiler executable"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
30 ('include-dirs=', 'I', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
31 "list of directories to search for header files"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
32 ('define=', 'D', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
33 "C preprocessor macros to define"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
34 ('undef=', 'U', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
35 "C preprocessor macros to undefine"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
36 ('libraries=', 'l', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
37 "external C libraries to link with"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
38 ('library-dirs=', 'L', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
39 "directories to search for external C libraries"), |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
40 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
41 ('noisy', None, |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
42 "show every action (compile, link, run, ...) taken"), |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
43 ('dump-source', None, |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
44 "dump generated source files before attempting to compile them"), |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
45 ] |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
46 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
47 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
48 # The three standard command methods: since the "config" command |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
49 # does nothing by default, these are empty. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
50 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
51 def initialize_options(self): |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
52 self.compiler = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
53 self.cc = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
54 self.include_dirs = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
55 self.libraries = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
56 self.library_dirs = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
57 |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
58 # maximal output for now |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
59 self.noisy = 1 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
60 self.dump_source = 1 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
61 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
62 # list of temporary files generated along-the-way that we have |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
63 # to clean at some point |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
64 self.temp_files = [] |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
65 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
66 def finalize_options(self): |
|
15213
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
67 if self.include_dirs is None: |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
68 self.include_dirs = self.distribution.include_dirs or [] |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
69 elif isinstance(self.include_dirs, str): |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
70 self.include_dirs = self.include_dirs.split(os.pathsep) |
|
15213
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
71 |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
72 if self.libraries is None: |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
73 self.libraries = [] |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
74 elif isinstance(self.libraries, str): |
|
15213
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
75 self.libraries = [self.libraries] |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
76 |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
77 if self.library_dirs is None: |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
78 self.library_dirs = [] |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
79 elif isinstance(self.library_dirs, str): |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
80 self.library_dirs = self.library_dirs.split(os.pathsep) |
|
15213
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
81 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
82 def run(self): |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
83 pass |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
84 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
85 # Utility methods for actual "config" commands. The interfaces are |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
86 # loosely based on Autoconf macros of similar names. Sub-classes |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
87 # may use these freely. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
88 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
89 def _check_compiler(self): |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
90 """Check that 'self.compiler' really is a CCompiler object; |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
91 if not, make it one. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
92 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
93 # We do this late, and only on-demand, because this is an expensive |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
94 # import. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
95 from distutils.ccompiler import CCompiler, new_compiler |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
96 if not isinstance(self.compiler, CCompiler): |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
13029
diff
changeset
|
97 self.compiler = new_compiler(compiler=self.compiler, |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21268
diff
changeset
|
98 dry_run=self.dry_run, force=1) |
|
27928
e31b39930a31
[Patch #681504] Call customize_compiler in config command
Andrew M. Kuchling <amk@amk.ca>
parents:
27628
diff
changeset
|
99 customize_compiler(self.compiler) |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
100 if self.include_dirs: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
101 self.compiler.set_include_dirs(self.include_dirs) |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
102 if self.libraries: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
103 self.compiler.set_libraries(self.libraries) |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
104 if self.library_dirs: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
105 self.compiler.set_library_dirs(self.library_dirs) |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
106 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
107 def _gen_temp_sourcefile(self, body, headers, lang): |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
108 filename = "_configtest" + LANG_EXT[lang] |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
109 file = open(filename, "w") |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
110 if headers: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
111 for header in headers: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
112 file.write("#include <%s>\n" % header) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
113 file.write("\n") |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
114 file.write(body) |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
115 if body[-1] != "\n": |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
116 file.write("\n") |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
117 file.close() |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
118 return filename |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
119 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
120 def _preprocess(self, body, headers, include_dirs, lang): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
121 src = self._gen_temp_sourcefile(body, headers, lang) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
122 out = "_configtest.i" |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
123 self.temp_files.extend([src, out]) |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
124 self.compiler.preprocess(src, out, include_dirs=include_dirs) |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
125 return (src, out) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
126 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
127 def _compile(self, body, headers, include_dirs, lang): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
128 src = self._gen_temp_sourcefile(body, headers, lang) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
129 if self.dump_source: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
130 dump_file(src, "compiling '%s':" % src) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
131 (obj,) = self.compiler.object_filenames([src]) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
132 self.temp_files.extend([src, obj]) |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
133 self.compiler.compile([src], include_dirs=include_dirs) |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
134 return (src, obj) |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
135 |
|
53090
168482eafb56
Merged revisions 71513 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53086
diff
changeset
|
136 def _link(self, body, headers, include_dirs, libraries, library_dirs, |
|
168482eafb56
Merged revisions 71513 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53086
diff
changeset
|
137 lang): |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
138 (src, obj) = self._compile(body, headers, include_dirs, lang) |
| 21268 | 139 prog = os.path.splitext(os.path.basename(src))[0] |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
140 self.compiler.link_executable([obj], prog, |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
141 libraries=libraries, |
|
26036
771b6f521b95
This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
25174
diff
changeset
|
142 library_dirs=library_dirs, |
|
771b6f521b95
This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
25174
diff
changeset
|
143 target_lang=lang) |
|
19303
cea945764db2
[Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19302
diff
changeset
|
144 |
|
27628
afc9a095a2d5
patch #664131, fix config command on OSX and Linux
Just van Rossum <just@letterror.com>
parents:
26285
diff
changeset
|
145 if self.compiler.exe_extension is not None: |
|
afc9a095a2d5
patch #664131, fix config command on OSX and Linux
Just van Rossum <just@letterror.com>
parents:
26285
diff
changeset
|
146 prog = prog + self.compiler.exe_extension |
|
19303
cea945764db2
[Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19302
diff
changeset
|
147 self.temp_files.append(prog) |
|
cea945764db2
[Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19302
diff
changeset
|
148 |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
149 return (src, obj, prog) |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
150 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
151 def _clean(self, *filenames): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
152 if not filenames: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
153 filenames = self.temp_files |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
154 self.temp_files = [] |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
155 log.info("removing: %s", ' '.join(filenames)) |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
156 for filename in filenames: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
157 try: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
158 os.remove(filename) |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
159 except OSError: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
160 pass |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
161 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
162 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
163 # XXX these ignore the dry-run flag: what to do, what to do? even if |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
164 # you want a dry-run build, you still need some sort of configuration |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
165 # info. My inclination is to make it up to the real config command to |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
166 # consult 'dry_run', and assume a default (minimal) configuration if |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
167 # true. The problem with trying to do it here is that you'd have to |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
168 # return either true or false from all the 'try' methods, neither of |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
169 # which is correct. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
170 |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
171 # XXX need access to the header search path and maybe default macros. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
172 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
173 def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
174 """Construct a source file from 'body' (a string containing lines |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
175 of C/C++ code) and 'headers' (a list of header files to include) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
176 and run it through the preprocessor. Return true if the |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
177 preprocessor succeeded, false if there were any errors. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
178 ('body' probably isn't of much use, but what the heck.) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
179 """ |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
180 from distutils.ccompiler import CompileError |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
181 self._check_compiler() |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
182 ok = True |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
183 try: |
|
19302
ed9abab97107
[Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19206
diff
changeset
|
184 self._preprocess(body, headers, include_dirs, lang) |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
185 except CompileError: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
186 ok = False |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
187 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
188 self._clean() |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
189 return ok |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
190 |
|
53090
168482eafb56
Merged revisions 71513 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53086
diff
changeset
|
191 def search_cpp(self, pattern, body=None, headers=None, include_dirs=None, |
|
168482eafb56
Merged revisions 71513 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53086
diff
changeset
|
192 lang="c"): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
193 """Construct a source file (just like 'try_cpp()'), run it through |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
194 the preprocessor, and return true if any line of the output matches |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
195 'pattern'. 'pattern' should either be a compiled regex object or a |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
196 string containing a regex. If both 'body' and 'headers' are None, |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
197 preprocesses an empty file -- which can be useful to determine the |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
198 symbols the preprocessor and compiler set by default. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
199 """ |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
200 self._check_compiler() |
|
53098
c916f854faeb
Merged revisions 71523 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53090
diff
changeset
|
201 src, out = self._preprocess(body, headers, include_dirs, lang) |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
202 |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
43026
diff
changeset
|
203 if isinstance(pattern, str): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
204 pattern = re.compile(pattern) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
205 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
206 file = open(out) |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
207 match = False |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
208 while True: |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
209 line = file.readline() |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
210 if line == '': |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
211 break |
|
19302
ed9abab97107
[Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19206
diff
changeset
|
212 if pattern.search(line): |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
213 match = True |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
214 break |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
215 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
216 file.close() |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
217 self._clean() |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
218 return match |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
219 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
220 def try_compile(self, body, headers=None, include_dirs=None, lang="c"): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
221 """Try to compile a source file built from 'body' and 'headers'. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
222 Return true on success, false otherwise. |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
223 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
224 from distutils.ccompiler import CompileError |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
225 self._check_compiler() |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
226 try: |
|
19302
ed9abab97107
[Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19206
diff
changeset
|
227 self._compile(body, headers, include_dirs, lang) |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
228 ok = True |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
229 except CompileError: |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
230 ok = False |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
231 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21268
diff
changeset
|
232 log.info(ok and "success!" or "failure.") |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
233 self._clean() |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
234 return ok |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
235 |
|
53090
168482eafb56
Merged revisions 71513 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53086
diff
changeset
|
236 def try_link(self, body, headers=None, include_dirs=None, libraries=None, |
|
168482eafb56
Merged revisions 71513 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53086
diff
changeset
|
237 library_dirs=None, lang="c"): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
238 """Try to compile and link a source file, built from 'body' and |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
239 'headers', to executable form. Return true on success, false |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
240 otherwise. |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
241 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
242 from distutils.ccompiler import CompileError, LinkError |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
243 self._check_compiler() |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
244 try: |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
245 self._link(body, headers, include_dirs, |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
246 libraries, library_dirs, lang) |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
247 ok = True |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
248 except (CompileError, LinkError): |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
249 ok = False |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
250 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21268
diff
changeset
|
251 log.info(ok and "success!" or "failure.") |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
252 self._clean() |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
253 return ok |
| 21268 | 254 |
|
53090
168482eafb56
Merged revisions 71513 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53086
diff
changeset
|
255 def try_run(self, body, headers=None, include_dirs=None, libraries=None, |
|
168482eafb56
Merged revisions 71513 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53086
diff
changeset
|
256 library_dirs=None, lang="c"): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
257 """Try to compile, link to an executable, and run a program |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
258 built from 'body' and 'headers'. Return true on success, false |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
259 otherwise. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
260 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
261 from distutils.ccompiler import CompileError, LinkError |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
262 self._check_compiler() |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
263 try: |
|
19206
de1c2d4d72ba
Fix for NameError caught by PyChecker.
Andrew M. Kuchling <amk@amk.ca>
parents:
15215
diff
changeset
|
264 src, obj, exe = self._link(body, headers, include_dirs, |
|
de1c2d4d72ba
Fix for NameError caught by PyChecker.
Andrew M. Kuchling <amk@amk.ca>
parents:
15215
diff
changeset
|
265 libraries, library_dirs, lang) |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
266 self.spawn([exe]) |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
267 ok = True |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
268 except (CompileError, LinkError, DistutilsExecError): |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
269 ok = False |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
270 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21268
diff
changeset
|
271 log.info(ok and "success!" or "failure.") |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
272 self._clean() |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
273 return ok |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
274 |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
275 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
276 # -- High-level methods -------------------------------------------- |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
277 # (these are the ones that are actually likely to be useful |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
278 # when implementing a real-world config command!) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
279 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
280 def check_func(self, func, headers=None, include_dirs=None, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
281 libraries=None, library_dirs=None, decl=0, call=0): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
282 """Determine if function 'func' is available by constructing a |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
283 source file that refers to 'func', and compiles and links it. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
284 If everything succeeds, returns true; otherwise returns false. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
285 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
286 The constructed source file starts out by including the header |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
287 files listed in 'headers'. If 'decl' is true, it then declares |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
288 'func' (as "int func()"); you probably shouldn't supply 'headers' |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
289 and set 'decl' true in the same call, or you might get errors about |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
290 a conflicting declarations for 'func'. Finally, the constructed |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
291 'main()' function either references 'func' or (if 'call' is true) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
292 calls it. 'libraries' and 'library_dirs' are used when |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
293 linking. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
294 """ |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
295 self._check_compiler() |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
296 body = [] |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
297 if decl: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
298 body.append("int %s ();" % func) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
299 body.append("int main () {") |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
300 if call: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
301 body.append(" %s();" % func) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
302 else: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
303 body.append(" %s;" % func) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
304 body.append("}") |
|
41480
99027c2b3fd2
Remove functions in string module that are also string methods. Also remove:
Neal Norwitz <nnorwitz@gmail.com>
parents:
40775
diff
changeset
|
305 body = "\n".join(body) + "\n" |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
306 |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
307 return self.try_link(body, headers, include_dirs, |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
308 libraries, library_dirs) |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
309 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
310 def check_lib(self, library, library_dirs=None, headers=None, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
311 include_dirs=None, other_libraries=[]): |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
312 """Determine if 'library' is available to be linked against, |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
313 without actually checking that any particular symbols are provided |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
314 by it. 'headers' will be used in constructing the source file to |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
315 be compiled, but the only effect of this is to check if all the |
|
15215
9598650f2bc9
Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents:
15213
diff
changeset
|
316 header files listed are available. Any libraries listed in |
|
9598650f2bc9
Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents:
15213
diff
changeset
|
317 'other_libraries' will be included in the link, in case 'library' |
|
9598650f2bc9
Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents:
15213
diff
changeset
|
318 has symbols that depend on other libraries. |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
319 """ |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
320 self._check_compiler() |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
321 return self.try_link("int main (void) { }", headers, include_dirs, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
322 [library] + other_libraries, library_dirs) |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
323 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
324 def check_header(self, header, include_dirs=None, library_dirs=None, |
|
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
325 lang="c"): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
326 """Determine if the system header file named by 'header_file' |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
327 exists and can be found by the preprocessor; return true if so, |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
328 false otherwise. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
329 """ |
|
25174
29efc2d83ade
Include an empty body when checking for a header file
Andrew M. Kuchling <amk@amk.ca>
parents:
23668
diff
changeset
|
330 return self.try_cpp(body="/* No body */", headers=[header], |
|
29efc2d83ade
Include an empty body when checking for a header file
Andrew M. Kuchling <amk@amk.ca>
parents:
23668
diff
changeset
|
331 include_dirs=include_dirs) |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
332 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
333 |
|
43026
a6d3930b5613
General cleanup, raise normalization in Lib/distutils.
Collin Winter <collinw@gmail.com>
parents:
41558
diff
changeset
|
334 def dump_file(filename, head=None): |
|
53086
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
335 """Dumps a file content into log.info. |
|
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
336 |
|
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
337 If head is not None, will be dumped before the file content. |
|
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
338 """ |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
339 if head is None: |
|
53086
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
340 log.info('%s' % filename) |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
341 else: |
|
53086
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
342 log.info(head) |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
343 file = open(filename) |
|
53086
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
344 try: |
|
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
345 log.info(file.read()) |
|
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
346 finally: |
|
e0723ccee74d
Merged revisions 71509 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
43577
diff
changeset
|
347 file.close() |
