Turned osdk into a python package.
This commit is contained in:
		
							parent
							
								
									d21f41448f
								
							
						
					
					
						commit
						7bf3c66ca7
					
				
					 8 changed files with 69 additions and 35 deletions
				
			
		
							
								
								
									
										44
									
								
								__main__.py → osdk/__init__.py
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										44
									
								
								__main__.py → osdk/__init__.py
									
										
									
									
									
										
										
										Executable file → Normal file
									
								
							|  | @ -3,11 +3,9 @@ import sys | ||||||
| import os | import os | ||||||
| import random | import random | ||||||
| 
 | 
 | ||||||
| 
 | import osdk.build as build | ||||||
| import build | import osdk.utils as utils | ||||||
| import utils | import osdk.environments as environments | ||||||
| from utils import Colors |  | ||||||
| import environments |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| CMDS = {} | CMDS = {} | ||||||
|  | @ -34,12 +32,12 @@ def parseOptions(args: list[str]) -> dict: | ||||||
| 
 | 
 | ||||||
| def runCmd(opts: dict, args: list[str]) -> None: | def runCmd(opts: dict, args: list[str]) -> None: | ||||||
|     if len(args) == 0: |     if len(args) == 0: | ||||||
|         print(f"Usage: {sys.argv[0]} run <component>") |         print(f"Usage: {args[0]} run <component>") | ||||||
|         sys.exit(1) |         sys.exit(1) | ||||||
| 
 | 
 | ||||||
|     out = build.buildOne(opts.get('env', 'host-clang'), args[0]) |     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:]) |     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: | 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("") | ||||||
| 
 | 
 | ||||||
|     print("Description:") |     print("Description:") | ||||||
|     print("   The skift operating system build system.") |     print("   Operating System Development Kit.") | ||||||
|     print("") |     print("") | ||||||
| 
 | 
 | ||||||
|     print("Commands:") |     print("Commands:") | ||||||
|  | @ -134,6 +132,10 @@ def helpCmd(opts: dict, args: list[str]) -> None: | ||||||
|     print("") |     print("") | ||||||
| 
 | 
 | ||||||
|     print("Enviroments:") |     print("Enviroments:") | ||||||
|  |     availableToolchains = environments.available() | ||||||
|  |     if len(availableToolchains) == 0: | ||||||
|  |         print("   No environments available") | ||||||
|  |     else: | ||||||
|         for env in environments.available(): |         for env in environments.available(): | ||||||
|             print("  " + env) |             print("  " + env) | ||||||
|     print("") |     print("") | ||||||
|  | @ -175,20 +177,22 @@ CMDS = { | ||||||
|     }, |     }, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | 
 | ||||||
|  | def main(): | ||||||
|  |     argv = sys.argv | ||||||
|     try: |     try: | ||||||
|         if len(sys.argv) < 2: |         if len(argv) < 2: | ||||||
|             helpCmd({}, []) |             helpCmd({}, []) | ||||||
|         else: |         else: | ||||||
|             o = parseOptions(sys.argv[2:]) |             o = parseOptions(argv[2:]) | ||||||
|             if not sys.argv[1] in CMDS: |             if not argv[1] in CMDS: | ||||||
|                 print(f"Unknown command: {sys.argv[1]}") |                 print(f"Unknown command: {argv[1]}") | ||||||
|                 print("") |                 print("") | ||||||
|                 print(f"Use '{sys.argv[0]} help' for a list of commands") |                 print(f"Use '{argv[0]} help' for a list of commands") | ||||||
|                 sys.exit(1) |                 return 1 | ||||||
|             CMDS[sys.argv[1]]["func"](o['opts'], o['args']) |             CMDS[argv[1]]["func"](o['opts'], o['args']) | ||||||
|             sys.exit(0) |             return 0 | ||||||
|     except utils.CliException as e: |     except utils.CliException as e: | ||||||
|         print() |         print() | ||||||
|         print(f"{Colors.RED}{e.msg}{Colors.RESET}") |         print(f"{utils.Colors.RED}{e.msg}{utils.Colors.RESET}") | ||||||
|         sys.exit(1) |         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 os import environ | ||||||
| from typing import TextIO, Tuple | from typing import TextIO, Tuple | ||||||
| import json | import json | ||||||
| 
 |  | ||||||
| import ninja |  | ||||||
| import manifests as m |  | ||||||
| import environments as e |  | ||||||
| import copy | 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: | 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: | def buildAll(envName: str) -> None: | ||||||
|     environment, _ = prepare(envName) |     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: |     try: | ||||||
|         utils.runCmd("ninja", "-j", "1", "-f", environment["ninjafile"]) |         utils.runCmd("ninja", "-j", "1", "-f", environment["ninjafile"]) | ||||||
|     except: |     except: | ||||||
|  | @ -101,7 +100,7 @@ def buildAll(envName: str) -> None: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def buildOne(envName: str, target: str) -> str: | 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) |     environment, manifests = prepare(envName) | ||||||
| 
 | 
 | ||||||
|     if not target in manifests: |     if not target in manifests: | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| import copy | import copy | ||||||
| import os | import os | ||||||
| 
 | 
 | ||||||
| import utils | from . import utils | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| PASSED_TO_BUILD = [ | PASSED_TO_BUILD = [ | ||||||
|  | @ -46,7 +46,8 @@ def enableOptimizer(env: dict, level: str) -> dict: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def available() -> list: | 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"] | VARIANTS = ["debug", "devel", "release", "sanatize"] | ||||||
|  | @ -2,7 +2,7 @@ import os | ||||||
| import json | import json | ||||||
| import copy | import copy | ||||||
| 
 | 
 | ||||||
| import utils | from . import utils | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def loadJsons(basedir: str) -> dict: | def loadJsons(basedir: str) -> dict: | ||||||
|  | @ -7,7 +7,6 @@ import requests | ||||||
| import subprocess | import subprocess | ||||||
| import json | import json | ||||||
| import copy | import copy | ||||||
| from types import SimpleNamespace |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Colors: | class Colors: | ||||||
|  | @ -187,3 +186,10 @@ def loadJson(filename: str) -> dict: | ||||||
| 
 | 
 | ||||||
|     result = copy.deepcopy(result) |     result = copy.deepcopy(result) | ||||||
|     return 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