pkgmkindex.n

来自「tcl是工具命令语言」· N 代码 · 共 245 行

N
245
字号
'\"'\" Copyright (c) 1996 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" RCS: @(#) $Id: pkgMkIndex.n,v 1.14 2003/02/25 23:58:09 dgp Exp $'\" .so man.macros.TH pkg_mkIndex n 8.3 Tcl "Tcl Built-In Commands".BS'\" Note:  do not modify the .SH NAME line immediately below!.SH NAMEpkg_mkIndex \- Build an index for automatic loading of packages.SH SYNOPSIS.nf.VS 8.3.0\fBpkg_mkIndex ?\fI\-direct\fR?  ?\fI\-lazy\fR?  ?\fI\-load pkgPat\fR? ?\fI\-verbose\fR? \fIdir\fR ?\fIpattern pattern ...\fR?.VE.fi.BE.SH DESCRIPTION.PP\fBPkg_mkIndex\fR is a utility procedure that is part of the standardTcl library.It is used to create index files that allow packages to be loadedautomatically when \fBpackage require\fR commands are executed.To use \fBpkg_mkIndex\fR, follow these steps:.IP [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 \fBload\fR commandwith a single argument;  for example, if the file is \fBtest.so\fR it mustbe possible to load this file with the command \fBload test.so\fR.Each script file must contain a \fBpackage provide\fR command to declarethe package and version number, and each binary file must containa call to \fBTcl_PkgProvide\fR..IP [2]Create the index by invoking \fBpkg_mkIndex\fR.The \fIdir\fR argument gives the name of a directory and each\fIpattern\fR argument is a \fBglob\fR-style pattern that selectsscript or binary files in \fIdir\fR..VS 8.0.3The default pattern is \fB*.tcl\fR and \fB*.[info sharedlibextension]\fR..VE.br\fBPkg_mkIndex\fR will create a file \fBpkgIndex.tcl\fR in \fIdir\fRwith package information about all the files given by the \fIpattern\fRarguments.It does this by loading each file into a slaveinterpreter and seeing what packagesand new commands appear (this is why it is essential to have\fBpackage provide\fR commands or \fBTcl_PkgProvide\fR callsin the files, as described above).If you have a package split among scripts and binary files, or if you have dependencies among files,you may have to use the \fB\-load\fP optionor adjust the order in which \fBpkg_mkIndex\fR processesthe files.  See COMPLEX CASES below..IP [3]Install the package as a subdirectory of one of the directories given bythe \fBtcl_pkgPath\fR variable.  If \fB$tcl_pkgPath\fR contains morethan one directory, machine-dependent packages (e.g., those thatcontain binary shared libraries) should normally be installedunder the first directory and machine-independent packages (e.g.,those that contain only Tcl scripts) should be installed under thesecond directory.The subdirectory should includethe package's script and/or binary files as well as the \fBpkgIndex.tcl\fRfile.  As long as the package is installed as a subdirectory of adirectory in \fB$tcl_pkgPath\fR it will automatically be found during\fBpackage require\fR commands..brIf you install the package anywhere else, then you must ensure thatthe directory containing the package is in the \fBauto_path\fR global variableor an immediate subdirectory of one of the directories in \fBauto_path\fR.\fBAuto_path\fR contains a list of directories that are searchedby both the auto-loader and the package loader; by default itincludes \fB$tcl_pkgPath\fR.The package loader also checks all of the subdirectories of thedirectories in \fBauto_path\fR.You can add a directory to \fBauto_path\fR explicitly in yourapplication, or you can add the directory to your \fBTCLLIBPATH\fRenvironment variable:  if this environment variable is present,Tcl initializes \fBauto_path\fR from it during application startup..IP [4]Once the above steps have been taken, all you need to do to use apackage is to invoke \fBpackage require\fR.For example, if versions 2.1, 2.3, and 3.1 of package \fBTest\fRhave been indexed by \fBpkg_mkIndex\fR, the command\fBpackage require Test\fR will make version 3.1 availableand the command \fBpackage require \-exact Test 2.1\fR willmake version 2.1 available.There may be many versions of a package in the various index filesin \fBauto_path\fR, but only one will actually be loaded in a giveninterpreter, based on the first call to \fBpackage require\fR.Different versions of a package may be loaded in differentinterpreters..SH OPTIONSThe optional switches are:.TP 15\fB\-direct\fRThe generated index will implement direct loading of the packageupon \fBpackage require\fR.  This is the default..TP 15\fB\-lazy\fRThe generated index will manage to delay loading the package until theuse of one of the commands provided by the package, instead of loadingit immediately upon \fBpackage require\fR..TP 15\fB\-load \fIpkgPat\fRThe index process will pre-load any packages that exist in thecurrent interpreter and match \fIpkgPat\fP into the slave interpreter used togenerate the index.  The pattern match uses string match rules, but withoutmaking case distinctions.See COMPLEX CASES below..TP 15\fB\-verbose\fRGenerate output during the indexing process.  Output is viathe \fBtclLog\fP procedure, which by default prints to stderr..TP 15\fB\-\-\fREnd of the flags, in case \fIdir\fP begins with a dash..SH "PACKAGES AND THE AUTO-LOADER".PPThe package management facilities overlap somewhat with the auto-loader,in that both arrange for files to be loaded on-demand.However, package management is a higher-level mechanism that usesthe auto-loader for the last step in the loading process.It is generally better to index a package with \fBpkg_mkIndex\fRrather than \fBauto_mkindex\fR because the package mechanism providesversion control:  several versions of a package can be made availablein the index files, with different applications using differentversions based on \fBpackage require\fR commands.In contrast, \fBauto_mkindex\fR does not understand versions soit can only handle a single version of each package. It is probably not a good idea to index a given package with both\fBpkg_mkIndex\fR and \fBauto_mkindex\fR.If you use \fBpkg_mkIndex\fR to index a package, its commands cannotbe invoked until \fBpackage require\fR has been used to select aversion;  in contrast, packages indexed with \fBauto_mkindex\fRcan be used immediately since there is no version control..SH "HOW IT WORKS".PP\fBPkg_mkIndex\fR depends on the \fBpackage unknown\fR command,the \fBpackage ifneeded\fR command, and the auto-loader.The first time a \fBpackage require\fR command is invoked,the \fBpackage unknown\fR script is invoked.This is set by Tcl initialization to a script thatevaluates all of the \fBpkgIndex.tcl\fR files in the\fBauto_path\fR.The \fBpkgIndex.tcl\fR files contain \fBpackage ifneeded\fRcommands for each version of each available package;  these commandsinvoke \fBpackage provide\fR commands to announce theavailability of the package, and they setup auto-loaderinformation to load the files of the package..VS 8.3If the \fI\-lazy\fR flag was provided when the \fBpkgIndex.tcl\fRwas generated,.VEa given file of a given version of a given package isn'tactually loaded until the first time one of its commandsis invoked.Thus, after invoking \fBpackage require\fR you maynot see the package's commands in the interpreter, but you will be ableto invoke the commands and they will be auto-loaded..VS 8.3.SH "DIRECT LOADING".PPSome packages, for instance packages which use namespaces and exportcommands or those which require special initialization, might selectthat their package files be loaded immediately upon \fBpackage require\fRinstead of delaying the actual loading to the first use of one of thepackage's command. This is the default mode when generating the packageindex.  It can be overridden by specifying the \fI\-lazy\fR argument..VE.SH "COMPLEX CASES"Most complex cases of dependencies among scriptsand binary files, and packages being split among scripts andbinary files are handled OK.  However, you may have to adjustthe order in which files are processed by \fBpkg_mkIndex\fR.These issues are described in detail below..PPIf each script or file contains one package, and packagesare only contained in one file, then things are easy.You simply specify all files to be indexed in any orderwith some glob patterns..PPIn general, it is OK for scripts to have dependencies on otherpackages.If scripts contain \fBpackage require\fP commands, these arestubbed out in the interpreter used to process the scripts,so these do not cause problems.If scripts call into other packages in global code,these calls are handled by a stub \fBunknown\fP command.However, if scripts make variable references to other package'svariables in global code, these will cause errors.  That isalso bad coding style..PPIf binary files have dependencies on other packages, thingscan become tricky because it is not possible to stub outC-level APIs such as \fBTcl_PkgRequire\fP APIwhen loading a binary file.For example, suppose the BLT package requires Tk, and expressesthis with a call to \fBTcl_PkgRequire\fP in its \fBBlt_Init\fP routine.To support this, you must run \fBpkg_mkIndex\fR in an interpreter thathas Tk loaded.  You can achieve this with the\fB\-load \fIpkgPat\fR option.  If you specify this option,\fBpkg_mkIndex\fR will load any packages listed by\fBinfo loaded\fP and that match \fIpkgPat\fPinto the interpreter used to process files.In most cases this will satisfy the \fBTcl_PkgRequire\fP callsmade by binary files..PPIf 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 provideswill be available when the second file is processed.You may also need to load the first package into thetemporary interpreter used to create the index by usingthe \fB\-load\fP flag;it won't hurt to specify package patterns that are not yet loaded..PPIf you have a package that is split across scripts and a binary file,then you should avoid the \fB\-load\fP flag. The problem is thatif you load a package before computing the index it masks anyother files that provide part of the same package.If you must use \fB\-load\fP,then you must specify the scripts first; otherwise the package loaded fromthe binary file may mask the package defined by the scripts..SH "SEE ALSO"package(n).SH KEYWORDSauto-load, index, package, version

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?