Build_src_filter not working with .ino files

Hi,

I’m trying to build a project with build_src_filter in platformio.ini:

[env:example_1]
board = m5stack-core2
build_src_filter =
    -<**/*.*>
    +<./example_1/*.*>

This works fine for .cpp files, but not for .ino files.

How can I make build_src_filter work with .ino files?

The idea is to be able to quickly test examples intended for the Arduino IDE.

NB. I assume that the .ino files are valid .cpp files. No conversion is necessary.

I don’t think this will work with .ino files.

You have to convert the files to .cpp- See Convert Arduino file to C++ manually — PlatformIO latest documentation

It’s just adding #include <Arduino.h>
and create function declarations before setup() and loop()
and you’re done.

OK, I think it’s a bit strange that this isn’t possible, since PIO compiles .ino files without a problem when they’re at the root of src or if they’re called with #include from a .cpp file.

The real problem is that the idea makes no sense - at least I don’t see any. It doesn’t make sense to test the examples at all.

You can assume that the examples have already been tested and work perfectly.

The knowledge gained from this could make your other question obsolete.

I am currently working with M5Stack products and a lot of their examples do not compile.

Can you explain this in detail?
What do you hope to gain from an automated test?

Edit:
I think i begin to understand what you want to acheive.
Is it about testing examples which are included in libraries?

Here’s my case study:

I bought a bunch of sensors and development boards from M5Stack.

I was bewildered by the difficulty of finding working examples.

As the vast majority of examples are intended for Arduino IDE, I created a PIO project in which I copy all the examples I find in the include folder and create an environment for example in platformio.ini.

If the .ino files are not C++ valid, I correct them manually.

In some rare case, the files are .cpp. In this case, I use build_src_filter in platformio.ini.

For .ino files, I use a pre-compile time Python script that generates src/main.cpp based on the path provided.See my other question for details.

Eventually I’d even like to automate the generation of platformio.ini with a Python script.

The idea is to quickly find working examples.

I hope these explanations make things clearer.

Yes, now the situation is much clearer.

The “testing” you mentioned led me on the wrong track (Unit Testing)

If I understood you correctly, you are creating a single project. In this project there are several subfolders for the individual examples in the src folder. The platformio.ini then contains a separate environment for each example?

Like so

.
├── include
├── lib
├── src
│   ├── ExampleA
│   │   └── ExampleA.ino
│   ├── ExampleB
│   │   └── ExampleB.ino
│   └── ExampleC
│       └── ExampleC.ino
├── test
├── .gitignore
└── platformio.ini

With a platformio.ini like:

[env]
platform = ...
board = ...
framework = arduino

[env:ExampleA]
build_src_filter = -<*> +<ExampleA/**>

[env:ExampleB]
build_src_filter = -<*> +<ExampleB/**>

[env:ExampleC]
build_src_filter = -<*> +<ExampleC/**>

Then your extrascript must simply temporary rename the *.ino file to *.ino.cpp - That’s how PlatformIO processes *.ino files.

But you must ensure that the *.ino contains valid C / C++ source code.

1 Like

Ok, your heart-like shows, that I’m now on the correct track.

I don’t think it’s worth the effort of writing an extra script.
You have to convert the *.ino files into valid C / C++ manually anyway.
By doing this, you can rename the *.ino file to *.cpp (or *.ino.cpp if there is an existing *.cpp) in one go.