Looking for a cure for weird scope/memory of variables

Mojca Miklavec mojca at macports.org
Tue Jul 23 07:47:56 PDT 2013


On Tue, Jul 9, 2013 at 6:39 PM, Mojca Miklavecwrote:
> Hi,
>
> I just stumbled upon the following problem with Geant4. See the minimal example:
>
> PortSystem          1.0
> name                foo
> version             1.0
> categories          science
> maintainers         nomaintainer
> description         Foo testing
> long_description    ${description}
>
> set foo.versions {
>     2.0 x
>     3.0 y
>     4.1 z
> }
>
> foreach {foo.version foo.string} ${foo.versions} {
>     subport foo-${foo.version} {
>         pre-fetch {
>             system "echo ${foo.version}"
>         }
>         fetch {}
>         extract {}
>         use_configure no
>         build {}
>         destroot {}
>     }
> }
>
> The command "port -v fetch foo-2.0" prints "4.1". How can I fix this?

After seeing all the different semi-confusing options I noticed
something really simple. While this fails:

    foreach {foo.version foo.string} ${foo.versions} {
        subport foo-${foo.version} {
            pre-fetch {
                system "echo ${foo.version}"
            }
        }
    }

the following works just fine:

    foreach {foo.version foo.string} ${foo.versions} {
        subport foo-${foo.version} {
            set foo.versionx ${foo.version}
            pre-fetch {
                system "echo ${foo.versionx}"
            }
        }
    }

I believe that this is more readable and easier to understand than the
map/eval trickery.

Mojca


More information about the macports-dev mailing list