Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
donn committed May 19, 2024
2 parents a398e6b + 7bf52ac commit a41330c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
14 changes: 14 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
## API Breaks
## Documentation
-->
# 2.0.7

## 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
configs (thanks @htfab)

# 2.0.6

## Misc. Enhancements/Bugfixes
* Fixed a crash on Linux distributions where `/etc/lsb-release` includes
comments.

# 2.0.5

## Misc. Enhancements/Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion openlane/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "2.0.5"
__version__ = "2.0.7"

if __name__ == "__main__":
print(__version__, end="")
49 changes: 15 additions & 34 deletions openlane/common/tcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
import tkinter
from typing import Dict, Mapping, Any, Iterable

_setter_rx = re.compile(r"set\s+(?:\:\:)?env\(\s*(\w+)\s*\)")
_env_rx = re.compile(r"(?:\:\:)?env\((\w+)\)")
_find_unsafe = re.compile(r"[^\w@%+=:,./-]", re.ASCII).search
_escapes_in_quotes = re.compile(r"([\\\$\"\[])")

Expand Down Expand Up @@ -57,43 +56,25 @@ def join(ss: Iterable[str]) -> str:
@staticmethod
def _eval_env(env_in: Mapping[str, Any], tcl_in: str) -> Dict[str, Any]:
interpreter = tkinter.Tcl()
keys_modified = _setter_rx.findall(tcl_in)

env_out = dict(env_in)
rollback = {}
interpreter.eval("array unset ::env")
for key, value in env_in.items():
rollback[key] = os.getenv(key)
os.environ[key] = str(value)
interpreter.setvar(f"env({key})", str(value))

tcl_script = f"""
{tcl_in}
set counter 0
foreach key [array names ::env] {{
set "key$counter" $key
set "value$counter" $::env($key)
incr counter
}}
"""
interpreter.eval(tcl_script)
env_out = dict(env_in)

for key, value in rollback.items():
if value is not None:
os.environ[key] = value
else:
del os.environ[key]
def py_set(key, value=None):
if match := _env_rx.fullmatch(key):
if value is not None:
env_out[match.group(1)] = value

counter = 0
while True:
key_var = f"key{counter}"
value_var = f"value{counter}"
py_set_name = interpreter.register(py_set)
interpreter.call("rename", py_set_name, "_py_set")
interpreter.call("rename", "set", "_orig_set")
interpreter.eval(
"proc set args { _py_set {*}$args; tailcall _orig_set {*}$args; }"
)

try:
key = interpreter.getvar(key_var)
except tkinter.TclError:
break
value = interpreter.getvar(value_var)
if key in keys_modified:
env_out[key] = value
counter += 1
interpreter.eval(tcl_in)

return env_out
2 changes: 2 additions & 0 deletions openlane/env_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def get():
for line in os_release.split("\n"):
if line.strip() == "":
continue
if line.strip().startswith("#"):
continue
key, value = line.split("=")
value = value.strip('"')

Expand Down

0 comments on commit a41330c

Please sign in to comment.