2009-12-30 16:34:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-12-30
|
2010-01-01 20:11:34 +00:00
|
|
|
# Copyright 2010 Hardcoded Software (http://www.hardcoded.net)
|
2009-12-30 16:34:41 +00:00
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-12-30 16:34:41 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2009-12-30 16:34:41 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path as op
|
2011-01-21 13:39:33 +00:00
|
|
|
from optparse import OptionParser
|
2010-01-01 20:42:52 +00:00
|
|
|
import shutil
|
2011-01-11 15:21:36 +00:00
|
|
|
import json
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2010-01-01 20:42:52 +00:00
|
|
|
from setuptools import setup
|
2010-08-17 07:30:25 +00:00
|
|
|
from distutils.extension import Extension
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2011-01-12 16:30:57 +00:00
|
|
|
from hscommon import sphinxgen
|
2011-01-22 16:06:04 +00:00
|
|
|
from hscommon.build import (add_to_pythonpath, print_and_do, copy_packages,
|
2011-01-19 08:47:00 +00:00
|
|
|
filereplace, get_module_version, build_all_cocoa_locs, build_all_qt_locs)
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2011-01-21 13:39:33 +00:00
|
|
|
def parse_args():
|
|
|
|
usage = "usage: %prog [options]"
|
|
|
|
parser = OptionParser(usage=usage)
|
2011-01-22 16:06:04 +00:00
|
|
|
parser.add_option('--clean', action='store_true', dest='clean',
|
|
|
|
help="Clean build folder before building")
|
2011-01-21 13:39:33 +00:00
|
|
|
parser.add_option('--only-help', action='store_true', dest='only_help',
|
|
|
|
help="Build only help file")
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
return options
|
|
|
|
|
2011-01-11 16:58:28 +00:00
|
|
|
def build_cocoa(edition, dev):
|
2011-01-18 14:35:14 +00:00
|
|
|
build_all_cocoa_locs('cocoalib')
|
|
|
|
build_all_cocoa_locs(op.join('cocoa', 'base'))
|
|
|
|
build_all_cocoa_locs(op.join('cocoa', edition))
|
|
|
|
|
2010-08-11 14:39:06 +00:00
|
|
|
print("Building dg_cocoa.plugin")
|
2010-02-09 14:32:52 +00:00
|
|
|
if not dev:
|
|
|
|
specific_packages = {
|
|
|
|
'se': ['core_se'],
|
2010-07-13 06:08:18 +00:00
|
|
|
'me': ['core_me'],
|
2010-02-09 14:32:52 +00:00
|
|
|
'pe': ['core_pe'],
|
|
|
|
}[edition]
|
2010-07-13 06:08:18 +00:00
|
|
|
copy_packages(['core', 'hscommon'] + specific_packages, 'build')
|
2010-02-09 14:32:52 +00:00
|
|
|
cocoa_project_path = 'cocoa/{0}'.format(edition)
|
|
|
|
shutil.copy(op.join(cocoa_project_path, 'dg_cocoa.py'), 'build')
|
|
|
|
os.chdir('build')
|
|
|
|
script_args = ['py2app', '-A'] if dev else ['py2app']
|
|
|
|
setup(
|
|
|
|
script_args = script_args,
|
|
|
|
plugin = ['dg_cocoa.py'],
|
|
|
|
setup_requires = ['py2app'],
|
|
|
|
)
|
|
|
|
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)
|
|
|
|
if dev:
|
|
|
|
# In alias mode, the tweakings we do to the pythonpath aren't counted in. We have to
|
|
|
|
# manually put a .pth in the plugin
|
|
|
|
pthpath = op.join(pluginpath, 'Contents/Resources/dev.pth')
|
|
|
|
open(pthpath, 'w').write(op.abspath('.'))
|
|
|
|
os.chdir(cocoa_project_path)
|
2011-01-13 10:29:01 +00:00
|
|
|
print('Generating Info.plist')
|
|
|
|
app_version = get_module_version('core_{}'.format(edition))
|
|
|
|
filereplace('InfoTemplate.plist', 'Info.plist', version=app_version)
|
2010-08-11 14:39:06 +00:00
|
|
|
print("Building the XCode project")
|
2010-02-09 14:32:52 +00:00
|
|
|
args = []
|
|
|
|
if dev:
|
|
|
|
args.append('-configuration dev')
|
|
|
|
else:
|
|
|
|
args.append('-configuration release')
|
|
|
|
args = ' '.join(args)
|
|
|
|
os.system('xcodebuild {0}'.format(args))
|
2010-10-04 13:42:38 +00:00
|
|
|
os.chdir('../..')
|
|
|
|
print("Creating the run.py file")
|
|
|
|
subfolder = 'dev' if dev else 'release'
|
|
|
|
app_path = {
|
|
|
|
'se': 'cocoa/se/build/{0}/dupeGuru.app',
|
|
|
|
'me': 'cocoa/me/build/{0}/dupeGuru\\ ME.app',
|
|
|
|
'pe': 'cocoa/pe/build/{0}/dupeGuru\\ PE.app',
|
|
|
|
}[edition].format(subfolder)
|
|
|
|
tmpl = open('run_template_cocoa.py', 'rt').read()
|
2010-10-05 07:27:32 +00:00
|
|
|
run_contents = tmpl.replace('{{app_path}}', app_path)
|
2010-10-04 13:42:38 +00:00
|
|
|
open('run.py', 'wt').write(run_contents)
|
2010-02-09 14:32:52 +00:00
|
|
|
|
|
|
|
def build_qt(edition, dev):
|
2011-01-19 08:47:00 +00:00
|
|
|
print("Building .ts files")
|
|
|
|
build_all_qt_locs(op.join('qt', 'lang'))
|
2010-08-17 07:30:25 +00:00
|
|
|
print("Building Qt stuff")
|
2010-08-11 14:39:06 +00:00
|
|
|
print_and_do("pyrcc4 -py3 {0} > {1}".format(op.join('qt', 'base', 'dg.qrc'), op.join('qt', 'base', 'dg_rc.py')))
|
2010-10-04 13:42:38 +00:00
|
|
|
print("Creating the run.py file")
|
|
|
|
tmpl = open('run_template_qt.py', 'rt').read()
|
2010-10-05 07:27:32 +00:00
|
|
|
run_contents = tmpl.replace('{{edition}}', edition)
|
2010-10-04 13:42:38 +00:00
|
|
|
open('run.py', 'wt').write(run_contents)
|
2010-08-17 07:30:25 +00:00
|
|
|
|
2011-01-21 13:39:33 +00:00
|
|
|
def build_help(edition):
|
2011-01-11 16:58:28 +00:00
|
|
|
print("Generating Help")
|
2011-01-12 16:30:57 +00:00
|
|
|
current_path = op.abspath('.')
|
|
|
|
help_basepath = op.join(current_path, 'help', 'en')
|
|
|
|
help_destpath = op.join(current_path, 'build', 'help'.format(edition))
|
|
|
|
changelog_path = op.join(current_path, 'help', 'changelog_{}'.format(edition))
|
|
|
|
tixurl = "https://hardcoded.lighthouseapp.com/projects/31699-dupeguru/tickets/{0}"
|
|
|
|
appname = {'se': 'dupeGuru', 'me': 'dupeGuru Music Edition', 'pe': 'dupeGuru Picture Edition'}[edition]
|
|
|
|
homepage = 'http://www.hardcoded.net/dupeguru{}/'.format('_' + edition if edition != 'se' else '')
|
|
|
|
confrepl = {'edition': edition, 'appname': appname, 'homepage': homepage}
|
2011-01-22 16:06:04 +00:00
|
|
|
sphinxgen.gen(help_basepath, help_destpath, changelog_path, tixurl, confrepl)
|
2011-01-11 16:58:28 +00:00
|
|
|
|
2010-08-17 07:30:25 +00:00
|
|
|
def build_pe_modules(ui):
|
|
|
|
def move(src, dst):
|
|
|
|
if not op.exists(src):
|
|
|
|
return
|
|
|
|
if op.exists(dst):
|
|
|
|
os.remove(dst)
|
|
|
|
print('Moving %s --> %s' % (src, dst))
|
|
|
|
os.rename(src, dst)
|
|
|
|
|
|
|
|
print("Building PE Modules")
|
|
|
|
exts = [
|
|
|
|
Extension("_block", [op.join('core_pe', 'modules', 'block.c'), op.join('core_pe', 'modules', 'common.c')]),
|
|
|
|
Extension("_cache", [op.join('core_pe', 'modules', 'cache.c'), op.join('core_pe', 'modules', 'common.c')]),
|
|
|
|
]
|
|
|
|
if ui == 'qt':
|
|
|
|
exts.append(Extension("_block_qt", [op.join('qt', 'pe', 'modules', 'block.c')]))
|
|
|
|
elif ui == 'cocoa':
|
|
|
|
exts.append(Extension(
|
|
|
|
"_block_osx", [op.join('core_pe', 'modules', 'block_osx.m'), op.join('core_pe', 'modules', 'common.c')],
|
|
|
|
extra_link_args=[
|
|
|
|
"-framework", "CoreFoundation",
|
|
|
|
"-framework", "Foundation",
|
|
|
|
"-framework", "ApplicationServices",]
|
|
|
|
))
|
|
|
|
setup(
|
|
|
|
script_args = ['build_ext', '--inplace'],
|
|
|
|
ext_modules = exts,
|
|
|
|
)
|
|
|
|
move('_block.so', op.join('core_pe', '_block.so'))
|
|
|
|
move('_block.pyd', op.join('core_pe', '_block.pyd'))
|
|
|
|
move('_block_osx.so', op.join('core_pe', '_block_osx.so'))
|
|
|
|
move('_cache.so', op.join('core_pe', '_cache.so'))
|
|
|
|
move('_cache.pyd', op.join('core_pe', '_cache.pyd'))
|
2010-08-21 15:04:23 +00:00
|
|
|
move('_block_qt.so', op.join('qt', 'pe', '_block_qt.so'))
|
|
|
|
move('_block_qt.pyd', op.join('qt', 'pe', '_block_qt.pyd'))
|
2010-02-09 14:32:52 +00:00
|
|
|
|
2011-01-21 13:39:33 +00:00
|
|
|
def build_normal(edition, ui, dev):
|
2010-08-11 14:39:06 +00:00
|
|
|
print("Building dupeGuru {0} with UI {1}".format(edition.upper(), ui))
|
2010-01-01 20:42:52 +00:00
|
|
|
add_to_pythonpath('.')
|
2011-01-22 15:12:18 +00:00
|
|
|
build_help(edition)
|
2010-08-11 14:39:06 +00:00
|
|
|
print("Building dupeGuru")
|
2009-12-30 16:34:41 +00:00
|
|
|
if edition == 'pe':
|
2010-08-17 07:30:25 +00:00
|
|
|
build_pe_modules(ui)
|
2009-12-30 16:34:41 +00:00
|
|
|
if ui == 'cocoa':
|
2011-01-11 16:58:28 +00:00
|
|
|
build_cocoa(edition, dev)
|
2009-12-30 16:34:41 +00:00
|
|
|
elif ui == 'qt':
|
2010-02-09 14:32:52 +00:00
|
|
|
build_qt(edition, dev)
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2011-01-21 13:39:33 +00:00
|
|
|
def main():
|
|
|
|
options = parse_args()
|
|
|
|
conf = json.load(open('conf.json'))
|
|
|
|
edition = conf['edition']
|
|
|
|
ui = conf['ui']
|
|
|
|
dev = conf['dev']
|
|
|
|
if dev:
|
|
|
|
print("Building in Dev mode")
|
2011-01-22 16:06:04 +00:00
|
|
|
if options.clean:
|
|
|
|
if op.exists('build'):
|
|
|
|
shutil.rmtree('build')
|
|
|
|
if not op.exists('build'):
|
|
|
|
os.mkdir('build')
|
2011-01-21 13:39:33 +00:00
|
|
|
if options.only_help:
|
|
|
|
build_help(edition)
|
|
|
|
else:
|
|
|
|
build_normal(edition, ui, dev)
|
|
|
|
|
2009-12-30 16:34:41 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|