Squashed commit of the following:
commit 9a5e1af9b969e3cbacdab1ece7ef25190194b3d5 Author: Joppe Blondel <joppe@blondel.nl> Date: Sun Sep 4 19:32:35 2022 +0200 Cleaned up tree Signed-off-by: Joppe Blondel <joppe@blondel.nl> commit 5f5556409a71afc904bb9df0915cd236d87fccb1 Author: Joppe Blondel <joppe@blondel.nl> Date: Sun Sep 4 19:31:20 2022 +0200 Split up different scripts Signed-off-by: Joppe Blondel <joppe@blondel.nl> commit 6855e9a1e808a99c4a326be7ef49b9b545eaf4bd Author: Jojojoppe <joppe@blondel.nl> Date: Sun Sep 4 14:21:35 2022 +0200 Client server structure done Signed-off-by: Jojojoppe <joppe@blondel.nl> commit 44923b8b3407adb1f8f1c0d24c016613da68a726 Author: Jojojoppe <joppe@blondel.nl> Date: Sat Sep 3 22:35:00 2022 +0200 Moved basic stuff to exec_class Signed-off-by: Jojojoppe <joppe@blondel.nl> Signed-off-by: Joppe Blondel <joppe@blondel.nl>
This commit is contained in:
@ -1 +0,0 @@
|
||||
from .synth import synth
|
@ -1,14 +0,0 @@
|
||||
import threading
|
||||
import shutil
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
def runner(threads, process, name):
|
||||
print(f" - executing {name}: ", end='', flush=True)
|
||||
p = subprocess.Popen(process, shell=True, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
threads.append(p)
|
||||
while p.poll() is None:
|
||||
print('.', end='', flush=True)
|
||||
time.sleep(2)
|
||||
res = p.returncode
|
79
remotesyn/ISE/syn.py
Normal file
79
remotesyn/ISE/syn.py
Normal file
@ -0,0 +1,79 @@
|
||||
import threading
|
||||
import shutil
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import signal
|
||||
import random
|
||||
|
||||
def needed_files(config, target) -> list:
|
||||
if not config.has_section(f'build:{target}'):
|
||||
print("ERROR: config file has no build section for target")
|
||||
return None
|
||||
needed_files = []
|
||||
for s in config.get(f'build:{target}', 'src_vhdl', fallback="").split():
|
||||
needed_files.append(s)
|
||||
for s in config.get(f'build:{target}', 'src_verilog', fallback="").split():
|
||||
needed_files.append(s)
|
||||
for s in config.get(f'build:{target}', 'src_sysverilog', fallback="").split():
|
||||
needed_files.append(s)
|
||||
return needed_files
|
||||
|
||||
def generated_files(config, target) -> list:
|
||||
outdir = f"{config.get('project', 'out_dir', fallback='out')}"
|
||||
return [
|
||||
f'{outdir}/{target}/synth.log',
|
||||
f'{outdir}/{target}/synth.ngc',
|
||||
]
|
||||
|
||||
def do(config, target, log, subprocesses, prefix='.') -> int:
|
||||
log("Synthesize:")
|
||||
|
||||
if not config.has_section(f'build:{target}'):
|
||||
log("ERROR: config file has no build section for target")
|
||||
return 1
|
||||
|
||||
devtarget = f'target:{config.get(f"build:{target}", "target", fallback="")}'
|
||||
if not config.has_section(devtarget):
|
||||
log("ERROR: config file has no section for device target")
|
||||
return 1
|
||||
|
||||
device = f"{config.get(devtarget, 'device', fallback='')}{config.get(devtarget, 'speedgrade', fallback='')}-{config.get(devtarget, 'package', fallback='')}"
|
||||
builddir = f"{prefix}/{config.get('project', 'build_dir', fallback='.build')}"
|
||||
outdir = f"{prefix}/{config.get('project', 'out_dir', fallback='out')}"
|
||||
|
||||
os.makedirs(builddir, exist_ok=True)
|
||||
curdir = f"{os.getcwd()}/{prefix}"
|
||||
|
||||
log(" - writing project file")
|
||||
with open(f'{builddir}/syn.prj', 'w') as f:
|
||||
for s in config.get(f'build:{target}', 'src_vhdl', fallback="").split():
|
||||
f.write(f"vhdl work {curdir}/{s}\n")
|
||||
for s in config.get(f'build:{target}', 'src_verilog', fallback="").split():
|
||||
f.write(f"verilog work {curdir}/{s}\n")
|
||||
for s in config.get(f'build:{target}', 'src_sysverilog', fallback="").split():
|
||||
f.write(f"verilog work {curdir}/{s}\n")
|
||||
|
||||
log(" - writing project generation file")
|
||||
with open(f'{builddir}/prj.scr', 'w') as f:
|
||||
f.write(f'run\n-ifn syn.prj\n-ofn syn.ngc\n-ifmt mixed\n')
|
||||
f.write(f'-top {config.get(f"sources:{target}", "toplevel", fallback="toplevel")}\n')
|
||||
f.write(f'-p {device}\n-glob_opt max_delay -opt_mode speed')
|
||||
|
||||
p = subprocess.Popen("xst -intstyle xflow -ifn prj.scr", shell=True, cwd=builddir, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
subprocesses.append(p)
|
||||
while p.poll() is None:
|
||||
time.sleep(1)
|
||||
res = p.returncode
|
||||
if res:
|
||||
log(" - ERROR: return code is", res)
|
||||
log(" - copy log")
|
||||
os.makedirs(f'{outdir}/{target}', exist_ok=True)
|
||||
shutil.copy(f'{builddir}/prj.srp', f'{outdir}/{target}/synth.log')
|
||||
return res
|
||||
|
||||
log(" - copy output files")
|
||||
os.makedirs(f'{outdir}/{target}', exist_ok=True)
|
||||
shutil.copy(f'{builddir}/syn.ngc', f'{outdir}/{target}/synth.ngc')
|
||||
shutil.copy(f'{builddir}/prj.srp', f'{outdir}/{target}/synth.log')
|
||||
return 0
|
@ -1,107 +0,0 @@
|
||||
import threading
|
||||
import shutil
|
||||
import os
|
||||
import time
|
||||
import subprocess
|
||||
import signal
|
||||
import random
|
||||
|
||||
from .runner import runner
|
||||
|
||||
class synth(threading.Thread):
|
||||
def __init__(self, config, copy, target):
|
||||
threading.Thread.__init__(self)
|
||||
self.config = config
|
||||
self.copy = copy
|
||||
self.target = target
|
||||
|
||||
self.threads = []
|
||||
self.running = True
|
||||
self.name = config.get('project', 'name', fallback=f'{random.random():.4f}')
|
||||
self.version = config.get('project', 'version', fallback=f'{random.random():.4f}')
|
||||
self.builddir = f"{config.get('project', 'build_dir', fallback='.build')}/synth_{target}_{self.name}_{self.version}"
|
||||
self.outdir = config.get('project', 'out_dir', fallback='out')
|
||||
|
||||
# Returns the list of needed files to execute operation. Caller need
|
||||
# to check for existance of the files and if in remote execution these
|
||||
# files must be synched
|
||||
def needed_files(self):
|
||||
if not self.config.has_section(f'sources:{self.target}'):
|
||||
print("ERROR: config file has no sources section for target")
|
||||
return None
|
||||
needed_files = []
|
||||
for s in self.config.get(f'sources:{self.target}', 'src_vhdl', fallback="").split():
|
||||
needed_files.append(s)
|
||||
for s in self.config.get(f'sources:{self.target}', 'src_verilog', fallback="").split():
|
||||
needed_files.append(s)
|
||||
for s in self.config.get(f'sources:{self.target}', 'src_sysverilog', fallback="").split():
|
||||
needed_files.append(s)
|
||||
return needed_files
|
||||
|
||||
def stop(self):
|
||||
print("Stopping synth...")
|
||||
for t in self.threads:
|
||||
print(" <> kill", t)
|
||||
t.send_signal(signal.SIGINT)
|
||||
ti = 0
|
||||
while t.poll() is None:
|
||||
time.sleep(1)
|
||||
ti += 1
|
||||
if ti>2:
|
||||
print(" <> force kill", t)
|
||||
t.send_signal(signal.SIGKILL)
|
||||
self.running = False
|
||||
|
||||
def run(self):
|
||||
print("Synthesize:")
|
||||
if not self.config.has_section(f'sources:{self.target}'):
|
||||
print("ERROR: config file has no sources section for target")
|
||||
self.running = False
|
||||
return None
|
||||
|
||||
devtarget = f'target:{self.config.get(f"sources:{self.target}", "target", fallback="")}'
|
||||
if not self.config.has_section(devtarget):
|
||||
print("ERROR: config file has no section for device target")
|
||||
self.running = False
|
||||
return None
|
||||
|
||||
device = f"{self.config.get(devtarget, 'device', fallback='')}{self.config.get(devtarget, 'speedgrade', fallback='')}-{self.config.get(devtarget, 'package', fallback='')}"
|
||||
|
||||
os.makedirs(self.builddir, exist_ok=True)
|
||||
curdir = os.getcwd()
|
||||
os.chdir(self.builddir)
|
||||
|
||||
try:
|
||||
|
||||
print(" - writing project file")
|
||||
with open('syn.prj', 'w') as f:
|
||||
for s in self.config.get(f'sources:{self.target}', 'src_vhdl', fallback="").split():
|
||||
f.write(f"vhdl work {curdir}/{s}\n")
|
||||
for s in self.config.get(f'sources:{self.target}', 'src_verilog', fallback="").split():
|
||||
f.write(f"verilog work {curdir}/{s}\n")
|
||||
for s in self.config.get(f'sources:{self.target}', 'src_sysverilog', fallback="").split():
|
||||
f.write(f"verilog work {curdir}/{s}\n")
|
||||
|
||||
print(" - writing project generation file")
|
||||
with open('prj.scr', 'w') as f:
|
||||
f.write(f'run\n-ifn syn.prj\n-ofn syn.ngc\n-ifmt mixed\n')
|
||||
f.write(f'-top {self.config.get(f"sources:{self.target}", "toplevel", fallback="toplevel")}\n')
|
||||
f.write(f'-p {device}\n-glob_opt max_delay -opt_mode speed')
|
||||
|
||||
runner(self.threads, "xst -intstyle xflow -ifn prj.scr", "xst")
|
||||
if not self.running:
|
||||
os.chdir(curdir)
|
||||
return
|
||||
print('DONE')
|
||||
|
||||
print(" - copy output files")
|
||||
os.makedirs(f'{curdir}/{self.outdir}/{self.target}', exist_ok=True)
|
||||
self.copy.copy_to_dir('syn.ngc', f'{curdir}/{self.outdir}/{self.target}/synth.ngc')
|
||||
self.copy.copy_to_dir('prj.srp', f'{curdir}/{self.outdir}/{self.target}/synth.log')
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
finally:
|
||||
os.chdir(curdir)
|
||||
self.running = False
|
@ -1 +0,0 @@
|
||||
from .copy import copy_local, copy_remote
|
@ -1,22 +0,0 @@
|
||||
import shutil
|
||||
|
||||
class copy_local:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
def copy_from_dir(self, src, dst):
|
||||
pass
|
||||
# Nothing to do here since we are working in local build
|
||||
|
||||
def copy_to_dir(self, src, dst):
|
||||
shutil.copy(src, dst)
|
||||
|
||||
class copy_remote:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
def copy_from_dir(self, src, dst):
|
||||
print("ERROR: Not yet implemented")
|
||||
|
||||
def copy_to_dir(self, src, dst):
|
||||
print("ERROR: Not yet implemented")
|
Reference in New Issue
Block a user