namespaced options variables?

René J.V. Bertin rjvbertin at gmail.com
Sun Aug 11 11:36:06 UTC 2024


On Sunday August 11 2024 02:17:42 Ryan Carsten Schmidt wrote:

>Lots of portgroups use namespaced variables.

I grepped for examples but couldn't find any namespaced *options* variables. Plenty with a simulated namespace using a dot instead of a double colon, maybe you meant those?

>You do of course need to declare the namespace first. 

Doh... I did.

I just tested, and basic functionality does seem to work (in a PG):

{{{
namespace eval dev {}

options dev::test
default dev::test {test}

proc test {} {
  global dev::test
  ui_msg ${dev::test}
}
test
}}}

prints "test". But note that in this test everything still works when you remove the namespace line.

My case is a bit more complex, a PG that has:

{{{
proc create_devport {dependency} {
  global dev::test
  subport ${name}-dev { ... }
  if {${subport} eq "${name}"} {
     pre-destroot {
        ui_msg ${dev::test}
     }
  }
}
}}}

and a Portfile that includes the PG and calls `create_devport` at an appropriate location. This gives the error 
{{{
Error: Failed to destroot XXX: can't read "dev::test": key "test" not known in dictionary
}}}

I'll admit that I'm never very clear on the proper Tcl way to access a *regular* namespaced variable from inside a procedure, so let alone an options variable.

Going over the sources I did notice that a number of data structures were turned into dicts since MP 2.7.1 which I've been running until now. I expected some of my tricky designs to break because of that but so far everything works except some things that I did NOT expect to fail, like this.

Another surprise which *may* be related: I had

{{{
platform linux {

    namespace eval stdcxxabi {
        # our directory:
        set currentportgroupdir [file dirname [dict get [info frame 0] file]]
}}}

which worked but now raises an error because `file` is not known in "the" dict. Indeed, it turns out that the return of `[info frame 0]` is now very different when run inside a `platform` command vs. inside the equivalent `if {${os.platform}}` expression. It no longer contains the name of the current file. 


More information about the macports-dev mailing list