Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't switch target on v1.9.0 (VSC-1537) #1363

Open
1 task done
michaelboeding opened this issue Dec 12, 2024 · 22 comments · May be fixed by #1385
Open
1 task done

Can't switch target on v1.9.0 (VSC-1537) #1363

michaelboeding opened this issue Dec 12, 2024 · 22 comments · May be fixed by #1385
Assignees
Labels
bug-report Bug Report from users on Github (don't use this tag manually, its supposed to be used via the issue)

Comments

@michaelboeding
Copy link

OS

MacOS

Operating System version

15.1.1 (24B2091)

Visual Studio Code version

1.9.0

ESP-IDF version

5.3.1

Python version

3.8.7

Doctor command output

NA

Extension

No response

Description

Project will not switch back to esp32s3 after going to esp32 target. Downgraded to 1.8.1 and it worked.

Debug Message

NA

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@michaelboeding michaelboeding added the bug-report Bug Report from users on Github (don't use this tag manually, its supposed to be used via the issue) label Dec 12, 2024
@github-actions github-actions bot changed the title Can't switch target on v1.9.0 Can't switch target on v1.9.0 (VSC-1537) Dec 12, 2024
@brianignacio5
Copy link
Collaborator

How are you switching target? What steps are you doing ? If you select a new target from the status bar it should run the idf.py set-target esp32s3 on the background and the target shown would be updated in sdkconfig and the status bar.

If an error happened we need those doctor command output as requested in the issue template.

@atlex92
Copy link

atlex92 commented Dec 13, 2024

Can confirm this bug. If I run set target via button in status bar, let's say idf.py set-target esp32s3, then id does reconfigure and update sdkconfig for esp32s3, BUT env IDF_TARGET is not updated, and if I try to build the project, it will be written that esp32 is sert as IDF_TARGET, whille project is configured for esp32s3, this is a conflict, workaround is just to manually export IDF_TARGET=esp32s3 and then continue with idf.py build

@michaelboeding
Copy link
Author

How are you switching target? What steps are you doing ? If you select a new target from the status bar it should run the idf.py set-target esp32s3 on the background and the target shown would be updated in sdkconfig and the status bar.
If an error happened we need those doctor command output as requested in the issue template.

Hey @brianignacio5 I tried multiple switching via the terminal command directly and via the bottom bar option via the plugin. Both always reverted back to esp32 (I think because the bottom bar never changed). So not matter what I did even after removing old sdkconfig/build files it would always conflict and wouldn't let me build even if I did IDF_TARGET=esp32s3 @atlex92 .

The fix for me has just been to downgrade to the previous version.

@john30
Copy link

john30 commented Dec 15, 2024

same here, no way to change the target any more with that release, neither in idf terminal with "idf.py set-target ..." nor with the bottom bar.
misleading error reported from implicitly executed fullclean (does not matter if it was fullcleaned before or not) and the target stays on the default esp32

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Dec 16, 2024

Seems to me that the issue is that I think because the bottom bar never changed which means for some reason idf.py set-target is failing in your setup. IDF_TARGET is set in the extension build command by reading it from the sdkconfig file CONFIG_IDF_TARGET value.

Could you share the ESP-IDF: Doctor Commandoutput ? I need to understand what is the error in your setup because I can't reproduce it myself just from your comments.

  1. I open a blink example from ESP-IDF v5.3.1 which was originally set to esp32.
  2. I click the status bar esp32 and select esp32s3. Wait for target to be updated (progress bar is finished)
  3. I build the project with the status bar build project button.
  4. I can see that build/project_description has target: esp32s3 with toolchain and others pointing to esp32s3.

@atlex92 @john30 Please also share the troubleshooting information, as a I said, I can't reproduce the issue myself but it seems that idf.py set-target itself is failing and that's why is not changing the IDF_TARGET.

Troubleshooting section

@brianignacio5
Copy link
Collaborator

Do you try to build the project from IDF Terminal that you opened before changing the target ? The terminal IDF_TARGET would not be updated. Need to close and open a new terminal for IDF_TARGET changes to be seen.

@john30
Copy link

john30 commented Dec 16, 2024

thanks for looking into it @brianignacio5 . I think it is related to #1263 but didn't have time to look at it in depth.
just found out along the way to get it working again from a clean checkout of my project (without any vscode settings.json) that after setting idf.espIdfPath and idf.toolsPath on user level to the exact locations it works with 1.9.0 as well. proably because my env does not contain either IDF_PATH or IDF_TOOLS_PATH.
please note that i work on Windows with vscode server in WSL

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Dec 17, 2024

#1263 does indeed remove the idf.adapterTargetName that was used before and instead reads IDF_TARGET from sdkconfig. We have tested that it should work the same for extension commands. I haven't been able to reproduce the issue which makes me believe there is something specific happening in your setup, that is why I need to check the troubleshooting information as requested in the issue template.

You mention you are using WSL. This could be the issue. If you open any host project in WSL, the settings being used are still from the host (Windows) instead of the WSL settings. You can try to save WSL settings on the current project .vscode/settings.json to make sure it works properly.

@brianignacio5 brianignacio5 self-assigned this Dec 18, 2024
@MBWeno
Copy link

MBWeno commented Dec 19, 2024

My sdkconfig is not in the root of the workspace directory. When I put a dummy sdkconfig in the root with the single line containing the config_id_target set to the target I want it works.

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Dec 19, 2024

You could also try using the idf.sdkconfigFilePath in your <project-dir>/.vscode/settings.json to define the sdkconfig file path. @MBWeno

@MBWeno
Copy link

MBWeno commented Dec 19, 2024 via email

@john30
Copy link

john30 commented Dec 19, 2024

isn't this a chicken-egg issue? my impression when trying to get it working was that the target is reset to the default of esp32 whenever trying to change it via "idf.py set-target" or via the bottom bar action item. as it was impossible to be saved to a decent sdkconfig due to the errors reported, it wasn't able to save at all.
what was the idea of reming the targetName setting in the first place? wasn't that a good way of defining a default for a project?

@brianignacio5
Copy link
Collaborator

 the target is reset to the default of esp32 whenever trying to change it via "idf.py set-target" or via the bottom bar action item.

This is not true. This command should set the desired IDF_TARGET to currently defined sdkconfig file path.

The idf.adapterTargetName configuration setting was removed because it is duplicated, you can get it from sdkconfig file. If no sdkconfig file is defined, the default target is esp32.

If you don't provide any troubleshooting information, I can't see why running the idf.py set-target via bottom bar doesn't work. Alternatively, could you share an example project where this behavior is shown ? I can't reproduce the issue locally.

@michaelboeding
Copy link
Author

 the target is reset to the default of esp32 whenever trying to change it via "idf.py set-target" or via the bottom bar action item.

This is not true. This command should set the desired IDF_TARGET to currently defined sdkconfig file path.

The idf.adapterTargetName configuration setting was removed because it is duplicated, you can get it from sdkconfig file. If no sdkconfig file is defined, the default target is esp32.

If you don't provide any troubleshooting information, I can't see why running the idf.py set-target via bottom bar doesn't work. Alternatively, could you share an example project where this behavior is shown ? I can't reproduce the issue locally.

Hey @brianignacio5 I am currently traveling for the remainder of the week or I would have sent some debug over for this earlier - sorry about that. I should be back home in 2 days.

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Dec 20, 2024

No worries @michaelboeding whenever you can.

@john30
Copy link

john30 commented Dec 20, 2024

I've tried to get the issue on one of the example projets of esp-idf and it is easily reproducable whenever something in the build system is wrong, i.e. a part of the set-target fails. I've tested it with an invalid CMakeLists.txt in the main component (and I'm sure this can also be done for any other subcomponent) by using "INCLUDES_DIR" instead of the correct "INCLUDE_DIR".
With that precondition it is impossible to the set target. Plus, the error output gives no hint to where the problem comes from, as it tries a fullclean several times which always fails. consequently, there is no generated sdkconfig and the target stays at esp32

@brianignacio5
Copy link
Collaborator

@john30 Without the ESP-IDF: Doctor Command output, steps to reproduce and a example project you are using I can't reproduce the issue. Please share this information so I can work on a bug fix.

@john30
Copy link

john30 commented Dec 20, 2024

please find attached the report
report.txt

and this is the error message:

/usr/bin/cmake

/usr/bin/ninja

CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must

  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.


Adding "set-target"'s dependency "fullclean" to list of commands with default set of options.
Executing action: fullclean
Build directory '/home/john/x/build' not found. Nothing to clean.
Executing action: set-target
Set Target to: esp32c6, new sdkconfig will be created.
Running cmake in directory /home/john/x/build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DPYTHON=/home/john/.espressif/python_env/idf5.3_py3.8_env/bin/python -DESP_PLATFORM=1 -DIDF_TARGET=esp32c6 -DCCACHE_ENABLE=0 /home/john/x"...
-- The C compiler identification is GNU 9.4.0

-- The CXX compiler identification is GNU 9.4.0

-- Check for working C compiler: /usr/bin/cc

-- Check for working C compiler: /usr/bin/cc -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Detecting C compile features

-- Detecting C compile features - done

-- Check for working CXX compiler: /usr/bin/c++

-- Check for working CXX compiler: /usr/bin/c++ -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

-- Detecting CXX compile features

-- Detecting CXX compile features - done

-- Found Git: /usr/bin/git (found version "2.25.1") 

CMake Error at CMakeLists.txt:6 (projects):
  Unknown CMake command "projects".



-- Configuring incomplete, errors occurred!
See also "/home/john/x/build/CMakeFiles/CMakeOutput.log".

cmake failed with exit code 1, output of the command is in the /home/john/x/build/log/idf_py_stderr_output_16851 and /home/john/x/build/log/idf_py_stdout_output_16851

Failed to set target esp32c6: non zero exit code 2

CMake Warning (dev) in CMakeLists.txt:
  No project() command is present.  The top-level CMakeLists.txt file must
  contain a literal, direct call to the project() command.  Add a line of
  code such as

    project(ProjectName)

  near the top of the file, but after cmake_minimum_required().

  CMake is pretending there is a "project(Project)" command on the first
  line.
This warning is for project developers.  Use -Wno-dev to suppress it.

Adding "set-target"'s dependency "fullclean" to list of commands with default set of options.
Executing action: fullclean
Build directory '/home/john/x/build' not found. Nothing to clean.
Executing action: set-target
Set Target to: esp32c6, new sdkconfig will be created.
Running cmake in directory /home/john/x/build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DPYTHON=/home/john/.espressif/python_env/idf5.3_py3.8_env/bin/python -DESP_PLATFORM=1 -DIDF_TARGET=esp32c6 -DCCACHE_ENABLE=0 /home/john/x"...
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /usr/bin/git (found version "2.25.1") 
CMake Error at CMakeLists.txt:6 (projects):
  Unknown CMake command "projects".


-- Configuring incomplete, errors occurred!
See also "/home/john/x/build/CMakeFiles/CMakeOutput.log".
cmake failed with exit code 1, output of the command is in the /home/john/x/build/log/idf_py_stderr_output_16851 and /home/john/x/build/log/idf_py_stdout_output_16851
.
Directory '/home/john/x/build' doesn't seem to be a CMake build directory. Refusing to automatically delete files in this directory. Delete the directory manually to 'clean' it.

Adding "set-target"'s dependency "fullclean" to list of commands with default set of options.
Executing action: fullclean

Failed to set target esp32c6: non zero exit code 2

Directory '/home/john/x/build' doesn't seem to be a CMake build directory. Refusing to automatically delete files in this directory. Delete the directory manually to 'clean' it.
Adding "set-target"'s dependency "fullclean" to list of commands with default set of options.
Executing action: fullclean

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Dec 20, 2024

Well, the thing you are testing is literally the reason why the target is not updated. Because there is an issue in the build system the set-target command is not going to work, (set-target command uses the build system to generate sdkconfig) therefore sdkconfig is not updated and the target remains as esp32.

It seems that what you want is to override the IDF_TARGET regardless of using set-target command. For that case you can use the idf.cmakeCompilerArgs configuration setting and add IDF_TARGET there like this:

"idf.cmakeCompilerArgs": [
    "-G",
    "Ninja",
    "-DPYTHON_DEPS_CHECKED=1",
    "-DESP_PLATFORM=1",
    "-DIDF_TARGET=esp32"
  ]

But if I add the previous setting, the build command will return something like this:

 *  Executing task: /usr/local/bin/cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DESP_PLATFORM=1 -DIDF_TARGET=esp32 -B /Users/brian/workspace/test/blink/build -S /Users/brian/workspace/test/blink -DSDKCONFIG=/Users/brian/workspace/test/blink/sdkconfig 

CMake Error at /Users/brian/.espressif/v5.3.2/esp-idf/tools/cmake/targets.cmake:97 (message):
   IDF_TARGET 'esp32' in CMake cache does not match currently selected IDF_TARGET 'esp32c3'. To change the target, clear the build directory and sdkconfig file, and build the project again.
Call Stack (most recent call first):
  /Users/brian/.espressif/v5.3.2/esp-idf/tools/cmake/project.cmake:24 (__target_init)
  CMakeLists.txt:5 (include)

This is because the sdkconfig file and the build directory both need to be deleted before running the build command with -DIDF_TARGET-esp32. Now if you delete them, the build command will work.

The use of idf.cmakeCompilerArgs is to build the project. Based on your test case, the project will not build and therefore the target will not be set in your project anyway, so we go back to the need of a successful build to set the IDF_TARGET.

I hope this output explain why a successful set-target command is necessary to update the IDF_TARGET, regardless of a configuration setting that force a new target in the build system.

Let say instead you execute idf.py reconfigure but you set a IDF_TARGET environment variable

 *  Executing task: /Users/brian/.espressif/v5.3.2/tools/python/bin/python3 /Users/brian/.espressif/v5.3.2/esp-idf/tools/idf.py -B /Users/brian/workspace/test/blink/build -DSDKCONFIG=/Users/brian/workspace/test/blink/sdkconfig reconfigure 

Executing action: reconfigure
Project sdkconfig '/Users/brian/workspace/test/blink/sdkconfig' was generated for target 'esp32', but environment variable IDF_TARGET is set to 'esp32c3'. Run 'idf.py set-target esp32c3' to generate new sdkconfig file for target esp32c3.

@larryk3
Copy link

larryk3 commented Dec 22, 2024

I am also experiencing odd issues with switching the target. I have set my esp_idf_project_configuration.json to use a custom sdkconfigDefaults, sdkconfigFilePath, and buildDirectoryPath.

My configuration can be seen on this branch in my project - https://github.com/K3Engineering/dynamite-sampler-firmware/tree/add-multiple-configurations

I did the following:

  • Start with a clean repo
  • Change the esp target from esp32 to esp32s3 by clicking the button at the bottom of vscode
  • Open a terminal and run $Env:IDF_TARGET (this prints the env variable in powershell) - the result is esp32s3
  • Delete the newly created build directory (in my case it is build.debug, as defined in my esp_idf_project_configuration.json)
  • Open a terminal and run $Env:IDF_TARGET - the result is now esp32

After this point, if I try to build, it will build a esp32 target. And I have to switch targets again to make it work. So after every clean, my IDF_TARGET env variable is set back to esp32.

This was done on plugin version 1.9.0. I tried the same thing with 1.8.1 and it didn't have this bug! After cleaning the build directory and getting the IDF_TARGET, it would properly show esp32s3.

@brianignacio5
Copy link
Collaborator

brianignacio5 commented Dec 23, 2024

Your sdkconfigFilePath is defined inside the build directory, so when you delete the build directory the sdkconfig file is also gone and so is the target that was set.

@brianignacio5 brianignacio5 linked a pull request Dec 26, 2024 that will close this issue
5 tasks
@brianignacio5
Copy link
Collaborator

I think I come up with a fix that makes sense in #1385 by saving IDF_TARGET in idf.customExtraVars and use it when the value from sdkconfig if not available.

Please try this vsix installer.

You can test these changes by installing this VSIX by click menu View -> Command Palette..., type Install from VSIX and then select downloaded esp-idf-extension.vsix file to install the extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-report Bug Report from users on Github (don't use this tag manually, its supposed to be used via the issue)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants