Skip to content

Commit

Permalink
Proper wine program locate + improved iverilog support
Browse files Browse the repository at this point in the history
  • Loading branch information
LudwigCRON committed May 31, 2020
1 parent c07c615 commit f991dca
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 150 deletions.
2 changes: 1 addition & 1 deletion analog/tools/ltspice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def run(asc: str):
if sys.platform == "darwin":
ltspice = "/Applications/LTspice.app/Contents/MacOS/LTspice"
elif sys.platform == "unix" or "linux" in sys.platform:
ltspice = 'wine "%s"' % shutil.which("XVIIx64.exe")
ltspice = 'wine "%s"' % utils.wine.locate("XVIIx64.exe")
asc = "z:%s" % asc
else:
ltspice = "XVIIx64.exe"
Expand Down
2 changes: 1 addition & 1 deletion analog/tools/ltspice_view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run(raw: str):
if sys.platform == "darwin":
ltspice = "/Applications/LTspice.app/Contents/MacOS/LTspice"
elif sys.platform == "unix" or "linux" in sys.platform:
ltspice = 'wine "%s"' % shutil.which("XVIIx64.exe")
ltspice = 'wine "%s"' % utils.wine.locate("XVIIx64.exe")
raw = "z:%s" % raw
else:
ltspice = "XVIIx64.exe"
Expand Down
2 changes: 0 additions & 2 deletions common/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def sh_exec(
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)
except (OSError, subprocess.CalledProcessError) as exception:
relog.error("Exception occured: ", str(exception))
return False
except subprocess.TimeoutExpired:
relog.error("Unexpected executer timeout")
Expand Down Expand Up @@ -125,7 +124,6 @@ def ish_exec(
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)
except (OSError, subprocess.CalledProcessError) as exception:
relog.error("Exception occured: ", str(exception))
return False
except subprocess.TimeoutExpired:
relog.error("Unexpected executer timeout")
Expand Down
1 change: 1 addition & 0 deletions common/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
import common.utils.tools as tools
import common.utils.graphs as graphs
import common.utils.parsers as parsers
import common.utils.wine as wine

from common.utils.run import *
19 changes: 19 additions & 0 deletions common/utils/wine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
# coding: utf-8

import os

from pathlib import Path


def locate(program: str):
"""
locate where an exe file is store in a wine installation
wine load application in WINEPREFIX (by default $HOME/.wine)
"""
wineprefix = os.getenv("WINEPREFIX") or os.path.join(os.getenv("HOME"), ".wine")
ans = []
for file in Path(wineprefix).rglob("**/*.exe"):
if program in str(file):
ans.append(str(file))
return ans[-1]
36 changes: 22 additions & 14 deletions digital/tools/iverilog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@

def transform_flags(flags: str) -> str:
flags = flags.strip()
if "-DEFINE " in flags:
flags = flags.replace("-DEFINE ", "+define+")
if "-define " in flags:
flags = flags.replace("-define ", "+define+")
if "-PARAM " in flags:
flags = flags.replace("-PARAM ", "+parameter+")
if "-param " in flags:
flags = flags.replace("-param ", "+parameter+")
# replace any values found by the key
matches = {
"+define+": ["-DEFINE ", "-define ", "-D", "-d"],
"+parameter+": ["-PARAM ", "-param ", "-P", "-p"],
}
for output, inputs in matches.items():
for i in inputs:
if i in flags:
flags = flags.replace(i, output)
# generate a string
flags = [flag for flag in flags.split(" ") if not flag.startswith("-g")]
return " ".join(flags)

Expand Down Expand Up @@ -78,12 +80,18 @@ def compile(generation, flags):
"iverilog -g%s -grelative-include %s -Wall -o %s -c %s"
% (generation, flags, EXE, SRCS)
)
executor.sh_exec(
"iverilog -g%s -grelative-include %s -Wall -o %s -c %s"
% (generation, flags, EXE, SRCS),
PARSER_LOG,
MAX_TIMEOUT=20,
)
try:
executor.sh_exec(
"iverilog -g%s -grelative-include %s -Wall -o %s -c %s"
% (generation, flags, EXE, SRCS),
PARSER_LOG,
MAX_TIMEOUT=20,
)
# ignore return code error
# as message is already displayed in stdout
# and in the log file
except subprocess.CalledProcessError:
pass


def run(lint: bool = False):
Expand Down
Loading

0 comments on commit f991dca

Please sign in to comment.