summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorneliu Stoicescu <corneliux.stoicescu@intel.com>2014-08-09 13:59:08 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-08-18 08:55:54 +0100
commitfec293be3a44b42c2a77f2242d171749a0d47881 (patch)
tree17c35eab4f6375f43bbf4491f44230e595bcccf6
parent2999a7f6845c72d8ddb19ec8d8dfccdc1cb1e23d (diff)
downloadpoky-fec293be3a44b42c2a77f2242d171749a0d47881.tar.gz
oeqa/utils/targetbuild.py: add support for sdk tests
- Create new abstract class BuildProject that provides basic functionality for a project/package building class * contains abstract method _run() that needs to be implemented by all extending classes. - The old TargetBuildProject class now extends the abstract BuildProjct class - Introducing new SDKBuildProject that extends the abstract BuildProjct class NOTE: Original patch made by: Richard Purdie <richard.purdie@linuxfoundation.org> (From OE-Core rev: bc8824fd361dbff96f5b5316ddfda36e96e8ea9b) Signed-off-by: Corneliu Stoicescu <corneliux.stoicescu@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/utils/targetbuild.py94
1 files changed, 79 insertions, 15 deletions
diff --git a/meta/lib/oeqa/utils/targetbuild.py b/meta/lib/oeqa/utils/targetbuild.py
index 32296762c0..eeb08ba716 100644
--- a/meta/lib/oeqa/utils/targetbuild.py
+++ b/meta/lib/oeqa/utils/targetbuild.py
@@ -6,23 +6,25 @@
6 6
7import os 7import os
8import re 8import re
9import bb.utils
9import subprocess 10import subprocess
11from abc import ABCMeta, abstractmethod
10 12
13class BuildProject():
11 14
12class TargetBuildProject(): 15 __metaclass__ = ABCMeta
13 16
14 def __init__(self, target, d, uri, foldername=None): 17 def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"):
15 self.target = target
16 self.d = d 18 self.d = d
17 self.uri = uri 19 self.uri = uri
18 self.targetdir = "~/"
19 self.archive = os.path.basename(uri) 20 self.archive = os.path.basename(uri)
20 self.localarchive = "/tmp/" + self.archive 21 self.localarchive = os.path.join(tmpdir,self.archive)
21 self.fname = re.sub(r'.tar.bz2|tar.gz$', '', self.archive) 22 self.fname = re.sub(r'.tar.bz2|tar.gz$', '', self.archive)
22 if foldername: 23 if foldername:
23 self.fname = foldername 24 self.fname = foldername
24 25
25 def download_archive(self): 26 # Download self.archive to self.localarchive
27 def _download_archive(self):
26 28
27 exportvars = ['HTTP_PROXY', 'http_proxy', 29 exportvars = ['HTTP_PROXY', 'http_proxy',
28 'HTTPS_PROXY', 'https_proxy', 30 'HTTPS_PROXY', 'https_proxy',
@@ -41,6 +43,38 @@ class TargetBuildProject():
41 cmd = cmd + "wget -O %s %s" % (self.localarchive, self.uri) 43 cmd = cmd + "wget -O %s %s" % (self.localarchive, self.uri)
42 subprocess.check_call(cmd, shell=True) 44 subprocess.check_call(cmd, shell=True)
43 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
44 (status, output) = self.target.copy_to(self.localarchive, self.targetdir) 78 (status, output) = self.target.copy_to(self.localarchive, self.targetdir)
45 if status != 0: 79 if status != 0:
46 raise Exception("Failed to copy archive to target, output: %s" % output) 80 raise Exception("Failed to copy archive to target, output: %s" % output)
@@ -54,15 +88,45 @@ class TargetBuildProject():
54 88
55 # The timeout parameter of target.run is set to 0 to make the ssh command 89 # The timeout parameter of target.run is set to 0 to make the ssh command
56 # run with no timeout. 90 # run with no timeout.
57 def run_configure(self): 91 def _run(self, cmd):
58 return self.target.run('cd %s; ./configure' % self.targetdir, 0)[0] 92 return self.target.run(cmd, 0)[0]
59 93
60 def run_make(self):
61 return self.target.run('cd %s; make' % self.targetdir, 0)[0]
62 94
63 def run_install(self): 95class SDKBuildProject(BuildProject):
64 return self.target.run('cd %s; make install' % self.targetdir, 0)[0] 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)
65 132
66 def clean(self):
67 self.target.run('rm -rf %s' % self.targetdir)
68 subprocess.call('rm -f %s' % self.localarchive, shell=True)