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
The abt.cnf file is an optional file expected to contain Smalltalk statement chunks that are executed during the startup process. The statements 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.
Historically, the abt.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 abt.ini file. Though the abt.cnf file is no longer required by VA Smalltalk, it is still processed during the image startup process if it exists in the startup directory.
The name abt.cnf is hard-coded in the class variable ConfigurationFileName of the class EsImageStartUp.
Users that have discovered this forgotten feature have found interesting uses for it, typically related to automating testing and packaging processes.
New in 8.6.2:
The abt.cnf file contents are processed very early in the startup sequence since the original intent of the abt.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 abt.cnf file has been divided into two unique processing sections. The first section is still processed at the same point in the startup sequence that it has historically run. The new section is processed after the image startup sequence has completed, allowing you to execute most any valid Smalltalk code in this section.
The two sections of the file are separated by the following code chunk:
If this code chunk is not found in the abt.cnf 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 demarkated by the PostStartup chunk in the abt.cnf file.
We recommend that you use the PostStartup section of abt.cnf, unless you need to initialize something very early in the startup sequence, on which your Application startup code relies.
Writing to Console
The examples below that write to TranscriptTTY default require that you have run the image with the -l (minus el) option:
abt.exe -lCON
On Windows, this is needed to make the conlsole visible.
abt.exe -lxyzzy.txt
Output to file xyzzt.txt
Ex: pre and post startup
Here is a simple example you can try out to see how an abt.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 abt.cnf 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 code 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: 03/17/2020