Issue with circular dependencies

Hey all,

I’m having an issue with circular dependencies and I think it links back to the print dependency tree function. Basically I have an open source project (I’d rather not have to mess with all of the includes) with circular dependencies (it’s made for the arduino IDE which doesn’t mind circles) and when I go to compile with pio it fails. I have flags set for the compiler to ignore circular dependencies but I don’t think the dependency tree function works with circular functions. It gets “RuntimeError: maximum recursion depth exceeded”. Now I’m no python guy, but it sounds like the recursive loop is not safed against circles. I’m guessing that as it’s going through this, it’s putting all of the libraries it finds on a list, do you think we could reference that list in the loop to make sure it doesn’t follow circles?

Anyways. let me know your thoughts.

-Lyle

After some more poking and prodding with the miniscule amount of python I know I found it’s a problem with how BuildDependentLibraries() in /builder/tools/piolab.py handles circles. I don’t know enough python to get past that point but hopefully that’s enough to find the problem.

-Lyle

“Circular dependencies” indicate about bad project architecture/structure. If you use Python, you will receive the same runtime error when you will import module “B” from module “A”, where module “B” imports module “A”.

Please review your code and remove circular dependencies. Otherwise, if you don’t want to refactor your project, please turn-off PaltformIO Library Dependency Finder Library Dependency Finder (LDF) — PlatformIO v6.1 documentation

[env:myenv]
platform =..
board = ..
lib_ldf_mode = 0

I kinda figured I would get an answer like that. I’m well aware that it’s a terrible way to structure code but I’m trying to import Marlin, a very popular open source 3D printer firmware and it seems off that pio can’t import something like that without major refactoring/restructuring.

I’m not terribly good at python as I said before, but there are people on my team who are. How much work do you think it would take to fix something like that? We are looking into using platformIO as a part of our toolchain for embedded development while we work on our test fixtures. If all goes well on that end, we were considering using it as we move into production, but that hinges on it actually working. Of course eventually we will restructure the code, but for now it is stock marlin.

Anyways, I’ve turned off the library dependency finder for now, but I think that is causing some other problems during compilation about not being able to find certain libraries. These are libraries that are in the correct file structure within lib are not found unless I move them into the same folder as the library that included them initially.

Do you mean that standard Marlin’s code doesn’t work? They use PlatformIO for a long time. Could you point me to the repo/source code where I can reproduce this issue?

Just need to fix a few #include <> that depend each other.

Now, you are in manual mode. Please specify project dependencies manually using lib_deps

Well, marlin works if you stick it all in the src folder but going back to the proper code structure thing that’s terrible. When I took the same code but split it into individual, properly structured library folders in lib I got the circular dependencies. We’d like to stick close to stock right now because the main marlin branch is implementing new features faster than we are, so integrating those in is easier if we stay true to marlin.

I don’t see any problems. I understand that you don’t want to share here your code (it’s normal!). Please Contact Us and we are ready to help you. PlatformIO is a right choice for your project. Also, Unit Testing will allow you to pass tests on a real hardware.