Bug 14918 - Devtool fails if SRCREV is set to ${AUTOREV}
Summary: Devtool fails if SRCREV is set to ${AUTOREV}
Status: RESOLVED FIXED
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: 4.0.4
Hardware: x86 Multiple
: Medium+ normal
Target Milestone: 5.0 M4
Assignee: Yoann Congal
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2022-09-27 07:20 UTC by Shibi Krishnamoorthy
Modified: 2024-03-05 15:54 UTC (History)
5 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: Regression (Used to work)
Verified:
Documentation change: Don't know


Attachments
Devtool error log (5.58 KB, application/octet-stream)
2022-09-27 07:20 UTC, Shibi Krishnamoorthy
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Shibi Krishnamoorthy 2022-09-27 07:20:23 UTC
Created attachment 4905 [details]
Devtool error log

Devtool fails after first recipe package devtool modify. Check scenario below


We perform yocto build and do devtool modify for one of package it works
if we perform devtool modify for another package without resetting the previously modified package we are getting below error in modified package during parsing bb step 

recipefile(.bb):
 
SRC_URI="git://git.com/pkg/linux;branch=mulberry-5.10;protocol=ssh;name=linux;destsuffix=git
 
SRCREV = "${AUTOREV}"
 
PV = "5.10+git${SRCPV}"
 
Yocto version: Kirkstone
BB_SRCREV_POLICY = "clear"

Steps to reproduce:
1. set SRCREV=${AUTOREV} in two/ three recipe file 
2. devtool modify <recipe-1 name>
3. devtool modify <recipe-2 name>

Expected Result:
1. create workspace, checkout the source code and set to build yocto from from external sources

Actual result:
1. Bitbake Fails at parsing recipe file (attached error log)


Additional Information: 
1. Error is reproduced only in Kirkstone ( unable to reproduce above issue Hardknott and Dunfell) 
2. Patch which is causing this issue
https://lists.openembedded.org/g/bitbake-devel/topic/89051455#13344 
3. If we set BB_SRCREV_POLICY = "cache" or fixed SRCREV it works without any issues
4. Topic in Mailing list https://lists.openembedded.org/g/bitbake-devel/topic/89051455#13344
Comment 2 Yoann Congal 2023-10-04 23:13:59 UTC
I've got another reproducer :
This recipe cmakehelloworld_git.bb:
----------------
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=be316b0d6cb4f744b08c9dc589a13eff"
SUMMARY = "XXX"
HOMEPAGE = "http://example.org"
SRC_URI = "git://github.com/jameskbride/cmake-hello-world.git;protocol=https;branch=master"
PV = "1.0+git"
SRCREV = "${AUTOREV}"
S = "${WORKDIR}/git"
inherit cmake
EXTRA_OECMAKE = ""
FILES:${PN}-staticdev:append = " /usr/bin/libHello.a"
----------------

And a symlink cmakehelloworld2_git.bb -> cmakehelloworld_git.bb

With these :
# clear workspace
rm -rf build/workspace/
sed -i '/workspace/d' build/conf/bblayers.conf
# devtool modify 2 AUTOREV recipes
devtool modify cmakehelloworld
devtool modify cmakehelloworld2


Result, this fail on kirkstone but not on master (Same log as reporter)

I've bisected the fix : commit 62afa02d01794376efab75623f42e7e08af08526 [0] does allow the second devtool modify to work correctly.

Sadly, this commit can't be trivially backported to kirkstone (event after paths fix, bitbake crashes on missing functions)

