2

currently, I'm working on an Embedded Project. At the moment, I have only a local git repository, as I'm the only developer. However, I'm thinking about making it OpenSource and move it to github (if a certain level of functionality is reached :-) ). So, I'm thinking a lot about making a good project structure, so other developers can join.

Well, at the moment, the project is a very easy setup.

I have a folder structure like:

/ (project root)
|-- .git
|-- documentation
|-- software
|      |
|      |-- subfolder_1
|      |       |
|      |       |-- someLib
|      |       |-- someOtherLib
|      |       
|      |-- subfolder_2
|
|-- hardware

You see, just a bunch of nested folders, with the .git folder in the project's root.

For the project, I need to develop a library, lets call it someLib (with the someLib folder in the "picture" above being empty at the moment, because I haven't started with the lib).

This lib will probably get very big. And, more important, it does not contain any features related to this specific project. I, or maybe even someone else, might use it in another project as well.

So, I think it's a good idea making the lib its own project. Then, I might use git submodule or subtree to "link" the lib into my project.

What's the problem now?

Well, when I move the lib into its own project I will have additional files. Developing the lib in the main project would be easy, but in its own project, I need additional testcode, makefile, a "main.c", and (because it's embedded) hardware drivers. Without this additional stuff, I cannot run/test the lib.

This would look like:

/ (someLib root)
|-- .git
|-- documentation
|-- makefile
|-- main.c
|-- hardwareDriver_1
|-- hardwareDriver_2
|-- someLib
       |
       |-- someLib.c
       |-- someLib.h

As you see, I don't want all this stuff in my main project.

So, when using the submodule or subtree approach, is there a way to exclude that stuff from being pulled into the main project?

Or, more important, how would you solve this?

I doubt I'm the first one who is facing this problem. Any good hints?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
lugge86
  • 255
  • 3
  • 11

2 Answers2

2

Then, I might use git submodule or subtree to "link" the lib into my project.

Rather than using submodules or subtrees, what about using this library as a library?

You could use this submodule to produce a .so, and have your main code use that package. Both projects (the library and the main one) files would then be completely decoupled, hence solving your issue.

gturri
  • 13,807
  • 9
  • 40
  • 57
0

I need additional testcode, makefile, a "main.c"

That sounds like another submodule, with:

  • a main parent repo for developping that library with:
    • a submodule for the lib sources (which can also be imported in your first project)
    • a submodule for the lib test-specific files

That parent repo is there to record which versions of the lib sources goes with with version of the lib test files/code.

Separating test code from actual code would help keeping the lib project more easily embedded into other projects.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Would I then have three "root projects", with main project and test_environment just have the third library project as a submodule? Or would the someLib project be embedded somewhere inside the someLib test environment? – lugge86 Aug 06 '14 at 08:29
  • @lugge86 in your original project, you would embed only the Lib sources. You would maintain a separate test project, with the same Lib sources, and the Lib test files. – VonC Aug 06 '14 at 08:57
  • Quote from your original post: "a submodule for the lib sources (which can also be imported in your first project)". Is this submodule realy part of the test project, or is this a real project on its own, loacted somewhere else and just being referenced via the "git submodul feature"? In other words, do I have 3 "root projects" or 2 (with one containing the lib development)? – lugge86 Aug 06 '14 at 09:03