Mercurial > cpython-lru_cache-weakref
annotate Lib/plat-mac/bundlebuilder.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | af9b6c43804e |
| children | 34a7a9158372 |
| rev | line source |
|---|---|
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
2 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
3 """\ |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
4 bundlebuilder.py -- Tools to assemble MacOS X (application) bundles. |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
5 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
6 This module contains two classes to build so called "bundles" for |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
7 MacOS X. BundleBuilder is a general tool, AppBuilder is a subclass |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
8 specialized in building application bundles. |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
9 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
10 [Bundle|App]Builder objects are instantiated with a bunch of keyword |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
11 arguments, and have a build() method that will do all the work. See |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
12 the class doc strings for a description of the constructor arguments. |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
13 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
14 The module contains a main program that can be used in two ways: |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
15 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
16 % python bundlebuilder.py [options] build |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
17 % python buildapp.py [options] build |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
18 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
19 Where "buildapp.py" is a user-supplied setup.py-like script following |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
20 this model: |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
21 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
22 from bundlebuilder import buildapp |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
23 buildapp(<lots-of-keyword-args>) |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
24 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
25 """ |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
26 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
27 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
28 __all__ = ["BundleBuilder", "BundleBuilderError", "AppBuilder", "buildapp"] |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
29 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
30 |
|
46967
6df0394abbf1
Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents:
38196
diff
changeset
|
31 from warnings import warnpy3k |
|
47958
e7a6a4515ab0
fix test_py3kwarns
Benjamin Peterson <benjamin@python.org>
parents:
46967
diff
changeset
|
32 warnpy3k("In 3.x, the bundlebuilder module is removed.", stacklevel=2) |
|
46967
6df0394abbf1
Add warnings to and deprecated all those Mac modules
Benjamin Peterson <benjamin@python.org>
parents:
38196
diff
changeset
|
33 |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
34 import sys |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
35 import os, errno, shutil |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
36 import imp, marshal |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
37 import re |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
38 from copy import deepcopy |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
39 import getopt |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
40 from plistlib import Plist |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
41 from types import FunctionType as function |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
42 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
43 class BundleBuilderError(Exception): pass |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
44 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
45 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
46 class Defaults: |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
47 |
| 28545 | 48 """Class attributes that don't start with an underscore and are |
| 49 not functions or classmethods are (deep)copied to self.__dict__. | |
| 50 This allows for mutable default values. | |
| 51 """ | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
52 |
| 28545 | 53 def __init__(self, **kwargs): |
| 54 defaults = self._getDefaults() | |
| 55 defaults.update(kwargs) | |
| 56 self.__dict__.update(defaults) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
57 |
| 28545 | 58 def _getDefaults(cls): |
| 59 defaults = {} | |
|
29800
1272f79547ba
Fixed a bug that's been there from the beginning but wasn't noticed
Just van Rossum <just@letterror.com>
parents:
29761
diff
changeset
|
60 for base in cls.__bases__: |
|
1272f79547ba
Fixed a bug that's been there from the beginning but wasn't noticed
Just van Rossum <just@letterror.com>
parents:
29761
diff
changeset
|
61 if hasattr(base, "_getDefaults"): |
|
1272f79547ba
Fixed a bug that's been there from the beginning but wasn't noticed
Just van Rossum <just@letterror.com>
parents:
29761
diff
changeset
|
62 defaults.update(base._getDefaults()) |
| 28545 | 63 for name, value in cls.__dict__.items(): |
| 64 if name[0] != "_" and not isinstance(value, | |
| 65 (function, classmethod)): | |
| 66 defaults[name] = deepcopy(value) | |
| 67 return defaults | |
| 68 _getDefaults = classmethod(_getDefaults) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
69 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
70 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
71 class BundleBuilder(Defaults): |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
72 |
| 28545 | 73 """BundleBuilder is a barebones class for assembling bundles. It |
| 74 knows nothing about executables or icons, it only copies files | |
| 75 and creates the PkgInfo and Info.plist files. | |
| 76 """ | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
77 |
| 28545 | 78 # (Note that Defaults.__init__ (deep)copies these values to |
| 79 # instance variables. Mutable defaults are therefore safe.) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
80 |
| 28545 | 81 # Name of the bundle, with or without extension. |
| 82 name = None | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
83 |
| 28545 | 84 # The property list ("plist") |
| 85 plist = Plist(CFBundleDevelopmentRegion = "English", | |
| 86 CFBundleInfoDictionaryVersion = "6.0") | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
87 |
| 28545 | 88 # The type of the bundle. |
| 89 type = "BNDL" | |
| 90 # The creator code of the bundle. | |
| 91 creator = None | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
92 |
| 29761 | 93 # the CFBundleIdentifier (this is used for the preferences file name) |
| 94 bundle_id = None | |
| 95 | |
| 28545 | 96 # List of files that have to be copied to <bundle>/Contents/Resources. |
| 97 resources = [] | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
98 |
| 28545 | 99 # List of (src, dest) tuples; dest should be a path relative to the bundle |
| 100 # (eg. "Contents/Resources/MyStuff/SomeFile.ext). | |
| 101 files = [] | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
102 |
| 28545 | 103 # List of shared libraries (dylibs, Frameworks) to bundle with the app |
| 104 # will be placed in Contents/Frameworks | |
| 105 libs = [] | |
|
28357
8d7ffe4caad9
Patch #681927 from Robin Dunn: add option to add shared libraries or
Just van Rossum <just@letterror.com>
parents:
28336
diff
changeset
|
106 |
| 28545 | 107 # Directory where the bundle will be assembled. |
| 108 builddir = "build" | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
109 |
| 28545 | 110 # Make symlinks instead copying files. This is handy during debugging, but |
| 111 # makes the bundle non-distributable. | |
| 112 symlink = 0 | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
113 |
| 28545 | 114 # Verbosity level. |
| 115 verbosity = 1 | |
|
35003
52fed2d0641a
whitespace normalisation
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34291
diff
changeset
|
116 |
| 34291 | 117 # Destination root directory |
| 118 destroot = "" | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
119 |
| 28545 | 120 def setup(self): |
| 121 # XXX rethink self.name munging, this is brittle. | |
| 122 self.name, ext = os.path.splitext(self.name) | |
| 123 if not ext: | |
| 124 ext = ".bundle" | |
| 125 bundleextension = ext | |
| 126 # misc (derived) attributes | |
| 127 self.bundlepath = pathjoin(self.builddir, self.name + bundleextension) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
128 |
| 28545 | 129 plist = self.plist |
| 130 plist.CFBundleName = self.name | |
| 131 plist.CFBundlePackageType = self.type | |
| 132 if self.creator is None: | |
| 133 if hasattr(plist, "CFBundleSignature"): | |
| 134 self.creator = plist.CFBundleSignature | |
| 135 else: | |
| 136 self.creator = "????" | |
| 137 plist.CFBundleSignature = self.creator | |
| 29761 | 138 if self.bundle_id: |
| 139 plist.CFBundleIdentifier = self.bundle_id | |
| 140 elif not hasattr(plist, "CFBundleIdentifier"): | |
| 28545 | 141 plist.CFBundleIdentifier = self.name |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
142 |
| 28545 | 143 def build(self): |
| 144 """Build the bundle.""" | |
| 145 builddir = self.builddir | |
| 146 if builddir and not os.path.exists(builddir): | |
| 147 os.mkdir(builddir) | |
| 148 self.message("Building %s" % repr(self.bundlepath), 1) | |
| 149 if os.path.exists(self.bundlepath): | |
| 150 shutil.rmtree(self.bundlepath) | |
|
38176
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
151 if os.path.exists(self.bundlepath + '~'): |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
152 shutil.rmtree(self.bundlepath + '~') |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
153 bp = self.bundlepath |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
154 |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
155 # Create the app bundle in a temporary location and then |
|
38196
ac506e2df04d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
38176
diff
changeset
|
156 # rename the completed bundle. This way the Finder will |
|
38176
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
157 # never see an incomplete bundle (where it might pick up |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
158 # and cache the wrong meta data) |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
159 self.bundlepath = bp + '~' |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
160 try: |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
161 os.mkdir(self.bundlepath) |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
162 self.preProcess() |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
163 self._copyFiles() |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
164 self._addMetaFiles() |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
165 self.postProcess() |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
166 os.rename(self.bundlepath, bp) |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
167 finally: |
|
cdf8f5334426
Rework the build system for osx applications:
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
35003
diff
changeset
|
168 self.bundlepath = bp |
| 28545 | 169 self.message("Done.", 1) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
170 |
| 28545 | 171 def preProcess(self): |
| 172 """Hook for subclasses.""" | |
| 173 pass | |
| 174 def postProcess(self): | |
| 175 """Hook for subclasses.""" | |
| 176 pass | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
177 |
| 28545 | 178 def _addMetaFiles(self): |
| 179 contents = pathjoin(self.bundlepath, "Contents") | |
| 180 makedirs(contents) | |
| 181 # | |
| 182 # Write Contents/PkgInfo | |
| 183 assert len(self.type) == len(self.creator) == 4, \ | |
| 184 "type and creator must be 4-byte strings." | |
| 185 pkginfo = pathjoin(contents, "PkgInfo") | |
| 186 f = open(pkginfo, "wb") | |
| 187 f.write(self.type + self.creator) | |
| 188 f.close() | |
| 189 # | |
| 190 # Write Contents/Info.plist | |
| 191 infoplist = pathjoin(contents, "Info.plist") | |
| 192 self.plist.write(infoplist) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
193 |
| 28545 | 194 def _copyFiles(self): |
| 195 files = self.files[:] | |
| 196 for path in self.resources: | |
| 197 files.append((path, pathjoin("Contents", "Resources", | |
|
29568
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
198 os.path.basename(path)))) |
| 28545 | 199 for path in self.libs: |
| 200 files.append((path, pathjoin("Contents", "Frameworks", | |
|
29568
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
201 os.path.basename(path)))) |
| 28545 | 202 if self.symlink: |
| 203 self.message("Making symbolic links", 1) | |
| 204 msg = "Making symlink from" | |
| 205 else: | |
| 206 self.message("Copying files", 1) | |
| 207 msg = "Copying" | |
| 208 files.sort() | |
| 209 for src, dst in files: | |
| 210 if os.path.isdir(src): | |
| 211 self.message("%s %s/ to %s/" % (msg, src, dst), 2) | |
| 212 else: | |
| 213 self.message("%s %s to %s" % (msg, src, dst), 2) | |
| 214 dst = pathjoin(self.bundlepath, dst) | |
| 215 if self.symlink: | |
| 216 symlink(src, dst, mkdirs=1) | |
| 217 else: | |
| 218 copy(src, dst, mkdirs=1) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
219 |
| 28545 | 220 def message(self, msg, level=0): |
| 221 if level <= self.verbosity: | |
| 222 indent = "" | |
| 223 if level > 1: | |
| 224 indent = (level - 1) * " " | |
| 225 sys.stderr.write(indent + msg + "\n") | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
226 |
| 28545 | 227 def report(self): |
| 228 # XXX something decent | |
| 229 pass | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
230 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
231 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
232 if __debug__: |
| 28545 | 233 PYC_EXT = ".pyc" |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
234 else: |
| 28545 | 235 PYC_EXT = ".pyo" |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
236 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
237 MAGIC = imp.get_magic() |
|
27022
e2c88c451c19
Replaced imp.set_frozenmodules() cruft with proper zipimport support.
Just van Rossum <just@letterror.com>
parents:
26884
diff
changeset
|
238 USE_ZIPIMPORT = "zipimport" in sys.builtin_module_names |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
239 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
240 # For standalone apps, we have our own minimal site.py. We don't need |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
241 # all the cruft of the real site.py. |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
242 SITE_PY = """\ |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
243 import sys |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
244 if not %(semi_standalone)s: |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
245 del sys.path[1:] # sys.path[0] is Contents/Resources/ |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
246 """ |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
247 |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
248 ZIP_ARCHIVE = "Modules.zip" |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
249 SITE_PY_ZIP = SITE_PY + ("sys.path.append(sys.path[0] + '/%s')\n" % ZIP_ARCHIVE) |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
250 |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
251 def getPycData(fullname, code, ispkg): |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
252 if ispkg: |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
253 fullname += ".__init__" |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
254 path = fullname.replace(".", os.sep) + PYC_EXT |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
255 return path, MAGIC + '\0\0\0\0' + marshal.dumps(code) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
256 |
|
28066
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
257 # |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
258 # Extension modules can't be in the modules zip archive, so a placeholder |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
259 # is added instead, that loads the extension from a specified location. |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
260 # |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
261 EXT_LOADER = """\ |
|
27022
e2c88c451c19
Replaced imp.set_frozenmodules() cruft with proper zipimport support.
Just van Rossum <just@letterror.com>
parents:
26884
diff
changeset
|
262 def __load(): |
| 28545 | 263 import imp, sys, os |
| 264 for p in sys.path: | |
| 265 path = os.path.join(p, "%(filename)s") | |
| 266 if os.path.exists(path): | |
| 267 break | |
| 268 else: | |
| 269 assert 0, "file not found: %(filename)s" | |
| 270 mod = imp.load_dynamic("%(name)s", path) | |
|
27022
e2c88c451c19
Replaced imp.set_frozenmodules() cruft with proper zipimport support.
Just van Rossum <just@letterror.com>
parents:
26884
diff
changeset
|
271 |
|
e2c88c451c19
Replaced imp.set_frozenmodules() cruft with proper zipimport support.
Just van Rossum <just@letterror.com>
parents:
26884
diff
changeset
|
272 __load() |
|
e2c88c451c19
Replaced imp.set_frozenmodules() cruft with proper zipimport support.
Just van Rossum <just@letterror.com>
parents:
26884
diff
changeset
|
273 del __load |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
274 """ |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
275 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
276 MAYMISS_MODULES = ['mac', 'os2', 'nt', 'ntpath', 'dos', 'dospath', |
| 28545 | 277 'win32api', 'ce', '_winreg', 'nturl2path', 'sitecustomize', |
| 278 'org.python.core', 'riscos', 'riscosenviron', 'riscospath' | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
279 ] |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
280 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
281 STRIP_EXEC = "/usr/bin/strip" |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
282 |
|
28066
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
283 # |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
284 # We're using a stock interpreter to run the app, yet we need |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
285 # a way to pass the Python main program to the interpreter. The |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
286 # bootstrapping script fires up the interpreter with the right |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
287 # arguments. os.execve() is used as OSX doesn't like us to |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
288 # start a real new process. Also, the executable name must match |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
289 # the CFBundleExecutable value in the Info.plist, so we lie |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
290 # deliberately with argv[0]. The actual Python executable is |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
291 # passed in an environment variable so we can "repair" |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
292 # sys.executable later. |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
293 # |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
294 BOOTSTRAP_SCRIPT = """\ |
|
28074
b04625cea061
use the same Python for running the bootstrap script and the main program
Just van Rossum <just@letterror.com>
parents:
28073
diff
changeset
|
295 #!%(hashbang)s |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
296 |
|
28064
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
297 import sys, os |
|
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
298 execdir = os.path.dirname(sys.argv[0]) |
|
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
299 executable = os.path.join(execdir, "%(executable)s") |
|
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
300 resdir = os.path.join(os.path.dirname(execdir), "Resources") |
|
28357
8d7ffe4caad9
Patch #681927 from Robin Dunn: add option to add shared libraries or
Just van Rossum <just@letterror.com>
parents:
28336
diff
changeset
|
301 libdir = os.path.join(os.path.dirname(execdir), "Frameworks") |
|
28064
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
302 mainprogram = os.path.join(resdir, "%(mainprogram)s") |
|
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
303 |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
304 if %(optimize)s: |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
305 sys.argv.insert(1, '-O') |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
306 |
|
28064
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
307 sys.argv.insert(1, mainprogram) |
| 29761 | 308 if %(standalone)s or %(semi_standalone)s: |
| 309 os.environ["PYTHONPATH"] = resdir | |
| 310 if %(standalone)s: | |
| 311 os.environ["PYTHONHOME"] = resdir | |
| 312 else: | |
| 313 pypath = os.getenv("PYTHONPATH", "") | |
| 314 if pypath: | |
| 315 pypath = ":" + pypath | |
| 316 os.environ["PYTHONPATH"] = resdir + pypath | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
317 |
|
28064
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
318 os.environ["PYTHONEXECUTABLE"] = executable |
|
28357
8d7ffe4caad9
Patch #681927 from Robin Dunn: add option to add shared libraries or
Just van Rossum <just@letterror.com>
parents:
28336
diff
changeset
|
319 os.environ["DYLD_LIBRARY_PATH"] = libdir |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
320 os.environ["DYLD_FRAMEWORK_PATH"] = libdir |
|
28064
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
321 os.execve(executable, sys.argv, os.environ) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
322 """ |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
323 |
|
28066
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
324 |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
325 # |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
326 # Optional wrapper that converts "dropped files" into sys.argv values. |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
327 # |
|
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
328 ARGV_EMULATOR = """\ |
|
27954
f310894107cb
Added an argv_emulation option (command line option: --argv or -a) which
Jack Jansen <jack.jansen@cwi.nl>
parents:
27931
diff
changeset
|
329 import argvemulator, os |
|
f310894107cb
Added an argv_emulation option (command line option: --argv or -a) which
Jack Jansen <jack.jansen@cwi.nl>
parents:
27931
diff
changeset
|
330 |
|
f310894107cb
Added an argv_emulation option (command line option: --argv or -a) which
Jack Jansen <jack.jansen@cwi.nl>
parents:
27931
diff
changeset
|
331 argvemulator.ArgvCollector().mainloop() |
|
f310894107cb
Added an argv_emulation option (command line option: --argv or -a) which
Jack Jansen <jack.jansen@cwi.nl>
parents:
27931
diff
changeset
|
332 execfile(os.path.join(os.path.split(__file__)[0], "%(realmainprogram)s")) |
|
f310894107cb
Added an argv_emulation option (command line option: --argv or -a) which
Jack Jansen <jack.jansen@cwi.nl>
parents:
27931
diff
changeset
|
333 """ |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
334 |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
335 # |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
336 # When building a standalone app with Python.framework, we need to copy |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
337 # a subset from Python.framework to the bundle. The following list |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
338 # specifies exactly what items we'll copy. |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
339 # |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
340 PYTHONFRAMEWORKGOODIES = [ |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
341 "Python", # the Python core library |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
342 "Resources/English.lproj", |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
343 "Resources/Info.plist", |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
344 "Resources/version.plist", |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
345 ] |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
346 |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
347 def isFramework(): |
|
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
348 return sys.exec_prefix.find("Python.framework") > 0 |
|
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
349 |
|
28066
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
350 |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
351 LIB = os.path.join(sys.prefix, "lib", "python" + sys.version[:3]) |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
352 SITE_PACKAGES = os.path.join(LIB, "site-packages") |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
353 |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
354 |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
355 class AppBuilder(BundleBuilder): |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
356 |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
357 use_zipimport = USE_ZIPIMPORT |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
358 |
| 28545 | 359 # Override type of the bundle. |
| 360 type = "APPL" | |
|
28172
a6cd9d6d5ca3
Moved some application-bundle specific code from the BundleBuilder class to
Jack Jansen <jack.jansen@cwi.nl>
parents:
28074
diff
changeset
|
361 |
| 28545 | 362 # platform, name of the subfolder of Contents that contains the executable. |
| 363 platform = "MacOS" | |
|
28172
a6cd9d6d5ca3
Moved some application-bundle specific code from the BundleBuilder class to
Jack Jansen <jack.jansen@cwi.nl>
parents:
28074
diff
changeset
|
364 |
| 28545 | 365 # A Python main program. If this argument is given, the main |
| 366 # executable in the bundle will be a small wrapper that invokes | |
| 367 # the main program. (XXX Discuss why.) | |
| 368 mainprogram = None | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
369 |
| 28545 | 370 # The main executable. If a Python main program is specified |
| 371 # the executable will be copied to Resources and be invoked | |
| 372 # by the wrapper program mentioned above. Otherwise it will | |
| 373 # simply be used as the main executable. | |
| 374 executable = None | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
375 |
| 28545 | 376 # The name of the main nib, for Cocoa apps. *Must* be specified |
| 377 # when building a Cocoa app. | |
| 378 nibname = None | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
379 |
| 28545 | 380 # The name of the icon file to be copied to Resources and used for |
| 381 # the Finder icon. | |
| 382 iconfile = None | |
|
27581
2d7c0cbc83cf
icon support by Robin Dunn, closes patch #678218
Just van Rossum <just@letterror.com>
parents:
27280
diff
changeset
|
383 |
| 28545 | 384 # Symlink the executable instead of copying it. |
| 385 symlink_exec = 0 | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
386 |
| 28545 | 387 # If True, build standalone app. |
| 388 standalone = 0 | |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
389 |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
390 # If True, build semi-standalone app (only includes third-party modules). |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
391 semi_standalone = 0 |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
392 |
|
29261
34f42e3450b4
Added a --python option, which sets the python to be used in the #! line
Jack Jansen <jack.jansen@cwi.nl>
parents:
28545
diff
changeset
|
393 # If set, use this for #! lines in stead of sys.executable |
|
34f42e3450b4
Added a --python option, which sets the python to be used in the #! line
Jack Jansen <jack.jansen@cwi.nl>
parents:
28545
diff
changeset
|
394 python = None |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
395 |
| 28545 | 396 # If True, add a real main program that emulates sys.argv before calling |
| 397 # mainprogram | |
| 398 argv_emulation = 0 | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
399 |
| 28545 | 400 # The following attributes are only used when building a standalone app. |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
401 |
| 28545 | 402 # Exclude these modules. |
| 403 excludeModules = [] | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
404 |
| 28545 | 405 # Include these modules. |
| 406 includeModules = [] | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
407 |
| 28545 | 408 # Include these packages. |
| 409 includePackages = [] | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
410 |
|
29565
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
411 # Strip binaries from debug info. |
| 28545 | 412 strip = 0 |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
413 |
| 28545 | 414 # Found Python modules: [(name, codeobject, ispkg), ...] |
| 415 pymodules = [] | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
416 |
| 28545 | 417 # Modules that modulefinder couldn't find: |
| 418 missingModules = [] | |
| 419 maybeMissingModules = [] | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
420 |
| 28545 | 421 def setup(self): |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
422 if ((self.standalone or self.semi_standalone) |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
423 and self.mainprogram is None): |
| 28545 | 424 raise BundleBuilderError, ("must specify 'mainprogram' when " |
| 425 "building a standalone application.") | |
| 426 if self.mainprogram is None and self.executable is None: | |
| 427 raise BundleBuilderError, ("must specify either or both of " | |
| 428 "'executable' and 'mainprogram'") | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
429 |
| 28545 | 430 self.execdir = pathjoin("Contents", self.platform) |
|
28172
a6cd9d6d5ca3
Moved some application-bundle specific code from the BundleBuilder class to
Jack Jansen <jack.jansen@cwi.nl>
parents:
28074
diff
changeset
|
431 |
| 28545 | 432 if self.name is not None: |
| 433 pass | |
| 434 elif self.mainprogram is not None: | |
| 435 self.name = os.path.splitext(os.path.basename(self.mainprogram))[0] | |
| 436 elif executable is not None: | |
| 437 self.name = os.path.splitext(os.path.basename(self.executable))[0] | |
| 438 if self.name[-4:] != ".app": | |
| 439 self.name += ".app" | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
440 |
| 28545 | 441 if self.executable is None: |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
442 if not self.standalone and not isFramework(): |
| 28545 | 443 self.symlink_exec = 1 |
|
29756
3c1f78340b65
If a --python option is used to specify the Python to use in the #!
Jack Jansen <jack.jansen@cwi.nl>
parents:
29692
diff
changeset
|
444 if self.python: |
|
3c1f78340b65
If a --python option is used to specify the Python to use in the #!
Jack Jansen <jack.jansen@cwi.nl>
parents:
29692
diff
changeset
|
445 self.executable = self.python |
|
3c1f78340b65
If a --python option is used to specify the Python to use in the #!
Jack Jansen <jack.jansen@cwi.nl>
parents:
29692
diff
changeset
|
446 else: |
|
3c1f78340b65
If a --python option is used to specify the Python to use in the #!
Jack Jansen <jack.jansen@cwi.nl>
parents:
29692
diff
changeset
|
447 self.executable = sys.executable |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
448 |
| 28545 | 449 if self.nibname: |
| 450 self.plist.NSMainNibFile = self.nibname | |
| 451 if not hasattr(self.plist, "NSPrincipalClass"): | |
| 452 self.plist.NSPrincipalClass = "NSApplication" | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
453 |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
454 if self.standalone and isFramework(): |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
455 self.addPythonFramework() |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
456 |
| 28545 | 457 BundleBuilder.setup(self) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
458 |
| 28545 | 459 self.plist.CFBundleExecutable = self.name |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
460 |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
461 if self.standalone or self.semi_standalone: |
| 28545 | 462 self.findDependencies() |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
463 |
| 28545 | 464 def preProcess(self): |
| 465 resdir = "Contents/Resources" | |
| 466 if self.executable is not None: | |
| 467 if self.mainprogram is None: | |
| 468 execname = self.name | |
| 469 else: | |
| 470 execname = os.path.basename(self.executable) | |
| 471 execpath = pathjoin(self.execdir, execname) | |
| 472 if not self.symlink_exec: | |
| 34291 | 473 self.files.append((self.destroot + self.executable, execpath)) |
| 28545 | 474 self.execpath = execpath |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
475 |
| 28545 | 476 if self.mainprogram is not None: |
| 477 mainprogram = os.path.basename(self.mainprogram) | |
| 478 self.files.append((self.mainprogram, pathjoin(resdir, mainprogram))) | |
| 479 if self.argv_emulation: | |
| 480 # Change the main program, and create the helper main program (which | |
| 481 # does argv collection and then calls the real main). | |
| 482 # Also update the included modules (if we're creating a standalone | |
| 483 # program) and the plist | |
| 484 realmainprogram = mainprogram | |
| 485 mainprogram = '__argvemulator_' + mainprogram | |
| 486 resdirpath = pathjoin(self.bundlepath, resdir) | |
| 487 mainprogrampath = pathjoin(resdirpath, mainprogram) | |
| 488 makedirs(resdirpath) | |
| 489 open(mainprogrampath, "w").write(ARGV_EMULATOR % locals()) | |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
490 if self.standalone or self.semi_standalone: |
| 28545 | 491 self.includeModules.append("argvemulator") |
| 492 self.includeModules.append("os") | |
| 493 if not self.plist.has_key("CFBundleDocumentTypes"): | |
| 494 self.plist["CFBundleDocumentTypes"] = [ | |
| 495 { "CFBundleTypeOSTypes" : [ | |
| 496 "****", | |
| 497 "fold", | |
| 498 "disk"], | |
| 499 "CFBundleTypeRole": "Viewer"}] | |
| 500 # Write bootstrap script | |
| 501 executable = os.path.basename(self.executable) | |
| 502 execdir = pathjoin(self.bundlepath, self.execdir) | |
| 503 bootstrappath = pathjoin(execdir, self.name) | |
| 504 makedirs(execdir) | |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
505 if self.standalone or self.semi_standalone: |
| 28545 | 506 # XXX we're screwed when the end user has deleted |
| 507 # /usr/bin/python | |
| 508 hashbang = "/usr/bin/python" | |
|
29261
34f42e3450b4
Added a --python option, which sets the python to be used in the #! line
Jack Jansen <jack.jansen@cwi.nl>
parents:
28545
diff
changeset
|
509 elif self.python: |
|
34f42e3450b4
Added a --python option, which sets the python to be used in the #! line
Jack Jansen <jack.jansen@cwi.nl>
parents:
28545
diff
changeset
|
510 hashbang = self.python |
| 28545 | 511 else: |
| 512 hashbang = os.path.realpath(sys.executable) | |
| 513 standalone = self.standalone | |
| 29761 | 514 semi_standalone = self.semi_standalone |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
515 optimize = sys.flags.optimize |
| 28545 | 516 open(bootstrappath, "w").write(BOOTSTRAP_SCRIPT % locals()) |
| 517 os.chmod(bootstrappath, 0775) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
518 |
| 28545 | 519 if self.iconfile is not None: |
| 520 iconbase = os.path.basename(self.iconfile) | |
| 521 self.plist.CFBundleIconFile = iconbase | |
| 522 self.files.append((self.iconfile, pathjoin(resdir, iconbase))) | |
|
27581
2d7c0cbc83cf
icon support by Robin Dunn, closes patch #678218
Just van Rossum <just@letterror.com>
parents:
27280
diff
changeset
|
523 |
| 28545 | 524 def postProcess(self): |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
525 if self.standalone or self.semi_standalone: |
| 28545 | 526 self.addPythonModules() |
| 527 if self.strip and not self.symlink: | |
| 528 self.stripBinaries() | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
529 |
| 28545 | 530 if self.symlink_exec and self.executable: |
| 531 self.message("Symlinking executable %s to %s" % (self.executable, | |
| 532 self.execpath), 2) | |
| 533 dst = pathjoin(self.bundlepath, self.execpath) | |
| 534 makedirs(os.path.dirname(dst)) | |
| 535 os.symlink(os.path.abspath(self.executable), dst) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
536 |
| 28545 | 537 if self.missingModules or self.maybeMissingModules: |
| 538 self.reportMissing() | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
539 |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
540 def addPythonFramework(self): |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
541 # If we're building a standalone app with Python.framework, |
|
29568
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
542 # include a minimal subset of Python.framework, *unless* |
|
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
543 # Python.framework was specified manually in self.libs. |
|
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
544 for lib in self.libs: |
|
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
545 if os.path.basename(lib) == "Python.framework": |
|
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
546 # a Python.framework was specified as a library |
|
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
547 return |
|
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
548 |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
549 frameworkpath = sys.exec_prefix[:sys.exec_prefix.find( |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
550 "Python.framework") + len("Python.framework")] |
|
29568
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
551 |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
552 version = sys.version[:3] |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
553 frameworkpath = pathjoin(frameworkpath, "Versions", version) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
554 destbase = pathjoin("Contents", "Frameworks", "Python.framework", |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
555 "Versions", version) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
556 for item in PYTHONFRAMEWORKGOODIES: |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
557 src = pathjoin(frameworkpath, item) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
558 dst = pathjoin(destbase, item) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
559 self.files.append((src, dst)) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
560 |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
561 def _getSiteCode(self): |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
562 if self.use_zipimport: |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
563 return compile(SITE_PY % {"semi_standalone": self.semi_standalone}, |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
564 "<-bundlebuilder.py->", "exec") |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
565 |
| 28545 | 566 def addPythonModules(self): |
| 567 self.message("Adding Python modules", 1) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
568 |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
569 if self.use_zipimport: |
| 28545 | 570 # Create a zip file containing all modules as pyc. |
| 571 import zipfile | |
| 572 relpath = pathjoin("Contents", "Resources", ZIP_ARCHIVE) | |
| 573 abspath = pathjoin(self.bundlepath, relpath) | |
| 574 zf = zipfile.ZipFile(abspath, "w", zipfile.ZIP_DEFLATED) | |
| 575 for name, code, ispkg in self.pymodules: | |
| 576 self.message("Adding Python module %s" % name, 2) | |
| 577 path, pyc = getPycData(name, code, ispkg) | |
| 578 zf.writestr(path, pyc) | |
| 579 zf.close() | |
| 580 # add site.pyc | |
| 581 sitepath = pathjoin(self.bundlepath, "Contents", "Resources", | |
| 582 "site" + PYC_EXT) | |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
583 writePyc(self._getSiteCode(), sitepath) |
| 28545 | 584 else: |
| 585 # Create individual .pyc files. | |
| 586 for name, code, ispkg in self.pymodules: | |
| 587 if ispkg: | |
| 588 name += ".__init__" | |
| 589 path = name.split(".") | |
| 590 path = pathjoin("Contents", "Resources", *path) + PYC_EXT | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
591 |
| 28545 | 592 if ispkg: |
| 593 self.message("Adding Python package %s" % path, 2) | |
| 594 else: | |
| 595 self.message("Adding Python module %s" % path, 2) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
596 |
| 28545 | 597 abspath = pathjoin(self.bundlepath, path) |
| 598 makedirs(os.path.dirname(abspath)) | |
| 599 writePyc(code, abspath) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
600 |
| 28545 | 601 def stripBinaries(self): |
| 602 if not os.path.exists(STRIP_EXEC): | |
| 603 self.message("Error: can't strip binaries: no strip program at " | |
| 604 "%s" % STRIP_EXEC, 0) | |
| 605 else: | |
|
29565
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
606 import stat |
| 28545 | 607 self.message("Stripping binaries", 1) |
|
29565
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
608 def walk(top): |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
609 for name in os.listdir(top): |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
610 path = pathjoin(top, name) |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
611 if os.path.islink(path): |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
612 continue |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
613 if os.path.isdir(path): |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
614 walk(path) |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
615 else: |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
616 mod = os.stat(path)[stat.ST_MODE] |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
617 if not (mod & 0100): |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
618 continue |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
619 relpath = path[len(self.bundlepath):] |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
620 self.message("Stripping %s" % relpath, 2) |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
621 inf, outf = os.popen4("%s -S \"%s\"" % |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
622 (STRIP_EXEC, path)) |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
623 output = outf.read().strip() |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
624 if output: |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
625 # usually not a real problem, like when we're |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
626 # trying to strip a script |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
627 self.message("Problem stripping %s:" % relpath, 3) |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
628 self.message(output, 3) |
|
8e92cc04b64b
Reworked --strip option: it will now look at _any_ file that's marked
Just van Rossum <just@letterror.com>
parents:
29563
diff
changeset
|
629 walk(self.bundlepath) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
630 |
| 28545 | 631 def findDependencies(self): |
| 632 self.message("Finding module dependencies", 1) | |
| 633 import modulefinder | |
| 634 mf = modulefinder.ModuleFinder(excludes=self.excludeModules) | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
635 if self.use_zipimport: |
| 28545 | 636 # zipimport imports zlib, must add it manually |
| 637 mf.import_hook("zlib") | |
| 638 # manually add our own site.py | |
| 639 site = mf.add_module("site") | |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
640 site.__code__ = self._getSiteCode() |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
641 mf.scan_code(site.__code__, site) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
642 |
| 28545 | 643 # warnings.py gets imported implicitly from C |
| 644 mf.import_hook("warnings") | |
|
28064
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
645 |
| 28545 | 646 includeModules = self.includeModules[:] |
| 647 for name in self.includePackages: | |
| 648 includeModules.extend(findPackageContents(name).keys()) | |
| 649 for name in includeModules: | |
| 650 try: | |
| 651 mf.import_hook(name) | |
| 652 except ImportError: | |
| 653 self.missingModules.append(name) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
654 |
| 28545 | 655 mf.run_script(self.mainprogram) |
| 656 modules = mf.modules.items() | |
| 657 modules.sort() | |
| 658 for name, mod in modules: | |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
659 path = mod.__file__ |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
660 if path and self.semi_standalone: |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
661 # skip the standard library |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
662 if path.startswith(LIB) and not path.startswith(SITE_PACKAGES): |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
663 continue |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
664 if path and mod.__code__ is None: |
| 28545 | 665 # C extension |
| 666 filename = os.path.basename(path) | |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
667 pathitems = name.split(".")[:-1] + [filename] |
|
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
668 dstpath = pathjoin(*pathitems) |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
669 if self.use_zipimport: |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
670 if name != "zlib": |
|
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
671 # neatly pack all extension modules in a subdirectory, |
|
51775
af9b6c43804e
Issue #5341: Fix a variety of spelling errors.
Mark Dickinson <dickinsm@gmail.com>
parents:
50451
diff
changeset
|
672 # except zlib, since it's necessary for bootstrapping. |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
673 dstpath = pathjoin("ExtensionModules", dstpath) |
| 28545 | 674 # Python modules are stored in a Zip archive, but put |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
675 # extensions in Contents/Resources/. Add a tiny "loader" |
| 28545 | 676 # program in the Zip archive. Due to Thomas Heller. |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
677 source = EXT_LOADER % {"name": name, "filename": dstpath} |
| 28545 | 678 code = compile(source, "<dynloader for %s>" % name, "exec") |
| 679 mod.__code__ = code | |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
680 self.files.append((path, pathjoin("Contents", "Resources", dstpath))) |
| 28545 | 681 if mod.__code__ is not None: |
| 682 ispkg = mod.__path__ is not None | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
683 if not self.use_zipimport or name != "site": |
| 28545 | 684 # Our site.py is doing the bootstrapping, so we must |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
685 # include a real .pyc file if self.use_zipimport is True. |
| 28545 | 686 self.pymodules.append((name, mod.__code__, ispkg)) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
687 |
| 28545 | 688 if hasattr(mf, "any_missing_maybe"): |
| 689 missing, maybe = mf.any_missing_maybe() | |
| 690 else: | |
| 691 missing = mf.any_missing() | |
| 692 maybe = [] | |
| 693 self.missingModules.extend(missing) | |
| 694 self.maybeMissingModules.extend(maybe) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
695 |
| 28545 | 696 def reportMissing(self): |
| 697 missing = [name for name in self.missingModules | |
| 698 if name not in MAYMISS_MODULES] | |
| 699 if self.maybeMissingModules: | |
| 700 maybe = self.maybeMissingModules | |
| 701 else: | |
| 702 maybe = [name for name in missing if "." in name] | |
| 703 missing = [name for name in missing if "." not in name] | |
| 704 missing.sort() | |
| 705 maybe.sort() | |
| 706 if maybe: | |
| 707 self.message("Warning: couldn't find the following submodules:", 1) | |
| 708 self.message(" (Note that these could be false alarms -- " | |
| 709 "it's not always", 1) | |
| 710 self.message(" possible to distinguish between \"from package " | |
| 711 "import submodule\" ", 1) | |
| 712 self.message(" and \"from package import name\")", 1) | |
| 713 for name in maybe: | |
| 714 self.message(" ? " + name, 1) | |
| 715 if missing: | |
| 716 self.message("Warning: couldn't find the following modules:", 1) | |
| 717 for name in missing: | |
| 718 self.message(" ? " + name, 1) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
719 |
| 28545 | 720 def report(self): |
| 721 # XXX something decent | |
| 722 import pprint | |
| 723 pprint.pprint(self.__dict__) | |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
724 if self.standalone or self.semi_standalone: |
| 28545 | 725 self.reportMissing() |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
726 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
727 # |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
728 # Utilities. |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
729 # |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
730 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
731 SUFFIXES = [_suf for _suf, _mode, _tp in imp.get_suffixes()] |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
732 identifierRE = re.compile(r"[_a-zA-z][_a-zA-Z0-9]*$") |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
733 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
734 def findPackageContents(name, searchpath=None): |
| 28545 | 735 head = name.split(".")[-1] |
| 736 if identifierRE.match(head) is None: | |
| 737 return {} | |
| 738 try: | |
| 739 fp, path, (ext, mode, tp) = imp.find_module(head, searchpath) | |
| 740 except ImportError: | |
| 741 return {} | |
| 742 modules = {name: None} | |
| 743 if tp == imp.PKG_DIRECTORY and path: | |
| 744 files = os.listdir(path) | |
| 745 for sub in files: | |
| 746 sub, ext = os.path.splitext(sub) | |
| 747 fullname = name + "." + sub | |
| 748 if sub != "__init__" and fullname not in modules: | |
| 749 modules.update(findPackageContents(fullname, [path])) | |
| 750 return modules | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
751 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
752 def writePyc(code, path): |
| 28545 | 753 f = open(path, "wb") |
| 754 f.write(MAGIC) | |
| 755 f.write("\0" * 4) # don't bother about a time stamp | |
| 756 marshal.dump(code, f) | |
| 757 f.close() | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
758 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
759 def copy(src, dst, mkdirs=0): |
| 28545 | 760 """Copy a file or a directory.""" |
| 761 if mkdirs: | |
| 762 makedirs(os.path.dirname(dst)) | |
| 763 if os.path.isdir(src): | |
|
29568
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
764 shutil.copytree(src, dst, symlinks=1) |
| 28545 | 765 else: |
| 766 shutil.copy2(src, dst) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
767 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
768 def copytodir(src, dstdir): |
| 28545 | 769 """Copy a file or a directory to an existing directory.""" |
| 770 dst = pathjoin(dstdir, os.path.basename(src)) | |
| 771 copy(src, dst) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
772 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
773 def makedirs(dir): |
| 28545 | 774 """Make all directories leading up to 'dir' including the leaf |
| 775 directory. Don't moan if any path element already exists.""" | |
| 776 try: | |
| 777 os.makedirs(dir) | |
| 778 except OSError, why: | |
| 779 if why.errno != errno.EEXIST: | |
| 780 raise | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
781 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
782 def symlink(src, dst, mkdirs=0): |
| 28545 | 783 """Copy a file or a directory.""" |
| 784 if not os.path.exists(src): | |
| 785 raise IOError, "No such file or directory: '%s'" % src | |
| 786 if mkdirs: | |
| 787 makedirs(os.path.dirname(dst)) | |
| 788 os.symlink(os.path.abspath(src), dst) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
789 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
790 def pathjoin(*args): |
| 28545 | 791 """Safe wrapper for os.path.join: asserts that all but the first |
| 792 argument are relative paths.""" | |
| 793 for seg in args[1:]: | |
| 794 assert seg[0] != "/" | |
| 795 return os.path.join(*args) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
796 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
797 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
798 cmdline_doc = """\ |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
799 Usage: |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
800 python bundlebuilder.py [options] command |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
801 python mybuildscript.py [options] command |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
802 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
803 Commands: |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
804 build build the application |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
805 report print a report |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
806 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
807 Options: |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
808 -b, --builddir=DIR the build directory; defaults to "build" |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
809 -n, --name=NAME application name |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
810 -r, --resource=FILE extra file or folder to be copied to Resources |
|
28067
9d297d3de36f
- renamed the --copyfile option to --file.
Just van Rossum <just@letterror.com>
parents:
28066
diff
changeset
|
811 -f, --file=SRC:DST extra file or folder to be copied into the bundle; |
|
9d297d3de36f
- renamed the --copyfile option to --file.
Just van Rossum <just@letterror.com>
parents:
28066
diff
changeset
|
812 DST must be a path relative to the bundle root |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
813 -e, --executable=FILE the executable to be used |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
814 -m, --mainprogram=FILE the Python main program |
|
27954
f310894107cb
Added an argv_emulation option (command line option: --argv or -a) which
Jack Jansen <jack.jansen@cwi.nl>
parents:
27931
diff
changeset
|
815 -a, --argv add a wrapper main program to create sys.argv |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
816 -p, --plist=FILE .plist file (default: generate one) |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
817 --nib=NAME main nib name |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
818 -c, --creator=CCCC 4-char creator code (default: '????') |
|
27602
c4214c20b21d
jeez, now I know why I shouldn't even _want_ to learn sh.
Just van Rossum <just@letterror.com>
parents:
27581
diff
changeset
|
819 --iconfile=FILE filename of the icon (an .icns file) to be used |
|
27581
2d7c0cbc83cf
icon support by Robin Dunn, closes patch #678218
Just van Rossum <just@letterror.com>
parents:
27280
diff
changeset
|
820 as the Finder icon |
| 29761 | 821 --bundle-id=ID the CFBundleIdentifier, in reverse-dns format |
| 822 (eg. org.python.BuildApplet; this is used for | |
| 823 the preferences file name) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
824 -l, --link symlink files/folder instead of copying them |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
825 --link-exec symlink the executable instead of copying it |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
826 --standalone build a standalone application, which is fully |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
827 independent of a Python installation |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
828 --semi-standalone build a standalone application, which depends on |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
829 an installed Python, yet includes all third-party |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
830 modules. |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
831 --no-zipimport Do not copy code into a zip file |
|
29261
34f42e3450b4
Added a --python option, which sets the python to be used in the #! line
Jack Jansen <jack.jansen@cwi.nl>
parents:
28545
diff
changeset
|
832 --python=FILE Python to use in #! line in stead of current Python |
|
28357
8d7ffe4caad9
Patch #681927 from Robin Dunn: add option to add shared libraries or
Just van Rossum <just@letterror.com>
parents:
28336
diff
changeset
|
833 --lib=FILE shared library or framework to be copied into |
|
8d7ffe4caad9
Patch #681927 from Robin Dunn: add option to add shared libraries or
Just van Rossum <just@letterror.com>
parents:
28336
diff
changeset
|
834 the bundle |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
835 -x, --exclude=MODULE exclude module (with --(semi-)standalone) |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
836 -i, --include=MODULE include module (with --(semi-)standalone) |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
837 --package=PACKAGE include a whole package (with --(semi-)standalone) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
838 --strip strip binaries (remove debug info) |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
839 -v, --verbose increase verbosity level |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
840 -q, --quiet decrease verbosity level |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
841 -h, --help print this message |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
842 """ |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
843 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
844 def usage(msg=None): |
| 28545 | 845 if msg: |
| 846 print msg | |
| 847 print cmdline_doc | |
| 848 sys.exit(1) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
849 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
850 def main(builder=None): |
| 28545 | 851 if builder is None: |
| 852 builder = AppBuilder(verbosity=1) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
853 |
| 28545 | 854 shortopts = "b:n:r:f:e:m:c:p:lx:i:hvqa" |
| 855 longopts = ("builddir=", "name=", "resource=", "file=", "executable=", | |
| 856 "mainprogram=", "creator=", "nib=", "plist=", "link", | |
| 857 "link-exec", "help", "verbose", "quiet", "argv", "standalone", | |
| 858 "exclude=", "include=", "package=", "strip", "iconfile=", | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
859 "lib=", "python=", "semi-standalone", "bundle-id=", "destroot=" |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
860 "no-zipimport" |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
861 ) |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
862 |
| 28545 | 863 try: |
| 864 options, args = getopt.getopt(sys.argv[1:], shortopts, longopts) | |
| 865 except getopt.error: | |
| 866 usage() | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
867 |
| 28545 | 868 for opt, arg in options: |
| 869 if opt in ('-b', '--builddir'): | |
| 870 builder.builddir = arg | |
| 871 elif opt in ('-n', '--name'): | |
| 872 builder.name = arg | |
| 873 elif opt in ('-r', '--resource'): | |
|
29568
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
874 builder.resources.append(os.path.normpath(arg)) |
| 28545 | 875 elif opt in ('-f', '--file'): |
| 876 srcdst = arg.split(':') | |
| 877 if len(srcdst) != 2: | |
| 878 usage("-f or --file argument must be two paths, " | |
| 879 "separated by a colon") | |
| 880 builder.files.append(srcdst) | |
| 881 elif opt in ('-e', '--executable'): | |
| 882 builder.executable = arg | |
| 883 elif opt in ('-m', '--mainprogram'): | |
| 884 builder.mainprogram = arg | |
| 885 elif opt in ('-a', '--argv'): | |
| 886 builder.argv_emulation = 1 | |
| 887 elif opt in ('-c', '--creator'): | |
| 888 builder.creator = arg | |
| 29761 | 889 elif opt == '--bundle-id': |
| 890 builder.bundle_id = arg | |
| 28545 | 891 elif opt == '--iconfile': |
| 892 builder.iconfile = arg | |
| 893 elif opt == "--lib": | |
|
29568
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
894 builder.libs.append(os.path.normpath(arg)) |
| 28545 | 895 elif opt == "--nib": |
| 896 builder.nibname = arg | |
| 897 elif opt in ('-p', '--plist'): | |
| 898 builder.plist = Plist.fromFile(arg) | |
| 899 elif opt in ('-l', '--link'): | |
| 900 builder.symlink = 1 | |
| 901 elif opt == '--link-exec': | |
| 902 builder.symlink_exec = 1 | |
| 903 elif opt in ('-h', '--help'): | |
| 904 usage() | |
| 905 elif opt in ('-v', '--verbose'): | |
| 906 builder.verbosity += 1 | |
| 907 elif opt in ('-q', '--quiet'): | |
| 908 builder.verbosity -= 1 | |
| 909 elif opt == '--standalone': | |
| 910 builder.standalone = 1 | |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
911 elif opt == '--semi-standalone': |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
912 builder.semi_standalone = 1 |
|
29261
34f42e3450b4
Added a --python option, which sets the python to be used in the #! line
Jack Jansen <jack.jansen@cwi.nl>
parents:
28545
diff
changeset
|
913 elif opt == '--python': |
|
34f42e3450b4
Added a --python option, which sets the python to be used in the #! line
Jack Jansen <jack.jansen@cwi.nl>
parents:
28545
diff
changeset
|
914 builder.python = arg |
| 28545 | 915 elif opt in ('-x', '--exclude'): |
| 916 builder.excludeModules.append(arg) | |
| 917 elif opt in ('-i', '--include'): | |
| 918 builder.includeModules.append(arg) | |
| 919 elif opt == '--package': | |
| 920 builder.includePackages.append(arg) | |
| 921 elif opt == '--strip': | |
| 922 builder.strip = 1 | |
| 34291 | 923 elif opt == '--destroot': |
| 924 builder.destroot = arg | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
925 elif opt == '--no-zipimport': |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
926 builder.use_zipimport = False |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
927 |
| 28545 | 928 if len(args) != 1: |
| 929 usage("Must specify one command ('build', 'report' or 'help')") | |
| 930 command = args[0] | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
931 |
| 28545 | 932 if command == "build": |
| 933 builder.setup() | |
| 934 builder.build() | |
| 935 elif command == "report": | |
| 936 builder.setup() | |
| 937 builder.report() | |
| 938 elif command == "help": | |
| 939 usage() | |
| 940 else: | |
| 941 usage("Unknown command '%s'" % command) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
942 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
943 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
944 def buildapp(**kwargs): |
| 28545 | 945 builder = AppBuilder(**kwargs) |
| 946 main(builder) | |
|
26884
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
947 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
948 |
|
f0f9acca4164
Moved most of Mac/Lib hierarchy to Lib/plat-mac: it can be used both
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff
changeset
|
949 if __name__ == "__main__": |
| 28545 | 950 main() |