[0] https://git.yoctoproject.org/poky/commit/?id=62afa02d01794376efab75623f42e7e08af08526
commit 62afa02d01794376efab75623f42e7e08af08526
Author: Richard Purdie <richard.purdie@linuxfoundation.org>
Date:   Fri Aug 11 13:52:59 2023 +0100

    base/package: Move source revision information from PV to PKGV
    
    Source control information being present in PV used to be a hard requirement
    for bitbake to operate correctly. Now that hashes are a required part of task
    stamps, this requirement no longer exists.
    
    This means we can defer the hash pieces to PKGV and simplify PV.
    
    Use new bitbake fetcher API to inject the source revisions directly into the hash
    allowing removal of some horrible code from base.bbclass and avoiding any hardcoding
    about how SRCREV may or may not be used.
    
    Use that API to object the string to append to PKGV and append that directly.
    
    The user visible effect of this change is that PV will no longer have revision
    information in it and this will now be appended to PV through PKGV when the
    packages are written. Since PV is used in STAMP and WORKDIR, users will see
    small directory naming and stamp naming changes.
    
    This will mean that sstate reuse through hash equivalence where the source
    revision changes but the output does not will become possible as the sstate
    naming will become less specific and no longer contain the revision.
    
    The SRCPV variable will no longer be needed in PV and is effectively now just
    a null operation. Usage can be removed over time.
    
    (From OE-Core rev: a8e7b0f932b9ea69b3a218fca18041676c65aba0)
    
    Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Comment 3 Yoann Congal 2023-11-08 22:53:14 UTC
Chris Wyse proposed a fix here : https://lists.yoctoproject.org/g/yocto/message/61639 :
> I ran into this problem as well.  It doesn't seem like SRCPV is being set
> properly before use in the externalsrc.bbclass.  I added the following line
> before bpn = d.getVar('BPN'), and now it works fine.  Unfortunately, I needed
> to create another layer that overrides the poky classes to include it in my
> build.  Here's the added line:
>
>   srcpv = d.getVar('SRCPV')

In patch format (in OE-core kirkstone branch) :

