TIP #59 Version 1.8: Embed Build Information in Tcl Binary Library

This is not necessarily the current version of this TIP.


TIP:59
Title:Embed Build Information in Tcl Binary Library
Version:$Revision: 1.8 $
Author:Andreas Kupries <andreas_kupries at users dot sourceforge dot net>
State:Draft
Type:Project
Tcl-Version:8.4
Vote:Pending
Created:Tuesday, 04 September 2001

Abstract

This TIP provides an interface through which Tcl may be queried for information on its own configuration, in order to extract the information directly instead of reading it from a Bourne shell file. An important reason to do this is to have the information not only available but also tightly bound to the binary configured by it, so that the information doesn't get lost.

Foreword

This TIP proposes a rather small change to Tcl and tries very hard to follow the KISS principle. Given that the casual observer might find it rather long, be assured, the actual specification in here is not very long, nor complicated. Most of the following explanations were added to preserve the KISS principle and head off attempts to extend the TIP beyond its small goal and scope.

Note: All instances of "Tcl library" in the following text refer to the generated installable library and not the script library coming with the core.

Background and Rationale

The main reason for writing this TIP are the disadvantages inherent in the current way of storing the configuration of Tcl, namely in the file tclConfig.sh.

Thus, this TIP proposes:

The file tclConfig.sh is not replaced by this system, both sets of information exist in parallel.

Neither is the variable tcl_platform replaced. This means that some information, like threaded, is held redundantly. Other information in tcl_platform, like user is runtime and not configuration information. The operating system information is important to a build system, but this is out of the scope of this TIP.

Interface Specification

Any embedded information is made accessible at the Tcl level through a new command. The name of the command used by Tcl itself is ::tcl::pkgconfig. Extensions have to use their own commands. These commands will be named pkgconfig too and have to be placed within in the namespaces owned by the extensions initializing them.

At the C-level the public API of the Tcl core is extended with a single function to register the embedded configuration information. This function is added to the public stub table of the Tcl core so that it can be used by Tcl and extensions to register their own configuration information in the system during initialization.

The function takes three (3) arguments; first, the name of the package registering its configuration information, second, a pointer to an array of structures, and third a string declaring the encoding used by the configuration values. Each element of the array refers to two strings containing the key and the value associated with that key. The end of the array is signaled by an empty key.

Formalized, name and signature of this new function are

 Tcl_RegisterConfig (CONST char* pkgName, Config* configuration, CONST char* valEncoding)

 typedef struct Config {
    char* key;
    char* value;
 }

The string valEncoding contains the name of an encoding known to Tcl. All these names are use only characters in the ASCII subset of UTF-8 and are thus implicity in the UTF-8 encoding. It is expected that keys are legible english text and therefore using the ASCII subset of UTF-8. In other words, they are expected to be in UTF-8 too. The values associated with the keys can be any string however. For these the contents of valEncoding define which encoding was used to represent the characters of the strings.

During compile time the value of valEncoding is specified as a makefile variable for non-configure based build systems and through the new option --with-encoding=FOO of configure otherwise. The default value is iso8859-1.

This approach gives us all what we desire with not too many drawbacks.

The function will

The command pkgconfig will provide two subcommands, list and get. The first subcommand, list takes no arguments and returns a list containing the names of the defined keys. The second subcommand takes one argument, the name of a key and returns the string associated with that key.

How to Gather the Embedded Information

The information to be embedded is gathered in a platform-specific way and written into the file generic/tclConfig.c. The different platforms may employ platform specific intermediate files to hold the information, but in the ocmpilation phase only tclConfig.c will be used.

Specification of Tcl Configuration Information

The configuration information registered by Tcl itself is specified here. A discussion of the choices made here follows in the next section. Please read this discussion before commenting on the specification.

The values associated with the keys below are all of one of the following types:

The registered keys follow below. They will be always present with some value. Non-boolean keys not applicable to a particular platform will contain the empty string as their value.