Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/config.py @ 57303:4aa4c19dfaed legacy-trunk
#1757126: fix typo with the cyrillic_asian alias
| author | Philip Jenvey <pjenvey@underboss.org> |
|---|---|
| date | Tue, 17 Nov 2009 02:42:26 +0000 |
| parents | 098885c6b101 |
| children | 3e2b7965ada9 |
| 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 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
12 __revision__ = "$Id$" |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
13 |
|
53104
098885c6b101
removed string usage and added a test for _clean
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53099
diff
changeset
|
14 import sys, os, re |
|
53099
536f180f66a7
added a test for finalize_options
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53096
diff
changeset
|
15 |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
16 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
|
17 from distutils.errors import DistutilsExecError |
|
27928
e31b39930a31
[Patch #681504] Call customize_compiler in config command
Andrew M. Kuchling <amk@amk.ca>
parents:
27628
diff
changeset
|
18 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
|
19 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
|
20 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
21 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
|
22 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
23 class config(Command): |
|
12864
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 description = "prepare to build" |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
26 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
27 user_options = [ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
28 ('compiler=', 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 type"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
30 ('cc=', None, |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
31 "specify the compiler executable"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
32 ('include-dirs=', 'I', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
33 "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
|
34 ('define=', 'D', |
|
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 define"), |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
36 ('undef=', 'U', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
37 "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
|
38 ('libraries=', 'l', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
39 "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
|
40 ('library-dirs=', 'L', |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
41 "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
|
42 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
43 ('noisy', None, |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
44 "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
|
45 ('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
|
46 "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
|
47 ] |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
48 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
49 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
50 # 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
|
51 # 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
|
52 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
53 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
|
54 self.compiler = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
55 self.cc = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
56 self.include_dirs = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
57 self.libraries = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
58 self.library_dirs = None |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
59 |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
60 # 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
|
61 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
|
62 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
|
63 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
64 # 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
|
65 # 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
|
66 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
|
67 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
68 def finalize_options(self): |
|
15213
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
69 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
|
70 self.include_dirs = self.distribution.include_dirs or [] |
|
53099
536f180f66a7
added a test for finalize_options
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53096
diff
changeset
|
71 elif isinstance(self.include_dirs, str): |
|
536f180f66a7
added a test for finalize_options
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53096
diff
changeset
|
72 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
|
73 |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
74 if self.libraries is None: |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
75 self.libraries = [] |
|
53099
536f180f66a7
added a test for finalize_options
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53096
diff
changeset
|
76 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
|
77 self.libraries = [self.libraries] |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
78 |
|
882cefe21dc3
Bastian Kleineidam: fix up any supplied command-line options.
Greg Ward <gward@python.net>
parents:
14948
diff
changeset
|
79 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
|
80 self.library_dirs = [] |
|
53099
536f180f66a7
added a test for finalize_options
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53096
diff
changeset
|
81 elif isinstance(self.library_dirs, str): |
|
536f180f66a7
added a test for finalize_options
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53096
diff
changeset
|
82 self.library_dirs = self.library_dirs.split(os.pathsep) |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
83 |
|
53104
098885c6b101
removed string usage and added a test for _clean
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53099
diff
changeset
|
84 def run(self): |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
85 pass |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
86 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
87 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
88 # 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
|
89 # 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
|
90 # may use these freely. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
91 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
92 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
|
93 """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
|
94 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
|
95 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
96 # 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
|
97 # import. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
98 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
|
99 if not isinstance(self.compiler, CCompiler): |
|
14948
7acb8bbc215b
Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents:
13029
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 if self.include_dirs: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
104 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
|
105 if self.libraries: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
106 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
|
107 if self.library_dirs: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
108 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
|
109 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
110 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 if headers: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
115 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
|
116 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
|
117 file.write("\n") |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
118 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
|
119 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
|
120 file.write("\n") |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
121 file.close() |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
122 return filename |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
123 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 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
|
135 (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
|
136 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
|
137 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
|
138 return (src, obj) |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
139 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
140 def _link(self, body, headers, include_dirs, libraries, library_dirs, |
|
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
141 lang): |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
142 (src, obj) = self._compile(body, headers, include_dirs, lang) |
| 21268 | 143 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
|
144 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
|
145 libraries=libraries, |
|
26036
771b6f521b95
This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
25174
diff
changeset
|
146 library_dirs=library_dirs, |
|
771b6f521b95
This patch fixes the following bugs:
Gustavo Niemeyer <gustavo@niemeyer.net>
parents:
25174
diff
changeset
|
147 target_lang=lang) |
|
19303
cea945764db2
[Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19302
diff
changeset
|
148 |
|
27628
afc9a095a2d5
patch #664131, fix config command on OSX and Linux
Just van Rossum <just@letterror.com>
parents:
26285
diff
changeset
|
149 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
|
150 prog = prog + self.compiler.exe_extension |
|
19303
cea945764db2
[Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19302
diff
changeset
|
151 self.temp_files.append(prog) |
|
cea945764db2
[Patch #444854 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19302
diff
changeset
|
152 |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
153 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
|
154 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 self.temp_files = [] |
|
53104
098885c6b101
removed string usage and added a test for _clean
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53099
diff
changeset
|
159 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
|
160 for filename in filenames: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
161 try: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
162 os.remove(filename) |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
163 except OSError: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
164 pass |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
165 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
166 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
167 # 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
|
168 # 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
|
169 # 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
|
170 # 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
|
171 # 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
|
172 # 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
|
173 # which is correct. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
174 |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
175 # 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
|
176 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
177 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
|
178 """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
|
179 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
|
180 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
|
181 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
|
182 ('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
|
183 """ |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
184 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
|
185 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
|
186 ok = 1 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
187 try: |
|
19302
ed9abab97107
[Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19206
diff
changeset
|
188 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
|
189 except CompileError: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
190 ok = 0 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
191 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
192 self._clean() |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
193 return ok |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
194 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
195 def search_cpp(self, pattern, body=None, headers=None, include_dirs=None, |
|
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
196 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
|
197 """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
|
198 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
|
199 '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
|
200 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
|
201 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
|
202 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
|
203 """ |
|
53096
26069d3b6891
added a simple test for search_cpp
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53088
diff
changeset
|
204 self._check_compiler() |
|
26069d3b6891
added a simple test for search_cpp
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53088
diff
changeset
|
205 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
|
206 |
|
53096
26069d3b6891
added a simple test for search_cpp
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53088
diff
changeset
|
207 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
|
208 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
|
209 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
210 file = open(out) |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
211 match = 0 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
212 while 1: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
213 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
|
214 if line == '': |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
215 break |
|
19302
ed9abab97107
[Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19206
diff
changeset
|
216 if pattern.search(line): |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
217 match = 1 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
218 break |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
219 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
220 file.close() |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
221 self._clean() |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
222 return match |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
223 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
224 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
|
225 """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
|
226 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
|
227 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
228 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
|
229 self._check_compiler() |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
230 try: |
|
19302
ed9abab97107
[Patch #442530 from twburton]
Andrew M. Kuchling <amk@amk.ca>
parents:
19206
diff
changeset
|
231 self._compile(body, headers, include_dirs, lang) |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
232 ok = 1 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
233 except CompileError: |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
234 ok = 0 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
235 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21268
diff
changeset
|
236 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
|
237 self._clean() |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
238 return ok |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
239 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
240 def try_link(self, body, headers=None, include_dirs=None, libraries=None, |
|
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
241 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
|
242 """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
|
243 '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
|
244 otherwise. |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
245 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
246 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
|
247 self._check_compiler() |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
248 try: |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
249 self._link(body, headers, include_dirs, |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
250 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
|
251 ok = 1 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
252 except (CompileError, LinkError): |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
253 ok = 0 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
254 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21268
diff
changeset
|
255 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
|
256 self._clean() |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
257 return ok |
| 21268 | 258 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
259 def try_run(self, body, headers=None, include_dirs=None, libraries=None, |
|
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
260 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
|
261 """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
|
262 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
|
263 otherwise. |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
264 """ |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
265 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
|
266 self._check_compiler() |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
267 try: |
|
19206
de1c2d4d72ba
Fix for NameError caught by PyChecker.
Andrew M. Kuchling <amk@amk.ca>
parents:
15215
diff
changeset
|
268 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
|
269 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
|
270 self.spawn([exe]) |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
271 ok = 1 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
272 except (CompileError, LinkError, DistutilsExecError): |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
273 ok = 0 |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
274 |
|
23668
ca87119255eb
Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21268
diff
changeset
|
275 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
|
276 self._clean() |
|
12864
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
277 return ok |
|
31d0988da8a9
First crack at the Distutils "config" command. Unlike other commands, this
Greg Ward <gward@python.net>
parents:
diff
changeset
|
278 |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
279 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
280 # -- 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
|
281 # (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
|
282 # 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
|
283 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
284 def check_func(self, func, headers=None, include_dirs=None, |
|
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
285 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
|
286 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
287 """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
|
288 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
|
289 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
|
290 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
291 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
|
292 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
|
293 '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
|
294 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
|
295 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
|
296 '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
|
297 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
|
298 linking. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
299 """ |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
300 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
301 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
|
302 body = [] |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
303 if decl: |
|
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("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
|
305 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
|
306 if call: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
307 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
|
308 else: |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
309 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
|
310 body.append("}") |
|
53104
098885c6b101
removed string usage and added a test for _clean
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53099
diff
changeset
|
311 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
|
312 |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
313 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
|
314 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
|
315 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
316 # check_func () |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
317 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
318 def check_lib(self, library, library_dirs=None, headers=None, |
|
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
319 include_dirs=None, other_libraries=[]): |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
320 """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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 '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
|
326 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
|
327 """ |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
328 self._check_compiler() |
|
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
329 return self.try_link("int main (void) { }", |
|
15215
9598650f2bc9
Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents:
15213
diff
changeset
|
330 headers, include_dirs, |
|
9598650f2bc9
Bastian Kleineidam: make 'check_lib()' more like AC_CHECK_LIB by adding
Greg Ward <gward@python.net>
parents:
15213
diff
changeset
|
331 [library]+other_libraries, library_dirs) |
|
13029
70b16dc6137f
Added 'include_dirs' parameters all over the place.
Greg Ward <gward@python.net>
parents:
12979
diff
changeset
|
332 |
|
53088
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
333 def check_header(self, header, include_dirs=None, library_dirs=None, |
|
754a3f73ff07
pep8-fied the module before adding tests
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
53084
diff
changeset
|
334 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
|
335 """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
|
336 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
|
337 false otherwise. |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
338 """ |
|
25174
29efc2d83ade
Include an empty body when checking for a header file
Andrew M. Kuchling <amk@amk.ca>
parents:
23668
diff
changeset
|
339 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
|
340 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
|
341 |
|
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
342 |
|
53084
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
343 def dump_file(filename, head=None): |
|
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
344 """Dumps a file content into log.info. |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
345 |
|
53084
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
346 If head is not None, will be dumped before the file content. |
|
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
347 """ |
|
12979
400382190364
Fleshed out and added a bunch of useful stuff, notably 'check_func()',
Greg Ward <gward@python.net>
parents:
12864
diff
changeset
|
348 if head is None: |
|
53084
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
349 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
|
350 else: |
|
53084
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
351 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
|
352 file = open(filename) |
|
53084
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
353 try: |
|
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
354 log.info(file.read()) |
|
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
355 finally: |
|
a824431252e0
removed the print statements and added a test
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
51047
diff
changeset
|
356 file.close() |
