<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>11372</bug_id>
          
          <creation_ts>2017-04-18 10:31:10 +0000</creation_ts>
          <short_desc>image.bbclass forces some flags for do_image_X tasks</short_desc>
          <delta_ts>2017-06-29 07:58:53 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>core</component>
          <version>2.3</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>2.4 M2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ola Nilsson">ola.x.nilsson</reporter>
          <assigned_to name="Ed Bartosh">eduard.bartosh</assigned_to>
          <cc>eduard.bartosh</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>ross.burton</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>72582</commentid>
    <comment_count>0</comment_count>
    <who name="Ola Nilsson">ola.x.nilsson</who>
    <bug_when>2017-04-18 10:31:10 +0000</bug_when>
    <thetext>The anonymous python function in image.bbclass that creates that do_image_X functions sets a number of flags for each of these functions.

Some of those flags can be useful to set or append to from an image_Y.bbclass that is inherited using the IMAGE_CLASSES variable.  However, image.bbclass sets all flags using setVarFlag which will overwrite any previous value.

The current flags that could be a problem are prefuncs, postfuncs, and subimages.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74137</commentid>
    <comment_count>1</comment_count>
    <who name="Ed Bartosh">eduard.bartosh</who>
    <bug_when>2017-06-14 09:10:41 +0000</bug_when>
    <thetext>Fixed by using appendVarFlag instead of setVarFlag:
http://lists.openembedded.org/pipermail/openembedded-core/2017-June/138103.html

please, review</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74140</commentid>
    <comment_count>2</comment_count>
    <who name="Ola Nilsson">ola.x.nilsson</who>
    <bug_when>2017-06-14 12:16:31 +0000</bug_when>
    <thetext>I&apos;m not sure this is enough. 

A simple anon python function in image_X.bbclass cannot just appendVarFlag to do_image_X[postfuncs] if it important that the function is executed after the functions added by image.bbclass.

This:

image_X.bbclass:

IMAGE_CMD_X = &quot;make_X_image&quot;

python() {
    d.appendVarFlag(&apos;do_image_X&apos;, &apos;postfuncs&apos;, &apos; after_symlinks_function&apos;)
}

MACHINE.conf: 

IMAGE_CLASSES += &quot;image_X&quot;
IMAGE_FSTYPES += &quot;X&quot;

after_symlinks_function will be executed before create_symlinks as the anon python in image_X.bbclass will execute first. 

Is it possible to move the anon function to before the inherit statement?

Otherwise I can think of these three solutions, but I&apos;m not really happy with either of them:

1) Add variables IMAGE_X_BEFORE_POSTFUNC amd IMAGE_X_AFTER_POSTFUNC to each varflag respectively.

appendVarFlag(task, &apos;postfuncs&apos;, &apos;${IMAGE_X_BEFORE_POSTFUNCS} .... ${IMAGE_X_AFTER_POSTFUNCS}&apos;

2) do not set varflags in image.bbclass. Use a variable like IMAGE_CMD_POSTFUNCS in the generated function instead.

3) Add some kind of hook in the anon python function.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74202</commentid>
    <comment_count>3</comment_count>
    <who name="Ed Bartosh">eduard.bartosh</who>
    <bug_when>2017-06-15 14:04:34 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; I&apos;m not sure this is enough. 
&gt; 
&gt; A simple anon python function in image_X.bbclass cannot just appendVarFlag
&gt; to do_image_X[postfuncs] if it important that the function is executed after
&gt; the functions added by image.bbclass.
&gt; 
&gt; This:
&gt; 
&gt; image_X.bbclass:
&gt; 
&gt; IMAGE_CMD_X = &quot;make_X_image&quot;
&gt; 
&gt; python() {
&gt;     d.appendVarFlag(&apos;do_image_X&apos;, &apos;postfuncs&apos;, &apos; after_symlinks_function&apos;)
&gt; }
&gt; 
&gt; after_symlinks_function will be executed before create_symlinks as the anon
&gt; python in image_X.bbclass will execute first. 
&gt; 
&gt; Is it possible to move the anon function to before the inherit statement?

