classes/lib/scripts: Use bb.utils.rename() instead of os.rename()

Incremental build in Docker fails with:

OSError: [Errno 18] Invalid cross-device link

when source and destination are on different overlay filesystems.

Rather than adding fallback code to every call site, use a new wrapper
in bitbake which detects this case and falls back to shutil.move
which is slower but will handtle the overlay docker filesystems correctly.

[YOCTO #14301]

(From OE-Core rev: 656a65b2b84e7d529b89cf5de7eb838f902d84a2)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Devendra Tewari 2021-04-19 11:23:58 -03:00 committed by Richard Purdie
parent 974441aeda
commit b71375304f
14 changed files with 30 additions and 29 deletions

View File

@ -875,7 +875,7 @@ python buildhistory_eventhandler() {
entries = [ x for x in os.listdir(rootdir) if not x.startswith('.') ] entries = [ x for x in os.listdir(rootdir) if not x.startswith('.') ]
bb.utils.mkdirhier(olddir) bb.utils.mkdirhier(olddir)
for entry in entries: for entry in entries:
os.rename(os.path.join(rootdir, entry), bb.utils.rename(os.path.join(rootdir, entry),
os.path.join(olddir, entry)) os.path.join(olddir, entry))
elif isinstance(e, bb.event.BuildCompleted): elif isinstance(e, bb.event.BuildCompleted):
if reset: if reset:

View File

@ -1049,7 +1049,7 @@ python fixup_perms () {
# Create path to move directory to, move it, and then setup the symlink # Create path to move directory to, move it, and then setup the symlink
bb.utils.mkdirhier(os.path.dirname(target)) bb.utils.mkdirhier(os.path.dirname(target))
#bb.note("Fixup Perms: Rename %s -> %s" % (dir, ptarget)) #bb.note("Fixup Perms: Rename %s -> %s" % (dir, ptarget))
os.rename(origin, target) bb.utils.rename(origin, target)
#bb.note("Fixup Perms: Link %s -> %s" % (dir, link)) #bb.note("Fixup Perms: Link %s -> %s" % (dir, link))
os.symlink(link, origin) os.symlink(link, origin)
@ -1967,7 +1967,7 @@ python package_do_shlibs() {
for (old, new) in renames: for (old, new) in renames:
bb.note("Renaming %s to %s" % (old, new)) bb.note("Renaming %s to %s" % (old, new))
os.rename(old, new) bb.utils.rename(old, new)
pkgfiles[pkg].remove(old) pkgfiles[pkg].remove(old)
shlibs_file = os.path.join(shlibswork_dir, pkg + ".list") shlibs_file = os.path.join(shlibswork_dir, pkg + ".list")

View File

@ -165,7 +165,7 @@ def create_filtered_tasklist(d, sdkbasepath, tasklistfile, conf_initpath):
shutil.rmtree(temp_sdkbasepath) shutil.rmtree(temp_sdkbasepath)
except FileNotFoundError: except FileNotFoundError:
pass pass
os.rename(sdkbasepath, temp_sdkbasepath) bb.utils.rename(sdkbasepath, temp_sdkbasepath)
cmdprefix = '. %s .; ' % conf_initpath cmdprefix = '. %s .; ' % conf_initpath
logfile = d.getVar('WORKDIR') + '/tasklist_bb_log.txt' logfile = d.getVar('WORKDIR') + '/tasklist_bb_log.txt'
try: try:
@ -175,7 +175,7 @@ def create_filtered_tasklist(d, sdkbasepath, tasklistfile, conf_initpath):
if 'attempted to execute unexpectedly and should have been setscened' in e.stdout: if 'attempted to execute unexpectedly and should have been setscened' in e.stdout:
msg += '\n----------\n\nNOTE: "attempted to execute unexpectedly and should have been setscened" errors indicate this may be caused by missing sstate artifacts that were likely produced in earlier builds, but have been subsequently deleted for some reason.\n' msg += '\n----------\n\nNOTE: "attempted to execute unexpectedly and should have been setscened" errors indicate this may be caused by missing sstate artifacts that were likely produced in earlier builds, but have been subsequently deleted for some reason.\n'
bb.fatal(msg) bb.fatal(msg)
os.rename(temp_sdkbasepath, sdkbasepath) bb.utils.rename(temp_sdkbasepath, sdkbasepath)
# Clean out residue of running bitbake, which check_sstate_task_list() # Clean out residue of running bitbake, which check_sstate_task_list()
# will effectively do # will effectively do
clean_esdk_builddir(d, sdkbasepath) clean_esdk_builddir(d, sdkbasepath)

View File

@ -66,7 +66,7 @@ python do_deploy_source_date_epoch_setscene () {
if os.path.exists(sde_file): if os.path.exists(sde_file):
target = d.getVar('SDE_FILE') target = d.getVar('SDE_FILE')
bb.debug(1, "Moving setscene SDE file %s -> %s" % (sde_file, target)) bb.debug(1, "Moving setscene SDE file %s -> %s" % (sde_file, target))
os.rename(sde_file, target) bb.utils.rename(sde_file, target)
else: else:
bb.debug(1, "%s not found!" % sde_file) bb.debug(1, "%s not found!" % sde_file)
} }

View File

@ -401,7 +401,7 @@ def sstate_installpkgdir(ss, d):
for state in ss['dirs']: for state in ss['dirs']:
prepdir(state[1]) prepdir(state[1])
os.rename(sstateinst + state[0], state[1]) bb.utils.rename(sstateinst + state[0], state[1])
sstate_install(ss, d) sstate_install(ss, d)
for plain in ss['plaindirs']: for plain in ss['plaindirs']:
@ -413,7 +413,7 @@ def sstate_installpkgdir(ss, d):
dest = plain dest = plain
bb.utils.mkdirhier(src) bb.utils.mkdirhier(src)
prepdir(dest) prepdir(dest)
os.rename(src, dest) bb.utils.rename(src, dest)
return True return True
@ -664,7 +664,7 @@ def sstate_package(ss, d):
continue continue
bb.error("sstate found an absolute path symlink %s pointing at %s. Please replace this with a relative link." % (srcpath, link)) bb.error("sstate found an absolute path symlink %s pointing at %s. Please replace this with a relative link." % (srcpath, link))
bb.debug(2, "Preparing tree %s for packaging at %s" % (state[1], sstatebuild + state[0])) bb.debug(2, "Preparing tree %s for packaging at %s" % (state[1], sstatebuild + state[0]))
os.rename(state[1], sstatebuild + state[0]) bb.utils.rename(state[1], sstatebuild + state[0])
workdir = d.getVar('WORKDIR') workdir = d.getVar('WORKDIR')
sharedworkdir = os.path.join(d.getVar('TMPDIR'), "work-shared") sharedworkdir = os.path.join(d.getVar('TMPDIR'), "work-shared")
@ -674,7 +674,7 @@ def sstate_package(ss, d):
pdir = plain.replace(sharedworkdir, sstatebuild) pdir = plain.replace(sharedworkdir, sstatebuild)
bb.utils.mkdirhier(plain) bb.utils.mkdirhier(plain)
bb.utils.mkdirhier(pdir) bb.utils.mkdirhier(pdir)
os.rename(plain, pdir) bb.utils.rename(plain, pdir)
d.setVar('SSTATE_BUILDDIR', sstatebuild) d.setVar('SSTATE_BUILDDIR', sstatebuild)
d.setVar('SSTATE_INSTDIR', sstatebuild) d.setVar('SSTATE_INSTDIR', sstatebuild)

View File

@ -184,7 +184,7 @@ python apply_update_alternative_renames () {
link_rename.append((alt_target, alt_target_rename)) link_rename.append((alt_target, alt_target_rename))
else: else:
bb.note('%s: Rename %s -> %s' % (pn, alt_target, alt_target_rename)) bb.note('%s: Rename %s -> %s' % (pn, alt_target, alt_target_rename))
os.rename(src, dest) bb.utils.rename(src, dest)
update_files(alt_target, alt_target_rename, pkg, d) update_files(alt_target, alt_target_rename, pkg, d)
else: else:
bb.warn("%s: alternative target (%s or %s) does not exist, skipping..." % (pn, alt_target, alt_target_rename)) bb.warn("%s: alternative target (%s or %s) does not exist, skipping..." % (pn, alt_target, alt_target_rename))
@ -201,7 +201,7 @@ python apply_update_alternative_renames () {
if os.path.lexists(link_target): if os.path.lexists(link_target):
# Ok, the link_target exists, we can rename # Ok, the link_target exists, we can rename
bb.note('%s: Rename (link) %s -> %s' % (pn, alt_target, alt_target_rename)) bb.note('%s: Rename (link) %s -> %s' % (pn, alt_target, alt_target_rename))
os.rename(src, dest) bb.utils.rename(src, dest)
else: else:
# Try to resolve the broken link to link.${BPN} # Try to resolve the broken link to link.${BPN}
link_maybe = '%s.%s' % (os.readlink(src), pn) link_maybe = '%s.%s' % (os.readlink(src), pn)

View File

@ -214,7 +214,7 @@ class DpkgPM(OpkgDpkgPM):
tmp_sf.write(status) tmp_sf.write(status)
os.rename(status_file + ".tmp", status_file) bb.utils.rename(status_file + ".tmp", status_file)
def run_pre_post_installs(self, package_name=None): def run_pre_post_installs(self, package_name=None):
""" """
@ -299,13 +299,13 @@ class DpkgPM(OpkgDpkgPM):
for dir in dirs: for dir in dirs:
new_dir = re.sub(r"\.dpkg-new", "", dir) new_dir = re.sub(r"\.dpkg-new", "", dir)
if dir != new_dir: if dir != new_dir:
os.rename(os.path.join(root, dir), bb.utils.rename(os.path.join(root, dir),
os.path.join(root, new_dir)) os.path.join(root, new_dir))
for file in files: for file in files:
new_file = re.sub(r"\.dpkg-new", "", file) new_file = re.sub(r"\.dpkg-new", "", file)
if file != new_file: if file != new_file:
os.rename(os.path.join(root, file), bb.utils.rename(os.path.join(root, file),
os.path.join(root, new_file)) os.path.join(root, new_file))

View File

@ -213,7 +213,7 @@ class OpkgPM(OpkgDpkgPM):
tmp_sf.write(status) tmp_sf.write(status)
os.rename(status_file + ".tmp", status_file) bb.utils.rename(status_file + ".tmp", status_file)
def _create_custom_config(self): def _create_custom_config(self):
bb.note("Building from feeds activated!") bb.note("Building from feeds activated!")

View File

@ -114,7 +114,7 @@ class Rootfs(object, metaclass=ABCMeta):
shutil.rmtree(self.image_rootfs + '-orig') shutil.rmtree(self.image_rootfs + '-orig')
except: except:
pass pass
os.rename(self.image_rootfs, self.image_rootfs + '-orig') bb.utils.rename(self.image_rootfs, self.image_rootfs + '-orig')
bb.note(" Creating debug rootfs...") bb.note(" Creating debug rootfs...")
bb.utils.mkdirhier(self.image_rootfs) bb.utils.mkdirhier(self.image_rootfs)
@ -165,10 +165,10 @@ class Rootfs(object, metaclass=ABCMeta):
shutil.rmtree(self.image_rootfs + '-dbg') shutil.rmtree(self.image_rootfs + '-dbg')
except: except:
pass pass
os.rename(self.image_rootfs, self.image_rootfs + '-dbg') bb.utils.rename(self.image_rootfs, self.image_rootfs + '-dbg')
bb.note(" Restoreing original rootfs...") bb.note(" Restoreing original rootfs...")
os.rename(self.image_rootfs + '-orig', self.image_rootfs) bb.utils.rename(self.image_rootfs + '-orig', self.image_rootfs)
def _exec_shell_cmd(self, cmd): def _exec_shell_cmd(self, cmd):
fakerootcmd = self.d.getVar('FAKEROOT') fakerootcmd = self.d.getVar('FAKEROOT')

View File

@ -1306,8 +1306,8 @@ class Wic2(WicTestCase):
result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path)) result = runCmd("%s/usr/sbin/sfdisk -F %s" % (sysroot, new_image_path))
self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output) self.assertTrue("0 B, 0 bytes, 0 sectors" in result.output)
os.rename(image_path, image_path + '.bak') bb.utils.rename(image_path, image_path + '.bak')
os.rename(new_image_path, image_path) bb.utils.rename(new_image_path, image_path)
# Check if it boots in qemu # Check if it boots in qemu
with runqemu('core-image-minimal', ssh=False) as qemu: with runqemu('core-image-minimal', ssh=False) as qemu:
@ -1318,7 +1318,7 @@ class Wic2(WicTestCase):
if os.path.exists(new_image_path): if os.path.exists(new_image_path):
os.unlink(new_image_path) os.unlink(new_image_path)
if os.path.exists(image_path + '.bak'): if os.path.exists(image_path + '.bak'):
os.rename(image_path + '.bak', image_path) bb.utils.rename(image_path + '.bak', image_path)
def test_wic_ls_ext(self): def test_wic_ls_ext(self):
"""Test listing content of the ext partition using 'wic ls'""" """Test listing content of the ext partition using 'wic ls'"""

View File

@ -508,7 +508,7 @@ def check_patch(patchfile):
f.close() f.close()
if of: if of:
of.close() of.close()
os.rename(patchfile + '.tmp', patchfile) bb.utils.rename(patchfile + '.tmp', patchfile)
def drop_to_shell(workdir=None): def drop_to_shell(workdir=None):
if not sys.stdin.isatty(): if not sys.stdin.isatty():

View File

@ -746,7 +746,7 @@ def _check_preserve(config, recipename):
os.remove(removefile) os.remove(removefile)
else: else:
tf.write(line) tf.write(line)
os.rename(newfile, origfile) bb.utils.rename(newfile, origfile)
def get_staging_kver(srcdir): def get_staging_kver(srcdir):
# Kernel version from work-shared # Kernel version from work-shared
@ -1094,10 +1094,10 @@ def rename(args, config, basepath, workspace):
# Rename bbappend # Rename bbappend
logger.info('Renaming %s to %s' % (append, newappend)) logger.info('Renaming %s to %s' % (append, newappend))
os.rename(append, newappend) bb.utils.rename(append, newappend)
# Rename recipe file # Rename recipe file
logger.info('Renaming %s to %s' % (recipefile, newfile)) logger.info('Renaming %s to %s' % (recipefile, newfile))
os.rename(recipefile, newfile) bb.utils.rename(recipefile, newfile)
# Rename source tree if it's the default path # Rename source tree if it's the default path
appendmd5 = None appendmd5 = None
@ -1333,7 +1333,7 @@ def _export_patches(srctree, rd, start_rev, destdir, changed_revs=None):
if match_name: if match_name:
# Rename patch files # Rename patch files
if new_patch != match_name: if new_patch != match_name:
os.rename(os.path.join(destdir, new_patch), bb.utils.rename(os.path.join(destdir, new_patch),
os.path.join(destdir, match_name)) os.path.join(destdir, match_name))
# Need to pop it off the list now before checking changed_revs # Need to pop it off the list now before checking changed_revs
oldpath = existing_patches.pop(old_patch) oldpath = existing_patches.pop(old_patch)

View File

@ -71,7 +71,8 @@ def _rename_recipe_dirs(oldpv, newpv, path):
if oldfile.find(oldpv) != -1: if oldfile.find(oldpv) != -1:
newfile = oldfile.replace(oldpv, newpv) newfile = oldfile.replace(oldpv, newpv)
if oldfile != newfile: if oldfile != newfile:
os.rename(os.path.join(path, oldfile), os.path.join(path, newfile)) bb.utils.rename(os.path.join(path, oldfile),
os.path.join(path, newfile))
def _rename_recipe_file(oldrecipe, bpn, oldpv, newpv, path): def _rename_recipe_file(oldrecipe, bpn, oldpv, newpv, path):
oldrecipe = os.path.basename(oldrecipe) oldrecipe = os.path.basename(oldrecipe)

View File

@ -616,5 +616,5 @@ class PartitionedImage():
part.start + part.size_sec - 1, part.size_sec) part.start + part.size_sec - 1, part.size_sec)
partimage = self.path + '.p%d' % part.num partimage = self.path + '.p%d' % part.num
os.rename(source, partimage) bb.utils.rename(source, partimage)
self.partimages.append(partimage) self.partimages.append(partimage)