Skip to content

fix: restore OpenOCD scripts/ search path for bundled releases#11

Merged
nedseb merged 2 commits into
mainfrom
fix/openocd-scripts-search-path
Apr 28, 2026
Merged

fix: restore OpenOCD scripts/ search path for bundled releases#11
nedseb merged 2 commits into
mainfrom
fix/openocd-scripts-search-path

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Apr 28, 2026

Summary

Hotfix for #8.

A cleanup commit during the wireless-stack PR (#5) dropped the -s scripts argument passed to OpenOCD, on the assumption that it was a leftover from the old script-dir layout. It wasn't.

The xpack-bundled release archive places OpenOCD's standard scripts (interface/, target/, ...) at <install>/scripts/ next to the binary. Our .cfg files load these with source [find interface/stlink.cfg] etc., which only resolves through OpenOCD's search path. Without -s <scripts-path>, the bundled OpenOCD falls back to its compiled-in install prefix, which doesn't match the flat layout — first flash on a fresh release archive fails with Can't find interface/stlink.cfg.

This restores the search path, but with two improvements over the original:

  • Absolute path built from dirs::get_exe_dir() instead of the bare relative "scripts", so it works regardless of the user's CWD.
  • Existence-guarded via is_dir(), so a system-OpenOCD setup (where <exe_dir>/scripts/ doesn't exist) keeps using OpenOCD's compiled-in defaults instead of getting a useless -s arg.

Test plan

  • cargo run from the repo root: DapLink unlock/erase/flash still resolves via the system OpenOCD (no <exe_dir>/scripts/ present, -s arg skipped).
  • Build a fresh release archive locally (cargo build --release + manually mirror the workflow's archive layout into a tmpdir with configs/, wireless_stack/, scripts/, openocd); run the binary; confirm the unlock step finds interface/stlink.cfg.
  • WB55 wireless-stack flow: flash operator (uses wb5x.cfg which source [find interface/cmsis-dap.cfg]) succeeds with the bundled scripts path.

The xpack-bundled OpenOCD release archive ships its standard scripts
under <install>/scripts/ (interface/, target/, ...). Our .cfg files
reference these via `source [find interface/stlink.cfg]` etc., which
resolves only through OpenOCD's search path.

A previous cleanup commit dropped the `-s scripts` argument, thinking
it was a leftover from the old script-dir layout — it wasn't. Without
that path, the bundled OpenOCD has to fall back to its compiled-in
install prefix, which doesn't match the flat layout the release
archive produces.

Restore the search path with an absolute resolution against exe_dir,
guarded by an `is_dir()` check so a system-OpenOCD install (where
`<exe_dir>/scripts/` doesn't exist) keeps using OpenOCD's defaults.

Closes #8.
Copilot AI review requested due to automatic review settings April 28, 2026 09:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Restores OpenOCD’s ability to resolve standard interface//target/ scripts when using the xpack-bundled OpenOCD layout by re-adding an OpenOCD -s search path entry that points at <exe_dir>/scripts when present.

Changes:

  • Adds an existence-guarded -s <exe_dir>/scripts argument to OpenOCD invocations (for bundled releases).
  • Simplifies the cmd.args(...) usage by removing an unnecessary re-binding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/open_ocd_task.rs Outdated
Comment on lines +143 to +145
.into_string()
.map_err(|_| "Failed to convert scripts path to string")?;
cmd.args(&["-s", &scripts_str]);
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new error string "Failed to convert scripts path to string" is missing a trailing period and is slightly inconsistent with nearby messages (e.g., tmp_dir/config path conversions). Consider standardizing the punctuation/style so user-facing errors are consistent.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made moot by 568e386 — the conversion (and its error message) are gone now that Command::arg accepts the PathBuf directly. Resolved by following the sibling suggestion.

Comment thread src/open_ocd_task.rs Outdated
Comment on lines +141 to +145
let scripts_str = scripts_folder
.into_os_string()
.into_string()
.map_err(|_| "Failed to convert scripts path to string")?;
cmd.args(&["-s", &scripts_str]);
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command can accept OsStr/Path arguments directly, so converting scripts_folder to a UTF-8 String is unnecessary and can fail on non-UTF8 paths. Consider passing the PathBuf (or OsStr) directly to avoid the extra conversion and keep this consistent with Rust’s usual path handling.

Suggested change
let scripts_str = scripts_folder
.into_os_string()
.into_string()
.map_err(|_| "Failed to convert scripts path to string")?;
cmd.args(&["-s", &scripts_str]);
cmd.arg("-s").arg(&scripts_folder);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 568e386 — applied your suggestion as-is. cmd.arg("-s").arg(&scripts_folder) removes the panic vector on non-UTF-8 paths and is cleaner. Thanks!

Command::arg accepts OsStr/Path directly, so the into_os_string()
+ into_string() conversion was both unnecessary and a panic vector
on non-UTF-8 paths.

Per Copilot review on PR #11.
@nedseb nedseb merged commit 476f3b3 into main Apr 28, 2026
@nedseb nedseb deleted the fix/openocd-scripts-search-path branch April 28, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants