Turned osdk into a python package.
This commit is contained in:
		
							parent
							
								
									d21f41448f
								
							
						
					
					
						commit
						7bf3c66ca7
					
				
					 8 changed files with 69 additions and 35 deletions
				
			
		
							
								
								
									
										48
									
								
								__main__.py → osdk/__init__.py
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										48
									
								
								__main__.py → osdk/__init__.py
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							|  | @ -3,11 +3,9 @@ import sys | |||
| import os | ||||
| import random | ||||
| 
 | ||||
| 
 | ||||
| import build | ||||
| import utils | ||||
| from utils import Colors | ||||
| import environments | ||||
| import osdk.build as build | ||||
| import osdk.utils as utils | ||||
| import osdk.environments as environments | ||||
| 
 | ||||
| 
 | ||||
| CMDS = {} | ||||
|  | @ -34,12 +32,12 @@ def parseOptions(args: list[str]) -> dict: | |||
| 
 | ||||
| def runCmd(opts: dict, args: list[str]) -> None: | ||||
|     if len(args) == 0: | ||||
|         print(f"Usage: {sys.argv[0]} run <component>") | ||||
|         print(f"Usage: {args[0]} run <component>") | ||||
|         sys.exit(1) | ||||
| 
 | ||||
|     out = build.buildOne(opts.get('env', 'host-clang'), args[0]) | ||||
| 
 | ||||
|     print(f"{Colors.BOLD}Running: {args[0]}{Colors.RESET}") | ||||
|     print(f"{utils.Colors.BOLD}Running: {args[0]}{utils.Colors.RESET}") | ||||
|     utils.runCmd(out, *args[1:]) | ||||
| 
 | ||||
| 
 | ||||
|  | @ -121,11 +119,11 @@ def idCmd(opts: dict, args: list[str]) -> None: | |||
| 
 | ||||
| 
 | ||||
| def helpCmd(opts: dict, args: list[str]) -> None: | ||||
|     print(f"Usage: {sys.argv[0]} <command> [options...] [<args...>]") | ||||
|     print(f"Usage: osdk <command> [options...] [<args...>]") | ||||
|     print("") | ||||
| 
 | ||||
|     print("Description:") | ||||
|     print("   The skift operating system build system.") | ||||
|     print("   Operating System Development Kit.") | ||||
|     print("") | ||||
| 
 | ||||
|     print("Commands:") | ||||
|  | @ -134,8 +132,12 @@ def helpCmd(opts: dict, args: list[str]) -> None: | |||
|     print("") | ||||
| 
 | ||||
|     print("Enviroments:") | ||||
|     for env in environments.available(): | ||||
|         print("  " + env) | ||||
|     availableToolchains = environments.available() | ||||
|     if len(availableToolchains) == 0: | ||||
|         print("   No environments available") | ||||
|     else: | ||||
|         for env in environments.available(): | ||||
|             print("  " + env) | ||||
|     print("") | ||||
| 
 | ||||
|     print("Variants:") | ||||
|  | @ -175,20 +177,22 @@ CMDS = { | |||
|     }, | ||||
| } | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
| 
 | ||||
| def main(): | ||||
|     argv = sys.argv | ||||
|     try: | ||||
|         if len(sys.argv) < 2: | ||||
|         if len(argv) < 2: | ||||
|             helpCmd({}, []) | ||||
|         else: | ||||
|             o = parseOptions(sys.argv[2:]) | ||||
|             if not sys.argv[1] in CMDS: | ||||
|                 print(f"Unknown command: {sys.argv[1]}") | ||||
|             o = parseOptions(argv[2:]) | ||||
|             if not argv[1] in CMDS: | ||||
|                 print(f"Unknown command: {argv[1]}") | ||||
|                 print("") | ||||
|                 print(f"Use '{sys.argv[0]} help' for a list of commands") | ||||
|                 sys.exit(1) | ||||
|             CMDS[sys.argv[1]]["func"](o['opts'], o['args']) | ||||
|             sys.exit(0) | ||||
|                 print(f"Use '{argv[0]} help' for a list of commands") | ||||
|                 return 1 | ||||
|             CMDS[argv[1]]["func"](o['opts'], o['args']) | ||||
|             return 0 | ||||
|     except utils.CliException as e: | ||||
|         print() | ||||
|         print(f"{Colors.RED}{e.msg}{Colors.RESET}") | ||||
|         sys.exit(1) | ||||
|         print(f"{utils.Colors.RED}{e.msg}{utils.Colors.RESET}") | ||||
|         return 1 | ||||
							
								
								
									
										5
									
								
								osdk/__main__.py
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										5
									
								
								osdk/__main__.py
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| import sys | ||||
| 
 | ||||
