summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py52
1 files changed, 38 insertions, 14 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 5f5767c1da..34fa0b7a67 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -16,7 +16,8 @@ import bb.msg
16import multiprocessing 16import multiprocessing
17import fcntl 17import fcntl
18import importlib 18import importlib
19from importlib import machinery 19import importlib.machinery
20import importlib.util
20import itertools 21import itertools
21import subprocess 22import subprocess
22import glob 23import glob
@@ -420,12 +421,14 @@ def better_eval(source, locals, extraglobals = None):
420 return eval(source, ctx, locals) 421 return eval(source, ctx, locals)
421 422
422@contextmanager 423@contextmanager
423def fileslocked(files): 424def fileslocked(files, *args, **kwargs):
424 """Context manager for locking and unlocking file locks.""" 425 """Context manager for locking and unlocking file locks."""
425 locks = [] 426 locks = []
426 if files: 427 if files:
427 for lockfile in files: 428 for lockfile in files:
428 locks.append(bb.utils.lockfile(lockfile)) 429 l = bb.utils.lockfile(lockfile, *args, **kwargs)
430 if l is not None:
431 locks.append(l)
429 432
430 try: 433 try:
431 yield 434 yield
@@ -458,9 +461,16 @@ def lockfile(name, shared=False, retry=True, block=False):
458 consider the possibility of sending a signal to the process to break 461 consider the possibility of sending a signal to the process to break
459 out - at which point you want block=True rather than retry=True. 462 out - at which point you want block=True rather than retry=True.
460 """ 463 """
464 basename = os.path.basename(name)
465 if len(basename) > 255:
466 root, ext = os.path.splitext(basename)
467 basename = root[:255 - len(ext)] + ext
468
461 dirname = os.path.dirname(name) 469 dirname = os.path.dirname(name)
462 mkdirhier(dirname) 470 mkdirhier(dirname)
463 471
472 name = os.path.join(dirname, basename)
473
464 if not os.access(dirname, os.W_OK): 474 if not os.access(dirname, os.W_OK):
465 logger.error("Unable to acquire lock '%s', directory is not writable", 475 logger.error("Unable to acquire lock '%s', directory is not writable",
466 name) 476 name)
@@ -494,7 +504,7 @@ def lockfile(name, shared=False, retry=True, block=False):
494 return lf 504 return lf
495 lf.close() 505 lf.close()
496 except OSError as e: 506 except OSError as e:
497 if e.errno == errno.EACCES: 507 if e.errno == errno.EACCES or e.errno == errno.ENAMETOOLONG:
498 logger.error("Unable to acquire lock '%s', %s", 508 logger.error("Unable to acquire lock '%s', %s",
499 e.strerror, name) 509 e.strerror, name)
500 sys.exit(1) 510 sys.exit(1)
@@ -959,6 +969,17 @@ def which(path, item, direction = 0, history = False, executable=False):
959 return "", hist 969 return "", hist
960 return "" 970 return ""
961 971
972@contextmanager
973def umask(new_mask):
974 """
975 Context manager to set the umask to a specific mask, and restore it afterwards.
976 """
977 current_mask = os.umask(new_mask)
978 try:
979 yield
980 finally:
981 os.umask(current_mask)
982
962def to_boolean(string, default=None): 983def to_boolean(string, default=None):
963 if not string: 984 if not string:
964 return default 985 return default
@@ -1560,21 +1581,22 @@ def set_process_name(name):
1560 1581
1561# export common proxies variables from datastore to environment 1582# export common proxies variables from datastore to environment
1562def export_proxies(d): 1583def export_proxies(d):
1563 import os 1584 """ export common proxies variables from datastore to environment """
1564 1585
1565 variables = ['http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY', 1586 variables = ['http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY',
1566 'ftp_proxy', 'FTP_PROXY', 'no_proxy', 'NO_PROXY', 1587 'ftp_proxy', 'FTP_PROXY', 'no_proxy', 'NO_PROXY',
1567 'GIT_PROXY_COMMAND'] 1588 'GIT_PROXY_COMMAND', 'SSL_CERT_FILE', 'SSL_CERT_DIR']
1568 exported = False 1589 exported = False
1569 1590
1570 for v in variables: 1591 origenv = d.getVar("BB_ORIGENV")
1571 if v in os.environ.keys(): 1592
1593 for name in variables:
1594 value = d.getVar(name)
1595 if not value and origenv:
1596 value = origenv.getVar(name)
1597 if value:
1598 os.environ[name] = value
1572 exported = True 1599 exported = True
1573 else:
1574 v_proxy = d.getVar(v)
1575 if v_proxy is not None:
1576 os.environ[v] = v_proxy
1577 exported = True
1578 1600
1579 return exported 1601 return exported
1580 1602
@@ -1584,7 +1606,9 @@ def load_plugins(logger, plugins, pluginpath):
1584 logger.debug(1, 'Loading plugin %s' % name) 1606 logger.debug(1, 'Loading plugin %s' % name)
1585 spec = importlib.machinery.PathFinder.find_spec(name, path=[pluginpath] ) 1607 spec = importlib.machinery.PathFinder.find_spec(name, path=[pluginpath] )
1586 if spec: 1608 if spec:
1587 return spec.loader.load_module() 1609 mod = importlib.util.module_from_spec(spec)
1610 spec.loader.exec_module(mod)
1611 return mod
1588 1612
1589 logger.debug(1, 'Loading plugins from %s...' % pluginpath) 1613 logger.debug(1, 'Loading plugins from %s...' % pluginpath)
1590 1614