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.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/meta/lib/oeqa/utils/targetbuild.py b/meta/lib/oeqa/utils/targetbuild.py
index 59593f5ef3..09738add1d 100644
--- a/meta/lib/oeqa/utils/targetbuild.py
+++ b/meta/lib/oeqa/utils/targetbuild.py
@@ -1,6 +1,8 @@
+#
# Copyright (C) 2013 Intel Corporation
#
-# Released under the MIT license (see COPYING.MIT)
+# SPDX-License-Identifier: MIT
+#
# Provides a class for automating build tests for projects
@@ -8,15 +10,22 @@ import os
import re
import bb.utils
import subprocess
+import tempfile
from abc import ABCMeta, abstractmethod
class BuildProject(metaclass=ABCMeta):
- def __init__(self, d, uri, foldername=None, tmpdir="/tmp/"):
+ def __init__(self, d, uri, foldername=None, tmpdir=None):
self.d = d
self.uri = uri
self.archive = os.path.basename(uri)
- self.localarchive = os.path.join(tmpdir,self.archive)
+ self.tempdirobj = None
+ if not tmpdir:
+ tmpdir = self.d.getVar('WORKDIR')
+ if not tmpdir:
+ self.tempdirobj = tempfile.TemporaryDirectory(prefix='buildproject-')
+ tmpdir = self.tempdirobj.name
+ self.localarchive = os.path.join(tmpdir, self.archive)
if foldername:
self.fname = foldername
else:
@@ -24,8 +33,7 @@ class BuildProject(metaclass=ABCMeta):
# Download self.archive to self.localarchive
def _download_archive(self):
-
- dl_dir = self.d.getVar("DL_DIR", True)
+ dl_dir = self.d.getVar("DL_DIR")
if dl_dir and os.path.exists(os.path.join(dl_dir, self.archive)):
bb.utils.copyfile(os.path.join(dl_dir, self.archive), self.localarchive)
return
@@ -40,12 +48,12 @@ class BuildProject(metaclass=ABCMeta):
cmd = ''
for var in exportvars:
- val = self.d.getVar(var, True)
+ val = self.d.getVar(var)
if val:
cmd = 'export ' + var + '=\"%s\"; %s' % (val, cmd)
cmd = cmd + "wget -O %s %s" % (self.localarchive, self.uri)
- subprocess.check_call(cmd, shell=True)
+ subprocess.check_output(cmd, shell=True)
# This method should provide a way to run a command in the desired environment.
@abstractmethod
@@ -64,16 +72,17 @@ class BuildProject(metaclass=ABCMeta):
return self._run('cd %s; make install %s' % (self.targetdir, install_args))
def clean(self):
+ if self.tempdirobj:
+ self.tempdirobj.cleanup()
self._run('rm -rf %s' % self.targetdir)
- subprocess.call('rm -f %s' % self.localarchive, shell=True)
- pass
+ subprocess.check_call('rm -f %s' % self.localarchive, shell=True)
class TargetBuildProject(BuildProject):
def __init__(self, target, d, uri, foldername=None):
self.target = target
self.targetdir = "~/"
- BuildProject.__init__(self, d, uri, foldername, tmpdir="/tmp")
+ BuildProject.__init__(self, d, uri, foldername)
def download_archive(self):
@@ -103,8 +112,8 @@ class SDKBuildProject(BuildProject):
self.testdir = testpath
self.targetdir = testpath
bb.utils.mkdirhier(testpath)
- self.datetime = d.getVar('DATETIME', True)
- self.testlogdir = d.getVar("TEST_LOG_DIR", True)
+ self.datetime = d.getVar('DATETIME')
+ self.testlogdir = d.getVar("TEST_LOG_DIR")
bb.utils.mkdirhier(self.testlogdir)
self.logfile = os.path.join(self.testlogdir, "sdk_target_log.%s" % self.datetime)
BuildProject.__init__(self, d, uri, foldername, tmpdir=testpath)
@@ -114,7 +123,7 @@ class SDKBuildProject(BuildProject):
self._download_archive()
cmd = 'tar xf %s%s -C %s' % (self.targetdir, self.archive, self.targetdir)
- subprocess.check_call(cmd, shell=True)
+ subprocess.check_output(cmd, shell=True)
#Change targetdir to project folder
self.targetdir = os.path.join(self.targetdir, self.fname)
@@ -132,4 +141,4 @@ class SDKBuildProject(BuildProject):
def _run(self, cmd):
self.log("Running . %s; " % self.sdkenv + cmd)
- return subprocess.call(". %s; " % self.sdkenv + cmd, shell=True)
+ return subprocess.check_call(". %s; " % self.sdkenv + cmd, shell=True)