Storing PlatformIO directory in Dropbox

I wanted to share something that might be helpful to others.

The Problem:

I’ve always kept my PlatformIO directory in Dropbox so that my project files are accessible between different computers (e.g. work and home). However, there are a couple of problems this imposes:

  1. For VSCode users, files inside the .vscode directory can contain host-specific information, such as paths to includes, compilers, and other resources.

    If you use different operating systems on computers where you use PlatformIO, or even the same OS but with different usernames or different architectures, these paths won’t match. This will break compiling and/or confuse IntelliSense.

  2. It seems that the constant syncing of files in .pio/build during a build can cause IntelliSense to freeze up.

    You can tell this has happened when VSCode underlines parts of your code and reports those as having errors that aren’t true (or don’t make sense), or when certain actions (like “Go to Definition”, “Go to Declaration”, “Find All References”, etc.) can’t find the file.

    Restarting VSCode (or running the “Reload Window” action) resolves this condition.

Of course, PlatformIO and VSCode never intended for us to store our project files in this manner, so these behaviors aren’t their fault. But keeping projects sync’d across computers seems like it’d be a popular requirement, so…

The Solution:

I created a simple Python script that you add as a PRE to the extra_scripts option in platformio.ini, which will set extended file attributes on the .vscode and .pio/build directories, causing the Dropbox client to ignore them (they’ll be local-only and not be sync’d). It works on Windows, MacOS, and Linux, and has no external dependencies.

See the Gist on GitHub: MaffooClock/

I’m no expert on the inner-workings of PlatformIO, but for me, this has resolved these two issues perfectly. If there are any flaws with this, or anything I’m overlooking, well… let the discussion begin!

More about the script

Originally, I just used the command-line to set those extended attributes according to Dropbox documentation, thinking it’d be a one-time thing. Nope – when building, PlatformIO (or something in the toolchain?) can sometimes trash the .pio/build directory and re-create it, so those extended attributes are gone. Adding this as a pre-action script guarantees those extended attributes are always set, and thus, those directories are never sync’d.

Applying the extended attributes to the .vscode directory is only ever needed once, so re-applying them every time we build isn’t necessary, but it doesn’t hurt anything.

1 Like