3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-04-05 22:14:08 +00:00

Minimum-modification change for stdin support

This commit is contained in:
Andrew Wygle 2017-11-24 09:39:41 -08:00
parent db9c7e97b8
commit b7c33a72e9
2 changed files with 21 additions and 10 deletions

View file

@ -17,7 +17,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# #
import os, sys, getopt, shutil import os, sys, getopt, shutil, tempfile
##yosys-sys-path## ##yosys-sys-path##
from sby_core import SbyJob from sby_core import SbyJob
@ -29,7 +29,7 @@ exe_paths = dict()
def usage(): def usage():
print(""" print("""
sby [options] <jobname>.sby sby [options] [<jobname>.sby]
-d <dirname> -d <dirname>
set workdir name. default: <jobname> (without .sby) set workdir name. default: <jobname> (without .sby)
@ -78,10 +78,13 @@ for o, a in opts:
else: else:
usage() usage()
if len(args) != 1: if len(args) > 1:
usage() usage()
sbyfile = args[0] if len(args) == 1:
sbyfile = args[0]
assert sbyfile.endswith(".sby")
early_logmsgs = list() early_logmsgs = list()
def early_log(msg): def early_log(msg):
@ -89,8 +92,10 @@ def early_log(msg):
print(early_logmsgs[-1]) print(early_logmsgs[-1])
if workdir is None: if workdir is None:
assert sbyfile.endswith(".sby") if sbyfile:
workdir = sbyfile[:-4] workdir = sbyfile[:-4]
else:
workdir = tempfile.mkdtemp()
if opt_backup: if opt_backup:
backup_idx = 0 backup_idx = 0
@ -101,7 +106,11 @@ if opt_backup:
if opt_force: if opt_force:
early_log("Removing direcory '%s'." % (workdir)) early_log("Removing direcory '%s'." % (workdir))
shutil.rmtree(workdir, ignore_errors=True) if sbyfile:
shutil.rmtree(workdir, ignore_errors=True)
if sbyfile:
os.makedirs(workdir)
job = SbyJob(sbyfile, workdir, early_logmsgs) job = SbyJob(sbyfile, workdir, early_logmsgs)
@ -110,5 +119,8 @@ for k, v in exe_paths.items():
job.run() job.run()
if not sbyfile:
shutil.rmtree(workdir, ignore_errors=True)
sys.exit(job.retcode) sys.exit(job.retcode)

View file

@ -16,7 +16,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# #
import os, re, resource import os, re, resource, sys
import subprocess, fcntl import subprocess, fcntl
from shutil import copyfile from shutil import copyfile
from select import select from select import select
@ -157,7 +157,6 @@ class SbyJob:
self.logprefix = "SBY [%s]" % self.workdir self.logprefix = "SBY [%s]" % self.workdir
self.summary = list() self.summary = list()
os.makedirs(workdir)
self.logfile = open("%s/logfile.txt" % workdir, "w") self.logfile = open("%s/logfile.txt" % workdir, "w")
for line in early_logs: for line in early_logs:
@ -167,7 +166,7 @@ class SbyJob:
mode = None mode = None
key = None key = None
with open(filename, "r") as f: with (open(filename, "r") if filename else sys.stdin) as f:
with open("%s/config.sby" % workdir, "w") as cfgfile: with open("%s/config.sby" % workdir, "w") as cfgfile:
pycode = None pycode = None
for line in f: for line in f: