mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 15:49:40 +00:00
Обновить логику сборки и запуска проекта, добавив поддержку флагов и исправив ошибки вывода
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
flags: list[str] = ["--release", "--debug"]
|
||||
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"],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user