Flattening Tests
This commit is contained in:
@@ -15,6 +15,7 @@ from .._config import Config
|
||||
from ._except import NoProjectFoundError
|
||||
from ._shared import projects_by_name_mapping
|
||||
from ._shared import targets_by_name_mapping
|
||||
from ._shared import tests_by_name_mapping
|
||||
from ._shared import project_by_targets_mapping
|
||||
|
||||
|
||||
@@ -35,7 +36,9 @@ def load(path: Path) -> Project:
|
||||
_collect_profiles(project)
|
||||
_collect_required(project)
|
||||
_collect_targets(project)
|
||||
_collect_tests(project)
|
||||
_flatten_targets(project)
|
||||
_flatten_tests(project)
|
||||
return project
|
||||
except Exception as rethrowme:
|
||||
raise rethrowme
|
||||
@@ -56,6 +59,11 @@ def _collect_targets(project: Project) -> None:
|
||||
targets_by_name_mapping[target.name] = target
|
||||
project_by_targets_mapping[target.name] = project
|
||||
|
||||
def _collect_targets(project: Project) -> None:
|
||||
for test in project.tests:
|
||||
if test.name not in tests_by_name_mapping:
|
||||
tests_by_name_mapping[test.name] = test
|
||||
|
||||
def _flatten_targets(project: Project) -> None:
|
||||
for target in project.targets:
|
||||
_flatten_target(target)
|
||||
@@ -70,6 +78,18 @@ def _flatten_targets(project: Project) -> None:
|
||||
value = project.destination.libpath
|
||||
))
|
||||
|
||||
def _flatten_tests(project: Project) -> None:
|
||||
for test in project.tests:
|
||||
_flatten_target(test)
|
||||
target.incs.includes.add(Accessor(
|
||||
level = Access.PRIVATE,
|
||||
value = project.origination.src("include")
|
||||
))
|
||||
target.incs.libraries.add(Accessor(
|
||||
level = Access.PRIVATE,
|
||||
value = project.destination.libpath
|
||||
))
|
||||
|
||||
def _flatten_target(target: Target) -> None:
|
||||
for dependency in target.deps:
|
||||
if (parent:=targets_by_name_mapping.get(dependency.value)) == None:
|
||||
@@ -77,6 +97,9 @@ def _flatten_target(target: Target) -> None:
|
||||
_inherit_target(target, parent)
|
||||
|
||||
def _inherit_target(target: Target, parent: Target) -> None:
|
||||
if parent.name in tests_by_name_mapping:
|
||||
raise ValueError("Cannot inherit tests")
|
||||
|
||||
_flatten_target(parent)
|
||||
target.incs.includes.update([v for v in parent.incs.includes if v.level != Access.PRIVATE])
|
||||
target.incs.libraries.update([v for v in parent.incs.libraries if v.level != Access.PRIVATE])
|
||||
|
||||
@@ -4,5 +4,6 @@ from ..models import Target
|
||||
|
||||
projects_by_name_mapping: dict[str, Project] = {}
|
||||
targets_by_name_mapping: dict[str, Target] = {}
|
||||
tests_by_name_mapping: dict[str, Target] = {}
|
||||
|
||||
project_by_targets_mapping: dict[str, Project] = {}
|
||||
|
||||
Reference in New Issue
Block a user