Skip to content

Commit 4916862

Browse files
authored
Include kicad drc json in release (#519)
* Include kicad drc json in release * Fix snapshot tests, add changelog
1 parent a5969f6 commit 4916862

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to Semantic Versioning (https://semver.org/spec/v2.0.0.
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- `pcb release` now includes `drc.json` in the release archive containing the full KiCad DRC report.
14+
1115
### Changed
1216

1317
- KiCad layout discovery no longer assumes `layout.kicad_pcb`; it now discovers a single top-level `.kicad_pro` (preferred) or `.kicad_pcb` in the layout directory and errors on ambiguity.

crates/pcb-kicad/src/lib.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,30 +319,31 @@ where
319319
/// # Arguments
320320
/// * `pcb_path` - Path to the .kicad_pcb file to check
321321
/// * `diagnostics` - Diagnostics collection to add violations to
322+
/// * `output` - Path to write the raw KiCad DRC JSON report to
322323
///
323324
/// # Example
324325
/// ```no_run
325326
/// use pcb_kicad::run_drc;
326327
/// use pcb_zen_core::Diagnostics;
327328
/// let mut diagnostics = Diagnostics::default();
328-
/// run_drc("layout/layout.kicad_pcb", &mut diagnostics).unwrap();
329+
/// let output = tempfile::NamedTempFile::new().unwrap();
330+
/// run_drc("layout/layout.kicad_pcb", &mut diagnostics, output.path()).unwrap();
329331
/// if diagnostics.error_count() > 0 {
330332
/// eprintln!("DRC errors found!");
331333
/// }
332334
/// ```
333-
pub fn run_drc(pcb_path: impl AsRef<Path>, diagnostics: &mut Diagnostics) -> Result<()> {
335+
pub fn run_drc(
336+
pcb_path: impl AsRef<Path>,
337+
diagnostics: &mut Diagnostics,
338+
output: &Path,
339+
) -> Result<()> {
334340
check_kicad_installed()?;
335341

336342
let pcb_path = pcb_path.as_ref();
337343
if !pcb_path.exists() {
338344
anyhow::bail!("PCB file not found: {}", pcb_path.display());
339345
}
340346

341-
// Create a temporary file for the JSON output
342-
let temp_file =
343-
NamedTempFile::new().context("Failed to create temporary file for DRC output")?;
344-
let temp_path = temp_file.path();
345-
346347
// Run kicad-cli pcb drc with JSON output
347348
KiCadCliBuilder::new()
348349
.command("pcb")
@@ -352,13 +353,13 @@ pub fn run_drc(pcb_path: impl AsRef<Path>, diagnostics: &mut Diagnostics) -> Res
352353
.arg("--severity-all") // Report all severities (errors and warnings)
353354
.arg("--severity-exclusions") // Include violations excluded by user in KiCad
354355
.arg("--output")
355-
.arg(temp_path.to_string_lossy())
356+
.arg(output.to_string_lossy())
356357
.arg(pcb_path.to_string_lossy())
357358
.run()
358359
.context("Failed to run KiCad DRC")?;
359360

360361
// Parse and add to diagnostics
361-
let report = drc::DrcReport::from_file(temp_path).context("Failed to parse DRC report")?;
362+
let report = drc::DrcReport::from_file(output).context("Failed to parse DRC report")?;
362363
report.add_to_diagnostics(diagnostics, &pcb_path.to_string_lossy());
363364
Ok(())
364365
}

crates/pcb/src/layout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ pub fn execute(mut args: LayoutArgs) -> Result<()> {
124124
// Run DRC in check mode
125125
if args.check {
126126
let spinner = Spinner::builder(format!("{file_name}: Running DRC checks")).start();
127-
pcb_kicad::run_drc(&pcb_file, &mut diagnostics)?;
127+
let drc_output = tempfile::NamedTempFile::new()?;
128+
pcb_kicad::run_drc(&pcb_file, &mut diagnostics, drc_output.path())?;
128129
spinner.finish();
129130
}
130131

crates/pcb/src/release.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,8 +1510,9 @@ fn run_kicad_drc(info: &ReleaseInfo, spinner: &Spinner) -> Result<()> {
15101510
&mut diagnostics,
15111511
)?;
15121512

1513-
// Run DRC and render all diagnostics
1514-
pcb_kicad::run_drc(&kicad_pcb_path, &mut diagnostics)?;
1513+
// Run DRC, writing raw KiCad JSON report to staging directory
1514+
let drc_json_path = info.staging_dir.join("drc.json");
1515+
pcb_kicad::run_drc(&kicad_pcb_path, &mut diagnostics, &drc_json_path)?;
15151516
spinner.suspend(|| crate::drc::render_diagnostics(&mut diagnostics, &info.suppress));
15161517

15171518
// Fail if there are errors

crates/pcb/tests/release.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ fn test_publish_board_full() {
249249
"manufacturing/*.html",
250250
"**/vendor/**",
251251
"**/build/**",
252+
"**/drc.json",
252253
])
253254
.init_git()
254255
.commit("Initial commit");

crates/pcb/tests/tag.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fn test_publish_board_simple_workspace() {
4747
"**/manufacturing/**",
4848
"**/3d/**",
4949
"**/bom/**",
50+
"**/drc.json",
5051
])
5152
.init_git()
5253
.commit("Initial commit");

0 commit comments

Comments
 (0)