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