On 22/01/2020 15.35, Richard Purdie wrote:
> On Wed, 2020-01-22 at 13:55 +0000, Rasmus Villemoes wrote:
>> I have a do_configure() python function which is essentially
>>
>> python do_configure() {
>>     import fileinput
>>     with open("foo.txt", "w") as out:
>>         for line in
>> fileinput.input(files=d.getVar("FOO_INPUT").split()):
>>             line = d.expand(line)
>>             out.write(line)
>> }
>>
>> So some of those input files can contain ${VARIABLE} and it gets
>> replaced appropriately. But to my surprise, when I then change
>> VARIABLE,
>> the recipe doesn't get rebuilt, so it seems that bitbake doesn't
>> automatically realize that the recipe (or task) depends on VARIABLE.
>>
>> So digging a bit into the code, it seems that d.expand() calls
>> expandWithRefs(), which returns a VariableParse object, but then only
>> uses the .value property, throwing away .references. So I assume that
>> what I really should be doing is call expandWithRefs and then somehow
>> manually pass .references to... something? Or, there must be some
>> other
>> bitbake interface for doing this properly?
> 
> Bitbake can only detect direct references to variables. The code above
> only runs at configure time, not at parse time so its not really
> surprising that bitbake can't know what its doing.

Well, I thought that as well at first. But there must be something done
at run-time to feed back the variable dependencies, because if I add a
completely dumb

python do_configure() {
    import fileinput
+    d.getVar("VARIABLE") # silly
    with open("foo.txt", "w") as out:
        for line in fileinput.input(files=d.getVar("FOO_INPUT").split()):
            line = d.expand(line)
            out.write(line)
}

build the recipe (because now it has of course changed), and then change
VARIABLE, the recipe does get re-built. Or does bitbake specifically
look for d.getVar(<literal>) when it parses a python function?

> You'd need to read the data from this file at parse time for bitbake to
> stand some chance of seeing it, or manually set the variables it
> depends upon using the vardeps flag.
> 
> Something like:
> 
> do_configure[vardeps] = "${@my_depends_function(d)}"
> 
> where my_depends_function would return a list of variables it
> references.
> 
> Reading files like that at parse time doesn't work out well for
> performance.

Yeah, so I'd very much like to avoid that, and the above observation
suggests that I might be able to do the expansion manually, just looking
for the \$\{...\} regexp and calling getVar to find the replacement. But
that seems like something that should be solved already.

Thanks,
Rasmus
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#48084): https://lists.yoctoproject.org/g/yocto/message/48084
Mute This Topic: https://lists.yoctoproject.org/mt/69979676/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub  
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to