summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/targetbuild.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils/targetbuild.py')
-rw-r--r--meta/lib/oeqa/utils/targetbuild.py132
1 files changed, 132 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/targetbuild.py b/meta/lib/oeqa/utils/targetbuild.py
new file mode 100644
index 0000000000..eeb08ba716
--- /dev/null
+++ b/meta/lib/oeqa/utils/targetbuild.py
@@ -0,0 +1,132 @@
1# Copyright (C) 2013 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4
5# Provides a class for automating build tests for projects
6
7import os
8import re
9import bb.utils
10import subprocess
11from abc import ABCMeta, abstractmethod
12
13class BuildProject():
14
15 __metaclass__ = ABCMeta
16
17 def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"):
18 self.d = d
19 self.uri = uri
20 self.archive = os.path.basename(uri)
21 self.localarchive = os.path.join(tmpdir,self.archive)
22 self.fname = re.sub(r'.tar.bz2|tar.gz$', '', self.archive)
23 if foldername:
24 self.fname = foldername
25
26 # Download self.archive to self.localarchive
27 def _download_archive(self):
28
29 exportvars = ['HTTP_PROXY', 'http_proxy',
30 'HTTPS_PROXY', 'https_proxy',
31 'FTP_PROXY', 'ftp_proxy',
32 'FTPS_PROXY', 'ftps_proxy',
33 'NO_PROXY', 'no_proxy',
34 'ALL_PROXY', 'all_proxy',
35 'SOCKS5_USER', 'SOCKS5_PASSWD']
36
37 cmd = ''
38 for var in exportvars:
39 val = self.d.getVar(var, True)
40 if val:
41 cmd = 'export ' + var + '=\"%s\"; %s' % (val, cmd)
42
43 cmd = cmd + "wget -O %s %s" % (self.localarchive, self.uri)
44 subprocess.check_call(cmd, shell=True)
45
46 # This method should provide a way to run a command in the desired environment.
47 @abstractmethod
48 def _run(self, cmd):
49 pass
50
51 # The timeout parameter of target.run is set to 0 to make the ssh command
52 # run with no timeout.
53 def run_configure(self, configure_args=''):
54 return self._run('cd %s; ./configure %s' % (self.targetdir, configure_args))
55
56 def run_make(self, make_args=''):
57 return self._run('cd %s; make %s' % (self.targetdir, make_args))
58
59 def run_install(self, install_args=''):
60 return self._run('cd %s; make install %s' % (self.targetdir, install_args))
61
62 def clean(self):
63 self._run('rm -rf %s' % self.targetdir)
64 subprocess.call('rm -f %s' % self.localarchive, shell=True)
65 pass
66
67class TargetBuildProject(BuildProject):
68
69 def __init__(self, target, d, uri, foldername=None):
70 self.target = target
71 self.targetdir = "~/"
72 BuildProject.__init__(self, d, uri, foldername, tmpdir="/tmp")
73
74 def download_archive(self):
75
76 self._download_archive()
77
78 (status, output) = self.target.copy_to(self.localarchive, self.targetdir)
79 if status != 0:
80 raise Exception("Failed to copy archive to target, output: %s" % output)
81
82 (status, output) = self.target.run('tar xf %s%s -C %s' % (self.targetdir, self.archive, self.targetdir))
83 if status != 0:
84 raise Exception("Failed to extract archive, output: %s" % output)
85
86 #Change targetdir to project folder
87 self.targetdir = self.targetdir + self.fname
88
89 # The timeout parameter of target.run is set to 0 to make the ssh command
90 # run with no timeout.
91 def _run(self, cmd):
92 return self.target.run(cmd, 0)[0]
93
94
95class SDKBuildProject(BuildProject):
96
97 def __init__(self, testpath, sdkenv, d, uri, foldername=None):
98 self.sdkenv = sdkenv
99 self.testdir = testpath
100 self.targetdir = testpath
101 bb.utils.mkdirhier(testpath)
102 self.datetime = d.getVar('DATETIME', True)
103 self.testlogdir = d.getVar("TEST_LOG_DIR", True)
104 bb.utils.mkdirhier(self.testlogdir)
105 self.logfile = os.path.join(self.testlogdir, "sdk_target_log.%s" % self.datetime)
106 BuildProject.__init__(self, d, uri, foldername, tmpdir=testpath)
107
108 def download_archive(self):
109
110 self._download_archive()
111
112 cmd = 'tar xf %s%s -C %s' % (self.targetdir, self.archive, self.targetdir)
113 subprocess.check_call(cmd, shell=True)
114
115 #Change targetdir to project folder
116 self.targetdir = self.targetdir + self.fname
117
118 def run_configure(self, configure_args=''):
119 return super(SDKBuildProject, self).run_configure(configure_args=(configure_args or '$CONFIGURE_FLAGS'))
120
121 def run_install(self, install_args=''):
122 return super(SDKBuildProject, self).run_install(install_args=(install_args or "DESTDIR=%s/../install" % self.targetdir))
123
124 def log(self, msg):
125 if self.logfile:
126 with open(self.logfile, "a") as f:
127 f.write("%s\n" % msg)
128
129 def _run(self, cmd):
130 self.log("Running source %s; " % self.sdkenv + cmd)
131 return subprocess.call("source %s; " % self.sdkenv + cmd, shell=True)
132