diff --git a/src/dcr/cli/build.py b/src/dcr/cli/build.py index 249699b..5f458f7 100644 --- a/src/dcr/cli/build.py +++ b/src/dcr/cli/build.py @@ -1,6 +1,6 @@ import os import subprocess -from dcr.config import flags +from ..config import flags, profile, c_comp def check_dir(dir: str | None = None) -> list[str]: @@ -10,25 +10,40 @@ def check_dir(dir: str | None = None) -> list[str]: return os.listdir(os.getcwd() + "/" + dir) -def build(args: list[str] | str) -> int: +def build(args: list[str] | None = None) -> int: + active_profile: str = profile if "dcr.toml" not in check_dir(): - print("error: Not font dcr.toml") + print("Ошибка: не найден файл dcr.toml") return 1 if "target" not in check_dir(): os.mkdir("./target") - if len(args) == 1 and args[0] in flags: - profile: str = args[0][2:] - else: - print("error: Unkown flags") - return 1 - if len(args) == 0: - profile: str = "debug" + if args: + if len(args) >= 1 and args[0].startswith("--"): + candidate: str = args[0][2:] + if candidate in flags: + active_profile = candidate + else: + print("Ошибка: неверный флаг сборки") + return 1 + else: + print("Ошибка: флаг сборки не найден") + return 1 - if profile not in check_dir("target"): - os.mkdir(f"./target/{profile}") + if active_profile not in check_dir("target"): + os.mkdir(f"./target/{active_profile}") if "main.c" in check_dir("src"): - print(f"Run build project as profiles {profile}") - subprocess.run(["gcc", "./src/main.c", "-o", f"./target/{profile}/main"]) + print(f"Run build project as profiles {active_profile}") + compile_flags = flags[active_profile] + subprocess.run( + [ + c_comp, + "./src/main.c", + *compile_flags, + "-o", + f"./target/{active_profile}/main", + ], + check=True, + ) print("Build complite") return 0 diff --git a/src/dcr/cli/run.py b/src/dcr/cli/run.py index 59e11b4..5f882e3 100644 --- a/src/dcr/cli/run.py +++ b/src/dcr/cli/run.py @@ -1,7 +1,7 @@ import os import subprocess -from dcr.config import flags +from ..config import flags, profile from .build import build @@ -12,19 +12,24 @@ def check_dir(dir: str | None = None) -> list[str]: return os.listdir(os.getcwd() + "/" + dir) -def run(args: list[str]) -> int: +def run(args: list[str] | None = None) -> int: + active_profile: str = profile if "dcr.toml" not in os.listdir(os.getcwd()): - print("error: Not fond dcr.toml") + print("Ошибка: не найден файл dcr.toml") return 1 - if len(args) == 0: - profile: str = "debug" - elif len(args) == 1 and args[0] in flags: - profile = args[0][2:] - else: - print("error: Unkown flags") - return 1 + if args: + if len(args) >= 1 and args[0].startswith("--"): + candidate: str = args[0][2:] + if candidate in flags: + active_profile = candidate + else: + print("Ошибка: неверный флаг сборки") + return 1 + else: + print("Ошибка: флаг сборки не найден") + return 1 build(args) print("Run project") - return subprocess.run([f"./target/{profile}/main"]).returncode + return subprocess.run([f"./target/{active_profile}/main"]).returncode diff --git a/src/dcr/config.py b/src/dcr/config.py index 5ac511e..6f18188 100644 --- a/src/dcr/config.py +++ b/src/dcr/config.py @@ -1 +1,6 @@ -flags: list[str] = ["--release", "--debug"] \ No newline at end of file +profile: str = "debug" +c_comp: str = "clang" +flags: dict[str, list[str]] = { + "release": ["-O3", "-DNDEBUG", "-march=native"], + "debug": ["-O0", "-g", "-Wall", "-Wextra", "-fno-omit-frame-pointer", "-DDEBUG"], +}