1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-03 13:49:49 +00:00

bitbake: cache/ConfHandler: Drop TOPDIR/chdir manipulations

This code has been unchanged since 2006 apart from attempts to optimise
performance by minimising chdir() calls.

There is no reason the modern bitbake parser should be changing directory
all the time. We did have some path assumptions in the mists of time but
those were resovled and the code is deterministic and doesn't depend on
cwd now for parsing. We can therefore drop the changes in directory.

Also, TOPDIR is now being set by cookerdata in all cases so we don't
need the fallbacks in this code (which was used to effectively initialise
a value). We don't need to change TOPDIR when parsing a recipe, that makes
no sense. If we stop all the other messing around, we don't need to expand
TMPDIR either.

These changes have the potential to break some obscure use cases such
as an anonymous function assuming the current working directory, or some
case which depends on TOPDIR changing but I believe any such uses should
be fixed at this point.

(Bitbake rev: add5d488e1d6607a98441836075d01cb1dc9c0fa)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2021-11-13 16:19:49 +00:00
parent 119c592530
commit f07a097213
2 changed files with 5 additions and 29 deletions
+4 -25
View File
@@ -284,36 +284,15 @@ def parse_recipe(bb_data, bbfile, appends, mc=''):
Parse a recipe Parse a recipe
""" """
chdir_back = False
bb_data.setVar("__BBMULTICONFIG", mc) bb_data.setVar("__BBMULTICONFIG", mc)
# expand tmpdir to include this topdir
bb_data.setVar('TMPDIR', bb_data.getVar('TMPDIR') or "")
bbfile_loc = os.path.abspath(os.path.dirname(bbfile)) bbfile_loc = os.path.abspath(os.path.dirname(bbfile))
oldpath = os.path.abspath(os.getcwd())
bb.parse.cached_mtime_noerror(bbfile_loc) bb.parse.cached_mtime_noerror(bbfile_loc)
# The ConfHandler first looks if there is a TOPDIR and if not if appends:
# then it would call getcwd(). bb_data.setVar('__BBAPPEND', " ".join(appends))
# Previously, we chdir()ed to bbfile_loc, called the handler bb_data = bb.parse.handle(bbfile, bb_data)
# and finally chdir()ed back, a couple of thousand times. We now return bb_data
# just fill in TOPDIR to point to bbfile_loc if there is no TOPDIR yet.
if not bb_data.getVar('TOPDIR', False):
chdir_back = True
bb_data.setVar('TOPDIR', bbfile_loc)
try:
if appends:
bb_data.setVar('__BBAPPEND', " ".join(appends))
bb_data = bb.parse.handle(bbfile, bb_data)
if chdir_back:
os.chdir(oldpath)
return bb_data
except:
if chdir_back:
os.chdir(oldpath)
raise
class NoCache(object): class NoCache(object):
+1 -4
View File
@@ -48,10 +48,7 @@ __unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
__unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.]+)\]$" ) __unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.]+)\]$" )
def init(data): def init(data):
topdir = data.getVar('TOPDIR', False) return
if not topdir:
data.setVar('TOPDIR', os.getcwd())
def supports(fn, d): def supports(fn, d):
return fn[-5:] == ".conf" return fn[-5:] == ".conf"