Commits

Virgil Dupras committed 66eff20

Modernized the cocoa build process.

Comments (0)

Files changed (5)

 496d9356d8b381b43977622de9a9f6dc8b0cf4d8 cocoalib
-8a155aeb161a9b26c1ff371f21cdc7a220038037 hscommon
+06f102102a164dd0e241e63a5c0eecba0082b127 hscommon
 48131959afaba0f50ef8014fd6adf83012915b5b qtlib
 
 - XCode's Command Line Tools
 - ObjP 1.2.1 (http://bitbucket.org/hsoft/objp)
-- pluginbuilder 1.1.0 (http://bitbucket.org/hsoft/pluginbuilder)
 - xibless 0.3.0 (https://bitbucket.org/hsoft/xibless)
 
 Windows prerequisites
 import shutil
 import json
 from argparse import ArgumentParser
+import compileall
 
 from setuptools import setup, Extension
 
 from hscommon import sphinxgen
 from hscommon.build import (print_and_do, copy_packages, get_module_version, filereplace, move,
-    add_to_pythonpath, copy, copy_sysconfig_files_for_embed, create_osx_app_structure,
-    build_cocoalib_xibless)
+    add_to_pythonpath, copy, copy_sysconfig_files_for_embed, OSXAppStructure,
+    build_cocoalib_xibless, copy_all, copy_embeddable_python_dylib, collect_stdlib_dependencies)
 from hscommon.plat import ISOSX
-from hscommon.util import ensure_folder
+from hscommon.util import ensure_folder, delete_files_with_pattern
 
 def parse_args():
     parser = ArgumentParser()
     xibless.generate('cocoa/ui/main_menu.py', 'cocoa/autogen/PMMainMenu_UI')
 
 def build_cocoa(dev):
+    app = OSXAppStructure('build/PdfMasher.app')
+    print('Generating Info.plist')
+    app_version = get_module_version('core')
+    filereplace('cocoa/InfoTemplate.plist', 'cocoa/Info.plist', version=app_version)    
+    app.create('cocoa/Info.plist')
     print("Building the cocoa layer")
     build_cocoalib_xibless()
     build_xibless()
-    if not op.exists('build/py'):
-        os.mkdir('build/py')
+    pydep_folder = op.join(app.resources, 'py')
+    if not op.exists(pydep_folder):
+        os.mkdir(pydep_folder)
     build_cocoa_proxy_module()
     build_cocoa_bridging_interfaces()
-    from pluginbuilder import copy_embeddable_python_dylib, collect_dependencies
     copy_embeddable_python_dylib('build')
-    tocopy = ['core', 'ebooks', 'hscommon', 'cocoa/inter', 'cocoalib/cocoa']
-    copy_packages(tocopy, 'build')
+    tocopy = ['core', 'ebooks', 'hscommon', 'cocoa/inter', 'cocoalib/cocoa', 'jobprogress', 'objp',
+        'cssutils', 'pdfminer', 'lxml', 'ply', 'markdown', 'encutils']
+    copy_packages(tocopy, pydep_folder, create_links=dev)
     copy('cocoa/pyplugin.py', 'build/pyplugin.py')
-    os.chdir('build')
-    collect_dependencies('pyplugin.py', 'py', excludes=['PyQt4'])
-    os.chdir('..')
-    if dev:
-        copy_packages(tocopy, 'build/py', create_links=True)
-    copy_sysconfig_files_for_embed('build/py')
+    sys.path.insert(0, 'build')
+    collect_stdlib_dependencies('build/pyplugin.py', pydep_folder)
+    del sys.path[0]
+    # Views are not referenced by python code, so they're not found by the collector.
+    copy_all('build/inter/*.so', op.join(pydep_folder, 'inter'))
+    copy_sysconfig_files_for_embed(pydep_folder)
+    if not dev:
+        # Important: Don't ever run delete_files_with_pattern('*.py') on dev builds because you'll
+        # be deleting all py files in symlinked folders.
+        compileall.compile_dir(pydep_folder, force=True, legacy=True)
+        delete_files_with_pattern(pydep_folder, '*.py')
+        delete_files_with_pattern(pydep_folder, '__pycache__')
     os.chdir('cocoa')
-    print('Generating Info.plist')
-    app_version = get_module_version('core')
-    filereplace('InfoTemplate.plist', 'Info.plist', version=app_version)
     print("Compiling with WAF")
     os.system('{0} waf configure && {0} waf'.format(sys.executable))
     os.chdir('..')
     print("Creating the .app folder")
-    resources = ['images/main_icon.icns', 'cocoa/dsa_pub.pem', 'build/pyplugin.py',
-        'build/py', 'build/help']
-    frameworks = ['build/Python', 'cocoalib/Sparkle.framework']
-    create_osx_app_structure('build/PdfMasher.app', 'cocoa/build/PdfMasher', 'cocoa/Info.plist',
-        resources, frameworks, symlink_resources=dev)
+    app.copy_executable('cocoa/build/PdfMasher')
+    resources = ['images/main_icon.icns', 'cocoa/dsa_pub.pem', 'build/pyplugin.py', 'build/help']
+    app.copy_resources(*resources, use_symlinks=dev)
+    app.copy_frameworks('build/Python', 'cocoalib/Sparkle.framework')
     print("Creating the run.py file")
     copy('cocoa/runtemplate.py', 'run.py')
 
         PageControllerView, PageReprView, PdfMasherView]
     clsspecs = [objp.o2p.spec_from_python_class(class_) for class_ in allclasses]
     objp.p2o.generate_python_proxy_code_from_clsspec(clsspecs, 'build/CocoaViews.m')
-    build_cocoa_ext('CocoaViews', 'build/py', ['build/CocoaViews.m', 'build/ObjP.m'])
+    build_cocoa_ext('CocoaViews', 'cocoa/inter', ['build/CocoaViews.m', 'build/ObjP.m'])
 
 def build_qt():
     print("Building resource file")
 int main(int argc, char *argv[])
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    setCocoaViewsModuleName(@"CocoaViews");
     /* We have to set the locate to UTF8 for mbstowcs() to correctly convert non-ascii chars in paths */
     setlocale(LC_ALL, "en_US.UTF-8");
     NSString *respath = [[NSBundle mainBundle] resourcePath];

requirements-osx.txt

 -r requirements.txt
 objp>=1.2.1
-pluginbuilder>=1.1.0
 xibless>=0.3.1