Skip to content

Commit b530999

Browse files
committed
Add option to show stack trace in failed builds
1 parent 7ad9b48 commit b530999

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

buildbot_nix/buildbot_nix/__init__.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def __init__(
125125
worker_count: int,
126126
max_memory_size: int,
127127
drv_gcroots_dir: util.Interpolate,
128+
show_trace: bool = False,
128129
**kwargs: Any,
129130
) -> None:
130131
kwargs = self.setupShellMixin(kwargs)
@@ -138,6 +139,7 @@ def __init__(
138139
self.worker_count = worker_count
139140
self.max_memory_size = max_memory_size
140141
self.drv_gcroots_dir = drv_gcroots_dir
142+
self.show_trace = show_trace
141143

142144
async def produce_event(self, event: str, result: None | int) -> None:
143145
build: dict[str, Any] = await self.master.data.get(
@@ -175,6 +177,7 @@ async def run(self) -> int:
175177
str(self.drv_gcroots_dir),
176178
"--force-recurse",
177179
"--check-cache-status",
180+
*(["--show-trace"] if self.show_trace else []),
178181
"--flake",
179182
f".#{branch_config.attribute}",
180183
*(
@@ -311,6 +314,7 @@ class CachedFailureStep(steps.BuildStep):
311314
post_build_steps: list[models.PostBuildStep]
312315
branch_config_dict: models.BranchConfigDict
313316
outputs_path: Path | None
317+
show_trace: bool
314318

315319
def __init__(
316320
self,
@@ -319,13 +323,15 @@ def __init__(
319323
post_build_steps: list[models.PostBuildStep],
320324
branch_config_dict: models.BranchConfigDict,
321325
outputs_path: Path | None,
326+
show_trace: bool = False,
322327
**kwargs: Any,
323328
) -> None:
324329
self.project = project
325330
self.worker_names = worker_names
326331
self.post_build_steps = post_build_steps
327332
self.branch_config_dict = branch_config_dict
328333
self.outputs_path = outputs_path
334+
self.show_trace = show_trace
329335

330336
super().__init__(**kwargs)
331337

@@ -349,6 +355,7 @@ async def run(self) -> int:
349355
self.post_build_steps,
350356
self.branch_config_dict,
351357
self.outputs_path,
358+
self.show_trace,
352359
)
353360
)
354361
return util.SUCCESS
@@ -543,6 +550,7 @@ def nix_eval_config(
543550
max_memory_size: int,
544551
job_report_limit: int | None,
545552
failed_builds_db: FailedBuildDB,
553+
show_trace: bool = False,
546554
) -> BuilderConfig:
547555
"""Uses nix-eval-jobs to evaluate hydraJobs from flake.nix in parallel.
548556
For each evaluated attribute a new build pipeline is started.
@@ -583,6 +591,7 @@ def nix_eval_config(
583591
max_memory_size=max_memory_size,
584592
drv_gcroots_dir=drv_gcroots_dir,
585593
logEnviron=False,
594+
show_trace=show_trace,
586595
),
587596
)
588597

@@ -658,6 +667,7 @@ def nix_build_steps(
658667
post_build_steps: list[steps.BuildStep],
659668
branch_config: models.BranchConfigDict,
660669
outputs_path: Path | None = None,
670+
show_trace: bool = False,
661671
) -> list[steps.BuildStep]:
662672
out_steps = [
663673
NixBuildCommand(
@@ -668,6 +678,7 @@ def nix_build_steps(
668678
"nix",
669679
"build",
670680
"-L",
681+
*(["--show-trace"] if show_trace else []),
671682
"--option",
672683
"keep-going",
673684
"true",
@@ -725,12 +736,18 @@ def nix_build_config(
725736
post_build_steps: list[steps.BuildStep],
726737
branch_config_dict: models.BranchConfigDict,
727738
outputs_path: Path | None = None,
739+
show_trace: bool = False,
728740
) -> BuilderConfig:
729741
"""Builds one nix flake attribute."""
730742
factory = util.BuildFactory()
731743
factory.addSteps(
732744
nix_build_steps(
733-
project, worker_names, post_build_steps, branch_config_dict, outputs_path
745+
project,
746+
worker_names,
747+
post_build_steps,
748+
branch_config_dict,
749+
outputs_path,
750+
show_trace,
734751
)
735752
)
736753

@@ -797,6 +814,7 @@ def nix_cached_failure_config(
797814
branch_config_dict: models.BranchConfigDict,
798815
post_build_steps: list[steps.BuildStep],
799816
outputs_path: Path | None = None,
817+
show_trace: bool = False,
800818
) -> BuilderConfig:
801819
"""Dummy builder that is triggered when a build is cached as failed."""
802820
factory = util.BuildFactory()
@@ -810,6 +828,7 @@ def nix_cached_failure_config(
810828
name="Cached failure",
811829
haltOnFailure=True,
812830
flunkOnFailure=True,
831+
show_trace=show_trace,
813832
),
814833
)
815834

@@ -984,6 +1003,7 @@ def config_for_project(
9841003
per_repo_effects_secrets: dict[str, str],
9851004
branch_config_dict: models.BranchConfigDict,
9861005
outputs_path: Path | None = None,
1006+
show_trace: bool = False,
9871007
) -> None:
9881008
config["projects"].append(Project(project.name))
9891009
config["schedulers"].extend(
@@ -1090,13 +1110,15 @@ def config_for_project(
10901110
max_memory_size=nix_eval_max_memory_size,
10911111
eval_lock=eval_lock,
10921112
failed_builds_db=failed_builds_db,
1113+
show_trace=show_trace,
10931114
),
10941115
nix_build_config(
10951116
project,
10961117
worker_names,
10971118
outputs_path=outputs_path,
10981119
branch_config_dict=branch_config_dict,
10991120
post_build_steps=post_build_steps,
1121+
show_trace=show_trace,
11001122
),
11011123
buildbot_effects_config(
11021124
project,
@@ -1119,6 +1141,7 @@ def config_for_project(
11191141
branch_config_dict=branch_config_dict,
11201142
post_build_steps=post_build_steps,
11211143
outputs_path=outputs_path,
1144+
show_trace=show_trace,
11221145
),
11231146
nix_register_gcroot_config(project, worker_names),
11241147
],
@@ -1338,6 +1361,7 @@ def configure(self, config: dict[str, Any]) -> None:
13381361
failed_builds_db=DB,
13391362
branch_config_dict=self.config.branches,
13401363
outputs_path=self.config.outputs_path,
1364+
show_trace=self.config.show_trace_on_failure,
13411365
)
13421366
except Exception: # noqa: BLE001
13431367
log.failure(f"Failed to configure project {project.name}")

buildbot_nix/buildbot_nix/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class BuildbotNixConfig(BaseModel):
282282

283283
nix_workers_secret_file: Path | None = None
284284
effects_per_repo_secrets: dict[str, str] = {}
285+
show_trace_on_failure: bool = False
285286

286287
def nix_worker_secrets(self) -> WorkerConfig:
287288
if self.nix_workers_secret_file is None:

nixosModules/master.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ in
538538
to force the endpoint to use https:// instead of http://.
539539
'';
540540
};
541+
showTrace = lib.mkOption {
542+
type = lib.types.nullOr lib.types.bool;
543+
default = false;
544+
description = "Show stack traces on failed builds";
545+
};
541546

542547
outputsPath = lib.mkOption {
543548
type = lib.types.nullOr lib.types.path;
@@ -780,6 +785,7 @@ in
780785
}) cfg.effects.perRepoSecretFiles;
781786
branches = cfg.branches;
782787
nix_workers_secret_file = "buildbot-nix-workers";
788+
show_trace_on_failure = cfg.showTrace;
783789
}
784790
}").read_text()))
785791
)

0 commit comments

Comments
 (0)