Seth Woolley's Man Viewer

pkg_mkIndex(n) - pkg_mkIndex - Build an index for automatic loading of packages - man n pkg_mkIndex

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

pkg_mkIndex(n)               Tcl Built-In Commands              pkg_mkIndex(n)


       pkg_mkIndex - Build an index for automatic loading of packages

       pkg_mkIndex ?-direct?  ?-lazy?  ?-load pkgPat? ?-verbose? dir ?pattern pattern ...?|

       Pkg_mkIndex  is  a  utility  procedure that is part of the standard Tcl
       library.  It is used to create index files that allow  packages  to  be
       loaded  automatically  when  package require commands are executed.  To
       use pkg_mkIndex, follow these steps:

       [1]    Create the package(s).  Each package may consist of one or  more
              Tcl script files or binary files.  Binary files must be suitable
              for loading with the load(7,n) command with a single  argument;   for
              example, if(3,n) the file(1,n) is it must be possible to load(7,n) this
              file(1,n) with the command load(7,n)  Each script file(1,n) must  con-
              tain  a  package provide command to declare the package and ver-
              sion(1,3,5) number, and  each  binary  file(1,n)  must  contain  a  call  to

       [2]    Create  the  index  by  invoking  pkg_mkIndex.  The dir argument
              gives the name of a directory and each  pattern  argument  is  a
              glob(1,3,7,n)-style  pattern  that selects script or binary files in(1,8) dir. |
              The default pattern is *.tcl and *.[info(1,5,n) sharedlibextension].
              Pkg_mkIndex will create a file(1,n) pkgIndex.tcl in(1,8) dir with  package
              information  about all the files given by the pattern arguments.
              It does this by loading each file(1,n) into a slave  interpreter  and
              seeing  what packages and new commands appear (this is why it is
              essential to have package  provide  commands  or  Tcl_PkgProvide
              calls  in(1,8) the files, as described above).  If you have a package
              split(1,n) among scripts and binary files, or if(3,n) you  have  dependen-
              cies among files, you may have to use the -load option or adjust
              the order in(1,8) which pkg_mkIndex processes the files.  See COMPLEX
              CASES below.

       [3]    Install  the package as a subdirectory of one of the directories
              given by the tcl_pkgPath  variable.   If  $tcl_pkgPath  contains
              more than one directory, machine-dependent packages (e.g., those
              that  contain  binary  shared  libraries)  should  normally   be
              installed  under  the  first  directory  and machine-independent
              packages (e.g., those that contain only Tcl scripts)  should  be
              installed  under  the second directory.  The subdirectory should
              include the package's script and/or binary files as well as  the
              pkgIndex.tcl  file.   As  long  as the package is installed as a
              subdirectory of a directory in(1,8) $tcl_pkgPath  it  will  automati-
              cally be found during package require commands.
              If  you  install the package anywhere else, then you must ensure
              that the directory containing the package is  in(1,8)  the  auto_path
              global  variable  or  an  immediate  subdirectory  of one of the
              directories in(1,8) auto_path.  Auto_path contains a list of directo-
              ries  that  are searched by both the auto-loader and the package
              loader; by default it includes $tcl_pkgPath.  The package loader
              also  checks  all  of  the  subdirectories of the directories in(1,8)
              auto_path.  You can add a directory to auto_path  explicitly  in(1,8)
              your  application,  or you can add the directory to your TCLLIB-
              PATH environment variable:   if(3,n)  this  environment  variable  is
              present,  Tcl  initializes  auto_path from it during application

       [4]    Once the above steps have been taken, all you need to do to  use
              a  package  is  to invoke package require.  For example, if(3,n) ver-
              sions 2.1, 2.3, and 3.1 of package Test  have  been  indexed  by
              pkg_mkIndex,  the command package require Test will make version(1,3,5)
              3.1 available and the command package require  -exact  Test  2.1
              will  make version(1,3,5) 2.1 available.  There may be many versions of
              a package in(1,8) the various index files in(1,8) auto_path, but only  one
              will  actually  be  loaded  in(1,8) a given interpreter, based on the
              first call to package require.  Different versions of a  package
              may be loaded in(1,8) different interpreters.

       The optional switches are:

       -direct        The generated index will implement direct loading of the
                      package upon package require.  This is the default.

       -lazy          The generated index will manage  to  delay  loading  the
                      package until the use of one of the commands provided by
                      the package, instead  of  loading  it  immediately  upon
                      package require.

       -load pkgPat   The  index process will pre-load any packages that exist
                      in(1,8) the current interpreter and  match  pkgPat  into  the
                      slave  interpreter used to generate the index.  The pat-
                      tern match uses string(3,n) match rules, but  without  making
                      case distinctions.  See COMPLEX CASES below.

       -verbose       Generate  output during the indexing process.  Output is
                      via the tclLog procedure, which  by  default  prints  to

       --             End of the flags, in(1,8) case dir begins with a dash.

       The  package  management  facilities  overlap  somewhat  with the auto-
       loader, in(1,8) that both arrange for files to be  loaded  on-demand.   How-
       ever,  package  management  is  a  higher-level mechanism that uses the
       auto-loader for the last step in(1,8) the loading process.  It is  generally
       better  to  index  a  package with pkg_mkIndex rather than auto_mkindex
       because the package mechanism provides version(1,3,5) control:   several  ver-
       sions  of a package can be made available in(1,8) the index files, with dif-
       ferent applications using different versions based on  package  require
       commands.  In contrast, auto_mkindex does not understand versions so it
       can only handle a single version(1,3,5) of each package.  It is probably not a
       good   idea  to  index  a  given  package  with  both  pkg_mkIndex  and
       auto_mkindex.  If you use pkg_mkIndex to index a package, its  commands
       cannot  be invoked until package require has been used to select(2,7,2 select_tut) a ver-
       sion(1,3,5);  in(1,8) contrast, packages indexed  with  auto_mkindex  can  be  used
       immediately since there is no version(1,3,5) control.

       Pkg_mkIndex  depends  on  the  package  unknown  command,  the  package
       ifneeded command, and  the  auto-loader.   The  first  time(1,2,n)  a  package
       require  command  is  invoked,  the  package unknown script is invoked.
       This is set(7,n,1 builtins) by Tcl initialization to a script that evaluates all of the
       pkgIndex.tcl  files  in(1,8)  the auto_path.  The pkgIndex.tcl files contain
       package ifneeded commands for each version(1,3,5) of each  available  package;
       these  commands  invoke package provide commands to announce the avail-
       ability of the package, and they setup(2,8) auto-loader information to  load(7,n)
       the  files  of  the  package.   If the -lazy flag was provided when the |
       pkgIndex.tcl was generated, a given file(1,n) of a given version(1,3,5) of a  given
       package  isn't actually loaded until the first time(1,2,n) one of its commands
       is invoked.  Thus, after invoking package require you may not  see  the
       package's  commands  in(1,8) the interpreter, but you will be able to invoke
       the commands and they will be auto-loaded.

