summaryrefslogtreecommitdiffstats
path: root/scripts/lib/scriptutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/scriptutils.py')
-rw-r--r--scripts/lib/scriptutils.py40
1 files changed, 17 insertions, 23 deletions
diff --git a/scripts/lib/scriptutils.py b/scripts/lib/scriptutils.py
index 3164171eb2..32e749dbb1 100644
--- a/scripts/lib/scriptutils.py
+++ b/scripts/lib/scriptutils.py
@@ -5,7 +5,6 @@
5# SPDX-License-Identifier: GPL-2.0-only 5# SPDX-License-Identifier: GPL-2.0-only
6# 6#
7 7
8import argparse
9import glob 8import glob
10import logging 9import logging
11import os 10import os
@@ -18,13 +17,14 @@ import sys
18import tempfile 17import tempfile
19import threading 18import threading
20import importlib 19import importlib
21from importlib import machinery 20import importlib.machinery
21import importlib.util
22 22
23class KeepAliveStreamHandler(logging.StreamHandler): 23class KeepAliveStreamHandler(logging.StreamHandler):
24 def __init__(self, keepalive=True, **kwargs): 24 def __init__(self, keepalive=True, **kwargs):
25 super().__init__(**kwargs) 25 super().__init__(**kwargs)
26 if keepalive is True: 26 if keepalive is True:
27 keepalive = 5000 # default timeout 27 keepalive = 5000 # default timeout
28 self._timeout = threading.Condition() 28 self._timeout = threading.Condition()
29 self._stop = False 29 self._stop = False
30 30
@@ -35,9 +35,9 @@ class KeepAliveStreamHandler(logging.StreamHandler):
35 with self._timeout: 35 with self._timeout:
36 if not self._timeout.wait(keepalive): 36 if not self._timeout.wait(keepalive):
37 self.emit(logging.LogRecord("keepalive", logging.INFO, 37 self.emit(logging.LogRecord("keepalive", logging.INFO,
38 None, None, "Keepalive message", None, None)) 38 None, None, "Keepalive message", None, None))
39 39
40 self._thread = threading.Thread(target = thread, daemon = True) 40 self._thread = threading.Thread(target=thread, daemon=True)
41 self._thread.start() 41 self._thread.start()
42 42
43 def close(self): 43 def close(self):
@@ -71,18 +71,19 @@ def logger_setup_color(logger, color='auto'):
71 71
72 for handler in logger.handlers: 72 for handler in logger.handlers:
73 if (isinstance(handler, logging.StreamHandler) and 73 if (isinstance(handler, logging.StreamHandler) and
74 isinstance(handler.formatter, BBLogFormatter)): 74 isinstance(handler.formatter, BBLogFormatter)):
75 if color == 'always' or (color == 'auto' and handler.stream.isatty()): 75 if color == 'always' or (color == 'auto' and handler.stream.isatty()):
76 handler.formatter.enable_color() 76 handler.formatter.enable_color()
77 77
78 78
79def load_plugins(logger, plugins, pluginpath): 79def load_plugins(logger, plugins, pluginpath):
80
81 def load_plugin(name): 80 def load_plugin(name):
82 logger.debug('Loading plugin %s' % name) 81 logger.debug('Loading plugin %s' % name)
83 spec = importlib.machinery.PathFinder.find_spec(name, path=[pluginpath] ) 82 spec = importlib.machinery.PathFinder.find_spec(name, path=[pluginpath])
84 if spec: 83 if spec:
85 return spec.loader.load_module() 84 mod = importlib.util.module_from_spec(spec)
85 spec.loader.exec_module(mod)
86 return mod
86 87
87 def plugin_name(filename): 88 def plugin_name(filename):
88 return os.path.splitext(os.path.basename(filename))[0] 89 return os.path.splitext(os.path.basename(filename))[0]
@@ -176,9 +177,15 @@ def fetch_url(tinfoil, srcuri, srcrev, destdir, logger, preserve_tmp=False, mirr
176 f.write('BB_STRICT_CHECKSUM = "ignore"\n') 177 f.write('BB_STRICT_CHECKSUM = "ignore"\n')
177 f.write('SRC_URI = "%s"\n' % srcuri) 178 f.write('SRC_URI = "%s"\n' % srcuri)
178 f.write('SRCREV = "%s"\n' % srcrev) 179 f.write('SRCREV = "%s"\n' % srcrev)
180 f.write('PV = "0.0+"\n')
179 f.write('WORKDIR = "%s"\n' % tmpworkdir) 181 f.write('WORKDIR = "%s"\n' % tmpworkdir)
182 f.write('UNPACKDIR = "%s"\n' % destdir)
183
180 # Set S out of the way so it doesn't get created under the workdir 184 # Set S out of the way so it doesn't get created under the workdir
181 f.write('S = "%s"\n' % os.path.join(tmpdir, 'emptysrc')) 185 s_dir = os.path.join(tmpdir, 'emptysrc')
186 bb.utils.mkdirhier(s_dir)
187 f.write('S = "%s"\n' % s_dir)
188
182 if not mirrors: 189 if not mirrors:
183 # We do not need PREMIRRORS since we are almost certainly 190 # We do not need PREMIRRORS since we are almost certainly
184 # fetching new source rather than something that has already 191 # fetching new source rather than something that has already
@@ -230,10 +237,6 @@ def fetch_url(tinfoil, srcuri, srcrev, destdir, logger, preserve_tmp=False, mirr
230 if e.errno != errno.ENOTEMPTY: 237 if e.errno != errno.ENOTEMPTY:
231 raise 238 raise
232 239
233 bb.utils.mkdirhier(destdir)
234 for fn in os.listdir(tmpworkdir):
235 shutil.move(os.path.join(tmpworkdir, fn), destdir)
236
237 finally: 240 finally:
238 if not preserve_tmp: 241 if not preserve_tmp:
239 shutil.rmtree(tmpdir) 242 shutil.rmtree(tmpdir)
@@ -269,12 +272,3 @@ def is_src_url(param):
269 return True 272 return True
270 return False 273 return False
271 274
272def filter_src_subdirs(pth):
273 """
274 Filter out subdirectories of initial unpacked source trees that we do not care about.
275 Used by devtool and recipetool.
276 """
277 dirlist = os.listdir(pth)
278 filterout = ['git.indirectionsymlink', 'source-date-epoch']
279 dirlist = [x for x in dirlist if x not in filterout]
280 return dirlist