diff --git a/meta/classes/externalsrc.bbclass b/meta/classes/externalsrc.bbclass
index 97d7379d9f..41f87b2ef8 100644
--- a/meta/classes/externalsrc.bbclass
+++ b/meta/classes/externalsrc.bbclass
@@ -36,6 +36,8 @@ python () {
     if externalsrcbuild and not externalsrcbuild.startswith("/"):
         bb.error("EXTERNALSRC_BUILD must be an absolute path")
 
+    srcpv = d.getVar('SRCPV')
+
     # If this is the base recipe and EXTERNALSRC is set for it or any of its
     # derivatives, then enable BB_DONT_CACHE to force the recipe to always be
     # re-parsed so that the file-checksums function for do_compile is run every
Comment 4 Yoann Congal 2023-12-07 08:15:56 UTC
Chris Wyse's proposal does indeed fix the problem:
  srcpv = d.getVar('SRCPV')

Notes:
* srcpv is unused afterward so creating this variable is useless.
* The fix is in reading "SRCPV" : while expanding it, it does run bb.fetch2.get_srcrev(d) (setting up __BBSEENSRCREV)
* So, the problem is that on the second devtool modify, bb.fetch2.get_srcrev(d) is not called before accessing SRC_URI and trigger this FetchError:
File: '.../poky/bitbake/lib/bb/fetch2/git.py', lineno: 743, function: _latest_revision
     0739:        """
     0740:        Compute the HEAD revision for the url
     0741:        """
     0742:        if not d.getVar("__BBSEENSRCREV"):
 *** 0743:            raise bb.fetch2.FetchError("Recipe uses a floating tag/branch '%s' for repo '%s' without a fixed SRCREV yet doesn't call bb.fetch2.get_srcrev() (use SRCPV in PV for OE)." % (ud.unresolvedrev[name], ud.host+ud.path))
     0744:
     0745:        # Ensure we mark as not cached
     0746:        bb.fetch2.get_autorev(d)
     0747:


https://git.yoctoproject.org/poky/commit/?id=62afa02d01794376efab75623f42e7e08af08526 does fix this by calling bb.fetch.get_hashvalue(d) before accessing SRC_URI.
Comment 5 Yoann Congal 2023-12-07 16:48:56 UTC
As discussed in triage meeting:
* As the master fix is too invasive, a workaround for kirkstone is acceptable
* d.getVar('SRCPV') might have other side-effect (One side-effect being a work-around this bug)
* I'll clean up the current workaround and propose it for review.
Comment 6 Yoann Congal 2023-12-07 22:35:24 UTC
Patch sent:
[kirkstone][PATCH] externalsrc: Ensure SRCREV is processed before accessing SRC_URI
https://lists.openembedded.org/g/openembedded-core/message/191978
Comment 7 Yoann Congal 2023-12-14 21:45:10 UTC
Steve Sakoman wrote :
> This patch resulted in oe-seftest failures on the autobuilder:
> https://autobuilder.yoctoproject.org/typhoon/#/builders/83/builds/6322
> 
> A representative log:
> https://errors.yoctoproject.org/Errors/Details/746003/

I can reproduce this problem locally with:
  oe-selftest -r devtool.DevtoolUpdateTests.test_devtool_update_recipe_local_files_subdir -T machine -T toolchain-user -T toolchain-system -j 15

The interesting part of the log:
Parsing recipes...ERROR: /home/yocon/Documents/projets/yocto/poky/build-kirkstone-st-2699726/meta-selftest/recipes-test/devtool/devtool-test-subdir.bb: Error executing a python function in <code>:

The stack trace of python calls that resulted in this exception/failure was:
File: '<code>', lineno: 10, function: <module>
     0006:__anon_725__tmp_devtoolqa8gqhqvbu_core_copy_meta_classes_package_rpm_bbclass(d)
     0007:__anon_29__tmp_devtoolqa8gqhqvbu_core_copy_meta_classes_debian_bbclass(d)
     0008:__anon_36__tmp_devtoolqa8gqhqvbu_core_copy_meta_classes_devshell_bbclass(d)
     0009:__anon_162__tmp_devtoolqa8gqhqvbu_core_copy_meta_classes_sstate_bbclass(d)
 *** 0010:__anon_149__tmp_devtoolqa8gqhqvbu_core_copy_meta_classes_externalsrc_bbclass(d)
File: '/tmp/devtoolqa8gqhqvbu/core-copy/meta/classes/externalsrc.bbclass', lineno: 66, function: __anon_149__tmp_devtoolqa8gqhqvbu_core_copy_meta_classes_externalsrc_bbclass
     0062:        else:
     0063:            d.setVar('B', '${WORKDIR}/${BPN}-${PV}')
     0064:
     0065:        # Ensure SRCREV has been processed before accessing SRC_URI
 *** 0066:        bb.fetch.get_srcrev(d)
     0067:
     0068:        local_srcuri = []
     0069:        fetch = bb.fetch2.Fetch((d.getVar('SRC_URI') or '').split(), d)
     0070:        for url in fetch.urls:
File: '/home/yocon/Documents/projets/yocto/poky/bitbake/lib/bb/fetch2/__init__.py', lineno: 782, function: get_srcrev
     0778:        if urldata[u].method.supports_srcrev():
     0779:            scms.append(u)
     0780:
     0781:    if not scms:
 *** 0782:        raise FetchError("SRCREV was used yet no valid SCM was found in SRC_URI")
     0783:
     0784:    if len(scms) == 1 and len(urldata[scms[0]].names) == 1:
     0785:        autoinc, rev = getattr(urldata[scms[0]].method, method_name)(urldata[scms[0]], d, urldata[scms[0]].names[0])
     0786:        if len(rev) > 10:
Exception: bb.fetch2.FetchError: Fetcher failure: SRCREV was used yet no valid SCM was found in SRC_URI

Maybe I need to call get_srcrev() unconditionally, call it only if it supports srcrev()?
Comment 8 Yoann Congal 2023-12-19 07:00:59 UTC
Bumping target milestone to 5.0 M2
Comment 9 Yoann Congal 2024-01-23 14:39:29 UTC
Bulk move to Milestone 5.0 M3
Comment 10 Yoann Congal 2024-02-22 16:23:31 UTC
Bulk move to 5.0 M4