diff --git a/sbysrc/sby.py b/sbysrc/sby.py index 315aa55..bc95900 100644 --- a/sbysrc/sby.py +++ b/sbysrc/sby.py @@ -224,6 +224,16 @@ def read_sbyconfig(sbydata, taskname): found_task_tag = False task_skip_line = False + windows_drive_path = re.match(r"^([A-Za-z]):[\\/]", line) + if windows_drive_path and windows_drive_path.group(1) in task_tags_all: + drive = windows_drive_path.group(1) + print( + f'ERROR: Task or group name "{drive}" conflicts with Windows path "{line}". ' + "Rename the task or group.", + file=sys.stderr, + ) + sys.exit(1) + for t in task_tags_all: if line.startswith(t+":"): line = line[len(t)+1:].lstrip() diff --git a/tests/config_parser/windows_drive_task_names.py b/tests/config_parser/windows_drive_task_names.py new file mode 100644 index 0000000..6ea08ae --- /dev/null +++ b/tests/config_parser/windows_drive_task_names.py @@ -0,0 +1,57 @@ +import subprocess +import sys + + +def run_sby(sby_main, config): + return subprocess.run( + [sys.executable, sby_main, "--dumptasks"], + input=config, + capture_output=True, + text=True, + ) + + +def expect_drive_conflict(sby_main, tasks, drive_path): + result = run_sby( + sby_main, + f"""[tasks] +{tasks} + +[options] +mode prep + +[files] +{drive_path} +""", + ) + + drive = drive_path[0] + expected = ( + f'ERROR: Task or group name "{drive}" conflicts with Windows path ' + f'"{drive_path}". Rename the task or group.' + ) + assert result.returncode == 1, result + assert expected in result.stderr, result.stderr + + +def main(): + sby_main = sys.argv[1] + + expect_drive_conflict(sby_main, "C", r"C:\src\example.sv") + expect_drive_conflict(sby_main, "task D", "D:/src/example.sv") + + result = run_sby( + sby_main, + """[tasks] +C + +[options] +C: mode prep +""", + ) + assert result.returncode == 0, result + assert "C" in result.stdout.splitlines(), result.stdout + + +if __name__ == "__main__": + main() diff --git a/tests/config_parser/windows_drive_task_names.sby b/tests/config_parser/windows_drive_task_names.sby new file mode 100644 index 0000000..85f2b12 --- /dev/null +++ b/tests/config_parser/windows_drive_task_names.sby @@ -0,0 +1,2 @@ +[options] +mode prep diff --git a/tests/config_parser/windows_drive_task_names.sh b/tests/config_parser/windows_drive_task_names.sh new file mode 100644 index 0000000..86eec4b --- /dev/null +++ b/tests/config_parser/windows_drive_task_names.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +python3 windows_drive_task_names.py "$SBY_MAIN"