Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 1 | """distutils.command.build |
| 2 | |
| 3 | Implements the Distutils 'build' command.""" |
| 4 | |
Greg Ward | 3ce77fd | 2000-03-02 01:49:45 +0000 | [diff] [blame] | 5 | __revision__ = "$Id$" |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 6 | |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 7 | import sys, os |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 8 | from distutils.core import Command |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 9 | from distutils.util import get_platform |
Greg Ward | 3459381 | 2000-06-24 01:23:37 +0000 | [diff] [blame] | 10 | |
| 11 | |
| 12 | def show_compilers (): |
| 13 | from distutils.ccompiler import show_compilers |
| 14 | show_compilers() |
| 15 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 16 | |
Greg Ward | 1993f9a | 2000-02-18 00:13:53 +0000 | [diff] [blame] | 17 | class build (Command): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 18 | |
Greg Ward | 37bc815 | 2000-01-30 18:34:15 +0000 | [diff] [blame] | 19 | description = "build everything needed to install" |
| 20 | |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 21 | user_options = [ |
| 22 | ('build-base=', 'b', |
| 23 | "base directory for build library"), |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 24 | ('build-purelib=', None, |
| 25 | "build directory for platform-neutral distributions"), |
| 26 | ('build-platlib=', None, |
| 27 | "build directory for platform-specific distributions"), |
| 28 | ('build-lib=', None, |
| 29 | "build directory for all distribution (defaults to either " + |
| 30 | "build-purelib or build-platlib"), |
Greg Ward | 8d5881a | 2000-05-25 01:19:18 +0000 | [diff] [blame] | 31 | ('build-scripts=', None, |
| 32 | "build directory for scripts"), |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 33 | ('build-temp=', 't', |
| 34 | "temporary build directory"), |
Gregory P. Smith | 9668b78 | 2000-05-12 00:33:14 +0000 | [diff] [blame] | 35 | ('compiler=', 'c', |
| 36 | "specify the compiler type"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 37 | ('debug', 'g', |
| 38 | "compile extensions and libraries with debugging information"), |
Greg Ward | c41d6b3 | 2000-04-10 00:19:42 +0000 | [diff] [blame] | 39 | ('force', 'f', |
Gregory P. Smith | 9668b78 | 2000-05-12 00:33:14 +0000 | [diff] [blame] | 40 | "forcibly build everything (ignore file timestamps)"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 41 | ] |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 42 | |
Greg Ward | 99b032e | 2000-09-25 01:41:15 +0000 | [diff] [blame] | 43 | boolean_options = ['debug', 'force'] |
| 44 | |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 45 | help_options = [ |
| 46 | ('help-compiler', None, |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 47 | "list available compilers", show_compilers), |
Greg Ward | fa9ff76 | 2000-10-14 04:06:40 +0000 | [diff] [blame] | 48 | ] |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 49 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 50 | def initialize_options (self): |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 51 | self.build_base = 'build' |
| 52 | # these are decided only after 'build_base' has its final value |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 53 | # (unless overridden by the user or client) |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 54 | self.build_purelib = None |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 55 | self.build_platlib = None |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 56 | self.build_lib = None |
| 57 | self.build_temp = None |
Greg Ward | 8d5881a | 2000-05-25 01:19:18 +0000 | [diff] [blame] | 58 | self.build_scripts = None |
Gregory P. Smith | 9668b78 | 2000-05-12 00:33:14 +0000 | [diff] [blame] | 59 | self.compiler = None |
Greg Ward | 3246200 | 2000-02-09 02:19:49 +0000 | [diff] [blame] | 60 | self.debug = None |
Greg Ward | c41d6b3 | 2000-04-10 00:19:42 +0000 | [diff] [blame] | 61 | self.force = 0 |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 62 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 63 | def finalize_options (self): |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 64 | |
Greg Ward | 53db815 | 2000-09-16 02:06:45 +0000 | [diff] [blame] | 65 | plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3]) |
Greg Ward | 4290094 | 2000-09-16 01:54:46 +0000 | [diff] [blame] | 66 | |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 67 | # 'build_purelib' and 'build_platlib' just default to 'lib' and |
| 68 | # 'lib.<plat>' under the base build directory. We only use one of |
| 69 | # them for a given distribution, though -- |
| 70 | if self.build_purelib is None: |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 71 | self.build_purelib = os.path.join(self.build_base, 'lib') |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 72 | if self.build_platlib is None: |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 73 | self.build_platlib = os.path.join(self.build_base, |
| 74 | 'lib' + plat_specifier) |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 75 | |
| 76 | # 'build_lib' is the actual directory that we will use for this |
| 77 | # particular module distribution -- if user didn't supply it, pick |
| 78 | # one of 'build_purelib' or 'build_platlib'. |
| 79 | if self.build_lib is None: |
| 80 | if self.distribution.ext_modules: |
| 81 | self.build_lib = self.build_platlib |
| 82 | else: |
| 83 | self.build_lib = self.build_purelib |
| 84 | |
| 85 | # 'build_temp' -- temporary directory for compiler turds, |
| 86 | # "build/temp.<plat>" |
| 87 | if self.build_temp is None: |
Greg Ward | cb1f4c4 | 2000-09-30 18:27:54 +0000 | [diff] [blame] | 88 | self.build_temp = os.path.join(self.build_base, |
| 89 | 'temp' + plat_specifier) |
Greg Ward | 8d5881a | 2000-05-25 01:19:18 +0000 | [diff] [blame] | 90 | if self.build_scripts is None: |
Michael W. Hudson | 49bdaed | 2001-12-10 15:28:30 +0000 | [diff] [blame] | 91 | self.build_scripts = os.path.join(self.build_base, |
| 92 | 'scripts-' + sys.version[0:3]) |
Greg Ward | 53db815 | 2000-09-16 02:06:45 +0000 | [diff] [blame] | 93 | |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 94 | # finalize_options () |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 95 | |
| 96 | |
| 97 | def run (self): |
| 98 | |
Greg Ward | 64d855a | 2000-09-30 17:08:12 +0000 | [diff] [blame] | 99 | # Run all relevant sub-commands. This will be some subset of: |
| 100 | # - build_py - pure Python modules |
| 101 | # - build_clib - standalone C libraries |
| 102 | # - build_ext - Python extensions |
| 103 | # - build_scripts - (Python) scripts |
| 104 | for cmd_name in self.get_sub_commands(): |
| 105 | self.run_command(cmd_name) |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 106 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 107 | |
Greg Ward | 64d855a | 2000-09-30 17:08:12 +0000 | [diff] [blame] | 108 | # -- Predicates for the sub-command list --------------------------- |
Greg Ward | 5f7c18e | 2000-02-05 02:24:16 +0000 | [diff] [blame] | 109 | |
Greg Ward | 64d855a | 2000-09-30 17:08:12 +0000 | [diff] [blame] | 110 | def has_pure_modules (self): |
| 111 | return self.distribution.has_pure_modules() |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 112 | |
Greg Ward | 64d855a | 2000-09-30 17:08:12 +0000 | [diff] [blame] | 113 | def has_c_libraries (self): |
| 114 | return self.distribution.has_c_libraries() |
| 115 | |
| 116 | def has_ext_modules (self): |
| 117 | return self.distribution.has_ext_modules() |
| 118 | |
| 119 | def has_scripts (self): |
| 120 | return self.distribution.has_scripts() |
| 121 | |
| 122 | |
| 123 | sub_commands = [('build_py', has_pure_modules), |
| 124 | ('build_clib', has_c_libraries), |
| 125 | ('build_ext', has_ext_modules), |
| 126 | ('build_scripts', has_scripts), |
| 127 | ] |
Greg Ward | 8d5881a | 2000-05-25 01:19:18 +0000 | [diff] [blame] | 128 | |
Greg Ward | fcd974e | 2000-05-25 01:10:04 +0000 | [diff] [blame] | 129 | # class build |