backing out r1057

This commit is contained in:
Nick Bolton 2011-06-29 09:56:32 +00:00
parent ec34e4a4d1
commit 54588b3d6f
2 changed files with 166 additions and 183 deletions

View File

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

View File

@ -22,7 +22,7 @@ if sys.version_info >= (2, 4):
import subprocess import subprocess
class InternalCommands: class InternalCommands:
project = 'synergy' project = 'synergy'
setup_version = 5 # increment to force setup/config setup_version = 5 # increment to force setup/config
website_url = 'http://synergy-foss.org/' website_url = 'http://synergy-foss.org/'
@ -46,26 +46,25 @@ class InternalCommands:
configFilename = '%s/%s.cfg' % (configDir, this_cmd) configFilename = '%s/%s.cfg' % (configDir, this_cmd)
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/{target}/synergyc', '../../bin/synergyc',
'bin/{target}/synergys', '../../bin/synergys',
'bin/{target}/QSynergy.app', '../../bin/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'
# try_chdir(...) and restore_chdir() will use this # try_chdir(...) and restore_chdir() will use this
prevdir = '' prevdir = ''
# by default, no index specified as arg # by default, no index specified as arg
generator_id = None generator_id = None
# by default, prompt user for input # by default, prompt user for input
no_prompts = False no_prompts = False
# by default, don't compile the gui # by default, don't compile the gui
enable_make_gui = False enable_make_gui = False
@ -100,7 +99,7 @@ class InternalCommands:
def xcodeproj_filepath(self, target=''): def xcodeproj_filepath(self, target=''):
return '%s/%s' % (self.getBuildDir(target), self.xcodeproj_filename) return '%s/%s' % (self.getBuildDir(target), self.xcodeproj_filename)
def usage(self): def usage(self):
app = sys.argv[0] app = sys.argv[0]
print ('Usage: %s <command> [-g <index>|-v|--no-prompts|<command-options>]\n' print ('Usage: %s <command> [-g <index>|-v|--no-prompts|<command-options>]\n'
@ -127,20 +126,20 @@ class InternalCommands:
def configureAll(self, targets): def configureAll(self, targets):
# if no mode specified, use default # if no mode specified, use default
if not targets: if len(targets) == 0:
targets += [self.defaultTarget,] targets += [self.defaultTarget,]
for target in targets: for target in targets:
self.configure(target) self.configure(target)
def configure(self, target='', extraArgs=''): def configure(self, target='', extraArgs=''):
cmake_args = '' cmake_args = ''
# ensure latest setup and do not ask config for generator (only fall # ensure latest setup and do not ask config for generator (only fall
# back to prompt if not specified as arg) # back to prompt if not specified as arg)
self.ensure_setup_latest() self.ensure_setup_latest()
# ensure that we have access to cmake # ensure that we have access to cmake
_cmake_cmd = self.persist_cmake() _cmake_cmd = self.persist_cmake()
@ -148,14 +147,14 @@ class InternalCommands:
# file for the generator (but again, we only fall back to this if not # file for the generator (but again, we only fall back to this if not
# specified as arg). # specified as arg).
generator = self.getGenerator() generator = self.getGenerator()
if generator != self.findGeneratorFromConfig(): if generator != self.findGeneratorFromConfig():
print('Generator changed, running setup.') print('Generator changed, running setup.')
self.setup(target) self.setup(target)
if generator.cmakeName != '': if generator.cmakeName != '':
cmake_args += ' -G "' + generator.cmakeName + '"' cmake_args += ' -G "' + generator.cmakeName + '"'
# default is release # default is release
if target == '': if target == '':
print 'Defaulting target to: ' + self.defaultTarget print 'Defaulting target to: ' + self.defaultTarget
@ -164,15 +163,15 @@ class InternalCommands:
# for makefiles always specify a build type (debug, release, etc) # for makefiles always specify a build type (debug, release, etc)
if generator.cmakeName.find('Unix Makefiles') != -1: if generator.cmakeName.find('Unix Makefiles') != -1:
cmake_args += ' -DCMAKE_BUILD_TYPE=' + target.capitalize() cmake_args += ' -DCMAKE_BUILD_TYPE=' + target.capitalize()
# if not visual studio, use parent dir # if not visual studio, use parent dir
sourceDir = generator.getSourceDir() sourceDir = generator.getSourceDir()
if extraArgs != '': if extraArgs != '':
cmake_args += ' ' + extraArgs cmake_args += ' ' + extraArgs
cmake_cmd_string = _cmake_cmd + cmake_args + ' ' + sourceDir cmake_cmd_string = _cmake_cmd + cmake_args + ' ' + sourceDir
# Run from build dir so we have an out-of-source build. # Run from build dir so we have an out-of-source build.
self.try_chdir(self.getBuildDir(target)) self.try_chdir(self.getBuildDir(target))
@ -181,34 +180,34 @@ class InternalCommands:
self.restore_chdir() self.restore_chdir()
if err: if err != 0:
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
if self.enable_make_gui: if self.enable_make_gui:
# make sure we have qmake # make sure we have qmake
self.persist_qmake() self.persist_qmake()
qmake_cmd_string = self.qmake_cmd + ' ' + self.qtpro_filename qmake_cmd_string = self.qmake_cmd + ' ' + self.qtpro_filename
print "QMake command: " + qmake_cmd_string print "QMake command: " + qmake_cmd_string
# run qmake from the gui dir # run qmake from the gui dir
self.try_chdir(self.gui_dir) self.try_chdir(self.gui_dir)
err = os.system(qmake_cmd_string) err = os.system(qmake_cmd_string)
self.restore_chdir() self.restore_chdir()
if err: if err != 0:
raise Exception('QMake encountered error: ' + str(err)) raise Exception('QMake encountered error: ' + str(err))
self.setConfRun(target) self.setConfRun(target)
def persist_cmake(self): def persist_cmake(self):
# even though we're running `cmake --version`, we're only doing this for the 0 return # even though we're running `cmake --version`, we're only doing this for the 0 return
# 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: if err != 0:
# 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'
@ -225,7 +224,7 @@ class InternalCommands:
# cannot use subprocess on < python 2.4 # cannot use subprocess on < python 2.4
if sys.version_info < (2, 4): if sys.version_info < (2, 4):
return return
try: try:
p = subprocess.Popen( p = subprocess.Popen(
[self.qmake_cmd, '--version'], [self.qmake_cmd, '--version'],
@ -240,9 +239,9 @@ class InternalCommands:
'2. Try to download Qt (check our dev FAQ for links):\n' '2. Try to download Qt (check our dev FAQ for links):\n'
' qt-sdk-win-opensource-2010.02.exe') ' qt-sdk-win-opensource-2010.02.exe')
raise Exception('Cannot continue without qmake.') raise Exception('Cannot continue without qmake.')
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
if p.returncode: if p.returncode != 0:
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)
@ -270,13 +269,13 @@ 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 not targets: if len(targets) == 0:
targets += [self.defaultTarget,] targets += [self.defaultTarget,]
self.ensure_setup_latest() self.ensure_setup_latest()
generator = self.getGeneratorFromConfig().cmakeName generator = self.getGeneratorFromConfig().cmakeName
if generator.find('Unix Makefiles') != -1: if generator.find('Unix Makefiles') != -1:
for target in targets: for target in targets:
self.ensureConfHasRun(target, skipConfig) self.ensureConfHasRun(target, skipConfig)
@ -295,22 +294,22 @@ class InternalCommands:
# allow user to skip qui compile # allow user to skip qui compile
if self.enable_make_gui: if self.enable_make_gui:
self.make_gui(targets) self.make_gui(targets)
def runBuildCommand(self, cmd, target): def runBuildCommand(self, cmd, target):
self.try_chdir(self.getBuildDir(target)) self.try_chdir(self.getBuildDir(target))
err = os.system(cmd) err = os.system(cmd)
self.restore_chdir() self.restore_chdir()
if err: if err != 0:
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 not targets: if len(targets) == 0:
targets += [self.defaultTarget,] targets += [self.defaultTarget,]
generator = self.getGeneratorFromConfig().cmakeName generator = self.getGeneratorFromConfig().cmakeName
if generator.startswith('Visual Studio'): if generator.startswith('Visual Studio'):
@ -318,13 +317,14 @@ class InternalCommands:
if generator.startswith('Visual Studio 10'): if generator.startswith('Visual Studio 10'):
for target in targets: for target in targets:
self.run_vcbuild(generator, target, '/target:clean') self.run_vcbuild(generator, target, '/target:clean')
# any other version of visual studio, use /clean # any other version of visual studio, use /clean
elif generator.startswith('Visual Studio'): elif generator.startswith('Visual Studio'):
for target in targets: for target in targets:
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: if err != 0:
raise Exception('Clean failed: ' + str(err)) raise Exception('Clean failed: ' + str(err))
# allow user to skip qui compile # allow user to skip qui compile
@ -347,9 +347,9 @@ class InternalCommands:
if self.enable_make_gui: if self.enable_make_gui:
for target in targets: for target in targets:
clean_targets.append(target + '-clean') clean_targets.append(target + '-clean')
self.make_gui(clean_targets) self.make_gui(clean_targets)
def make_gui(self, targets): def make_gui(self, targets):
if sys.platform == 'win32': if sys.platform == 'win32':
gui_make_cmd = self.w32_make_cmd gui_make_cmd = self.w32_make_cmd
@ -359,9 +359,9 @@ class InternalCommands:
gui_make_cmd = self.xcodebuild_cmd gui_make_cmd = self.xcodebuild_cmd
else: else:
raise Exception('Unsupported platform: ' + sys.platform) raise Exception('Unsupported platform: ' + sys.platform)
print 'Make GUI command: ' + gui_make_cmd print 'Make GUI command: ' + gui_make_cmd
# HACK: don't know how to build in either debug or release on unix; # HACK: don't know how to build in either debug or release on unix;
# always builds release! # always builds release!
if sys.platform == 'win32': if sys.platform == 'win32':
@ -369,8 +369,8 @@ class InternalCommands:
self.try_chdir(self.gui_dir) self.try_chdir(self.gui_dir)
err = os.system(gui_make_cmd + ' ' + target) err = os.system(gui_make_cmd + ' ' + target)
self.restore_chdir() self.restore_chdir()
if err: if err != 0:
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':
@ -381,26 +381,26 @@ class InternalCommands:
self.try_chdir(make_dir) self.try_chdir(make_dir)
err = os.system(gui_make_cmd) err = os.system(gui_make_cmd)
self.restore_chdir() self.restore_chdir()
def open(self): def open(self):
generator = self.getGeneratorFromConfig().cmakeName generator = self.getGeneratorFromConfig().cmakeName
if generator.startswith('Visual Studio'): if generator.startswith('Visual Studio'):
print 'Opening with %s...' % generator print 'Opening with %s...' % generator
self.open_internal(self.sln_filepath()) self.open_internal(self.sln_filepath())
elif generator.startswith('Xcode'): elif generator.startswith('Xcode'):
print 'Opening with %s...' % generator print 'Opening with %s...' % generator
self.open_internal(self.xcodeproj_filepath(), 'open') self.open_internal(self.xcodeproj_filepath(), 'open')
else: else:
raise Exception('Not supported with generator: ' + generator) raise Exception('Not supported with generator: ' + generator)
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: if err != 0:
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):
print self.find_revision() print self.find_revision()
@ -412,42 +412,39 @@ 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: if p.returncode != 0:
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)
if not m: if not m:
raise Exception('Could not find revision number in svn info output.') raise Exception('Could not find revision number in svn info output.')
return m.group(1) return m.group(1)
def kill(self): def kill(self):
if sys.platform == 'win32': if sys.platform == 'win32':
return os.system('taskkill /F /FI "IMAGENAME eq synergy*"') return os.system('taskkill /F /FI "IMAGENAME eq synergy*"')
else: else:
raise Exception('Not implemented for platform: ' + sys.platform) raise Exception('Not implemented for platform: ' + sys.platform)
def doxygen(self): def doxygen(self):
# The conf generates doc/doxygen.cfg from cmake/doxygen.cfg.in # The conf generates doc/doxygen.cfg from cmake/doxygen.cfg.in
if not self.hasConfRun(): if not self.hasConfRun():
self.configure() self.configure()
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: if err != 0:
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):
# Package is supported by default. # Package is supported by default.
package_unsupported = False package_unsupported = False
unixTarget = self.defaultTarget unixTarget = self.defaultTarget
if type == '' or type is None: if type == '' or type == None:
if sys.platform == 'darwin': raise Exception('No type specified.')
type = 'mac'
else:
raise Exception('No type specified.')
if type != 'win' and type != 'mac': if type != 'win' and type != 'mac':
self.configure(unixTarget, '-DCONF_CPACK:BOOL=TRUE') self.configure(unixTarget, '-DCONF_CPACK:BOOL=TRUE')
@ -457,42 +454,42 @@ class InternalCommands:
moveExt = '' moveExt = ''
if type is None: if type == None:
self.dist_usage() self.dist_usage()
return return
elif type == 'src': elif type == 'src':
if sys.platform in ['linux2', 'darwin']: if sys.platform in ['linux2', 'darwin']:
self.distSrc() self.distSrc()
else: else:
package_unsupported = True package_unsupported = True
elif type == 'rpm': elif type == 'rpm':
if sys.platform == 'linux2': if sys.platform == 'linux2':
self.dist_run('cpack -G RPM', unixTarget) self.dist_run('cpack -G RPM', unixTarget)
moveExt = 'rpm' moveExt = 'rpm'
else: else:
package_unsupported = True package_unsupported = True
elif type == 'deb': elif type == 'deb':
if sys.platform == 'linux2': if sys.platform == 'linux2':
self.dist_run('cpack -G DEB', unixTarget) self.dist_run('cpack -G DEB', unixTarget)
moveExt = 'deb' moveExt = 'deb'
else: else:
package_unsupported = True package_unsupported = True
elif type == 'win': elif type == 'win':
if sys.platform == 'win32': if sys.platform == 'win32':
self.distNsis(vcRedistDir, qtDir) self.distNsis(vcRedistDir, qtDir)
else: else:
package_unsupported = True package_unsupported = True
elif type == 'mac': elif type == 'mac':
if sys.platform == 'darwin': if sys.platform == 'darwin':
self.distMac(unixTarget) self.distMac(unixTarget)
else: else:
package_unsupported = True package_unsupported = True
else: else:
raise Exception('Package type not supported: ' + type) raise Exception('Package type not supported: ' + type)
@ -505,7 +502,7 @@ class InternalCommands:
raise Exception( raise Exception(
("Package type, '%s' is not supported for platform, '%s'") ("Package type, '%s' is not supported for platform, '%s'")
% (type, sys.platform)) % (type, sys.platform))
def distSrc(self): def distSrc(self):
version = self.getVersionFromCmake() version = self.getVersionFromCmake()
name = (self.project + '-' + version + '-Source') name = (self.project + '-' + version + '-Source')
@ -518,7 +515,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: if err != 0:
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'
@ -527,7 +524,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: if err != 0:
raise Exception('Package failed: ' + str(err)) raise Exception('Package failed: ' + str(err))
finally: finally:
self.restore_chdir() self.restore_chdir()
@ -535,7 +532,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: if err != 0:
raise Exception('Package failed: ' + str(err)) raise Exception('Package failed: ' + str(err))
def distMac(self, unixTarget): def distMac(self, unixTarget):
@ -546,7 +543,7 @@ class InternalCommands:
version = self.getVersionFromCmake() version = self.getVersionFromCmake()
zipFile = (self.project + '-' + version + '-' + zipFile = (self.project + '-' + version + '-' +
self.getMacPackageName()) self.getMacPackageName())
binDir = self.getBinDir(unixTarget) binDir = self.getBinDir(unixTarget)
buildDir = self.getBuildDir(unixTarget) buildDir = self.getBuildDir(unixTarget)
@ -561,9 +558,6 @@ 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):
@ -573,18 +567,18 @@ 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: if err != 0:
raise Exception('Zip failed, code: ' + err) raise Exception('Zip failed, code: ' + err)
finally: finally:
self.restore_chdir() self.restore_chdir()
def distNsis(self, vcRedistDir, qtDir): def distNsis(self, vcRedistDir, qtDir):
if vcRedistDir == '': if vcRedistDir == '':
raise Exception( raise Exception(
'VC++ redist dir path not specified (--vcredist-dir).') 'VC++ redist dir path not specified (--vcredist-dir).')
@ -601,7 +595,7 @@ class InternalCommands:
if generator.endswith('Win64'): if generator.endswith('Win64'):
arch = 'x64' arch = 'x64'
installDirVar = '$PROGRAMFILES64' installDirVar = '$PROGRAMFILES64'
templateFile = open(self.cmake_dir + '\Installer.nsi.in') templateFile = open(self.cmake_dir + '\Installer.nsi.in')
template = templateFile.read() template = templateFile.read()
@ -619,7 +613,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: if err != 0:
raise Exception('Package failed: ' + str(err)) raise Exception('Package failed: ' + str(err))
def getVersionFromCmake(self): def getVersionFromCmake(self):
@ -640,10 +634,10 @@ class InternalCommands:
def distftp(self, type, ftp): def distftp(self, type, ftp):
if not type: if not type:
raise Exception('Type not specified.') raise Exception('Type not specified.')
if not ftp: if not ftp:
raise Exception('FTP info not defined.') raise Exception('FTP info not defined.')
src = self.dist_name(type) src = self.dist_name(type)
dest = self.dist_name_rev(type) dest = self.dist_name_rev(type)
print 'Uploading %s to FTP server %s...' % (dest, ftp.host) print 'Uploading %s to FTP server %s...' % (dest, ftp.host)
@ -655,30 +649,30 @@ class InternalCommands:
ftp.run(srcDir + src, dest) ftp.run(srcDir + src, dest)
print 'Done' print 'Done'
def dist_name(self, type): def dist_name(self, type):
ext = None ext = None
platform = None platform = None
if type == 'src': if type == 'src':
ext = 'tar.gz' ext = 'tar.gz'
platform = 'Source' platform = 'Source'
elif type == 'rpm' or type == 'deb': elif type == 'rpm' or type == 'deb':
# os_bits should be loaded with '32bit' or '64bit' # os_bits should be loaded with '32bit' or '64bit'
import platform import platform
(os_bits, other) = platform.architecture() (os_bits, other) = platform.architecture()
# get platform based on current platform # get platform based on current platform
ext = type ext = type
if os_bits == '32bit': if os_bits == '32bit':
platform = 'Linux-i686' platform = 'Linux-i686'
elif os_bits == '64bit': elif os_bits == '64bit':
platform = 'Linux-x86_64' platform = 'Linux-x86_64'
elif type == 'win': elif type == 'win':
# get platform based on last generator used # get platform based on last generator used
ext = 'exe' ext = 'exe'
generator = self.getGeneratorFromConfig().cmakeName generator = self.getGeneratorFromConfig().cmakeName
@ -686,39 +680,39 @@ class InternalCommands:
platform = 'Windows-x64' platform = 'Windows-x64'
else: else:
platform = 'Windows-x86' platform = 'Windows-x86'
elif type == 'mac': elif type == 'mac':
#ext = 'dmg' #ext = 'dmg'
ext = 'zip' ext = 'zip'
platform = self.getMacPackageName() platform = self.getMacPackageName()
if not platform: if not platform:
raise Exception('Unable to detect package platform.') raise Exception('Unable to detect package platform.')
pattern = re.escape(self.project + '-') + '\d\.\d\.\d' + re.escape('-' + platform + '.' + ext) pattern = re.escape(self.project + '-') + '\d\.\d\.\d' + re.escape('-' + platform + '.' + ext)
# only use release dir if not windows # only use release dir if not windows
target = '' target = ''
for filename in os.listdir(self.getBinDir(target)): for filename in os.listdir(self.getBinDir(target)):
if re.search(pattern, filename): if re.search(pattern, filename):
return filename return filename
# still here? package probably not created yet. # still here? package probably not created yet.
raise Exception('Could not find package name with pattern: ' + pattern) raise Exception('Could not find package name with pattern: ' + pattern)
def dist_name_rev(self, type): def dist_name_rev(self, type):
# find the version number (we're puting the rev in after this) # find the version number (we're puting the rev in after this)
pattern = '(.*\d+\.\d+\.\d+)(.*)' pattern = '(.*\d+\.\d+\.\d+)(.*)'
replace = '\g<1>-r' + self.find_revision() + '\g<2>' replace = '\g<1>-r' + self.find_revision() + '\g<2>'
return re.sub(pattern, replace, self.dist_name(type)) return re.sub(pattern, replace, self.dist_name(type))
def dist_run(self, command, target=''): def dist_run(self, command, target=''):
self.try_chdir(self.getBuildDir(target)) self.try_chdir(self.getBuildDir(target))
print 'CPack command: ' + command print 'CPack command: ' + command
err = os.system(command) err = os.system(command)
self.restore_chdir() self.restore_chdir()
if err: if err != 0:
raise Exception('Package failed: ' + str(err)) raise Exception('Package failed: ' + str(err))
def dist_usage(self): def dist_usage(self):
@ -750,7 +744,7 @@ class InternalCommands:
if not os.path.exists(dir): if not os.path.exists(dir):
print 'Creating dir: ' + dir print 'Creating dir: ' + dir
os.makedirs(dir) os.makedirs(dir)
prevdir = os.path.abspath(os.curdir) prevdir = os.path.abspath(os.curdir)
# It will exist by this point, so it's safe to chdir. # It will exist by this point, so it's safe to chdir.
@ -770,19 +764,19 @@ class InternalCommands:
raise Exception('Project file (%s) not found, run hm conf first.' % project_filename) raise Exception('Project file (%s) not found, run hm conf first.' % project_filename)
else: else:
path = project_filename path = project_filename
if application != '': if application != '':
path = application + ' ' + path path = application + ' ' + path
err = os.system(path) err = os.system(path)
if err: if err != 0:
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 is None: if not oldGenerator == None:
for target in ['debug', 'release']: for target in ['debug', 'release']:
buildDir = oldGenerator.getBuildDir(target) buildDir = oldGenerator.getBuildDir(target)
@ -809,9 +803,9 @@ class InternalCommands:
if not config.has_section('cmake'): if not config.has_section('cmake'):
config.add_section('cmake') config.add_section('cmake')
config.set('hm', 'setup_version', self.setup_version) config.set('hm', 'setup_version', self.setup_version)
# store the generator so we don't need to ask again # store the generator so we don't need to ask again
config.set('cmake', 'generator', generator) config.set('cmake', 'generator', generator)
@ -834,16 +828,16 @@ class InternalCommands:
generator = self.findGeneratorFromConfig() generator = self.findGeneratorFromConfig()
if generator: if generator:
return generator return generator
raise Exception("Could not find generator: " + name) raise Exception("Could not find generator: " + name)
def findGeneratorFromConfig(self): def findGeneratorFromConfig(self):
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
config.read(self.configFilename) config.read(self.configFilename)
if not config.has_section('cmake'): if not config.has_section('cmake'):
return None return None
name = config.get('cmake', 'generator') name = config.get('cmake', 'generator')
generators = self.get_generators() generators = self.get_generators()
@ -852,7 +846,7 @@ class InternalCommands:
for k in keys: for k in keys:
if generators[k].cmakeName == name: if generators[k].cmakeName == name:
return generators[k] return generators[k]
return None return None
def min_setup_version(self, version): def min_setup_version(self, version):
@ -896,7 +890,7 @@ class InternalCommands:
return self.darwin_generators return self.darwin_generators
else: else:
raise Exception('Unsupported platform: ' + sys.platform) raise Exception('Unsupported platform: ' + sys.platform)
def get_generator_from_prompt(self): def get_generator_from_prompt(self):
return self.getGenerator().cmakeName return self.getGenerator().cmakeName
@ -904,25 +898,15 @@ class InternalCommands:
generators = self.get_generators() generators = self.get_generators()
if len(generators.keys()) == 1: if len(generators.keys()) == 1:
return generators[generators.keys()[0]] return generators[generators.keys()[0]]
# if user has specified a generator as an argument # if user has specified a generator as an argument
if self.generator_id: if self.generator_id:
return generators[int(self.generator_id)] return generators[int(self.generator_id)]
conf = self.findGeneratorFromConfig() conf = self.findGeneratorFromConfig()
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).')
@ -931,12 +915,12 @@ class InternalCommands:
if self.no_prompts: if self.no_prompts:
raise Exception('User prompting is disabled.') raise Exception('User prompting is disabled.')
prompt = 'Enter a number:' prompt = 'Enter a number:'
print prompt, print prompt,
generator_id = raw_input() generator_id = raw_input()
if generator_id in generators: if generator_id in generators:
print 'Selected generator:', generators[generator_id] print 'Selected generator:', generators[generator_id]
else: else:
@ -947,20 +931,21 @@ class InternalCommands:
def get_vcvarsall(self, generator): def get_vcvarsall(self, generator):
import platform, _winreg import platform, _winreg
# os_bits should be loaded with '32bit' or '64bit' # os_bits should be loaded with '32bit' or '64bit'
(os_bits, other) = platform.architecture() (os_bits, other) = platform.architecture()
# visual studio is a 32-bit app, so when we're on 64-bit, we need to check the WoW dungeon # visual studio is a 32-bit app, so when we're on 64-bit, we need to check the WoW dungeon
if os_bits == '64bit': if os_bits == '64bit':
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:
raise Exception('Unable to open Visual Studio registry key. Application may not be installed.') raise Exception('Unable to open Visual Studio registry key. Application may not be installed.')
if generator.startswith('Visual Studio 8'): if generator.startswith('Visual Studio 8'):
value,type = _winreg.QueryValueEx(key, '8.0') value,type = _winreg.QueryValueEx(key, '8.0')
elif generator.startswith('Visual Studio 9'): elif generator.startswith('Visual Studio 9'):
@ -969,26 +954,26 @@ class InternalCommands:
value,type = _winreg.QueryValueEx(key, '10.0') value,type = _winreg.QueryValueEx(key, '10.0')
else: else:
raise Exception('Cannot determin vcvarsall.bat location for: ' + generator) raise Exception('Cannot determin vcvarsall.bat location for: ' + generator)
# not sure why, but the value on 64-bit differs slightly to the original # not sure why, but the value on 64-bit differs slightly to the original
if os_bits == '64bit': if os_bits == '64bit':
path = value + r'vc\vcvarsall.bat' path = value + r'vc\vcvarsall.bat'
else: else:
path = value + r'vcvarsall.bat' path = value + r'vcvarsall.bat'
if not os.path.exists(path): if not os.path.exists(path):
raise Exception("'%s' not found." % path) raise Exception("'%s' not found." % path)
return path return path
def run_vcbuild(self, generator, mode, args=''): def run_vcbuild(self, generator, mode, args=''):
import platform import platform
# os_bits should be loaded with '32bit' or '64bit' # os_bits should be loaded with '32bit' or '64bit'
(os_bits, other) = platform.architecture() (os_bits, other) = platform.architecture()
# Now we choose the parameters bases on OS 32/64 and our target 32/64 # Now we choose the parameters bases on OS 32/64 and our target 32/64
# http://msdn.microsoft.com/en-us/library/x4d2c09s%28VS.80%29.aspx # http://msdn.microsoft.com/en-us/library/x4d2c09s%28VS.80%29.aspx
# valid options are only: ia64 amd64 x86_amd64 x86_ia64 # valid options are only: ia64 amd64 x86_amd64 x86_ia64
# but calling vcvarsall.bat does not garantee that it will work # but calling vcvarsall.bat does not garantee that it will work
# ret code from vcvarsall.bat is always 0 so the only way of knowing that I worked is by analysing the text output # ret code from vcvarsall.bat is always 0 so the only way of knowing that I worked is by analysing the text output
@ -1007,7 +992,7 @@ class InternalCommands:
config = 'Release' config = 'Release'
else: else:
config = 'Debug' config = 'Debug'
if generator.startswith('Visual Studio 10'): if generator.startswith('Visual Studio 10'):
cmd = ('@echo off\n' cmd = ('@echo off\n'
'call "%s" %s \n' 'call "%s" %s \n'
@ -1019,7 +1004,7 @@ class InternalCommands:
'call "%s" %s \n' 'call "%s" %s \n'
'vcbuild /nologo %s "%s" "%s"' 'vcbuild /nologo %s "%s" "%s"'
) % (self.get_vcvarsall(generator), vcvars_platform, args, self.sln_filepath(), config) ) % (self.get_vcvarsall(generator), vcvars_platform, args, self.sln_filepath(), config)
# Generate a batch file, since we can't use environment variables directly. # Generate a batch file, since we can't use environment variables directly.
temp_bat = self.getBuildDir() + r'\vcbuild.bat' temp_bat = self.getBuildDir() + r'\vcbuild.bat'
file = open(temp_bat, 'w') file = open(temp_bat, 'w')
@ -1027,7 +1012,7 @@ class InternalCommands:
file.close() file.close()
err = os.system(temp_bat) err = os.system(temp_bat)
if err: if err != 0:
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):
@ -1039,8 +1024,8 @@ class InternalCommands:
r'tool\astyle\AStyle.exe ' r'tool\astyle\AStyle.exe '
'--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: if err != 0:
raise Exception('Reformat failed with error code: ' + str(err)) raise Exception('Reformat failed with error code: ' + str(err))
def printGeneratorList(self): def printGeneratorList(self):
@ -1062,7 +1047,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
@ -1073,14 +1058,14 @@ class CommandHandler:
build_targets = [] build_targets = []
vcRedistDir = '' vcRedistDir = ''
qtDir = '' qtDir = ''
def __init__(self, argv, opts, args, verbose): def __init__(self, argv, opts, args, verbose):
self.ic.verbose = verbose self.ic.verbose = verbose
self.opts = opts self.opts = opts
self.args = args self.args = args
for o, a in self.opts: for o, a in self.opts:
if o == '--no-prompts': if o == '--no-prompts':
self.ic.no_prompts = True self.ic.no_prompts = True
@ -1096,37 +1081,37 @@ class CommandHandler:
self.vcRedistDir = a self.vcRedistDir = a
elif o == '--qt-dir': elif o == '--qt-dir':
self.qtDir = a self.qtDir = a
def about(self): def about(self):
self.ic.about() self.ic.about()
def setup(self): def setup(self):
self.ic.setup() self.ic.setup()
def configure(self): def configure(self):
self.ic.configureAll(self.build_targets) self.ic.configureAll(self.build_targets)
def build(self): def build(self):
self.ic.build(self.build_targets) self.ic.build(self.build_targets)
def clean(self): def clean(self):
self.ic.clean(self.build_targets) self.ic.clean(self.build_targets)
def update(self): def update(self):
self.ic.update() self.ic.update()
def install(self): def install(self):
print 'Not yet implemented: install' print 'Not yet implemented: install'
def doxygen(self): def doxygen(self):
self.ic.doxygen () self.ic.doxygen ()
def dist(self): def dist(self):
type = None type = None
if len(self.args) > 0: if len(self.args) > 0:
type = self.args[0] type = self.args[0]
self.ic.dist(type, self.vcRedistDir, self.qtDir) self.ic.dist(type, self.vcRedistDir, self.qtDir)
def distftp(self): def distftp(self):
@ -1135,10 +1120,10 @@ class CommandHandler:
user = None user = None
password = None password = None
dir = None dir = None
if len(self.args) > 0: if len(self.args) > 0:
type = self.args[0] type = self.args[0]
for o, a in self.opts: for o, a in self.opts:
if o == '--host': if o == '--host':
host = a host = a
@ -1148,32 +1133,32 @@ class CommandHandler:
password = a password = a
elif o == '--dir': elif o == '--dir':
dir = a dir = a
ftp = None ftp = None
if host: if host:
ftp = ftputil.FtpUploader( ftp = ftputil.FtpUploader(
host, user, password, dir) host, user, password, dir)
self.ic.distftp(type, ftp) self.ic.distftp(type, ftp)
def destroy(self): def destroy(self):
self.ic.destroy() self.ic.destroy()
def kill(self): def kill(self):
self.ic.kill() self.ic.kill()
def usage(self): def usage(self):
self.ic.usage() self.ic.usage()
def revision(self): def revision(self):
self.ic.revision() self.ic.revision()
def hammer(self): def hammer(self):
self.ic.hammer() self.ic.hammer()
def reformat(self): def reformat(self):
self.ic.reformat() self.ic.reformat()
def open(self): def open(self):
self.ic.open() self.ic.open()