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):
def __init__(self, cmakeName, buildDir='build', sourceDir='..', binDir='bin'):
self.cmakeName = cmakeName
@ -9,7 +11,7 @@ class Generator(object):
return self.buildDir
def getBinDir(self, target=''):
return self.binDir
return os.path.abspath(os.path.join(self.binDir,target))
def getSourceDir(self):
return self.sourceDir

View File

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