Compare commits

...

27 Commits
main ... dev

Author SHA1 Message Date
anulax 835a9758ce Update src/main.py ago%!(EXTRA string=2 months)
anulax 18b5137083 Update src/Package.py ago%!(EXTRA string=2 months)
anulax1225 92f468bfa4 Remove compile commands ago%!(EXTRA string=7 months)
anulax1225 e33dddedea Auto compile commands on build ago%!(EXTRA string=7 months)
Ambigapathy Vinayak 805b14955a Adapted a parameter of init and of the premake5 file ago%!(EXTRA string=11 months)
Ambigapathy Vinayak 977def38e5 Modified config ago%!(EXTRA string=11 months)
Ambigapathy Vinayak 711d0d00bd modified installer ago%!(EXTRA string=11 months)
Ambigapathy Vinayak 4ac96d14c7 modified installer ago%!(EXTRA string=11 months)
Ambigapathy Vinayak 4fec524051 Added arg to save command and modified windows build logic ago%!(EXTRA string=11 months)
anulax1225 87974f3b34 Fixed error in reconfig func ago%!(EXTRA string=11 months)
anulax1225 039432ad8b Modified gitignore ago%!(EXTRA string=11 months)
anulax1225 b9c33275d5 Modified logic in packages config and simplefied some args ago%!(EXTRA string=11 months)
anulax1225 f1a7bf1813 Modified logic in packages config and simplefied some args ago%!(EXTRA string=11 months)
anulax1225 f02512a5f5 Fixed speling error ago%!(EXTRA string=11 months)
anulax1225 433ff3181f Fixed comma error ago%!(EXTRA string=11 months)
anulax1225 eebe1b81e4 Added a default include dir and fixed double reconfig ago%!(EXTRA string=11 months)
anulax1225 7ba1b95963 Modified log style ago%!(EXTRA string=11 months)
anulax1225 2469739971 Modified log style ago%!(EXTRA string=11 months)
anulax1225 ba336b7bad Cleaned cli app ago%!(EXTRA string=11 months)
anulax1225 b89395a611
Update Package.py ago%!(EXTRA string=11 months)
anulax1225 493f052be9 Modified .git ingnore file ago%!(EXTRA string=11 months)
anulax1225 b18457acad Functionnal packet manager ago%!(EXTRA string=11 months)
Ambigapathy Vinayak e39362ddf1 Continued ago%!(EXTRA string=11 months)
Ambigapathy Vinayak 52754001aa Truc fait ago%!(EXTRA string=11 months)
Ambigapathy Vinayak 71a6bde442 Continued on the creation and recreation of a project ago%!(EXTRA string=11 months)
LocalInfo ff6e01acd0 Continue init of project ago%!(EXTRA string=11 months)
LocalInfo d7785f4a1b First python test program ago%!(EXTRA string=12 months)
  1. 6
      .gitignore
  2. 1
      pycompile
  3. 8
      src/Command.py
  4. 30
      src/Log.py
  5. 161
      src/Package.py
  6. 52
      src/Premake/App.py
  7. 20
      src/Premake/Wks.py
  8. 2
      src/Premake/__init__.py
  9. 88
      src/Project.py
  10. 56
      src/ToolChaine.py
  11. 98
      src/main.py

6
.gitignore vendored

@ -0,0 +1,6 @@
/test_app/
bin/
build/
dist/
**.spec
**__pycache__**

@ -0,0 +1 @@
pyinstaller src/main.py --onefile --distpath ./bin -n bakasable

@ -0,0 +1,8 @@
import os
import sys
from Log import ShColors
def exec(command):
print(ShColors.OKGREEN)
os.system(f"{command}")
print(ShColors.ENDC)

@ -0,0 +1,30 @@
class ShColors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def logo() -> None:
print(
f"""
{ShColors.BOLD}____ _ _ __ _ ____ _ ____ _ _____
| __ ) / \\ | |/ / / \\ / ___| / \\ | __ )| | | ____|
| _ \\ / _ \\ | ' / / _ \\ \\___ \\ / _ \\ | _ \\| | | _|
| |_) / ___ \\| . \\ / ___ \\ ___) / ___ \\| |_) | |___| |___
|____/_/ \\_\\_|\\_\\/_/ \\_\\____/_/ \\_\\____/|_____|_____|
{ShColors.ENDC}""")
def info(message) -> None:
print(f"{ShColors.OKGREEN}[INFO] {message}{ShColors.ENDC}")
def warning(message) -> None:
print(f"{ShColors.WARNING}[WARNING] {message}{ShColors.ENDC}")
def error(message) -> None:
print(f"{ShColors.FAIL}[ERROR] {ShColors.UNDERLINE}{message}{ShColors.ENDC}")
exit(1)

@ -0,0 +1,161 @@
import shutil
import stat
import os
import json
import Command
import ToolChaine
import webbrowser
import Log
def config(package):
Log.info(f"Reconfiguring package {package}")
if os.path.exists(f"./vendor/{package}/dependencies"):
dep = open(f"./vendor/{package}/dependencies", "r")
pkg_deps = dep.read()
dep.close()
if not os.path.exists("./dependencies.lua"):
dep = open("./dependencies.lua", "w")
dep.write("IncludeDirs = {}")
dep.write("\n" + pkg_deps)
dep.close()
else:
dep = open(f"./dependencies.lua", "a")
dep.write("\n" + pkg_deps)
dep.close()
linker = []
if os.path.exists(f"./vendor/{package}/package.json"):
f_conf = open(f"./vendor/{package}/package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
linker.append({
"links": conf["links"],
"includes": conf["includes"]
})
return linker
def reconfig():
Log.info("Reconfiguring build settings :")
f_conf = open("./package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
if os.path.exists("./dependencies.lua"): os.remove("./dependencies.lua")
if os.path.exists("./app/linker.lua"): os.remove("./app/linker.lua")
linkers = []
for package in os.listdir("./vendor"):
linkers += config(package)
links = "\nlinks\n{\n"
includes = '\nincludedirs\n{\n\t"%{prj.location}/src/",\n'
for linker in linkers:
if len(linker["links"]):
for link in linker["links"]:
if len(link): links += '\t"' + link + '",\n'
if len(linker["includes"]):
for include in linker["includes"]:
if len(include): includes += '\t"%{IncludeDirs.' + include + '}",\n'
links += "}\n"
includes += "}\n"
f_linker= open("./app/linker.lua", "w")
f_linker.write(includes + links)
f_linker.close()
def install(author, package, repo) -> None:
Log.info(f"Installing package {package}")
if os.path.exists(f"./vendor/{package}"):
Log.warning(f"Package {package} already added")
if os.path.exists(f"./vendor/{package}/package.json"):
conf = open(f"./vendor/{package}/package.json", "r").read()
conf = json.loads(conf)
if len(conf["packages"]) > 0:
for pkg in conf["packages"]:
install(pkg["author"], pkg["name"], pkg["repo"] if "repo" in pkg else "git.anulax.ch")
return
if not ToolChaine.tool_exist("git"):
Log.error("Tool missing git")
Command.exec(f"git clone --depth 5 https://{repo}/{author}/{package} ./vendor/{package}")
if os.path.exists(f"./vendor/{package}/package.json"):
conf = open(f"./vendor/{package}/package.json", "r").read()
conf = json.loads(conf)
if len(conf["packages"]) > 0:
for pkg in conf["packages"]:
install(pkg["author"], pkg["name"], pkg["repo"] if "repo" in pkg else "git.anulax.ch")
def add(author, package) -> None:
f_conf = open("./package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
if package in conf["packages"]: Log.error("Package already added")
f_conf = open("./package.json", "w")
conf["packages"].append({ "author": author, "name": package})
f_conf.write(json.dumps(conf, indent=4))
f_conf.close()
install(author, package)
reconfig()
def update(package) -> None:
Log.info(f"Updating package {package}")
if not os.path.exists(f"./vendor/{package}"): Log.error("Package not found")
os.chdir(f"./vendor/{package}")
Command.exec("git pull")
os.chdir("../../")
reconfig()
def save(package, message, paths) -> None:
Log.info(f"Saving package {package}")
if not os.path.exists(f"./vendor/{package}"): Log.error("Package not found")
adds = ""
if paths is not None and len(paths):
for path in paths:
adds += path + " "
else: adds = "."
Log.info(f"Paths to archive : {adds}")
os.chdir(f"./vendor/{package}")
Command.exec("git status")
Command.exec(f"git add {adds}")
Command.exec(f'git commit -m "{message}"')
Command.exec("git push")
def remove(package) -> None:
f_conf = open("./package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
conf["packages"] = [pkg for pkg in conf["packages"] if pkg['name'] != package]
r_remove(package)
f_conf = open("./package.json", "w")
f_conf.write(json.dumps(conf, indent=4))
f_conf.close()
reconfig()
def r_remove(package) -> None:
Log.info(f"Removing package {package}")
if not os.path.exists(f"./vendor/{package}/") : Log.error(f"Package {package} not the dependencies")
if os.path.exists(f"./vendor/{package}/package.json") :
r_pkgs = json.loads(open(f"./vendor/{package}/package.json", "r").read())["packages"]
for r_pkg in r_pkgs:
r_remove(r_pkg["name"])
os.chmod(f"./vendor/{package}/", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
shutil.rmtree(f"./vendor/{package}/", ignore_errors=True)
def install_root() -> None:
Log.info("Reinstalling all packages :")
if not os.path.exists("./package.json"):
Log.error("No package config file")
f_conf = open("./package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
for pkg in conf["packages"]:
install(pkg["author"], pkg["name"], pkg["repo"] if "repo" in pkg else "git.anulax.ch")
reconfig()
def load_doc(package) -> None:
if not ToolChaine.tool_exist("doxygen"):
Log.error("Tool missing doxygen")
if not os.path.exists(f"./vendor/{package}/Doxyfile"):
Log.error("Doxygen config file not found")
Command.exec(f"doxygen ./vendor/{package}")
webbrowser.open("file://" + os.path.realpath(f"./vendor/{package}/docs/html/index.html"))

@ -0,0 +1,52 @@
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}")
include "linker.lua"
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"
buildoptions "/MT"
staticruntime "on"
defines
{
"BK_PLATFORM_WINDOWS"
}
filter "system:linux"
staticruntime "on"
defines
{
"BK_PLATFORM_LINUX"
}
"""

@ -0,0 +1,20 @@
def get(name) -> str:
return '''workspace "''' + name + '''"
architecture "x64"
configurations { "Debug", "Release" }
startproject "App"
flags
{
"MultiProcessorCompile"
}
toolset "clang"
linkgroups "On"
outputdir = "%{cfg.system}-%{cfg.architecture}-%{cfg.buildcfg}"
include "dependencies.lua"
group "App"
include "app"
group ""
'''

@ -0,0 +1,2 @@
from . import Wks
from . import App

@ -0,0 +1,88 @@
import os
import json
import Premake
import Command
import Log
class Builder:
def __init__(self, conf) -> None:
self.owner = conf["author"]
self.name = conf["name"]
self.git_repo = conf["git"]
def __init__(self, name, repo, author = "") -> None:
self.name = name
self.owner = author
self.git_repo = repo
def set_git_repo(self, url) -> None:
self.git_repo = url
def create(self) -> None:
self.create_folder()
self.config()
def config(self) -> None:
conf = {
"name": self.name,
"author": self.owner,
"git": self.git_repo,
"packages": []
}
Log.info("Configuring package.json")
file_conf = open("./package.json", "w")
file_conf.write(json.dumps(conf, indent=4))
file_conf.close()
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()
git_ign = open("./.gitignore", "w")
git_ign.write("""/vendor/
/bin/
/bin-int/
/.vscode/
/.vs/
/docs/
**.log
**.sln
**.vcxproj*
**.make
**Makefile
**dependencies.lua
**linker.lua
""")
def create_folder(self) -> None:
try:
os.mkdir("./app")
os.mkdir("./vendor")
os.mkdir("./app/src")
except: Log.error("Directory already exists.")
create_file("./app/src/app.cpp")
create_file("./premake5.lua")
create_file("./app/premake5.lua")
create_file("./package.json")
create_file("./.gitignore")
def as_git_repo(self) -> bool:
return os.path.exists("./.git")
def init_git_repo(self) -> None:
if self.as_git_repo():
Log.warning("Git folder already exists.")
return
Command.exec("git init --initial-branch=main")
Command.exec("git add .")
Command.exec('git commit -m "Initial commit"')
if len(self.git_repo) > 0: Command.exec(f'git remote add origin ${self.git_repo}')
def create_file(path) -> None:
file = open(path, "w")
file.close()

@ -0,0 +1,56 @@
import platform
import os
import json
import Command
import Log
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_build_tools() -> None:
Log.info(f"Verifing build tools")
none_tools: str = []
match platform.system():
case "Windows":
none_tools = search_tools(["git", "premake5"])
case "Linux":
none_tools = search_tools(["git", "g++", "premake5", "make"])
case _:
Log.error("Platform not supported")
if len(none_tools) > 0:
Log.error(f"Tools missing {none_tools}")
def run(config) -> None:
Log.info("Running app")
Log.info(f"./bin/{platform.system().lower()}-{platform.machine().lower()}-{config}/App/App")
if not os.path.exists(f"./bin/{platform.system().lower()}-{platform.machine().lower()}-{config}/App/App"):
Log.error("Executable not found")
Command.exec(f"chmod +x ./bin/{platform.system().lower()}-{platform.machine().lower()}-{config}/App/App && ./bin/{platform.system().lower()}-{platform.machine().lower()}-{config}/App/App")
def build(config) -> None:
Log.info(f"Starting build with config {config}")
verifie_build_tools()
match platform.system():
case "Windows":
Command.exec("premake5 vs2022")
Log.info("Build with vscode 2022")
case "Linux":
Command.exec("premake5 gmake2")
Command.exec("premake5 export-compile-commands")
Command.exec(f"mv ./compile_commands/{config.lower()}.json ./compile_commands.json")
Command.exec("rm -rf ./compile_commands")
Command.exec(f"make config={config.lower()}")
case _:
Log.error("Platform not supported")
Log.info("Finished build")

@ -0,0 +1,98 @@
import os
import argparse
import Package
import ToolChaine
import Log
import Project
def init(args) -> None:
Log.info(f"Initialising new project : {args.name} by {args.owner}")
Log.info(f"Path to the project : {args.path}")
Log.info(f"Git repository : {args.repo}")
project = Project.Builder(args.name, args.repo, args.owner)
project.create()
if args.git_init:
Log.info("Initialising local git folder")
project.init_git_repo()
def add(args) -> None:
Package.add(args.author, args.name)
def remove(args) -> None:
Package.remove(args.name)
def update(args) -> None:
Package.update(args.name)
def save(args) -> None:
Package.save(args.name, args.message, args.paths)
def install(args) -> None:
Package.install_root()
def doc(args) -> None:
Package.load_doc(args.package)
def build(args) -> None:
ToolChaine.build(args.config)
if (args.run): ToolChaine.run(args.config)
def run(args) -> None:
ToolChaine.run(args.config)
def bakasable() -> None:
program_parser = argparse.ArgumentParser(prog="bakasable", description="baka developpement enviromment")
program_parser.add_argument("-p", "--path", type=str, default="./", dest="path", help="path to the project")
sub_parsers = program_parser.add_subparsers(title="subcommmands", required=True, help="operations on your project")
init_parser = sub_parsers.add_parser("init", help="initialise a new project")
init_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of your")
init_parser.add_argument("-r", "--repo", type=str, default="", dest="repo", help="git repository where project is stored")
init_parser.add_argument("-a", "--author", type=str, default="", dest="owner", help="owner of the project")
init_parser.add_argument("-g", "--git-init", action="store_const", const=True, default=False, dest="git_init", help="initialise a local git folder")
init_parser.set_defaults(func=init)
add_parser = sub_parsers.add_parser("add", help="add a module to your project from github")
add_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
add_parser.add_argument("-a", "--author", type=str, required=True, dest="author", help="name of the github user")
add_parser.add_argument("-r", "--repo", type=str, default="git.anulax.ch", dest="repo", help="git repository where project is stored")
add_parser.set_defaults(func=add)
remove_parser = sub_parsers.add_parser("remove", help="remove a module from your project")
remove_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
remove_parser.set_defaults(func=remove)
update_parser = sub_parsers.add_parser("update", help="updates a module from your project")
update_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
update_parser.set_defaults(func=update)
save_parser = sub_parsers.add_parser("save", help="saves a module to it's repo")
save_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
save_parser.add_argument("-m", "--message", type=str, required=True, dest="message", help="message of the git commit")
save_parser.add_argument("-p", "--path", type=str, nargs="+", dest="paths", help="files to archive else archive all")
save_parser.set_defaults(func=save)
install_parser = sub_parsers.add_parser("install", help="installs the dependencies of your project")
install_parser.set_defaults(func=install)
doc_parser = sub_parsers.add_parser("doc", help="documents a module from your project if it as one")
doc_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
doc_parser.set_defaults(func=doc)
build_parser = sub_parsers.add_parser("build", help="")
build_parser.add_argument("-c", "--config", type=str, dest="config", help="", choices=["Debug", "Release"], default="Debug")
build_parser.add_argument("-r", "--run", action="store_const", const=True, default=False, dest="run", help="")
build_parser.set_defaults(func=build)
run_parser = sub_parsers.add_parser("run", help="")
run_parser.add_argument("-c", "--config", type=str, dest="config", help="", choices=["Debug", "Release"], default="Debug")
run_parser.set_defaults(func=run)
args = program_parser.parse_args()
if not os.path.exists(args.path): os.mkdir(args.path)
os.chdir(args.path)
args.func(args)
if __name__ == "__main__":
Log.logo()
bakasable()
Loading…
Cancel
Save