diff mbox series

image_types_wic.bbclass: remove .env file in do_clean

Message ID 20240306163658.34188-1-m.salvini@koansoftware.com
State New
Headers show
Series image_types_wic.bbclass: remove .env file in do_clean | expand

Commit Message

Mauro Salvini March 6, 2024, 4:36 p.m. UTC
Before this commit, the .env file created in
tmp/sysroots/<machine>/imgdata/<image>.env was never cleaned,
but when the do_clean task is invoked on an image, the .env file
contains paths that are not valid anymore.
If another image wants to use the cleaned image fs to build a .wic,
the wic command fails because paths contained in .env are not found.
With this patch, the returned error is more clear:

  "File /.../tmp/sysroots/<machine>/imgdata/<image>.env doesn't exist"

Signed-off-by: Mauro Salvini <m.salvini@koansoftware.com>
---
 meta/classes-recipe/image_types_wic.bbclass | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Richard Purdie March 6, 2024, 4:57 p.m. UTC | #1
On Wed, 2024-03-06 at 08:37 -0800, Mauro wrote:
> Before this commit, the .env file created in
> tmp/sysroots/<machine>/imgdata/<image>.env was never cleaned,
> but when the do_clean task is invoked on an image, the .env file
> contains paths that are not valid anymore.
> If another image wants to use the cleaned image fs to build a .wic,
> the wic command fails because paths contained in .env are not found.
> With this patch, the returned error is more clear:
> 
>   "File /.../tmp/sysroots/<machine>/imgdata/<image>.env doesn't
> exist"
> 
> Signed-off-by: Mauro Salvini <m.salvini@koansoftware.com>
> ---
>  meta/classes-recipe/image_types_wic.bbclass | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/meta/classes-recipe/image_types_wic.bbclass
> b/meta/classes-recipe/image_types_wic.bbclass
> index cf3be909b3..b0b5691225 100644
> --- a/meta/classes-recipe/image_types_wic.bbclass
> +++ b/meta/classes-recipe/image_types_wic.bbclass
> @@ -205,3 +205,14 @@ addtask do_flush_pseudodb after do_rootfs before
> do_image do_image_qa
>  addtask do_rootfs_wicenv after do_image before do_image_wic
>  do_rootfs_wicenv[vardeps] += "${WICVARS}"
>  do_rootfs_wicenv[prefuncs] = 'set_image_size'
> +
> +#
> +# Clean also .env file created in
> tmp/sysroots/<machine>/imgdata/<image>.env
> +# when a clean is invoked
> +#
> +do_clean:append() {
> +    stdir = d.getVar('STAGING_DIR')
> +    outdir = os.path.join(stdir, d.getVar('MACHINE'), 'imgdata')
> +    basename = d.getVar('IMAGE_BASENAME')
> +    bb.utils.remove(os.path.join(outdir, basename) + '.env')
> +}

This doesn't look right unfortunately.

Things should not be being placed into the sysroots (STAGING_DIR) that
aren't under the control of sstate. If things are, we need to fix that
at the source of the problem.

Cheers,

Richard
Mauro Salvini March 7, 2024, 8:21 a.m. UTC | #2
On 06/03/24 17:57, Richard Purdie wrote:
> On Wed, 2024-03-06 at 08:37 -0800, Mauro wrote:
>> Before this commit, the .env file created in
>> tmp/sysroots/<machine>/imgdata/<image>.env was never cleaned,
>> but when the do_clean task is invoked on an image, the .env file
>> contains paths that are not valid anymore.
>> If another image wants to use the cleaned image fs to build a .wic,
>> the wic command fails because paths contained in .env are not found.
>> With this patch, the returned error is more clear:
>>
>>    "File /.../tmp/sysroots/<machine>/imgdata/<image>.env doesn't
>> exist"
>>
>> Signed-off-by: Mauro Salvini <m.salvini@koansoftware.com>
>> ---
>>   meta/classes-recipe/image_types_wic.bbclass | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/meta/classes-recipe/image_types_wic.bbclass
>> b/meta/classes-recipe/image_types_wic.bbclass
>> index cf3be909b3..b0b5691225 100644
>> --- a/meta/classes-recipe/image_types_wic.bbclass
>> +++ b/meta/classes-recipe/image_types_wic.bbclass
>> @@ -205,3 +205,14 @@ addtask do_flush_pseudodb after do_rootfs before
>> do_image do_image_qa
>>   addtask do_rootfs_wicenv after do_image before do_image_wic
>>   do_rootfs_wicenv[vardeps] += "${WICVARS}"
>>   do_rootfs_wicenv[prefuncs] = 'set_image_size'
>> +
>> +#
>> +# Clean also .env file created in
>> tmp/sysroots/<machine>/imgdata/<image>.env
>> +# when a clean is invoked
>> +#
>> +do_clean:append() {
>> +    stdir = d.getVar('STAGING_DIR')
>> +    outdir = os.path.join(stdir, d.getVar('MACHINE'), 'imgdata')
>> +    basename = d.getVar('IMAGE_BASENAME')
>> +    bb.utils.remove(os.path.join(outdir, basename) + '.env')
>> +}
> 
> This doesn't look right unfortunately.
> 
> Things should not be being placed into the sysroots (STAGING_DIR) that
> aren't under the control of sstate. If things are, we need to fix that
> at the source of the problem.
> 
> Cheers,
> 
> Richard
> 

