Skip to content

Commit eb6a91c

Browse files
authored
Merge pull request #438 from Erethon/feat-show-stack-trace
Add option to show stack trace in failed builds
2 parents 12c4ab4 + 4bae315 commit eb6a91c

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

@@ -656,6 +665,7 @@ def nix_build_steps(
656665
post_build_steps: list[steps.BuildStep],
657666
branch_config: models.BranchConfigDict,
658667
outputs_path: Path | None = None,
668+
show_trace: bool = False,
659669
) -> list[steps.BuildStep]:
660670
out_steps = [
661671
NixBuildCommand(
@@ -666,6 +676,7 @@ def nix_build_steps(
666676
"nix",
667677
"build",
668678
"-L",
679+
*(["--show-trace"] if show_trace else []),
669680
"--option",
670681
"keep-going",
671682
"true",
@@ -723,12 +734,18 @@ def nix_build_config(
723734
post_build_steps: list[steps.BuildStep],
724735
branch_config_dict: models.BranchConfigDict,
725736
outputs_path: Path | None = None,
737+
show_trace: bool = False,
726738
) -> BuilderConfig:
727739
"""Builds one nix flake attribute."""
728740
factory = util.BuildFactory()
729741
factory.addSteps(
730742
nix_build_steps(
731-
project, worker_names, post_build_steps, branch_config_dict, outputs_path
743+
project,
744+
worker_names,
745+
post_build_steps,
746+
branch_config_dict,
747+
outputs_path,
748+
show_trace,
732749
)
733750
)
734751

@@ -795,6 +812,7 @@ def nix_cached_failure_config(
795812
branch_config_dict: models.BranchConfigDict,
796813
post_build_steps: list[steps.BuildStep],
797814
outputs_path: Path | None = None,
815+
show_trace: bool = False,
798816
) -> BuilderConfig:
799817
"""Dummy builder that is triggered when a build is cached as failed."""
800818
factory = util.BuildFactory()
@@ -808,6 +826,7 @@ def nix_cached_failure_config(
808826
name="Cached failure",
809827
haltOnFailure=True,
810828
flunkOnFailure=True,
829+
show_trace=show_trace,
811830
),
812831
)
813832

@@ -980,6 +999,7 @@ def config_for_project(
980999
per_repo_effects_secrets: dict[str, str],
9811000
branch_config_dict: models.BranchConfigDict,
9821001
outputs_path: Path | None = None,
1002+
show_trace: bool = False,
9831003
) -> None:
9841004
config["projects"].append(Project(project.name))
9851005
config["schedulers"].extend(
@@ -1086,13 +1106,15 @@ def config_for_project(
10861106
max_memory_size=nix_eval_max_memory_size,
10871107
eval_lock=eval_lock,
10881108
failed_builds_db=failed_builds_db,
1109+
show_trace=show_trace,
10891110
),
10901111
nix_build_config(
10911112
project,
10921113
worker_names,
10931114
outputs_path=outputs_path,
10941115
branch_config_dict=branch_config_dict,
10951116
post_build_steps=post_build_steps,
1117+
show_trace=show_trace,
10961118
),
10971119
buildbot_effects_config(
10981120
project,
@@ -1115,6 +1137,7 @@ def config_for_project(
11151137
branch_config_dict=branch_config_dict,
11161138
post_build_steps=post_build_steps,
11171139
outputs_path=outputs_path,
1140+
show_trace=show_trace,
11181141
),
11191142
nix_register_gcroot_config(project, worker_names),
11201143
],
@@ -1334,6 +1357,7 @@ def configure(self, config: dict[str, Any]) -> None:
13341357
failed_builds_db=DB,
13351358
branch_config_dict=self.config.branches,
13361359
outputs_path=self.config.outputs_path,
1360+
show_trace=self.config.show_trace_on_failure,
13371361
)
13381362
except Exception: # noqa: BLE001
13391363
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
@@ -287,6 +287,7 @@ class BuildbotNixConfig(BaseModel):
287287

288288
nix_workers_secret_file: Path | None = None
289289
effects_per_repo_secrets: dict[str, str] = {}
290+
show_trace_on_failure: bool = False
290291

291292
def nix_worker_secrets(self) -> WorkerConfig:
292293
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
@@ -563,6 +563,11 @@ in
563563
to force the endpoint to use https:// instead of http://.
564564
'';
565565
};
566+
showTrace = lib.mkOption {
567+
type = lib.types.nullOr lib.types.bool;
568+
default = false;
569+
description = "Show stack traces on failed evaluations";
570+
};
566571

567572
outputsPath = lib.mkOption {
568573
type = lib.types.nullOr lib.types.path;
@@ -809,6 +814,7 @@ in
809814
}) cfg.effects.perRepoSecretFiles;
810815
branches = cfg.branches;
811816
nix_workers_secret_file = "buildbot-nix-workers";
817+
show_trace_on_failure = cfg.showTrace;
812818
}
813819
}").read_text()))
814820
)

0 commit comments

Comments
 (0)