public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] wic-img: switch over to use the template.bbclass mechanism
@ 2019-03-13 13:05 claudius.heine.ext
  2019-03-13 13:16 ` Henning Schild
  2019-03-25 16:35 ` Maxim Yu. Osipov
  0 siblings, 2 replies; 4+ messages in thread
From: claudius.heine.ext @ 2019-03-13 13:05 UTC (permalink / raw)
  To: isar-users; +Cc: Claudius Heine

From: Claudius Heine <ch@denx.de>

We don't need to have two template mechanism implemented in Isar. This
patch switches the very specific one in wic-img to use the generic one
from template.bbclass.

Signed-off-by: Claudius Heine <ch@denx.de>
---
 meta/classes/wic-img.bbclass | 40 +++++++++++++-----------------------
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass
index 5a451a0..09d9f2e 100644
--- a/meta/classes/wic-img.bbclass
+++ b/meta/classes/wic-img.bbclass
@@ -6,29 +6,14 @@
 
 WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}')}"
 
-python do_write_wks_template () {
-    """Write out expanded template contents to WKS_FULL_PATH."""
-    import re
-
-    template_body = d.getVar('_WKS_TEMPLATE')
-
-    # Remove any remnant variable references left behind by the expansion
-    # due to undefined variables
-    expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}")
-    while True:
-        new_body = re.sub(expand_var_regexp, '', template_body)
-        if new_body == template_body:
-            break
-        else:
-            template_body = new_body
-
-    wks_file = d.getVar('WKS_FULL_PATH')
-    with open(wks_file, 'w') as f:
-        f.write(template_body)
+do_copy_wks_template[file-checksums] += "${WKS_FILE_CHECKSUM}"
+do_copy_wks_template () {
+    cp -f '${WKS_TEMPLATE_PATH}' '${WORKDIR}/${WKS_TEMPLATE_FILE}'
 }
 
 python () {
     import itertools
+    import re
 
     wks_full_path = None
 
@@ -70,22 +55,25 @@ python () {
         d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
         d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True')
 
+        wks_template_file = os.path.basename(base) + '.tmpl'
+        d.setVar('WKS_TEMPLATE_FILE', wks_template_file)
+        d.appendVar('TEMPLATE_FILES', " {}".format(wks_template_file))
+
         # We need to re-parse each time the file changes, and bitbake
         # needs to be told about that explicitly.
         bb.parse.mark_dependency(d, wks_file)
 
+        expand_var_regexp = re.compile(r"\${(?P<name>[^{}@\n\t :]+)}")
+
         try:
             with open(wks_file, 'r') as f:
-                body = f.read()
+                d.appendVar("TEMPLATE_VARS", " {}".format(
+                    " ".join(expand_var_regexp.findall(f.read()))))
         except (IOError, OSError) as exc:
             pass
         else:
-            # Previously, I used expandWithRefs to get the dependency list
-            # and add it to WICVARS, but there's no point re-parsing the
-            # file in process_wks_template as well, so just put it in
-            # a variable and let the metadata deal with the deps.
-            d.setVar('_WKS_TEMPLATE', body)
-            bb.build.addtask('do_write_wks_template', 'do_wic_image', None, d)
+            bb.build.addtask('do_copy_wks_template', 'do_transform_template do_wic_image', None, d)
+            bb.build.addtask('do_transform_template', 'do_wic_image', None, d)
 }
 
 inherit buildchroot
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] wic-img: switch over to use the template.bbclass mechanism
  2019-03-13 13:05 [PATCH] wic-img: switch over to use the template.bbclass mechanism claudius.heine.ext