Considering current complexity of image.bbclass code I&apos;m hesitating to move it. It can cause unpredictable effects. I can try if we don&apos;t come up with something better.

I&apos;m not sure it&apos;s a good idea to assume that postfuncs are run in one or another order. What if yo need to run your function before create_symlinks?

If you want to enforce order would it be acceptable to use setVarFlag and take care of the order in your postfunc, e.g.

python() {
    d.setVarFlag(&apos;do_image_X&apos;, &apos;postfuncs&apos;, &apos;my_postfunc&apos;)
}

python my_postfunc () {
    create_symlinks()
    # put your code here
}


&gt; Otherwise I can think of these three solutions, but I&apos;m not really happy
&gt; with either of them:
&gt; 
&gt; 1) Add variables IMAGE_X_BEFORE_POSTFUNC amd IMAGE_X_AFTER_POSTFUNC to each
&gt; varflag respectively.
&gt; 
&gt; appendVarFlag(task, &apos;postfuncs&apos;, &apos;${IMAGE_X_BEFORE_POSTFUNCS} ....
&gt; ${IMAGE_X_AFTER_POSTFUNCS}&apos;
&gt; 
&gt; 2) do not set varflags in image.bbclass. Use a variable like
&gt; IMAGE_CMD_POSTFUNCS in the generated function instead.
&gt; 
&gt; 3) Add some kind of hook in the anon python function.

I&apos;m not happy about my proposal as well to be honest.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74222</commentid>
    <comment_count>4</comment_count>
    <who name="Ola Nilsson">ola.x.nilsson</who>
    <bug_when>2017-06-15 15:12:58 +0000</bug_when>
    <thetext>&gt; Considering current complexity of image.bbclass code I&apos;m hesitating to move it. &gt; It can cause unpredictable effects. I can try if we don&apos;t come up 
&gt; with something better.

Understandable.

&gt; I&apos;m not sure it&apos;s a good idea to assume that postfuncs are run in one 
&gt; or another order. What if yo need to run your function 
&gt; before create_symlinks?
&gt;
&gt; If you want to enforce order would it be acceptable to use setVarFlag 
&gt; and take care of the order in your postfunc, e.g.
&gt;
&gt; python() {
&gt;     d.setVarFlag(&apos;do_image_X&apos;, &apos;postfuncs&apos;, &apos;my_postfunc&apos;)
&gt; }
&gt; 
&gt; python my_postfunc () {
&gt;     create_symlinks()
&gt;     # put your code here
&gt; }

This wont work because of the ordering.  Since image_X.bbclass will be inherited before the problematic anon in image.bbclass we would end up with
&quot;my_postfunc create_symlinks&quot;

I&apos;ve actually done 
create_symlinks_append() {
   other_func()
}
but I felt unclean afterwards :)

How about this (without your cleanup):

        d.setVar(&apos;do_image_%s&apos; % t, &apos;\n&apos;.join(cmds))
        d.setVarFlag(&apos;do_image_%s&apos; % t, &apos;func&apos;, &apos;1&apos;)
        d.setVarFlag(&apos;do_image_%s&apos; % t, &apos;fakeroot&apos;, &apos;1&apos;)
        d.setVarFlag(&apos;do_image_%s&apos; % t, &apos;prefuncs&apos;, &apos;${IMAGE_&apos; + t.upper() + &apos;_PREFUNCS}&apos;)
        d.appendVar(&apos;IMAGE_&apos; + t.upper() + &apos;_PREFUNCS&apos;, &apos; &apos; + debug + &apos; set_image_size&apos;)
        d.setVarFlag(&apos;do_image_%s&apos; % t, &apos;postfuncs&apos;, &apos;${IMAGE_&apos; + t.upper() + &apos;_POSTFUNCS}&apos;)
        d.appendVar(&apos;IMAGE_&apos; + t.upper() + &apos;_POSTFUNCS&apos;,  create_symlinks&apos;)
        d.setVarFlag(&apos;do_image_%s&apos; % t, &apos;subimages&apos;, &apos; &apos;.join(subimages))
        d.appendVarFlag(&apos;do_image_%s&apos; % t, &apos;vardeps&apos;, &apos; &apos;.join(vardeps))
        d.appendVarFlag(&apos;do_image_%s&apos; % t, &apos;vardepsexclude&apos;, &apos;DATETIME&apos;)

