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

Merge pull request #232 from dlmiles/win-qol-cleanopt

-f clean: QoL improvement on Windows concerning file/dir removal locking
This commit is contained in:
Jannis Harder 2023-02-20 19:48:36 +01:00 committed by GitHub
commit 74f33880bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -412,6 +412,17 @@ if (workdir is not None) and (len(tasknames) != 1):
print("ERROR: Exactly one task is required when workdir is specified. Specify the task or use --prefix instead of -d.", file=sys.stderr)
sys.exit(1)
# Check there are no files in this dir or any of its subdirs
def check_dirtree_empty_of_files(dir):
list = os.listdir(dir)
if list:
for fn in list:
child_dir = os.path.join(dir, fn)
if os.path.isdir(child_dir) and check_dirtree_empty_of_files(child_dir):
continue
return False
return True
def start_task(taskloop, taskname):
sbyconfig, _, _, _ = read_sbyconfig(sbydata, taskname)
@ -446,10 +457,10 @@ def start_task(taskloop, taskname):
if reusedir:
pass
elif os.path.isdir(my_workdir):
elif os.path.isdir(my_workdir) and not check_dirtree_empty_of_files(my_workdir):
print(f"ERROR: Directory '{my_workdir}' already exists, use -f to overwrite the existing directory.")
sys.exit(1)
else:
elif not os.path.isdir(my_workdir):
os.makedirs(my_workdir)
else:

View file

@ -920,10 +920,11 @@ class SbyTask(SbyConfig):
def makedirs(self, path):
if self.reusedir and os.path.isdir(path):
rmtree(path, ignore_errors=True)
os.makedirs(path)
if not os.path.isdir(path):
os.makedirs(path)
def copy_src(self):
os.makedirs(self.workdir + "/src")
self.makedirs(self.workdir + "/src")
for dstfile, lines in self.verbatim_files.items():
dstfile = self.workdir + "/src/" + dstfile