Skip to content

Commit 4084a6b

Browse files
committed
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.
1 parent a5ac69c commit 4084a6b

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

src/e3/anod/context.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from e3.error import E3Error
3333

3434
if TYPE_CHECKING:
35-
from typing import cast, NoReturn, Optional, Tuple
35+
from typing import cast, NoReturn, Optional
3636
from collections.abc import Callable
3737
from e3.anod.action import Action
3838
from e3.anod.package import SourceBuilder
@@ -44,7 +44,7 @@
4444
from e3.mypy import assert_never
4545

4646
# spec name, build env, target env, host env, qualifier, kind, source name
47-
CacheKeyType = Tuple[
47+
CacheKeyType = tuple[
4848
str, Platform, Platform, Platform, Optional[str], Optional[str], Optional[str]
4949
]
5050
ResolverType = Callable[[Action, Decision], bool]
@@ -439,7 +439,22 @@ def add_dep(spec_instance: Anod, dep: Dependency, dep_instance: Anod) -> None:
439439
spec_instance.name, dep.local_name
440440
),
441441
)
442-
spec_instance.deps[dep.local_name] = dep_instance
442+
if dep.kind != "source":
443+
spec_instance.deps[dep.local_name] = dep_instance
444+
else:
445+
srcbuild_list = dep_instance.source_pkg_build
446+
spec_instance.source_list[dep.local_name] = set()
447+
if not srcbuild_list:
448+
raise AnodError(
449+
f"{dep.local_name} is marked as source_pkg but not sources are "
450+
"defined"
451+
)
452+
for srcbuild in srcbuild_list:
453+
if srcbuild.name in spec_instance.source_list[dep.local_name]:
454+
raise AnodError(
455+
f"{srcbuild.name} defined two times in source_pkg_build"
456+
)
457+
spec_instance.source_list[dep.local_name].add(srcbuild.name) # type: ignore[attr-defined]
443458

444459
# Initialize a spec instance
445460
spec = self.load(
@@ -669,7 +684,7 @@ def add_dep(spec_instance: Anod, dep: Dependency, dep_instance: Anod) -> None:
669684
add_dep(spec_instance=spec, dep=e, dep_instance=child_instance)
670685
self.dependencies[spec.uid][e.local_name] = (
671686
e,
672-
spec.deps[e.local_name],
687+
child_instance,
673688
)
674689

675690
continue

src/e3/anod/driver.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,28 @@ def activate(self, sandbox: SandBox, spec_repository: AnodSpecRepository) -> Non
6161
kind=e.kind,
6262
env=e.env(self.anod_instance, BaseEnv.from_env()),
6363
)
64-
self.anod_instance.deps[e.local_name] = dep_instance
64+
if e.kind != "source":
65+
self.anod_instance.deps[e.local_name] = dep_instance
66+
else:
67+
srcbuild_list = dep_instance.source_pkg_build
68+
self.anod_instance.source_list[e.local_name] = set()
69+
if not srcbuild_list:
70+
raise AnodError(
71+
f"{e.local_name} is marked as source_pkg but not sources "
72+
"are defined"
73+
)
74+
for srcbuild in srcbuild_list:
75+
if (
76+
srcbuild.name
77+
in self.anod_instance.source_list[e.local_name]
78+
):
79+
raise AnodError(
80+
f"{srcbuild.name} defined two times in source_pkg_build"
81+
)
82+
self.anod_instance.source_list[e.local_name].add( # type: ignore[attr-defined]
83+
srcbuild.name
84+
)
85+
6586
e3.log.debug("activating spec %s", self.anod_instance.uid)
6687

6788
def call(self, action: str) -> Any:

src/e3/anod/spec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
Literal,
3535
Union,
3636
)
37-
from collections.abc import Callable, Sequence
37+
from collections.abc import Callable, Sequence, Iterable
3838
from e3.anod.buildspace import BuildSpace
3939
from e3.anod.sandbox import SandBox
4040
from e3.env import BaseEnv
@@ -212,6 +212,7 @@ def __init__(
212212
:raise: SpecError
213213
"""
214214
self.deps: dict[str, Anod] = {}
215+
self.source_list: dict[str, Iterable[str]] = {}
215216

216217
self.kind = kind
217218
self.jobs = jobs

tests/tests_e3/anod/context_test.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,10 @@ def anod_action(
498498
assert ctag["plan_line"] == "plan.txt:4"
499499

500500
# Also verify that the instance deps is properly loaded
501-
assert set(action.anod_instance.deps.keys()) == {"spec1"}
502-
assert action.anod_instance.deps["spec1"].__class__.__name__ == "Spec1"
501+
assert not set(action.anod_instance.deps.keys())
502+
# Also verify that the instance source list is properly loaded
503+
assert set(action.anod_instance.source_list.keys()) == {"spec1"}
504+
assert set(action.anod_instance.source_list["spec1"]) == {"spec1-src"}
503505

504506
# Also test that we are still able to extract the values
505507
# after having scheduled the action graph.
@@ -522,11 +524,12 @@ def anod_action(
522524
assert sched_dag.get_tag(uid)
523525

524526
# Also verify that the instance deps is properly loaded
525-
assert set(action.anod_instance.deps.keys()) == {"spec1", "spec11"}
527+
assert set(action.anod_instance.deps.keys()) == {"spec11"}
528+
assert set(action.anod_instance.source_list.keys()) == {"spec1"}
526529
assert (
527530
action.anod_instance.deps["spec11"].__class__.__name__ == "Spec11"
528531
)
529-
assert action.anod_instance.deps["spec1"].__class__.__name__ == "Spec1"
532+
assert set(action.anod_instance.source_list["spec1"]) == {"spec1-src"}
530533

531534
elif uid.endswith("spec3.build"):
532535
assert sched_dag.get_tag(uid)

0 commit comments

Comments
 (0)