Re: [yocto] Path to current bb-file or layer

2017-09-22 Thread Svein Seldal



On 22. sep. 2017 13:42, Richard Purdie wrote:

A better way to get what you're after may be to look at the contents
of BBINCLUDED.


Ah, yes. Perfect. You got me onto a lead: Setting SP_BASEDIR := 
"${LAYERDIR}" in layer.conf and then access this variable from the 
bbclass file.


Although I would like to suggest that bitbake should have a FILE-ish 
variable that points to the actual running current file. Especially when 
bbclass files is thought to act as generic black-box-ish collection of 
funtions.


Thank you Richard


Best regards,
Svein
--
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto


Re: [yocto] Path to current bb-file or layer

2017-09-22 Thread Richard Purdie
On Fri, 2017-09-22 at 13:04 +0200, Svein Seldal wrote:
> On 22. sep. 2017 10:30, Richard Purdie wrote:
> > Its all about when your code is executed. Try putting:
> > 
> > SP_BASEVERSION := "${@read_spbaseversion(d)}"
> > 
> > in the bbclass file. I suspect that will give you the bbclass file
> > name.
> > 
> > By default everything is deferred expansion so your code would give
> you
> > the final .bb as that is the context the code is run in.
> 
> In local.conf I put:
> 
>  INHERIT += "sp-version"
> 
> In classes/sp-version.bbclass
> 
>  def read_spbaseversion(d):
> # The goal of this function is to read and
> # parse a file from the layer
>  bb.warn("MYSELF: ", d.getVar('FILE', False))
>  return '0'
> 
>  SP_BASEVERSION := "${@read_spbaseversion(d)}"
> 
> Then both on Krogoth and Pyro, the following command returns:
> 
>  $ bitbake -e |tee var.txt |grep MYSELF
> 
> WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
> WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
>  bb.warn("MYSELF: ", d.getVar('FILE', False))
> 
> Likewise:
> 
>  $ bitbake -e sp-image |tee sp-image.txt |grep MYSELF
> 
> WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
> WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
> WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
>  bb.warn("MYSELF: ", d.getVar('FILE', False))
> 
> 
> Is there an alternative to d.getVar() to access the "other" versions
> of the variable?

I suspect I'm misremembering the places that FILE gets reset in the
bitbake parser. It probably changes for conf and bb files and maybe inc
files but not bbclass files.

Why it does that is before my time with the codebase and I've never
really dared change it.

A better way to get what you're after may be to look at the contents
of BBINCLUDED.

Cheers,

Richard


-- 
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto


Re: [yocto] Path to current bb-file or layer

2017-09-22 Thread Svein Seldal


On 22. sep. 2017 10:30, Richard Purdie wrote:

> Its all about when your code is executed. Try putting:
> 
> SP_BASEVERSION := "${@read_spbaseversion(d)}"
> 
> in the bbclass file. I suspect that will give you the bbclass file
> name.
> 
> By default everything is deferred expansion so your code would give you
> the final .bb as that is the context the code is run in.

In local.conf I put:

 INHERIT += "sp-version"

In classes/sp-version.bbclass

 def read_spbaseversion(d):
# The goal of this function is to read and
# parse a file from the layer
 bb.warn("MYSELF: ", d.getVar('FILE', False))
 return '0'

 SP_BASEVERSION := "${@read_spbaseversion(d)}"

Then both on Krogoth and Pyro, the following command returns:

 $ bitbake -e |tee var.txt |grep MYSELF

WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
 bb.warn("MYSELF: ", d.getVar('FILE', False))

Likewise:

 $ bitbake -e sp-image |tee sp-image.txt |grep MYSELF

WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
WARNING: MYSELF: /home/s/bughunt-pyro/build/conf/bblayers.conf
 bb.warn("MYSELF: ", d.getVar('FILE', False))


Is there an alternative to d.getVar() to access the "other" versions of 
the variable?


Best regards,
Svein
-- 
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto


Re: [yocto] Path to current bb-file or layer

2017-09-22 Thread Richard Purdie
On Fri, 2017-09-22 at 10:17 +0200, Svein Seldal wrote:
> On 21. sep. 2017 23:36, Richard Purdie wrote:
>  > You mean like ${FILE} ?
>  >
>  > $ bitbake bash -e | grep ^FILE=
>  > FILE="/media/build1/poky/meta/recipes-extended/bash/bash_4.4.bb"
> 
> To me ${FILE} seems to be pointing towards the receipe, and not the 
> current .bbclass file as you'd expect.
> 
> If I put this in local.conf
> 
>  INHERIT += "sp-version"
>  SP_BASEVERSION = "${@read_spbaseversion(d)}"
> 
> And in sp-version.bbclass:
> 
>  def read_spbaseversion(d):
>  bb.warn("SVEIN FILE: ", d.getVar('FILE', False))
>   return '0'
> 
> If I do bitbake -e, I get
> 
>  WARNING: SVEIN FILE: /home/s/build-sp-
> image/build/conf/bblayers.conf
> 
> Later the read_spbaseversion is used from within recipe (although
> they 
> don't need to as this variable goes into the global scope, but for
> the 
> sake of the demonstration). Then the value being prined is:
> 
> WARNING: /home/s/build-sp-image/meta-sp/sp/sp.bb: SVEIN OPEN: 
> /home/s/build-sp-image/meta-sp/sp/sp.bb
> 
> Hence, ${FILE} seems to point to the current file scope, like a
> recipe, 
> and not any class files that the recipe might take use of.