Hi Richard,

thank you.

If I understood correctly, your suggestion is to create the .env file in 
WORKDIR instead of in the STAGING_DIR, and use 
tmp/deploy/images/<machine>/<image>.env (now copied from STAGING_DIR, 
after copied from WORKDIR) when creating the wic file. If this is the 
right way, I can try to produce a patch.

Thanks. regards
Mauro Salvini March 11, 2024, 2:58 p.m. UTC | #3
On 06/03/24 17:57, Richard Purdie wrote:
> On Wed, 2024-03-06 at 08:37 -0800, Mauro wrote:
>> Before this commit, the .env file created in
>> tmp/sysroots/<machine>/imgdata/<image>.env was never cleaned,
>> but when the do_clean task is invoked on an image, the .env file
>> contains paths that are not valid anymore.
>> If another image wants to use the cleaned image fs to build a .wic,
>> the wic command fails because paths contained in .env are not found.
>> With this patch, the returned error is more clear:
>>
>>    "File /.../tmp/sysroots/<machine>/imgdata/<image>.env doesn't
>> exist"
>>
>> Signed-off-by: Mauro Salvini <m.salvini@koansoftware.com>
>> ---
>>   meta/classes-recipe/image_types_wic.bbclass | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/meta/classes-recipe/image_types_wic.bbclass
>> b/meta/classes-recipe/image_types_wic.bbclass
>> index cf3be909b3..b0b5691225 100644
>> --- a/meta/classes-recipe/image_types_wic.bbclass
>> +++ b/meta/classes-recipe/image_types_wic.bbclass
>> @@ -205,3 +205,14 @@ addtask do_flush_pseudodb after do_rootfs before
>> do_image do_image_qa
>>   addtask do_rootfs_wicenv after do_image before do_image_wic
>>   do_rootfs_wicenv[vardeps] += "${WICVARS}"
>>   do_rootfs_wicenv[prefuncs] = 'set_image_size'
>> +
>> +#
>> +# Clean also .env file created in
>> tmp/sysroots/<machine>/imgdata/<image>.env
>> +# when a clean is invoked
>> +#
>> +do_clean:append() {
>> +    stdir = d.getVar('STAGING_DIR')
>> +    outdir = os.path.join(stdir, d.getVar('MACHINE'), 'imgdata')
>> +    basename = d.getVar('IMAGE_BASENAME')
>> +    bb.utils.remove(os.path.join(outdir, basename) + '.env')
>> +}
> 
> This doesn't look right unfortunately.
> 
> Things should not be being placed into the sysroots (STAGING_DIR) that
> aren't under the control of sstate. If things are, we need to fix that
> at the source of the problem.
> 
> Cheers,
> 
> Richard
> 
> 

Hi Richard,

thank you.

What would be the correct directory where to put the .env files?
I don't know much about Yocto internals, but I can try do arrange a 
patch to solve the problem at the source.

Thanks, regards
diff mbox series

Patch

diff --git a/meta/classes-recipe/image_types_wic.bbclass b/meta/classes-recipe/image_types_wic.bbclass
index cf3be909b3..b0b5691225 100644
--- a/meta/classes-recipe/image_types_wic.bbclass
+++ b/meta/classes-recipe/image_types_wic.bbclass
@@ -205,3 +205,14 @@  addtask do_flush_pseudodb after do_rootfs before do_image do_image_qa
 addtask do_rootfs_wicenv after do_image before do_image_wic
 do_rootfs_wicenv[vardeps] += "${WICVARS}"
 do_rootfs_wicenv[prefuncs] = 'set_image_size'
+
+#
+# Clean also .env file created in tmp/sysroots/<machine>/imgdata/<image>.env
+# when a clean is invoked
+#
+do_clean:append() {
+    stdir = d.getVar('STAGING_DIR')
+    outdir = os.path.join(stdir, d.getVar('MACHINE'), 'imgdata')
+    basename = d.getVar('IMAGE_BASENAME')
+    bb.utils.remove(os.path.join(outdir, basename) + '.env')
+}