Hi,
When building the FS image, files are collected from the data/ directory.
But I’m building some of them before building the filesystem itself (templating, HTML, CSS etc) and I would like to exclude “source” files from the FS build.
I tried adding src_filter = -<*.slim> in my platformio.ini for .slim files are still added.
This only affects C/C++/ASM source files for the firmware, not the filesystem. PlatformIO has no filter option for the filesystem build. Every file that is in the data/ directory (or more generally $PROJECT_DATA_DIR) at the point the DataToBin builder is executed will be included in the filesystem. See source and source.
or, use advanced scripting and a Pre action to the littefs.bin / spiffs.bin build in which you move all non-wanted files out of the data/ directory before the conversion is done, and back in after the conversion is done (Post action). See documentation.
I had the same requirement today and asked GPT4, which imagined the concept of a .pioignore file for the purpose, along with fancy regex support as well. Pointing out that this wouldn’t work it suggested a filter (Max’s option 2), and while its implementation was rather faulty and as it turns out doomed to failure, a script can still help.
It seems that a pre buildfs hook fires after the .bin file has been built, at least for LittleFS, so as there doesn’t seem to a suitable hook for the purpose, simply setup the data directory in a top level script. This will fire unnecessarily, but also when needed, which might be good enough. So an example would be to add extra_scripts = filter_data.py to the platformio.ini file, with a script along these lines:
Import('env')
import os
import time
from shutil import copytree, ignore_patterns
data_master_dir = 'data_master'
data_dir = 'data'
print("Prepare data directory")
if os.path.exists(data_dir):
bakid = int(time.time())
os.rename(data_dir, data_dir + "." + str(bakid))
copytree(data_master_dir, data_dir, ignore=ignore_patterns('workfiles', '*~'))
This opts to rename the existing data directory rather than remove it, but removing should be safe and would avoid debris building up.