blob: 03d8c81776d7885cea9164b4f2541ec512cb4440 [file] [log] [blame]
Just van Rossumad33d722002-11-21 10:23:04 +00001#! /usr/bin/env python
2
3"""\
4bundlebuilder.py -- Tools to assemble MacOS X (application) bundles.
5
Just van Rossumceeb9622002-11-21 23:19:37 +00006This module contains two classes to build so called "bundles" for
Just van Rossumad33d722002-11-21 10:23:04 +00007MacOS X. BundleBuilder is a general tool, AppBuilder is a subclass
Just van Rossumceeb9622002-11-21 23:19:37 +00008specialized in building application bundles.
Just van Rossumad33d722002-11-21 10:23:04 +00009
Just van Rossumceeb9622002-11-21 23:19:37 +000010[Bundle|App]Builder objects are instantiated with a bunch of keyword
11arguments, and have a build() method that will do all the work. See
12the class doc strings for a description of the constructor arguments.
13
14The module contains a main program that can be used in two ways:
15
16 % python bundlebuilder.py [options] build
17 % python buildapp.py [options] build
18
19Where "buildapp.py" is a user-supplied setup.py-like script following
20this model:
21
22 from bundlebuilder import buildapp
23 buildapp(<lots-of-keyword-args>)
Just van Rossumad33d722002-11-21 10:23:04 +000024
25"""
26
Just van Rossumad33d722002-11-21 10:23:04 +000027
Just van Rossumcef32882002-11-26 00:34:52 +000028__all__ = ["BundleBuilder", "BundleBuilderError", "AppBuilder", "buildapp"]
Just van Rossumad33d722002-11-21 10:23:04 +000029
30
31import sys
32import os, errno, shutil
Just van Rossumcef32882002-11-26 00:34:52 +000033import imp, marshal
34import re
Just van Rossumda302da2002-11-23 22:26:44 +000035from copy import deepcopy
Just van Rossumceeb9622002-11-21 23:19:37 +000036import getopt
Just van Rossumad33d722002-11-21 10:23:04 +000037from plistlib import Plist
Just van Rossumda302da2002-11-23 22:26:44 +000038from types import FunctionType as function
Just van Rossumad33d722002-11-21 10:23:04 +000039
Just van Rossumcef32882002-11-26 00:34:52 +000040class BundleBuilderError(Exception): pass
41
42
Just van Rossumda302da2002-11-23 22:26:44 +000043class Defaults:
44
Jack Jansen0ae32202003-04-09 13:25:43 +000045 """Class attributes that don't start with an underscore and are
46 not functions or classmethods are (deep)copied to self.__dict__.
47 This allows for mutable default values.
48 """
Just van Rossumda302da2002-11-23 22:26:44 +000049
Jack Jansen0ae32202003-04-09 13:25:43 +000050 def __init__(self, **kwargs):
51 defaults = self._getDefaults()
52 defaults.update(kwargs)
53 self.__dict__.update(defaults)
Just van Rossumda302da2002-11-23 22:26:44 +000054
Jack Jansen0ae32202003-04-09 13:25:43 +000055 def _getDefaults(cls):
56 defaults = {}
Just van Rossumed8bfce2003-07-10 14:53:27 +000057 for base in cls.__bases__:
58 if hasattr(base, "_getDefaults"):
59 defaults.update(base._getDefaults())
Jack Jansen0ae32202003-04-09 13:25:43 +000060 for name, value in cls.__dict__.items():
61 if name[0] != "_" and not isinstance(value,
62 (function, classmethod)):
63 defaults[name] = deepcopy(value)
Jack Jansen0ae32202003-04-09 13:25:43 +000064 return defaults
65 _getDefaults = classmethod(_getDefaults)
Just van Rossumad33d722002-11-21 10:23:04 +000066
67
Just van Rossumda302da2002-11-23 22:26:44 +000068class BundleBuilder(Defaults):
Just van Rossumad33d722002-11-21 10:23:04 +000069
Jack Jansen0ae32202003-04-09 13:25:43 +000070 """BundleBuilder is a barebones class for assembling bundles. It
71 knows nothing about executables or icons, it only copies files
72 and creates the PkgInfo and Info.plist files.
73 """
Just van Rossumad33d722002-11-21 10:23:04 +000074
Jack Jansen0ae32202003-04-09 13:25:43 +000075 # (Note that Defaults.__init__ (deep)copies these values to
76 # instance variables. Mutable defaults are therefore safe.)
Just van Rossumda302da2002-11-23 22:26:44 +000077
Jack Jansen0ae32202003-04-09 13:25:43 +000078 # Name of the bundle, with or without extension.
79 name = None
Just van Rossumda302da2002-11-23 22:26:44 +000080
Jack Jansen0ae32202003-04-09 13:25:43 +000081 # The property list ("plist")
82 plist = Plist(CFBundleDevelopmentRegion = "English",
83 CFBundleInfoDictionaryVersion = "6.0")
Just van Rossumda302da2002-11-23 22:26:44 +000084
Jack Jansen0ae32202003-04-09 13:25:43 +000085 # The type of the bundle.
86 type = "BNDL"
87 # The creator code of the bundle.
88 creator = None
Just van Rossumda302da2002-11-23 22:26:44 +000089
Just van Rossumbe56aae2003-07-04 14:20:03 +000090 # the CFBundleIdentifier (this is used for the preferences file name)
91 bundle_id = None
92
Jack Jansen0ae32202003-04-09 13:25:43 +000093 # List of files that have to be copied to <bundle>/Contents/Resources.
94 resources = []
Just van Rossumda302da2002-11-23 22:26:44 +000095
Jack Jansen0ae32202003-04-09 13:25:43 +000096 # List of (src, dest) tuples; dest should be a path relative to the bundle
97 # (eg. "Contents/Resources/MyStuff/SomeFile.ext).
98 files = []
Just van Rossumda302da2002-11-23 22:26:44 +000099
Jack Jansen0ae32202003-04-09 13:25:43 +0000100 # List of shared libraries (dylibs, Frameworks) to bundle with the app
101 # will be placed in Contents/Frameworks
102 libs = []
Just van Rossum15624d82003-03-21 09:26:59 +0000103
Jack Jansen0ae32202003-04-09 13:25:43 +0000104 # Directory where the bundle will be assembled.
105 builddir = "build"
Just van Rossumda302da2002-11-23 22:26:44 +0000106
Jack Jansen0ae32202003-04-09 13:25:43 +0000107 # Make symlinks instead copying files. This is handy during debugging, but
108 # makes the bundle non-distributable.
109 symlink = 0
Just van Rossumda302da2002-11-23 22:26:44 +0000110
Jack Jansen0ae32202003-04-09 13:25:43 +0000111 # Verbosity level.
112 verbosity = 1
Tim Peters5a9fb3c2005-01-07 16:01:32 +0000113
Jack Jansenc77f6df2004-12-27 15:51:03 +0000114 # Destination root directory
115 destroot = ""
Just van Rossumad33d722002-11-21 10:23:04 +0000116
Jack Jansen0ae32202003-04-09 13:25:43 +0000117 def setup(self):
118 # XXX rethink self.name munging, this is brittle.
119 self.name, ext = os.path.splitext(self.name)
120 if not ext:
121 ext = ".bundle"
122 bundleextension = ext
123 # misc (derived) attributes
124 self.bundlepath = pathjoin(self.builddir, self.name + bundleextension)
Just van Rossumceeb9622002-11-21 23:19:37 +0000125
Jack Jansen0ae32202003-04-09 13:25:43 +0000126 plist = self.plist
127 plist.CFBundleName = self.name
128 plist.CFBundlePackageType = self.type
129 if self.creator is None:
130 if hasattr(plist, "CFBundleSignature"):
131 self.creator = plist.CFBundleSignature
132 else:
133 self.creator = "????"
134 plist.CFBundleSignature = self.creator
Just van Rossumbe56aae2003-07-04 14:20:03 +0000135 if self.bundle_id:
136 plist.CFBundleIdentifier = self.bundle_id
137 elif not hasattr(plist, "CFBundleIdentifier"):
Jack Jansen0ae32202003-04-09 13:25:43 +0000138 plist.CFBundleIdentifier = self.name
Just van Rossumceeb9622002-11-21 23:19:37 +0000139
Jack Jansen0ae32202003-04-09 13:25:43 +0000140 def build(self):
141 """Build the bundle."""
142 builddir = self.builddir
143 if builddir and not os.path.exists(builddir):
144 os.mkdir(builddir)
145 self.message("Building %s" % repr(self.bundlepath), 1)
146 if os.path.exists(self.bundlepath):
147 shutil.rmtree(self.bundlepath)
148 os.mkdir(self.bundlepath)
149 self.preProcess()
150 self._copyFiles()
151 self._addMetaFiles()
152 self.postProcess()
153 self.message("Done.", 1)
Just van Rossumad33d722002-11-21 10:23:04 +0000154
Jack Jansen0ae32202003-04-09 13:25:43 +0000155 def preProcess(self):
156 """Hook for subclasses."""
157 pass
158 def postProcess(self):
159 """Hook for subclasses."""
160 pass
Just van Rossumad33d722002-11-21 10:23:04 +0000161
Jack Jansen0ae32202003-04-09 13:25:43 +0000162 def _addMetaFiles(self):
163 contents = pathjoin(self.bundlepath, "Contents")
164 makedirs(contents)
165 #
166 # Write Contents/PkgInfo
167 assert len(self.type) == len(self.creator) == 4, \
168 "type and creator must be 4-byte strings."
169 pkginfo = pathjoin(contents, "PkgInfo")
170 f = open(pkginfo, "wb")
171 f.write(self.type + self.creator)
172 f.close()
173 #
174 # Write Contents/Info.plist
175 infoplist = pathjoin(contents, "Info.plist")
176 self.plist.write(infoplist)
Just van Rossumad33d722002-11-21 10:23:04 +0000177
Jack Jansen0ae32202003-04-09 13:25:43 +0000178 def _copyFiles(self):
179 files = self.files[:]
180 for path in self.resources:
181 files.append((path, pathjoin("Contents", "Resources",
Just van Rossumdc31dc02003-06-20 21:43:36 +0000182 os.path.basename(path))))
Jack Jansen0ae32202003-04-09 13:25:43 +0000183 for path in self.libs:
184 files.append((path, pathjoin("Contents", "Frameworks",
Just van Rossumdc31dc02003-06-20 21:43:36 +0000185 os.path.basename(path))))
Jack Jansen0ae32202003-04-09 13:25:43 +0000186 if self.symlink:
187 self.message("Making symbolic links", 1)
188 msg = "Making symlink from"
189 else:
190 self.message("Copying files", 1)
191 msg = "Copying"
192 files.sort()
193 for src, dst in files:
194 if os.path.isdir(src):
195 self.message("%s %s/ to %s/" % (msg, src, dst), 2)
196 else:
197 self.message("%s %s to %s" % (msg, src, dst), 2)
198 dst = pathjoin(self.bundlepath, dst)
199 if self.symlink:
200 symlink(src, dst, mkdirs=1)
201 else:
202 copy(src, dst, mkdirs=1)
Just van Rossumad33d722002-11-21 10:23:04 +0000203
Jack Jansen0ae32202003-04-09 13:25:43 +0000204 def message(self, msg, level=0):
205 if level <= self.verbosity:
206 indent = ""
207 if level > 1:
208 indent = (level - 1) * " "
209 sys.stderr.write(indent + msg + "\n")
Just van Rossumceeb9622002-11-21 23:19:37 +0000210
Jack Jansen0ae32202003-04-09 13:25:43 +0000211 def report(self):
212 # XXX something decent
213 pass
Just van Rossumad33d722002-11-21 10:23:04 +0000214
215
Just van Rossumcef32882002-11-26 00:34:52 +0000216if __debug__:
Jack Jansen0ae32202003-04-09 13:25:43 +0000217 PYC_EXT = ".pyc"
Just van Rossumcef32882002-11-26 00:34:52 +0000218else:
Jack Jansen0ae32202003-04-09 13:25:43 +0000219 PYC_EXT = ".pyo"
Just van Rossumcef32882002-11-26 00:34:52 +0000220
221MAGIC = imp.get_magic()
Just van Rossum109ecbf2003-01-02 13:13:01 +0000222USE_ZIPIMPORT = "zipimport" in sys.builtin_module_names
Just van Rossumcef32882002-11-26 00:34:52 +0000223
224# For standalone apps, we have our own minimal site.py. We don't need
225# all the cruft of the real site.py.
226SITE_PY = """\
227import sys
Just van Rossum762d2cc2003-06-29 21:54:12 +0000228if not %(semi_standalone)s:
229 del sys.path[1:] # sys.path[0] is Contents/Resources/
Just van Rossumcef32882002-11-26 00:34:52 +0000230"""
231
Just van Rossum109ecbf2003-01-02 13:13:01 +0000232if USE_ZIPIMPORT:
Jack Jansen0ae32202003-04-09 13:25:43 +0000233 ZIP_ARCHIVE = "Modules.zip"
234 SITE_PY += "sys.path.append(sys.path[0] + '/%s')\n" % ZIP_ARCHIVE
235 def getPycData(fullname, code, ispkg):
236 if ispkg:
237 fullname += ".__init__"
238 path = fullname.replace(".", os.sep) + PYC_EXT
239 return path, MAGIC + '\0\0\0\0' + marshal.dumps(code)
Just van Rossumcef32882002-11-26 00:34:52 +0000240
Just van Rossum8a3ed3f2003-02-25 20:53:12 +0000241#
242# Extension modules can't be in the modules zip archive, so a placeholder
243# is added instead, that loads the extension from a specified location.
244#
Just van Rossum535ffa22002-11-29 20:06:52 +0000245EXT_LOADER = """\
Just van Rossum109ecbf2003-01-02 13:13:01 +0000246def __load():
Jack Jansen0ae32202003-04-09 13:25:43 +0000247 import imp, sys, os
248 for p in sys.path:
249 path = os.path.join(p, "%(filename)s")
250 if os.path.exists(path):
251 break
252 else:
253 assert 0, "file not found: %(filename)s"
254 mod = imp.load_dynamic("%(name)s", path)
Just van Rossum109ecbf2003-01-02 13:13:01 +0000255
256__load()
257del __load
Just van Rossum535ffa22002-11-29 20:06:52 +0000258"""
259
Just van Rossumcef32882002-11-26 00:34:52 +0000260MAYMISS_MODULES = ['mac', 'os2', 'nt', 'ntpath', 'dos', 'dospath',
Jack Jansen0ae32202003-04-09 13:25:43 +0000261 'win32api', 'ce', '_winreg', 'nturl2path', 'sitecustomize',
262 'org.python.core', 'riscos', 'riscosenviron', 'riscospath'
Just van Rossumcef32882002-11-26 00:34:52 +0000263]
264
265STRIP_EXEC = "/usr/bin/strip"
266
Just van Rossum8a3ed3f2003-02-25 20:53:12 +0000267#
268# We're using a stock interpreter to run the app, yet we need
269# a way to pass the Python main program to the interpreter. The
270# bootstrapping script fires up the interpreter with the right
271# arguments. os.execve() is used as OSX doesn't like us to
272# start a real new process. Also, the executable name must match
273# the CFBundleExecutable value in the Info.plist, so we lie
274# deliberately with argv[0]. The actual Python executable is
275# passed in an environment variable so we can "repair"
276# sys.executable later.
277#
Just van Rossum74bdca82002-11-28 11:30:56 +0000278BOOTSTRAP_SCRIPT = """\
Just van Rossum0ff7a4e2003-02-26 11:27:56 +0000279#!%(hashbang)s
Just van Rossumad33d722002-11-21 10:23:04 +0000280
Just van Rossum7322b1a2003-02-25 20:15:40 +0000281import sys, os
282execdir = os.path.dirname(sys.argv[0])
283executable = os.path.join(execdir, "%(executable)s")
284resdir = os.path.join(os.path.dirname(execdir), "Resources")
Just van Rossum15624d82003-03-21 09:26:59 +0000285libdir = os.path.join(os.path.dirname(execdir), "Frameworks")
Just van Rossum7322b1a2003-02-25 20:15:40 +0000286mainprogram = os.path.join(resdir, "%(mainprogram)s")
287
288sys.argv.insert(1, mainprogram)
Just van Rossumbe56aae2003-07-04 14:20:03 +0000289if %(standalone)s or %(semi_standalone)s:
290 os.environ["PYTHONPATH"] = resdir
291 if %(standalone)s:
292 os.environ["PYTHONHOME"] = resdir
293else:
294 pypath = os.getenv("PYTHONPATH", "")
295 if pypath:
296 pypath = ":" + pypath
297 os.environ["PYTHONPATH"] = resdir + pypath
Just van Rossum7322b1a2003-02-25 20:15:40 +0000298os.environ["PYTHONEXECUTABLE"] = executable
Just van Rossum15624d82003-03-21 09:26:59 +0000299os.environ["DYLD_LIBRARY_PATH"] = libdir
Just van Rossum3166f592003-06-20 18:56:10 +0000300os.environ["DYLD_FRAMEWORK_PATH"] = libdir
Just van Rossum7322b1a2003-02-25 20:15:40 +0000301os.execve(executable, sys.argv, os.environ)
Just van Rossumad33d722002-11-21 10:23:04 +0000302"""
303
Just van Rossum8a3ed3f2003-02-25 20:53:12 +0000304
305#
306# Optional wrapper that converts "dropped files" into sys.argv values.
307#
308ARGV_EMULATOR = """\
Jack Jansena03adde2003-02-18 23:29:46 +0000309import argvemulator, os
310
311argvemulator.ArgvCollector().mainloop()
312execfile(os.path.join(os.path.split(__file__)[0], "%(realmainprogram)s"))
313"""
Just van Rossumcef32882002-11-26 00:34:52 +0000314
Just van Rossum3166f592003-06-20 18:56:10 +0000315#
316# When building a standalone app with Python.framework, we need to copy
317# a subset from Python.framework to the bundle. The following list
318# specifies exactly what items we'll copy.
319#
320PYTHONFRAMEWORKGOODIES = [
321 "Python", # the Python core library
322 "Resources/English.lproj",
323 "Resources/Info.plist",
324 "Resources/version.plist",
325]
326
Just van Rossum79b0ae12003-06-29 22:20:26 +0000327def isFramework():
328 return sys.exec_prefix.find("Python.framework") > 0
329
Just van Rossum8a3ed3f2003-02-25 20:53:12 +0000330
Just van Rossum762d2cc2003-06-29 21:54:12 +0000331LIB = os.path.join(sys.prefix, "lib", "python" + sys.version[:3])
332SITE_PACKAGES = os.path.join(LIB, "site-packages")
333
334
Just van Rossumad33d722002-11-21 10:23:04 +0000335class AppBuilder(BundleBuilder):
336
Jack Jansen0ae32202003-04-09 13:25:43 +0000337 # Override type of the bundle.
338 type = "APPL"
Jack Jansencc81b802003-03-05 14:42:18 +0000339
Jack Jansen0ae32202003-04-09 13:25:43 +0000340 # platform, name of the subfolder of Contents that contains the executable.
341 platform = "MacOS"
Jack Jansencc81b802003-03-05 14:42:18 +0000342
Jack Jansen0ae32202003-04-09 13:25:43 +0000343 # A Python main program. If this argument is given, the main
344 # executable in the bundle will be a small wrapper that invokes
345 # the main program. (XXX Discuss why.)
346 mainprogram = None
Just van Rossumceeb9622002-11-21 23:19:37 +0000347
Jack Jansen0ae32202003-04-09 13:25:43 +0000348 # The main executable. If a Python main program is specified
349 # the executable will be copied to Resources and be invoked
350 # by the wrapper program mentioned above. Otherwise it will
351 # simply be used as the main executable.
352 executable = None
Just van Rossumceeb9622002-11-21 23:19:37 +0000353
Jack Jansen0ae32202003-04-09 13:25:43 +0000354 # The name of the main nib, for Cocoa apps. *Must* be specified
355 # when building a Cocoa app.
356 nibname = None
Just van Rossumad33d722002-11-21 10:23:04 +0000357
Jack Jansen0ae32202003-04-09 13:25:43 +0000358 # The name of the icon file to be copied to Resources and used for
359 # the Finder icon.
360 iconfile = None
Just van Rossum2aa09562003-02-01 08:34:46 +0000361
Jack Jansen0ae32202003-04-09 13:25:43 +0000362 # Symlink the executable instead of copying it.
363 symlink_exec = 0
Just van Rossumad33d722002-11-21 10:23:04 +0000364
Jack Jansen0ae32202003-04-09 13:25:43 +0000365 # If True, build standalone app.
366 standalone = 0
Just van Rossum3166f592003-06-20 18:56:10 +0000367
Just van Rossum762d2cc2003-06-29 21:54:12 +0000368 # If True, build semi-standalone app (only includes third-party modules).
369 semi_standalone = 0
370
Jack Jansen8ba0e802003-05-25 22:00:17 +0000371 # If set, use this for #! lines in stead of sys.executable
372 python = None
Just van Rossum3166f592003-06-20 18:56:10 +0000373
Jack Jansen0ae32202003-04-09 13:25:43 +0000374 # If True, add a real main program that emulates sys.argv before calling
375 # mainprogram
376 argv_emulation = 0
Just van Rossumcef32882002-11-26 00:34:52 +0000377
Jack Jansen0ae32202003-04-09 13:25:43 +0000378 # The following attributes are only used when building a standalone app.
Just van Rossumcef32882002-11-26 00:34:52 +0000379
Jack Jansen0ae32202003-04-09 13:25:43 +0000380 # Exclude these modules.
381 excludeModules = []
Just van Rossumcef32882002-11-26 00:34:52 +0000382
Jack Jansen0ae32202003-04-09 13:25:43 +0000383 # Include these modules.
384 includeModules = []
Just van Rossumcef32882002-11-26 00:34:52 +0000385
Jack Jansen0ae32202003-04-09 13:25:43 +0000386 # Include these packages.
387 includePackages = []
Just van Rossumcef32882002-11-26 00:34:52 +0000388
Just van Rossum00a0b972003-06-20 21:18:22 +0000389 # Strip binaries from debug info.
Jack Jansen0ae32202003-04-09 13:25:43 +0000390 strip = 0
Just van Rossumcef32882002-11-26 00:34:52 +0000391
Jack Jansen0ae32202003-04-09 13:25:43 +0000392 # Found Python modules: [(name, codeobject, ispkg), ...]
393 pymodules = []
Just van Rossumcef32882002-11-26 00:34:52 +0000394
Jack Jansen0ae32202003-04-09 13:25:43 +0000395 # Modules that modulefinder couldn't find:
396 missingModules = []
397 maybeMissingModules = []
Just van Rossumcef32882002-11-26 00:34:52 +0000398
Jack Jansen0ae32202003-04-09 13:25:43 +0000399 def setup(self):
Just van Rossum762d2cc2003-06-29 21:54:12 +0000400 if ((self.standalone or self.semi_standalone)
401 and self.mainprogram is None):
Jack Jansen0ae32202003-04-09 13:25:43 +0000402 raise BundleBuilderError, ("must specify 'mainprogram' when "
403 "building a standalone application.")
404 if self.mainprogram is None and self.executable is None:
405 raise BundleBuilderError, ("must specify either or both of "
406 "'executable' and 'mainprogram'")
Just van Rossumceeb9622002-11-21 23:19:37 +0000407
Jack Jansen0ae32202003-04-09 13:25:43 +0000408 self.execdir = pathjoin("Contents", self.platform)
Jack Jansencc81b802003-03-05 14:42:18 +0000409
Jack Jansen0ae32202003-04-09 13:25:43 +0000410 if self.name is not None:
411 pass
412 elif self.mainprogram is not None:
413 self.name = os.path.splitext(os.path.basename(self.mainprogram))[0]
414 elif executable is not None:
415 self.name = os.path.splitext(os.path.basename(self.executable))[0]
416 if self.name[-4:] != ".app":
417 self.name += ".app"
Just van Rossumceeb9622002-11-21 23:19:37 +0000418
Jack Jansen0ae32202003-04-09 13:25:43 +0000419 if self.executable is None:
Just van Rossum79b0ae12003-06-29 22:20:26 +0000420 if not self.standalone and not isFramework():
Jack Jansen0ae32202003-04-09 13:25:43 +0000421 self.symlink_exec = 1
Jack Jansenbbaa0832003-07-04 11:05:35 +0000422 if self.python:
423 self.executable = self.python
424 else:
425 self.executable = sys.executable
Just van Rossum74bdca82002-11-28 11:30:56 +0000426
Jack Jansen0ae32202003-04-09 13:25:43 +0000427 if self.nibname:
428 self.plist.NSMainNibFile = self.nibname
429 if not hasattr(self.plist, "NSPrincipalClass"):
430 self.plist.NSPrincipalClass = "NSApplication"
Just van Rossumceeb9622002-11-21 23:19:37 +0000431
Just van Rossum79b0ae12003-06-29 22:20:26 +0000432 if self.standalone and isFramework():
Just van Rossum3166f592003-06-20 18:56:10 +0000433 self.addPythonFramework()
434
Jack Jansen0ae32202003-04-09 13:25:43 +0000435 BundleBuilder.setup(self)
Just van Rossumceeb9622002-11-21 23:19:37 +0000436
Jack Jansen0ae32202003-04-09 13:25:43 +0000437 self.plist.CFBundleExecutable = self.name
Just van Rossumf7aba232002-11-22 00:31:50 +0000438
Just van Rossum762d2cc2003-06-29 21:54:12 +0000439 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000440 self.findDependencies()
Just van Rossumcef32882002-11-26 00:34:52 +0000441
Jack Jansen0ae32202003-04-09 13:25:43 +0000442 def preProcess(self):
443 resdir = "Contents/Resources"
444 if self.executable is not None:
445 if self.mainprogram is None:
446 execname = self.name
447 else:
448 execname = os.path.basename(self.executable)
449 execpath = pathjoin(self.execdir, execname)
450 if not self.symlink_exec:
Jack Jansenc77f6df2004-12-27 15:51:03 +0000451 self.files.append((self.destroot + self.executable, execpath))
Jack Jansen0ae32202003-04-09 13:25:43 +0000452 self.execpath = execpath
Just van Rossumad33d722002-11-21 10:23:04 +0000453
Jack Jansen0ae32202003-04-09 13:25:43 +0000454 if self.mainprogram is not None:
455 mainprogram = os.path.basename(self.mainprogram)
456 self.files.append((self.mainprogram, pathjoin(resdir, mainprogram)))
457 if self.argv_emulation:
458 # Change the main program, and create the helper main program (which
459 # does argv collection and then calls the real main).
460 # Also update the included modules (if we're creating a standalone
461 # program) and the plist
462 realmainprogram = mainprogram
463 mainprogram = '__argvemulator_' + mainprogram
464 resdirpath = pathjoin(self.bundlepath, resdir)
465 mainprogrampath = pathjoin(resdirpath, mainprogram)
466 makedirs(resdirpath)
467 open(mainprogrampath, "w").write(ARGV_EMULATOR % locals())
Just van Rossum762d2cc2003-06-29 21:54:12 +0000468 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000469 self.includeModules.append("argvemulator")
470 self.includeModules.append("os")
471 if not self.plist.has_key("CFBundleDocumentTypes"):
472 self.plist["CFBundleDocumentTypes"] = [
473 { "CFBundleTypeOSTypes" : [
474 "****",
475 "fold",
476 "disk"],
477 "CFBundleTypeRole": "Viewer"}]
478 # Write bootstrap script
479 executable = os.path.basename(self.executable)
480 execdir = pathjoin(self.bundlepath, self.execdir)
481 bootstrappath = pathjoin(execdir, self.name)
482 makedirs(execdir)
Just van Rossum762d2cc2003-06-29 21:54:12 +0000483 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000484 # XXX we're screwed when the end user has deleted
485 # /usr/bin/python
486 hashbang = "/usr/bin/python"
Jack Jansen8ba0e802003-05-25 22:00:17 +0000487 elif self.python:
488 hashbang = self.python
Jack Jansen0ae32202003-04-09 13:25:43 +0000489 else:
490 hashbang = os.path.realpath(sys.executable)
491 standalone = self.standalone
Just van Rossumbe56aae2003-07-04 14:20:03 +0000492 semi_standalone = self.semi_standalone
Jack Jansen0ae32202003-04-09 13:25:43 +0000493 open(bootstrappath, "w").write(BOOTSTRAP_SCRIPT % locals())
494 os.chmod(bootstrappath, 0775)
Just van Rossumad33d722002-11-21 10:23:04 +0000495
Jack Jansen0ae32202003-04-09 13:25:43 +0000496 if self.iconfile is not None:
497 iconbase = os.path.basename(self.iconfile)
498 self.plist.CFBundleIconFile = iconbase
499 self.files.append((self.iconfile, pathjoin(resdir, iconbase)))
Just van Rossum2aa09562003-02-01 08:34:46 +0000500
Jack Jansen0ae32202003-04-09 13:25:43 +0000501 def postProcess(self):
Just van Rossum762d2cc2003-06-29 21:54:12 +0000502 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000503 self.addPythonModules()
504 if self.strip and not self.symlink:
505 self.stripBinaries()
Just van Rossumcef32882002-11-26 00:34:52 +0000506
Jack Jansen0ae32202003-04-09 13:25:43 +0000507 if self.symlink_exec and self.executable:
508 self.message("Symlinking executable %s to %s" % (self.executable,
509 self.execpath), 2)
510 dst = pathjoin(self.bundlepath, self.execpath)
511 makedirs(os.path.dirname(dst))
512 os.symlink(os.path.abspath(self.executable), dst)
Just van Rossum16aebf72002-11-22 11:43:10 +0000513
Jack Jansen0ae32202003-04-09 13:25:43 +0000514 if self.missingModules or self.maybeMissingModules:
515 self.reportMissing()
Just van Rossumcef32882002-11-26 00:34:52 +0000516
Just van Rossum3166f592003-06-20 18:56:10 +0000517 def addPythonFramework(self):
518 # If we're building a standalone app with Python.framework,
Just van Rossumdc31dc02003-06-20 21:43:36 +0000519 # include a minimal subset of Python.framework, *unless*
520 # Python.framework was specified manually in self.libs.
521 for lib in self.libs:
522 if os.path.basename(lib) == "Python.framework":
523 # a Python.framework was specified as a library
524 return
525
Just van Rossum3166f592003-06-20 18:56:10 +0000526 frameworkpath = sys.exec_prefix[:sys.exec_prefix.find(
527 "Python.framework") + len("Python.framework")]
Just van Rossumdc31dc02003-06-20 21:43:36 +0000528
Just van Rossum3166f592003-06-20 18:56:10 +0000529 version = sys.version[:3]
530 frameworkpath = pathjoin(frameworkpath, "Versions", version)
531 destbase = pathjoin("Contents", "Frameworks", "Python.framework",
532 "Versions", version)
533 for item in PYTHONFRAMEWORKGOODIES:
534 src = pathjoin(frameworkpath, item)
535 dst = pathjoin(destbase, item)
536 self.files.append((src, dst))
537
Just van Rossum762d2cc2003-06-29 21:54:12 +0000538 def _getSiteCode(self):
539 return compile(SITE_PY % {"semi_standalone": self.semi_standalone},
540 "<-bundlebuilder.py->", "exec")
541
Jack Jansen0ae32202003-04-09 13:25:43 +0000542 def addPythonModules(self):
543 self.message("Adding Python modules", 1)
Just van Rossumcef32882002-11-26 00:34:52 +0000544
Jack Jansen0ae32202003-04-09 13:25:43 +0000545 if USE_ZIPIMPORT:
546 # Create a zip file containing all modules as pyc.
547 import zipfile
548 relpath = pathjoin("Contents", "Resources", ZIP_ARCHIVE)
549 abspath = pathjoin(self.bundlepath, relpath)
550 zf = zipfile.ZipFile(abspath, "w", zipfile.ZIP_DEFLATED)
551 for name, code, ispkg in self.pymodules:
552 self.message("Adding Python module %s" % name, 2)
553 path, pyc = getPycData(name, code, ispkg)
554 zf.writestr(path, pyc)
555 zf.close()
556 # add site.pyc
557 sitepath = pathjoin(self.bundlepath, "Contents", "Resources",
558 "site" + PYC_EXT)
Just van Rossum762d2cc2003-06-29 21:54:12 +0000559 writePyc(self._getSiteCode(), sitepath)
Jack Jansen0ae32202003-04-09 13:25:43 +0000560 else:
561 # Create individual .pyc files.
562 for name, code, ispkg in self.pymodules:
563 if ispkg:
564 name += ".__init__"
565 path = name.split(".")
566 path = pathjoin("Contents", "Resources", *path) + PYC_EXT
Just van Rossumcef32882002-11-26 00:34:52 +0000567
Jack Jansen0ae32202003-04-09 13:25:43 +0000568 if ispkg:
569 self.message("Adding Python package %s" % path, 2)
570 else:
571 self.message("Adding Python module %s" % path, 2)
Just van Rossumcef32882002-11-26 00:34:52 +0000572
Jack Jansen0ae32202003-04-09 13:25:43 +0000573 abspath = pathjoin(self.bundlepath, path)
574 makedirs(os.path.dirname(abspath))
575 writePyc(code, abspath)
Just van Rossumcef32882002-11-26 00:34:52 +0000576
Jack Jansen0ae32202003-04-09 13:25:43 +0000577 def stripBinaries(self):
578 if not os.path.exists(STRIP_EXEC):
579 self.message("Error: can't strip binaries: no strip program at "
580 "%s" % STRIP_EXEC, 0)
581 else:
Just van Rossum00a0b972003-06-20 21:18:22 +0000582 import stat
Jack Jansen0ae32202003-04-09 13:25:43 +0000583 self.message("Stripping binaries", 1)
Just van Rossum00a0b972003-06-20 21:18:22 +0000584 def walk(top):
585 for name in os.listdir(top):
586 path = pathjoin(top, name)
587 if os.path.islink(path):
588 continue
589 if os.path.isdir(path):
590 walk(path)
591 else:
592 mod = os.stat(path)[stat.ST_MODE]
593 if not (mod & 0100):
594 continue
595 relpath = path[len(self.bundlepath):]
596 self.message("Stripping %s" % relpath, 2)
597 inf, outf = os.popen4("%s -S \"%s\"" %
598 (STRIP_EXEC, path))
599 output = outf.read().strip()
600 if output:
601 # usually not a real problem, like when we're
602 # trying to strip a script
603 self.message("Problem stripping %s:" % relpath, 3)
604 self.message(output, 3)
605 walk(self.bundlepath)
Just van Rossumcef32882002-11-26 00:34:52 +0000606
Jack Jansen0ae32202003-04-09 13:25:43 +0000607 def findDependencies(self):
608 self.message("Finding module dependencies", 1)
609 import modulefinder
610 mf = modulefinder.ModuleFinder(excludes=self.excludeModules)
611 if USE_ZIPIMPORT:
612 # zipimport imports zlib, must add it manually
613 mf.import_hook("zlib")
614 # manually add our own site.py
615 site = mf.add_module("site")
Just van Rossum762d2cc2003-06-29 21:54:12 +0000616 site.__code__ = self._getSiteCode()
617 mf.scan_code(site.__code__, site)
Just van Rossumcef32882002-11-26 00:34:52 +0000618
Jack Jansen0ae32202003-04-09 13:25:43 +0000619 # warnings.py gets imported implicitly from C
620 mf.import_hook("warnings")
Just van Rossum7322b1a2003-02-25 20:15:40 +0000621
Jack Jansen0ae32202003-04-09 13:25:43 +0000622 includeModules = self.includeModules[:]
623 for name in self.includePackages:
624 includeModules.extend(findPackageContents(name).keys())
625 for name in includeModules:
626 try:
627 mf.import_hook(name)
628 except ImportError:
629 self.missingModules.append(name)
Just van Rossumcef32882002-11-26 00:34:52 +0000630
Jack Jansen0ae32202003-04-09 13:25:43 +0000631 mf.run_script(self.mainprogram)
632 modules = mf.modules.items()
633 modules.sort()
634 for name, mod in modules:
Just van Rossum762d2cc2003-06-29 21:54:12 +0000635 path = mod.__file__
636 if path and self.semi_standalone:
637 # skip the standard library
638 if path.startswith(LIB) and not path.startswith(SITE_PACKAGES):
639 continue
640 if path and mod.__code__ is None:
Jack Jansen0ae32202003-04-09 13:25:43 +0000641 # C extension
Jack Jansen0ae32202003-04-09 13:25:43 +0000642 filename = os.path.basename(path)
Just van Rossum79b0ae12003-06-29 22:20:26 +0000643 pathitems = name.split(".")[:-1] + [filename]
644 dstpath = pathjoin(*pathitems)
Jack Jansen0ae32202003-04-09 13:25:43 +0000645 if USE_ZIPIMPORT:
Just van Rossum79b0ae12003-06-29 22:20:26 +0000646 if name != "zlib":
647 # neatly pack all extension modules in a subdirectory,
648 # except zlib, since it's neccesary for bootstrapping.
649 dstpath = pathjoin("ExtensionModules", dstpath)
Jack Jansen0ae32202003-04-09 13:25:43 +0000650 # Python modules are stored in a Zip archive, but put
Just van Rossum762d2cc2003-06-29 21:54:12 +0000651 # extensions in Contents/Resources/. Add a tiny "loader"
Jack Jansen0ae32202003-04-09 13:25:43 +0000652 # program in the Zip archive. Due to Thomas Heller.
Just van Rossum762d2cc2003-06-29 21:54:12 +0000653 source = EXT_LOADER % {"name": name, "filename": dstpath}
Jack Jansen0ae32202003-04-09 13:25:43 +0000654 code = compile(source, "<dynloader for %s>" % name, "exec")
655 mod.__code__ = code
Just van Rossum762d2cc2003-06-29 21:54:12 +0000656 self.files.append((path, pathjoin("Contents", "Resources", dstpath)))
Jack Jansen0ae32202003-04-09 13:25:43 +0000657 if mod.__code__ is not None:
658 ispkg = mod.__path__ is not None
659 if not USE_ZIPIMPORT or name != "site":
660 # Our site.py is doing the bootstrapping, so we must
661 # include a real .pyc file if USE_ZIPIMPORT is True.
662 self.pymodules.append((name, mod.__code__, ispkg))
Just van Rossumcef32882002-11-26 00:34:52 +0000663
Jack Jansen0ae32202003-04-09 13:25:43 +0000664 if hasattr(mf, "any_missing_maybe"):
665 missing, maybe = mf.any_missing_maybe()
666 else:
667 missing = mf.any_missing()
668 maybe = []
669 self.missingModules.extend(missing)
670 self.maybeMissingModules.extend(maybe)
Just van Rossumcef32882002-11-26 00:34:52 +0000671
Jack Jansen0ae32202003-04-09 13:25:43 +0000672 def reportMissing(self):
673 missing = [name for name in self.missingModules
674 if name not in MAYMISS_MODULES]
675 if self.maybeMissingModules:
676 maybe = self.maybeMissingModules
677 else:
678 maybe = [name for name in missing if "." in name]
679 missing = [name for name in missing if "." not in name]
680 missing.sort()
681 maybe.sort()
682 if maybe:
683 self.message("Warning: couldn't find the following submodules:", 1)
684 self.message(" (Note that these could be false alarms -- "
685 "it's not always", 1)
686 self.message(" possible to distinguish between \"from package "
687 "import submodule\" ", 1)
688 self.message(" and \"from package import name\")", 1)
689 for name in maybe:
690 self.message(" ? " + name, 1)
691 if missing:
692 self.message("Warning: couldn't find the following modules:", 1)
693 for name in missing:
694 self.message(" ? " + name, 1)
Just van Rossum74bdca82002-11-28 11:30:56 +0000695
Jack Jansen0ae32202003-04-09 13:25:43 +0000696 def report(self):
697 # XXX something decent
698 import pprint
699 pprint.pprint(self.__dict__)
Just van Rossum762d2cc2003-06-29 21:54:12 +0000700 if self.standalone or self.semi_standalone:
Jack Jansen0ae32202003-04-09 13:25:43 +0000701 self.reportMissing()
Just van Rossumcef32882002-11-26 00:34:52 +0000702
703#
704# Utilities.
705#
706
707SUFFIXES = [_suf for _suf, _mode, _tp in imp.get_suffixes()]
708identifierRE = re.compile(r"[_a-zA-z][_a-zA-Z0-9]*$")
709
710def findPackageContents(name, searchpath=None):
Jack Jansen0ae32202003-04-09 13:25:43 +0000711 head = name.split(".")[-1]
712 if identifierRE.match(head) is None:
713 return {}
714 try:
715 fp, path, (ext, mode, tp) = imp.find_module(head, searchpath)
716 except ImportError:
717 return {}
718 modules = {name: None}
719 if tp == imp.PKG_DIRECTORY and path:
720 files = os.listdir(path)
721 for sub in files:
722 sub, ext = os.path.splitext(sub)
723 fullname = name + "." + sub
724 if sub != "__init__" and fullname not in modules:
725 modules.update(findPackageContents(fullname, [path]))
726 return modules
Just van Rossumcef32882002-11-26 00:34:52 +0000727
728def writePyc(code, path):
Jack Jansen0ae32202003-04-09 13:25:43 +0000729 f = open(path, "wb")
730 f.write(MAGIC)
731 f.write("\0" * 4) # don't bother about a time stamp
732 marshal.dump(code, f)
733 f.close()
Just van Rossumad33d722002-11-21 10:23:04 +0000734
Just van Rossumad33d722002-11-21 10:23:04 +0000735def copy(src, dst, mkdirs=0):
Jack Jansen0ae32202003-04-09 13:25:43 +0000736 """Copy a file or a directory."""
737 if mkdirs:
738 makedirs(os.path.dirname(dst))
739 if os.path.isdir(src):
Just van Rossumdc31dc02003-06-20 21:43:36 +0000740 shutil.copytree(src, dst, symlinks=1)
Jack Jansen0ae32202003-04-09 13:25:43 +0000741 else:
742 shutil.copy2(src, dst)
Just van Rossumad33d722002-11-21 10:23:04 +0000743
744def copytodir(src, dstdir):
Jack Jansen0ae32202003-04-09 13:25:43 +0000745 """Copy a file or a directory to an existing directory."""
746 dst = pathjoin(dstdir, os.path.basename(src))
747 copy(src, dst)
Just van Rossumad33d722002-11-21 10:23:04 +0000748
749def makedirs(dir):
Jack Jansen0ae32202003-04-09 13:25:43 +0000750 """Make all directories leading up to 'dir' including the leaf
751 directory. Don't moan if any path element already exists."""
752 try:
753 os.makedirs(dir)
754 except OSError, why:
755 if why.errno != errno.EEXIST:
756 raise
Just van Rossumad33d722002-11-21 10:23:04 +0000757
758def symlink(src, dst, mkdirs=0):
Jack Jansen0ae32202003-04-09 13:25:43 +0000759 """Copy a file or a directory."""
760 if not os.path.exists(src):
761 raise IOError, "No such file or directory: '%s'" % src
762 if mkdirs:
763 makedirs(os.path.dirname(dst))
764 os.symlink(os.path.abspath(src), dst)
Just van Rossumad33d722002-11-21 10:23:04 +0000765
766def pathjoin(*args):
Jack Jansen0ae32202003-04-09 13:25:43 +0000767 """Safe wrapper for os.path.join: asserts that all but the first
768 argument are relative paths."""
769 for seg in args[1:]:
770 assert seg[0] != "/"
771 return os.path.join(*args)
Just van Rossumad33d722002-11-21 10:23:04 +0000772
773
Just van Rossumceeb9622002-11-21 23:19:37 +0000774cmdline_doc = """\
775Usage:
Just van Rossumf7aba232002-11-22 00:31:50 +0000776 python bundlebuilder.py [options] command
Just van Rossumceeb9622002-11-21 23:19:37 +0000777 python mybuildscript.py [options] command
778
779Commands:
780 build build the application
781 report print a report
782
783Options:
784 -b, --builddir=DIR the build directory; defaults to "build"
785 -n, --name=NAME application name
786 -r, --resource=FILE extra file or folder to be copied to Resources
Just van Rossum7215e082003-02-25 21:00:55 +0000787 -f, --file=SRC:DST extra file or folder to be copied into the bundle;
788 DST must be a path relative to the bundle root
Just van Rossumceeb9622002-11-21 23:19:37 +0000789 -e, --executable=FILE the executable to be used
790 -m, --mainprogram=FILE the Python main program
Jack Jansena03adde2003-02-18 23:29:46 +0000791 -a, --argv add a wrapper main program to create sys.argv
Just van Rossumceeb9622002-11-21 23:19:37 +0000792 -p, --plist=FILE .plist file (default: generate one)
793 --nib=NAME main nib name
794 -c, --creator=CCCC 4-char creator code (default: '????')
Just van Rossum9af69682003-02-02 18:56:37 +0000795 --iconfile=FILE filename of the icon (an .icns file) to be used
Just van Rossum2aa09562003-02-01 08:34:46 +0000796 as the Finder icon
Just van Rossumbe56aae2003-07-04 14:20:03 +0000797 --bundle-id=ID the CFBundleIdentifier, in reverse-dns format
798 (eg. org.python.BuildApplet; this is used for
799 the preferences file name)
Just van Rossumceeb9622002-11-21 23:19:37 +0000800 -l, --link symlink files/folder instead of copying them
Just van Rossum16aebf72002-11-22 11:43:10 +0000801 --link-exec symlink the executable instead of copying it
Just van Rossumcef32882002-11-26 00:34:52 +0000802 --standalone build a standalone application, which is fully
803 independent of a Python installation
Just van Rossum762d2cc2003-06-29 21:54:12 +0000804 --semi-standalone build a standalone application, which depends on
805 an installed Python, yet includes all third-party
806 modules.
Jack Jansen8ba0e802003-05-25 22:00:17 +0000807 --python=FILE Python to use in #! line in stead of current Python
Just van Rossum15624d82003-03-21 09:26:59 +0000808 --lib=FILE shared library or framework to be copied into
809 the bundle
Just van Rossum762d2cc2003-06-29 21:54:12 +0000810 -x, --exclude=MODULE exclude module (with --(semi-)standalone)
811 -i, --include=MODULE include module (with --(semi-)standalone)
812 --package=PACKAGE include a whole package (with --(semi-)standalone)
Just van Rossumcef32882002-11-26 00:34:52 +0000813 --strip strip binaries (remove debug info)
Just van Rossumceeb9622002-11-21 23:19:37 +0000814 -v, --verbose increase verbosity level
815 -q, --quiet decrease verbosity level
816 -h, --help print this message
817"""
818
819def usage(msg=None):
Jack Jansen0ae32202003-04-09 13:25:43 +0000820 if msg:
821 print msg
822 print cmdline_doc
823 sys.exit(1)
Just van Rossumceeb9622002-11-21 23:19:37 +0000824
825def main(builder=None):
Jack Jansen0ae32202003-04-09 13:25:43 +0000826 if builder is None:
827 builder = AppBuilder(verbosity=1)
Just van Rossumceeb9622002-11-21 23:19:37 +0000828
Jack Jansen0ae32202003-04-09 13:25:43 +0000829 shortopts = "b:n:r:f:e:m:c:p:lx:i:hvqa"
830 longopts = ("builddir=", "name=", "resource=", "file=", "executable=",
831 "mainprogram=", "creator=", "nib=", "plist=", "link",
832 "link-exec", "help", "verbose", "quiet", "argv", "standalone",
833 "exclude=", "include=", "package=", "strip", "iconfile=",
Jack Jansenc77f6df2004-12-27 15:51:03 +0000834 "lib=", "python=", "semi-standalone", "bundle-id=", "destroot=")
Just van Rossumceeb9622002-11-21 23:19:37 +0000835
Jack Jansen0ae32202003-04-09 13:25:43 +0000836 try:
837 options, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
838 except getopt.error:
839 usage()
Just van Rossumceeb9622002-11-21 23:19:37 +0000840
Jack Jansen0ae32202003-04-09 13:25:43 +0000841 for opt, arg in options:
842 if opt in ('-b', '--builddir'):
843 builder.builddir = arg
844 elif opt in ('-n', '--name'):
845 builder.name = arg
846 elif opt in ('-r', '--resource'):
Just van Rossumdc31dc02003-06-20 21:43:36 +0000847 builder.resources.append(os.path.normpath(arg))
Jack Jansen0ae32202003-04-09 13:25:43 +0000848 elif opt in ('-f', '--file'):
849 srcdst = arg.split(':')
850 if len(srcdst) != 2:
851 usage("-f or --file argument must be two paths, "
852 "separated by a colon")
853 builder.files.append(srcdst)
854 elif opt in ('-e', '--executable'):
855 builder.executable = arg
856 elif opt in ('-m', '--mainprogram'):
857 builder.mainprogram = arg
858 elif opt in ('-a', '--argv'):
859 builder.argv_emulation = 1
860 elif opt in ('-c', '--creator'):
861 builder.creator = arg
Just van Rossumbe56aae2003-07-04 14:20:03 +0000862 elif opt == '--bundle-id':
863 builder.bundle_id = arg
Jack Jansen0ae32202003-04-09 13:25:43 +0000864 elif opt == '--iconfile':
865 builder.iconfile = arg
866 elif opt == "--lib":
Just van Rossumdc31dc02003-06-20 21:43:36 +0000867 builder.libs.append(os.path.normpath(arg))
Jack Jansen0ae32202003-04-09 13:25:43 +0000868 elif opt == "--nib":
869 builder.nibname = arg
870 elif opt in ('-p', '--plist'):
871 builder.plist = Plist.fromFile(arg)
872 elif opt in ('-l', '--link'):
873 builder.symlink = 1
874 elif opt == '--link-exec':
875 builder.symlink_exec = 1
876 elif opt in ('-h', '--help'):
877 usage()
878 elif opt in ('-v', '--verbose'):
879 builder.verbosity += 1
880 elif opt in ('-q', '--quiet'):
881 builder.verbosity -= 1
882 elif opt == '--standalone':
883 builder.standalone = 1
Just van Rossum762d2cc2003-06-29 21:54:12 +0000884 elif opt == '--semi-standalone':
885 builder.semi_standalone = 1
Jack Jansen8ba0e802003-05-25 22:00:17 +0000886 elif opt == '--python':
887 builder.python = arg
Jack Jansen0ae32202003-04-09 13:25:43 +0000888 elif opt in ('-x', '--exclude'):
889 builder.excludeModules.append(arg)
890 elif opt in ('-i', '--include'):
891 builder.includeModules.append(arg)
892 elif opt == '--package':
893 builder.includePackages.append(arg)
894 elif opt == '--strip':
895 builder.strip = 1
Jack Jansenc77f6df2004-12-27 15:51:03 +0000896 elif opt == '--destroot':
897 builder.destroot = arg
Just van Rossumceeb9622002-11-21 23:19:37 +0000898
Jack Jansen0ae32202003-04-09 13:25:43 +0000899 if len(args) != 1:
900 usage("Must specify one command ('build', 'report' or 'help')")
901 command = args[0]
Just van Rossumceeb9622002-11-21 23:19:37 +0000902
Jack Jansen0ae32202003-04-09 13:25:43 +0000903 if command == "build":
904 builder.setup()
905 builder.build()
906 elif command == "report":
907 builder.setup()
908 builder.report()
909 elif command == "help":
910 usage()
911 else:
912 usage("Unknown command '%s'" % command)
Just van Rossumceeb9622002-11-21 23:19:37 +0000913
914
Just van Rossumad33d722002-11-21 10:23:04 +0000915def buildapp(**kwargs):
Jack Jansen0ae32202003-04-09 13:25:43 +0000916 builder = AppBuilder(**kwargs)
917 main(builder)
Just van Rossumad33d722002-11-21 10:23:04 +0000918
919
920if __name__ == "__main__":
Jack Jansen0ae32202003-04-09 13:25:43 +0000921 main()