lol

Merge pull request #199300 from Fuuzetsu/escape-rust-exports

rustBuildCrate: properly handle cargo env pragmas with spaces

authored by

Aaron Andersen and committed by
GitHub
adbe2f53 a9032733

+13 -1
+13 -1
pkgs/build-support/rust/build-rust-crate/configure-crate.nix
··· 189 189 EXTRA_LINK=$(sed -n "s/^cargo:rustc-link-lib=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ') 190 190 EXTRA_LINK_SEARCH=$(sed -n "s/^cargo:rustc-link-search=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ' | sort -u) 191 191 192 + # We want to read part of every line that has cargo:rustc-env= prefix and 193 + # export it as environment variables. This turns out tricky if the lines 194 + # have spaces: we can't wrap the command in double quotes as that captures 195 + # all the lines in single output. We can't use while read loop because 196 + # exporting from inside of it doesn't make it to the outside scope. We 197 + # can't use xargs as export is a built-in and does not work from it. As a 198 + # last resort then, we change the IFS so that the for loop does not split 199 + # on spaces and reset it after we are done. See ticket #199298. 200 + # 201 + _OLDIFS="$IFS" 202 + IFS=$'\n' 192 203 for env in $(sed -n "s/^cargo:rustc-env=\(.*\)/\1/p" target/build/${crateName}.opt); do 193 - export $env 204 + export "$env" 194 205 done 206 + IFS="$_OLDIFS" 195 207 196 208 CRATENAME=$(echo ${crateName} | sed -e "s/\(.*\)-sys$/\U\1/" -e "s/-/_/g") 197 209 grep -P "^cargo:(?!(rustc-|warning=|rerun-if-changed=|rerun-if-env-changed))" target/build/${crateName}.opt \