| from . import main | ||||
| 
 | ||||
| sys.exit(main()) | ||||
|  | @ -1,13 +1,12 @@ | |||
| from os import environ | ||||
| from typing import TextIO, Tuple | ||||
| import json | ||||
| 
 | ||||
| import ninja | ||||
| import manifests as m | ||||
| import environments as e | ||||
| import copy | ||||
| import utils | ||||
| from utils import Colors | ||||
| 
 | ||||
| from . import ninja | ||||
| from . import manifests as m | ||||
| from . import environments as e | ||||
| from . import utils | ||||
| 
 | ||||
| 
 | ||||
| def genNinja(out: TextIO, manifests: dict, env: dict) -> None: | ||||
|  | @ -92,7 +91,7 @@ def prepare(envName: str) -> Tuple[dict, dict]: | |||
| 
 | ||||
| def buildAll(envName: str) -> None: | ||||
|     environment, _ = prepare(envName) | ||||
|     print(f"{Colors.BOLD}Building all targets for {envName}{Colors.RESET}") | ||||
|     print(f"{utils.Colors.BOLD}Building all targets for {envName}{utils.Colors.RESET}") | ||||
|     try: | ||||
|         utils.runCmd("ninja", "-j", "1", "-f", environment["ninjafile"]) | ||||
|     except: | ||||
|  | @ -101,7 +100,7 @@ def buildAll(envName: str) -> None: | |||
| 
 | ||||
| 
 | ||||
| def buildOne(envName: str, target: str) -> str: | ||||
|     print(f"{Colors.BOLD}Building {target} for {envName}{Colors.RESET}") | ||||
|     print(f"{utils.Colors.BOLD}Building {target} for {envName}{utils.Colors.RESET}") | ||||
|     environment, manifests = prepare(envName) | ||||
| 
 | ||||
|     if not target in manifests: | ||||
|  | @ -2,7 +2,7 @@ | |||
| import copy | ||||
| import os | ||||
| 
 | ||||
| import utils | ||||
| from . import utils | ||||
| 
 | ||||
| 
 | ||||
| PASSED_TO_BUILD = [ | ||||
|  | @ -46,7 +46,8 @@ def enableOptimizer(env: dict, level: str) -> dict: | |||
| 
 | ||||
| 
 | ||||
| def available() -> list: | ||||
|     return [file.removesuffix(".json") for file in os.listdir("meta/toolchains") if file.endswith(".json")] | ||||
|     return [file.removesuffix(".json") for file in utils.tryListDir("meta/toolchains") | ||||
|             if file.endswith(".json")] | ||||
| 
 | ||||
| 
 | ||||
| VARIANTS = ["debug", "devel", "release", "sanatize"] | ||||
|  | @ -2,7 +2,7 @@ import os | |||
| import json | ||||
| import copy | ||||
| 
 | ||||
| import utils | ||||
| from . import utils | ||||
| 
 | ||||
| 
 | ||||
| def loadJsons(basedir: str) -> dict: | ||||
|  | @ -7,7 +7,6 @@ import requests | |||
| import subprocess | ||||
| import json | ||||
| import copy | ||||
| from types import SimpleNamespace | ||||
| 
 | ||||
| 
 | ||||
| class Colors: | ||||
|  | @ -187,3 +186,10 @@ def loadJson(filename: str) -> dict: | |||
| 
 | ||||
|     result = copy.deepcopy(result) | ||||
|     return result | ||||
| 
 | ||||
| 
 | ||||
| def tryListDir(path: str) -> list[str]: | ||||
|     try: | ||||
|         return os.listdir(path) | ||||
|     except FileNotFoundError: | ||||
|         return [] | ||||
							
								
								
									
										19
									
								
								setup.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								setup.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| from setuptools import setup | ||||
| 
 | ||||
| setup( | ||||
|     name="osdk", | ||||
|     version="0.0.1", | ||||
|     description="Operating System Development Kit", | ||||
|     author="The DEVSE Community", | ||||
|     author_email="contact@devse.wiki", | ||||
|     url="https://devse.wiki/", | ||||
|     packages=["osdk"], | ||||
|     install_requires=[ | ||||
|         "requests", | ||||
|     ], | ||||
|     entry_points={ | ||||
|         "console_scripts": [ | ||||
|             "osdk = osdk:main", | ||||
|         ], | ||||
|     } | ||||
| ) | ||||
		Loading…
	
	Add table
		
		Reference in a new issue