diff --git a/build.py b/build.py index 908bd2fa..1ae901d9 100644 --- a/build.py +++ b/build.py @@ -6,6 +6,7 @@ # which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/bsd_license +import sys import os import os.path as op from optparse import OptionParser @@ -16,7 +17,7 @@ from setuptools import setup, Extension from hscommon import sphinxgen from hscommon.build import (add_to_pythonpath, print_and_do, copy_packages, filereplace, - get_module_version, build_all_cocoa_locs, move_all) + get_module_version, build_all_cocoa_locs, move_all, copy_sysconfig_files_for_embed) from hscommon import loc def parse_args(): @@ -36,7 +37,6 @@ def parse_args(): return options def build_cocoa(edition, dev): - from pluginbuilder import build_plugin build_cocoa_proxy_module() print("Building dg_cocoa.plugin") specific_packages = { @@ -48,14 +48,16 @@ def build_cocoa(edition, dev): copy_packages(tocopy, 'build', create_links=dev) cocoa_project_path = 'cocoa/{0}'.format(edition) shutil.copy(op.join(cocoa_project_path, 'dg_cocoa.py'), 'build') - os.chdir('build') - # We have to exclude PyQt4 specifically because it's conditionally imported in hscommon.trans - build_plugin('dg_cocoa.py', excludes=['PyQt4'], alias=dev) - os.chdir('..') - pluginpath = op.join(cocoa_project_path, 'dg_cocoa.plugin') - if op.exists(pluginpath): - shutil.rmtree(pluginpath) - shutil.move('build/dist/dg_cocoa.plugin', pluginpath) + from pluginbuilder import copy_embeddable_python_dylib, get_python_header_folder, collect_dependencies + copy_embeddable_python_dylib('build') + if not op.exists('build/PythonHeaders'): + os.symlink(get_python_header_folder(), 'build/PythonHeaders') + if not op.exists('build/py'): + os.mkdir('build/py') + sys.path.insert(0, 'build') + collect_dependencies('build/dg_cocoa.py', 'build/py', excludes=['PyQt4']) + del sys.path[0] + copy_sysconfig_files_for_embed('build/py') os.chdir(cocoa_project_path) print('Generating Info.plist') app_version = get_module_version('core_{}'.format(edition)) diff --git a/cocoa/se/dupeguru.xcodeproj/project.pbxproj b/cocoa/se/dupeguru.xcodeproj/project.pbxproj index d377af31..3a4ba9db 100644 --- a/cocoa/se/dupeguru.xcodeproj/project.pbxproj +++ b/cocoa/se/dupeguru.xcodeproj/project.pbxproj @@ -10,13 +10,15 @@ 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; CE073F6309CAE1A3005C1D2F /* help in Resources */ = {isa = PBXBuildFile; fileRef = CE073F5409CAE1A3005C1D2F /* help */; }; + CE18004D14BDD837001B6329 /* Python in Frameworks */ = {isa = PBXBuildFile; fileRef = CE18004C14BDD837001B6329 /* Python */; }; + CE18004F14BDD854001B6329 /* Python in CopyFiles */ = {isa = PBXBuildFile; fileRef = CE18004C14BDD837001B6329 /* Python */; }; + CE18005114BDD87B001B6329 /* py in Resources */ = {isa = PBXBuildFile; fileRef = CE18005014BDD87B001B6329 /* py */; }; CE19BC6411199231007CCEB0 /* progress.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE19BC6111199231007CCEB0 /* progress.xib */; }; CE27D3C412CCA43800859E67 /* HSAboutBox.m in Sources */ = {isa = PBXBuildFile; fileRef = CE27D3C312CCA43800859E67 /* HSAboutBox.m */; }; CE31819D13D85D9B00B6D649 /* about.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE31819913D85D9B00B6D649 /* about.xib */; }; CE31819E13D85D9B00B6D649 /* ErrorReportWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE31819B13D85D9B00B6D649 /* ErrorReportWindow.xib */; }; CE381C9609914ACE003581CE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = CE381C9409914ACE003581CE /* AppDelegate.m */; }; CE381C9C09914ADF003581CE /* ResultWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = CE381C9A09914ADF003581CE /* ResultWindow.m */; }; - CE381D0509915304003581CE /* dg_cocoa.plugin in Resources */ = {isa = PBXBuildFile; fileRef = CE381CF509915304003581CE /* dg_cocoa.plugin */; }; CE41672D141FE1E5004F3F0B /* HSSelectableList.m in Sources */ = {isa = PBXBuildFile; fileRef = CE41672B141FE1E5004F3F0B /* HSSelectableList.m */; }; CE45579B0AE3BC2B005A9546 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE45579A0AE3BC2B005A9546 /* Sparkle.framework */; }; CE4557B40AE3BC50005A9546 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CE45579A0AE3BC2B005A9546 /* Sparkle.framework */; }; @@ -52,6 +54,7 @@ CE9777D1141F8CB400C13FB5 /* PrioritizeDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE9777CF141F8CB400C13FB5 /* PrioritizeDialog.xib */; }; CE9777D5141F9D7600C13FB5 /* HSPopUpList.m in Sources */ = {isa = PBXBuildFile; fileRef = CE9777D4141F9D7600C13FB5 /* HSPopUpList.m */; }; CEA175CA1461E8E600776591 /* locale in Resources */ = {isa = PBXBuildFile; fileRef = CEA175C91461E8E600776591 /* locale */; }; + CEA450B814BDDFD7002DAAF2 /* dg_cocoa.py in Resources */ = {isa = PBXBuildFile; fileRef = CEA450B714BDDFD7002DAAF2 /* dg_cocoa.py */; }; CEBE4D74111F0EE1009AAC6D /* HSWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBE4D73111F0EE1009AAC6D /* HSWindowController.m */; }; CEE7EA130FE675C80004E467 /* DetailsPanel.m in Sources */ = {isa = PBXBuildFile; fileRef = CEE7EA120FE675C80004E467 /* DetailsPanel.m */; }; CEEB135209C837A2004D2330 /* dupeguru.icns in Resources */ = {isa = PBXBuildFile; fileRef = CEEB135109C837A2004D2330 /* dupeguru.icns */; }; @@ -75,6 +78,7 @@ dstSubfolderSpec = 10; files = ( CE4557B40AE3BC50005A9546 /* Sparkle.framework in CopyFiles */, + CE18004F14BDD854001B6329 /* Python in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -116,6 +120,8 @@ CE112F5F145EF28D009C9E3E /* cs */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = cs; path = ../cs.lproj/about.xib; sourceTree = ""; }; CE112F60145EF28D009C9E3E /* cs */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = cs; path = ../cs.lproj/ErrorReportWindow.xib; sourceTree = ""; }; CE112F61145EF28D009C9E3E /* cs */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = cs; path = ../cs.lproj/FairwareReminder.xib; sourceTree = ""; }; + CE18004C14BDD837001B6329 /* Python */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = Python; path = ../../build/Python; sourceTree = ""; }; + CE18005014BDD87B001B6329 /* py */ = {isa = PBXFileReference; lastKnownFileType = folder; name = py; path = ../../build/py; sourceTree = ""; }; CE19BC6111199231007CCEB0 /* progress.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = progress.xib; sourceTree = ""; }; CE27D3C212CCA43800859E67 /* HSAboutBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HSAboutBox.h; path = ../../cocoalib/HSAboutBox.h; sourceTree = SOURCE_ROOT; }; CE27D3C312CCA43800859E67 /* HSAboutBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HSAboutBox.m; path = ../../cocoalib/HSAboutBox.m; sourceTree = SOURCE_ROOT; }; @@ -130,7 +136,6 @@ CE381C9509914ACE003581CE /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = SOURCE_ROOT; }; CE381C9A09914ADF003581CE /* ResultWindow.m */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.objc; path = ResultWindow.m; sourceTree = SOURCE_ROOT; }; CE381C9B09914ADF003581CE /* ResultWindow.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = ResultWindow.h; sourceTree = SOURCE_ROOT; }; - CE381CF509915304003581CE /* dg_cocoa.plugin */ = {isa = PBXFileReference; lastKnownFileType = folder; path = dg_cocoa.plugin; sourceTree = SOURCE_ROOT; }; CE41672A141FE1E5004F3F0B /* HSSelectableList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HSSelectableList.h; sourceTree = ""; }; CE41672B141FE1E5004F3F0B /* HSSelectableList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HSSelectableList.m; sourceTree = ""; }; CE41672C141FE1E5004F3F0B /* HSTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HSTable.h; sourceTree = ""; }; @@ -219,6 +224,7 @@ CE9777D3141F9D7600C13FB5 /* HSPopUpList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HSPopUpList.h; sourceTree = ""; }; CE9777D4141F9D7600C13FB5 /* HSPopUpList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HSPopUpList.m; sourceTree = ""; }; CEA175C91461E8E600776591 /* locale */ = {isa = PBXFileReference; lastKnownFileType = folder; name = locale; path = ../../build/locale; sourceTree = ""; }; + CEA450B714BDDFD7002DAAF2 /* dg_cocoa.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; name = dg_cocoa.py; path = ../../build/dg_cocoa.py; sourceTree = ""; }; CEB57990146ADC5100EDF7D7 /* HSConsts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HSConsts.h; path = ../../cocoalib/HSConsts.h; sourceTree = ""; }; CEBE4D72111F0EE1009AAC6D /* HSWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HSWindowController.h; sourceTree = ""; }; CEBE4D73111F0EE1009AAC6D /* HSWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HSWindowController.m; sourceTree = ""; }; @@ -275,6 +281,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + CE18004D14BDD837001B6329 /* Python in Frameworks */, CE533603142BC034008E5374 /* Quartz.framework in Frameworks */, 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, CE45579B0AE3BC2B005A9546 /* Sparkle.framework in Frameworks */, @@ -300,6 +307,7 @@ 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { isa = PBXGroup; children = ( + CE18004C14BDD837001B6329 /* Python */, CE45579A0AE3BC2B005A9546 /* Sparkle.framework */, 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, CE533602142BC034008E5374 /* Quartz.framework */, @@ -341,9 +349,10 @@ 29B97317FDCFA39411CA2CEA /* Resources */ = { isa = PBXGroup; children = ( + CEA450B714BDDFD7002DAAF2 /* dg_cocoa.py */, + CE18005014BDD87B001B6329 /* py */, CEA175C91461E8E600776591 /* locale */, CE073F5409CAE1A3005C1D2F /* help */, - CE381CF509915304003581CE /* dg_cocoa.plugin */, CEFC294309C89E0000D9F998 /* images */, CEEFC0CA10943849001F3A39 /* xib */, CEEB135109C837A2004D2330 /* dupeguru.icns */, @@ -584,7 +593,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - CE381D0509915304003581CE /* dg_cocoa.plugin in Resources */, CE073F6309CAE1A3005C1D2F /* help in Resources */, CEEB135209C837A2004D2330 /* dupeguru.icns in Resources */, CEFC294609C89E3D00D9F998 /* folder32.png in Resources */, @@ -603,6 +611,8 @@ CE31819E13D85D9B00B6D649 /* ErrorReportWindow.xib in Resources */, CE9777D1141F8CB400C13FB5 /* PrioritizeDialog.xib in Resources */, CEA175CA1461E8E600776591 /* locale in Resources */, + CE18005114BDD87B001B6329 /* py in Resources */, + CEA450B814BDDFD7002DAAF2 /* dg_cocoa.py in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -845,8 +855,8 @@ buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; GCC_C_LANGUAGE_STANDARD = c99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = "\"$(SRCROOT)/../../build/PythonHeaders\""; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.6; SDKROOT = macosx10.6; }; @@ -857,8 +867,8 @@ buildSettings = { ARCHS = "$(NATIVE_ARCH_ACTUAL)"; GCC_C_LANGUAGE_STANDARD = c99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; + HEADER_SEARCH_PATHS = "\"$(SRCROOT)/../../build/PythonHeaders\""; + LD_RUNPATH_SEARCH_PATHS = "@executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.6; SDKROOT = macosx10.6; }; diff --git a/cocoa/se/main.m b/cocoa/se/main.m index 7fedbb8e..163a7b58 100644 --- a/cocoa/se/main.m +++ b/cocoa/se/main.m @@ -7,17 +7,32 @@ http://www.hardcoded.net/licenses/bsd_license */ #import -#import "Utils.h" +#import +#import int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [Utils setPluginName:@"dg_cocoa"]; - NSString *pluginPath = [[NSBundle mainBundle] - pathForResource:@"dg_cocoa" - ofType:@"plugin"]; - NSBundle *pluginBundle = [NSBundle bundleWithPath:pluginPath]; - [pluginBundle load]; + NSString *respath = [[NSBundle mainBundle] resourcePath]; + NSString *mainpy = [respath stringByAppendingPathComponent:@"dg_cocoa.py"]; + wchar_t wPythonPath[PATH_MAX+1]; + NSString *pypath = [respath stringByAppendingPathComponent:@"py"]; + mbstowcs(wPythonPath, [pypath fileSystemRepresentation], PATH_MAX+1); + Py_SetPath(wPythonPath); + Py_SetPythonHome(wPythonPath); + Py_Initialize(); + PyEval_InitThreads(); + PyGILState_STATE gilState = PyGILState_Ensure(); + FILE* fp = fopen([mainpy UTF8String], "r"); + PyRun_SimpleFile(fp, [mainpy UTF8String]); + fclose(fp); + PyGILState_Release(gilState); + if (gilState == PyGILState_LOCKED) { + PyThreadState_Swap(NULL); + PyEval_ReleaseLock(); + } + int result = NSApplicationMain(argc, (const char **) argv); + Py_Finalize(); [pool release]; - return NSApplicationMain(argc, (const char **) argv); + return result; }