Mercurial > cpython-lru_cache-weakref
annotate Lib/plat-mac/bundlebuilder.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| 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 |
|
61258
f6785bce54b5
In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
60278
diff
changeset
|
276 MAYMISS_MODULES = ['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 ] |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
345 |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
346 def isFramework(): |
|
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
347 return sys.exec_prefix.find("Python.framework") > 0 |
|
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
348 |
|
28066
d6730590526c
added some comments, minor tweaks
Just van Rossum <just@letterror.com>
parents:
28064
diff
changeset
|
349 |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
350 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
|
351 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
|
352 |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
353 |
|
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
|
354 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
|
355 |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
356 use_zipimport = USE_ZIPIMPORT |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
357 |
| 28545 | 358 # Override type of the bundle. |
| 359 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
|
360 |
| 28545 | 361 # platform, name of the subfolder of Contents that contains the executable. |
| 362 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
|
363 |
| 28545 | 364 # A Python main program. If this argument is given, the main |
| 365 # executable in the bundle will be a small wrapper that invokes | |
| 366 # the main program. (XXX Discuss why.) | |
| 367 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
|
368 |
| 28545 | 369 # The main executable. If a Python main program is specified |
| 370 # the executable will be copied to Resources and be invoked | |
| 371 # by the wrapper program mentioned above. Otherwise it will | |
| 372 # simply be used as the main executable. | |
| 373 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
|
374 |
| 28545 | 375 # The name of the main nib, for Cocoa apps. *Must* be specified |
| 376 # when building a Cocoa app. | |
| 377 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
|
378 |
| 28545 | 379 # The name of the icon file to be copied to Resources and used for |
| 380 # the Finder icon. | |
| 381 iconfile = None | |
|
27581
2d7c0cbc83cf
icon support by Robin Dunn, closes patch #678218
Just van Rossum <just@letterror.com>
parents:
27280
diff
changeset
|
382 |
| 28545 | 383 # Symlink the executable instead of copying it. |
| 384 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
|
385 |
| 28545 | 386 # If True, build standalone app. |
| 387 standalone = 0 | |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
388 |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
389 # 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
|
390 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
|
391 |
|
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
|
392 # 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
|
393 python = None |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
394 |
| 28545 | 395 # If True, add a real main program that emulates sys.argv before calling |
| 396 # mainprogram | |
| 397 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
|
398 |
| 28545 | 399 # 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
|
400 |
| 28545 | 401 # Exclude these modules. |
| 402 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
|
403 |
| 28545 | 404 # Include these modules. |
| 405 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
|
406 |
| 28545 | 407 # Include these packages. |
| 408 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
|
409 |
|
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
|
410 # Strip binaries from debug info. |
| 28545 | 411 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
|
412 |
| 28545 | 413 # Found Python modules: [(name, codeobject, ispkg), ...] |
| 414 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
|
415 |
| 28545 | 416 # Modules that modulefinder couldn't find: |
| 417 missingModules = [] | |
| 418 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
|
419 |
| 28545 | 420 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
|
421 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
|
422 and self.mainprogram is None): |
| 28545 | 423 raise BundleBuilderError, ("must specify 'mainprogram' when " |
| 424 "building a standalone application.") | |
| 425 if self.mainprogram is None and self.executable is None: | |
| 426 raise BundleBuilderError, ("must specify either or both of " | |
| 427 "'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
|
428 |
| 28545 | 429 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
|
430 |
| 28545 | 431 if self.name is not None: |
| 432 pass | |
| 433 elif self.mainprogram is not None: | |
| 434 self.name = os.path.splitext(os.path.basename(self.mainprogram))[0] | |
|
58795
ca67c37cd26d
Merged revisions 78035,78040,78043,78049-78050,78052-78054 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55857
diff
changeset
|
435 elif self.executable is not None: |
| 28545 | 436 self.name = os.path.splitext(os.path.basename(self.executable))[0] |
| 437 if self.name[-4:] != ".app": | |
| 438 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
|
439 |
| 28545 | 440 if self.executable is None: |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
441 if not self.standalone and not isFramework(): |
| 28545 | 442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 |
| 28545 | 448 if self.nibname: |
| 449 self.plist.NSMainNibFile = self.nibname | |
| 450 if not hasattr(self.plist, "NSPrincipalClass"): | |
| 451 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
|
452 |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
453 if self.standalone and isFramework(): |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
454 self.addPythonFramework() |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
455 |
| 28545 | 456 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
|
457 |
| 28545 | 458 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
|
459 |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
460 if self.standalone or self.semi_standalone: |
| 28545 | 461 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
|
462 |
| 28545 | 463 def preProcess(self): |
| 464 resdir = "Contents/Resources" | |
| 465 if self.executable is not None: | |
| 466 if self.mainprogram is None: | |
| 467 execname = self.name | |
| 468 else: | |
| 469 execname = os.path.basename(self.executable) | |
| 470 execpath = pathjoin(self.execdir, execname) | |
| 471 if not self.symlink_exec: | |
| 34291 | 472 self.files.append((self.destroot + self.executable, execpath)) |
| 28545 | 473 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
|
474 |
| 28545 | 475 if self.mainprogram is not None: |
| 476 mainprogram = os.path.basename(self.mainprogram) | |
| 477 self.files.append((self.mainprogram, pathjoin(resdir, mainprogram))) | |
| 478 if self.argv_emulation: | |
| 479 # Change the main program, and create the helper main program (which | |
| 480 # does argv collection and then calls the real main). | |
| 481 # Also update the included modules (if we're creating a standalone | |
| 482 # program) and the plist | |
| 483 realmainprogram = mainprogram | |
| 484 mainprogram = '__argvemulator_' + mainprogram | |
| 485 resdirpath = pathjoin(self.bundlepath, resdir) | |
| 486 mainprogrampath = pathjoin(resdirpath, mainprogram) | |
| 487 makedirs(resdirpath) | |
| 488 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
|
489 if self.standalone or self.semi_standalone: |
| 28545 | 490 self.includeModules.append("argvemulator") |
| 491 self.includeModules.append("os") | |
|
60278
e29a2e03e739
Silence DeprecationWarnings from uses of has_key and <> in plat-mac.
Mark Dickinson <dickinsm@gmail.com>
parents:
58777
diff
changeset
|
492 if "CFBundleDocumentTypes" not in self.plist: |
| 28545 | 493 self.plist["CFBundleDocumentTypes"] = [ |
| 494 { "CFBundleTypeOSTypes" : [ | |
| 495 "****", | |
| 496 "fold", | |
| 497 "disk"], | |
| 498 "CFBundleTypeRole": "Viewer"}] | |
| 499 # Write bootstrap script | |
| 500 executable = os.path.basename(self.executable) | |
| 501 execdir = pathjoin(self.bundlepath, self.execdir) | |
| 502 bootstrappath = pathjoin(execdir, self.name) | |
| 503 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
|
504 if self.standalone or self.semi_standalone: |
| 28545 | 505 # XXX we're screwed when the end user has deleted |
| 506 # /usr/bin/python | |
| 507 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
|
508 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
|
509 hashbang = self.python |
| 28545 | 510 else: |
| 511 hashbang = os.path.realpath(sys.executable) | |
| 512 standalone = self.standalone | |
| 29761 | 513 semi_standalone = self.semi_standalone |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
514 optimize = sys.flags.optimize |
| 28545 | 515 open(bootstrappath, "w").write(BOOTSTRAP_SCRIPT % locals()) |
| 516 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
|
517 |
| 28545 | 518 if self.iconfile is not None: |
| 519 iconbase = os.path.basename(self.iconfile) | |
| 520 self.plist.CFBundleIconFile = iconbase | |
| 521 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
|
522 |
| 28545 | 523 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
|
524 if self.standalone or self.semi_standalone: |
| 28545 | 525 self.addPythonModules() |
| 526 if self.strip and not self.symlink: | |
| 527 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
|
528 |
| 28545 | 529 if self.symlink_exec and self.executable: |
| 530 self.message("Symlinking executable %s to %s" % (self.executable, | |
| 531 self.execpath), 2) | |
| 532 dst = pathjoin(self.bundlepath, self.execpath) | |
| 533 makedirs(os.path.dirname(dst)) | |
| 534 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
|
535 |
| 28545 | 536 if self.missingModules or self.maybeMissingModules: |
| 537 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
|
538 |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
539 def addPythonFramework(self): |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
540 # 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
|
541 # 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
|
542 # 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
|
543 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
|
544 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
|
545 # 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
|
546 return |
|
ad02a38a96ea
- do the right thing with symlinks inside directories we're copying
Just van Rossum <just@letterror.com>
parents:
29566
diff
changeset
|
547 |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
548 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
|
549 "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
|
550 |
|
29562
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
551 version = sys.version[:3] |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
552 frameworkpath = pathjoin(frameworkpath, "Versions", version) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
553 destbase = pathjoin("Contents", "Frameworks", "Python.framework", |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
554 "Versions", version) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
555 for item in PYTHONFRAMEWORKGOODIES: |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
556 src = pathjoin(frameworkpath, item) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
557 dst = pathjoin(destbase, item) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
558 self.files.append((src, dst)) |
|
448c1441964f
Add initial standalone support for Python.framework
Just van Rossum <just@letterror.com>
parents:
29261
diff
changeset
|
559 |
|
29691
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
560 def _getSiteCode(self): |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
561 if self.use_zipimport: |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
562 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
|
563 "<-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
|
564 |
| 28545 | 565 def addPythonModules(self): |
| 566 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
|
567 |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
568 if self.use_zipimport: |
| 28545 | 569 # Create a zip file containing all modules as pyc. |
| 570 import zipfile | |
| 571 relpath = pathjoin("Contents", "Resources", ZIP_ARCHIVE) | |
| 572 abspath = pathjoin(self.bundlepath, relpath) | |
| 573 zf = zipfile.ZipFile(abspath, "w", zipfile.ZIP_DEFLATED) | |
| 574 for name, code, ispkg in self.pymodules: | |
| 575 self.message("Adding Python module %s" % name, 2) | |
| 576 path, pyc = getPycData(name, code, ispkg) | |
| 577 zf.writestr(path, pyc) | |
| 578 zf.close() | |
| 579 # add site.pyc | |
| 580 sitepath = pathjoin(self.bundlepath, "Contents", "Resources", | |
| 581 "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
|
582 writePyc(self._getSiteCode(), sitepath) |
| 28545 | 583 else: |
| 584 # Create individual .pyc files. | |
| 585 for name, code, ispkg in self.pymodules: | |
| 586 if ispkg: | |
| 587 name += ".__init__" | |
| 588 path = name.split(".") | |
| 589 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
|
590 |
| 28545 | 591 if ispkg: |
| 592 self.message("Adding Python package %s" % path, 2) | |
| 593 else: | |
| 594 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
|
595 |
| 28545 | 596 abspath = pathjoin(self.bundlepath, path) |
| 597 makedirs(os.path.dirname(abspath)) | |
| 598 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
|
599 |
| 28545 | 600 def stripBinaries(self): |
| 601 if not os.path.exists(STRIP_EXEC): | |
| 602 self.message("Error: can't strip binaries: no strip program at " | |
| 603 "%s" % STRIP_EXEC, 0) | |
| 604 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
|
605 import stat |
| 28545 | 606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 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
|
618 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
|
619 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
|
620 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
|
621 (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
|
622 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
|
623 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
|
624 # 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
|
625 # 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
|
626 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
|
627 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
|
628 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
|
629 |
| 28545 | 630 def findDependencies(self): |
| 631 self.message("Finding module dependencies", 1) | |
| 632 import modulefinder | |
| 633 mf = modulefinder.ModuleFinder(excludes=self.excludeModules) | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
634 if self.use_zipimport: |
| 28545 | 635 # zipimport imports zlib, must add it manually |
| 636 mf.import_hook("zlib") | |
| 637 # manually add our own site.py | |
| 638 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
|
639 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
|
640 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
|
641 |
| 28545 | 642 # warnings.py gets imported implicitly from C |
| 643 mf.import_hook("warnings") | |
|
28064
324896b7f4e1
Resolving parts of #688907:
Just van Rossum <just@letterror.com>
parents:
28050
diff
changeset
|
644 |
| 28545 | 645 includeModules = self.includeModules[:] |
| 646 for name in self.includePackages: | |
| 647 includeModules.extend(findPackageContents(name).keys()) | |
| 648 for name in includeModules: | |
| 649 try: | |
| 650 mf.import_hook(name) | |
| 651 except ImportError: | |
| 652 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
|
653 |
| 28545 | 654 mf.run_script(self.mainprogram) |
| 655 modules = mf.modules.items() | |
| 656 modules.sort() | |
| 657 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
|
658 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
|
659 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
|
660 # 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
|
661 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
|
662 continue |
|
537c8b1aef7f
- added --semi-standalone option that builds apps that depend on an
Just van Rossum <just@letterror.com>
parents:
29568
diff
changeset
|
663 if path and mod.__code__ is None: |
| 28545 | 664 # C extension |
| 665 filename = os.path.basename(path) | |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
666 pathitems = name.split(".")[:-1] + [filename] |
|
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
667 dstpath = pathjoin(*pathitems) |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
668 if self.use_zipimport: |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
669 if name != "zlib": |
|
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
670 # neatly pack all extension modules in a subdirectory, |
|
55049
74c0a78114ae
Merged revisions 69846 via svnmerge from
Jesus Cea <jcea@jcea.es>
parents:
47958
diff
changeset
|
671 # except zlib, since it's necessary for bootstrapping. |
|
29692
c4f9ff291229
restore 2.2 compatibility:
Just van Rossum <just@letterror.com>
parents:
29691
diff
changeset
|
672 dstpath = pathjoin("ExtensionModules", dstpath) |
| 28545 | 673 # 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
|
674 # extensions in Contents/Resources/. Add a tiny "loader" |
| 28545 | 675 # 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
|
676 source = EXT_LOADER % {"name": name, "filename": dstpath} |
| 28545 | 677 code = compile(source, "<dynloader for %s>" % name, "exec") |
| 678 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
|
679 self.files.append((path, pathjoin("Contents", "Resources", dstpath))) |
| 28545 | 680 if mod.__code__ is not None: |
| 681 ispkg = mod.__path__ is not None | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
682 if not self.use_zipimport or name != "site": |
| 28545 | 683 # 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
|
684 # include a real .pyc file if self.use_zipimport is True. |
| 28545 | 685 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
|
686 |
| 28545 | 687 if hasattr(mf, "any_missing_maybe"): |
| 688 missing, maybe = mf.any_missing_maybe() | |
| 689 else: | |
| 690 missing = mf.any_missing() | |
| 691 maybe = [] | |
| 692 self.missingModules.extend(missing) | |
| 693 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
|
694 |
| 28545 | 695 def reportMissing(self): |
| 696 missing = [name for name in self.missingModules | |
| 697 if name not in MAYMISS_MODULES] | |
| 698 if self.maybeMissingModules: | |
| 699 maybe = self.maybeMissingModules | |
| 700 else: | |
| 701 maybe = [name for name in missing if "." in name] | |
| 702 missing = [name for name in missing if "." not in name] | |
| 703 missing.sort() | |
| 704 maybe.sort() | |
| 705 if maybe: | |
| 706 self.message("Warning: couldn't find the following submodules:", 1) | |
| 707 self.message(" (Note that these could be false alarms -- " | |
| 708 "it's not always", 1) | |
| 709 self.message(" possible to distinguish between \"from package " | |
| 710 "import submodule\" ", 1) | |
| 711 self.message(" and \"from package import name\")", 1) | |
| 712 for name in maybe: | |
| 713 self.message(" ? " + name, 1) | |
| 714 if missing: | |
| 715 self.message("Warning: couldn't find the following modules:", 1) | |
| 716 for name in missing: | |
| 717 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
|
718 |
| 28545 | 719 def report(self): |
| 720 # XXX something decent | |
| 721 import pprint | |
| 722 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
|
723 if self.standalone or self.semi_standalone: |
| 28545 | 724 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
|
725 |
|
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 # 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
|
728 # |
|
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 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
|
731 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
|
732 |
|
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 def findPackageContents(name, searchpath=None): |
| 28545 | 734 head = name.split(".")[-1] |
| 735 if identifierRE.match(head) is None: | |
| 736 return {} | |
| 737 try: | |
| 738 fp, path, (ext, mode, tp) = imp.find_module(head, searchpath) | |
| 739 except ImportError: | |
| 740 return {} | |
| 741 modules = {name: None} | |
| 742 if tp == imp.PKG_DIRECTORY and path: | |
| 743 files = os.listdir(path) | |
| 744 for sub in files: | |
| 745 sub, ext = os.path.splitext(sub) | |
| 746 fullname = name + "." + sub | |
| 747 if sub != "__init__" and fullname not in modules: | |
| 748 modules.update(findPackageContents(fullname, [path])) | |
| 749 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
|
750 |
|
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 def writePyc(code, path): |
| 28545 | 752 f = open(path, "wb") |
| 753 f.write(MAGIC) | |
| 754 f.write("\0" * 4) # don't bother about a time stamp | |
| 755 marshal.dump(code, f) | |
| 756 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
|
757 |
|
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 def copy(src, dst, mkdirs=0): |
| 28545 | 759 """Copy a file or a directory.""" |
| 760 if mkdirs: | |
| 761 makedirs(os.path.dirname(dst)) | |
| 762 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
|
763 shutil.copytree(src, dst, symlinks=1) |
| 28545 | 764 else: |
| 765 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
|
766 |
|
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 def copytodir(src, dstdir): |
| 28545 | 768 """Copy a file or a directory to an existing directory.""" |
| 769 dst = pathjoin(dstdir, os.path.basename(src)) | |
| 770 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
|
771 |
|
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 def makedirs(dir): |
| 28545 | 773 """Make all directories leading up to 'dir' including the leaf |
| 774 directory. Don't moan if any path element already exists.""" | |
| 775 try: | |
| 776 os.makedirs(dir) | |
| 777 except OSError, why: | |
| 778 if why.errno != errno.EEXIST: | |
| 779 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
|
780 |
|
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 def symlink(src, dst, mkdirs=0): |
| 28545 | 782 """Copy a file or a directory.""" |
| 783 if not os.path.exists(src): | |
| 784 raise IOError, "No such file or directory: '%s'" % src | |
| 785 if mkdirs: | |
| 786 makedirs(os.path.dirname(dst)) | |
| 787 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
|
788 |
|
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 def pathjoin(*args): |
| 28545 | 790 """Safe wrapper for os.path.join: asserts that all but the first |
| 791 argument are relative paths.""" | |
| 792 for seg in args[1:]: | |
| 793 assert seg[0] != "/" | |
| 794 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
|
795 |
|
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 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
|
798 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
|
799 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
|
800 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
|
801 |
|
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 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
|
803 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
|
804 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
|
805 |
|
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 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
|
807 -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
|
808 -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
|
809 -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
|
810 -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
|
811 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
|
812 -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
|
813 -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
|
814 -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
|
815 -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
|
816 --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
|
817 -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
|
818 --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
|
819 as the Finder icon |
| 29761 | 820 --bundle-id=ID the CFBundleIdentifier, in reverse-dns format |
| 821 (eg. org.python.BuildApplet; this is used for | |
| 822 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
|
823 -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
|
824 --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
|
825 --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
|
826 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
|
827 --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
|
828 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
|
829 modules. |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
830 --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
|
831 --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
|
832 --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
|
833 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
|
834 -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
|
835 -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
|
836 --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
|
837 --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
|
838 -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
|
839 -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
|
840 -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
|
841 """ |
|
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 def usage(msg=None): |
| 28545 | 844 if msg: |
| 845 print msg | |
| 846 print cmdline_doc | |
| 847 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
|
848 |
|
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 def main(builder=None): |
| 28545 | 850 if builder is None: |
| 851 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
|
852 |
| 28545 | 853 shortopts = "b:n:r:f:e:m:c:p:lx:i:hvqa" |
| 854 longopts = ("builddir=", "name=", "resource=", "file=", "executable=", | |
| 855 "mainprogram=", "creator=", "nib=", "plist=", "link", | |
| 856 "link-exec", "help", "verbose", "quiet", "argv", "standalone", | |
| 857 "exclude=", "include=", "package=", "strip", "iconfile=", | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
858 "lib=", "python=", "semi-standalone", "bundle-id=", "destroot=" |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
859 "no-zipimport" |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
860 ) |
|
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
|
861 |
| 28545 | 862 try: |
| 863 options, args = getopt.getopt(sys.argv[1:], shortopts, longopts) | |
| 864 except getopt.error: | |
| 865 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
|
866 |
| 28545 | 867 for opt, arg in options: |
| 868 if opt in ('-b', '--builddir'): | |
| 869 builder.builddir = arg | |
| 870 elif opt in ('-n', '--name'): | |
| 871 builder.name = arg | |
| 872 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
|
873 builder.resources.append(os.path.normpath(arg)) |
| 28545 | 874 elif opt in ('-f', '--file'): |
| 875 srcdst = arg.split(':') | |
| 876 if len(srcdst) != 2: | |
| 877 usage("-f or --file argument must be two paths, " | |
| 878 "separated by a colon") | |
| 879 builder.files.append(srcdst) | |
| 880 elif opt in ('-e', '--executable'): | |
| 881 builder.executable = arg | |
| 882 elif opt in ('-m', '--mainprogram'): | |
| 883 builder.mainprogram = arg | |
| 884 elif opt in ('-a', '--argv'): | |
| 885 builder.argv_emulation = 1 | |
| 886 elif opt in ('-c', '--creator'): | |
| 887 builder.creator = arg | |
| 29761 | 888 elif opt == '--bundle-id': |
| 889 builder.bundle_id = arg | |
| 28545 | 890 elif opt == '--iconfile': |
| 891 builder.iconfile = arg | |
| 892 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
|
893 builder.libs.append(os.path.normpath(arg)) |
| 28545 | 894 elif opt == "--nib": |
| 895 builder.nibname = arg | |
| 896 elif opt in ('-p', '--plist'): | |
| 897 builder.plist = Plist.fromFile(arg) | |
| 898 elif opt in ('-l', '--link'): | |
| 899 builder.symlink = 1 | |
| 900 elif opt == '--link-exec': | |
| 901 builder.symlink_exec = 1 | |
| 902 elif opt in ('-h', '--help'): | |
| 903 usage() | |
| 904 elif opt in ('-v', '--verbose'): | |
| 905 builder.verbosity += 1 | |
| 906 elif opt in ('-q', '--quiet'): | |
| 907 builder.verbosity -= 1 | |
| 908 elif opt == '--standalone': | |
| 909 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
|
910 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
|
911 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
|
912 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
|
913 builder.python = arg |
| 28545 | 914 elif opt in ('-x', '--exclude'): |
| 915 builder.excludeModules.append(arg) | |
| 916 elif opt in ('-i', '--include'): | |
| 917 builder.includeModules.append(arg) | |
| 918 elif opt == '--package': | |
| 919 builder.includePackages.append(arg) | |
| 920 elif opt == '--strip': | |
| 921 builder.strip = 1 | |
| 34291 | 922 elif opt == '--destroot': |
| 923 builder.destroot = arg | |
|
50451
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
924 elif opt == '--no-zipimport': |
|
69a240e5f01d
Fix for issues #841800 and #900506
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
47958
diff
changeset
|
925 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
|
926 |
| 28545 | 927 if len(args) != 1: |
| 928 usage("Must specify one command ('build', 'report' or 'help')") | |
| 929 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
|
930 |
| 28545 | 931 if command == "build": |
| 932 builder.setup() | |
| 933 builder.build() | |
| 934 elif command == "report": | |
| 935 builder.setup() | |
| 936 builder.report() | |
| 937 elif command == "help": | |
| 938 usage() | |
| 939 else: | |
| 940 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
|
941 |
|
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 def buildapp(**kwargs): |
| 28545 | 944 builder = AppBuilder(**kwargs) |
| 945 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
|
946 |
|
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 if __name__ == "__main__": |
| 28545 | 949 main() |
