vxSDK/vxsdk/core/build/project.py

171 lines
5.8 KiB
Python

"""
core.build.project - Core building function
"""
import os
from core.logger import log
from core.build.meta import VxProjectMeta
from core.build.dependency import dependency_project_clone
from core.build.compile import compile_project
from core.build.rules import rules_project_exec
__all__ = [
'VxProject'
]
#---
# Public
#---
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
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='', build_prefix='', target='', 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
> build_prefix (str) - the project build prefix
> 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(),
build_prefix,
target,
extra_conf
)
#---
# Public methods
#---
def update(self):
"""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, verbose=False):
""" Install the project.
@args
> verbose (bool) : display project logs or just strict minimum
@return
> True if no error, False otherwise
"""
return rules_project_exec(
self,
['install'],
self.get_env_config()['public'],
verbose
)
def uninstall(self, verbose=False):
""" Uninstall the project
@args
> verbose (bool) : display project logs or just strict minimum
@return
> True if no error, False otherwise
"""
return rules_project_exec(
self,
['uninstall'],
self.get_env_config()['public'],
verbose
)
def build(self, 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...")
# clone dependencies
if not (dep_graph := dependency_project_clone(self)):
log.error(f"[{self.name}] unable to perform dependency relovation")
return -1
log.debug(f"dep_graph = {dep_graph}")
# compile the entire project
return compile_project(dep_graph, verbose)