From 18f516bc235250cca5384172344eee365af40ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Cardao?= Date: Fri, 21 Jul 2023 14:17:30 +0200 Subject: [PATCH] Add e3.anod.spec.Anod.source_list e3.anod.spec.Anod.source_list contain the dependencies source list (any e3.anod.deps.Dependency that require 'source_pkg') e3.anod.spec.Anod.deps will not reference anymore the source_pkg dependencies. --- src/e3/anod/context.py | 23 +++++++++++++++++++---- src/e3/anod/driver.py | 23 ++++++++++++++++++++++- src/e3/anod/spec.py | 3 ++- tests/tests_e3/anod/context_test.py | 11 +++++++---- 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/e3/anod/context.py b/src/e3/anod/context.py index 1e48a055..d8825679 100644 --- a/src/e3/anod/context.py +++ b/src/e3/anod/context.py @@ -32,7 +32,7 @@ from e3.error import E3Error if TYPE_CHECKING: - from typing import cast, NoReturn, Optional, Tuple + from typing import cast, NoReturn, Optional from collections.abc import Callable from e3.anod.action import Action from e3.anod.package import SourceBuilder @@ -44,7 +44,7 @@ from e3.mypy import assert_never # spec name, build env, target env, host env, qualifier, kind, source name - CacheKeyType = Tuple[ + CacheKeyType = tuple[ str, Platform, Platform, Platform, Optional[str], Optional[str], Optional[str] ] ResolverType = Callable[[Action, Decision], bool] @@ -439,7 +439,22 @@ def add_dep(spec_instance: Anod, dep: Dependency, dep_instance: Anod) -> None: spec_instance.name, dep.local_name ), ) - spec_instance.deps[dep.local_name] = dep_instance + if dep.kind != "source": + spec_instance.deps[dep.local_name] = dep_instance + else: + srcbuild_list = dep_instance.source_pkg_build + spec_instance.source_list[dep.local_name] = set() + if not srcbuild_list: + raise AnodError( + f"{dep.local_name} is marked as source_pkg but not sources is " + "defined" + ) + for srcbuild in srcbuild_list: + if srcbuild.name in spec_instance.source_list[dep.local_name]: + raise AnodError( + f"{srcbuild.name} defined two times in source_pkg_build" + ) + spec_instance.source_list[dep.local_name].add(srcbuild.name) # type: ignore[attr-defined] # Initialize a spec instance spec = self.load( @@ -669,7 +684,7 @@ def add_dep(spec_instance: Anod, dep: Dependency, dep_instance: Anod) -> None: add_dep(spec_instance=spec, dep=e, dep_instance=child_instance) self.dependencies[spec.uid][e.local_name] = ( e, - spec.deps[e.local_name], + child_instance, ) continue diff --git a/src/e3/anod/driver.py b/src/e3/anod/driver.py index d60adf02..261e315e 100644 --- a/src/e3/anod/driver.py +++ b/src/e3/anod/driver.py @@ -61,7 +61,28 @@ def activate(self, sandbox: SandBox, spec_repository: AnodSpecRepository) -> Non kind=e.kind, env=e.env(self.anod_instance, BaseEnv.from_env()), ) - self.anod_instance.deps[e.local_name] = dep_instance + if e.kind != "source": + self.anod_instance.deps[e.local_name] = dep_instance + else: + srcbuild_list = dep_instance.source_pkg_build + self.anod_instance.source_list[e.local_name] = set() + if not srcbuild_list: + raise AnodError( + f"{e.local_name} is marked as source_pkg but not sources is" + " defined" + ) + for srcbuild in srcbuild_list: + if ( + srcbuild.name + in self.anod_instance.source_list[e.local_name] + ): + raise AnodError( + f"{srcbuild.name} defined two times in source_pkg_build" + ) + self.anod_instance.source_list[e.local_name].add( # type: ignore[attr-defined] + srcbuild.name + ) + e3.log.debug("activating spec %s", self.anod_instance.uid) def call(self, action: str) -> Any: diff --git a/src/e3/anod/spec.py b/src/e3/anod/spec.py index 8f37d828..2ce3710d 100644 --- a/src/e3/anod/spec.py +++ b/src/e3/anod/spec.py @@ -34,7 +34,7 @@ Literal, Union, ) - from collections.abc import Callable, Sequence + from collections.abc import Callable, Sequence, Iterable from e3.anod.buildspace import BuildSpace from e3.anod.sandbox import SandBox from e3.env import BaseEnv @@ -212,6 +212,7 @@ def __init__( :raise: SpecError """ self.deps: dict[str, Anod] = {} + self.source_list: dict[str, Iterable[str]] = {} self.kind = kind self.jobs = jobs diff --git a/tests/tests_e3/anod/context_test.py b/tests/tests_e3/anod/context_test.py index e77c8b4b..4fffdefd 100644 --- a/tests/tests_e3/anod/context_test.py +++ b/tests/tests_e3/anod/context_test.py @@ -498,8 +498,10 @@ def anod_action( assert ctag["plan_line"] == "plan.txt:4" # Also verify that the instance deps is properly loaded - assert set(action.anod_instance.deps.keys()) == {"spec1"} - assert action.anod_instance.deps["spec1"].__class__.__name__ == "Spec1" + assert not set(action.anod_instance.deps.keys()) + # Also verify that the instance source list is properly loaded + assert set(action.anod_instance.source_list.keys()) == {"spec1"} + assert set(action.anod_instance.source_list["spec1"]) == {"spec1-src"} # Also test that we are still able to extract the values # after having scheduled the action graph. @@ -522,11 +524,12 @@ def anod_action( assert sched_dag.get_tag(uid) # Also verify that the instance deps is properly loaded - assert set(action.anod_instance.deps.keys()) == {"spec1", "spec11"} + assert set(action.anod_instance.deps.keys()) == {"spec11"} + assert set(action.anod_instance.source_list.keys()) == {"spec1"} assert ( action.anod_instance.deps["spec11"].__class__.__name__ == "Spec11" ) - assert action.anod_instance.deps["spec1"].__class__.__name__ == "Spec1" + assert set(action.anod_instance.source_list["spec1"]) == {"spec1-src"} elif uid.endswith("spec3.build"): assert sched_dag.get_tag(uid)