blob: 4eca9c3426bbe2d20289c776dd6700f2d0696b97 [file] [log] [blame]
Greg Ward0f77f952000-03-31 02:55:12 +00001"""distutils.command.bdist
2
3Implements the Distutils 'bdist' command (create a built [binary]
4distribution)."""
5
Andrew M. Kuchlingd448f662002-11-19 13:12:28 +00006# This module should be kept compatible with Python 1.5.2.
7
Greg Ward0f77f952000-03-31 02:55:12 +00008__revision__ = "$Id$"
9
10import os, string
Greg Ward6b213762000-03-31 04:53:41 +000011from types import *
Greg Ward0f77f952000-03-31 02:55:12 +000012from distutils.core import Command
Greg Ward02296ce2000-03-31 05:08:50 +000013from distutils.errors import *
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000014from distutils.util import get_platform
Greg Ward0f77f952000-03-31 02:55:12 +000015
16
Greg Ward34593812000-06-24 01:23:37 +000017def show_formats ():
18 """Print list of available formats (arguments to "--format" option).
19 """
Fred Drake21d45352001-12-06 21:01:19 +000020 from distutils.fancy_getopt import FancyGetopt
Greg Ward34593812000-06-24 01:23:37 +000021 formats=[]
22 for format in bdist.format_commands:
23 formats.append(("formats=" + format, None,
24 bdist.format_command[format][1]))
25 pretty_printer = FancyGetopt(formats)
26 pretty_printer.print_help("List of available distribution formats:")
27
28
Greg Ward0f77f952000-03-31 02:55:12 +000029class bdist (Command):
30
31 description = "create a built (binary) distribution"
32
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000033 user_options = [('bdist-base=', 'b',
34 "temporary directory for creating built distributions"),
Greg Ward20283e52000-09-11 00:47:35 +000035 ('plat-name=', 'p',
36 "platform name to embed in generated filenames "
37 "(default: %s)" % get_platform()),
Greg Warde18dd8d2000-06-06 02:51:38 +000038 ('formats=', None,
Greg Ward2ff78872000-06-24 00:23:20 +000039 "formats for distribution (comma-separated list)"),
Greg Ward040dc0b2000-07-05 03:07:18 +000040 ('dist-dir=', 'd',
41 "directory to put final built distributions in "
42 "[default: dist]"),
Martin v. Löwis9668b932002-01-12 11:27:42 +000043 ('skip-build', None,
44 "skip rebuilding everything (for testing/debugging)"),
Greg Ward0f77f952000-03-31 02:55:12 +000045 ]
46
Martin v. Löwis9668b932002-01-12 11:27:42 +000047 boolean_options = ['skip-build']
48
Greg Ward34593812000-06-24 01:23:37 +000049 help_options = [
50 ('help-formats', None,
51 "lists available distribution formats", show_formats),
Greg Wardfa9ff762000-10-14 04:06:40 +000052 ]
Greg Ward34593812000-06-24 01:23:37 +000053
Gregory P. Smith52e399c2000-05-13 01:49:56 +000054 # The following commands do not take a format option from bdist
Marc-André Lemburgc7cdd712002-10-04 09:30:06 +000055 no_format_option = ('bdist_rpm',
56 #'bdist_sdux', 'bdist_pkgtool'
57 )
Gregory P. Smith52e399c2000-05-13 01:49:56 +000058
Greg Ward0f77f952000-03-31 02:55:12 +000059 # This won't do in reality: will need to distinguish RPM-ish Linux,
60 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
61 default_format = { 'posix': 'gztar',
Marc-André Lemburg2544f512002-01-31 18:56:00 +000062 'nt': 'zip',
63 'os2': 'zip', }
Greg Ward0f77f952000-03-31 02:55:12 +000064
Greg Ward6f628bb2000-08-02 01:44:44 +000065 # Establish the preferred order (for the --help-formats option).
66 format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
Marc-André Lemburgc7cdd712002-10-04 09:30:06 +000067 'wininst', 'zip',
68 #'pkgtool', 'sdux'
69 ]
Greg Ward6f628bb2000-08-02 01:44:44 +000070
71 # And the real information.
Greg Ward2ff78872000-06-24 00:23:20 +000072 format_command = { 'rpm': ('bdist_rpm', "RPM distribution"),
Marc-André Lemburgc7cdd712002-10-04 09:30:06 +000073 'zip': ('bdist_dumb', "ZIP file"),
74 'gztar': ('bdist_dumb', "gzip'ed tar file"),
Greg Ward2ff78872000-06-24 00:23:20 +000075 'bztar': ('bdist_dumb', "bzip2'ed tar file"),
76 'ztar': ('bdist_dumb', "compressed tar file"),
77 'tar': ('bdist_dumb', "tar file"),
Greg Ward1f9b73b2000-06-27 01:24:07 +000078 'wininst': ('bdist_wininst',
79 "Windows executable installer"),
Greg Ward6f628bb2000-08-02 01:44:44 +000080 'zip': ('bdist_dumb', "ZIP file"),
Tim Peters182b5ac2004-07-18 06:16:08 +000081 #'pkgtool': ('bdist_pkgtool',
Marc-André Lemburgc7cdd712002-10-04 09:30:06 +000082 # "Solaris pkgtool distribution"),
83 #'sdux': ('bdist_sdux', "HP-UX swinstall depot"),
Marc-André Lemburg0538f1f2002-04-17 20:30:10 +000084 }
Greg Ward0f77f952000-03-31 02:55:12 +000085
86
87 def initialize_options (self):
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000088 self.bdist_base = None
Greg Ward20283e52000-09-11 00:47:35 +000089 self.plat_name = None
Greg Warde18dd8d2000-06-06 02:51:38 +000090 self.formats = None
Greg Ward040dc0b2000-07-05 03:07:18 +000091 self.dist_dir = None
Martin v. Löwis9668b932002-01-12 11:27:42 +000092 self.skip_build = 0
Greg Ward0f77f952000-03-31 02:55:12 +000093
94 # initialize_options()
95
96
97 def finalize_options (self):
Greg Ward20283e52000-09-11 00:47:35 +000098 # have to finalize 'plat_name' before 'bdist_base'
99 if self.plat_name is None:
100 self.plat_name = get_platform()
101
Gregory P. Smithc59d4e02000-05-13 03:08:28 +0000102 # 'bdist_base' -- parent of per-built-distribution-format
103 # temporary directories (eg. we'll probably have
104 # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
105 if self.bdist_base is None:
Greg Ward4fb29e52000-05-27 17:27:23 +0000106 build_base = self.get_finalized_command('build').build_base
Greg Wardbeb6d722000-09-16 16:04:59 +0000107 self.bdist_base = os.path.join(build_base,
108 'bdist.' + self.plat_name)
Gregory P. Smithc59d4e02000-05-13 03:08:28 +0000109
Greg Warde18dd8d2000-06-06 02:51:38 +0000110 self.ensure_string_list('formats')
111 if self.formats is None:
Greg Ward0f77f952000-03-31 02:55:12 +0000112 try:
Greg Warde18dd8d2000-06-06 02:51:38 +0000113 self.formats = [self.default_format[os.name]]
Greg Ward0f77f952000-03-31 02:55:12 +0000114 except KeyError:
115 raise DistutilsPlatformError, \
116 "don't know how to create built distributions " + \
117 "on platform %s" % os.name
Greg Ward040dc0b2000-07-05 03:07:18 +0000118
119 if self.dist_dir is None:
120 self.dist_dir = "dist"
Fred Drake21d45352001-12-06 21:01:19 +0000121
Greg Ward0f77f952000-03-31 02:55:12 +0000122 # finalize_options()
123
124
125 def run (self):
126
Greg Wardbeb6d722000-09-16 16:04:59 +0000127 # Figure out which sub-commands we need to run.
128 commands = []
Greg Warde18dd8d2000-06-06 02:51:38 +0000129 for format in self.formats:
Greg Warde18dd8d2000-06-06 02:51:38 +0000130 try:
Greg Wardbeb6d722000-09-16 16:04:59 +0000131 commands.append(self.format_command[format][0])
Greg Warde18dd8d2000-06-06 02:51:38 +0000132 except KeyError:
Greg Wardbeb6d722000-09-16 16:04:59 +0000133 raise DistutilsOptionError, "invalid format '%s'" % format
Greg Warde18dd8d2000-06-06 02:51:38 +0000134
Greg Wardbeb6d722000-09-16 16:04:59 +0000135 # Reinitialize and run each command.
136 for i in range(len(self.formats)):
137 cmd_name = commands[i]
Greg Warde18dd8d2000-06-06 02:51:38 +0000138 sub_cmd = self.reinitialize_command(cmd_name)
139 if cmd_name not in self.no_format_option:
Greg Wardbeb6d722000-09-16 16:04:59 +0000140 sub_cmd.format = self.formats[i]
141
Greg Wardbeb6d722000-09-16 16:04:59 +0000142 # If we're going to need to run this command again, tell it to
143 # keep its temporary files around so subsequent runs go faster.
144 if cmd_name in commands[i+1:]:
145 sub_cmd.keep_temp = 1
Greg Wardcb1f4c42000-09-30 18:27:54 +0000146 self.run_command(cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +0000147
148 # run()
149
150# class bdist