annotate Lib/distutils/command/build_clib.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 6240ff5dfebe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11898
4679bcef7a4f Renamed 'build_lib' command to 'build_clib':
Greg Ward <gward@python.net>
parents: 11897
diff changeset
1 """distutils.command.build_clib
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
2
11898
4679bcef7a4f Renamed 'build_lib' command to 'build_clib':
Greg Ward <gward@python.net>
parents: 11897
diff changeset
3 Implements the Distutils 'build_clib' command, to build a C/C++ library
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
4 that is included in the module distribution and needed by an extension
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
5 module."""
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
6
11897
017e592c0fd2 Changed '__rcsid__' to '__revision__'.
Greg Ward <gward@python.net>
parents: 11895
diff changeset
7 __revision__ = "$Id$"
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
8
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
9
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
10 # XXX this module has *lots* of code ripped-off quite transparently from
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
11 # build_ext.py -- not surprisingly really, as the work required to build
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
12 # a static library from a collection of C source files is not really all
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
13 # that different from what's required to build a shared object file from
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
14 # a collection of C source files. Nevertheless, I haven't done the
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
15 # necessary refactoring to account for the overlap in code between the
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
16 # two modules, mainly because a number of subtle details changed in the
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
17 # cut 'n paste. Sigh.
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
18
53843
35597d3dbd08 removed string.split usage
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53839
diff changeset
19 import os
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
20 from distutils.core import Command
57847
3e2b7965ada9 massive import cleaning in Distutils
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53886
diff changeset
21 from distutils.errors import DistutilsSetupError
74871
6240ff5dfebe Issue #13994: Earler partial revert of Distutils enhancements in 2.7
Ned Deily <nad@acm.org>
parents: 64546
diff changeset
22 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
23 from distutils import log
12999
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
24
53886
4c3a84e54d08 removed remaining spaces
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53843
diff changeset
25 def show_compilers():
12999
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
26 from distutils.ccompiler import show_compilers
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
27 show_compilers()
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
28
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
29
53886
4c3a84e54d08 removed remaining spaces
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53843
diff changeset
30 class build_clib(Command):
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
31
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
32 description = "build C/C++ libraries used by Python extensions"
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
33
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
34 user_options = [
64546
03a6f7839d6d Merged revisions 84608 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 58450
diff changeset
35 ('build-clib=', 'b',
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
36 "directory to build C/C++ libraries to"),
64546
03a6f7839d6d Merged revisions 84608 via svnmerge from
Éric Araujo <merwok@netwok.org>
parents: 58450
diff changeset
37 ('build-temp=', 't',
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
38 "directory to put temporary build by-products"),
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
39 ('debug', 'g',
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
40 "compile with debugging information"),
12314
20a5cbf9fcc0 Added '--force' option -- very clear what it means for building (ignore
Greg Ward <gward@python.net>
parents: 12166
diff changeset
41 ('force', 'f',
12670
2feb9790b404 Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12407
diff changeset
42 "forcibly build everything (ignore file timestamps)"),
2feb9790b404 Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12407
diff changeset
43 ('compiler=', 'c',
2feb9790b404 Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12407
diff changeset
44 "specify the compiler type"),
11815
03902bc0214a Renamed all 'options' class attributes to 'user_options'.
Greg Ward <gward@python.net>
parents: 11813
diff changeset
45 ]
12997
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
46
14829
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 13011
diff changeset
47 boolean_options = ['debug', 'force']
b1f220f636ed Added 'boolean_options' list to support config file parsing.
Greg Ward <gward@python.net>
parents: 13011
diff changeset
48
12869
88872791998a Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents: 12743
diff changeset
49 help_options = [
88872791998a Patch from Rene Liebscher: this adds "--help-foo" options to list the
Greg Ward <gward@python.net>
parents: 12743
diff changeset
50 ('help-compiler', None,
12997
27f3a18fd296 Stylistic/formatting changes to Rene Liebscher's '--help-xxx' patch.
Greg Ward <gward@python.net>
parents: 12869
diff changeset
51 "list available compilers", show_compilers),
15216
a3975d2811f0 Untabified.
Greg Ward <gward@python.net>
parents: 14948
diff changeset
52 ]
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
53
53835
e620701a3ec8 pep8-fied build_clib module : it is now similar to the one in 3.x
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53830
diff changeset
54 def initialize_options(self):
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
55 self.build_clib = None
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
56 self.build_temp = None
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
57
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
58 # List of libraries to build
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
59 self.libraries = None
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
60
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
61 # Compilation options for all libraries
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
62 self.include_dirs = None
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
63 self.define = None
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
64 self.undef = None
11732
c976d693ddeb Added 'debug' option, and changed compile/link calls to use it.
Greg Ward <gward@python.net>
parents: 11713
diff changeset
65 self.debug = None
12314
20a5cbf9fcc0 Added '--force' option -- very clear what it means for building (ignore
Greg Ward <gward@python.net>
parents: 12166
diff changeset
66 self.force = 0
12670
2feb9790b404 Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12407
diff changeset
67 self.compiler = None
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
68
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
69
53835
e620701a3ec8 pep8-fied build_clib module : it is now similar to the one in 3.x
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53830
diff changeset
70 def finalize_options(self):
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
71 # This might be confusing: both build-clib and build-temp default
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
72 # to build-temp as defined by the "build" command. This is because
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
73 # I think that C libraries are really just temporary build
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
74 # by-products, at least from the point of view of building Python
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
75 # extensions -- but I want to keep my options open.
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
76 self.set_undefined_options('build',
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
77 ('build_temp', 'build_clib'),
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
78 ('build_temp', 'build_temp'),
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
79 ('compiler', 'compiler'),
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
80 ('debug', 'debug'),
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
81 ('force', 'force'))
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
82
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
83 self.libraries = self.distribution.libraries
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
84 if self.libraries:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
85 self.check_library_list(self.libraries)
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
86
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
87 if self.include_dirs is None:
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
88 self.include_dirs = self.distribution.include_dirs or []
53839
cac2a5f4b9fa more build_clib cleanup + test coverage
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53835
diff changeset
89 if isinstance(self.include_dirs, str):
53843
35597d3dbd08 removed string.split usage
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53839
diff changeset
90 self.include_dirs = self.include_dirs.split(os.pathsep)
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
91
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
92 # XXX same as for build_ext -- what about 'self.define' and
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
93 # 'self.undef' ?
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
94
53835
e620701a3ec8 pep8-fied build_clib module : it is now similar to the one in 3.x
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53830
diff changeset
95 def run(self):
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
96 if not self.libraries:
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
97 return
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
98
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
99 # Yech -- this is cut 'n pasted from build_ext.py!
12999
7160b52ca74a Changed so all the help-generating functions are defined, at module-level,
Greg Ward <gward@python.net>
parents: 12997
diff changeset
100 from distutils.ccompiler import new_compiler
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
101 self.compiler = new_compiler(compiler=self.compiler,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
102 dry_run=self.dry_run,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
103 force=self.force)
13011
37401ec2e910 Call 'customize_compiler()' after getting CCompiler object.
Greg Ward <gward@python.net>
parents: 12999
diff changeset
104 customize_compiler(self.compiler)
12670
2feb9790b404 Fix from Lyle Johnson: add the '--compiler' option.
Gregory P. Smith <greg@mad-scientist.com>
parents: 12407
diff changeset
105
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
106 if self.include_dirs is not None:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
107 self.compiler.set_include_dirs(self.include_dirs)
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
108 if self.define is not None:
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
109 # 'define' option is a list of (name,value) tuples
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
110 for (name,value) in self.define:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
111 self.compiler.define_macro(name, value)
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
112 if self.undef is not None:
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
113 for macro in self.undef:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
114 self.compiler.undefine_macro(macro)
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
115
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
116 self.build_libraries(self.libraries)
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
117
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
118
53830
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
119 def check_library_list(self, libraries):
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
120 """Ensure that the list of libraries is valid.
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
121
53830
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
122 `library` is presumably provided as a command option 'libraries'.
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
123 This method checks that it is a list of 2-tuples, where the tuples
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
124 are (library_name, build_info_dict).
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
125
53830
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
126 Raise DistutilsSetupError if the structure is invalid anywhere;
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
127 just returns otherwise.
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
128 """
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
129 if not isinstance(libraries, list):
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12314
diff changeset
130 raise DistutilsSetupError, \
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
131 "'libraries' option must be a list of tuples"
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
132
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
133 for lib in libraries:
53830
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
134 if not isinstance(lib, tuple) and len(lib) != 2:
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12314
diff changeset
135 raise DistutilsSetupError, \
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
136 "each element of 'libraries' must a 2-tuple"
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
137
53830
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
138 name, build_info = lib
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
139
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
140 if not isinstance(name, str):
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12314
diff changeset
141 raise DistutilsSetupError, \
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
142 "first element of each tuple in 'libraries' " + \
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
143 "must be a string (the library name)"
53830
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
144 if '/' in name or (os.sep != '/' and os.sep in name):
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12314
diff changeset
145 raise DistutilsSetupError, \
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19149
diff changeset
146 ("bad library name '%s': " +
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
147 "may not contain directory separators") % \
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
148 lib[0]
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
149
53830
0f6a785cf286 Added a test and cleaned check_library_list to be ready to fix #5940
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 51047
diff changeset
150 if not isinstance(build_info, dict):
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12314
diff changeset
151 raise DistutilsSetupError, \
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
152 "second element of each tuple in 'libraries' " + \
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
153 "must be a dictionary (build info)"
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
154
53835
e620701a3ec8 pep8-fied build_clib module : it is now similar to the one in 3.x
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53830
diff changeset
155 def get_library_names(self):
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
156 # Assume the library list is valid -- 'check_library_list()' is
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
157 # called from 'finalize_options()', so it should be!
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
158 if not self.libraries:
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
159 return None
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
160
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
161 lib_names = []
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
162 for (lib_name, build_info) in self.libraries:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
163 lib_names.append(lib_name)
11895
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
164 return lib_names
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
165
cd57f776c1df Added command description.
Greg Ward <gward@python.net>
parents: 11817
diff changeset
166
53835
e620701a3ec8 pep8-fied build_clib module : it is now similar to the one in 3.x
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53830
diff changeset
167 def get_source_files(self):
19149
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
168 self.check_library_list(self.libraries)
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
169 filenames = []
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
170 for (lib_name, build_info) in self.libraries:
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
171 sources = build_info.get('sources')
53839
cac2a5f4b9fa more build_clib cleanup + test coverage
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53835
diff changeset
172 if sources is None or not isinstance(sources, (list, tuple)):
19149
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
173 raise DistutilsSetupError, \
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
174 ("in 'libraries' option (library '%s'), "
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
175 "'sources' must be present and must be "
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
176 "a list of source filenames") % lib_name
21268
d296e6bb17e5 Whitespace normalization.
Fred Drake <fdrake@acm.org>
parents: 19149
diff changeset
177
19149
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
178 filenames.extend(sources)
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
179 return filenames
481b81d300df [Bug #414032] Make the 'sdist' command work when the distribution contains
Andrew M. Kuchling <amk@amk.ca>
parents: 15216
diff changeset
180
53886
4c3a84e54d08 removed remaining spaces
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53843
diff changeset
181 def build_libraries(self, libraries):
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
182 for (lib_name, build_info) in libraries:
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
183 sources = build_info.get('sources')
53839
cac2a5f4b9fa more build_clib cleanup + test coverage
Tarek Ziadé <ziade.tarek@gmail.com>
parents: 53835
diff changeset
184 if sources is None or not isinstance(sources, (list, tuple)):
12407
01cff9fe2d45 Cleaned up/simplified error-handling:
Greg Ward <gward@python.net>
parents: 12314
diff changeset
185 raise DistutilsSetupError, \
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
186 ("in 'libraries' option (library '%s'), " +
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
187 "'sources' must be present and must be " +
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
188 "a list of source filenames") % lib_name
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
189 sources = list(sources)
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
190
23668
ca87119255eb Make setup.py less chatty by default.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21268
diff changeset
191 log.info("building '%s' library", lib_name)
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
192
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
193 # First, compile the source code to object files in the library
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
194 # directory. (This should probably change to putting object
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
195 # files in a temporary build directory.)
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
196 macros = build_info.get('macros')
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
197 include_dirs = build_info.get('include_dirs')
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
198 objects = self.compiler.compile(sources,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
199 output_dir=self.build_temp,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
200 macros=macros,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
201 include_dirs=include_dirs,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
202 debug=self.debug)
11713
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
203
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
204 # Now "link" the object files together into a static library.
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
205 # (On Unix at least, this isn't really linking -- it just
abfa1cb1ed05 New command to build C (and C++, hopefully) libraries needed by extensions
Greg Ward <gward@python.net>
parents:
diff changeset
206 # builds an archive. Whatever.)
14948
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
207 self.compiler.create_static_lib(objects, lib_name,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
208 output_dir=self.build_clib,
7acb8bbc215b Standardized whitespace around function calls.
Greg Ward <gward@python.net>
parents: 14829
diff changeset
209 debug=self.debug)