@ 2019-03-13 13:16 ` Henning Schild
  2019-03-13 13:18   ` Claudius Heine
  2019-03-25 16:35 ` Maxim Yu. Osipov
  1 sibling, 1 reply; 4+ messages in thread
From: Henning Schild @ 2019-03-13 13:16 UTC (permalink / raw)
  To: Cedric Hombourger
  Cc: [ext] claudius.heine.ext@siemens.com, isar-users, Claudius Heine

Cedric you might want to test that on more than just the example we
have inside Isar.

Henning

Am Wed, 13 Mar 2019 14:05:57 +0100
schrieb "[ext] claudius.heine.ext@siemens.com"
<claudius.heine.ext@siemens.com>:

> From: Claudius Heine <ch@denx.de>
> 
> We don't need to have two template mechanism implemented in Isar. This
> patch switches the very specific one in wic-img to use the generic one
> from template.bbclass.
> 
> Signed-off-by: Claudius Heine <ch@denx.de>
> ---
>  meta/classes/wic-img.bbclass | 40
> +++++++++++++----------------------- 1 file changed, 14
> insertions(+), 26 deletions(-)
> 
> diff --git a/meta/classes/wic-img.bbclass
> b/meta/classes/wic-img.bbclass index 5a451a0..09d9f2e 100644
> --- a/meta/classes/wic-img.bbclass
> +++ b/meta/classes/wic-img.bbclass
> @@ -6,29 +6,14 @@
>  
>  WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' %
> os.path.exists('${WKS_FULL_PATH}')}" 
> -python do_write_wks_template () {
> -    """Write out expanded template contents to WKS_FULL_PATH."""
> -    import re
> -
> -    template_body = d.getVar('_WKS_TEMPLATE')
> -
> -    # Remove any remnant variable references left behind by the
> expansion
> -    # due to undefined variables
> -    expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}")
> -    while True:
> -        new_body = re.sub(expand_var_regexp, '', template_body)
> -        if new_body == template_body:
> -            break
> -        else:
> -            template_body = new_body
> -
> -    wks_file = d.getVar('WKS_FULL_PATH')
> -    with open(wks_file, 'w') as f:
> -        f.write(template_body)
> +do_copy_wks_template[file-checksums] += "${WKS_FILE_CHECKSUM}"
> +do_copy_wks_template () {
> +    cp -f '${WKS_TEMPLATE_PATH}' '${WORKDIR}/${WKS_TEMPLATE_FILE}'
>  }
>  
>  python () {
>      import itertools
> +    import re
>  
>      wks_full_path = None
>  
> @@ -70,22 +55,25 @@ python () {
>          d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
>          d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True')
>  
> +        wks_template_file = os.path.basename(base) + '.tmpl'
> +        d.setVar('WKS_TEMPLATE_FILE', wks_template_file)
> +        d.appendVar('TEMPLATE_FILES',
> " {}".format(wks_template_file)) +
>          # We need to re-parse each time the file changes, and bitbake
>          # needs to be told about that explicitly.
>          bb.parse.mark_dependency(d, wks_file)
>  
> +        expand_var_regexp =
> re.compile(r"\${(?P<name>[^{}@\n\t :]+)}") +
>          try:
>              with open(wks_file, 'r') as f:
> -                body = f.read()
> +                d.appendVar("TEMPLATE_VARS", " {}".format(
> +                    " ".join(expand_var_regexp.findall(f.read()))))
>          except (IOError, OSError) as exc:
>              pass
>          else:
> -            # Previously, I used expandWithRefs to get the
> dependency list
> -            # and add it to WICVARS, but there's no point re-parsing
> the
> -            # file in process_wks_template as well, so just put it in
> -            # a variable and let the metadata deal with the deps.
> -            d.setVar('_WKS_TEMPLATE', body)
> -            bb.build.addtask('do_write_wks_template',
> 'do_wic_image', None, d)
> +            bb.build.addtask('do_copy_wks_template',
> 'do_transform_template do_wic_image', None, d)
> +            bb.build.addtask('do_transform_template',
> 'do_wic_image', None, d) }
>  
>  inherit buildchroot


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] wic-img: switch over to use the template.bbclass mechanism
  2019-03-13 13:16 ` Henning Schild
