Import("env")


if env["debugger"]:
    cmd_prefx = f"{env['debugger']} -ex r --args "
else:
    cmd_prefx = ""


if env["pytest_args"]:
    cmd_suffix = " ".join(f"--pytest={arg}" for arg in env["pytest_args"].split())
else:
    cmd_suffix = ""


if env["headless"]:
    cmd_suffix += " --no-window "


# TODO: fix&reenable work_with_gdscript test...
for test in ["bindings", "helloworld", "threading", "global_constants"]:
    dist_symlink = env.Symlink(f"{test}/addons", "$DIST_ROOT/addons")
    dist_symlink = env.Symlink(f"{test}/lib", "_lib_vendors")
    target = env.Command(
        test,
        ["$pandemonium_binary", dist_symlink],
        cmd_prefx + "${SOURCE.abspath} ${pandemonium_args} --path ${TARGET} " + cmd_suffix,
    )
    env.Depends(target, env["DIST_ROOT"])
    env.AlwaysBuild(target)


SConscript(["python_binary/SConscript"])
env.Alias("test", "bindings")
env.Alias("test-threading", "threading")