1#
2# Copyright (C) 2016 Intel Corporation
3#
4# SPDX-License-Identifier: MIT
5#
6
7import os
8import subprocess
9
10from oeqa.utils.buildproject import BuildProject
11
12class 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):
26        self._download_archive()
27
28        cmd = 'tar xf %s -C %s' % (os.path.join(self.targetdir, self.archive), self.targetdir)
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)
47        try:
48            output = subprocess.check_output(". %s; " % self.sdkenv + cmd, shell=True,
49                                             executable='/bin/bash', stderr=subprocess.STDOUT)
50        except subprocess.CalledProcessError as exc:
51            print(exc.output.decode('utf-8'))
52            return exc.returncode
53        return 0
54