@ 2019-03-13 13:18   ` Claudius Heine
  0 siblings, 0 replies; 4+ messages in thread
From: Claudius Heine @ 2019-03-13 13:18 UTC (permalink / raw)
  To: Henning Schild, Cedric Hombourger; +Cc: isar-users, Claudius Heine

On 13/03/2019 14.16, Henning Schild wrote:
> Cedric you might want to test that on more than just the example we
> have inside Isar.

Regarding testing. I tested this patch locally with the 
'multiconfig:de0-nano-soc-stretch:isar-image-base' target, but since the 
isar-build.org seems to be currently down, I could not test it there.

Claudius

> 
> Henning
> 
> Am Wed, 13 Mar 2019 14:05:57 +0100
> schrieb "[ext] claudius.heine.ext@siemens.com"
> <claudius.heine.ext@siemens.com>:
> 
>> From: Claudius Heine <ch@denx.de>
>>
>> We don't need to have two template mechanism implemented in Isar. This
>> patch switches the very specific one in wic-img to use the generic one
>> from template.bbclass.
>>
>> Signed-off-by: Claudius Heine <ch@denx.de>
>> ---
>>   meta/classes/wic-img.bbclass | 40
>> +++++++++++++----------------------- 1 file changed, 14
>> insertions(+), 26 deletions(-)
>>
>> diff --git a/meta/classes/wic-img.bbclass
>> b/meta/classes/wic-img.bbclass index 5a451a0..09d9f2e 100644
>> --- a/meta/classes/wic-img.bbclass
>> +++ b/meta/classes/wic-img.bbclass
>> @@ -6,29 +6,14 @@
>>   
>>   WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' %
>> os.path.exists('${WKS_FULL_PATH}')}"
>> -python do_write_wks_template () {
>> -    """Write out expanded template contents to WKS_FULL_PATH."""
>> -    import re
>> -
>> -    template_body = d.getVar('_WKS_TEMPLATE')
>> -
>> -    # Remove any remnant variable references left behind by the
>> expansion
>> -    # due to undefined variables
>> -    expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}")
>> -    while True:
>> -        new_body = re.sub(expand_var_regexp, '', template_body)
>> -        if new_body == template_body:
>> -            break
>> -        else:
>> -            template_body = new_body
>> -
>> -    wks_file = d.getVar('WKS_FULL_PATH')
>> -    with open(wks_file, 'w') as f:
>> -        f.write(template_body)
>> +do_copy_wks_template[file-checksums] += "${WKS_FILE_CHECKSUM}"
>> +do_copy_wks_template () {
>> +    cp -f '${WKS_TEMPLATE_PATH}' '${WORKDIR}/${WKS_TEMPLATE_FILE}'
>>   }
>>   
>>   python () {
>>       import itertools
>> +    import re
>>   
>>       wks_full_path = None
>>   
>> @@ -70,22 +55,25 @@ python () {
>>           d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
>>           d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True')
>>   
>> +        wks_template_file = os.path.basename(base) + '.tmpl'
>> +        d.setVar('WKS_TEMPLATE_FILE', wks_template_file)
>> +        d.appendVar('TEMPLATE_FILES',
>> " {}".format(wks_template_file)) +
>>           # We need to re-parse each time the file changes, and bitbake
>>           # needs to be told about that explicitly.
>>           bb.parse.mark_dependency(d, wks_file)
>>   
>> +        expand_var_regexp =
>> re.compile(r"\${(?P<name>[^{}@\n\t :]+)}") +
>>           try:
>>               with open(wks_file, 'r') as f:
>> -                body = f.read()
>> +                d.appendVar("TEMPLATE_VARS", " {}".format(
>> +                    " ".join(expand_var_regexp.findall(f.read()))))
>>           except (IOError, OSError) as exc:
>>               pass
>>           else:
>> -            # Previously, I used expandWithRefs to get the
>> dependency list
>> -            # and add it to WICVARS, but there's no point re-parsing
>> the
>> -            # file in process_wks_template as well, so just put it in
>> -            # a variable and let the metadata deal with the deps.
>> -            d.setVar('_WKS_TEMPLATE', body)
>> -            bb.build.addtask('do_write_wks_template',
>> 'do_wic_image', None, d)
>> +            bb.build.addtask('do_copy_wks_template',
>> 'do_transform_template do_wic_image', None, d)
>> +            bb.build.addtask('do_transform_template',
>> 'do_wic_image', None, d) }
>>   
>>   inherit buildchroot
> 

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-54 Fax: (+49)-8142-66989-80 Email: ch@denx.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] wic-img: switch over to use the template.bbclass mechanism
  2019-03-13 13:05 [PATCH] wic-img: switch over to use the template.bbclass mechanism claudius.heine.ext
  2019-03-13 13:16 ` Henning Schild
