Added auto-selection of xcode build if user specifies nothing. Includes some additional code cleanup.

This commit is contained in:
sorin.sbarnea@gmail.com 2011-06-29 07:43:51 +00:00
parent 9104860863
commit ec34e4a4d1
2 changed files with 183 additions and 166 deletions

View File

@ -1,3 +1,5 @@
import os
class Generator(object): class Generator(object):
def __init__(self, cmakeName, buildDir='build', sourceDir='..', binDir='bin'): def __init__(self, cmakeName, buildDir='build', sourceDir='..', binDir='bin'):
self.cmakeName = cmakeName self.cmakeName = cmakeName
@ -9,7 +11,7 @@ class Generator(object):
return self.buildDir return self.buildDir
def getBinDir(self, target=''): def getBinDir(self, target=''):
return self.binDir return os.path.abspath(os.path.join(self.binDir,target))
def getSourceDir(self): def getSourceDir(self):
return self.sourceDir return self.sourceDir

View File

@ -47,12 +47,13 @@ class InternalCommands:
qtpro_filename = 'qsynergy.pro' qtpro_filename = 'qsynergy.pro'
doxygen_filename = 'doxygen.cfg' doxygen_filename = 'doxygen.cfg'
# this is supposed to be relative to the project directory
macZipFiles = [ macZipFiles = [
'../../bin/synergyc', 'bin/{target}/synergyc',
'../../bin/synergys', 'bin/{target}/synergys',
'../../bin/QSynergy.app', 'bin/{target}/QSynergy.app',
'../../doc/synergy.conf.example', 'doc/synergy.conf.example',
'../../doc/MacReadme.txt'] 'doc/MacReadme.txt']
cmake_url = 'http://www.cmake.org/cmake/resources/software.html' cmake_url = 'http://www.cmake.org/cmake/resources/software.html'
@ -126,7 +127,7 @@ class InternalCommands:
def configureAll(self, targets): def configureAll(self, targets):
# if no mode specified, use default # if no mode specified, use default
if len(targets) == 0: if not targets:
targets += [self.defaultTarget,] targets += [self.defaultTarget,]
for target in targets: for target in targets:
@ -180,7 +181,7 @@ class InternalCommands:
self.restore_chdir() self.restore_chdir()
if err != 0: if err:
raise Exception('CMake encountered error: ' + str(err)) raise Exception('CMake encountered error: ' + str(err))
# allow user to skip qui compile # allow user to skip qui compile
@ -197,7 +198,7 @@ class InternalCommands:
err = os.system(qmake_cmd_string) err = os.system(qmake_cmd_string)
self.restore_chdir() self.restore_chdir()
if err != 0: if err:
raise Exception('QMake encountered error: ' + str(err)) raise Exception('QMake encountered error: ' + str(err))
self.setConfRun(target) self.setConfRun(target)
@ -207,7 +208,7 @@ class InternalCommands:
# code; we don't care about the version, since CMakeLists worrys about this for us. # code; we don't care about the version, since CMakeLists worrys about this for us.
err = os.system('%s --version' % self.cmake_cmd) err = os.system('%s --version' % self.cmake_cmd)
if err != 0: if err:
# if return code from cmake is not 0, then either something has # if return code from cmake is not 0, then either something has
# gone terribly wrong with --version, or it genuinely doesn't exist. # gone terribly wrong with --version, or it genuinely doesn't exist.
print ('Could not find `%s` in system path.\n' print ('Could not find `%s` in system path.\n'
@ -241,7 +242,7 @@ class InternalCommands:
raise Exception('Cannot continue without qmake.') raise Exception('Cannot continue without qmake.')
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if p.returncode != 0: if p.returncode:
raise Exception('Could not test for cmake: %s' % stderr) raise Exception('Could not test for cmake: %s' % stderr)
else: else:
m = re.search('.*Using Qt version (\d+\.\d+\.\d+).*', stdout) m = re.search('.*Using Qt version (\d+\.\d+\.\d+).*', stdout)
@ -269,7 +270,7 @@ class InternalCommands:
def build(self, targets=[], skipConfig=False): def build(self, targets=[], skipConfig=False):
# if no mode specified, use default # if no mode specified, use default
if len(targets) == 0: if not targets:
targets += [self.defaultTarget,] targets += [self.defaultTarget,]
self.ensure_setup_latest() self.ensure_setup_latest()
@ -301,13 +302,13 @@ class InternalCommands:
err = os.system(cmd) err = os.system(cmd)
self.restore_chdir() self.restore_chdir()
if err != 0: if err:
raise Exception(cmd + ' failed: ' + str(err)) raise Exception(cmd + ' failed: ' + str(err))
def clean(self, targets=[]): def clean(self, targets=[]):
# if no mode specified, use default # if no mode specified, use default
if len(targets) == 0: if not targets:
targets += [self.defaultTarget,] targets += [self.defaultTarget,]
generator = self.getGeneratorFromConfig().cmakeName generator = self.getGeneratorFromConfig().cmakeName
@ -324,7 +325,6 @@ class InternalCommands:
self.run_vcbuild(generator, target, '/clean') self.run_vcbuild(generator, target, '/clean')
else: else:
cmd = ''
if generator == "Unix Makefiles": if generator == "Unix Makefiles":
print 'Cleaning with GNU Make...' print 'Cleaning with GNU Make...'
cmd = self.make_cmd cmd = self.make_cmd
@ -339,7 +339,7 @@ class InternalCommands:
err = os.system(cmd + ' clean') err = os.system(cmd + ' clean')
self.restore_chdir() self.restore_chdir()
if err != 0: if err:
raise Exception('Clean failed: ' + str(err)) raise Exception('Clean failed: ' + str(err))
# allow user to skip qui compile # allow user to skip qui compile
@ -370,7 +370,7 @@ class InternalCommands:
err = os.system(gui_make_cmd + ' ' + target) err = os.system(gui_make_cmd + ' ' + target)
self.restore_chdir() self.restore_chdir()
if err != 0: if err:
raise Exception(gui_make_cmd + ' failed with error: ' + str(err)) raise Exception(gui_make_cmd + ' failed with error: ' + str(err))
else: else:
if sys.platform == 'darwin': if sys.platform == 'darwin':
@ -398,7 +398,7 @@ class InternalCommands:
def update(self): def update(self):
print "Running Subversion update..." print "Running Subversion update..."
err = os.system('svn update') err = os.system('svn update')
if err != 0: if err:
raise Exception('Could not update from repository with error code code: ' + str(err)) raise Exception('Could not update from repository with error code code: ' + str(err))
def revision(self): def revision(self):
@ -412,7 +412,7 @@ class InternalCommands:
p = subprocess.Popen(['svn', 'info'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(['svn', 'info'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if p.returncode != 0: if p.returncode:
raise Exception('Could not get revision - svn info failed with code: ' + str(p.returncode)) raise Exception('Could not get revision - svn info failed with code: ' + str(p.returncode))
m = re.search('.*Revision: (\d+).*', stdout) m = re.search('.*Revision: (\d+).*', stdout)
@ -434,7 +434,7 @@ class InternalCommands:
err = os.system('doxygen %s/%s' % (self.doc_dir, self.doxygen_filename)) err = os.system('doxygen %s/%s' % (self.doc_dir, self.doxygen_filename))
if err != 0: if err:
raise Exception('doxygen failed with error code: ' + str(err)) raise Exception('doxygen failed with error code: ' + str(err))
def dist(self, type, vcRedistDir, qtDir): def dist(self, type, vcRedistDir, qtDir):
@ -443,7 +443,10 @@ class InternalCommands:
package_unsupported = False package_unsupported = False
unixTarget = self.defaultTarget unixTarget = self.defaultTarget
if type == '' or type == None: if type == '' or type is None:
if sys.platform == 'darwin':
type = 'mac'
else:
raise Exception('No type specified.') raise Exception('No type specified.')
if type != 'win' and type != 'mac': if type != 'win' and type != 'mac':
@ -454,7 +457,7 @@ class InternalCommands:
moveExt = '' moveExt = ''
if type == None: if type is None:
self.dist_usage() self.dist_usage()
return return
@ -515,7 +518,7 @@ class InternalCommands:
print 'Exporting repository to: ' + exportPath print 'Exporting repository to: ' + exportPath
err = os.system('svn export . ' + exportPath) err = os.system('svn export . ' + exportPath)
if err != 0: if err:
raise Exception('Repository export failed: ' + str(err)) raise Exception('Repository export failed: ' + str(err))
packagePath = '../' + self.getGenerator().binDir + '/' + name + '.tar.gz' packagePath = '../' + self.getGenerator().binDir + '/' + name + '.tar.gz'
@ -524,7 +527,7 @@ class InternalCommands:
self.try_chdir(self.getGenerator().buildDir) self.try_chdir(self.getGenerator().buildDir)
print 'Packaging to: ' + packagePath print 'Packaging to: ' + packagePath
err = os.system('tar cfvz ' + packagePath + ' ' + name) err = os.system('tar cfvz ' + packagePath + ' ' + name)
if err != 0: if err:
raise Exception('Package failed: ' + str(err)) raise Exception('Package failed: ' + str(err))
finally: finally:
self.restore_chdir() self.restore_chdir()
@ -532,7 +535,7 @@ class InternalCommands:
def unixMove(self, source, dest): def unixMove(self, source, dest):
print 'Moving ' + source + ' to ' + dest print 'Moving ' + source + ' to ' + dest
err = os.system('mv ' + source + ' ' + dest) err = os.system('mv ' + source + ' ' + dest)
if err != 0: if err:
raise Exception('Package failed: ' + str(err)) raise Exception('Package failed: ' + str(err))
def distMac(self, unixTarget): def distMac(self, unixTarget):
@ -558,6 +561,9 @@ class InternalCommands:
os.makedirs(zipFile) os.makedirs(zipFile)
for f in self.macZipFiles: for f in self.macZipFiles:
f = f.replace('{target}', unixTarget)
f = os.path.abspath(os.path.join(os.path.dirname(__file__),"../../..",f))
print f
if not os.path.exists(f): if not os.path.exists(f):
raise Exception('File does not exist: ' + f) raise Exception('File does not exist: ' + f)
elif os.path.isdir(f): elif os.path.isdir(f):
@ -567,11 +573,11 @@ class InternalCommands:
else: else:
shutil.copy2(f, zipFile + '/') shutil.copy2(f, zipFile + '/')
zipCmd = ('zip -r ../../' + binDir + '/' + zipFile + '.zip ' + zipFile); zipCmd = ('zip -r ../../' + binDir + '/' + zipFile + '.zip ' + zipFile)
print 'Creating package: ' + zipCmd print 'Creating package: ' + zipCmd
err = os.system(zipCmd) err = os.system(zipCmd)
if err != 0: if err:
raise Exception('Zip failed, code: ' + err) raise Exception('Zip failed, code: ' + err)
finally: finally:
@ -613,7 +619,7 @@ class InternalCommands:
command = 'makensis ' + nsiPath command = 'makensis ' + nsiPath
print 'NSIS command: ' + command print 'NSIS command: ' + command
err = os.system(command) err = os.system(command)
if err != 0: if err:
raise Exception('Package failed: ' + str(err)) raise Exception('Package failed: ' + str(err))
def getVersionFromCmake(self): def getVersionFromCmake(self):
@ -712,7 +718,7 @@ class InternalCommands:
print 'CPack command: ' + command print 'CPack command: ' + command
err = os.system(command) err = os.system(command)
self.restore_chdir() self.restore_chdir()
if err != 0: if err:
raise Exception('Package failed: ' + str(err)) raise Exception('Package failed: ' + str(err))
def dist_usage(self): def dist_usage(self):
@ -769,14 +775,14 @@ class InternalCommands:
path = application + ' ' + path path = application + ' ' + path
err = os.system(path) err = os.system(path)
if err != 0: if err:
raise Exception('Could not open project with error code code: ' + str(err)) raise Exception('Could not open project with error code code: ' + str(err))
def setup(self, target=''): def setup(self, target=''):
print "Running setup..." print "Running setup..."
oldGenerator = self.findGeneratorFromConfig() oldGenerator = self.findGeneratorFromConfig()
if not oldGenerator == None: if not oldGenerator is None:
for target in ['debug', 'release']: for target in ['debug', 'release']:
buildDir = oldGenerator.getBuildDir(target) buildDir = oldGenerator.getBuildDir(target)
@ -907,6 +913,16 @@ class InternalCommands:
if conf: if conf:
return conf return conf
# generator not configured, will auto-configure it
generators = self.get_generators()
keys = generators.keys()
keys.sort()
for k in keys:
# print str(k) + ': ' + generators[k].cmakeName
if sys.platform == 'darwin' and generators[k].cmakeName == 'Xcode':
return generators[int(k)]
# TODO add auto-detection for other platforms, eventually by detecting what is available
raise Exception( raise Exception(
'Generator not specified, use -g arg ' + 'Generator not specified, use -g arg ' +
'(use `hm genlist` for a list of generators).') '(use `hm genlist` for a list of generators).')
@ -940,7 +956,6 @@ class InternalCommands:
key_name = r'SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' key_name = r'SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7'
else: else:
key_name = r'SOFTWARE\Microsoft\VisualStudio\SxS\VC7' key_name = r'SOFTWARE\Microsoft\VisualStudio\SxS\VC7'
try: try:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key_name) key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key_name)
except: except:
@ -1012,7 +1027,7 @@ class InternalCommands:
file.close() file.close()
err = os.system(temp_bat) err = os.system(temp_bat)
if err != 0: if err:
raise Exception('Microsoft compiler failed with error code: ' + str(err)) raise Exception('Microsoft compiler failed with error code: ' + str(err))
def ensure_setup_latest(self): def ensure_setup_latest(self):
@ -1025,7 +1040,7 @@ class InternalCommands:
'--quiet --suffix=none --style=java --indent=force-tab=4 --recursive ' '--quiet --suffix=none --style=java --indent=force-tab=4 --recursive '
'lib/*.cpp lib/*.h cmd/*.cpp cmd/*.h') 'lib/*.cpp lib/*.h cmd/*.cpp cmd/*.h')
if err != 0: if err:
raise Exception('Reformat failed with error code: ' + str(err)) raise Exception('Reformat failed with error code: ' + str(err))
def printGeneratorList(self): def printGeneratorList(self):
@ -1047,7 +1062,7 @@ class InternalCommands:
# version is major and minor with no dots (e.g. 106) # version is major and minor with no dots (e.g. 106)
return ('MacOSX' + str(result.group(1)) + return ('MacOSX' + str(result.group(1)) +
str(result.group(2)) + '-Universal'); str(result.group(2)) + '-Universal')
# the command handler should be called only from hm.py (i.e. directly # the command handler should be called only from hm.py (i.e. directly
# from the command prompt). the purpose of this class is so that we # from the command prompt). the purpose of this class is so that we