]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - support/testing/infra/builder.py
testing/infra/builder: call make with empty env
[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         env = {"PATH": os.environ["PATH"]}
28         cmd = ["make",
29                "O={}".format(self.builddir),
30                "olddefconfig"]
31         ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile,
32                               env=env)
33         if ret != 0:
34             raise SystemError("Cannot olddefconfig")
35
36         cmd = ["make", "-C", self.builddir]
37         ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile,
38                               env=env)
39         if ret != 0:
40             raise SystemError("Build failed")
41
42         open(self.stamp_path(), 'a').close()
43
44     def stamp_path(self):
45         return os.path.join(self.builddir, "build-done")
46
47     def is_finished(self):
48         return os.path.exists(self.stamp_path())
49
50     def delete(self):
51         if os.path.exists(self.builddir):
52             shutil.rmtree(self.builddir)