diff options
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r-- | meta/lib/oeqa/utils/buildproject.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/buildproject.py b/meta/lib/oeqa/utils/buildproject.py new file mode 100644 index 0000000000..1ed9624a76 --- /dev/null +++ b/meta/lib/oeqa/utils/buildproject.py | |||
@@ -0,0 +1,69 @@ | |||
1 | # Copyright (C) 2013-2016 Intel Corporation | ||
2 | # | ||
3 | # Released under the MIT license (see COPYING.MIT) | ||
4 | |||
5 | # Provides a class for automating build tests for projects | ||
6 | |||
7 | import os | ||
8 | import re | ||
9 | import bb.utils | ||
10 | import subprocess | ||
11 | from abc import ABCMeta, abstractmethod | ||
12 | |||
13 | class BuildProject(metaclass=ABCMeta): | ||
14 | |||
15 | def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"): | ||
16 | self.d = d | ||
17 | self.uri = uri | ||
18 | self.archive = os.path.basename(uri) | ||
19 | self.localarchive = os.path.join(tmpdir,self.archive) | ||
20 | if foldername: | ||
21 | self.fname = foldername | ||
22 | else: | ||
23 | self.fname = re.sub(r'\.tar\.bz2$|\.tar\.gz$|\.tar\.xz$', '', self.archive) | ||
24 | |||
25 | # Download self.archive to self.localarchive | ||
26 | def _download_archive(self): | ||
27 | |||
28 | dl_dir = self.d.getVar("DL_DIR") | ||
29 | if dl_dir and os.path.exists(os.path.join(dl_dir, self.archive)): | ||
30 | bb.utils.copyfile(os.path.join(dl_dir, self.archive), self.localarchive) | ||
31 | return | ||
32 | |||
33 | exportvars = ['HTTP_PROXY', 'http_proxy', | ||
34 | 'HTTPS_PROXY', 'https_proxy', | ||
35 | 'FTP_PROXY', 'ftp_proxy', | ||
36 | 'FTPS_PROXY', 'ftps_proxy', | ||
37 | 'NO_PROXY', 'no_proxy', | ||
38 | 'ALL_PROXY', 'all_proxy', | ||
39 | 'SOCKS5_USER', 'SOCKS5_PASSWD'] | ||
40 | |||
41 | cmd = '' | ||
42 | for var in exportvars: | ||
43 | val = self.d.getVar(var) | ||
44 | if val: | ||
45 | cmd = 'export ' + var + '=\"%s\"; %s' % (val, cmd) | ||
46 | |||
47 | cmd = cmd + "wget -O %s %s" % (self.localarchive, self.uri) | ||
48 | subprocess.check_call(cmd, shell=True) | ||
49 | |||
50 | # This method should provide a way to run a command in the desired environment. | ||
51 | @abstractmethod | ||
52 | def _run(self, cmd): | ||
53 | pass | ||
54 | |||
55 | # The timeout parameter of target.run is set to 0 to make the ssh command | ||
56 | # run with no timeout. | ||
57 | def run_configure(self, configure_args='', extra_cmds=''): | ||
58 | return self._run('cd %s; %s ./configure %s' % (self.targetdir, extra_cmds, configure_args)) | ||
59 | |||
60 | def run_make(self, make_args=''): | ||
61 | return self._run('cd %s; make %s' % (self.targetdir, make_args)) | ||
62 | |||
63 | def run_install(self, install_args=''): | ||
64 | return self._run('cd %s; make install %s' % (self.targetdir, install_args)) | ||
65 | |||
66 | def clean(self): | ||
67 | self._run('rm -rf %s' % self.targetdir) | ||
68 | subprocess.call('rm -f %s' % self.localarchive, shell=True) | ||
69 | pass | ||