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