diff --git a/neb/README.md b/neb/README.md index ff6b41a..f05b0cc 100644 --- a/neb/README.md +++ b/neb/README.md @@ -8,7 +8,7 @@ There is also Github mirror of Comet if you would prefer that: https://github.co ## Usage ### Installing a Package -To install a package type: +To install a rock type: ``` neb install packageName ``` @@ -16,12 +16,13 @@ Or if you wish to install a particular version: ``` neb install packageName@1.0.0 ``` -(replace the number with the version number of the package you want to install) +(replace the number with the version number of the rock you want to install) ## Changelog ### 1.2.0 - Add support for modules written in Comet - Made it so that you don't have to build Comet to install the headers +- Added the `neb build` command to make it easier to develop rocks ### 1.1.0 - Switched from getting the latest commit of packages to getting the latest release diff --git a/neb/src/build.py b/neb/src/build.py new file mode 100644 index 0000000..7b608cb --- /dev/null +++ b/neb/src/build.py @@ -0,0 +1,33 @@ +from .util import libs_dir, print_error_message +from .console import console + +import sys +import os +import glob +import pathlib +import subprocess + +def build(args): + comet_libs_dir = libs_dir() + + folder_path = pathlib.Path(args.path).resolve() + folder_name = folder_path.name + + out_path = os.path.join(comet_libs_dir, f"{folder_name}.cometlib") + + c_files = glob.glob(f"{args.path}/*.c", recursive=True) + if len(c_files) == 0: + print_error_message(f"No C files were found in that directory! [d white]({folder_name})[/d white]") + sys.exit(1) + + with console.status("Building", spinner="moon") as status: + try: + subprocess.run( + ["gcc"] + c_files + ["-fPIC", "-shared", "-Wl,-undefined,symbol_lookup", "-o", out_path] + args.gcc_args, + check=True + ) + except subprocess.CalledProcessError as e: + print_error_message(f"Failed to install [b]{folder_name}[/]: build failed!") + sys.exit(1) + + console.log(f"[b][:white_check_mark:] Installed [green]{folder_name}[/green]![/b]") \ No newline at end of file diff --git a/neb/src/main.py b/neb/src/main.py index 611ffd9..3e7c9ab 100644 --- a/neb/src/main.py +++ b/neb/src/main.py @@ -7,6 +7,7 @@ from .pull import pull from .list import list_packages from .uninstall import uninstall from .search import search +from .build import build def main() -> int: @@ -31,6 +32,11 @@ def main() -> int: uninstall_cmd = sub_parsers.add_parser(name="uninstall", description="uninstall an installed rock(s)") uninstall_cmd.add_argument("names", help="name of the rocks to uninstall", nargs="+") + # build command + build_cmd = sub_parsers.add_parser(name="build", description="build a module") + build_cmd.add_argument("path", help="the path to build from") + build_cmd.add_argument("gcc_args", nargs=argparse.REMAINDER, help="args to give to gcc") + # search command search_cmd = sub_parsers.add_parser(name="search", description="search for rocks") search_cmd.add_argument("query", help="search query") @@ -55,6 +61,8 @@ def main() -> int: uninstall(args) case "search": search(args) + case "build": + build(args) # really feeling like a C programmer lmao return 0