On Wed, Dec 11, 2019 at 8:18 AM Trevor Woerner <[email protected]> wrote:
>
> Is there a document, or better yet a diagram, showing the order in which
> various config files, recipes, tasks, etc are parsed?
>
> Figuring out the order of the config files is easy enough (bitbake.conf), but
> trying to figure out when various other parts are processed is just a guess
> for me right now.
well the easiest way to visualize it is to think about all variables
being in a large array. Each variable (each row) having a different
'value' for each 'column' and each column representing a recipe. When
bitbake references a variable it is always in the context of a given
recipe, so you are looking at a specific 'column'. Initially this
array is filled with default values resulting from the parsing of all
global .conf files, as you noticed the list of conf files and the
order is set in bitbake.conf (which itself is hardcoded in bitbake,
and the first file to parse).
then bitbake will parse each recipe, one by one, and update each
variable's value in that array (in the relevant column). At the end of
the parsing, you have all variables which are known.
you can use bitbake -e to print variables value:
bitbake -e | grep ^MESON_BUILDTYPE
it will show you the default value (if it is set) outside the context
of any recipe.
bitbake -e <bar> | grep ^MESON_BUILDTYPE
will give you the value of this variable as it is set in <bar> recipe
Of course, the parsing is dealing with all operators as well.
In a global conf file you set a variable for a specific recipe with
the _pn- operator. e.g. use:
MESON_BUILDTYPE_pn-bar = "debug"
to set MESON_BUILDTYPE to debug for the <bar> recipe.
>
> Conceptually this is what I want to do:
>
> Currently the meson build system (class) is hard-coded to always
> produce
> a buildtype of "plain", which are (basically) production builds. But
> there are other buildtypes that can be specified; such as
> "debugoptimized". I want a recipe to be able to influence the meson
> buildtype, and I want the user to be able to tweak this parameter from
> their conf/local.conf.
>
> Here's what I want to do:
>
> diff --git a/meta/classes/meson.bbclass b/meta/classes/meson.bbclass
> index dc8c28963c..e1a13bbbf7 100644
> --- a/meta/classes/meson.bbclass
> +++ b/meta/classes/meson.bbclass
> @@ -12,8 +12,9 @@ MESON_SOURCEPATH = "${S}"
> def noprefix(var, d):
> return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
>
> +MESON_BUILDTYPE ?= "plain"
> MESONOPTS = " --prefix ${prefix} \
> - --buildtype plain \
> + --buildtype ${MESON_BUILDTYPE} \
> --bindir ${@noprefix('bindir', d)} \
> --sbindir ${@noprefix('sbindir', d)} \
> --datadir ${@noprefix('datadir', d)} \
> diff --git a/meta/recipes-graphics/mesa/mesa.inc
> b/meta/recipes-graphics/mesa/mesa.inc
> index 5838207e6b..fb232d414e 100644
> --- a/meta/recipes-graphics/mesa/mesa.inc
> +++ b/meta/recipes-graphics/mesa/mesa.inc
> @@ -46,6 +46,20 @@ export WANT_LLVM_RELEASE = "${MESA_LLVM_RELEASE}"
>
> MESA_LLVM_RELEASE ?= "${LLVMVERSION}"
>
> +# set the build type to either 'release' or 'debug'
> +# the upstream mesa sources actually build a debug release by default
> +# but here we assume the user will want a release build by default
> +MESA_BUILD_TYPE ?= "release"
The content of the class is parsed when it is inherited. So you need
to initialize class variables *before* you inherit the class. e.g.
MESA_BUILD_TYPE ?= "release"
...
inherit meson
in your case is very different from
inherit meson
...
MESA_BUILD_TYPE ?= "release"
> +python do_check_build_type() {
> + _buildtype = d.getVar('MESA_BUILD_TYPE')
> + if _buildtype not in ['release', 'debug']:
> + bb.fatal("unknown build type (%s), please set to either
> 'release' or 'debug'" % _buildtype)
> + if _buildtype == 'debug':
> + d.setVar('MESON_BUILDTYPE', 'debugoptimized')
> + bb.plain("setting meson build type to debugoptimized")
> +}
> +addtask check_build_type before do_configure
> +
> EXTRA_OEMESON = " \
> -Dshared-glapi=true \
> -Dgallium-opencl=disabled \
>
> Therefore if the user doesn't do anything explicitly, a production buildtype
> will be produced. However, if the user were to specify the following in their
> conf/local.conf:
>
> MESA_BUILD_TYPE = "debug"
>
> I want mesa's buildtype to be "debugoptimized".
>
> I don't want the user to specify the following in their conf/local.conf:
>
> MESON_BUILDTYPE = "debugoptimized"
use _pn- operator for that, as mentioned above.
>
> because that would cause *all* meson-built packages to switch to the
> debugoptimized buildtype. I only want mesa's build to be debugoptimized.
>
> However, the above doesn't work. If I set MESA_BUILD_TYPE to "hello" in my
> conf/local.conf, then the build will flag it and error out asking me to
> specify either 'release' or 'debug', which is great. But if I set
> MESA_BUILD_TYPE to 'debug' the MESON_BUILDTYPE variable is always set to
> "plain" regardless. So this task runs, but I guess it runs too late to
> influence the MESON_BUILDTYPE variable?
That is unexpected.. I would have thought it should work. You are
mixing BUILD_TYPE and BUILDTYPE in your email.. maybe you are mixing
that in your testing as well? What is set in local.conf will be parsed
first, so if you set a variable there, it will be 'set' when you parse
the recipe, so when you use ?= it should be a no-op.
>
> So, how can I run this function earlier (?) so that it can set the
> MESON_BUILDTYPE variable correctly? I tried the following:
>
> diff --git a/meta/classes/meson.bbclass b/meta/classes/meson.bbclass
> index dc8c28963c..e1a13bbbf7 100644
> --- a/meta/classes/meson.bbclass
> +++ b/meta/classes/meson.bbclass
> @@ -12,8 +12,9 @@ MESON_SOURCEPATH = "${S}"
> def noprefix(var, d):
> return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
>
> +MESON_BUILDTYPE ?= "plain"
> MESONOPTS = " --prefix ${prefix} \
> - --buildtype plain \
> + --buildtype ${MESON_BUILDTYPE} \
> --bindir ${@noprefix('bindir', d)} \
> --sbindir ${@noprefix('sbindir', d)} \
> --datadir ${@noprefix('datadir', d)} \
> diff --git a/meta/recipes-graphics/mesa/mesa.inc
> b/meta/recipes-graphics/mesa/mesa.inc
> index 5838207e6b..b302f8ee55 100644
> --- a/meta/recipes-graphics/mesa/mesa.inc
> +++ b/meta/recipes-graphics/mesa/mesa.inc
> @@ -46,6 +46,20 @@ export WANT_LLVM_RELEASE = "${MESA_LLVM_RELEASE}"
>
> MESA_LLVM_RELEASE ?= "${LLVMVERSION}"
>
> +# set the build type to either 'release' or 'debug'
> +# the upstream mesa sources actually build a debug release by default
> +# but here we assume the user will want a release build by default
> +MESA_BUILD_TYPE ?= "release"
> +def check_buildtype(d):
> + _buildtype = d.getVar('MESA_BUILD_TYPE')
> + if _buildtype not in ['release', 'debug']:
> + bb.fatal("unknown build type (%s), please set to either
> 'release' or 'debug'" % _buildtype)
> + if _buildtype == 'debug':
> + bb.plain("setting meson build type to debugoptimized")
> + return 'debugoptimized'
> + return 'plain'
> +MESON_BUILDTYPE = "${@check_buildtype(d)}"
> +
> EXTRA_OEMESON = " \
> -Dshared-glapi=true \
> -Dgallium-opencl=disabled \
>
> This will print out the bb.plain() message 16 times during parsing etc, it
> will fail out if MESA_BUILD_TYPE is not one of 'release' or 'debug' (which is
> good), but if this occurs, the error message is printed out twice plus a
> python traceback, which might be scary to users.
>
> The last thing I tried was the following:
>
> diff --git a/meta/classes/meson.bbclass b/meta/classes/meson.bbclass
> index dc8c28963c..e1a13bbbf7 100644
> --- a/meta/classes/meson.bbclass
> +++ b/meta/classes/meson.bbclass
> @@ -12,8 +12,9 @@ MESON_SOURCEPATH = "${S}"
> def noprefix(var, d):
> return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
>
> +MESON_BUILDTYPE ?= "plain"
> MESONOPTS = " --prefix ${prefix} \
> - --buildtype plain \
> + --buildtype ${MESON_BUILDTYPE} \
> --bindir ${@noprefix('bindir', d)} \
> --sbindir ${@noprefix('sbindir', d)} \
> --datadir ${@noprefix('datadir', d)} \
> diff --git a/meta/recipes-graphics/mesa/mesa.inc
> b/meta/recipes-graphics/mesa/mesa.inc
> index 5838207e6b..c265ffc246 100644
> --- a/meta/recipes-graphics/mesa/mesa.inc
> +++ b/meta/recipes-graphics/mesa/mesa.inc
> @@ -46,6 +46,12 @@ export WANT_LLVM_RELEASE = "${MESA_LLVM_RELEASE}"
>
> MESA_LLVM_RELEASE ?= "${LLVMVERSION}"
>
> +# set the build type to either 'release' or 'debug'
> +# the upstream mesa sources actually build a debug release by default
> +# but here we assume the user will want a release build by default
> +MESA_BUILD_TYPE ?= "release"
> +MESON_BUILDTYPE = "${@bb.utils.contains('MESA_BUILD_TYPE', 'debug',
> 'debugoptimized', 'plain', d)}"
> +
> EXTRA_OEMESON = " \
> -Dshared-glapi=true \
> -Dgallium-opencl=disabled \
>
> This works perfectly, but it lacks the error checking and helpful messages of
> the previous attempts.
>
> Any thoughts on how I can have it all? (i.e. nice error checking and error
> messages with the variable tweakable from conf/local.conf?
>
> Best regards,
> Trevor
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
>
> View/Reply Online (#47628):
> https://lists.yoctoproject.org/g/yocto/message/47628
> Mute This Topic: https://lists.yoctoproject.org/mt/68144480/1279857
> Group Owner: [email protected]
> Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub
> [[email protected]]
> -=-=-=-=-=-=-=-=-=-=-=-
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#47630): https://lists.yoctoproject.org/g/yocto/message/47630
Mute This Topic: https://lists.yoctoproject.org/mt/68144480/21656
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-