Reputation: 22225
My Tcl project library is organized in a tree like this:
mylib : Base folder (has some Tcl) files
mylib/foo , mylib/bar (subdirectories with some other Tcl files).
In particular, I have mylib/foo/mc.tcl, providing a package mc with names
# File mc.tcl
namespace eval ::mc {
namespace export dance&sing
}
proc ::mc::dance&sing { {s {Oh Tannenbaum} } } { puts "$s,...." }
package provide mc 1.4
which works well. Now I added mylib/bar/by.tcl, providing a namespace :by and using the package mc :
# file by.tcl
package require mc
namespace eval ::by {}
proc ::by::execute {} {
::mc::dance&sing "Sushi&more"
}
package provide by 1.1
So far, everything works as advertized. Now I wanted (as an exercise) to change by.tcl by importing the exported symbols from :mc. This is my change:
namespace eval ::by {
namespace import ::mc::dance&sing
}
When running the modified file through pkg_mkIndex, I found that the resulting pkgIndex.tcl does NOT contain an entry for the package by, which usually is a sign that there is some error in the tcl file. However, I can execute by.tcl without getting an error message. If there is a bug in my design, it must be more subtle.
My TCLLIBPATH environment variable contains only the base folder, mylib (as absolute path, of course). This should not be a problem, because files for the packages are found recursively.
Any idea of what went wrong here?
I ADDED AN EXAMPLE FOR REPRODUCING THE PROBLEM
Here is how you can reproduce it:
(1) Download http://files.ronaldf.eml.cc/stovfl0.tgz and unpack it to some directory (2) Ensure that bash (or zsh) and tclsh is in your PATH (3) cd into the directory where you have unpacked everything to, and run it like this:
bash ./run-it.sh
You should see an output similar to this:
pkg_mkIndex for directory ....stovfl0/mylib/foo
pkg_mkIndex for directory ....stovfl0/mylib/bar
(4) cat mylib/bar/pkgIndex.tcl
You will notice, that package 'by' is missing.
Upvotes: 1
Views: 1824
Reputation: 137557
Whatever is going wrong is pretty mysterious. When I create the following two files in a new, empty directory:
# mc.tcl
namespace eval ::mc {
namespace export dance&sing
}
proc ::mc::dance&sing { {s {Oh Tannenbaum} } } { puts "$s,...." }
package provide mc 1.4
# by.tcl
package require mc
namespace eval ::by {}
proc ::by::execute {} {
namespace import ::mc::dance&sing
::mc::dance&sing "Sushi&more"
}
package provide by 1.1
And then I go into that directory with tclsh8.5 (the Snow Leopard system build), and issue this Tcl command:
pkg_mkIndex . *.tcl
Then I get this package index file created, which is correct.
# Tcl package index file, version 1.1
# This file is generated by the "pkg_mkIndex" command
# and sourced either when an application starts up or
# by a "package unknown" script. It invokes the
# "package ifneeded" command to set up package-related
# information so that packages will be loaded automatically
# in response to "package require" commands. When this
# script is sourced, the variable $dir must contain the
# full path name of this file's directory.
package ifneeded by 1.1 [list source [file join $dir by.tcl]]
package ifneeded mc 1.4 [list source [file join $dir mc.tcl]]
I get exactly the same when I use Tcl 8.4 or Tcl 8.6.
Upvotes: 1