Version 12 of pkgIndex.tcl

Updated 2012-12-28 19:49:33 by pooryorick

Summary

pkgIndex.tcl is used by the package command to identify and load packages

Description

See package for the details of how the pkgIndex.tcl file is used.

See also pkg_mkIndex.

This is different from the unknown proc and its use of tclIndex.

PkgIndexUtil.tcl - determining a platform name

Recently in comp.lang.tcl, DKF writes (in part) [L1 ]:

Further investigation reveals a badly-written pkgIndex.tcl file, so it 
is doing: 
   package ifneeded foo 1.0 "load [file join $dir foo.dll]" 
instead of: 
   package ifneeded foo 1.0 "load [file join [list $dir] foo.dll]" 
(or one of the many variants on both those). 

I advise that all package authors should test their code when it is 
installed in a directory with a space (or square bracket) in the name, 
and if they find any problems, fix them using [list] carefully to wrap 
$dir or the value derived from it. (Remember, when you're in quoting 
hell, [list] is the road out.) 

Later in that thread, it is observed that both of the above are actually wrong.

Possible corrections of the second are:

package ifneeded foo 1.0 [list load [file join $dir foo.dll]]     ; # File join when setting script
package ifneeded foo 1.0 "load \[file join [list $dir] foo.dll\]" ; # File join when evaluating script

but for multiple-command scripts, DKF ends up recommending:

package ifneeded foo 1.0 [list apply {dir { 
    load [file join $dir foo.dll] 
    uplevel 1 [list source [file join $dir foo.tcl]] 
}} $dir] 

DGP WARNING: if you want to use that last version, you need to guard against interps that lack the apply command. Be sure to start the pkgIndex.tcl file with

if {![package vsatisfies [package provide Tcl] 8.5]} {return}

More generally, see the package index script interface guidelines.


  Use pkgIndex.tcl in package subfolders

HaO 2011-05-04 A package has subpackages in subfolders.

Typically, the parent folder of packages is in the auto_path and thus only the package main folder is scanned for any pkgIndex.tcl files. Any pkgIndex.tcl files in subfolders are ignored.

To include pkgIndex.tcl files in package subfolders, one may add to the pkgIndex.tcl file of the package:

lappend auto_path $dir