From 075043a8778638e7e0d54e9a5f981019674d2663 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 2 Nov 2009 21:17:45 +0000 Subject: [PATCH] Added a hammer command for buildbot. --- hm.bat => hm.cmd | 1 + hm.py | 103 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 75 insertions(+), 29 deletions(-) rename hm.bat => hm.cmd (56%) diff --git a/hm.bat b/hm.cmd similarity index 56% rename from hm.bat rename to hm.cmd index a1351647..60596e2a 100644 --- a/hm.bat +++ b/hm.cmd @@ -1,2 +1,3 @@ @echo off python hm.py %* +exit /b %errorlevel% \ No newline at end of file diff --git a/hm.py b/hm.py index be377af2..43c496e9 100644 --- a/hm.py +++ b/hm.py @@ -49,6 +49,7 @@ commands = [ 'usage', 'revision', 'help', + 'hammer', '--help', '-h', '/?' @@ -96,9 +97,14 @@ sln_filename = '%s.sln' % project xcodeproj_filename = '%s.xcodeproj' % project config_filename = '%s.cfg' % this_cmd -config_filepath = '%s/%s' % (bin_dir, config_filename) -sln_filepath = '%s\%s' % (bin_dir, sln_filename) -xcodeproj_filepath= '%s/%s' % (bin_dir, xcodeproj_filename) +def config_filepath(): + return '%s/%s' % (bin_dir, config_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 prevdir = '' @@ -119,6 +125,7 @@ def usage(): ' revision Display the current source code revision\n' ' package Create a distribution package (e.g. tar.gz)\n' ' install Installs the program\n' + ' hammer Golden hammer (config, build, package)\n' ' usage Shows the help screen\n' '\n' 'Alias commands:\n' @@ -266,10 +273,10 @@ def clean(mode): def open_project(): generator = get_generator() if generator.startswith('Visual Studio'): - open_project_internal(sln_filepath) + open_project_internal(sln_filepath()) return True elif generator.startswith('Xcode'): - open_project_internal(xcodeproj_filepath, 'open') + open_project_internal(xcodeproj_filepath(), 'open') return True else: print 'Not supported with generator:',generator @@ -301,14 +308,9 @@ def package(type): if type == None: package_usage() - elif type == 'src-tgz': + elif type == 'src': if sys.platform in ['linux2', 'darwin']: - package_src() - else: - package_unsupported = True - elif type == 'src-zip': - if sys.platform == 'win32': - package_src() + package_tgz() else: package_unsupported = True elif type == 'rpm': @@ -338,8 +340,7 @@ def package(type): print ('Package type, %s is not ' 'supported for platform, %s') % (type, sys.platform) -def package_src(): - # Enter the temp build dir, to preserve source tree. +def package_tgz(): try_chdir(bin_dir) os.system('make package_source') restore_chdir() @@ -368,12 +369,11 @@ def package_usage(): print ('Usage: %s package [package-type]\n' '\n' 'Replace [package-type] with one of:\n' - ' src-tgz Create a .tar.gz source distribution\n' - ' src-zip Create a .zip source distribution\n' - ' rpm Create a .rpm package (Red Hat)\n' - ' deb Create a .deb paclage (Debian)\n' - ' win Create a .exe installer (Windows)\n' - ' mac Create a .dmg package (Mac OS X)\n' + ' src .tar.gz source (Posix only)\n' + ' rpm .rpm package (Red Hat)\n' + ' deb .deb paclage (Debian)\n' + ' win .exe installer (Windows)\n' + ' mac .dmg package (Mac OS X)\n' '\n' 'Example: %s package src-tgz') % (this_cmd, this_cmd) @@ -442,6 +442,8 @@ def main(argv): destroy() elif cmd in ['setup']: setup() + elif cmd in ['hammer']: + hammer() else: print 'Command not yet implemented:',cmd @@ -504,9 +506,9 @@ def setup(generator = None): if not os.path.exists(bin_dir): os.mkdir(bin_dir) - if os.path.exists(config_filepath): + if os.path.exists(config_filepath()): config = ConfigParser.ConfigParser() - config.read(config_filepath) + config.read(config_filepath()) else: config = ConfigParser.ConfigParser() @@ -529,18 +531,18 @@ def setup(generator = None): print "\nSetup complete." def write_config(config): - configfile = open(config_filepath, 'wb') + configfile = open(config_filepath(), 'wb') config.write(configfile) def get_generator(): config = ConfigParser.RawConfigParser() - config.read(config_filepath) + config.read(config_filepath()) return config.get('cmake', 'generator') def has_setup_version(version): - if os.path.exists(config_filepath): + if os.path.exists(config_filepath()): config = ConfigParser.RawConfigParser() - config.read(config_filepath) + config.read(config_filepath()) try: return config.getint('hm', 'setup_version') >= version @@ -552,7 +554,7 @@ def has_setup_version(version): def has_conf_run(): if has_setup_version(2): config = ConfigParser.RawConfigParser() - config.read(config_filepath) + config.read(config_filepath()) try: return config.getboolean('hm', 'has_conf_run') except: @@ -563,7 +565,7 @@ def has_conf_run(): def set_conf_run(): if has_setup_version(3): config = ConfigParser.RawConfigParser() - config.read(config_filepath) + config.read(config_filepath()) config.set('hm', 'has_conf_run', True) write_config(config) else: @@ -654,7 +656,7 @@ def run_vcbuild(generator, mode, args=''): cmd = ('@echo off\n' 'call "%s" %s \n' '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 # Generate a batch file, since we can't use environment variables directly. temp_bat = bin_dir + r'\vcbuild.bat' @@ -668,5 +670,48 @@ def ensure_setup_latest(generator = None): if not has_setup_version(setup_version): 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. main(sys.argv)