2
votes

Background: I am trying to build ADLINK Vortex OpenSplice Community Edition in a Yocto recipe.
Everything works fine when I try build OpenSplice in a Bash shell. However, there are a lot of problems when I try to build OpenSplice in an sh shell. The problem is that configure script (and the scripts it calls) have a lot of bashisms (arrays, popd, pushd, etc). The Bash configure files are too long and complicated to rewrite to sh with a Yocto patch file.

Problem I cannot source a Bash script to set environment variables in do_configure() in a Yocto recipe.
I can run the configure script in my Yocto recipe. This works for instance:
bash -c "printf '5' | source ${S}/configure" The configure script asks for which platform I want to build OpenSplice, printf '5' enters option 5.
But this script does not set the environment variables that are supposed to be set. I know, Bash starts a child shell, and the environment variables do not leave that shell.
I tried to source Bash in my recipe: . bash -c "printf '5' | source ${S}/configure"
But this gives the following error: sh: 3: /bin/bash: Syntax error: Unterminated quoted string

What I also tried is using system calls in python. But this gives the same problem, it opens a child shell and the environment variables are not available in the parent shell.

Question So, the question is how can I source a Bash script in a Yocto recipe? Any solution is welcome, also the dirty ones.

Recipe

LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=c4bfc022908a26f6f895ab14b6baebca"

# Opensplice does not work with semantic versioning. Therefore ${PV} cannot be used.
# OSPL_V6_9_190925OSS_RELEASE is the 10th release of Opensplice V6.9 (.9 in zero-based 
# numbering). SRCREV is commit hash of OSPL_V6_9_190925OSS_RELEASE.
SRC_URI = "git://github.com/ADLINK-IST/opensplice.git"
SRCREV = "c98e118a2e4366d2a5a6af8cbcecdf112bf9e4ab"

S = "${WORKDIR}/git"

DEPENDS += " bash gcc gawk flex bison perl bison-native "
RDEPENDS_${PN} += " bash bison "

do_configure () {
#    # configure prompts for choice of target architecture
#    # printf '5' enters choice 5; armv7l.linux-release
    bash -c "printf '5' | source ${S}/configure"
}


do_build () {
    make
}

do_install () {
    make install
}
2

2 Answers

1
votes

You could try changing this line from the do_configure method:

bash -c "printf '5' | source ${S}/configure"

to something like this:

bash -c ". /some/path/fileName && printf '5' | source ${S}/configure"
0
votes

You cannot source a Bash script that has Bash specific commands in a Yocto recipe.

Luckily, at the end of the OpenSplice configure script all environment variables are dumped to an sh file. This sh file can then be sourced in a POSIX compatible way. Resulting recipe is:

LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=c4bfc022908a26f6f895ab14b6baebca"

SRC_URI = "git://github.com/ADLINK-IST/opensplice.git"
SRCREV = "c98e118a2e4366d2a5a6af8cbcecdf112bf9e4ab"

S = "${WORKDIR}/git"

DEPENDS += " bash gcc gawk flex bison perl bison-native "
RDEPENDS_${PN} += " bash "

do_configure () {
#   configure prompts for choice of target architecture
#   printf '5' enters choice 5; armv7l.linux-release
#   This command creates the file ./envs-armv7l.linux-release.sh
#   which is sourced by do_compile and do_install
    bash -c "printf '5' | source ${S}/configure"
}

do_compile () {
    # Source the file with the environment variables
    . ${S}/envs-armv7l.linux-release.sh
    make
}

do_install_prepend () {
    # Source the file with the environment variables
    . ${S}/envs-armv7l.linux-release.sh
}

do_install_append () {
    install -d ${D}/bin/
    install -m 0644 ${S}/exec/armv7l.linux-release/* ${D}/bin/
    install -d ${D}/lib/
    install -m 0644 ${S}/lib/armv7l.linux-release/* ${D}/lib/
}