Skip to content

Commit 85a012e

Browse files
committed
feat(pkg/build): add InternalPreset for build stages always executed first
1 parent 116f8a1 commit 85a012e

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

packages/debmagic-pkg/src/debmagic/v0/_build.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import shutil
34
import subprocess
45
import typing
56
from dataclasses import dataclass, field
@@ -9,6 +10,7 @@
910
from debmagic.common.utils import run_cmd
1011

1112
from ._build_stage import BuildStage
13+
from ._preset import Preset
1214

1315
if typing.TYPE_CHECKING:
1416
from debmagic.common.package import BinaryPackage
@@ -73,6 +75,8 @@ def run(
7375
self,
7476
target_stage: BuildStage | None = None,
7577
) -> None:
78+
internal_stages = InternalPreset()
79+
7680
for stage in BuildStage:
7781
print(f"debmagic: stage {stage!s}", end="")
7882

@@ -82,6 +86,10 @@ def run(
8286
continue
8387
print(":")
8488

89+
# run internal function for stage
90+
if internal_stage_function := internal_stages.get_stage(stage):
91+
internal_stage_function(self)
92+
8593
# run stage function from debian/rules.py
8694
if rules_stage_function := self.package.stage_functions.get(stage):
8795
print("debmagic: running stage from rules file...")
@@ -108,3 +116,16 @@ def run(
108116

109117
class BuildError(RuntimeError):
110118
pass
119+
120+
121+
class InternalPreset(Preset):
122+
"""
123+
these stages here are always executed before
124+
build stage functions from debian/rules.py or a preset from modules/,
125+
"""
126+
127+
def clean(self, build: Build) -> None:
128+
# clean install dirs
129+
for install_dir in build.install_dirs.values():
130+
if install_dir.is_dir():
131+
shutil.rmtree(install_dir)

packages/debmagic-pkg/src/debmagic/v0/_module/default.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
fallback for all build stages.
33
"""
44

5-
import shutil
5+
from __future__ import annotations
6+
7+
import typing
68

7-
from .._build import Build
89
from .._preset import Preset as BasePreset
910
from .dh import Preset as DHPreset
1011

12+
if typing.TYPE_CHECKING:
13+
from .._build import Build
14+
1115

1216
class Preset(BasePreset):
1317
"""
@@ -24,12 +28,6 @@ def __init__(self):
2428
self._dh_preset = DHPreset()
2529

2630
def clean(self, build: Build) -> None:
27-
# clean install dirs
28-
for install_dir in build.install_dirs.values():
29-
if install_dir.is_dir():
30-
shutil.rmtree(install_dir)
31-
32-
# run dh's clean sequence
3331
self._dh_preset.clean(build)
3432

3533
def prepare(self, build: Build) -> None:

packages/debmagic-pkg/src/debmagic/v0/_preset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from types import MethodType, ModuleType
55
from typing import TYPE_CHECKING, Callable, TypeVar, cast, overload
66

7-
from ._build import Build
87
from ._build_stage import BuildStage
9-
from ._build_step import BuildStep
108

119
if TYPE_CHECKING:
10+
from ._build import Build
11+
from ._build_step import BuildStep
1212
from ._package import Package
1313

1414

0 commit comments

Comments
 (0)