Added a hammer command for buildbot.

This commit is contained in:
Nick Bolton 2009-11-02 21:17:45 +00:00
parent d85c266aa0
commit 075043a877
2 changed files with 75 additions and 29 deletions

View File

@ -1,2 +1,3 @@
@echo off @echo off
python hm.py %* python hm.py %*
exit /b %errorlevel%

103
hm.py
View File

@ -49,6 +49,7 @@ commands = [
'usage', 'usage',
'revision', 'revision',
'help', 'help',
'hammer',
'--help', '--help',
'-h', '-h',
'/?' '/?'
@ -96,9 +97,14 @@ sln_filename = '%s.sln' % project
xcodeproj_filename = '%s.xcodeproj' % project xcodeproj_filename = '%s.xcodeproj' % project
config_filename = '%s.cfg' % this_cmd config_filename = '%s.cfg' % this_cmd
config_filepath = '%s/%s' % (bin_dir, config_filename) def config_filepath():
sln_filepath = '%s\%s' % (bin_dir, sln_filename) return '%s/%s' % (bin_dir, config_filename)
xcodeproj_filepath= '%s/%s' % (bin_dir, xcodeproj_filename)
def sln_filepath():
return '%s\%s' % (bin_dir, sln_filename)
def xcodeproj_filepath():
return '%s/%s' % (bin_dir, xcodeproj_filename)
# try_chdir(...) and restore_chdir() will use this # try_chdir(...) and restore_chdir() will use this
prevdir = '' prevdir = ''
@ -119,6 +125,7 @@ def usage():
' revision Display the current source code revision\n' ' revision Display the current source code revision\n'
' package Create a distribution package (e.g. tar.gz)\n' ' package Create a distribution package (e.g. tar.gz)\n'
' install Installs the program\n' ' install Installs the program\n'
' hammer Golden hammer (config, build, package)\n'
' usage Shows the help screen\n' ' usage Shows the help screen\n'
'\n' '\n'
'Alias commands:\n' 'Alias commands:\n'
@ -266,10 +273,10 @@ def clean(mode):
def open_project(): def open_project():
generator = get_generator() generator = get_generator()
if generator.startswith('Visual Studio'): if generator.startswith('Visual Studio'):
open_project_internal(sln_filepath) open_project_internal(sln_filepath())
return True return True
elif generator.startswith('Xcode'): elif generator.startswith('Xcode'):
open_project_internal(xcodeproj_filepath, 'open') open_project_internal(xcodeproj_filepath(), 'open')
return True return True
else: else:
print 'Not supported with generator:',generator print 'Not supported with generator:',generator
@ -301,14 +308,9 @@ def package(type):
if type == None: if type == None:
package_usage() package_usage()
elif type == 'src-tgz': elif type == 'src':
if sys.platform in ['linux2', 'darwin']: if sys.platform in ['linux2', 'darwin']:
package_src() package_tgz()
else:
package_unsupported = True
elif type == 'src-zip':
if sys.platform == 'win32':
package_src()
else: else:
package_unsupported = True package_unsupported = True
elif type == 'rpm': elif type == 'rpm':
@ -338,8 +340,7 @@ def package(type):
print ('Package type, %s is not ' print ('Package type, %s is not '
'supported for platform, %s') % (type, sys.platform) 'supported for platform, %s') % (type, sys.platform)
def package_src(): def package_tgz():
# Enter the temp build dir, to preserve source tree.
try_chdir(bin_dir) try_chdir(bin_dir)
os.system('make package_source') os.system('make package_source')
restore_chdir() restore_chdir()
@ -368,12 +369,11 @@ def package_usage():
print ('Usage: %s package [package-type]\n' print ('Usage: %s package [package-type]\n'
'\n' '\n'
'Replace [package-type] with one of:\n' 'Replace [package-type] with one of:\n'
' src-tgz Create a .tar.gz source distribution\n' ' src .tar.gz source (Posix only)\n'
' src-zip Create a .zip source distribution\n' ' rpm .rpm package (Red Hat)\n'
' rpm Create a .rpm package (Red Hat)\n' ' deb .deb paclage (Debian)\n'
' deb Create a .deb paclage (Debian)\n' ' win .exe installer (Windows)\n'
' win Create a .exe installer (Windows)\n' ' mac .dmg package (Mac OS X)\n'
' mac Create a .dmg package (Mac OS X)\n'
'\n' '\n'
'Example: %s package src-tgz') % (this_cmd, this_cmd) 'Example: %s package src-tgz') % (this_cmd, this_cmd)
@ -442,6 +442,8 @@ def main(argv):
destroy() destroy()
elif cmd in ['setup']: elif cmd in ['setup']:
setup() setup()
elif cmd in ['hammer']:
hammer()
else: else:
print 'Command not yet implemented:',cmd print 'Command not yet implemented:',cmd
@ -504,9 +506,9 @@ def setup(generator = None):
if not os.path.exists(bin_dir): if not os.path.exists(bin_dir):
os.mkdir(bin_dir) os.mkdir(bin_dir)
if os.path.exists(config_filepath): if os.path.exists(config_filepath()):
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
config.read(config_filepath) config.read(config_filepath())
else: else:
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
@ -529,18 +531,18 @@ def setup(generator = None):
print "\nSetup complete." print "\nSetup complete."
def write_config(config): def write_config(config):
configfile = open(config_filepath, 'wb') configfile = open(config_filepath(), 'wb')
config.write(configfile) config.write(configfile)
def get_generator(): def get_generator():
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
config.read(config_filepath) config.read(config_filepath())
return config.get('cmake', 'generator') return config.get('cmake', 'generator')
def has_setup_version(version): def has_setup_version(version):
if os.path.exists(config_filepath): if os.path.exists(config_filepath()):
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
config.read(config_filepath) config.read(config_filepath())
try: try:
return config.getint('hm', 'setup_version') >= version return config.getint('hm', 'setup_version') >= version
@ -552,7 +554,7 @@ def has_setup_version(version):
def has_conf_run(): def has_conf_run():
if has_setup_version(2): if has_setup_version(2):
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
config.read(config_filepath) config.read(config_filepath())
try: try:
return config.getboolean('hm', 'has_conf_run') return config.getboolean('hm', 'has_conf_run')
except: except:
@ -563,7 +565,7 @@ def has_conf_run():
def set_conf_run(): def set_conf_run():
if has_setup_version(3): if has_setup_version(3):
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
config.read(config_filepath) config.read(config_filepath())
config.set('hm', 'has_conf_run', True) config.set('hm', 'has_conf_run', True)
write_config(config) write_config(config)
else: else:
@ -654,7 +656,7 @@ def run_vcbuild(generator, mode, args=''):
cmd = ('@echo off\n' cmd = ('@echo off\n'
'call "%s" %s \n' 'call "%s" %s \n'
'vcbuild /nologo %s "%s" "%s"' 'vcbuild /nologo %s "%s" "%s"'
) % (get_vcvarsall(generator), vcvars_platform, args, sln_filepath, config) ) % (get_vcvarsall(generator), vcvars_platform, args, sln_filepath(), config)
print cmd print cmd
# 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 = bin_dir + r'\vcbuild.bat' temp_bat = bin_dir + r'\vcbuild.bat'
@ -668,5 +670,48 @@ def ensure_setup_latest(generator = None):
if not has_setup_version(setup_version): if not has_setup_version(setup_version):
setup(generator) setup(generator)
class HammerBuild:
generator = None
target_dir = None
def __init__(self, _generator, _target_dir):
self.generator = _generator
self.target_dir = _target_dir
def run(self):
global bin_dir
bin_dir = self.target_dir
configure(self.generator)
build('debug')
build('release')
def hammer():
hammer_builds = []
if sys.platform == 'win32':
hammer_builds += [
HammerBuild('Visual Studio 9 2008', 'bin32'),
HammerBuild('Visual Studio 9 2008 Win64', 'bin64')]
elif sys.platform in ['linux2', 'sunos5', 'freebsd7']:
hammer_builds += [
HammerBuild('Unix Makefiles', 'bin')]
elif sys.platform == 'darwin':
hammer_builds += [
HammerBuild('Xcode', 'bin')]
for hb in hammer_builds:
hb.run()
package_types = []
if sys.platform == 'win32':
package_types += ['win']
elif sys.platform == 'linux2':
package_types += ['src', 'rpm', 'deb']
elif sys.platform == 'darwin':
package_types += ['mac']
for pt in package_types:
package(pt)
# Start the program. # Start the program.
main(sys.argv) main(sys.argv)