Repository navigation
Hoist the shared USB device-tree builder into AbstractUsbDevice - #3452
Conversation
The recursive controller/hub tree assembly (apply parent vid/pid defaults, recurse children via a parent->children map, sort by name, fall back to "vid:pid" for an absent name) was copied verbatim into five platform USB classes. Extract it once as AbstractUsbDevice.buildDeviceTree, parameterized by a UsbDeviceFactory so each platform still produces its own type. Linux, BSD, FreeBSD, Solaris, and Mac now call buildDeviceTree and keep only their platform-specific map building (udev / usbdevs / lshal / prtconf / IOKit). Solaris passes empty vendor/serial maps; Mac keys its maps by the "0x"-prefixed hex registry id it already used as the unique device id. Windows (child->parent map, PnP device-id parsing, parent serial inheritance) and AIX (flat lscfg list, no device tree) genuinely don't fit this model and keep their own assembly, now with a comment noting why. No user-facing change. The tree-builder unit tests move from LinuxUsbDeviceTest to AbstractUsbDeviceTest, exercising buildDeviceTree directly; the JNA-vs-FFM NativeComparisonTest.usbDevices() recursive deep-equal passes on Apple Silicon.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
💤 Files with no reviewable changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (16)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
🔇 Additional comments (13)
📝 WalkthroughWalkthroughUSB device-tree construction is centralized in ChangesUSB device tree refactor
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3452 +/- ##
============================================
- Coverage 74.55% 74.52% -0.03%
Complexity 76 76
============================================
Files 583 583
Lines 22001 21961 -40
Branches 3686 3682 -4
============================================
- Hits 16402 16366 -36
+ Misses 3557 3548 -9
- Partials 2042 2047 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Capstone of the cross-OS USB consistency arc (follows #3447 Windows, #3448 Linux, #3449 Mac). Every platform's USB class carried its own copy of the same recursive controller/hub tree assembly — apply the parent's vendor/product IDs as defaults, recurse children through a parent→children map, sort by name, and fall back to
"vid:pid"when a device reports no name. This hoists that single algorithm intoAbstractUsbDevice, so the per-OS code is reduced to what genuinely differs: how each OS enumerates devices.Producer / consumer split
AbstractUsbDevice.buildDeviceTree(id, vid, pid, nameMap, vendorMap, vendorIdMap, productIdMap, serialMap, hubMap, factory)— the one recursive builder — plus a nestedUsbDeviceFactoryfunctional interface so each platform still constructs its ownUsbDevicetype.getDeviceAndChildrenand callbuildDeviceTree(..., XxxUsbDevice::new). Each keeps its own platform-specific map building (udev /usbdevs/lshal/prtconf/ IOKit) — the legitimately-different producer.Longto the"0x"-prefixed hex form it already used asuniqueDeviceId— behavior-identical.Deliberately excluded (documented in-code)
lscfg; no parent/child tree exists to assemble.Result
getDeviceAndChildrengoes from 5 copies to 1; net −79 lines across 10 files. The producer differs per OS (inherent); the tree-building consumer is now single-source.Behavior
No user-facing change. The tree-builder unit tests move from
LinuxUsbDeviceTestintoAbstractUsbDeviceTest, now exercisingbuildDeviceTreedirectly.NativeComparisonTest.usbDevices()(JNA vs FFM recursive deep-equal) passes on macOS/Apple Silicon.Testing
install: BUILD SUCCESS, 0 tests failedNativeComparisonTest.usbDevices()(JNA vs FFM): passesSummary by CodeRabbit
Bug Fixes
Tests