Repository navigation
Description
Configuration
Operating system: Windows 11
PlatformIO Version (platformio --version): PlatformIO Core, version 6.2.0
(the code in question is identical on develop, 6.2.1b2)
Description of the problem
When the project environment is "Default" (no forced environment), the
generated PIO Debug entries in .vscode/launch.json take projectEnvName
from one environment and executable / preLaunchTask from another.
In platformio/project/integration/tpls/vscode/.vscode/launch.json.tpl:
"executable": _escape_path(prog_path),
"projectEnvName": env_name if forced_env_name else default_debug_env_name,
...
"task": ("Pre-Debug (%s)" % env_name) if len(config.envs()) > 1 and forced_env_name else "Pre-Debug",
Without a forced environment the two names come from two different rules:
env_name(used forprog_path,cc_path, i.e.executableand
toolchainBinDir) isProjectGenerator.get_best_envname(), which returns
default_envs[0].default_debug_env_name(used forprojectEnvName) is
get_default_debug_env()inplatformio/debug/helpers.py, which prefers
any environment withbuild_type = debug, even if it is not in
default_envs.
If these two are different environments, the entry is inconsistent:
projectEnvName names environment A while executable points into the build
folder of environment B. As far as I can see in the debug adapter
(platformio-vscode-debug), it starts platformio debug -e <projectEnvName>
and reads symbols from executable, so the two would not belong together. I
have not run a debug session on this; the report is about the generated
file.
Preferring a build_type = debug environment for debugging looks
intentional, so I am not asking to change that rule. The two fields just
should not come from different environments.
Steps to Reproduce
Minimal project, platformio.ini:
[platformio]
default_envs = hardware
[env]
platform = espressif32
framework = arduino
board = esp32-s3-devkitc-1
; first environment in the file, the only one with build_type = debug
[env:simulation]
build_type = debug
; selected by default_envs
[env:hardware]plus src/main.cpp with an empty setup() / loop().
pio project init --ide vscode- Open
.vscode/launch.json.
(In VS Code with the PlatformIO IDE extension the entries are regenerated on
reload and whenever the status-bar environment picker changes. In a real
project with this layout, forcing an environment there made both fields
agree, see the table below.)
Actual Results
All three generated entries (PIO Debug, PIO Debug (skip Pre-Debug),
PIO Debug (without uploading)) contain:
"projectEnvName": "simulation",
"executable": "C:/path/to/repro/.pio/build/hardware/firmware.elf",
"toolchainBinDir": "C:/Users/<user>/.platformio/packages/toolchain-xtensa-esp32s3/bin"and PIO Debug has "task": "Pre-Debug". Checked directly with the core
API on the same project: get_default_debug_env(config) returns
simulation, ProjectGenerator(config, None, "vscode").env_name returns
hardware.
Forcing an environment (status-bar picker in VS Code) gives consistent
entries each time:
| Selection | projectEnvName |
executable |
task |
|---|---|---|---|
| Default | simulation |
.../build/hardware/firmware.elf |
Pre-Debug |
env:hardware |
hardware |
.../build/hardware/firmware.elf |
Pre-Debug (hardware) |
env:simulation |
simulation |
.../build/simulation/firmware.elf |
Pre-Debug (simulation) |
(The last two rows were observed in a real project with the same layout,
the first row in the minimal one above.)
Expected Results
For the Default selection, projectEnvName, executable, toolchainBinDir
and the pre-debug task refer to the same environment. Either choice would
do, for example deriving executable and toolchainBinDir from
default_debug_env_name, or the other way round.
Additional info
Context: I work on a Windows desktop and take a MacBook to the customer, so
one repository with a committed .vscode/launch.json is used on both. The
file also holds our own launch entries (kept intact since #3824), so it
cannot simply be left out of version control; the regenerated PlatformIO
entries are the only part that changes between machines and environment
selections. I am not asking to stop the regeneration, only for consistent
entries. The portable-path side of this is the long-open
platformio-vscode-ide#1469, where I am adding our use case.
Related earlier reports about the debugger and the selected environment:
#4098 and #4597 (both closed). This report is narrower: it concerns the
generated file under the Default selection, with the code locations above.
Activity