Its all about when your code is executed. Try putting:

SP_BASEVERSION := "${@read_spbaseversion(d)}"

in the bbclass file. I suspect that will give you the bbclass file
name.

By default everything is deferred expansion so your code would give you
the final .bb as that is the context the code is run in.

Cheers,

Richard
-- 
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto


Re: [yocto] Path to current bb-file or layer

2017-09-22 Thread Svein Seldal


On 21. sep. 2017 23:36, Richard Purdie wrote:
> You mean like ${FILE} ?
>
> $ bitbake bash -e | grep ^FILE=
> FILE="/media/build1/poky/meta/recipes-extended/bash/bash_4.4.bb"

To me ${FILE} seems to be pointing towards the receipe, and not the 
current .bbclass file as you'd expect.


If I put this in local.conf

INHERIT += "sp-version"
SP_BASEVERSION = "${@read_spbaseversion(d)}"

And in sp-version.bbclass:

def read_spbaseversion(d):
bb.warn("SVEIN FILE: ", d.getVar('FILE', False))
return '0'

If I do bitbake -e, I get

WARNING: SVEIN FILE: /home/s/build-sp-image/build/conf/bblayers.conf

Later the read_spbaseversion is used from within recipe (although they 
don't need to as this variable goes into the global scope, but for the 
sake of the demonstration). Then the value being prined is:


WARNING: /home/s/build-sp-image/meta-sp/sp/sp.bb: SVEIN OPEN: 
/home/s/build-sp-image/meta-sp/sp/sp.bb


Hence, ${FILE} seems to point to the current file scope, like a recipe, 
and not any class files that the recipe might take use of.



Best regards,
Svein
--
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto


Re: [yocto] Path to current bb-file or layer

2017-09-21 Thread Richard Purdie
On Thu, 2017-09-21 at 22:00 +0200, Svein Seldal wrote:
> To determine a image version, I'd like to read a VERSION file which
> is 
> located in the root of the layer. (Per our development procedure.)
> I'd 
> like to read it from a bbclass file. However I seem to be unable to
> find 
> any methods or variables to find a useful path to either the current 
> bb-file or the root of the layer.
> 
> The only way I have found is to parse through BBLAYERS and guess at
> what 
> my own layer is of those, and then use the found to access the file.
> But 
> this feels very wacky.
> 
> Is there a reason why bitbake doesn't have a variable path reference
> to the current file?

You mean like ${FILE} ?

$ bitbake bash -e | grep ^FILE=
FILE="/media/build1/poky/meta/recipes-extended/bash/bash_4.4.bb"

Cheers,

Richard
-- 
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto


Re: [yocto] Path to current bb-file or layer

2017-09-21 Thread Andre McCurdy
On Thu, Sep 21, 2017 at 1:00 PM, Svein Seldal  wrote:
>
> To determine a image version, I'd like to read a VERSION file which is
> located in the root of the layer. (Per our development procedure.) I'd like
> to read it from a bbclass file. However I seem to be unable to find any
> methods or variables to find a useful path to either the current bb-file or
> the root of the layer.
>
> The only way I have found is to parse through BBLAYERS and guess at what my
> own layer is of those, and then use the found to access the file. But this
> feels very wacky.
>
> Is there a reason why bitbake doesn't have a variable path reference to the
> current file?

Doesn't FILE give you exactly that?

  
http://www.yoctoproject.org/docs/2.3/bitbake-user-manual/bitbake-user-manual.html#var-FILE

You can derive from it using python, e.g.

  MYFILE := "${@os.path.abspath(os.path.dirname(d.getVar('FILE')) +
'/../../myfile.txt')}"

If you want to construct paths relative to the top level meta layers
then COREBASE might be useful too.

>
> Best regards,
> Svein
> --
> ___
> yocto mailing list
> yocto@yoctoproject.org
> https://lists.yoctoproject.org/listinfo/yocto
-- 
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto


[yocto] Path to current bb-file or layer

2017-09-21 Thread Svein Seldal


To determine a image version, I'd like to read a VERSION file which is 
located in the root of the layer. (Per our development procedure.) I'd 
like to read it from a bbclass file. However I seem to be unable to find 
any methods or variables to find a useful path to either the current 
bb-file or the root of the layer.


The only way I have found is to parse through BBLAYERS and guess at what 
my own layer is of those, and then use the found to access the file. But 
this feels very wacky.


Is there a reason why bitbake doesn't have a variable path reference to 
the current file?



Best regards,
Svein
--
___
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto