blob: e0648f3bdd11e01d185547f5ba6b99f586c84952 [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
Greg Ward0f77f952000-03-31 02:55:12 +00006__revision__ = "$Id$"
7
8import os, string
Greg Ward6b213762000-03-31 04:53:41 +00009from types import *
Greg Ward0f77f952000-03-31 02:55:12 +000010from distutils.core import Command
Greg Ward02296ce2000-03-31 05:08:50 +000011from distutils.errors import *
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000012from distutils.util import get_platform
Greg Ward0f77f952000-03-31 02:55:12 +000013
14
Greg Ward34593812000-06-24 01:23:37 +000015def show_formats ():
16 """Print list of available formats (arguments to "--format" option).
17 """
Fred Drake21d45352001-12-06 21:01:19 +000018 from distutils.fancy_getopt import FancyGetopt
Greg Ward34593812000-06-24 01:23:37 +000019 formats=[]
20 for format in bdist.format_commands:
21 formats.append(("formats=" + format, None,
22 bdist.format_command[format][1]))
23 pretty_printer = FancyGetopt(formats)
24 pretty_printer.print_help("List of available distribution formats:")
25
26
Greg Ward0f77f952000-03-31 02:55:12 +000027class bdist (Command):
28
29 description = "create a built (binary) distribution"
30
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000031 user_options = [('bdist-base=', 'b',
32 "temporary directory for creating built distributions"),
Greg Ward20283e52000-09-11 00:47:35 +000033 ('plat-name=', 'p',
34 "platform name to embed in generated filenames "
35 "(default: %s)" % get_platform()),
Greg Warde18dd8d2000-06-06 02:51:38 +000036 ('formats=', None,
Greg Ward2ff78872000-06-24 00:23:20 +000037 "formats for distribution (comma-separated list)"),
Greg Ward040dc0b2000-07-05 03:07:18 +000038 ('dist-dir=', 'd',
39 "directory to put final built distributions in "
40 "[default: dist]"),
Martin v. Löwis9668b932002-01-12 11:27:42 +000041 ('skip-build', None,
42 "skip rebuilding everything (for testing/debugging)"),
Greg Ward0f77f952000-03-31 02:55:12 +000043 ]
44
Martin v. Löwis9668b932002-01-12 11:27:42 +000045 boolean_options = ['skip-build']
46
Greg Ward34593812000-06-24 01:23:37 +000047 help_options = [
48 ('help-formats', None,
49 "lists available distribution formats", show_formats),
Greg Wardfa9ff762000-10-14 04:06:40 +000050 ]
Greg Ward34593812000-06-24 01:23:37 +000051
Gregory P. Smith52e399c2000-05-13 01:49:56 +000052 # The following commands do not take a format option from bdist
Marc-André Lemburgc7cdd712002-10-04 09:30:06 +000053 no_format_option = ('bdist_rpm',
54 #'bdist_sdux', 'bdist_pkgtool'
55 )
Gregory P. Smith52e399c2000-05-13 01:49:56 +000056
Greg Ward0f77f952000-03-31 02:55:12 +000057 # This won't do in reality: will need to distinguish RPM-ish Linux,
58 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS.
59 default_format = { 'posix': 'gztar',
Marc-André Lemburg2544f512002-01-31 18:56:00 +000060 'nt': 'zip',
61 'os2': 'zip', }
Greg Ward0f77f952000-03-31 02:55:12 +000062
Greg Ward6f628bb2000-08-02 01:44:44 +000063 # Establish the preferred order (for the --help-formats option).
64 format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar',
Marc-André Lemburgc7cdd712002-10-04 09:30:06 +000065 'wininst', 'zip',
66 #'pkgtool', 'sdux'
67 ]
Greg Ward6f628bb2000-08-02 01:44:44 +000068
69 # And the real information.
Greg Ward2ff78872000-06-24 00:23:20 +000070 format_command = { 'rpm': ('bdist_rpm', "RPM distribution"),
Marc-André Lemburgc7cdd712002-10-04 09:30:06 +000071 'zip': ('bdist_dumb', "ZIP file"),
72 'gztar': ('bdist_dumb', "gzip'ed tar file"),
Greg Ward2ff78872000-06-24 00:23:20 +000073 'bztar': ('bdist_dumb', "bzip2'ed tar file"),
74 'ztar': ('bdist_dumb', "compressed tar file"),
75 'tar': ('bdist_dumb', "tar file"),
Greg Ward1f9b73b2000-06-27 01:24:07 +000076 'wininst': ('bdist_wininst',
77 "Windows executable installer"),
Greg Ward6f628bb2000-08-02 01:44:44 +000078 'zip': ('bdist_dumb', "ZIP file"),
Marc-André Lemburgc7cdd712002-10-04 09:30:06 +000079 #'pkgtool': ('bdist_pkgtool',
80 # "Solaris pkgtool distribution"),
81 #'sdux': ('bdist_sdux', "HP-UX swinstall depot"),
Marc-André Lemburg0538f1f2002-04-17 20:30:10 +000082 }
Greg Ward0f77f952000-03-31 02:55:12 +000083
84
85 def initialize_options (self):
Gregory P. Smithc59d4e02000-05-13 03:08:28 +000086 self.bdist_base = None
Greg Ward20283e52000-09-11 00:47:35 +000087 self.plat_name = None
Greg Warde18dd8d2000-06-06 02:51:38 +000088 self.formats = None
Greg Ward040dc0b2000-07-05 03:07:18 +000089 self.dist_dir = None
Martin v. Löwis9668b932002-01-12 11:27:42 +000090 self.skip_build = 0
Greg Ward0f77f952000-03-31 02:55:12 +000091
92 # initialize_options()
93
94
95 def finalize_options (self):
Greg Ward20283e52000-09-11 00:47:35 +000096 # have to finalize 'plat_name' before 'bdist_base'
97 if self.plat_name is None:
98 self.plat_name = get_platform()
99
Gregory P. Smithc59d4e02000-05-13 03:08:28 +0000100 # 'bdist_base' -- parent of per-built-distribution-format
101 # temporary directories (eg. we'll probably have
102 # "build/bdist.<plat>/dumb", "build/bdist.<plat>/rpm", etc.)
103 if self.bdist_base is None:
Greg Ward4fb29e52000-05-27 17:27:23 +0000104 build_base = self.get_finalized_command('build').build_base
Greg Wardbeb6d722000-09-16 16:04:59 +0000105 self.bdist_base = os.path.join(build_base,
106 'bdist.' + self.plat_name)
Gregory P. Smithc59d4e02000-05-13 03:08:28 +0000107
Greg Warde18dd8d2000-06-06 02:51:38 +0000108 self.ensure_string_list('formats')
109 if self.formats is None:
Greg Ward0f77f952000-03-31 02:55:12 +0000110 try:
Greg Warde18dd8d2000-06-06 02:51:38 +0000111 self.formats = [self.default_format[os.name]]
Greg Ward0f77f952000-03-31 02:55:12 +0000112 except KeyError:
113 raise DistutilsPlatformError, \
114 "don't know how to create built distributions " + \
115 "on platform %s" % os.name
Greg Ward040dc0b2000-07-05 03:07:18 +0000116
117 if self.dist_dir is None:
118 self.dist_dir = "dist"
Fred Drake21d45352001-12-06 21:01:19 +0000119
Greg Ward0f77f952000-03-31 02:55:12 +0000120 # finalize_options()
121
122
123 def run (self):
124
Greg Wardbeb6d722000-09-16 16:04:59 +0000125 # Figure out which sub-commands we need to run.
126 commands = []
Greg Warde18dd8d2000-06-06 02:51:38 +0000127 for format in self.formats:
Greg Warde18dd8d2000-06-06 02:51:38 +0000128 try:
Greg Wardbeb6d722000-09-16 16:04:59 +0000129 commands.append(self.format_command[format][0])
Greg Warde18dd8d2000-06-06 02:51:38 +0000130 except KeyError:
Greg Wardbeb6d722000-09-16 16:04:59 +0000131 raise DistutilsOptionError, "invalid format '%s'" % format
Greg Warde18dd8d2000-06-06 02:51:38 +0000132
Greg Wardbeb6d722000-09-16 16:04:59 +0000133 # Reinitialize and run each command.
134 for i in range(len(self.formats)):
135 cmd_name = commands[i]
Greg Warde18dd8d2000-06-06 02:51:38 +0000136 sub_cmd = self.reinitialize_command(cmd_name)
137 if cmd_name not in self.no_format_option:
Greg Wardbeb6d722000-09-16 16:04:59 +0000138 sub_cmd.format = self.formats[i]
139
Greg Wardbeb6d722000-09-16 16:04:59 +0000140 # If we're going to need to run this command again, tell it to
141 # keep its temporary files around so subsequent runs go faster.
142 if cmd_name in commands[i+1:]:
143 sub_cmd.keep_temp = 1
Greg Wardcb1f4c42000-09-30 18:27:54 +0000144 self.run_command(cmd_name)
Greg Ward0f77f952000-03-31 02:55:12 +0000145
146 # run()
147
148# class bdist