All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Trevor Woerner" <twoerner@gmail.com>
To: yocto@yoctoproject.org
Subject: variable and task/function timing
Date: Wed, 11 Dec 2019 02:18:07 -0500	[thread overview]
Message-ID: <20191211071807.GA32639@linux-uys3> (raw)

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.

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"
	+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"

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?

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

             reply	other threads:[~2019-12-11  7:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-11  7:18 Trevor Woerner [this message]
2019-12-11 10:06 ` [yocto] variable and task/function timing Nicolas Dechesne
2019-12-11 15:39   ` Trevor Woerner
2019-12-11 15:48     ` Richard Purdie
2019-12-11 15:51       ` Nicolas Dechesne
2019-12-11 16:26       ` Trevor Woerner
2019-12-11 15:49     ` Nicolas Dechesne
2019-12-11 16:41       ` Trevor Woerner
2019-12-11 17:37         ` Nicolas Dechesne
2019-12-19 16:16     ` Joel A Cohen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191211071807.GA32639@linux-uys3 \
    --to=twoerner@gmail.com \
    --cc=yocto@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.