The current implementation for parsing Tcl config files fails to catch environment variables defined in subordinate .tcl files included from the main .tcl with the source command. This breaks openlane1 compatibility for almost every user design submitted to Tiny Tapeout.
Tcl config files are parsed using TclUtils._eval_env(). The current version
modifies os.environ to provide inputs to the script
runs the script
converts ::env to numbered variables on the tcl side
rolls back the changes to os.environ
reads the numbered variables from tcl back into python
filters the results to entries appearing in set ::env(...) constructs in the script
The last step is there to filter out entries inherited from the environment, but it also filters out entries defined in included files. This python-tcl interface relying on os.environ modifications and rewriting ::env to numbered variables also feels brittle in some other ways. I'm proposing to rewrite it in the following manner:
set env(...) directly instead of modifying and rolling back os.environ
provide a python callback function to tcl code for easier backwards communication
patch tcl's set function to also call our callback
on the python side, save all set calls that match env(...) to the returned dictionary
This makes the code more robust and only saves environment variables explicitly set by the Tcl config, making it unnecessary to use the problematic filtering step.
Merging to main. Rationale: fixes incompatibility with OpenLane 1 config files.
Misc Enhancements/Bugfixes
Overhauled Tcl configuration loading code to fix a number of bugs that may occur when a Tcl file sources another Tcl file, such as for TinyTapeout-based configs (thanks @htfab)
The current implementation for parsing Tcl config files fails to catch environment variables defined in subordinate
.tcl
files included from the main.tcl
with thesource
command. This breaks openlane1 compatibility for almost every user design submitted to Tiny Tapeout.Tcl config files are parsed using
TclUtils._eval_env()
. The current versionos.environ
to provide inputs to the script::env
to numbered variables on the tcl sideos.environ
set ::env(...)
constructs in the scriptThe last step is there to filter out entries inherited from the environment, but it also filters out entries defined in included files. This python-tcl interface relying on
os.environ
modifications and rewriting::env
to numbered variables also feels brittle in some other ways. I'm proposing to rewrite it in the following manner:env(...)
directly instead of modifying and rolling backos.environ
set
function to also call our callbackset
calls that matchenv(...)
to the returned dictionaryThis makes the code more robust and only saves environment variables explicitly set by the Tcl config, making it unnecessary to use the problematic filtering step.