Skip to content

IEP-1756 Deprecated! use 'adapter usb location <location>' command instead of OPENOCD_USB_ADAPTER_LOCATION variable#1450

Merged
kolipakakondal merged 2 commits intomasterfrom
IEP-1756
May 6, 2026
Merged

IEP-1756 Deprecated! use 'adapter usb location <location>' command instead of OPENOCD_USB_ADAPTER_LOCATION variable#1450
kolipakakondal merged 2 commits intomasterfrom
IEP-1756

Conversation

@sigmaaa
Copy link
Copy Markdown
Collaborator

@sigmaaa sigmaaa commented Apr 29, 2026

Description

Created OpenOcdVersionManager to optimize the usage of the openocd --version command. It is now used to determine whether the adapted USB location command should be used instead of the OPENOCD_USB_ADAPTER_LOCATION variable.

Fixes # (IEP-1756)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this been tested?

Download the latest openocd https://github.com/espressif/openocd-esp32/releases/tag/v0.12.0-esp32-20260424 and test it. There should no Deprecated! use 'adapter usb location <location>' command instead of OPENOCD_USB_ADAPTER_LOCATION variable in the logs

Test Configuration:

  • ESP-IDF Version:
  • OS (Windows,Linux and macOS):

Dependent components impacted by this PR:

  • Debug

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Added Unit Test
  • Verified on all platforms - Windows,Linux and macOS

Summary by CodeRabbit

  • New Features

    • Added USB location configuration support for OpenOCD when supported by the detected OpenOCD build.
  • Bug Fixes

    • Stop applying USB location settings when the selected OpenOCD build lacks support, preventing incorrect command injection.
  • Improvements

    • More reliable OpenOCD version detection and capability checks to improve compatibility and reduce false positives.
  • Tests

    • Added unit tests covering version parsing and comparison logic.

@sigmaaa sigmaaa self-assigned this Apr 29, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

A new OpenOcdVersionManager utility centralizes OpenOCD version retrieval/caching and parsing; Configuration and GdbServerBackend now consult it to decide runtime command/environment adjustments (e.g., adapter USB location) instead of spawning inline version-check processes.

Changes

Cohort / File(s) Summary
Core Utility
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/OpenOcdVersionManager.java
Adds a cached, thread-safe OpenOCD version retriever that runs openocd --version (2s timeout), merges stderr/stdout, parses major/minor/optional patch and optional build date via regex, and exposes isAtLeast() / isBuildDateAtLeast() comparison helpers.
Integration Refactors
bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java, bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java
Replaces inline process-based version detection with OpenOcdVersionManager calls; injects -c "adapter usb location ..." only when supported by detected OpenOCD build date and conditions; conditions for setting OPENOCD_USB_LOCATION are tightened.
Tests
tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/OpenOcdVersionManagerTest.java
Adds unit tests covering parsing variations (vendor tags, build dates, missing patch), comparison semantics (isAtLeast, isBuildDateAtLeast), null/empty inputs, and toString() formatting.

Sequence Diagram(s)

sequenceDiagram
    participant Config as Configuration
    participant Backend as GdbServerBackend
    participant Manager as OpenOcdVersionManager
    participant OpenOCD as OpenOCD executable

    Config->>Backend: prepare launch args
    Backend->>Manager: getVersion(openocdPath)
    Manager->>OpenOCD: run "openocd --version" (stderr->stdout, 2s timeout)
    OpenOCD-->>Manager: version output
    Manager-->>Backend: OpenOcdVersion (cached)
    Backend->>Config: capability flags (isAtLeast / isBuildDateAtLeast)
    Config->>Backend: finalize args/env (inject -c adapter usb location or OPENOCD_USB_LOCATION as needed)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • kolipakakondal
  • AndriiFilippov
  • alirana01

Poem

🐇 I sniff the version trail at dawn,
I cache the dates before they're gone,
I parse the numbers, patch and day,
Then tell the launch just what to say —
A hopping helper, ready, on! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: deprecating use of OPENOCD_USB_ADAPTER_LOCATION variable in favor of an 'adapter usb location' command. This aligns with the core objectives of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch IEP-1756

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java (1)

349-357: Refactor opportunity: avoid duplicating version/build-date thresholds.