@ 2019-03-25 16:35 ` Maxim Yu. Osipov
  1 sibling, 0 replies; 4+ messages in thread
From: Maxim Yu. Osipov @ 2019-03-25 16:35 UTC (permalink / raw)
  To: claudius.heine.ext, isar-users; +Cc: Claudius Heine

On 3/13/19 2:05 PM, claudius.heine.ext@siemens.com wrote:
> From: Claudius Heine <ch@denx.de>
> 
> We don't need to have two template mechanism implemented in Isar. This
> patch switches the very specific one in wic-img to use the generic one
> from template.bbclass.

Applied to the 'next'.


> Signed-off-by: Claudius Heine <ch@denx.de>
> ---
>   meta/classes/wic-img.bbclass | 40 +++++++++++++-----------------------
>   1 file changed, 14 insertions(+), 26 deletions(-)
> 
> diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass
> index 5a451a0..09d9f2e 100644
> --- a/meta/classes/wic-img.bbclass
> +++ b/meta/classes/wic-img.bbclass
> @@ -6,29 +6,14 @@
>   
>   WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}')}"
>   
> -python do_write_wks_template () {
> -    """Write out expanded template contents to WKS_FULL_PATH."""
> -    import re
> -
> -    template_body = d.getVar('_WKS_TEMPLATE')
> -
> -    # Remove any remnant variable references left behind by the expansion
> -    # due to undefined variables
> -    expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}")
> -    while True:
> -        new_body = re.sub(expand_var_regexp, '', template_body)
> -        if new_body == template_body:
> -            break
> -        else:
> -            template_body = new_body
> -
> -    wks_file = d.getVar('WKS_FULL_PATH')
> -    with open(wks_file, 'w') as f:
> -        f.write(template_body)
> +do_copy_wks_template[file-checksums] += "${WKS_FILE_CHECKSUM}"
> +do_copy_wks_template () {
> +    cp -f '${WKS_TEMPLATE_PATH}' '${WORKDIR}/${WKS_TEMPLATE_FILE}'
>   }
>   
>   python () {
>       import itertools
> +    import re
>   
>       wks_full_path = None
>   
> @@ -70,22 +55,25 @@ python () {
>           d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
>           d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True')
>   
> +        wks_template_file = os.path.basename(base) + '.tmpl'
> +        d.setVar('WKS_TEMPLATE_FILE', wks_template_file)
> +        d.appendVar('TEMPLATE_FILES', " {}".format(wks_template_file))
> +
>           # We need to re-parse each time the file changes, and bitbake
>           # needs to be told about that explicitly.
>           bb.parse.mark_dependency(d, wks_file)
>   
> +        expand_var_regexp = re.compile(r"\${(?P<name>[^{}@\n\t :]+)}")
> +
>           try:
>               with open(wks_file, 'r') as f:
> -                body = f.read()
> +                d.appendVar("TEMPLATE_VARS", " {}".format(
> +                    " ".join(expand_var_regexp.findall(f.read()))))
>           except (IOError, OSError) as exc:
>               pass
>           else:
> -            # Previously, I used expandWithRefs to get the dependency list
> -            # and add it to WICVARS, but there's no point re-parsing the
> -            # file in process_wks_template as well, so just put it in
> -            # a variable and let the metadata deal with the deps.
> -            d.setVar('_WKS_TEMPLATE', body)
> -            bb.build.addtask('do_write_wks_template', 'do_wic_image', None, d)
> +            bb.build.addtask('do_copy_wks_template', 'do_transform_template do_wic_image', None, d)
> +            bb.build.addtask('do_transform_template', 'do_wic_image', None, d)
>   }
>   
>   inherit buildchroot
> 


-- 
Maxim Osipov
ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn
Germany
+49 (151) 6517 6917
mosipov@ilbers.de
http://ilbers.de/
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-25 16:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-13 13:05 [PATCH] wic-img: switch over to use the template.bbclass mechanism claudius.heine.ext
2019-03-13 13:16 ` Henning Schild
2019-03-13 13:18   ` Claudius Heine
2019-03-25 16:35 ` Maxim Yu. Osipov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox