96 lines
2.4 KiB
Python
96 lines
2.4 KiB
Python
import sys
|
|
import os
|
|
import tomli
|
|
from seed import Seed
|
|
from target import Target
|
|
from platform import Platform
|
|
from config import Config
|
|
from cache import Cache
|
|
from command import Command, UserCommand
|
|
from args import Args
|
|
from env import Environment
|
|
from dependency import SeedDependency, DependencyResolutionError
|
|
from builtin import *
|
|
from colorama import init as colorama_init
|
|
from colorama import Fore, Style
|
|
|
|
|
|
def main():
|
|
colorama_init()
|
|
Command.register(SetCommand())
|
|
Command.register(SeedsCommand())
|
|
Command.register(PlatformsCommand())
|
|
Command.register(HelpCommand())
|
|
Command.register(BuildCommand())
|
|
Command.register(CleanCommand())
|
|
Config.load()
|
|
Cache.load()
|
|
Environment.set_source_root(os.getcwd())
|
|
|
|
Seed.scan_directory([
|
|
'base',
|
|
'external',
|
|
'interface',
|
|
'toolchain',
|
|
'lib',
|
|
'programs',
|
|
'services',
|
|
'sys'
|
|
])
|
|
|
|
UserCommand.scan_directory([
|
|
'toolchain'
|
|
])
|
|
|
|
Target.scan_directory('./target')
|
|
platforms = Platform.scan_directory('./arch')
|
|
|
|
current_platform = Platform.current_platform()
|
|
if current_platform:
|
|
current_platform.load_extensions()
|
|
|
|
if len(sys.argv) < 2:
|
|
print(f'{Fore.CYAN}Usage:{Style.RESET_ALL} {sys.argv[0]} <command> [args...]')
|
|
return -1
|
|
|
|
command_name = sys.argv[1]
|
|
command = Command.get(command_name)
|
|
if command is None:
|
|
print(f'{Fore.RED}Err:{Style.RESET_ALL} unknown command "{command_name}"')
|
|
return -1
|
|
|
|
current_target = Target.current_target()
|
|
seeds = Seed.all_seeds()
|
|
|
|
if current_target is not None:
|
|
system_dep_names = current_target.base_components()
|
|
|
|
for s in seeds.values():
|
|
if s.name() in system_dep_names or not s.should_include_standard_dependencies():
|
|
continue
|
|
|
|
for n in system_dep_names:
|
|
s.add_dependency(n, SeedDependency(parent=s.name(), name=n))
|
|
|
|
try:
|
|
current_target.resolve()
|
|
except DependencyResolutionError as e:
|
|
print(f'{Fore.RED}Err:{Style.RESET_ALL} {e}')
|
|
return -1
|
|
|
|
args = Args(sys.argv[2:])
|
|
result = None
|
|
try:
|
|
result = command.run(args)
|
|
except Exception as e:
|
|
print(f'{Fore.RED}Err:{Style.RESET_ALL} {e}')
|
|
finally:
|
|
Cache.save()
|
|
Config.save()
|
|
|
|
return result
|
|
|
|
|
|
if __name__ == '__main__':
|
|
exit(main())
|