From 3e6e56f7f66e41aa2579fc6589a54040019ae2d5 Mon Sep 17 00:00:00 2001 From: Brett Date: Sat, 1 Jun 2024 14:08:25 -0400 Subject: [PATCH] bargo working --- bargo.py | 99 ++++++++++++++++++---- clion_cmake_exec.txt | 2 +- clion_cmake_lib.txt | 2 +- commit.py | 2 +- util/__pycache__/color_io.cpython-311.pyc | Bin 1005 -> 1171 bytes 5 files changed, 86 insertions(+), 19 deletions(-) diff --git a/bargo.py b/bargo.py index d9bb43d..9d166b5 100755 --- a/bargo.py +++ b/bargo.py @@ -10,8 +10,10 @@ import subprocess import create_git_repo as repo import util.color_io as io -git_ignore = """ -cmake-build*/ +scripts_dir = "/home/brett/Documents/code/scripts" +github_url = "https://github.com/Tri11Paragon/" + +git_ignore = """cmake-build*/ build/ out/ ./cmake-build*/ @@ -19,9 +21,8 @@ out/ ./out/ """ -cmake_exec_default_text = """" -cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) -project(${PROJECT_NAME}) +cmake_exec_default_text = """cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) +project(${PROJECT_NAME} VERSION 0.0.1) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) @@ -57,8 +58,7 @@ if (${ENABLE_TSAN} MATCHES ON) endif () """ -cmake_lib_default_text = """" -cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) +cmake_lib_default_text = """cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) project(${PROJECT_NAME}) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) @@ -95,10 +95,19 @@ if (${ENABLE_TSAN} MATCHES ON) endif () """ +default_main_file = """#include + +int main() +{ + std::cout << "Hello World!" << std::endl; +} +""" + parser = argparse.ArgumentParser(prog='Bargo', description='Cargo but bad, for C++', epilog='Meow :3') -parser.add_argument("--cmake", "-c", default=None, help="Specify CMake version, defaults to using version installed on the system") -parser.add_argument("--cpp", "-p", default="17", help="C++ Version") +parser.add_argument("--cmake", default=None, help="Specify CMake version, defaults to using version installed on the system") +parser.add_argument("--cpp", "-p", default="17", help="C++ Version, defaults to C++17") parser.add_argument("--no_git", default=True, action="store_false", help="Disables creating a git repo") +parser.add_argument("--create_git", "-c", nargs='?', const=True, default=False, help="Create the associated git repo", metavar="DESCRIPTION") parser.add_argument("--no_blt", default=True, action="store_false", help="Disables init with BLT") parser.add_argument("--lib", action="store_true", help="Create a lib instead of an exec") parser.add_argument("--graphics", "-g", default=False, action="store_true", help="Init with graphics in mind, ie use BLT With Graphics") @@ -108,18 +117,24 @@ parser.add_argument("name", help="Project Name") args = parser.parse_args() -def open_process(command): +def open_process(command, print_out = True): process = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = process.communicate() exit_code = process.wait() + str_out = stdout.decode('utf8') + str_err = stderr.decode('utf8') + if print_out and len(str_out) > 0: + print(str_out, end='') + if print_out and len(str_err) > 0: + print(str_err, end='') #print(stdout, stderr, exit_code) return (stdout, stderr, exit_code) def get_cmake_version(): cmake_output, _, _ = open_process(["cmake", "--version"]) - cmake_lines = cmake_output.splitlines() - cmake_version = str(cmake_lines[0]).split("version ")[1][0:-1].split('.') + cmake_lines = cmake_output.decode('utf8').splitlines() + cmake_version = str(cmake_lines[0]).split("version ")[1].split('.') cmake_major = cmake_version[0] cmake_minor = cmake_version[1] @@ -129,23 +144,35 @@ def get_cmake_version(): def setup_dirs(): open_process(["mkdir", "include", "src", "lib"]) -def setup_blt(use_git, blt_url): +def setup_blt(use_git, blt_url, blt_path): if use_git: - open_process(["git", "submodule", "add", blt_url, "lib/blt"]) + open_process(["git", "submodule", "add", blt_url, "lib/" + blt_path]) open_process(["git", "submodule", "update", "--remote", "--init", "--recursive"]) else: - open_process(["git", "clone", "--recursive", blt_url, "lib/blt"]) + open_process(["git", "clone", "--recursive", blt_url, "lib/" + blt_path]) def create_git_ignore(): with open(".gitignore", "w") as f: f.write(git_ignore) - + cmake_major, cmake_minor = get_cmake_version() cpp_version = args.cpp use_blt = args.no_blt use_git = args.no_git blt_url = "https://github.com/Tri11Paragon/BLT.git" +blt_path = "blt" +blt_lib = "BLT" cmake_text = cmake_exec_default_text +project_name = args.name.replace(" ", "-").replace("_", "-") +sub_dirs = "" +links = "" + +open_process(["mkdir", project_name]) +wd = os.getcwd() +if not wd.endswith('/'): + wd += "/" +wd += project_name +os.chdir(wd); if args.lib: cmake_text = cmake_lib_default_text @@ -160,4 +187,44 @@ if args.cmake: if args.graphics: blt_url = "https://git.tpgc.me/tri11paragon/BLT-With-Graphics-Template" + blt_path = "blt-with-graphics" + blt_lib = "BLT_WITH_GRAPHICS" + +open_process(["cp", scripts_dir + "/commit.py", "./"]); + +setup_dirs() + +if use_git: + open_process(["git", "init"]) + open_process(["git", "branch", "-M", "main"]) + create_git_ignore() + +if use_blt: + setup_blt(use_git=use_git, blt_url=blt_url, blt_path=blt_path) + sub_dirs += "add_subdirectory(lib/" + blt_path + ")" + links += "target_link_libraries(${PROJECT_NAME} PRIVATE " + blt_lib + ")" + +if args.create_git: + desc = "" + if isinstance(args.create_git, str): + desc = args.create_git + open_process(["create_git_repo", "-d", desc, project_name]) + if not github_url.endswith("/"): + github_url += "/" + open_process(["git", "remote", "add", "origin", github_url + project_name]) + +cmake_text = cmake_text.replace("${SUB_DIRS}", sub_dirs) +cmake_text = cmake_text.replace("${LINKS}", links) +cmake_text = cmake_text.replace("${CMAKE_MAJOR_VERSION}", cmake_major) +cmake_text = cmake_text.replace("${CMAKE_MINOR_VERSION}", cmake_minor) +cmake_text = cmake_text.replace("${PROJECT_NAME}", project_name) +cmake_text = cmake_text.replace("${CMAKE_LANGUAGE_VERSION}", cpp_version) + +with open("CMakeLists.txt", "w") as f: + f.write(cmake_text) + +with open("src/main.cpp", "w") as f: + f.write(default_main_file) + +print("Created " + project_name + "!") diff --git a/clion_cmake_exec.txt b/clion_cmake_exec.txt index ebadb3c..8ddb4b8 100644 --- a/clion_cmake_exec.txt +++ b/clion_cmake_exec.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) -project(${PROJECT_NAME}) +project(${PROJECT_NAME} VERSION 0.0.1) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/clion_cmake_lib.txt b/clion_cmake_lib.txt index e21567d..b78bad6 100644 --- a/clion_cmake_lib.txt +++ b/clion_cmake_lib.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) -project(${PROJECT_NAME}) +project(${PROJECT_NAME} VERSION 0.0.1) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/commit.py b/commit.py index cbacb91..b39f82d 100755 --- a/commit.py +++ b/commit.py @@ -6,7 +6,7 @@ import subprocess # CONFIG #--------------------------------------- -VERSION_BEGIN_STR = "set(BLT_VERSION " +VERSION_BEGIN_STR = " VERSION " VERSION_END_STR = ")" PATCH_LIMIT = 100000 diff --git a/util/__pycache__/color_io.cpython-311.pyc b/util/__pycache__/color_io.cpython-311.pyc index 9cbeb1acad619a4d78632cfd3783f8bf754a9d14..0b6b34a051cda1b976c1d689e675739b034e3f1e 100644 GIT binary patch delta 247 zcmaFMKADquIWI340}!OfhNsP($SbL*0pv_)NMT4}%wdRPNMUMWh+<4(Phn|cjABY* z1@f3v*nlKU3S%&XCdWp|iu$)?O2lUFkZ z)*Bn<7KsBziX=dUB#M*!a%B+5lAQ$flR%{onDlhnipSCl$lpj zBn}i204bPk&8#5>RLu+IXtETs0V%KnMM5B!_+&m7DK1GM6J$`a*JL9W7d{3?M)eOM JqKF452mnhdAtV3*