all_builds.py 2 KB
Newer Older
1 2
#!/usr/bin/python

3
import getopt
4 5 6
import subprocess
import sys

7
LONG_OPTIONS = ["shard=", "shards="]
8
BASE_COMMAND = "./configure --enable-internal-stats --enable-experimental"
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
def RunCommand(command):
  run = subprocess.Popen(command, shell=True)
  output = run.communicate()
  if run.returncode:
    print "Non-zero return code: " + str(run.returncode) + " => exiting!"
    sys.exit(1)

def list_of_experiments():
  experiments = []
  configure_file = open("configure")
  list_start = False
  for line in configure_file.read().split("\n"):
    if line == 'EXPERIMENT_LIST="':
      list_start = True
    elif line == '"':
      list_start = False
    elif list_start:
      currently_broken = ["csm"]
      experiment = line[4:]
      if experiment not in currently_broken:
        experiments.append(experiment)
  return experiments

33 34 35
def main(argv):
  # Parse arguments
  options = {"--shard": 0, "--shards": 1}
36 37 38 39 40 41 42 43 44 45 46
  if "--" in argv:
    opt_end_index = argv.index("--")
  else:
    opt_end_index = len(argv)
  try:
    o, _ = getopt.getopt(argv[1:opt_end_index], None, LONG_OPTIONS)
  except getopt.GetoptError, err:
    print str(err)
    print "Usage: %s [--shard=<n> --shards=<n>] -- [configure flag ...]"%argv[0]
    sys.exit(2)

47
  options.update(o)
48
  extra_args = argv[opt_end_index + 1:]
49 50 51 52 53

  # Shard experiment list
  shard = int(options["--shard"])
  shards = int(options["--shards"])
  experiments = list_of_experiments()
54 55 56
  base_command = " ".join([BASE_COMMAND] + extra_args)
  configs = [base_command]
  configs += ["%s --enable-%s" % (base_command, e) for e in experiments]
57 58 59 60 61 62 63
  my_configs = zip(configs, range(len(configs)))
  my_configs = filter(lambda x: x[1] % shards == shard, my_configs)
  my_configs = [e[0] for e in my_configs]

  # Run configs for this shard
  for config in my_configs:
    test_build(config)
64 65 66 67 68 69 70 71

def test_build(configure_command):
  print "\033[34m\033[47mTesting %s\033[0m" % (configure_command)
  RunCommand(configure_command)
  RunCommand("make clean")
  RunCommand("make")

if __name__ == "__main__":
72
  main(sys.argv)