All of lore.kernel.org
 help / color / mirror / Atom feed
* variable and task/function timing
@ 2019-12-11  7:18 Trevor Woerner
  2019-12-11 10:06 ` [yocto] " Nicolas Dechesne
  0 siblings, 1 reply; 10+ messages in thread
From: Trevor Woerner @ 2019-12-11  7:18 UTC (permalink / raw)
  To: yocto

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

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

end of thread, other threads:[~2019-12-19 16:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11  7:18 variable and task/function timing Trevor Woerner
2019-12-11 10:06 ` [yocto] " 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

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.