How to make py2app app stub link to Cocoa framework?

Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make py2app app stub link to Cocoa framework?

Kevin Walzer-5
I've been trying to get one of my Python-Tk applications to integrate
with Lion's sandboxing framework (for Mac App Store submission) and have
been having difficulty. Based on some feedback I received in the Apple
Developer forums, it appears that part of the issue is that the
executable stub created by py2app does not link to the Cocoa frameworks.
A quick run of otool -L confirms this:

Kevin-Walzers-MacBook:~ kevin$ otool -L
/Users/kevin/Programming/quickwho/cbk/QuickWho.app/Contents/MacOS/QuickWho
/Users/kevin/Programming/quickwho/cbk/QuickWho.app/Contents/MacOS/QuickWho:
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version
832.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 125.2.10)

Is there any way I can get this executable linked to
/System/Library/Frameworks/Cocoa.framework? I didn't think
install_name_tool would do the trick, as that just rewrites links,
rather than adding them. A

Any suggestions are appreciated.

--Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Reply | Threaded
Open this post in threaded view
|

Re: How to make py2app app stub link to Cocoa framework?

Kevin Walzer-5
On 11/8/11 11:41 PM, Kevin Walzer wrote:
> Is there any way I can get this executable linked to
> /System/Library/Frameworks/Cocoa.framework? I didn't think
> install_name_tool would do the trick, as that just rewrites links,
> rather than adding them. A
>
> Any suggestions are appreciated.

I solved the problem by hacking the setup.py file in apptemplates (in
the py2app source tree) to add an LDFLAGS parameter with a '-framework
Cocoa' linker flag. Ugly, but it meets my needs. Probably not worth it
to submit a patch.

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Reply | Threaded
Open this post in threaded view
|

Re: How to make py2app app stub link to Cocoa framework?

Ronald Oussoren
In reply to this post by Kevin Walzer-5

On 9 Nov, 2011, at 5:41, Kevin Walzer wrote:

> I've been trying to get one of my Python-Tk applications to integrate with Lion's sandboxing framework (for Mac App Store submission) and have been having difficulty. Based on some feedback I received in the Apple Developer forums, it appears that part of the issue is that the executable stub created by py2app does not link to the Cocoa frameworks.

What kind of problem did you run into? Are those something that can be easily reproduced by signing a trivial application?


> A quick run of otool -L confirms this:
>
> Kevin-Walzers-MacBook:~ kevin$ otool -L /Users/kevin/Programming/quickwho/cbk/QuickWho.app/Contents/MacOS/QuickWho
> /Users/kevin/Programming/quickwho/cbk/QuickWho.app/Contents/MacOS/QuickWho:
> /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 832.0.0)
> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
>
> Is there any way I can get this executable linked to /System/Library/Frameworks/Cocoa.framework? I didn't think install_name_tool would do the trick, as that just rewrites links, rather than adding them. A
>
> Any suggestions are appreciated.
You'll have to rebuild the stubs, and as you already noticed you can do this by patching the setup.py in py2app/apptemplate.

BTW. The reason py2app doesn't link with Cocoa is to avoid Cocoa's triggering backward compatibility modes. That is, when you link to Cocoa.framework with the 10.4 SDK a number of classes will behave slightly different than they do when linking to the 10.6 SDK. The precisedetails elude me at the moment though.

It might be useful to add separate stubs for codesigning (possibly with additional flags in py2app to trigger codesigning from your setup.py file), or even replace the current stubs by ones that link to the Cocoa frameworks.

Ronald

>
> --Kevin
>
> --
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com
> _______________________________________________
> Pythonmac-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/pythonmac-sig
> unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG

smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to make py2app app stub link to Cocoa framework?

Kevin Walzer-5
On 11/10/11 5:39 AM, Ronald Oussoren wrote:

> What kind of problem did you run into? Are those something that can be easily reproduced by signing a trivial application?

It wouldn't display a save dialog. Under the hood Tkinter/Tk's save
dialog calls into NSSavePanel. In a sandboxed app, the call to
NSSavePanel is supposed to be intercepted by the Powerbox (sandbox save
dialog), but no dialog would display.
>
> You'll have to rebuild the stubs, and as you already noticed you can do this by patching the setup.py in py2app/apptemplate.
>
> BTW. The reason py2app doesn't link with Cocoa is to avoid Cocoa's triggering backward compatibility modes. That is, when you link to Cocoa.framework with the 10.4 SDK a number of classes will behave slightly different than they do when linking to the 10.6 SDK. The precisedetails elude me at the moment though.
>
> It might be useful to add separate stubs for codesigning (possibly with additional flags in py2app to trigger codesigning from your setup.py file), or even replace the current stubs by ones that link to the Cocoa frameworks.

