Cannot build or upload project after cloning from Github?

When using Github for version control and backup, I added almost all automatically generated CLion configuration files to the git ignore list. The only project directories I’ve added to the repo are lib, src, CMakeLists.txt and PlatformIO.ini. I figured doing this would reduce the clutter of the project’s file structure and make it easier to clone or pull from.

While doing this, I deleted the local project configuration and build files from my hard drive after I had performed an initial push to a new repository. At first I thought this was no problem-- I can just go to Tools->PlatformIO->Re-Init. PlatformIO will auto-generate the needed files for me and fix the problem. This is the case but with some caveats.

I can right click Platformio.ini in my project and build my project just fine from there. However, Clion is still complaining that all my scripts are not part of my opened project and code syntax highlighting may be disabled, when in reality it is working just fine. Despite re-initializing the project, checking for updates, restarting the program, running in admin mode-- I cannot get rid of this prompt and it is driving me crazy. Additionally, it seems as though the configuration files for debug and upload are broken. They are greyed out and I can no longer upload to the board or run the debugger. Again-- I can build the project successfully without a problem. This just seems to be an issue with PlatformIO’s configuration and the IDE’s configuration not communicating properly.

I created a new Arduino project from the PlatformIO project menu to see if I could compare the configuration files side by side and detect any major differences. They were the exact same, with the exception of the project name (since the new dummy comparitor project had to have a different folder name of course). The new project allows me to run the build/upload configurations just fine, so I am deeply confused how to fix this issue or implement syncing code across development environments (such as from desktop to laptop) when using Github.

What is going on here? How does Clion run the build or upload configurations and how are they linked to PlatformIO and it’s files?

My project/repository in question can be found here

After you have re-initiliazed the project to give you new correct CMakeLists.txt files, did you do a right-click on the project in the project explorer and “Reload CMake Project”?

I’ve tried clicking “Reload from disk”. I do not see explicitly “Reload CMake Project”, however I have the automatically update CMakelists feature enabled in Clion so it is not something I should have to do.

I just went into the settings menu and double checked too. So deleting a single character in the .txt configuration file and typing it back in should automatically reload it. It seems to make no difference at all.

I noticed that when re-initializing, there is no “reload Cmake” option like there is when starting a new project.

Additionally, if you go to the top right where the configurations drop down menu is you can see that after re initializing the platformIO project, the generated configurations are targeting “Debug” as an environment instead of “uno” like a new project would. Debug and Production should not exist.

Adding PlatformIO’s version of “Upload” or “Debug” from the templated configurations does not seem to fix or resolve this issue either.

Clion seems to auto-generate a hidden folder to the project directory called .idea it is there where a series of XML files can be found. I believe these are the files that tell Clion how the project’s Cmake/Make configs should be setup. workspace.xml I would assume to be the culprit.

This seems to happen only when I clone the repository. The issue does not happen if I were to create a new project and copy the lib include src and test folders into it. Additionally, I can copy and paste my older platformio.ini config file to the new project and then re-init everything without any issues at all.

This is so bizzare. Why does this happen? I need to know otherwise version control and backup through git is impossible.

screenshot

To follow up on my last post, I was indeed correct. In the .idea folder (auto-generated by Clion), the workstation.xml file has a component tag named Cmakesettings which generates a profile and configuration name that does not target any valid environment:

When pulling from Github (/.idea/ not included in repository and is auto-generated):

<component name="CMakeSettings">
<configurations>
  <configuration PROFILE_NAME="debug" CONFIG_NAME="debug" />
</configurations>

Example of /.idea/ from a new platformIO project:

<component name="CMakeSettings">
<configurations>
  <configuration PROFILE_NAME="uno" CONFIG_NAME="uno" />
</configurations>

Changing that one line of code in this file solved the entire issue, but it doesn’t neccessarily mean the problem is solved. PlatformIO should be checking for this when doing the Re-Init action, but it seems to skip this check. I am not sure if this is a bug or intentional by design.

How can I get this checked by someone by the pluggin’s development team?

After further investigation and reproducing the error on my secondary laptop computer. I kind of figured it out. The issue has to do with Clion auto-selecting a Cmake build profile that is invalid and should not exist for a given PlatformIO project type.

When pulling or cloning a platformIO project from a repository and re-initializing it from the Tools pane window, PlatformIO will generate a Cmake Build Profile which is used to target different configurations upon deployment. By default when opening a project, the Clion IDE does not know that the project is of a PlatformIO type, so it will auto-generate a Cmake build-profile suitable for C++ application development instead (ie labeled ‘debug’).

Re-initializing in Platformio will only generate the Cmake Build Profiles for the environments you have defined in the platformio.ini configuration file. In my case I have 2 different micro-controller boards I have been testing code on: an Arduino Uno and Arduino Nano. I can specify these two environments like so in the .ini file:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps = 
	mike-matera/ArduinoSTL@^1.1.0
	https://github.com/mpflaga/Arduino-MemoryFree.git
monitor_port = COM[6]
monitor_speed = 115200

[env:nano]
platform = atmelavr
board = nanoatmega328
framework = arduino
lib_deps = 
	mike-matera/ArduinoSTL@^1.1.0
	https://github.com/mpflaga/Arduino-MemoryFree.git
	smfsw/Queue@^1.9
monitor_port = COM[6]
monitor_speed = 115200

After re-initializing the project, in the Cmake build settings menu I can now select these two separate environments as corresponding Cmake build profiles which can be seen in the screenshot below.

It’s worth mentioning that you can add multiple environments through this settings window using the + or - buttons on the left hand column, which will allow hot-swapable switching between physical Arduino boards without the need to re-open the settings menu frequently. After selecting one of the Cmake build profiles and closing the menu, the ‘debug’ option will dispensary completely-- even if you were to re-open the profiles menu again. But before this issue is fixed entirely, you still to re-setup the target configuration types.

In the upper right hand corner you can select the configurations menu via a drop down bar. To change them, click it and go to ‘edit configurations’. A new prompt window will open. On the left hand toolbar labeled ‘Templates’, find PlatformIO and choose the appropriate configuration. Most common are ‘Upload’ ‘Test’ and ‘Debug’. Then select ‘Create configuration’ and close the window.

Now when we go to the drop down menu bar in the upper right corner, we can select not only the Arduino board and environment we want to use, but we can also choose what deployment configuration type such as “Upload” or “Debug” like we could in a brand new PlatformIO project.

I’m not sure if the cause of this issue is from the pluggin itself or just an inherent behavior of the IDE. I haven’t confirmed this yet but a workaround to this issue might be to just include the hidden /.idea/ directory in the project whenever committing to a Github repository, since that seems to be where Cmake build profiles are defined (workstation.xml). However, it would add extra redundant files and clutter to other users/developers pulling from a repo if using a different IDE.

I would be surprised if this issue could not be patched. All the PlatformIO developers would need to do is implement a check to remove any invalid build profiles for the project that weren’t a valid environment defined in the platformio.ini configuration file. Maybe that check already exists but isn’t functioning correctly. I’m not super involved in the pluggin’s development and after finding the cause and solution to my issue, I’m not sure how much more time I’ll spend on it anyway.