Skip to content

Commit 1c1f283

Browse files
committed
Address PR comments
1 parent e26a27d commit 1c1f283

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

crates/pcb-layout/src/lib.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ pub fn process_layout(
437437
.expect("Failed to create temporary directory")
438438
.keep()
439439
} else {
440-
match utils::resolve_layout_dir(schematic) {
440+
match utils::resolve_layout_dir(schematic)? {
441441
Some(path) => path,
442442
None => return Ok(None),
443443
}
@@ -592,17 +592,22 @@ pub mod utils {
592592
use pcb_sch::InstanceKind;
593593
use std::collections::HashMap;
594594

595-
/// Extract layout path from schematic's root instance attributes
596595
/// Resolve layout directory from schematic.
597-
/// Returns None if the schematic has no layout_path attribute.
598-
pub fn resolve_layout_dir(schematic: &Schematic) -> Option<PathBuf> {
599-
let root_ref = schematic.root_ref.as_ref()?;
600-
let root = schematic.instances.get(root_ref)?;
601-
let layout_uri = root
602-
.attributes
603-
.get(ATTR_LAYOUT_PATH)
604-
.and_then(|v| v.string())?;
605-
schematic.resolve_package_uri(layout_uri).ok()
596+
/// Returns `Ok(None)` if no `layout_path` attribute is set.
597+
pub fn resolve_layout_dir(schematic: &Schematic) -> anyhow::Result<Option<PathBuf>> {
598+
let uri = schematic
599+
.root_ref
600+
.as_ref()
601+
.and_then(|r| schematic.instances.get(r))
602+
.and_then(|inst| inst.attributes.get(ATTR_LAYOUT_PATH))
603+
.and_then(|v| v.string());
604+
match uri {
605+
None => Ok(None),
606+
Some(s) => schematic
607+
.resolve_package_uri(s)
608+
.map(Some)
609+
.with_context(|| format!("Failed to resolve layout_path '{s}'")),
610+
}
606611
}
607612

608613
pub const DEFAULT_KICAD_BASENAME: &str = "layout";

crates/pcb-layout/src/scripts/lens/tests/test_adapter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,9 @@ def set_field(name, value):
557557

558558
footprint_lib_map = {"Resistor_SMD": "/path/to/lib"}
559559

560-
_create_footprint(view, complement, mock_board, mock_pcbnew, footprint_lib_map, {}, None)
560+
_create_footprint(
561+
view, complement, mock_board, mock_pcbnew, footprint_lib_map, {}, None
562+
)
561563

562564
# Custom fields should be hidden
563565
assert visibility_calls.get("Path") is False

crates/pcb-sch/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub fn format_package_uri(abs: &Path, package_roots: &BTreeMap<String, PathBuf>)
105105
if rel_str.is_empty() {
106106
Some(format!("{PACKAGE_URI_PREFIX}{pkg_url}"))
107107
} else {
108+
let rel_str = rel_str.replace('\\', "/");
108109
Some(format!("{PACKAGE_URI_PREFIX}{pkg_url}/{rel_str}"))
109110
}
110111
}

crates/pcb/src/open.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn execute(args: OpenArgs) -> Result<()> {
3636
.map_err(|_| anyhow::anyhow!("Build failed for {}", file_name))?;
3737

3838
let schematic = output.to_schematic()?;
39-
let layout_dir = utils::resolve_layout_dir(&schematic)
39+
let layout_dir = utils::resolve_layout_dir(&schematic)?
4040
.ok_or_else(|| anyhow::anyhow!("No layout path defined in {}", file_name))?;
4141

4242
let kicad_files = utils::require_kicad_files(&layout_dir)?;

crates/pcb/src/route.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn execute(args: RouteArgs) -> Result<()> {
6060

6161
let schematic = output.context("No schematic output from evaluation")?;
6262

63-
let layout_dir = utils::resolve_layout_dir(&schematic)
63+
let layout_dir = utils::resolve_layout_dir(&schematic)?
6464
.context("No layout path defined in schematic. Add layout=\"path\" to your module.")?;
6565

6666
// Discover KiCad project + board paths

0 commit comments

Comments
 (0)