Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-detect dependencies between libraries [imported] #236

Closed
cmaglie opened this issue Nov 15, 2012 · 6 comments
Closed

Auto-detect dependencies between libraries [imported] #236

cmaglie opened this issue Nov 15, 2012 · 6 comments
Assignees
Labels
Component: Compilation Related to compilation of Arduino sketches
Milestone

Comments

@cmaglie
Copy link
Member

cmaglie commented Nov 15, 2012

This is Issue 236 moved from a Google Code project.
Added by 2010-04-29T16:16:24.000Z by follower@gmail.com.
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Enhancement, Priority-Medium, Component-IDE

Original description

What change would like to see?

Enable libraries to include other libraries

Why?

AFAIK at present it's not possible for one library to include another library. This makes it difficult
to have, for example, a SPI device with a library that includes a generic SPI communication
library--the SPI library currently needs to be included in the same folder as the device library.

Would this cause any incompatibilities with previous versions? If so, how
can these be mitigated?

It shouldn't.

(I'm reasonably certain this enhancement has been discussed before but I couldn't find an
existing issue for it.)

@ffissore ffissore added the New label Feb 27, 2014
matthijskooijman added a commit to matthijskooijman/Arduino that referenced this issue Jul 10, 2014
Previously, any libraries #included by the sketch were added to the
include path and link, but any libraries included by other libraries
were not. This meant that all libraries used, even indirectly by other
libraries, must be explicitely included in the sketch.

This commit changes the dependency resolution to become recursive - it
also includes the libraries included by other libraries in the build.

This commit is based on code by Christian Maglie and fixes arduino#236.
@martinjos
Copy link
Contributor

Is this still not fixed? I have seen things like "library.json" (e.g. in i2cdevlib) that seem to describe the dependencies, but they do not seem to be used by the Arduino IDE.

I have read the comments on the Google Code issue, particularly the objections about users being unaware of what libraries are drawn in by a given include file.

It has occurred to me that a tree of includes could be shown within the file, like this (greyed out and non-editable, and not saved to file, except the first line):

[-] #include <header1.h>
| [-] #include <header2.h> // from directory2, included by <header1.h>
| |--- #include <header3.h> // from directory3, included by <header2.h>
|--- #include <header4.h> // from directory4, included by <header1.h>

The comments help you to see what includes what, and the plus/minus signs allow you to fold the section up. Perhaps just the one plus/minus sign at the top would be necessary.

@PaulStoffregen
Copy link
Sponsor Contributor

I worked on this many years ago, when the IDE code was simpler, and had a solution. But the main problem here is not coding, it's a matter of being able to make a decision. So far, there have been numerous discussions, but nobody like David or Cristian has managed to make the final decision.

Without an authoritative decision from Cristian, I'm afraid this is never going to happen.

@martinjos
Copy link
Contributor

But that is why I am making this suggestion. From looking at the old comments, it seems that the main thing that was preventing people from making a decision was the concern that users would not be aware of what was going on behind the scenes. My solution ensures that users will always be aware what libraries are being used, even if they did not explicitly include them. It also protects the user from accidentally deleting any necessary includes (because all but the top line of the tree is not editable, and in any case, it is only a representation of the includes that are present within the header files themselves).

The only question that remains is how to differentiate between different libraries that contain header files with the same names. I would suggest that libraries are required to contain something like #include ARDUINO_LIB <directory1/header1.h>. The angle brackets indicate that the include is external (as usual in C/++), while the macro ARDUINO_LIB (which expands to the empty string) indicates that the Arduino IDE should treat it specially by looking for (compiling, adding to the link path, linking) a library named "directory1". There are no backward compatibility issues with this, as existing libraries cannot include from other libraries anyway. Note that the include search path need only be extended with the "libraries" directories.

I appreciate the previous comments about using the compiler toolchain to traverse the header tree, but unfortunately with traditional C compilers (such as GCC) this is generally prohibitively difficult, and if there is a desire to support multiple toolchains it would mean having to support each one. Until somebody decides to move the Arduino project permanently over to LLVM (which would make this relatively easy, albeit still tied to one toolchain), I would propose to simply extend the existing dependency detection code, which seems to work well enough.

@PaulStoffregen
Copy link
Sponsor Contributor

seems that the main thing that was preventing people from making a decision was the concern that users would not be aware of what was going on behind the scenes

That was David Mellis, many years ago. By the time he changed his mind, I had moved to a hardware project...

Since then, more discussion happened at least a couple times on the developers mail list. I believe it also ended with indecision, specifically about whether to parse for #include lines, or perhaps get the dependency info from meta data files.

The theme is the same though, ongoing indecision.

@matthijskooijman
Copy link
Collaborator

Note that dependency autodetection was implemented in #2174. That PR is probably outdated by now, but I can updated if autodetection is decided to be the way forward.

@ffissore
Copy link
Contributor

ffissore commented Oct 2, 2015

Fixed with 9fadb54, available with hourly builds http://www.arduino.cc/en/Main/Software#hourly

@ffissore ffissore closed this as completed Oct 2, 2015
@ffissore ffissore added the Component: Compilation Related to compilation of Arduino sketches label Oct 2, 2015
@ffissore ffissore added this to the Release 1.6.6 milestone Oct 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Compilation Related to compilation of Arduino sketches
Projects
None yet
Development

No branches or pull requests

5 participants