All of lore.kernel.org
 help / color / mirror / Atom feed
* Path to current bb-file or layer
@ 2017-09-21 20:00 Svein Seldal
  2017-09-21 21:29 ` Andre McCurdy
  2017-09-21 21:36 ` Richard Purdie
  0 siblings, 2 replies; 8+ messages in thread
From: Svein Seldal @ 2017-09-21 20:00 UTC (permalink / raw)
  To: yocto


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Path to current bb-file or layer
  2017-09-21 20:00 Path to current bb-file or layer Svein Seldal
@ 2017-09-21 21:29 ` Andre McCurdy
  2017-09-21 21:36 ` Richard Purdie
  1 sibling, 0 replies; 8+ messages in thread
From: Andre McCurdy @ 2017-09-21 21:29 UTC (permalink / raw)
  To: Svein Seldal; +Cc: yocto

On Thu, Sep 21, 2017 at 1:00 PM, Svein Seldal <sveinse@seldal.com> 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Path to current bb-file or layer
  2017-09-21 20:00 Path to current bb-file or layer Svein Seldal
  2017-09-21 21:29 ` Andre McCurdy
@ 2017-09-21 21:36 ` Richard Purdie
  2017-09-22  8:17   ` Svein Seldal
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Purdie @ 2017-09-21 21:36 UTC (permalink / raw)
  To: Svein Seldal, yocto

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Path to current bb-file or layer
  2017-09-21 21:36 ` Richard Purdie
@ 2017-09-22  8:17   ` Svein Seldal
  2017-09-22  8:30     ` Richard Purdie
  0 siblings, 1 reply; 8+ messages in thread
From: Svein Seldal @ 2017-09-22  8:17 UTC (permalink / raw)
  To: Richard Purdie, yocto


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Path to current bb-file or layer
  2017-09-22  8:17   ` Svein Seldal
@ 2017-09-22  8:30     ` Richard Purdie
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Purdie @ 2017-09-22  8:30 UTC (permalink / raw)
  To: Svein Seldal, yocto

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Path to current bb-file or layer
  2017-09-22 11:42 ` Richard Purdie
@ 2017-09-22 13:39   ` Svein Seldal
  0 siblings, 0 replies; 8+ messages in thread
From: Svein Seldal @ 2017-09-22 13:39 UTC (permalink / raw)
  To: Richard Purdie, yocto



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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Path to current bb-file or layer
  2017-09-22 11:04 Svein Seldal
@ 2017-09-22 11:42 ` Richard Purdie
  2017-09-22 13:39   ` Svein Seldal
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Purdie @ 2017-09-22 11:42 UTC (permalink / raw)
  To: Svein Seldal, yocto

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




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Path to current bb-file or layer
@ 2017-09-22 11:04 Svein Seldal
  2017-09-22 11:42 ` Richard Purdie
  0 siblings, 1 reply; 8+ messages in thread
From: Svein Seldal @ 2017-09-22 11:04 UTC (permalink / raw)
  To: Richard Purdie, yocto

[-- Attachment #1: Type: text/plain, Size: 1440 bytes --]



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

[-- Attachment #2: Type: text/html, Size: 1905 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-09-22 13:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-21 20:00 Path to current bb-file or layer Svein Seldal
2017-09-21 21:29 ` Andre McCurdy
2017-09-21 21:36 ` Richard Purdie
2017-09-22  8:17   ` Svein Seldal
2017-09-22  8:30     ` Richard Purdie
2017-09-22 11:04 Svein Seldal
2017-09-22 11:42 ` Richard Purdie
2017-09-22 13:39   ` Svein Seldal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.