meta: add sources from prototype meadow build system
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
import os
|
||||
import shutil
|
||||
from env import Environment
|
||||
from path import Path
|
||||
from pathlib import Path as SysPath
|
||||
|
||||
|
||||
class UnknownBuildSystemError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class BuildConfigurationError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class BuildError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class BuildSystem:
|
||||
def __init__(self, **kwargs):
|
||||
self.__name = None
|
||||
self.__source_dir = None
|
||||
self.__bin_dir = None
|
||||
self.__parent = None
|
||||
self.__install = None
|
||||
|
||||
if 'name' in kwargs:
|
||||
self.__name = kwargs['name']
|
||||
if 'source_dir' in kwargs:
|
||||
self.__source_dir = kwargs['source_dir']
|
||||
if 'bin_dir' in kwargs:
|
||||
self.__bin_dir = kwargs['bin_dir']
|
||||
if 'parent' in kwargs:
|
||||
self.__parent = kwargs['parent']
|
||||
if 'install' in kwargs:
|
||||
self.__install = kwargs['install']
|
||||
|
||||
|
||||
def name(self):
|
||||
return self.__name
|
||||
|
||||
|
||||
def source_dir(self):
|
||||
return self.__source_dir
|
||||
|
||||
|
||||
def binary_dir(self):
|
||||
return self.__bin_dir
|
||||
|
||||
|
||||
def parent(self):
|
||||
return self.__parent
|
||||
|
||||
|
||||
def install_manifest(self):
|
||||
return self.__install
|
||||
|
||||
|
||||
def build_for(self):
|
||||
return 'target'
|
||||
|
||||
|
||||
def get_path_namespaces(self):
|
||||
ns = {
|
||||
'src': os.path.abspath(self.source_dir()),
|
||||
'root-src': Environment.source_root(),
|
||||
'bin': os.path.abspath(self.binary_dir()),
|
||||
}
|
||||
|
||||
if self.build_for() == 'host':
|
||||
ns['install'] = Environment.native_root()
|
||||
else:
|
||||
ns['install'] = Environment.system_root()
|
||||
|
||||
return ns
|
||||
|
||||
|
||||
def check_out_of_date(self):
|
||||
self.__config_out_of_date = self._is_configuration_out_of_date()
|
||||
self.__build_out_of_date = self._is_build_out_of_date()
|
||||
|
||||
|
||||
def is_configuration_out_of_date(self):
|
||||
return self.__config_out_of_date
|
||||
|
||||
|
||||
def is_build_out_of_date(self):
|
||||
return self.__build_out_of_date
|
||||
|
||||
|
||||
def configure(self):
|
||||
return
|
||||
|
||||
|
||||
def build(self):
|
||||
return
|
||||
|
||||
|
||||
def __copy_dir(self, src, dst):
|
||||
dst_dir = os.path.dirname(dst)
|
||||
SysPath(dst_dir).mkdir(parents=True, exist_ok=True)
|
||||
shutil.copytree(src, dst, dirs_exist_ok=True)
|
||||
|
||||
|
||||
def __copy_file(self, src, dst):
|
||||
dst_dir = os.path.dirname(dst)
|
||||
SysPath(dst_dir).mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(src, dst)
|
||||
|
||||
|
||||
def install_from_seed(self):
|
||||
manifest = self.install_manifest()
|
||||
if manifest is None:
|
||||
return
|
||||
|
||||
ns = self.get_path_namespaces()
|
||||
source_dir = self.source_dir()
|
||||
|
||||
dest_dir = Environment.system_root()
|
||||
if self.build_for() == 'host':
|
||||
dest_dir = Environment.native_root()
|
||||
|
||||
for dest, src in manifest.items():
|
||||
if dest[0] != '/':
|
||||
continue
|
||||
|
||||
dest = Path(dest).remove_root().get_path()
|
||||
|
||||
for p in src:
|
||||
path = Path(p)
|
||||
files = path.expand_path(relative_to=ns)
|
||||
|
||||
for p2 in files:
|
||||
file_name = os.path.basename(p2)
|
||||
rel_path = os.path.relpath(p2, start=source_dir)
|
||||
src_path = p2
|
||||
dst_path = os.path.join(dest_dir, dest, file_name)
|
||||
if os.path.isdir(src_path):
|
||||
self.__copy_dir(src_path, dst_path)
|
||||
else:
|
||||
self.__copy_file(src_path, dst_path)
|
||||
|
||||
|
||||
def install(self):
|
||||
return
|
||||
Reference in New Issue
Block a user