Kaydet (Commit) 21ed16ac authored tarafından Jack Jansen's avatar Jack Jansen

Added one call to Py_Main(), for OSX framework builds only, that will get the

actual script to run in case we are running from an applet. If we are indeed
running an applet we skip the normal option processing leaving it all to the
applet code.

This allows us to get use the normal python binary in the Python.app bundle,
giving us all the normal command line options through PythonLauncher while
still allowing Python.app to be used as the template for building applets.

Consequently, pythonforbundle is gone, and Mac/Python/macmain.c isn't used
on OSX anymore.
üst 94416e55
...@@ -34,7 +34,9 @@ char *PyMac_StrError(int); /* strerror with mac errors */ ...@@ -34,7 +34,9 @@ char *PyMac_StrError(int); /* strerror with mac errors */
PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */ PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */ PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert fsspec->path */ extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert fsspec->path */
#ifdef WITH_NEXT_FRAMEWORK
extern char *PyMac_GetAppletScriptFile(void); /* Return applet script file or NULL */
#endif
/* /*
** These conversion routines are defined in mactoolboxglue.c itself. ** These conversion routines are defined in mactoolboxglue.c itself.
*/ */
......
...@@ -37,9 +37,6 @@ LD=cc ...@@ -37,9 +37,6 @@ LD=cc
REZ=/Developer/Tools/Rez REZ=/Developer/Tools/Rez
DEREZ=/Developer/Tools/DeRez DEREZ=/Developer/Tools/DeRez
OBJECTS=$(builddir)/Mac/Python/macmain.o \
$(builddir)/Mac/Python/macgetargv.o
PYTHON=$(builddir)/python.exe PYTHON=$(builddir)/python.exe
APPTEMPLATE=$(srcdir)/Mac/OSXResources/app APPTEMPLATE=$(srcdir)/Mac/OSXResources/app
APPSUBDIRS=MacOS Resources Resources/English.lproj APPSUBDIRS=MacOS Resources Resources/English.lproj
...@@ -53,7 +50,7 @@ install_PythonLauncher: ...@@ -53,7 +50,7 @@ install_PythonLauncher:
cd $(srcdir)/Mac/OSX/PythonLauncher/PythonLauncher.pbproj ; \ cd $(srcdir)/Mac/OSX/PythonLauncher/PythonLauncher.pbproj ; \
pbxbuild -target PythonLauncher -buildstyle Deployment DSTROOT=/ install pbxbuild -target PythonLauncher -buildstyle Deployment DSTROOT=/ install
install_Python: pythonforbundle install_Python: $(PYTHON)
@for i in $(PYTHONAPPSDIR) $(APPINSTALLDIR) $(APPINSTALLDIR)/Contents; do \ @for i in $(PYTHONAPPSDIR) $(APPINSTALLDIR) $(APPINSTALLDIR)/Contents; do \
if test ! -d $$i; then \ if test ! -d $$i; then \
echo "Creating directory $$i"; \ echo "Creating directory $$i"; \
...@@ -91,7 +88,7 @@ install_Python: pythonforbundle ...@@ -91,7 +88,7 @@ install_Python: pythonforbundle
esac; \ esac; \
done; \ done; \
done done
$(INSTALL_PROGRAM) $(STRIPFLAG) pythonforbundle $(APPINSTALLDIR)/Contents/MacOS/python $(INSTALL_PROGRAM) $(STRIPFLAG) $(PYTHON) $(APPINSTALLDIR)/Contents/MacOS/python
# Create a temporary version of the resources here # Create a temporary version of the resources here
$(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/dialogs.rsrc dialogs.rsrc $(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/dialogs.rsrc dialogs.rsrc
$(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/errors.rsrc errors.rsrc $(PYTHON) $(RFCONVERTER) -r $(RESOURCEDIR)/errors.rsrc errors.rsrc
...@@ -231,14 +228,3 @@ dontinstallmacsubtree: ...@@ -231,14 +228,3 @@ dontinstallmacsubtree:
l=`cd $(srcdir)/Mac/Lib; pwd`; \ l=`cd $(srcdir)/Mac/Lib; pwd`; \
echo $$l > $(prefix)/lib/python$(VERSION)/site-packages/Mac.pth ; \ echo $$l > $(prefix)/lib/python$(VERSION)/site-packages/Mac.pth ; \
echo $$l/lib-scriptpackages >> $(prefix)/lib/python$(VERSION)/site-packages/Mac.pth echo $$l/lib-scriptpackages >> $(prefix)/lib/python$(VERSION)/site-packages/Mac.pth
pythonforbundle: $(OBJECTS)
$(LD) $(LDFLAGS) $(OBJECTS) -o pythonforbundle
# Rules to build each file in OBJECTS - is there a better way?
$(builddir)/Mac/Python/macmain.o: $(srcdir)/Mac/Python/macmain.c
$(CC) $(CFLAGS) -c $(srcdir)/Mac/Python/macmain.c -o $@
$(builddir)/Mac/Python/macgetargv.o: $(srcdir)/Mac/Python/macgetargv.c
$(CC) $(CFLAGS) -c $(srcdir)/Mac/Python/macgetargv.c -o $@
This directory contains a Makefile that will create a proof-of-concept This directory contains a Makefile that will create a couple of python-related
Mac OS X application for Python. The process is far from streamlined, applications (fullblown OSX .app applications, that is) in /Applications/Python,
and it will definitely change in future releases of Python, but I wanted to and a hidden helper application Python.app inside the Python.framework. In addition
include this in the current distribution so people could play with it. it has a target "installmacsubtree" that installs the relevant portions of the
Mac subtree into the Python.framework.
To create a fullblown Python.app proceed as follows. It is normally invoked indirectly through the main Makefile, as the last step
in the sequence
1. configure --enable-framework
2. make
3. make frameworkinstall
4. make osxapps
1. In the main Python source directory configure python with The interesting targets in the makefile are:
configure --enable-framework installmacsubtree - explained above,
2. Do a "make clean" if you did a previous build, then "make". dontinstallmacsubtree - Put only a .pth file into the framework (pointing to this
3. Install this as a framework with "make frameworkinstall". This puts a Python sourcetree), which may be easier for development,
framework into /Library/Frameworks. install_all - install all three .app applications,
4. Come back here (Mac/OSX) and build and install the application, install_Python - install the hidden interpreter .app into the framework,
with "make install". install_PythonLauncher - install the user-visible script launch helper
5. It is probably a good idea to add the Mac-specific modules to the framework, install_IDE - install the IDE
with "make installmacsubtree". This puts a MacPython lib directory into installunixprograms - install symlinks/scripts mimicking normal unix Python into
sys.prefix/Mac/Lib. Again, this is a temporary measure. /usr/local.
6. To actually find the Lib directory installed in step 5 you add a line
to your site.py file (the one in /Library/Frameworks/....):
sys.path.append(os.path.join(sys.prefix, 'Mac/Lib'))
You are now done. In your Applications you should have a "Python", with the icon
being a falling 16 Ton weight with a shadow under it. You can drop Python scripts
on this and the will be run, in a full-windowing environment. Note that you
do not get sys.stdin, and that sys.stdout goes to the console (Use
Applications/Utilities/Console to see it).
For some reason the application only accepts files with TEXT type, not straight unix
typeless files.
Something to take note of is that the ".rsrc" files in the distribution are not Something to take note of is that the ".rsrc" files in the distribution are not
actually resource files, they're AppleSingle encoded resource files. actually resource files, they're AppleSingle encoded resource files.
Jack Jansen, jack@oratrix.com, 11-Sep-01. Jack Jansen, jack@oratrix.com, 02-Aug-02
\ No newline at end of file \ No newline at end of file
...@@ -135,6 +135,22 @@ Py_Main(int argc, char **argv) ...@@ -135,6 +135,22 @@ Py_Main(int argc, char **argv)
PySys_ResetWarnOptions(); PySys_ResetWarnOptions();
#if defined(WITH_NEXT_FRAMEWORK)
/* If we are running from a framework it could be that we are actually
** the main program for an applet. If so, the next call will return the
** filename that we are supposed to run.
*/
filename = PyMac_GetAppletScriptFile();
if (filename != NULL) {
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "%s: can't open file '%s'\n",
argv[0], filename);
exit(2);
}
}
/* Skip option-processing if we are an applet */
if (filename == NULL)
#endif
while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) { while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
if (c == 'c') { if (c == 'c') {
/* -c is the last option; following arguments /* -c is the last option; following arguments
...@@ -261,7 +277,7 @@ Py_Main(int argc, char **argv) ...@@ -261,7 +277,7 @@ Py_Main(int argc, char **argv)
(p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0') (p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1; unbuffered = 1;
if (command == NULL && _PyOS_optind < argc && if (command == NULL && filename == NULL && _PyOS_optind < argc &&
strcmp(argv[_PyOS_optind], "-") != 0) strcmp(argv[_PyOS_optind], "-") != 0)
{ {
filename = argv[_PyOS_optind]; filename = argv[_PyOS_optind];
......
...@@ -175,6 +175,94 @@ PyMac_GetFullPathname(FSSpec *fss, char *path, int len) ...@@ -175,6 +175,94 @@ PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
} }
#endif /* TARGET_API_MAC_OSX */ #endif /* TARGET_API_MAC_OSX */
#ifdef WITH_NEXT_FRAMEWORK
/*
** In a bundle, find a file "resourceName" of type "resourceType". Return the
** full pathname in "resourceURLCstr".
*/
static int
locateResourcePy(CFStringRef resourceType, CFStringRef resourceName, char *resourceURLCStr, int length)
{
CFBundleRef mainBundle = NULL;
CFURLRef URL, absoluteURL;
CFStringRef filenameString, filepathString;
CFIndex size, i;
CFArrayRef arrayRef = NULL;
int success = 0;
#if TARGET_API_MAC_OSX
CFURLPathStyle thePathStyle = kCFURLPOSIXPathStyle;
#else
CFURLPathStyle thePathStyle = kCFURLHFSPathStyle;
#endif
/* Get a reference to our main bundle */
mainBundle = CFBundleGetMainBundle();
/* If we are running inside a bundle, look through it. Otherwise, do nothing. */
if (mainBundle) {
/* Look for py files in the main bundle by type */
arrayRef = CFBundleCopyResourceURLsOfType( mainBundle,
resourceType,
NULL );
/* See if there are any filename matches */
size = CFArrayGetCount(arrayRef);
for (i = 0; i < size; i++) {
URL = CFArrayGetValueAtIndex(arrayRef, i);
filenameString = CFURLCopyLastPathComponent(URL);
if (CFStringCompare(filenameString, resourceName, 0) == kCFCompareEqualTo) {
/* We found a match, get the file's full path */
absoluteURL = CFURLCopyAbsoluteURL(URL);
filepathString = CFURLCopyFileSystemPath(absoluteURL, thePathStyle);
CFRelease(absoluteURL);
/* Copy the full path into the caller's character buffer */
success = CFStringGetCString(filepathString, resourceURLCStr, length,
kCFStringEncodingMacRoman);
CFRelease(filepathString);
}
CFRelease(filenameString);
}
CFRelease(arrayRef);
}
return success;
}
/*
** iff we are running in a .app framework then we could be
** the main program for an applet. In that case, return the
** script filename for the applet.
** Otherwise return NULL.
*/
char *
PyMac_GetAppletScriptFile(void)
{
static char scriptpath[1024];
/* First we see whether we have __rawmain__.py and run that if it
** is there. This is used for applets that want sys.argv to be
** unix-like: __rawmain__ will construct it (from the initial appleevent)
** and then call __main__.py.
*/
if (locateResourcePy(CFSTR("py"), CFSTR("__rawmain__.py"), scriptpath, 1024)) {
return scriptpath;
} else if (locateResourcePy(CFSTR("pyc"), CFSTR("__rawmain__.pyc"), scriptpath, 1024)) {
return scriptpath;
} else if (locateResourcePy(CFSTR("py"), CFSTR("__main__.py"), scriptpath, 1024)) {
return scriptpath;
} else if (locateResourcePy(CFSTR("pyc"), CFSTR("__main__.pyc"), scriptpath, 1024)) {
return scriptpath;
}
return NULL;
}
#endif
/* Convert a 4-char string object argument to an OSType value */ /* Convert a 4-char string object argument to an OSType value */
int int
PyMac_GetOSType(PyObject *v, OSType *pr) PyMac_GetOSType(PyObject *v, OSType *pr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment