annotate Lib/distutils/command/config.py @ 80661:94de77bd0b4b 2.7

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