Here document written within loops (or probably any other compound commands) in ebuilds are getting misinterpreted (compared to plain bash behavior). Reproducible: Always Steps to Reproduce: 1. Create a simple ebuild: src_install () { for (( i = 0; i < 2; i++ )) ; do cat <<EOFF ${i} EOFF done echo qqq } 2. emerge it Actual Results: >>> Install qqq-999 into /var/tmp/portage/test-bug/qqq-999/image/ category test-bug qqq >>> Completed installing qqq-999 into /var/tmp/portage/test-bug/qqq-999/image/ Expected Results: >>> Install qqq-999 into /var/tmp/portage/test-bug/qqq-999/image/ category test-bug 0 1 qqq >>> Completed installing qqq-999 into /var/tmp/portage/test-bug/qqq-999/image/ The reason for this behavior is that src_install() gets clobbered in the environment: src_install () { for ((i = 0; i < 2; i++ )) do cat; done <<EOFF ${i} EOFF echo qqq } The easy workaround is to add line " :" after closing EOFF.
Created attachment 269697 [details] emerge --info
If you source the ebuild in a bash shell and then use declare -fp (as portage does) or declare -f src_install to view the function, then you'll see that bash itself is the source of the function corruption.
seems like a simple variant of bug 310197. simple test case: f() { for (( :; :; )) ; do cat <<EOF EOF done; :; } type f seems to be a regression between bash-3.x and bash-4.x
(In reply to comment #3) > seems like a simple variant of bug 310197. simple test case: > f() { for (( :; :; )) ; do > cat <<EOF > EOF > done; :; } > type f > > seems to be a regression between bash-3.x and bash-4.x The problem is not exactly the same but may be related. Bug 310197 is "bash executes function incorrectly" while current bug is "bash executes function properly but dumps it improperly". I.e., the bash script """ src_install () { for (( i = 0; i < 2; i++ )) ; do cat <<EOFF ${i} EOFF done echo qqq } src_install """ works as expected but "declare -f src_install" dumps incorrect function representation.
no, they're the same bug. even upstream said this. read the referenced one again. the issue only comes up when the source is dumped and reloaded.
(In reply to comment #5) > no, they're the same bug. even upstream said this. read the referenced one > again. the issue only comes up when the source is dumped and reloaded. Ouch, sorry, I haven't read through that thread carefully and now I see I was wrong.
not a problem. often times upstream posts a patch quickly, but until then, you can simply work around the issue by putting a ":" after the `cat`.
(In reply to comment #7) > not a problem. often times upstream posts a patch quickly, but until then, you > can simply work around the issue by putting a ":" after the `cat`. Thank you for contacting upstream! Yeah, thanks, I know the workaround.:)
ive added a patch from upstream to 4.2_p8-r1 http://sources.gentoo.org/app-shells/bash/files/bash-4.2-print-heredoc.patch?rev=1.1