Skip to contentSkip to conversation

build: defer processing of cleandirs until after lockfiles are acquired

PATCH Superseded Chris Laplante 2 participants 3 messages Nov 3, 2020 – Nov 9, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: defer processing of cleandirs until after lockfiles are acquired

This is to avoid potential races for tasks that use both [cleandirs] and [lockfiles].

It is currently believed that normal [dirs] handling is fine as-is.

---
 lib/bb/build.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/bb/build.py +6 -5
index 974d2ff0..51bcad96 100644
@@ -188,11 +188,6 @@ def exec_func(func, d, dirs = None):
         oldcwd = None
 
     flags = d.getVarFlags(func)
-    cleandirs = flags.get('cleandirs') if flags else None
-    if cleandirs:
-        for cdir in d.expand(cleandirs).split():
-            bb.utils.remove(cdir, True)
-            bb.utils.mkdirhier(cdir)
 
     if flags and dirs is None:
         dirs = flags.get('dirs')
@@ -250,6 +245,12 @@ def exec_func(func, d, dirs = None):
                 pass
 
     with bb.utils.fileslocked(lockfiles):
+        cleandirs = flags.get('cleandirs') if flags else None
+        if cleandirs:
+            for cdir in d.expand(cleandirs).split():
+                bb.utils.remove(cdir, True)
+                bb.utils.mkdirhier(cdir)
+
         if ispython:
             exec_func_python(func, d, runfile, cwd=adir)
         else:
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines · Chris Laplante via lists.openembedded.org

This is to avoid potential races for tasks that use both [cleandirs] and
[lockfiles].

It is currently believed that normal [dirs] handling is fine as-is.

Unfortunately this caused all kinds of weird build failures in testing:

See the builds triggered by:
https://autobuilder.yoctoproject.org/typhoon/#/builders/83/builds/1550

I reverted this commit and things started working so there is something wrong.

Cheers,

Richard

#2 lore raw
Quoted 14 lines
Quoted 1 line

It is currently believed that normal [dirs] handling is fine as-is.

Unfortunately this caused all kinds of weird build failures in testing:

See the builds triggered by:
https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fauto
builder.yoctoproject.org%2Ftyphoon%2F%23%2Fbuilders%2F83%2Fbuilds%2 F1550&data=04%7C01%7Cchris.laplante%40agilent.com%7Cee947569 e10046e6fadc08d8836fadd8%7Ca9c0bc098b46420693512ba12fb4a5c0%7C 0%7C0%7C637403862972297032%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C10 00&sdata=o0aDi1y39HZVEmvjSMRcwb4CXI6igsSrpaaQ8efGJrY%3D&am p;reserved=0

Quoted 2 lines

I reverted this commit and things started working so there is something wrong.

I've gotten to the bottom of why at least some of these failed. It turns out we do need to move [dirs] processing after [cleandirs], since there might be something like:

do_task[cleandirs] = "${MY_DIR}"
do_task[dirs] += "${MY_DIR}/subdir"

When [dirs] happens before [cleandirs], then ${MY_DIR}/subdir is created, but then the entire directory is wiped by [cleandirs] handling leaving just ${MY_DIR}.

I am working on a v2 of the patch to fix this. I am also going to add a sanity check to ensure that [lockfiles] don't intersect with [cleandirs], since otherwise processing of [cleandirs] would result in the deletion of lockfiles that are actively being used. I have no reason to believe that this is currently a problem in poky, but I think it's a good idea to catch this.

Chris