tobozo / M5Stack-SD-Updater

💾 Customizable menu system for M5Stack, M5Unified and ESP32-Chimera-Core - loads apps from the Micro SD card. Easily add you own apps
MIT License
309 stars 41 forks source link

__has_include breaks under some conditions #179

Closed GOB52 closed 1 year ago

GOB52 commented 1 year ago

M5StackUpdater.hpp

#if ! SDU_HAS_FS
  #define SDU_HAS_SD
  #if defined USE_SDFATFS
    #pragma message "SDUpdater will use SdFat"
    #undef __has_include <======================= !!!
    #include <misc/sdfat32fs_wrapper.h>
    #define __has_include <======================= !!!
    #define SDU_SD_BEGIN SDU_SDFatBegin

If the above part has been compiled, A compile error occurs at subsequent __has_include.

#include <M5StackUpdater.h>
#if __has_include(<foo.hpp>) <==  error: operator '<' has no left operand
#endif
tobozo commented 1 year ago

there may be a fix in 1.2.5, it's addressing a similar issue, however the fix is only for an error with ESP32-targz when gzip is enabled and SdFat is used.

the workaround is to evaluate the __has_include earlier in the flow:

#if __has_include(<foo.hpp>)
  #define HAS_FOO
#endif
#include <M5StackUpdater.h>

#if defined HAS_FOO
  // foo specific code
#endif 

I'm aware it isn't a satisfying solution and still researching, any suggestion is welcome.

GOB52 commented 1 year ago

This workaround is not a panacea, but it is one solution.

Hopefully 1.2.5 will be a smarter solution.

tobozo commented 1 year ago

SdFsFileImpl is the closest thing I could find, and it came with the infamous #undef __has_include, so maybe it's just optional?

Arduino IDE doesn't seem to complain when I do this, but I suspect platformio will not:

    //#undef __has_include
    #include <FS.h>
    #include <FSImpl.h>
    #include <SdFat.h>
    //#define __has_include

the smarter solution is probably to create some kind of lgfx::DataWrapper for SdFs, but it is beyond my skills.

GOB52 commented 1 year ago

I know it's risky, but how about this approach?

#undef __has_include
#include <misc/sdfat32fs_wrapper.h>
#define __has_include(STR)  __has_include__(STR)

__hasinclude is defined by \_hasinclude_\

tobozo commented 1 year ago

looks like platformio doesn't care when the infamous #undef __has_include is removed :thinking: so I may remove it completely?

https://github.com/tobozo/M5Stack-SD-Updater/actions/runs/4863851743