DIRECT LOADING                                                                 |
       Some packages, for instance packages which use  namespaces  and  export |
       commands  or  those  which require special initialization, might select(2,7,2 select_tut) |
       that their package files be loaded  immediately  upon  package  require |
       instead  of  delaying the actual loading to the first use of one of the |
       package's command. This is the default mode when generating the package |
       index.  It can be overridden by specifying the -lazy argument.

       Most  complex cases of dependencies among scripts and binary files, and
       packages being split(1,n) among scripts and binary  files  are  handled  OK.
       However,  you may have to adjust the order in(1,8) which files are processed
       by pkg_mkIndex.  These issues are described in(1,8) detail below.

       If each script or file(1,n) contains one package, and packages are only con-
       tained in(1,8) one file(1,n), then things are easy.  You simply specify all files
       to be indexed in(1,8) any order with some glob(1,3,7,n) patterns.

       In general, it is OK for scripts to have dependencies  on  other  pack-
       ages.   If  scripts contain package require commands, these are stubbed
       out in(1,8) the interpreter used to process the scripts,  so  these  do  not
       cause  problems.   If  scripts call into other packages in(1,8) global code,
       these calls are handled by a stub unknown command.  However, if(3,n) scripts
       make  variable  references to other package's variables in(1,8) global code,
       these will cause errors.  That is also bad coding style.

       If binary files have dependencies on other packages, things can  become
       tricky  because  it  is  not  possible to stub out C-level APIs such as
       Tcl_PkgRequire API when loading a binary file.   For  example,  suppose
       the  BLT  package  requires  Tk,  and  expresses  this  with  a call to
       Tcl_PkgRequire in(1,8) its Blt_Init routine.  To support this, you must  run
       pkg_mkIndex in(1,8) an interpreter that has Tk loaded.  You can achieve this
       with the -load pkgPat option.  If you specify this option,  pkg_mkIndex
       will load(7,n) any packages listed by info(1,5,n) loaded and that match pkgPat into
       the interpreter used to process files.  In most cases this will satisfy
       the Tcl_PkgRequire calls made by binary files.

       If  you are indexing two binary files and one depends on the other, you
       should specify the one that has dependencies last.  This  way  the  one
       without  dependencies will get loaded and indexed, and then the package
       it provides will be available when the second file(1,n) is  processed.   You
       may  also need to load(7,n) the first package into the temporary interpreter
       used to create the index by using the -load  flag;  it  won't  hurt  to
       specify package patterns that are not yet loaded.

       If  you  have a package that is split(1,n) across scripts and a binary file(1,n),
       then you should avoid the -load flag. The problem is that if(3,n) you load(7,n) a
       package  before  computing the index it masks any other files that pro-
       vide part of the same package.  If you must use -load,  then  you  must
       specify the scripts first; otherwise the package loaded from the binary
       file(1,n) may mask the package defined by the scripts.


       auto-load, index, package, version(1,3,5)

Tcl                                   8.3                       pkg_mkIndex(n)

References for this manual (incoming links)