Rebuilding the stubs was easy enough to do, and sufficient for my needs,
but if you decide to add this capability to py2app, I'm sure other folks
would find it useful.

--Kevin


--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________
Pythonmac-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG
Reply | Threaded
Open this post in threaded view
|

Re: How to make py2app app stub link to Cocoa framework?

sameer
This post has NOT been accepted by the mailing list yet.
Hello all. I'm trying to make a Mac App using py2app that will go on the Mac App store. I enabled sandboxing and now my app crashes. I noticed on the py2app bitbucket issue #85

https://bitbucket.org/ronaldoussoren/py2app/issue/85/sandboxing-interaction-issue

which led me to find this thread about linking Cocoa. I applied the following patch to my py2app

--- a/py2app/apptemplate/setup.py       Tue Mar 26 13:24:12 2013 +0100
+++ b/py2app/apptemplate/setup.py       Sat Mar 30 19:13:28 2013 -0400
@@ -107,8 +107,9 @@
 
                 CC=os.path.join(root, 'usr', 'bin', entry['cc'])
                 CFLAGS = BASE_CFLAGS + ' ' + entry['cflags'].replace('@@XCODE_ROOT@@', root)
+                LDFLAGS = '-framework Cocoa'
                 os.environ['MACOSX_DEPLOYMENT_TARGET'] = entry['target']
-                os.system('"%(CC)s" -o "%(dest)s" "%(src)s" %(CFLAGS)s' % locals())
+                os.system('"%(CC)s" -o "%(dest)s" "%(src)s" %(CFLAGS)s %(LDFLAGS)s' % locals())
 
     dest = os.path.join(
             builddir,

And now when I launch my app it still crashes with the following errors (which is the same as before I did the LDFLAGS change):

3/30/13 7:04:01.840 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/__init__.pyc
3/30/13 7:04:01.843 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/error.pyc
3/30/13 7:04:01.846 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/tokens.pyc
3/30/13 7:04:01.848 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/events.pyc
3/30/13 7:04:01.851 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/nodes.pyc
3/30/13 7:04:01.853 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/loader.pyc
3/30/13 7:04:01.855 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/reader.pyc
3/30/13 7:04:01.891 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/scanner.pyc
3/30/13 7:04:01.897 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/parser.pyc
3/30/13 7:04:01.899 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/composer.pyc
3/30/13 7:04:01.905 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/constructor.pyc
3/30/13 7:04:01.915 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/resolver.pyc
3/30/13 7:04:01.923 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/dumper.pyc
3/30/13 7:04:01.933 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/emitter.pyc
3/30/13 7:04:01.935 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/serializer.pyc
3/30/13 7:04:01.940 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/representer.pyc
3/30/13 7:04:01.942 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-unlink /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/yaml/cyaml.pyc
3/30/13 7:04:01.979 PM sandboxd: ([11451]) DeFisheye(11451) deny file-write-create /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/PySide/__init__.pyc
3/30/13 7:04:02.049 PM sandboxd: ([11451]) DeFisheye(11451) deny file-read-data /usr/X11/lib/libpng15.15.dylib
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye: argvemulator warning: fetching events failed
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye: Traceback (most recent call last):
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   File "/Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/__boot__.py", line 352, in <module>
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:     _run()
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   File "/Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/__boot__.py", line 347, in _run
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:     exec(compile(source, path, 'exec'), globals(), globals())
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   File "/Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/defisheye", line 43, in <module>
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:     import cv2
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye: ImportError: dlopen(/Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/Resources/lib/python2.7/lib-dynload/cv2.so, 2): Library not loaded: /usr/X11/lib/libpng15.15.dylib
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   Referenced from: /Users/sameer/Documents/Falkor Systems/gopro_calibration/DeFisheye/dist/DeFisheye.app/Contents/MacOS/../Frameworks/libopencv_highgui.2.4.4.dylib
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye:   Reason: no suitable image found.  Did find:
3/30/13 7:04:02.050 PM [0x0-0xb15b15].com.falkorsystems.defisheye: 	/usr/X11/lib/libpng15.15.dylib: open() failed with errno=1
3/30/13 7:04:02.119 PM DeFisheye: DeFisheye Error
3/30/13 7:04:03.683 PM lsboxd: @AE relay 61657674:72617070
3/30/13 7:04:03.703 PM com.apple.launchd.peruser.501: ([0x0-0xb15b15].com.falkorsystems.defisheye[11451]) Exited with code: 255

Does anyone have any hints about how I can make this work? I am new to Mac Apps and sandboxing.

Thanks,
-s