diff --git a/.gitignore b/.gitignore index 16e803e..c6b7041 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/test_app/ \ No newline at end of file +/test_app/ +**__pycache__** \ No newline at end of file diff --git a/src/Buildtools.py b/src/Buildtools.py new file mode 100644 index 0000000..d2b4369 --- /dev/null +++ b/src/Buildtools.py @@ -0,0 +1,24 @@ +import platform + +def tool_exist(name: str) -> bool: + from shutil import which + return which(name) is not None + +def search_tools(tools: str) -> str: + none_tools: str = [] + for tool in tools: + if not tool_exist(tool): + none_tools.append(tool) + return none_tools + +def verifie_tools() -> None: + none_tools: str = [] + match platform.system(): + case "Windows": + none_tools = search_tools(["git"]) + case "Linux": + none_tools = search_tools(["git"]) + case _: + raise Exception("Platform not supported") + if len(none_tools) > 0: + raise Exception(f"Tools missing {none_tools}") \ No newline at end of file diff --git a/src/Package.py b/src/Package.py new file mode 100644 index 0000000..c715475 --- /dev/null +++ b/src/Package.py @@ -0,0 +1,2 @@ +def add(name: str) -> None: + \ No newline at end of file diff --git a/src/Premake/App.py b/src/Premake/App.py new file mode 100644 index 0000000..73ca003 --- /dev/null +++ b/src/Premake/App.py @@ -0,0 +1,54 @@ +def get() -> str: + return '''project "App" + kind "ConsoleApp" + language "C++" + cppdialect "C++20" + systemversion "latest" + + targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") + objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") + + files + { + "src/**.h", + "src/**.cpp" + } + + filter "configurations:Debug" + defines + { + "BK_DEBUG", + "DEBUG" + } + runtime "Debug" + symbols "on" + + + filter "configurations:Release" + defines + { + "BK_RELEASE", + "NDEBUG" + } + runtime "Release" + optimize "on" + + filter "system:windows" + staticruntime "on" + defines + { + "BK_PLATFORM_WINDOWS" + } + + filter "system:linux" + staticruntime "on" + defines + { + "BK_PLATFORM_LINUX" + } + filter "" + includedirs + + links + + ''' \ No newline at end of file diff --git a/src/Premake/Wks.py b/src/Premake/Wks.py new file mode 100644 index 0000000..de1dc1c --- /dev/null +++ b/src/Premake/Wks.py @@ -0,0 +1,20 @@ +def get(name) -> str: + return '''workspace "''' + name + '''" + architecture "x64" + configurations { "Debug", "Release" } + startproject "App" + + flags + { + "MultiProcessorCompile" + } + + linkgroups "On" + outputdir = "%{cfg.system}-%{cfg.architecture}-%{cfg.buildcfg}" + + include "Depedencies.lua" + + group "App" + include "app" + group "" + ''' \ No newline at end of file diff --git a/src/Premake/__init__.py b/src/Premake/__init__.py new file mode 100644 index 0000000..ed58936 --- /dev/null +++ b/src/Premake/__init__.py @@ -0,0 +1,2 @@ +from . import Wks +from . import App \ No newline at end of file diff --git a/src/Project.py b/src/Project.py new file mode 100644 index 0000000..5baae27 --- /dev/null +++ b/src/Project.py @@ -0,0 +1,49 @@ +import os +import Premake + +class Project: + def __init__(self, name) -> None: + self.name = name + self.git_repo = "" + + def set_git_repo(self, url) -> None: + self.git_repo = url + + def create(self) -> None: + self.create_folder() + self.premake_conf() + if not self.as_git_repo(): self.init_git_repo() + + def premake_conf(self) -> None: + wks = open("./premake5.lua", "w") + wks.write(Premake.Wks.get(self.name)) + wks.close() + app = open("./app/premake5.lua", "w") + app.write(Premake.App.get()) + app.close() + + def create_folder(self) -> None: + try: + os.mkdir("./app") + os.mkdir("./vendor") + os.mkdir("./app/src") + except: raise Exception("A directory already exists.") + create_file("./app/src/app.cpp") + create_file("./premake5.lua") + create_file("./app/premake5.lua") + + def as_git_repo(self) -> bool: + return os.path.exists("./.git") + + def init_git_repo(self) -> None: + os.system("git init --initial-branch=main") + os.system("git add .") + os.system('git commit -m "Initial commit"') + if len(self.git_repo) > 0: os.system(f'git remote add origin ${self.git_repo}') + +def create_file(path) -> None: + file = open(path, "w") + file.close() + + + \ No newline at end of file diff --git a/src/main.py b/src/main.py index 8b54849..2bea6a7 100644 --- a/src/main.py +++ b/src/main.py @@ -1,48 +1,16 @@ import os import sys -import platform -import numpy as np +from Buildtools import verifie_tools +from Project import Project -def tool_exist(name: str) -> bool: - from shutil import which - return which(name) is not None - -def search_tools(tools: str) -> str: - none_tools: str = [] - for tool in tools: - if not tool_exist(tool): - none_tools.append(tool) - return none_tools - -def verifie_tools(): - none_tools: str = [] - match platform.system(): - case "Windows": - none_tools = search_tools(["git"]) - case "Linux": - none_tools = search_tools(["git"]) - case _: - print("Platform not supported") - exit(1) - if len(none_tools) > 0: - print(f"Tools missing {none_tools}") - exit(1) - -def create_file(path): - file = open(path, "w") - file.close() - - -def setup(): - if len(sys.argv[1]): +def setup() -> None: + if len(sys.argv) >= 2: + if not os.path.exists(sys.argv[1]): os.mkdir(sys.argv[1]) os.chdir(sys.argv[1]) verifie_tools() - os.mkdir("./app") - os.mkdir("./vendor") - os.mkdir("./app/src") - create_file("./app/src/app.cpp") - create_file("./premake5.lua") - create_file("./app/premake5.lua") + project: Project = Project("Test") + project.create() + -if __name__ == "main": +if __name__ == "__main__": setup() \ No newline at end of file