forked from platformio/platformio-core
Speeded up device port finder by avoiding loading board HWIDs from development platforms
This commit is contained in:
@ -16,6 +16,7 @@ PlatformIO Core 6
|
|||||||
6.1.5 (2022-??-??)
|
6.1.5 (2022-??-??)
|
||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Speeded up device port finder by avoiding loading board HWIDs from development platforms
|
||||||
* Improved caching of build metadata in debug mode
|
* Improved caching of build metadata in debug mode
|
||||||
|
|
||||||
6.1.4 (2022-08-12)
|
6.1.4 (2022-08-12)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import serial
|
import serial
|
||||||
@ -119,6 +120,8 @@ class SerialPortFinder:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def match_device_hwid(patterns):
|
def match_device_hwid(patterns):
|
||||||
|
if not patterns:
|
||||||
|
return None
|
||||||
for item in list_serial_ports(as_objects=True):
|
for item in list_serial_ports(as_objects=True):
|
||||||
if not item.vid or not item.pid:
|
if not item.vid or not item.pid:
|
||||||
continue
|
continue
|
||||||
@ -215,20 +218,27 @@ class SerialPortFinder:
|
|||||||
if os.path.isfile(udev_rules_path):
|
if os.path.isfile(udev_rules_path):
|
||||||
hwids.extend(parse_udev_rules_hwids(udev_rules_path))
|
hwids.extend(parse_udev_rules_hwids(udev_rules_path))
|
||||||
|
|
||||||
# load from installed dev-platforms
|
@lru_cache(maxsize=1)
|
||||||
for platform in PlatformPackageManager().get_installed():
|
def _fetch_hwids_from_platforms():
|
||||||
p = PlatformFactory.new(platform)
|
"""load from installed dev-platforms"""
|
||||||
for board_config in p.get_boards().values():
|
result = []
|
||||||
for board_hwid in board_config.get("build.hwids", []):
|
print(result)
|
||||||
board_hwid = self.normalize_board_hwid(board_hwid)
|
for platform in PlatformPackageManager().get_installed():
|
||||||
if board_hwid not in hwids:
|
p = PlatformFactory.new(platform)
|
||||||
hwids.append(board_hwid)
|
for board_config in p.get_boards().values():
|
||||||
|
for board_hwid in board_config.get("build.hwids", []):
|
||||||
|
board_hwid = self.normalize_board_hwid(board_hwid)
|
||||||
|
if board_hwid not in hwids:
|
||||||
|
result.append(board_hwid)
|
||||||
|
return result
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
@retry(timeout=self.timeout)
|
@retry(timeout=self.timeout)
|
||||||
def wrapper():
|
def wrapper():
|
||||||
device = self.match_device_hwid(hwids)
|
device = self.match_device_hwid(hwids)
|
||||||
|
if not device:
|
||||||
|
device = self.match_device_hwid(_fetch_hwids_from_platforms())
|
||||||
if device:
|
if device:
|
||||||
return device
|
return device
|
||||||
raise retry.RetryNextException()
|
raise retry.RetryNextException()
|
||||||
|
Reference in New Issue
Block a user