2

背景: 我正在尝试在 Yocto 配方中构建ADLINK Vortex OpenSplice 社区版。
当我尝试在 Bash shell 中构建 OpenSplice 时,一切正常。但是,当我尝试在 sh shell 中构建 OpenSplice 时会出现很多问题。问题是配置脚本(以及它调用的脚本)有很多 bashisms(数组、popd、pushd 等)。Bash 配置文件太长且复杂,无法使用 Yocto 补丁文件重写为 sh。

问题我无法获取 Bash 脚本来在 Yocto 配方中的 do_configure() 中设置环境变量。
我可以在我的 Yocto 配方中运行配置脚本。例如:
bash -c "printf '5' | source ${S}/configure" 配置脚本询问我要构建 OpenSplice 的平台,printf '5'输入选项5
但是这个脚本没有设置应该设置的环境变量。我知道,Bash 启动了一个子 shell,环境变量不会离开那个 shell。
我试图在我的食谱中找到 Bash: . bash -c "printf '5' | source ${S}/configure"
但这会产生以下错误: sh: 3: /bin/bash: Syntax error: Unterminated quoted string

我还尝试过在 python 中使用系统调用。但这给出了同样的问题,它打开了一个子 shell,并且环境变量在父 shell 中不可用。

问题那么,问题是如何在 Yocto 食谱中获取 Bash 脚本?欢迎任何解决方案,也包括肮脏的解决方案。

食谱

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
}
4

2 回答 2

1

您可以尝试从 do_configure 方法更改此行:

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

像这样:

bash -c ". /some/path/fileName && printf '5' | source ${S}/configure"
于 2019-12-11T03:56:56.403 回答
0

您不能在 Yocto 配方中获取具有 Bash 特定命令的 Bash 脚本。

幸运的是,在 OpenSplice 配置脚本结束时,所有环境变量都被转储到 sh 文件中。然后可以以与 POSIX 兼容的方式获取此 sh 文件。结果配方是:

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/
}
于 2019-12-12T16:04:57.840 回答