summaryrefslogtreecommitdiffstats
path: root/support/testing/infra/builder.py
diff options
context:
space:
mode:
Diffstat (limited to 'support/testing/infra/builder.py')
-rw-r--r--support/testing/infra/builder.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/support/testing/infra/builder.py b/support/testing/infra/builder.py
new file mode 100644
index 0000000000..105da01ca2
--- /dev/null
+++ b/support/testing/infra/builder.py
@@ -0,0 +1,49 @@
+import os
+import shutil
+import subprocess
+
+import infra
+
+class Builder(object):
+ def __init__(self, config, builddir, logtofile):
+ self.config = config
+ self.builddir = builddir
+ self.logtofile = logtofile
+
+ def build(self):
+ if not os.path.isdir(self.builddir):
+ os.makedirs(self.builddir)
+
+ log = "{}-build.log".format(self.builddir)
+ if not self.logtofile:
+ log = None
+
+ config_file = os.path.join(self.builddir, ".config")
+ with open(config_file, "w+") as cf:
+ cf.write(self.config)
+
+ cmd = ["make",
+ "O={}".format(self.builddir),
+ "olddefconfig"]
+ with infra.smart_open(log) as log_fh:
+ ret = subprocess.call(cmd, stdout=log_fh, stderr=log_fh)
+ if ret != 0:
+ raise SystemError("Cannot olddefconfig")
+
+ cmd = ["make", "-C", self.builddir]
+ with infra.smart_open(log) as log_fh:
+ ret = subprocess.call(cmd, stdout=log_fh, stderr=log_fh)
+ if ret != 0:
+ raise SystemError("Build failed")
+
+ open(self.stamp_path(), 'a').close()
+
+ def stamp_path(self):
+ return os.path.join(self.builddir, "build-done")
+
+ def is_finished(self):
+ return os.path.exists(self.stamp_path())
+
+ def delete(self):
+ if os.path.exists(self.builddir):
+ shutil.rmtree(self.builddir)
OpenPOWER on IntegriCloud