meta: add sources from prototype meadow build system
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import os
|
||||
import sys
|
||||
import tomli
|
||||
from dependency import *
|
||||
from config import Config
|
||||
from path import Path
|
||||
|
||||
|
||||
all_targets = {}
|
||||
|
||||
|
||||
class Target(DependencyItem):
|
||||
def all_targets():
|
||||
global all_targets
|
||||
return all_targets
|
||||
|
||||
|
||||
def current_target():
|
||||
name = Config.get('target.name')
|
||||
if not name or name not in all_targets:
|
||||
return None
|
||||
|
||||
return all_targets[name]
|
||||
|
||||
|
||||
def load_file(self, path):
|
||||
with open(path, mode='rb') as f:
|
||||
self.__data = tomli.load(f)
|
||||
|
||||
|
||||
def __init_dependencies(self):
|
||||
self.__dependencies = {}
|
||||
|
||||
if 'dependency' not in self.__data:
|
||||
return
|
||||
|
||||
dependency = self.__data['dependency']
|
||||
if 'seeds' in dependency:
|
||||
seeds = dependency['seeds']
|
||||
self.__dependencies = {}
|
||||
for s in seeds:
|
||||
self.__dependencies[s] = SeedDependency(parent=self.name(), name=s)
|
||||
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
if 'path' not in kwargs:
|
||||
return
|
||||
|
||||
self.load_file(kwargs['path'])
|
||||
self.__init_dependencies()
|
||||
|
||||
|
||||
def name(self):
|
||||
if not 'target' in self.__data:
|
||||
return None
|
||||
|
||||
s = self.__data['target']
|
||||
if 'name' in s:
|
||||
return s['name']
|
||||
return None
|
||||
|
||||
|
||||
def dependencies(self):
|
||||
return self.__dependencies
|
||||
|
||||
|
||||
def base_components(self):
|
||||
if not 'target' in self.__data:
|
||||
return None
|
||||
|
||||
s = self.__data['target']
|
||||
if 'base_components' in s:
|
||||
return s['base_components']
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def install_prefix(self, **kwargs):
|
||||
make_relative = kwargs.get('make_relative', False)
|
||||
path = self.__data.get('target', {}).get('default_prefix', '/')
|
||||
|
||||
if make_relative:
|
||||
path = Path(path).remove_root().get_path
|
||||
|
||||
return path
|
||||
|
||||
|
||||
def scan_directory(root_path):
|
||||
global all_targets
|
||||
|
||||
for root, dirs, files in os.walk(root_path):
|
||||
for f in files:
|
||||
if not f.endswith('.target'):
|
||||
continue
|
||||
target_path = os.path.join(root, f)
|
||||
target = None
|
||||
try:
|
||||
target = Target(path=target_path)
|
||||
except tomli.TOMLDecodeError as e:
|
||||
print('Err: Failed to parse target file {}\n {}'.format(target_path, e))
|
||||
continue
|
||||
|
||||
all_targets[target.name()] = target
|
||||
Reference in New Issue
Block a user