* [PATCH] utils: Refactor filemode variable conversion to a function
@ 2025-06-27 9:16 Richard Purdie
2025-06-30 7:42 ` [bitbake-devel] " Antonin Godard
0 siblings, 1 reply; 3+ messages in thread
From: Richard Purdie @ 2025-06-27 9:16 UTC (permalink / raw)
To: bitbake-devel
We have other places in the code where we need to take filemode/mask
information from a bitbake variable and turn it into a real python
number. Turn this internal code into public API in bb.utils and
add some tests for it.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
bin/bitbake-worker | 7 ++-----
lib/bb/tests/utils.py | 11 +++++++++++
lib/bb/utils.py | 10 ++++++++++
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/bin/bitbake-worker b/bin/bitbake-worker
index 35fa1ab62be..9f33195176f 100755
--- a/bin/bitbake-worker
+++ b/bin/bitbake-worker
@@ -182,11 +182,8 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask):
elif workerdata["umask"]:
umask = workerdata["umask"]
if umask:
- # umask might come in as a number or text string..
- try:
- umask = int(umask, 8)
- except TypeError:
- pass
+ # Convert to a python numeric value as it could be a string
+ bb.utils.to_filemode(umask)
dry_run = cfg.dry_run or runtask['dry_run']
diff --git a/lib/bb/tests/utils.py b/lib/bb/tests/utils.py
index 48e61dfcea0..52b7bf85bf4 100644
--- a/lib/bb/tests/utils.py
+++ b/lib/bb/tests/utils.py
@@ -692,3 +692,14 @@ class EnvironmentTests(unittest.TestCase):
self.assertIn("A", os.environ)
self.assertEqual(os.environ["A"], "this is A")
self.assertNotIn("B", os.environ)
+
+class FilemodeTests(unittest.TestCase):
+ def test_filemode_convert(self):
+ self.assertEqual(0o775, bb.utils.to_filemode("0o775"))
+ self.assertEqual(0o775, bb.utils.to_filemode(0o775))
+ self.assertEqual(0o775, bb.utils.to_filemode("775"))
+ with self.assertRaises(ValueError):
+ bb.utils.to_filemode("xyz")
+ with self.assertRaises(ValueError):
+ bb.utils.to_filemode("999")
+
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index a2806fd360d..01f7cf81f46 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -1211,6 +1211,16 @@ def which(path, item, direction = 0, history = False, executable=False):
return "", hist
return ""
+def to_filemode(input):
+ """
+ Take a bitbake variable contents defining a file mode and return
+ the proper python representation of the number
+ """
+ # umask might come in as a number or text string..
+ if type(input) is int:
+ return input
+ return int(input, 8)
+
@contextmanager
def umask(new_mask):
"""
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [bitbake-devel] [PATCH] utils: Refactor filemode variable conversion to a function
2025-06-27 9:16 [PATCH] utils: Refactor filemode variable conversion to a function Richard Purdie
@ 2025-06-30 7:42 ` Antonin Godard
2025-06-30 7:53 ` Richard Purdie
0 siblings, 1 reply; 3+ messages in thread
From: Antonin Godard @ 2025-06-30 7:42 UTC (permalink / raw)
To: richard.purdie, bitbake-devel
Hi Richard,
On Fri Jun 27, 2025 at 11:16 AM CEST, Richard Purdie via lists.openembedded.org wrote:
> We have other places in the code where we need to take filemode/mask
> information from a bitbake variable and turn it into a real python
> number. Turn this internal code into public API in bb.utils and
> add some tests for it.
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
> bin/bitbake-worker | 7 ++-----
> lib/bb/tests/utils.py | 11 +++++++++++
> lib/bb/utils.py | 10 ++++++++++
> 3 files changed, 23 insertions(+), 5 deletions(-)
>
> diff --git a/bin/bitbake-worker b/bin/bitbake-worker
> index 35fa1ab62be..9f33195176f 100755
> --- a/bin/bitbake-worker
> +++ b/bin/bitbake-worker
> @@ -182,11 +182,8 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask):
> elif workerdata["umask"]:
> umask = workerdata["umask"]
> if umask:
> - # umask might come in as a number or text string..
> - try:
> - umask = int(umask, 8)
> - except TypeError:
> - pass
> + # Convert to a python numeric value as it could be a string
> + bb.utils.to_filemode(umask)
>
> dry_run = cfg.dry_run or runtask['dry_run']
>
> diff --git a/lib/bb/tests/utils.py b/lib/bb/tests/utils.py
> index 48e61dfcea0..52b7bf85bf4 100644
> --- a/lib/bb/tests/utils.py
> +++ b/lib/bb/tests/utils.py
> @@ -692,3 +692,14 @@ class EnvironmentTests(unittest.TestCase):
> self.assertIn("A", os.environ)
> self.assertEqual(os.environ["A"], "this is A")
> self.assertNotIn("B", os.environ)
> +
> +class FilemodeTests(unittest.TestCase):
> + def test_filemode_convert(self):
> + self.assertEqual(0o775, bb.utils.to_filemode("0o775"))
> + self.assertEqual(0o775, bb.utils.to_filemode(0o775))
> + self.assertEqual(0o775, bb.utils.to_filemode("775"))
> + with self.assertRaises(ValueError):
> + bb.utils.to_filemode("xyz")
> + with self.assertRaises(ValueError):
> + bb.utils.to_filemode("999")
> +
> diff --git a/lib/bb/utils.py b/lib/bb/utils.py
> index a2806fd360d..01f7cf81f46 100644
> --- a/lib/bb/utils.py
> +++ b/lib/bb/utils.py
> @@ -1211,6 +1211,16 @@ def which(path, item, direction = 0, history = False, executable=False):
> return "", hist
> return ""
>
> +def to_filemode(input):
> + """
> + Take a bitbake variable contents defining a file mode and return
> + the proper python representation of the number
> + """
It could be nice to keep the same format as the other functions in this file:
explicit the arguments and the return value.
> + # umask might come in as a number or text string..
> + if type(input) is int:
> + return input
> + return int(input, 8)
> +
> @contextmanager
> def umask(new_mask):
> """
I think this triggered a wall of errors of the autobuilder:
https://autobuilder.yoctoproject.org/valkyrie/#/builders/29/builds/1910
Locally I also reproduced the issue:
ERROR: Task (/data/yoctoproject/ws/repos/openembedded-core/meta/recipes-bsp/efivar/efivar_39.bb:do_recipe_qa) failed with exit code '1'
If I drop this commit (and the two others on OE-Core that use to_filemode),
then re-run it becomes successful again. Cleaning the sstate of the recipe
then, and re-introducing your commit only, triggers the error. I don't have any
log to show because I think the issue happens before do_recipe_qa is run.
Antonin
--
Antonin Godard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [bitbake-devel] [PATCH] utils: Refactor filemode variable conversion to a function
2025-06-30 7:42 ` [bitbake-devel] " Antonin Godard
@ 2025-06-30 7:53 ` Richard Purdie
0 siblings, 0 replies; 3+ messages in thread
From: Richard Purdie @ 2025-06-30 7:53 UTC (permalink / raw)
To: Antonin Godard, bitbake-devel
On Mon, 2025-06-30 at 09:42 +0200, Antonin Godard wrote:
> Hi Richard,
>
> On Fri Jun 27, 2025 at 11:16 AM CEST, Richard Purdie via lists.openembedded.org wrote:
> > We have other places in the code where we need to take filemode/mask
> > information from a bitbake variable and turn it into a real python
> > number. Turn this internal code into public API in bb.utils and
> > add some tests for it.
> >
> > Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> > ---
> > bin/bitbake-worker | 7 ++-----
> > lib/bb/tests/utils.py | 11 +++++++++++
> > lib/bb/utils.py | 10 ++++++++++
> > 3 files changed, 23 insertions(+), 5 deletions(-)
> >
> > diff --git a/bin/bitbake-worker b/bin/bitbake-worker
> > index 35fa1ab62be..9f33195176f 100755
> > --- a/bin/bitbake-worker
> > +++ b/bin/bitbake-worker
> > @@ -182,11 +182,8 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask):
> > elif workerdata["umask"]:
> > umask = workerdata["umask"]
> > if umask:
> > - # umask might come in as a number or text string..
> > - try:
> > - umask = int(umask, 8)
> > - except TypeError:
> > - pass
> > + # Convert to a python numeric value as it could be a string
> > + bb.utils.to_filemode(umask)
> >
> > dry_run = cfg.dry_run or runtask['dry_run']
> >
> > diff --git a/lib/bb/tests/utils.py b/lib/bb/tests/utils.py
> > index 48e61dfcea0..52b7bf85bf4 100644
> > --- a/lib/bb/tests/utils.py
> > +++ b/lib/bb/tests/utils.py
> > @@ -692,3 +692,14 @@ class EnvironmentTests(unittest.TestCase):
> > self.assertIn("A", os.environ)
> > self.assertEqual(os.environ["A"], "this is A")
> > self.assertNotIn("B", os.environ)
> > +
> > +class FilemodeTests(unittest.TestCase):
> > + def test_filemode_convert(self):
> > + self.assertEqual(0o775, bb.utils.to_filemode("0o775"))
> > + self.assertEqual(0o775, bb.utils.to_filemode(0o775))
> > + self.assertEqual(0o775, bb.utils.to_filemode("775"))
> > + with self.assertRaises(ValueError):
> > + bb.utils.to_filemode("xyz")
> > + with self.assertRaises(ValueError):
> > + bb.utils.to_filemode("999")
> > +
> > diff --git a/lib/bb/utils.py b/lib/bb/utils.py
> > index a2806fd360d..01f7cf81f46 100644
> > --- a/lib/bb/utils.py
> > +++ b/lib/bb/utils.py
> > @@ -1211,6 +1211,16 @@ def which(path, item, direction = 0, history = False, executable=False):
> > return "", hist
> > return ""
> >
> > +def to_filemode(input):
> > + """
> > + Take a bitbake variable contents defining a file mode and return
> > + the proper python representation of the number
> > + """
>
> It could be nice to keep the same format as the other functions in this file:
> explicit the arguments and the return value.
>
> > + # umask might come in as a number or text string..
> > + if type(input) is int:
> > + return input
> > + return int(input, 8)
> > +
> > @contextmanager
> > def umask(new_mask):
> > """
>
> I think this triggered a wall of errors of the autobuilder:
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/29/builds/1910
>
> Locally I also reproduced the issue:
>
> ERROR: Task (/data/yoctoproject/ws/repos/openembedded-core/meta/recipes-bsp/efivar/efivar_39.bb:do_recipe_qa) failed with exit code '1'
>
> If I drop this commit (and the two others on OE-Core that use to_filemode),
> then re-run it becomes successful again. Cleaning the sstate of the recipe
> then, and re-introducing your commit only, triggers the error. I don't have any
> log to show because I think the issue happens before do_recipe_qa is run.
Thanks, I've tweaked the docstring and fixed the issue in v2.
Cheers,
Richard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-30 7:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-27 9:16 [PATCH] utils: Refactor filemode variable conversion to a function Richard Purdie
2025-06-30 7:42 ` [bitbake-devel] " Antonin Godard
2025-06-30 7:53 ` Richard Purdie
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.