Rough merge of master into experimental
[platform/upstream/libvpx.git] / tools / all_builds.py
1 #!/usr/bin/python
2
3 import getopt
4 import subprocess
5 import sys
6
7 LONG_OPTIONS = ["shard=", "shards="]
8 BASE_COMMAND = "./configure --disable-vp8 --disable-unit-tests --enable-internal-stats --enable-experimental"
9
10 def 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
17 def 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
33 def 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
65 def 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
71 if __name__ == "__main__":
72   main(sys.argv)