196 lines
7.0 KiB
Python
196 lines
7.0 KiB
Python
r""" build.core - Core building function
|
|
|
|
This module exports:
|
|
|
|
VxProject - a class representing a "Vhex" project
|
|
"""
|
|
import os
|
|
|
|
from core.logger import log
|
|
from core.build.meta import VxProjectMeta
|
|
from core.build.dependency import project_dependency_clone
|
|
from core.build.compile import project_compile
|
|
from core.build.rules import project_rules_exec
|
|
|
|
__all__ = [
|
|
'VxProject'
|
|
]
|
|
|
|
|
|
#---
|
|
# Public object
|
|
#---
|
|
|
|
class VxProject(VxProjectMeta):
|
|
r"""Represent a Vhex project
|
|
|
|
A Vhex project is a folder which contains a 'vxsdk.toml' file. This file
|
|
describe information about the project, like its name, version, description,
|
|
and many other information.
|
|
|
|
This class will handle this particular file, and will abstract some complex
|
|
tasks like build abstraction, assets conversion, manage project dependencies
|
|
and more.
|
|
|
|
All project information and file generation (file objects, build logs,
|
|
assets conversion, ...) will be stored in a '.vxsdk' folder at the root of
|
|
the project folder.
|
|
|
|
The VxProject exposes:
|
|
|
|
================================== =========================================
|
|
Property VxprojectMeta Description
|
|
================================== =========================================
|
|
name (str) * Holds name
|
|
type (str) * Holds type (lib, app or addin)
|
|
path (str) * Holds project path
|
|
dependencies (list) * Holds project dependencies
|
|
description (str) * Holds description
|
|
build_rules (dict) * Holds custom build information
|
|
board_support (list,str) * List of all supported board (None if all)
|
|
extra_conf (dict) Holds extra rules information
|
|
parent (str) Holds project parent path
|
|
version (str) Holds version
|
|
assets (list) Holds project assets paths
|
|
is_original (bool) Return True if its the original package
|
|
================================== =========================================
|
|
|
|
================================== =========================================
|
|
Method Description
|
|
================================== =========================================
|
|
update() Try to update project's dependencies
|
|
install() Install the project
|
|
uninstall() Uninstall the project
|
|
build() Build the entiere project (dep, src, ...)
|
|
rebuild() Rebuild the entiere project
|
|
================================== =========================================
|
|
"""
|
|
def __init__(self, path=None, parent_path=None, extra_conf=None):
|
|
r""" Try to read the TOML project file of a project
|
|
|
|
This constructor will simply try to read the vxsdk.toml file stored at
|
|
the root of the project directory . The project path can be provided by
|
|
`path` but if the path is not provided, the vxSDK will select the
|
|
current working directory.
|
|
|
|
The `parent` path is used to know if the project is the original one or
|
|
a dependency. If it a dependency, its build genereted files will be done
|
|
in the `.vxsdk/*` directory of the original one.
|
|
|
|
Extra information for each building steps can be provided in the form of
|
|
dictionary. Like this:
|
|
|
|
```
|
|
{
|
|
'configure' : '--static --enable-xana',
|
|
'build': '--verbose'
|
|
}
|
|
```
|
|
|
|
@args
|
|
> path (str) - the project path
|
|
> parent_path (str) - the project parent path
|
|
> extra (dict) - extra flags information about particular steps
|
|
|
|
@raise
|
|
> Exception - if the project file cannot be loaded
|
|
"""
|
|
super().__init__(
|
|
os.path.abspath(path) if path else os.getcwd(),
|
|
parent_path,
|
|
extra_conf
|
|
)
|
|
|
|
#---
|
|
# Public methods
|
|
#---
|
|
|
|
def update(self):
|
|
r"""Update project's dependencies.
|
|
|
|
This method will try to bump all dependencies to the possible newest
|
|
version, always validating the dependencies versioning match
|
|
|
|
TODO:
|
|
> display dependency name and tag and "old version -> new version"
|
|
> try to update and build the new dependencies before override
|
|
"""
|
|
log.error('dependencies update not implemented yet')
|
|
return -1
|
|
|
|
def install(self, target, verbose=False):
|
|
r""" Install the project.
|
|
|
|
@args
|
|
> target (str) : targeted board for operation (fxcg50, SDL, ...)
|
|
> verbose (bool) : display project logs or just strict minimum
|
|
|
|
@return
|
|
> True if no error, False otherwise
|
|
"""
|
|
if target and self.target_support and target not in self.target_support:
|
|
log.error(f"[{self.name}] target '{target}' not supported")
|
|
return -1
|
|
return project_rules_exec(
|
|
self,
|
|
target,
|
|
['install'],
|
|
verbose
|
|
)
|
|
|
|
def uninstall(self, target, verbose=False):
|
|
""" Uninstall the project
|
|
|
|
@args
|
|
> target (str) : targted board for operation (fxcg50, SDL, ...)
|
|
> verbose (bool) : display project logs or just strict minimum
|
|
|
|
@return
|
|
> True if no error, False otherwise
|
|
"""
|
|
if target and self.target_support and target not in self.target_support:
|
|
log.error(f"[{self.name}] target '{target}' not supported")
|
|
return -1
|
|
return project_rules_exec(
|
|
self,
|
|
target,
|
|
['uninstall'],
|
|
verbose
|
|
)
|
|
|
|
def build(self, target=None, verbose=False):
|
|
"""Build the entire project
|
|
|
|
Args:
|
|
> target (str) : target build operation
|
|
> verbose (bool) : display project logs or just strict minimum
|
|
|
|
Return:
|
|
> True if success, False otherwise
|
|
"""
|
|
log.user(f"[{self.name}] start building package...")
|
|
|
|
# check target availability
|
|
if target and self.target_support and target not in self.target_support:
|
|
log.error(f"[{self.name}] target '{target}' not supported")
|
|
return -1
|
|
|
|
# check if the project is compatible with the board
|
|
build_rules = self.get_build_rules(target)
|
|
if not 'config' in build_rules \
|
|
and not 'build' in build_rules \
|
|
and not 'install' in build_rules:
|
|
log.error(f"[{self.name}] project not compatible for '{target}'")
|
|
return -2
|
|
|
|
# clone dependencies
|
|
log.debug(f"target test = {target}")
|
|
dep_graph = project_dependency_clone(self, target)
|
|
if not dep_graph:
|
|
log.error(f"[{self.name}] unable to perform dependeincy relovation")
|
|
return -3
|
|
|
|
# compile the entire project
|
|
log.debug(f"dep_graph = {dep_graph}")
|
|
return project_compile(dep_graph, verbose)
|