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