<?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>10096</bug_id>
          
          <creation_ts>2016-08-08 11:18:20 +0000</creation_ts>
          <short_desc>Allow PREFERRED_VERSION miss to be fatal</short_desc>
          <delta_ts>2021-03-18 15:03:22 +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>BitBake</product>
          <component>bitbake</component>
          <version>unspecified</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>NEWCOMER</status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>3.3 M3</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Niko Mauno">niko.mauno</reporter>
          <assigned_to name="Charles Davies">charles.davies</assigned_to>
          <cc>bluelightning</cc>
    
    <cc>charles.davies</cc>
    
    <cc>poky.bs.watcher</cc>
    
    <cc>poky.watcher</cc>
    
    <cc>randy.macleod</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Yes (doc changes required)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>64941</commentid>
    <comment_count>0</comment_count>
    <who name="Niko Mauno">niko.mauno</who>
    <bug_when>2016-08-08 11:18:20 +0000</bug_when>
    <thetext>When creating releases of Yocto-framework generated OS images containing components which should be enforced to a certain version, it sometimes occurs that an undesired version of some package(s) is/are included, which has the tendency to slow down release cycles. 

Yocto/OE have PREFERRED_VERSION_packagename = &quot;&lt;version&gt;&quot; support already since OE-classic, but even years have passed, a sufficiently well-established method to enforce certain packages to certain specific versions when bitbaking, doesn&apos;t however seem to have emerged.

I currently am able to fatalize PREFERRED_VERSION misses by definitions like:
RDEPENDS_${PN} = &quot;package-foo ( = 1.2.3 )&quot;
but this doesn&apos;t quite provide the desired behaviour, as the version miss error seems to occur typically at very late point of bitbaking process, namely do_rootfs @ satisfy_dependencies_for. 
If version misses would break the build already when bitbake performs initial recipe parsing, right after it is started, it wouldn&apos;t take potentially several hours to detect the version miss.
Furthermore packages which are built, but aren&apos;t installed to target image don&apos;t seem to be able to utilize the above RDEPENDS_${PN} approach.

Thus I respectfully call for a method to fatalize situations when a PREFERRED_VERSION of package is unavailable, as in current &quot;fallback&quot; behaviour bitbake (despite reporting such incidences) happily continues building non-preferred version of the package (as long as there is another version of package/recipe available to fall back to).

I briefly looked into this and found that the following addition, which introduces a new PREFERRED_VERSIONS_ARE_REQUIRED (feel free to change to more apposite name) variable, would add an optional &quot;quick fatalization&quot; behaviour in case of PREFERRED_VERSION miss to bitbake:

diff --git a/bitbake/lib/bb/providers.py b/bitbake/lib/bb/providers.py
index 637e1fa..b6bf2ba 100644
--- a/bitbake/lib/bb/providers.py
+++ b/bitbake/lib/bb/providers.py
@@ -174,6 +174,9 @@ def findPreferredProvider(pn, cfgData, dataCache, pkg_pn = None, item = None):
             if available_vers:
                 available_vers.sort()
                 logger.info(&quot;versions of %s available: %s&quot;, pn, &apos; &apos;.join(available_vers))
+            preferred_required = localdata.getVar(&apos;PREFERRED_VERSIONS_ARE_REQUIRED&apos;, True)
+            if preferred_required and preferred_required not in (&quot;0&quot;, &quot;False&quot;):
+                bb.fatal(&quot;PREFERRED_VERSIONS_ARE_REQUIRED is set, preferred version not found for %s&quot; % pn)
         else:
             logger.debug(1, &quot;selecting %s as PREFERRED_VERSION %s of package %s%s&quot;, preferred_file, pv_str, pn, itemstr)


For completeness; I also thought that another, perhaps more appropriate way to fulfill this feature gap could maybe be to add a new REQUIRED_VERSION_packagename = &quot;&lt;version&gt;&quot; (in parallel to existing PREFERRED_VERSION_packagename = &quot;&lt;version&gt;&quot;) support in bitbake. But this I didn&apos;t have the time to look further into currently.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89261</commentid>
    <comment_count>1</comment_count>
    <who name="Charles Davies">charles.davies</who>
    <bug_when>2021-02-14 11:05:43 +0000</bug_when>
    <thetext>My initial thoughts on this are the following; the reporter&apos;s first suggestion of PREFERRED_VERSIONS_ARE_REQUIRED has too much of a global effect on the PREFERRED_VERSION behaviour.

The solution that I would propose is to follow the reporter&apos;s second suggestion and introduce a REQUIRED_VERSION_&lt;packagename&gt; alongside PREFERRED_VERSION_&lt;packagename&gt;. This solution allows for a party to enforce a particular version of a package if they desire whilst still maintaining the behaviour (and usefulness) of PREFERRED_VERSION.

As for the reporter&apos;s requirement to fail quickly, on initial recipe parsing, changes to the area of code (bitbake/lib/bb/providers.py) the reporter mentions would have this effect.

Going forward I will add the necessary code to facilitate the use of REQUIRED_VERSION if this is deemed to be a suitable solution?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89275</commentid>
    <comment_count>2</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2021-02-16 21:37:14 +0000</bug_when>
    <thetext>Hi Charles,
Since no one has replied, please send a comment or patch to the list:
  https://lists.openembedded.org/g/bitbake-devel
Thanks,
../Randy</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89276</commentid>
    <comment_count>3</comment_count>
    <who name="Charles Davies">charles.davies</who>
    <bug_when>2021-02-17 00:33:40 +0000</bug_when>
    <thetext>Hi Randy,

I have gone ahead and started to work on a patch which adds a REQUIRED_VERSION variable and will submit patch when ready to mailing list. This will be a good starting point for comments regarding the best approach to solve this bug.

Kind Regards,

Charles</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89300</commentid>
    <comment_count>4</comment_count>
    <who name="Charles Davies">charles.davies</who>
    <bug_when>2021-02-18 21:03:04 +0000</bug_when>
    <thetext>First version of patches submitted to mailing list:

https://lists.openembedded.org/g/bitbake-devel/topic/rfc_patch_0_9_addition_of/80740556?p=,,,20,0,0,0::recentpostdate%2Fsticky,,,20,2,0,80740556</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>89650</commentid>
    <comment_count>5</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2021-03-18 15:03:22 +0000</bug_when>
    <thetext>Fixed by:

https://git.openembedded.org/openembedded-core/commit/?id=05ba2df8e565589cf7b0b7cedcb96c7fdf97298b

and bitbake:

https://git.openembedded.org/bitbake/commit/?id=5df201d746f26154213e6d15d2721cd35b38b59e

and others.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>