Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | # Copyright (C) 2016 Intel Corporation |
| 2 | # Released under the MIT license (see COPYING.MIT) |
| 3 | |
| 4 | import os |
| 5 | import subprocess |
| 6 | |
| 7 | from oeqa.utils.buildproject import BuildProject |
| 8 | |
| 9 | class SDKBuildProject(BuildProject): |
| 10 | def __init__(self, testpath, sdkenv, uri, testlogdir, builddatetime, |
| 11 | foldername=None, dl_dir=None): |
| 12 | self.sdkenv = sdkenv |
| 13 | self.testdir = testpath |
| 14 | self.targetdir = testpath |
| 15 | os.makedirs(testpath, exist_ok=True) |
| 16 | self.datetime = builddatetime |
| 17 | self.testlogdir = testlogdir |
| 18 | os.makedirs(self.testlogdir, exist_ok=True) |
| 19 | self.logfile = os.path.join(self.testlogdir, "sdk_target_log.%s" % self.datetime) |
| 20 | BuildProject.__init__(self, uri, foldername, tmpdir=testpath, dl_dir=dl_dir) |
| 21 | |
| 22 | def download_archive(self): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 23 | self._download_archive() |
| 24 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 25 | cmd = 'tar xf %s -C %s' % (os.path.join(self.targetdir, self.archive), self.targetdir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 26 | subprocess.check_output(cmd, shell=True) |
| 27 | |
| 28 | #Change targetdir to project folder |
| 29 | self.targetdir = os.path.join(self.targetdir, self.fname) |
| 30 | |
| 31 | def run_configure(self, configure_args='', extra_cmds=''): |
| 32 | return super(SDKBuildProject, self).run_configure(configure_args=(configure_args or '$CONFIGURE_FLAGS'), extra_cmds=extra_cmds) |
| 33 | |
| 34 | def run_install(self, install_args=''): |
| 35 | return super(SDKBuildProject, self).run_install(install_args=(install_args or "DESTDIR=%s/../install" % self.targetdir)) |
| 36 | |
| 37 | def log(self, msg): |
| 38 | if self.logfile: |
| 39 | with open(self.logfile, "a") as f: |
| 40 | f.write("%s\n" % msg) |
| 41 | |
| 42 | def _run(self, cmd): |
| 43 | self.log("Running . %s; " % self.sdkenv + cmd) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 44 | try: |
| 45 | output = subprocess.check_output(". %s; " % self.sdkenv + cmd, shell=True, stderr=subprocess.STDOUT) |
| 46 | except subprocess.CalledProcessError as exc: |
| 47 | print(exc.output.decode('utf-8')) |
| 48 | return exc.returncode |
| 49 | return 0 |