all_builds.py 2.0 KB

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