1 | n/a | """distutils.command.build |
---|
2 | n/a | |
---|
3 | n/a | Implements the Distutils 'build' command.""" |
---|
4 | n/a | |
---|
5 | n/a | import sys, os |
---|
6 | n/a | from distutils.core import Command |
---|
7 | n/a | from distutils.errors import DistutilsOptionError |
---|
8 | n/a | from distutils.util import get_platform |
---|
9 | n/a | |
---|
10 | n/a | |
---|
11 | n/a | def show_compilers(): |
---|
12 | n/a | from distutils.ccompiler import show_compilers |
---|
13 | n/a | show_compilers() |
---|
14 | n/a | |
---|
15 | n/a | |
---|
16 | n/a | class build(Command): |
---|
17 | n/a | |
---|
18 | n/a | description = "build everything needed to install" |
---|
19 | n/a | |
---|
20 | n/a | user_options = [ |
---|
21 | n/a | ('build-base=', 'b', |
---|
22 | n/a | "base directory for build library"), |
---|
23 | n/a | ('build-purelib=', None, |
---|
24 | n/a | "build directory for platform-neutral distributions"), |
---|
25 | n/a | ('build-platlib=', None, |
---|
26 | n/a | "build directory for platform-specific distributions"), |
---|
27 | n/a | ('build-lib=', None, |
---|
28 | n/a | "build directory for all distribution (defaults to either " + |
---|
29 | n/a | "build-purelib or build-platlib"), |
---|
30 | n/a | ('build-scripts=', None, |
---|
31 | n/a | "build directory for scripts"), |
---|
32 | n/a | ('build-temp=', 't', |
---|
33 | n/a | "temporary build directory"), |
---|
34 | n/a | ('plat-name=', 'p', |
---|
35 | n/a | "platform name to build for, if supported " |
---|
36 | n/a | "(default: %s)" % get_platform()), |
---|
37 | n/a | ('compiler=', 'c', |
---|
38 | n/a | "specify the compiler type"), |
---|
39 | n/a | ('parallel=', 'j', |
---|
40 | n/a | "number of parallel build jobs"), |
---|
41 | n/a | ('debug', 'g', |
---|
42 | n/a | "compile extensions and libraries with debugging information"), |
---|
43 | n/a | ('force', 'f', |
---|
44 | n/a | "forcibly build everything (ignore file timestamps)"), |
---|
45 | n/a | ('executable=', 'e', |
---|
46 | n/a | "specify final destination interpreter path (build.py)"), |
---|
47 | n/a | ] |
---|
48 | n/a | |
---|
49 | n/a | boolean_options = ['debug', 'force'] |
---|
50 | n/a | |
---|
51 | n/a | help_options = [ |
---|
52 | n/a | ('help-compiler', None, |
---|
53 | n/a | "list available compilers", show_compilers), |
---|
54 | n/a | ] |
---|
55 | n/a | |
---|
56 | n/a | def initialize_options(self): |
---|
57 | n/a | self.build_base = 'build' |
---|
58 | n/a | # these are decided only after 'build_base' has its final value |
---|
59 | n/a | # (unless overridden by the user or client) |
---|
60 | n/a | self.build_purelib = None |
---|
61 | n/a | self.build_platlib = None |
---|
62 | n/a | self.build_lib = None |
---|
63 | n/a | self.build_temp = None |
---|
64 | n/a | self.build_scripts = None |
---|
65 | n/a | self.compiler = None |
---|
66 | n/a | self.plat_name = None |
---|
67 | n/a | self.debug = None |
---|
68 | n/a | self.force = 0 |
---|
69 | n/a | self.executable = None |
---|
70 | n/a | self.parallel = None |
---|
71 | n/a | |
---|
72 | n/a | def finalize_options(self): |
---|
73 | n/a | if self.plat_name is None: |
---|
74 | n/a | self.plat_name = get_platform() |
---|
75 | n/a | else: |
---|
76 | n/a | # plat-name only supported for windows (other platforms are |
---|
77 | n/a | # supported via ./configure flags, if at all). Avoid misleading |
---|
78 | n/a | # other platforms. |
---|
79 | n/a | if os.name != 'nt': |
---|
80 | n/a | raise DistutilsOptionError( |
---|
81 | n/a | "--plat-name only supported on Windows (try " |
---|
82 | n/a | "using './configure --help' on your platform)") |
---|
83 | n/a | |
---|
84 | n/a | plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2]) |
---|
85 | n/a | |
---|
86 | n/a | # Make it so Python 2.x and Python 2.x with --with-pydebug don't |
---|
87 | n/a | # share the same build directories. Doing so confuses the build |
---|
88 | n/a | # process for C modules |
---|
89 | n/a | if hasattr(sys, 'gettotalrefcount'): |
---|
90 | n/a | plat_specifier += '-pydebug' |
---|
91 | n/a | |
---|
92 | n/a | # 'build_purelib' and 'build_platlib' just default to 'lib' and |
---|
93 | n/a | # 'lib.<plat>' under the base build directory. We only use one of |
---|
94 | n/a | # them for a given distribution, though -- |
---|
95 | n/a | if self.build_purelib is None: |
---|
96 | n/a | self.build_purelib = os.path.join(self.build_base, 'lib') |
---|
97 | n/a | if self.build_platlib is None: |
---|
98 | n/a | self.build_platlib = os.path.join(self.build_base, |
---|
99 | n/a | 'lib' + plat_specifier) |
---|
100 | n/a | |
---|
101 | n/a | # 'build_lib' is the actual directory that we will use for this |
---|
102 | n/a | # particular module distribution -- if user didn't supply it, pick |
---|
103 | n/a | # one of 'build_purelib' or 'build_platlib'. |
---|
104 | n/a | if self.build_lib is None: |
---|
105 | n/a | if self.distribution.ext_modules: |
---|
106 | n/a | self.build_lib = self.build_platlib |
---|
107 | n/a | else: |
---|
108 | n/a | self.build_lib = self.build_purelib |
---|
109 | n/a | |
---|
110 | n/a | # 'build_temp' -- temporary directory for compiler turds, |
---|
111 | n/a | # "build/temp.<plat>" |
---|
112 | n/a | if self.build_temp is None: |
---|
113 | n/a | self.build_temp = os.path.join(self.build_base, |
---|
114 | n/a | 'temp' + plat_specifier) |
---|
115 | n/a | if self.build_scripts is None: |
---|
116 | n/a | self.build_scripts = os.path.join(self.build_base, |
---|
117 | n/a | 'scripts-%d.%d' % sys.version_info[:2]) |
---|
118 | n/a | |
---|
119 | n/a | if self.executable is None: |
---|
120 | n/a | self.executable = os.path.normpath(sys.executable) |
---|
121 | n/a | |
---|
122 | n/a | if isinstance(self.parallel, str): |
---|
123 | n/a | try: |
---|
124 | n/a | self.parallel = int(self.parallel) |
---|
125 | n/a | except ValueError: |
---|
126 | n/a | raise DistutilsOptionError("parallel should be an integer") |
---|
127 | n/a | |
---|
128 | n/a | def run(self): |
---|
129 | n/a | # Run all relevant sub-commands. This will be some subset of: |
---|
130 | n/a | # - build_py - pure Python modules |
---|
131 | n/a | # - build_clib - standalone C libraries |
---|
132 | n/a | # - build_ext - Python extensions |
---|
133 | n/a | # - build_scripts - (Python) scripts |
---|
134 | n/a | for cmd_name in self.get_sub_commands(): |
---|
135 | n/a | self.run_command(cmd_name) |
---|
136 | n/a | |
---|
137 | n/a | |
---|
138 | n/a | # -- Predicates for the sub-command list --------------------------- |
---|
139 | n/a | |
---|
140 | n/a | def has_pure_modules(self): |
---|
141 | n/a | return self.distribution.has_pure_modules() |
---|
142 | n/a | |
---|
143 | n/a | def has_c_libraries(self): |
---|
144 | n/a | return self.distribution.has_c_libraries() |
---|
145 | n/a | |
---|
146 | n/a | def has_ext_modules(self): |
---|
147 | n/a | return self.distribution.has_ext_modules() |
---|
148 | n/a | |
---|
149 | n/a | def has_scripts(self): |
---|
150 | n/a | return self.distribution.has_scripts() |
---|
151 | n/a | |
---|
152 | n/a | |
---|
153 | n/a | sub_commands = [('build_py', has_pure_modules), |
---|
154 | n/a | ('build_clib', has_c_libraries), |
---|
155 | n/a | ('build_ext', has_ext_modules), |
---|
156 | n/a | ('build_scripts', has_scripts), |
---|
157 | n/a | ] |
---|