Smalltalk User Guide : Setting up, customizing, and extending the system : Executing scripted Smalltalk code during image start up
Executing scripted Smalltalk code during image start up
A configuration (.cnf) file is an optional file expected to contain Smalltalk statement chunks that are executed during the image startup process. The reasons for adding this code to image startup typically relate to the automation of testing and packaging processes.
Historically, the configuration (.cnf) file was used to initialize image settings such as setting the Envy library values. This approach to initialization was later replaced by the use of the ini file (abt.ini). (See Using and maintaining configuration (.ini) files.) Though the configuration (.cnf) file is no longer required by VAST Platform, it is still processed during the image startup process if it exists in the startup directory.
The statements in the configuration (.cnf) file must be grouped together into one or more compilation units (chunks) by terminating each code group with an exclamation mark (!). Any exclamation marks contained in the code need to be doubled so that the code processor does not think the end of a chunk has been reached.
The configuration (.cnf) file contents are processed very early in the startup sequence since the original intent of the configuration (.cnf) file was to set image values required for the image to startup properly. This makes automating startup tasks challenging because the image is not fully functional at the time the file is processed. To make automation tasks easier to code, the processing of the configuration (.cnf) file has been divided into two unique processing sections. The first section is processed at the same point in the startup sequence that it has historically run. The second section is processed after the image startup sequence has completed, allowing users to execute most valid Smalltalk code in this second section.
The two sections of the file are separated by the following code chunk:
If this code chunk is not found in the configuration file, the entire contents of the file are processed during the early part of the image startup sequence. If it is present, the code chunks prior to it are processed during the early part of the startup sequence, and those following it are processed after image startup has completed.
There are two parts to loading an image: pre-startUp and post-startUp. After some initialization, the method EmSystemConfiguration>>startUp sends the startUp message to all loaded Applications and Subapplications. This moment of execution is demarcated by the PostStartup chunk in the configuration (.cnf) file.
We recommend that you use the PostStartup section of the configuration (.cnf) file, unless you need to initialize something very early in the startup sequence, on which your Application startup code relies.
The default name for the configuration file (abt.cnf) is hard-coded in the class variable ConfigurationFileName of the class EsImageStartUp. Users can customize it via the setter #configurationFileName:. In addition, beginning in version 11.0.0, users can customize the configuration file name using the command line.
The examples below show some of the Smalltalk code which can be performed during image startup.
Note on writing to Console
The examples below that write to TranscriptTTY default require that the image starts with the -l (minus el) option. This command line option makes the console available and redirects console output to a named file. For more, see command line.
Ex: pre and post startup
Here is a simple example you can try out to see how a configuration (.cnf) file is structured and to see why the post startup section was added:
Smalltalk at: #TEMP put: OrderedCollection new!
TEMP add: '1'.
TEMP add: '2'.
TEMP add: '3'
TEMP add: ‘!!’ “Exclamation marks in the Smalltalk code must be doubled to avoid being interpreted as the end of a code chunk” !
Transcript cr; show: ‘This message will not show up because the system is not fully initialized yet.’!
Transcript cr; show: 'TEMP = ', TEMP printString!
Smalltalk removeKey: #TEMP!
Statements in a configuration (.cnf) file that do not compile will be shown on the Transcript but will not generally halt image initialization.
Ex: Load code
Load the configuration map Hello World.
PostStartUp !
System loadedSubApplications do: [:app | app recacheMethodPointers.]!
"load the map" !
((EmConfigurationMap editionsFor: 'Hello World') first loadWithRequiredMaps) ifFalse: [System exit]. !
"save the image" !
System saveImage: 'helloWorld.icx' !
Ex: Test code library size
See if the development library is configured to hold 16 gigabytes.
PostStartUp !
TranscriptTTY default show: (EmLibrary default versionNumber = 6) printString !
System exit !
Ex: Automate packaging
Load the Hello World Configuration map and create a runtime image.
PostStartUp !
System loadedSubApplications do: [:app | app recacheMethodPointers.]!
(EmConfigurationMap editionsFor: 'Hello World') first load. !
“store the result of packaging. ok will be true if successful " !
| ok |
ok := (EpPackager packageUsingInstructions: HelloWorldPackagingInstructions withProgressMessage:
(DirectedMessage receiver: EpPackager basicNew selector: #packageApplicationsFractionComplete:progressDialog: arguments: (Array with: 0 with: EtProgressReporter basicNew))).
TranscriptTTY default show: ok printString;cr. !
System exit !
Last modified date: 04/19/2022