[76912] trunk/dports/devel/bzr-svn
Ryan Schmidt
ryandesign at macports.org
Sat Mar 12 15:20:51 PST 2011
On Mar 12, 2011, at 16:58, Jeremy Lavergne wrote:
> How does base/Tcl handle the concept of defaults?
>
> Is it done by simply seeing if the value is set in the Portfile? Does it then check if the value is different?
MacPorts uses the "options"/"default" mechanism. Certain variables like epoch, revision, distname, worksrcdir, etc. are assigned defaults, and if the port doesn't override them, then that's the value they'll have:
http://trac.macports.org/browser/trunk/base/src/port1.0/portmain.tcl?rev=67763#L75
Note that "options"/"default" in MacPorts implements lazy evaluation [1] using the Tcl variable trace capability. This doesn't matter for epoch or revision, which default to constants ("0" in both cases), but it matters for variables that default to other variables. For example, distname is set to {${name}-${version}} and worksrcdir is set to {$distname}. But these variables aren't evaluated until they're used. If the port overrides distname to be something else, and hasn't used worksrcdir by that point, then worksrcdir will also get that new distname value, not the default ${name}-${version}. You've no doubt already seen this behavior at work in countless portfiles, but that's the technical details of how it works.
http://trac.macports.org/browser/trunk/base/src/port1.0/portutil.tcl?rev=76482#L406
[1] http://en.wikipedia.org/wiki/Lazy_evaluation
More information about the macports-dev
mailing list