If IMAGE_X_PREFUNCS is set by image_X.bbclass the value will be appended to, and image_X.bbclass can use IMAGE_X_PREFUNCS_append if it needs to.

We can let this rest for a while and I will try out your patches properly and see how it works.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74233</commentid>
    <comment_count>5</comment_count>
    <who name="Ed Bartosh">eduard.bartosh</who>
    <bug_when>2017-06-15 15:36:56 +0000</bug_when>
    <thetext>&gt; How about this

That could work, but I don&apos;t like introducing 2 more variables.

How about this? 

@@ -497,12 +497,16 @@ python () {
         d.setVarFlag(task, &apos;func&apos;, &apos;1&apos;)
         d.setVarFlag(task, &apos;fakeroot&apos;, &apos;1&apos;)
 
-        d.appendVarFlag(task, &apos;prefuncs&apos;, &apos; &apos; + debug + &apos; set_image_size&apos;)
-        d.appendVarFlag(task, &apos;postfuncs&apos;, &apos; create_symlinks&apos;)
+        prefuncs = d.getVarFlag(task, &apos;prefuncs&apos;) or &apos;&apos;
+        d.setVarFlag(task, &apos;prefuncs&apos;, debug + &apos; set_image_size &apos; + prefuncs)
+        postfuncs = d.getVarFlag(task, &apos;postfuncs&apos;) or &apos;&apos;
+        d.setVarFlag(task, &apos;postfuncs&apos;, &apos;create_symlinks &apos; + postfuncs)
         d.appendVarFlag(task, &apos;subimages&apos;, &apos; &apos; + &apos; &apos;.join(subimages))
         d.appendVarFlag(task, &apos;vardeps&apos;, &apos; &apos; + &apos; &apos;.join(vardeps))
         d.appendVarFlag(task, &apos;vardepsexclude&apos;, &apos;DATETIME&apos;)

I&apos;m using updated code as my patch is in master already.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74243</commentid>
    <comment_count>6</comment_count>
    <who name="Ola Nilsson">ola.x.nilsson</who>
    <bug_when>2017-06-15 16:49:28 +0000</bug_when>
    <thetext>Isn&apos;t that the same as prependVarFlag?
And then it wont be possible to add anything before the functions added by image.bbclass.

How about if prefuncs are added with append and postfuncs with prepend, and then image_X.bbclass can add code with either pre/post-funcs or do_image_x_append or _prepend. The execution order would be

image_X prefuncs
image prefuncs
do_image_X_prepend from image_X.bbclass
do_image_X from image.bbclass
do_image_X_append from image_X.bbclass
image postfuncs
image_X postfuncs

Then it would be possible to achieve any order, but the default implementation is still simple. 

Obviously not many image types will use this, so I think you are right in keeping it simple.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74271</commentid>
    <comment_count>7</comment_count>
    <who name="Ed Bartosh">eduard.bartosh</who>
    <bug_when>2017-06-16 09:17:41 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; Isn&apos;t that the same as prependVarFlag?
&gt; And then it wont be possible to add anything before the functions added by
&gt; image.bbclass.
&gt; 
&gt; How about if prefuncs are added with append and postfuncs with prepend, and
&gt; then image_X.bbclass can add code with either pre/post-funcs or
&gt; do_image_x_append or _prepend. The execution order would be
&gt; 
&gt; image_X prefuncs
&gt; image prefuncs
&gt; do_image_X_prepend from image_X.bbclass
&gt; do_image_X from image.bbclass
&gt; do_image_X_append from image_X.bbclass
&gt; image postfuncs
&gt; image_X postfuncs
&gt; 
&gt; Then it would be possible to achieve any order, but the default
&gt; implementation is still simple. 
&gt; 
&gt; Obviously not many image types will use this, so I think you are right in
&gt; keeping it simple.

Thank you! That&apos;s a nice idea!

So, this tiny patch is what should do the trick, right?

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 9a04b43..be8c9dd 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -498,7 +498,7 @@ python () {
         d.setVarFlag(task, &apos;fakeroot&apos;, &apos;1&apos;)
 
         d.appendVarFlag(task, &apos;prefuncs&apos;, &apos; &apos; + debug + &apos; set_image_size&apos;)
-        d.appendVarFlag(task, &apos;postfuncs&apos;, &apos; create_symlinks&apos;)
+        d.prependVarFlag(task, &apos;postfuncs&apos;, &apos; create_symlinks&apos;)
         d.appendVarFlag(task, &apos;subimages&apos;, &apos; &apos; + &apos; &apos;.join(subimages))
         d.appendVarFlag(task, &apos;vardeps&apos;, &apos; &apos; + &apos; &apos;.join(vardeps))
         d.appendVarFlag(task, &apos;vardepsexclude&apos;, &apos;DATETIME&apos;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74272</commentid>
    <comment_count>8</comment_count>
    <who name="Ola Nilsson">ola.x.nilsson</who>
    <bug_when>2017-06-16 10:06:09 +0000</bug_when>
    <thetext>(In reply to comment #7)
&gt; (In reply to comment #6)
&gt; Thank you! That&apos;s a nice idea!
&gt; 
&gt; So, this tiny patch is what should do the trick, right?
&gt; 
&gt; diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
&gt; index 9a04b43..be8c9dd 100644
&gt; --- a/meta/classes/image.bbclass
&gt; +++ b/meta/classes/image.bbclass
&gt; @@ -498,7 +498,7 @@ python () {
&gt;          d.setVarFlag(task, &apos;fakeroot&apos;, &apos;1&apos;)
&gt;  
&gt;          d.appendVarFlag(task, &apos;prefuncs&apos;, &apos; &apos; + debug + &apos; set_image_size&apos;)
&gt; -        d.appendVarFlag(task, &apos;postfuncs&apos;, &apos; create_symlinks&apos;)
&gt; +        d.prependVarFlag(task, &apos;postfuncs&apos;, &apos; create_symlinks&apos;)
&gt;          d.appendVarFlag(task, &apos;subimages&apos;, &apos; &apos; + &apos; &apos;.join(subimages))
&gt;          d.appendVarFlag(task, &apos;vardeps&apos;, &apos; &apos; + &apos; &apos;.join(vardeps))
&gt;          d.appendVarFlag(task, &apos;vardepsexclude&apos;, &apos;DATETIME&apos;)

I think so, yes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74277</commentid>
    <comment_count>9</comment_count>
    <who name="Ed Bartosh">eduard.bartosh</who>
    <bug_when>2017-06-16 12:10:05 +0000</bug_when>
    <thetext>ok, sent for review: http://lists.openembedded.org/pipermail/openembedded-core/2017-June/138339.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>74622</commentid>
    <comment_count>10</comment_count>
    <who name="Ed Bartosh">eduard.bartosh</who>
    <bug_when>2017-06-29 07:58:53 +0000</bug_when>
    <thetext>The fix has been accepted to poky master. Commit id: 6fa6099b493f9fb164bda5f66e678984da83989e</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>