1#!/usr/bin/python 2 3import getopt 4import subprocess 5import sys 6 7LONG_OPTIONS = ["shard=", "shards="] 8BASE_COMMAND = "./configure --enable-internal-stats --enable-experimental" 9 10def RunCommand(command): 11 run = subprocess.Popen(command, shell=True) 12 output = run.communicate() 13 if run.returncode: 14 print "Non-zero return code: " + str(run.returncode) + " => exiting!" 15 sys.exit(1) 16 17def list_of_experiments(): 18 experiments = [] 19 configure_file = open("configure") 20 list_start = False 21 for line in configure_file.read().split("\n"): 22 if line == 'EXPERIMENT_LIST="': 23 list_start = True 24 elif line == '"': 25 list_start = False 26 elif list_start: 27 currently_broken = ["csm"] 28 experiment = line[4:] 29 if experiment not in currently_broken: 30 experiments.append(experiment) 31 return experiments 32 33def main(argv): 34 # Parse arguments 35 options = {"--shard": 0, "--shards": 1} 36 if "--" in argv: 37 opt_end_index = argv.index("--") 38 else: 39 opt_end_index = len(argv) 40 try: 41 o, _ = getopt.getopt(argv[1:opt_end_index], None, LONG_OPTIONS) 42 except getopt.GetoptError, err: 43 print str(err) 44 print "Usage: %s [--shard=<n> --shards=<n>] -- [configure flag ...]"%argv[0] 45 sys.exit(2) 46 47 options.update(o) 48 extra_args = argv[opt_end_index + 1:] 49 50 # Shard experiment list 51 shard = int(options["--shard"]) 52 shards = int(options["--shards"]) 53 experiments = list_of_experiments() 54 base_command = " ".join([BASE_COMMAND] + extra_args) 55 configs = [base_command] 56 configs += ["%s --enable-%s" % (base_command, e) for e in experiments] 57 my_configs = zip(configs, range(len(configs))) 58 my_configs = filter(lambda x: x[1] % shards == shard, my_configs) 59 my_configs = [e[0] for e in my_configs] 60 61 # Run configs for this shard 62 for config in my_configs: 63 test_build(config) 64 65def test_build(configure_command): 66 print "\033[34m\033[47mTesting %s\033[0m" % (configure_command) 67 RunCommand(configure_command) 68 RunCommand("make clean") 69 RunCommand("make") 70 71if __name__ == "__main__": 72 main(sys.argv) 73