Build filesystem image: exclude files from buildfs

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.

Any clue on how to have a “.buildignore”-like ?

Thank you

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.

Which means that either

  1. file a feature request in Issues · platformio/platform-espressif32 · GitHub
  2. 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.

Thank you for your quick reply @maxgerhardt !

Two options for my situation:

  1. put my files in src/data and, at build-time, rsync files with an include/exclude filter to data/ which is being built and shipped
  2. permanent files stay in data/ and build-time files are cleaned up before each build, and build again from src/data to data/

Hope this helps anyone else

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 = to the platformio.ini file, with a script along these lines:

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.