Skip to content

Fix matching of "components" dir when there's a symlink in the path to .platformio #1599

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

mhkrebs
Copy link

@mhkrebs mhkrebs commented Jun 8, 2025

compile_source_files() uses a relative path for the object if the source file is within the "components" tree. It checks the path string with .startswith(), though, and that can fail if the paths point to the same file but look different due to symlinks.

In my case, it saw two different source paths in "target-__idf_efuse-5f3f9f6e3513e0903efa.json":

  1. /space/home/user/.platformio/packages/framework-espidf/components/efuse/esp32c6/esp_efuse_fields.c
  2. /space/home/user/.platformio/packages/framework-espidf/components/efuse/src/esp_efuse_fields.c

But my home directory uses a symlink, so components_dir was:

  • /home/user/.platformio/packages/framework-espidf/components

This resulted in attempting to build the same object file for both:

*** Multiple ways to build the same target were specified for: /space/home/user/git/project/esphome/.esphome/build/device/.pioenvs/device/esp_efuse_fields.c.o  (from ['/space/home/user/.platformio/packages/framework-espidf/components/efuse/esp32c6/esp_efuse_fields.c'] and from ['/space/home/user/.platformio/packages/framework-espidf/components/efuse/src/esp_efuse_fields.c'])
File "/home/user/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 773, in compile_source_files

This fix simply resolves any symlinks in components_dir before using it for the comparison.

Fixes #515

…o .platformio

compile_source_files() uses a relative path for the object if the source file is within the "components" tree.  It checks the path string with .startswith(), though, and that can fail if the paths point to the same file but look different due to symlinks.

In my case, it saw two different source paths in target-__idf_efuse-5f3f9f6e3513e0903efa.json:
1. /space/home/user/.platformio/packages/framework-espidf/components/efuse/esp32c6/esp_efuse_fields.c
2. /space/home/user/.platformio/packages/framework-espidf/components/efuse/src/esp_efuse_fields.c

But my home directory uses a symlink, so components_dir was:
- /home/user/.platformio/packages/framework-espidf/components

This resulted in attempting to build the same object file for both:

*** Multiple ways to build the same target were specified for: /space/home/user/git/project/esphome/.esphome/build/device/.pioenvs/device/esp_efuse_fields.c.o  (from ['/space/home/user/.platformio/packages/framework-espidf/components/efuse/esp32c6/esp_efuse_fields.c'] and from ['/space/home/user/.platformio/packages/framework-espidf/components/efuse/src/esp_efuse_fields.c'])
File "/home/user/.platformio/platforms/espressif32/builder/frameworks/espidf.py", line 773, in compile_source_files

This fix simply resolves any symlinks in components_dir before using it for the comparison.
@valeros
Copy link
Member

valeros commented Jun 11, 2025

Hi @mhkrebs, thanks for the PR. Could you please provide instructions how to reproduce the issue?

@mhkrebs
Copy link
Author

mhkrebs commented Jun 17, 2025

In my case (and in this comment), the issue is that /home is a symlink. (I'm on Linux). I've seen others have the problem when ~/.platformio is a symlink.

To reproduce maybe try:

cd
mv .platformio temp
ln -s temp .platformio
cd esphome
esphome compile device.yaml

(BTW, I don't feel sentimental about this PR... I can believe there's a better fix for this.)

@Jason2866
Copy link
Contributor

Well the fix isn't a fix, it breaks Windows compile.

My original fix resolved links in `components_dir`, but apparently the source paths might not be resolved themselves (at least on Windows).  This fix simply resolves links in both before doing the comparison.
@mhkrebs
Copy link
Author

mhkrebs commented Jun 17, 2025

Alright, I updated the fix. Sorry about that. I was worried about that possibility, that the source paths might not be resolved themselves. (I'm guessing that's the issue on Windows.)

I don't have Windows, but with this updated fix it still fixes my issue on Linux. I don't know how to test for Windows, but it looks like the tests will automatically run for this PR? Although, like I implied, I'm fine if somebody wants to make a better fix for this... I just want to be able to compile ESPHome. :)

@brisk0 brisk0 mentioned this pull request Jun 28, 2025
13 tasks
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.

[esp-idf] Failed build because “Multiple ways to build the same target were specified…”
3 participants