diff mbox

[1/1] class/barebox: Add option of custom environment for barebox

Message ID 88cee887841ad14feace8f95bba455b49692f6a6.1385362830.git.christian.braunersorensen@prevas.dk
State Changes Requested
Delegated to: Esben Haabendal
Headers show

Commit Message

christian.braunersorensen@prevas.dk Nov. 25, 2013, 7:01 a.m. UTC
From: Christian Sørensen <christian.braunersorensen@prevas.dk>

Added use flag barebox_custom_env, which may be set to a provider of a
tarball containing the custom environment.
The tarball must be named: barebox-env.tar.

Signed-off-by: Christian Sørensen <christian.braunersorensen@prevas.dk>
---
 classes/barebox.oeclass | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Esben Haabendal Nov. 27, 2013, 12:24 p.m. UTC | #1
<christian.braunersorensen@prevas.dk> writes:

> From: Christian Sørensen <christian.braunersorensen@prevas.dk>
>
> Added use flag barebox_custom_env, which may be set to a provider of a
> tarball containing the custom environment.
> The tarball must be named: barebox-env.tar.
>
> Signed-off-by: Christian Sørensen <christian.braunersorensen@prevas.dk>
> ---
>  classes/barebox.oeclass | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/classes/barebox.oeclass b/classes/barebox.oeclass
> index cb8a7f1..9214d5f 100644
> --- a/classes/barebox.oeclass
> +++ b/classes/barebox.oeclass
> @@ -52,6 +52,29 @@ do_configure() {
>  	fi
>  }
>  
> +#
> +# Barebox custom environment can be provided using the following method
> +#
> +# Use barebox env from DEPENDS, by setting USE_barebox_custom_env to a name
> +# of the package providing the custom env. The custom env must be a tarball
> +# named barebox-env.tar placed in / in HOST_SYSROOT.
> +BAREBOX_CUSTOM_ENV_TAR_FILE = "barebox-env.tar"
> +CLASS_FLAGS += "barebox_custom_env"
> +CLASS_DEPENDS:>USE_barebox_custom_env = " ${USE_barebox_custom_env}"
> +
> +do_configure[postfuncs] += "do_configure_custom_env"
> +do_configure_custom_env () {
> +	if [ -f ${HOST_SYSROOT}/${BAREBOX_CUSTOM_ENV_TAR_FILE} ]; then
> +		mkdir -p ${S}/customenv
> +		tar -xf ${HOST_SYSROOT}/${BAREBOX_CUSTOM_ENV_TAR_FILE} \
> +			-C ${S}/customenv/ --strip-components=1
> +		sed -i -e 's/\(CONFIG_DEFAULT_ENVIRONMENT_PATH=\).*/\1"customenv"/' \
> +			.config
> +	else
> +		die "No barebox-env.tar available from stage"
> +	fi
> +}
> +

This still does not provide a robust handling of the dependency.  If the
configuration is set to pull in a custom env tarball through
dependencies, and the package pulled in does not actually provide the
needed tarball, the code above will happily continue without a custom
environment.  The function must fail if the USE flag has required a
custom env tarball in stage and none is there.

Also, as explained offline, the USE flag should be defined in a similar
way to the USE_barebox_defconfig flag, which is:

commit 90f0cb123db074e874b92feb8fa2ea2bb8767d82
Author: Esben Haabendal <esben.haabendal@prevas.dk>
Date:   Tue Feb 28 14:18:50 2012 +0100

    class/barebox: Improved USE_barebox_defconfig support
    
    Make it possible to provide barebox defconfig in 3 different ways:
    * USE_barebox_defconfig not set (this is default).
      -> Use defconfig file from DEPENDS (barebox-defconfig)
    * Set USE_barebox_defconfig to something like "blahblah_defconfig"
      -> Use defconfig from barebox source.
    * Set USE_barebox_defconfig to "file"
      -> Use defconfig file from SRC_URI

A similar definition for a USE_barebox_custom_env flag could be

    * USE_barebox_custom_env not set (this is default)
      -> Use default environment from barebox source
    * Set USE_barebox_custom_env to "file"
      -> Use barebox-env.tar file from SRC_URI
    * Set USE_barebox_custom_env to "barebox-env"
      (or some other random dependency)
      -> Add "barebox-env" to CLASS_DEPENDS" and use barebox-env.tar
         file from stage

In both of the last two cases, do_configure_custom_env must fail if
barebox-env.tar is not found.


>  do_compile () {
>  	oe_runmake all
>  }
diff mbox

Patch

diff --git a/classes/barebox.oeclass b/classes/barebox.oeclass
index cb8a7f1..9214d5f 100644
--- a/classes/barebox.oeclass
+++ b/classes/barebox.oeclass
@@ -52,6 +52,29 @@  do_configure() {
 	fi
 }
 
+#
+# Barebox custom environment can be provided using the following method
+#
+# Use barebox env from DEPENDS, by setting USE_barebox_custom_env to a name
+# of the package providing the custom env. The custom env must be a tarball
+# named barebox-env.tar placed in / in HOST_SYSROOT.
+BAREBOX_CUSTOM_ENV_TAR_FILE = "barebox-env.tar"
+CLASS_FLAGS += "barebox_custom_env"
+CLASS_DEPENDS:>USE_barebox_custom_env = " ${USE_barebox_custom_env}"
+
+do_configure[postfuncs] += "do_configure_custom_env"
+do_configure_custom_env () {
+	if [ -f ${HOST_SYSROOT}/${BAREBOX_CUSTOM_ENV_TAR_FILE} ]; then
+		mkdir -p ${S}/customenv
+		tar -xf ${HOST_SYSROOT}/${BAREBOX_CUSTOM_ENV_TAR_FILE} \
+			-C ${S}/customenv/ --strip-components=1
+		sed -i -e 's/\(CONFIG_DEFAULT_ENVIRONMENT_PATH=\).*/\1"customenv"/' \
+			.config
+	else
+		die "No barebox-env.tar available from stage"
+	fi
+}
+
 do_compile () {
 	oe_runmake all
 }