]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - support/testing/infra/builder.py
testing/infra/builder: dump defconfig to log
[coffee/buildroot.git] / support / testing / infra / builder.py
1 import os
2 import shutil
3 import subprocess
4
5 import infra
6
7 class Builder(object):
8     def __init__(self, config, builddir, logtofile):
9         self.config = config
10         self.builddir = builddir
11         self.logfile = infra.open_log_file(builddir, "build", logtofile)
12
13     def build(self):
14         if not os.path.isdir(self.builddir):
15             os.makedirs(self.builddir)
16
17         config_file = os.path.join(self.builddir, ".config")
18         with open(config_file, "w+") as cf:
19             cf.write(self.config)
20         # dump the defconfig to the logfile for easy debugging
21         self.logfile.write("> start defconfig\n" + self.config +
22                            "> end defconfig\n")
23         self.logfile.flush()
24
25         cmd = ["make",
26                "O={}".format(self.builddir),
27                "olddefconfig"]
28         ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile)
29         if ret != 0:
30             raise SystemError("Cannot olddefconfig")
31
32         cmd = ["make", "-C", self.builddir]
33         ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile)
34         if ret != 0:
35             raise SystemError("Build failed")
36
37         open(self.stamp_path(), 'a').close()
38
39     def stamp_path(self):
40         return os.path.join(self.builddir, "build-done")
41
42     def is_finished(self):
43         return os.path.exists(self.stamp_path())
44
45     def delete(self):
46         if os.path.exists(self.builddir):
47             shutil.rmtree(self.builddir)