Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
byBretema committed Oct 1, 2024
1 parent 7415cbc commit a7c3e57
Showing 1 changed file with 94 additions and 79 deletions.
173 changes: 94 additions & 79 deletions src/ccpm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from urllib.parse import urlparse

PREFIX = "ccpm"
VERBOSE = False


def invalid_folder(path):
Expand Down Expand Up @@ -123,7 +124,7 @@ def process_package(repo_url, tag, defines, download_prefix, install_prefix):
"--prefix",
install_dir_type,
]
run_command(install_cmd, cwd=build_dir_type, quiet=True)
run_command(install_cmd, cwd=build_dir_type, quiet=(not VERBOSE))

return install_dir

Expand Down Expand Up @@ -182,7 +183,7 @@ def gen_cmake_script(root_dir, install_dir, packages_path):

cmake_script += """
string(TOLOWER "${CMAKE_BUILD_TYPE}" CCPM_BUILD_TYPE_LOWER)
if(BUILD_TYPE_LOWER MATCHES "debug")
if(CCPM_BUILD_TYPE_LOWER MATCHES "debug")
SET(CCPM_BUILD_ID Debug)
else()
SET(CCPM_BUILD_ID Release)
Expand Down Expand Up @@ -222,7 +223,7 @@ def gen_cmake_script(root_dir, install_dir, packages_path):


def do_project_build(root_dir, project_build_dir, build_type):
print(f"[{PREFIX.upper()}] :: Building current project")
print(f"[{PREFIX.upper()}] :: Building current project : {build_type}")
run_command(
[
"cmake",
Expand All @@ -247,100 +248,114 @@ def do_project_build(root_dir, project_build_dir, build_type):


def main():
try:
# ARGS ################################################################

# Define arguments
parser = argparse.ArgumentParser(description="Manage your Cmake project")
parser.add_argument(
"-p",
"--path",
type=str,
default=".",
help=f"Where the {PREFIX}.toml is and install will be",
)
parser.add_argument(
"-c",
"--clear",
action="store_true",
default=False,
help="Clear build and external dependencies",
)
parser.add_argument(
"-i",
"--install",
action="store_true",
default=False,
help="Install dependencies (not needed if you don't change the TOML)",
)
parser.add_argument(
"-b",
"--build",
action="store_true",
default=False,
help="Specify if you want to build your CMakeList.txt (default Debug)",
)
parser.add_argument(
"-r",
"--release",
action="store_true",
default=False,
help="If build process is requested, build type will be Release",
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
default=False,
help="Doesn't hide any output",
)

# ARGS ################################################################
# Check cli commands
if run_command_silent_unchecked("cmake --version") != 0:
parser.error("Install CMake first")

# Define arguments
parser = argparse.ArgumentParser(description="Manage your Cmake project")
parser.add_argument(
"-p",
"--path",
type=str,
default=".",
help=f"Where the {PREFIX}.toml is and install will be",
)
parser.add_argument(
"-c",
"--clear",
action="store_true",
default=False,
help="Clear build and external dependencies",
)
parser.add_argument(
"-i",
"--install",
action="store_true",
default=False,
help="Install dependencies (not needed if you don't change the TOML)",
)
parser.add_argument(
"-b",
"--build",
action="store_true",
default=False,
help="Specify if you want to build your CMakeList.txt (default Debug)",
)
parser.add_argument(
"-r",
"--release",
action="store_true",
default=False,
help="If build process is requested, build type will be Release",
)
if run_command_silent_unchecked("git --version") != 0:
parser.error("Install Git first")

# Check cli commands
if run_command_silent_unchecked("cmake --version") != 0:
parser.error("Install CMake first")
# Parse arguments
args = parser.parse_args()

if run_command_silent_unchecked("git --version") != 0:
parser.error("Install Git first")
global VERBOSE
VERBOSE = args.verbose

# Parse arguments
args = parser.parse_args()
a_clear = args.clear
a_install = args.install

a_clear = args.clear
a_install = args.install
a_path = args.path
if invalid_folder(a_path) or (not os.path.exists(f"{a_path}/{PREFIX}.toml")):
parser.error(
f"Invalid path, folder doesn't exist or not contains a '{PREFIX}.toml' file"
)

a_path = args.path
if invalid_folder(a_path) or (not os.path.exists(f"{a_path}/{PREFIX}.toml")):
parser.error(
f"Invalid path, folder doesn't exist or not contains a '{PREFIX}.toml' file"
)
a_build = args.build
a_build_type = "Release" if args.release else "Debug"

a_build = args.build
a_build_type = "Release" if args.release else "Debug"
home_dir = os.path.expanduser("~").replace("\\", "/")
download_dir_prefix = f"{home_dir}/.{PREFIX}"

home_dir = os.path.expanduser("~").replace("\\", "/")
download_dir_prefix = f"{home_dir}/.{PREFIX}"
root_dir = os.path.abspath(a_path).replace("\\", "/")
install_dir_prefix = f"{root_dir}/.{PREFIX}"

root_dir = os.path.abspath(a_path).replace("\\", "/")
install_dir_prefix = f"{root_dir}/.{PREFIX}"
project_build_dir = f"{root_dir}/build/{a_build_type}"

project_build_dir = f"{root_dir}/build"
print(f"project_build_dir :: {project_build_dir}")
# CLEAR ALL ###########################################################

# CLEAR ALL ###########################################################
# Deps
if a_clear and not invalid_folder(install_dir_prefix):
shutil.rmtree(install_dir_prefix)

# Deps
if a_clear and not invalid_folder(install_dir_prefix):
shutil.rmtree(install_dir_prefix)
# Build
if a_clear and not invalid_folder(project_build_dir):
shutil.rmtree(project_build_dir)

# Build
if a_clear and not invalid_folder(project_build_dir):
shutil.rmtree(project_build_dir)
# INSTALL DEPS ########################################################

# INSTALL DEPS ########################################################
if a_install:
packages_path = process_toml(
root_dir, download_dir_prefix, install_dir_prefix
)
gen_cmake_script(root_dir, install_dir_prefix, packages_path)
print()

if a_install:
packages_path = process_toml(root_dir, download_dir_prefix, install_dir_prefix)
gen_cmake_script(root_dir, install_dir_prefix, packages_path)
print()
# BUILD CURRENT PROJECT ###############################################

# BUILD CURRENT PROJECT ###############################################
if a_build:
do_project_build(root_dir, project_build_dir, a_build_type)
print()

if a_build:
do_project_build(root_dir, project_build_dir, a_build_type)
print()
except KeyboardInterrupt:
print(f"\n[{PREFIX.upper()}] :: User interrupts execution!\n")


if __name__ == "__main__":
Expand Down

0 comments on commit a7c3e57

Please sign in to comment.