Looking for a cure for weird scope/memory of variables

Clemens Lang cal at macports.org
Tue Jul 9 10:25:17 PDT 2013

On Tue, Jul 09, 2013 at 06:39:48PM +0200, Mojca Miklavec wrote:
>     subport foo-${foo.version} {
>         pre-fetch {
>             system "echo ${foo.version}"
>         }
>         fetch {}
>         extract {}
>         use_configure no
>         build {}
>         destroot {}
>     }

The contents of the pre-fetch block are not expanded when defining it.
Consider the pre-fetch block to work like this:

  pre-fetch "a string that will be executed pre-fetch. At this point, it does not matter whether the contents are valid Tcl."

This explains the result: the last value for foo.version is 4.1, which
is still in the variable when the pre-fetch block is evaluated. I've
stumbled on this a couple of times, too, and haven't yet found a good
solution. A solution that works is forcing variable substitution on the
whole pre-fetch block, e.g. using:

  eval "pre-fetch { system \"echo ${foo.version}\" }"

with all the ugly quoting that will be caused by this.
Clemens Lang

More information about the macports-dev mailing list