1 |
578 |
markom |
'\"
|
2 |
|
|
'\" Copyright (c) 1996 Sun Microsystems, Inc.
|
3 |
|
|
'\"
|
4 |
|
|
'\" See the file "license.terms" for information on usage and redistribution
|
5 |
|
|
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
6 |
|
|
'\"
|
7 |
|
|
'\" RCS: @(#) $Id: package.n,v 1.1.1.1 2002-01-16 10:25:24 markom Exp $
|
8 |
|
|
'\"
|
9 |
|
|
.so man.macros
|
10 |
|
|
.TH package n 7.5 Tcl "Tcl Built-In Commands"
|
11 |
|
|
.BS
|
12 |
|
|
'\" Note: do not modify the .SH NAME line immediately below!
|
13 |
|
|
.SH NAME
|
14 |
|
|
package \- Facilities for package loading and version control
|
15 |
|
|
.SH SYNOPSIS
|
16 |
|
|
.nf
|
17 |
|
|
\fBpackage forget \fIpackage\fR
|
18 |
|
|
\fBpackage ifneeded \fIpackage version\fR ?\fIscript\fR?
|
19 |
|
|
\fBpackage names\fR
|
20 |
|
|
\fBpackage provide \fIpackage \fR?\fIversion\fR?
|
21 |
|
|
\fBpackage require \fR?\fB\-exact\fR? \fIpackage \fR?\fIversion\fR?
|
22 |
|
|
\fBpackage unknown \fR?\fIcommand\fR?
|
23 |
|
|
\fBpackage vcompare \fIversion1 version2\fR
|
24 |
|
|
\fBpackage versions \fIpackage\fR
|
25 |
|
|
\fBpackage vsatisfies \fIversion1 version2\fR
|
26 |
|
|
.fi
|
27 |
|
|
.BE
|
28 |
|
|
|
29 |
|
|
.SH DESCRIPTION
|
30 |
|
|
.PP
|
31 |
|
|
This command keeps a simple database of the packages available for
|
32 |
|
|
use by the current interpreter and how to load them into the
|
33 |
|
|
interpreter.
|
34 |
|
|
It supports multiple versions of each package and arranges
|
35 |
|
|
for the correct version of a package to be loaded based on what
|
36 |
|
|
is needed by the application.
|
37 |
|
|
This command also detects and reports version clashes.
|
38 |
|
|
Typically, only the \fBpackage require\fR and \fBpackage provide\fR
|
39 |
|
|
commands are invoked in normal Tcl scripts; the other commands are used
|
40 |
|
|
primarily by system scripts that maintain the package database.
|
41 |
|
|
.PP
|
42 |
|
|
The behavior of the \fBpackage\fR command is determined by its first argument.
|
43 |
|
|
The following forms are permitted:
|
44 |
|
|
.TP
|
45 |
|
|
\fBpackage forget \fIpackage\fR
|
46 |
|
|
Removes all information about \fIpackage\fR from this interpreter,
|
47 |
|
|
including information provided by both \fBpackage ifneeded\fR and
|
48 |
|
|
\fBpackage provide\fR.
|
49 |
|
|
.TP
|
50 |
|
|
\fBpackage ifneeded \fIpackage version\fR ?\fIscript\fR?
|
51 |
|
|
This command typically appears only in system configuration
|
52 |
|
|
scripts to set up the package database.
|
53 |
|
|
It indicates that a particular version of
|
54 |
|
|
a particular package is available if needed, and that the package
|
55 |
|
|
can be added to the interpreter by executing \fIscript\fR.
|
56 |
|
|
The script is saved in a database for use by subsequent
|
57 |
|
|
\fBpackage require\fR commands; typically, \fIscript\fR
|
58 |
|
|
sets up auto-loading for the commands in the package (or calls
|
59 |
|
|
\fBload\fR and/or \fBsource\fR directly), then invokes
|
60 |
|
|
\fBpackage provide\fR to indicate that the package is present.
|
61 |
|
|
There may be information in the database for several different
|
62 |
|
|
versions of a single package.
|
63 |
|
|
If the database already contains information for \fIpackage\fR
|
64 |
|
|
and \fIversion\fR, the new \fIscript\fR replaces the existing
|
65 |
|
|
one.
|
66 |
|
|
If the \fIscript\fR argument is omitted, the current script for
|
67 |
|
|
version \fIversion\fR of package \fIpackage\fR is returned,
|
68 |
|
|
or an empty string if no \fBpackage ifneeded\fR command has
|
69 |
|
|
been invoked for this \fIpackage\fR and \fIversion\fR.
|
70 |
|
|
.TP
|
71 |
|
|
\fBpackage names\fR
|
72 |
|
|
Returns a list of the names of all packages in the
|
73 |
|
|
interpreter for which a version has been provided (via
|
74 |
|
|
\fBpackage provide\fR) or for which a \fBpackage ifneeded\fR
|
75 |
|
|
script is available.
|
76 |
|
|
The order of elements in the list is arbitrary.
|
77 |
|
|
.TP
|
78 |
|
|
\fBpackage provide \fIpackage \fR?\fIversion\fR?
|
79 |
|
|
This command is invoked to indicate that version \fIversion\fR
|
80 |
|
|
of package \fIpackage\fR is now present in the interpreter.
|
81 |
|
|
It is typically invoked once as part of an \fBifneeded\fR script,
|
82 |
|
|
and again by the package itself when it is finally loaded.
|
83 |
|
|
An error occurs if a different version of \fIpackage\fR has been
|
84 |
|
|
provided by a previous \fBpackage provide\fR command.
|
85 |
|
|
If the \fIversion\fR argument is omitted, then the command
|
86 |
|
|
returns the version number that is currently provided, or an
|
87 |
|
|
empty string if no \fBpackage provide\fR command has been
|
88 |
|
|
invoked for \fIpackage\fR in this interpreter.
|
89 |
|
|
.TP
|
90 |
|
|
\fBpackage require \fR?\fB\-exact\fR? \fIpackage \fR?\fIversion\fR?
|
91 |
|
|
This command is typically invoked by Tcl code that wishes to use
|
92 |
|
|
a particular version of a particular package. The arguments
|
93 |
|
|
indicate which package is wanted, and the command ensures that
|
94 |
|
|
a suitable version of the package is loaded into the interpreter.
|
95 |
|
|
If the command succeeds, it returns the version number that is
|
96 |
|
|
loaded; otherwise it generates an error.
|
97 |
|
|
If both the \fB\-exact\fR
|
98 |
|
|
switch and the \fIversion\fR argument are specified then only the
|
99 |
|
|
given version is acceptable. If \fB\-exact\fR is omitted but
|
100 |
|
|
\fIversion\fR is specified, then versions later than \fIversion\fR
|
101 |
|
|
are also acceptable as long as they have the same major version
|
102 |
|
|
number as \fIversion\fR.
|
103 |
|
|
If both \fB\-exact\fR and \fIversion\fR are omitted then any
|
104 |
|
|
version whatsoever is acceptable.
|
105 |
|
|
If a version of \fIpackage\fR has already been provided (by invoking
|
106 |
|
|
the \fBpackage provide\fR command), then its version number must
|
107 |
|
|
satisfy the criteria given by \fB\-exact\fR and \fIversion\fR and
|
108 |
|
|
the command returns immediately.
|
109 |
|
|
Otherwise, the command searches the database of information provided by
|
110 |
|
|
previous \fBpackage ifneeded\fR commands to see if an acceptable
|
111 |
|
|
version of the package is available.
|
112 |
|
|
If so, the script for the highest acceptable version number is invoked;
|
113 |
|
|
it must do whatever is necessary to load the package,
|
114 |
|
|
including calling \fBpackage provide\fR for the package.
|
115 |
|
|
If the \fBpackage ifneeded\fR database does not contain an acceptable
|
116 |
|
|
version of the package and a \fBpackage unknown\fR command has been
|
117 |
|
|
specified for the interpreter then that command is invoked; when
|
118 |
|
|
it completes, Tcl checks again to see if the package is now provided
|
119 |
|
|
or if there is a \fBpackage ifneeded\fR script for it.
|
120 |
|
|
If all of these steps fail to provide an acceptable version of the
|
121 |
|
|
package, then the command returns an error.
|
122 |
|
|
.TP
|
123 |
|
|
\fBpackage unknown \fR?\fIcommand\fR?
|
124 |
|
|
This command supplies a ``last resort'' command to invoke during
|
125 |
|
|
\fBpackage require\fR if no suitable version of a package can be found
|
126 |
|
|
in the \fBpackage ifneeded\fR database.
|
127 |
|
|
If the \fIcommand\fR argument is supplied, it contains the first part
|
128 |
|
|
of a command; when the command is invoked during a \fBpackage require\fR
|
129 |
|
|
command, Tcl appends two additional arguments giving the desired package
|
130 |
|
|
name and version.
|
131 |
|
|
For example, if \fIcommand\fR is \fBfoo bar\fR and later the command
|
132 |
|
|
\fBpackage require test 2.4\fR is invoked, then Tcl will execute
|
133 |
|
|
the command \fBfoo bar test 2.4\fR to load the package.
|
134 |
|
|
If no version number is supplied to the \fBpackage require\fR command,
|
135 |
|
|
then the version argument for the invoked command will be an empty string.
|
136 |
|
|
If the \fBpackage unknown\fR command is invoked without a \fIcommand\fR
|
137 |
|
|
argument, then the current \fBpackage unknown\fR script is returned,
|
138 |
|
|
or an empty string if there is none.
|
139 |
|
|
If \fIcommand\fR is specified as an empty string, then the current
|
140 |
|
|
\fBpackage unknown\fR script is removed, if there is one.
|
141 |
|
|
.TP
|
142 |
|
|
\fBpackage vcompare \fIversion1 version2\fR
|
143 |
|
|
Compares the two version numbers given by \fIversion1\fR and \fIversion2\fR.
|
144 |
|
|
Returns -1 if \fIversion1\fR is an earlier version than \fIversion2\fR,
|
145 |
|
|
|
146 |
|
|
.TP
|
147 |
|
|
\fBpackage versions \fIpackage\fR
|
148 |
|
|
Returns a list of all the version numbers of \fIpackage\fR
|
149 |
|
|
for which information has been provided by \fBpackage ifneeded\fR
|
150 |
|
|
commands.
|
151 |
|
|
.TP
|
152 |
|
|
\fBpackage vsatisfies \fIversion1 version2\fR
|
153 |
|
|
Returns 1 if scripts written for \fIversion2\fR will work unchanged
|
154 |
|
|
with \fIversion1\fR (i.e. \fIversion1\fR is equal to or greater
|
155 |
|
|
than \fIversion2\fR and they both have the same major version
|
156 |
|
|
number), 0 otherwise.
|
157 |
|
|
|
158 |
|
|
.SH "VERSION NUMBERS"
|
159 |
|
|
.PP
|
160 |
|
|
Version numbers consist of one or more decimal numbers separated
|
161 |
|
|
by dots, such as 2 or 1.162 or 3.1.13.1.
|
162 |
|
|
The first number is called the major version number.
|
163 |
|
|
Larger numbers correspond to later versions of a package, with
|
164 |
|
|
leftmost numbers having greater significance.
|
165 |
|
|
For example, version 2.1 is later than 1.3 and version
|
166 |
|
|
3.4.6 is later than 3.3.5.
|
167 |
|
|
Missing fields are equivalent to zeroes: version 1.3 is the
|
168 |
|
|
same as version 1.3.0 and 1.3.0.0, so it is earlier than 1.3.1 or 1.3.0.2.
|
169 |
|
|
A later version number is assumed to be upwards compatible with
|
170 |
|
|
an earlier version number as long as both versions have the same
|
171 |
|
|
major version number.
|
172 |
|
|
For example, Tcl scripts written for version 2.3 of a package should
|
173 |
|
|
work unchanged under versions 2.3.2, 2.4, and 2.5.1.
|
174 |
|
|
Changes in the major version number signify incompatible changes:
|
175 |
|
|
if code is written to use version 2.1 of a package, it is not guaranteed
|
176 |
|
|
to work unmodified with either version 1.7.3 or version 3.1.
|
177 |
|
|
|
178 |
|
|
.SH "PACKAGE INDICES"
|
179 |
|
|
.PP
|
180 |
|
|
The recommended way to use packages in Tcl is to invoke \fBpackage require\fR
|
181 |
|
|
and \fBpackage provide\fR commands in scripts, and use the procedure
|
182 |
|
|
\fBpkg_mkIndex\fR to create package index files.
|
183 |
|
|
Once you've done this, packages will be loaded automatically
|
184 |
|
|
in response to \fBpackage require\fR commands.
|
185 |
|
|
See the documentation for \fBpkg_mkIndex\fR for details.
|
186 |
|
|
|
187 |
|
|
.SH KEYWORDS
|
188 |
|
|
package, version
|