From 7939e710a6ce3f87b5ed497a6831cfc82e002280 Mon Sep 17 00:00:00 2001 From: Dexoron Date: Wed, 11 Feb 2026 19:54:53 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D1=81=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=BA=D0=B8=20=D0=B8=20=D0=B7=D0=B0=D0=BF=D1=83?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= =?UTF-8?q?,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=B2=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83=20=D1=84=D0=BB=D0=B0?= =?UTF-8?q?=D0=B3=D0=BE=D0=B2=20=D0=B8=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=B2=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dcr/cli/build.py | 43 +++++++++++++++++++++++++++++-------------- src/dcr/cli/run.py | 27 ++++++++++++++++----------- src/dcr/config.py | 7 ++++++- 3 files changed, 51 insertions(+), 26 deletions(-) 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"], +}