Skip to content

Commit 5da0cba

Browse files
authored
Fix pcb publish in board dir (#530)
* Fix `pcb publish` in board dir * Add regression test
1 parent 10da5b3 commit 5da0cba

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

CHANGELOG.md

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

1313
- `load()` and `Module()` with relative paths can now cross package boundaries within a workspace, resolved through the dependency system.
1414

15+
### Fixed
16+
17+
- `pcb publish` now works when run from a board directory with a relative `.zen` path (e.g., `pcb publish DM0002.zen`).
18+
1519
### Changed
1620

1721
- Resolve `Path()` and `File()` to stable relative paths for machine-independent build artifacts.

crates/pcb/src/file_walker.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ pub struct BoardTarget {
135135
pub fn resolve_board_target(path: &Path, action: &str) -> Result<BoardTarget> {
136136
require_zen_file(path)?;
137137
let file_provider = DefaultFileProvider::new();
138-
let start_path = path.parent().unwrap_or(Path::new("."));
138+
let start_path = path
139+
.parent()
140+
.filter(|p| !p.as_os_str().is_empty())
141+
.unwrap_or(Path::new("."));
139142
let workspace = get_workspace_info(&file_provider, start_path)?;
140143

141144
if !workspace.errors.is_empty() {

crates/pcb/tests/release.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,31 @@ fn test_publish_board_with_description() {
345345
let staging_dir = find_staging_dir(&sb, "DescBoard");
346346
assert_snapshot!("publish_with_description", sb.snapshot_dir(&staging_dir));
347347
}
348+
349+
/// Test that `pcb publish` works when run from the board directory with a relative .zen path.
350+
/// Regression test: previously, `pcb publish DM0002.zen` from `boards/DM0002/` would fail
351+
/// with "No lockfile found" because workspace discovery broke on the empty parent path.
352+
#[test]
353+
fn test_publish_board_from_board_dir() {
354+
let mut sb = Sandbox::new();
355+
sb.cwd("src")
356+
.write("pcb.toml", PCB_TOML)
357+
.write("boards/pcb.toml", BOARD_PCB_TOML)
358+
.write("boards/modules/LedModule.zen", LED_MODULE_ZEN)
359+
.write("boards/TestBoard.zen", TEST_BOARD_ZEN)
360+
.hash_globs(["*.kicad_mod", "**/diodeinc/stdlib/*.zen", "**/netlist.json"])
361+
.ignore_globs(["layout/*", "**/vendor/**", "**/build/**"])
362+
.init_git()
363+
.commit("Initial commit");
364+
365+
// Build first to generate lockfile
366+
sb.run("pcb", ["build", "boards/TestBoard.zen"])
367+
.run()
368+
.expect("build failed");
369+
370+
// Run publish from the board directory with a relative path
371+
sb.cwd("src/boards")
372+
.run("pcb", source_only_args("TestBoard.zen"))
373+
.run()
374+
.expect("publish from board dir with relative path should work");
375+
}

0 commit comments

Comments
 (0)