From 14ec0b24563375e748ca085b49980f2a34db31ae Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 22 Mar 2022 10:13:04 +0100 Subject: [PATCH] eclass/coreos-cargo: Ensure the modified config is valid TOML We were appending the [build] section, and the updated cargo eclass already added that to the config, so we ended up with having two [build] sections in the config file. Try to amend the section instead of appending it to the file. While at it, do the same with the target.${RUST_TARGET} section too to be a bit more futureproof. --- .../coreos-overlay/eclass/coreos-cargo.eclass | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-cargo.eclass b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-cargo.eclass index dfad60d56a..e48b5383fb 100644 --- a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-cargo.eclass +++ b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-cargo.eclass @@ -76,15 +76,36 @@ coreos-cargo_src_unpack() { # Compile for the built-in target, using the SDK cross-tools. export RUST_TARGET=$(rust_builtin_target "${CHOST}") - cat <<- EOF >> "${ECARGO_HOME}/config" - - [build] - target = "${RUST_TARGET}" - - [target.${RUST_TARGET}] - ar = "${TARGET_AR}" - linker = "${TARGET_CC}" - EOF + local -a config_lines + local build_amended=0 + local target_rust_target_amended=0 + local REPLY + readonly b_header='[build]' + readonly t_header="[target.${RUST_TARGET}]" + readonly target_line="target = \"${RUST_TARGET}\"" + readonly ar_line="ar = \"${TARGET_AR}\"" + readonly linker_line="linker = \"${TARGET_CC}\"" + while read -r; do + config_lines+=("${REPLY}") + case "${REPLY}" in + "${b_header}") + config_lines+=("${target_line}") + build_amended=1 + ;; + "${t_header}") + config_lines+=("${ar_line}") + config_lines+=("${linker_line}") + target_rust_target_amended=1 + ;; + esac + done <"${ECARGO_HOME}/config" + if [[ "${build_amended}" -eq 0 ]]; then + config_lines+=('' "${b_header}" "${target_line}") + fi + if [[ "" -eq 0 ]]; then + config_lines+=('' "${t_header}" "${ar_line}" "${linker_line}") + fi + printf '%s\n' "${config_lines[@]}" >"${ECARGO_HOME}/config" } fi