Hi Sai,

On Tue, 2026-05-19 at 15:39 +0530, Sai Sneha via lists.openembedded.org
wrote:

<snip>

> +def check_srcrev_set(d):
> +    import bb.fetch2
> +    src_uri = (d.getVar('SRC_URI', False) or '').split()
> +    pn = d.getVar('PN')
> +    found_issue = False
> +    for uri in src_uri:
> +        try:
> +            (scheme, _, _, _, _, params) = bb.fetch2.decodeurl(uri)
> +        except Exception:
> +            continue
> +        if scheme not in ('git', 'gitsm', 'hg', 'svn'):
> +            continue
> +        if params.get('rev', ''):
> +            continue
> +        name = params.get('name', '') or 'default'

Use
    name = params.get('name', 'default')

> +        candidates = [
> +            'SRCREV_%s:pn-%s' % (name, pn),
> +            'SRCREV_%s' % name,
> +            'SRCREV:pn-%s' % pn,
> +            'SRCREV',
> +        ]

Consider using f-strings here:

    candidates = [
        f'SRCREV_{name}:pn-{pn}',
        f'SRCREV_{name}'
        f'SRCREV:pn-{pn}'
        'SRCREV'
    ]

Maybe also reverse the list, so plain 'SRCREV' is tested first, as that
is the most common variable used for SCM revision.

> +        raw = None

Why is this variable named 'raw'? Should it be 'rev'?

> +        for candidate in candidates:
> +            raw = d.getVar(candidate, False)
> +            if raw:
> +                break

I would use a `for-else` block:

    for candidate in candidates:
        rev = d.getVar(candidate, False)
        if rev and rev == 'INVALID':
            break
    else:
       # report and return error

    return False
        

> +        if not raw or raw == 'INVALID':
> +            found_issue = True
> +            if bb.utils.contains('ERROR_QA', 'missing-srcrev', True,
> False, d):
> +                bb.error("%s: %s not set for %s" % (pn, candidates[-
> 1], uri))
> +            elif bb.utils.contains('WARN_QA', 'missing-srcrev',
> True, False, d):
> +                bb.warn("%s: %s not set for %s" % (pn, candidates[-
> 1], uri))
> +        elif '${AUTOREV}' in raw:
> +            return True
> +    return not found_issue

I'm confused about the return value of this function. Add a short doc-
string explaining what is indicated by True and False.

Also, drop the use of the `found_issue` variable, and reorder the code
to return 'True' or 'False' directly from the right places.

// Martin

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#237385): 
https://lists.openembedded.org/g/openembedded-core/message/237385
Mute This Topic: https://lists.openembedded.org/mt/119387996/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to