xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/runtime/utils/targetbuildproject.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#
2# Copyright (C) 2016 Intel Corporation
3#
4# SPDX-License-Identifier: MIT
5#
6
7from oeqa.utils.buildproject import BuildProject
8
9class TargetBuildProject(BuildProject):
10
11    def __init__(self, target, uri, foldername=None, dl_dir=None):
12        self.target = target
13        self.targetdir = "~/buildtest/"
14        BuildProject.__init__(self, uri, foldername, dl_dir=dl_dir)
15
16    def download_archive(self):
17        self.target.run("mkdir " + self.targetdir + " || true")
18
19        self._download_archive()
20
21        status, output = self.target.copyTo(self.localarchive, self.targetdir)
22        if status:
23            raise Exception('Failed to copy archive to target, '
24                            'output: %s' % output)
25
26        cmd = 'tar xf %s%s -C %s' % (self.targetdir,
27                                     self.archive,
28                                     self.targetdir)
29        status, output = self.target.run(cmd)
30        if status:
31            raise Exception('Failed to extract archive, '
32                            'output: %s' % output)
33
34        # Change targetdir to project folder
35        self.targetdir = self.targetdir + self.fname
36
37    # The timeout parameter of target.run is set to 0
38    # to make the ssh command run with no timeout.
39    def _run(self, cmd):
40        ret = self.target.run(cmd, 0)
41        msg = "Command %s failed with exit code %s: %s" % (cmd, ret[0], ret[1])
42        if ret[0] != 0:
43            raise Exception(msg)
44        return ret[0]
45