diff mbox

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

Message ID d5d56aaa43f8fc5299e70b6c135c1b6af3fe7e06.1380192796.git.christian.braunersorensen@prevas.dk
State Superseded
Delegated to: Esben Haabendal
Headers show

Commit Message

christian.braunersorensen@prevas.dk Sept. 26, 2013, 10:54 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.
Furthermore, besides setting the barebox_custom_env use flag, one may place
two files in SRCDIR (config / init) using file input to use that those as
environment.

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

Comments

Esben Haabendal Oct. 14, 2013, 9:28 a.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.
> Furthermore, besides setting the barebox_custom_env use flag, one may place
> two files in SRCDIR (config / init) using file input to use that those as
> environment.

This still includes hardcoding of environment structure in
barebox.oeclass.  If possible, it would be nice to provide a generic
solution instead.

> Signed-off-by: Christian Sørensen <christian.braunersorensen@prevas.dk>
> ---
>  classes/barebox.oeclass | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
>
> diff --git a/classes/barebox.oeclass b/classes/barebox.oeclass
> index cb8a7f1..9d1d3d0 100644
> --- a/classes/barebox.oeclass
> +++ b/classes/barebox.oeclass
> @@ -50,6 +50,28 @@ do_configure() {
>  	else
>  		die "No default configuration available"
>  	fi
> +

No reason to add blank line here...

> +}
> +
> +BAREBOX_CUSTOM_ENV_TAR_FILE = "barebox-env.tar"
> +CLASS_FLAGS += "barebox_custom_env"
> +CLASS_DEPENDS:>USE_barebox_custom_env = "${USE_barebox_custom_env}"

You need to add a space in front of the value to handle cases where
CLASS_DEPENDS is defined and does not end in a space.

> +
> +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
> +	elif [ -f ${SRCDIR}/init ] && [ -f ${SRCDIR}/config ]; then
> +		mkdir -p ${S}/customenv/bin
> +		cp ${SRCDIR}/init ${S}/customenv/bin/
> +		cp ${SRCDIR}/config ${S}/customenv/
> +		sed -i -e 's/\(CONFIG_DEFAULT_ENVIRONMENT_PATH=\).*/\1"customenv"/' \
> +			.config
> +	fi

This is includes some rather unfortunate "error handling".  Let's say
you set USE_barebox_custom_env, and the intention is to pull in a
package which provides the environment. If the barebox-env.tar file is
not found, do_configure_custom_env tries to find init and config files,
and use them if possible, and as last resort just continous happily
without a custom env. Both of these cases are clearly not what the
developer expects.

Instead of figuring out a smart way of handling this, why not just
require custom env to be provided in the form of a dependency?

>  }
>  
>  do_compile () {

/Esben
diff mbox

Patch

diff --git a/classes/barebox.oeclass b/classes/barebox.oeclass
index cb8a7f1..9d1d3d0 100644
--- a/classes/barebox.oeclass
+++ b/classes/barebox.oeclass
@@ -50,6 +50,28 @@  do_configure() {
 	else
 		die "No default configuration available"
 	fi
+
+}
+
+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
+	elif [ -f ${SRCDIR}/init ] && [ -f ${SRCDIR}/config ]; then
+		mkdir -p ${S}/customenv/bin
+		cp ${SRCDIR}/init ${S}/customenv/bin/
+		cp ${SRCDIR}/config ${S}/customenv/
+		sed -i -e 's/\(CONFIG_DEFAULT_ENVIRONMENT_PATH=\).*/\1"customenv"/' \
+			.config
+	fi
 }
 
 do_compile () {