Consider moving these thresholds into OpenOcdVersionManager as a named capability API so both call sites stay consistent.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java`
around lines 349 - 357, Extract the duplicated version/build-date thresholds
into named capability methods on OpenOcdVersionManager and call those from
Configuration: replace the inline checks in supportsAdapterUsbCommand(String
executablePath) and useModernPortSyntax(String executablePath) with calls like
OpenOcdVersionManager.supportsAdapterUsbCommand(executablePath) and
OpenOcdVersionManager.useModernPortSyntax(executablePath) (or similarly named
methods) so the version logic (e.g., isBuildDateAtLeast(0,12,20260424) and
isAtLeast(0,12)) lives only in OpenOcdVersionManager and both call sites
delegate to those new capability APIs for consistency.
bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java (1)

247-250: Consider centralizing the adapter-support threshold in one place.

This literal threshold is duplicated across classes. Expose a single capability helper (or shared constant) to prevent future divergence.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java`
around lines 247 - 250, The method supportsAdapterUsbCommand currently embeds a
hard-coded threshold (0,12,20260424); centralize this by introducing a single
shared capability helper or constant (e.g.,
OpenOcdCapabilities.ADAPTER_USB_COMMAND_THRESHOLD or a helper method
OpenOcdVersionManager.supportsAdapterUsbCommand(executablePath)) and replace the
literal check in supportsAdapterUsbCommand with a call/reference to that shared
symbol so all classes use the same source of truth; update other duplicates to
use the same new constant/helper and keep the version comparison logic inside
OpenOcdVersionManager (or the new helper) to avoid duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java`:
- Around line 230-234: The code currently sets
IDFLaunchConstants.OPENOCD_USB_LOCATION when
supportsAdapterUsbCommand(commandLineArray[0]) returns true, which is reversed;
change the condition so OPENOCD_USB_LOCATION is set only when openocdLoc != null
&& commandLineArray != null && commandLineArray.length > 0 &&
!supportsAdapterUsbCommand(commandLineArray[0]) (i.e., for legacy OpenOCD that
does NOT support adapter usb location), keeping the same envMap.put call and
using the existing variables openocdLoc, commandLineArray and
supportsAdapterUsbCommand to locate the fix.

---

Nitpick comments:
In
`@bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java`:
- Around line 349-357: Extract the duplicated version/build-date thresholds into
named capability methods on OpenOcdVersionManager and call those from
Configuration: replace the inline checks in supportsAdapterUsbCommand(String
executablePath) and useModernPortSyntax(String executablePath) with calls like
OpenOcdVersionManager.supportsAdapterUsbCommand(executablePath) and
OpenOcdVersionManager.useModernPortSyntax(executablePath) (or similarly named
methods) so the version logic (e.g., isBuildDateAtLeast(0,12,20260424) and
isAtLeast(0,12)) lives only in OpenOcdVersionManager and both call sites
delegate to those new capability APIs for consistency.

In
`@bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java`:
- Around line 247-250: The method supportsAdapterUsbCommand currently embeds a
hard-coded threshold (0,12,20260424); centralize this by introducing a single
shared capability helper or constant (e.g.,
OpenOcdCapabilities.ADAPTER_USB_COMMAND_THRESHOLD or a helper method
OpenOcdVersionManager.supportsAdapterUsbCommand(executablePath)) and replace the
literal check in supportsAdapterUsbCommand with a call/reference to that shared
symbol so all classes use the same source of truth; update other duplicates to
use the same new constant/helper and keep the version comparison logic inside
OpenOcdVersionManager (or the new helper) to avoid duplication.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3753ca32-b686-43dd-9c13-0ab4161939e4

📥 Commits

Reviewing files that changed from the base of the PR and between aacc821 and 20ab65a.

📒 Files selected for processing (4)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/OpenOcdVersionManager.java
  • bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java
  • bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/OpenOcdVersionManagerTest.java

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java (1)

247-250: ⚡ Quick win

Deduplicate the adapter USB support threshold to avoid drift.

This method hardcodes 0, 12, 20260424, and the same threshold exists in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java:349-352. Please centralize this in one shared API/constant (ideally in OpenOcdVersionManager) so command-line injection and env-var fallback can’t diverge later.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java`
around lines 247 - 250, The hardcoded version threshold (0, 12, 20260424) must
be centralized to avoid drift: add a single public constant or helper in
OpenOcdVersionManager (e.g. ADAPTER_USB_SUPPORT_MAJOR/MINOR/BUILDDATE or a
method isAdapterUsbSupported(executablePath)) and update
GdbServerBackend.supportsAdapterUsbCommand and the check in Configuration to
call that new constant/method instead of repeating the triple (0,12,20260424);
ensure the behavior still uses
OpenOcdVersionManager.getVersion(...).isBuildDateAtLeast(...) under the new
centralized symbol.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java`:
- Around line 247-250: The hardcoded version threshold (0, 12, 20260424) must be
centralized to avoid drift: add a single public constant or helper in
OpenOcdVersionManager (e.g. ADAPTER_USB_SUPPORT_MAJOR/MINOR/BUILDDATE or a
method isAdapterUsbSupported(executablePath)) and update
GdbServerBackend.supportsAdapterUsbCommand and the check in Configuration to
call that new constant/method instead of repeating the triple (0,12,20260424);
ensure the behavior still uses
OpenOcdVersionManager.getVersion(...).isBuildDateAtLeast(...) under the new
centralized symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 685a4e7f-204b-463a-9785-2d010c38a29e

📥 Commits

Reviewing files that changed from the base of the PR and between 20ab65a and 94e5087.

📒 Files selected for processing (1)
  • bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/GdbServerBackend.java

Copy link
Copy Markdown
Collaborator

@kolipakakondal kolipakakondal left a comment

Choose a reason for hiding this comment

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

LGTM

@kolipakakondal kolipakakondal added this to the v4.3.0 milestone May 5, 2026
Copy link
Copy Markdown
Collaborator

@AndriiFilippov AndriiFilippov left a comment

Choose a reason for hiding this comment

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

@sigmaaa hi !

Tested under:
OS: Windows 11 / Mac arm64
OpenOCD: v12

LGTM 👍

@kolipakakondal kolipakakondal merged commit 99419b4 into master May 6, 2026
3 of 6 checks passed
@kolipakakondal kolipakakondal deleted the IEP-1756 branch May 6, 2026 12:48
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.

3 participants