modm-io / lbuild

lbuild: a generic, modular code generator in Python 3
https://pypi.org/project/lbuild
BSD 2-Clause "Simplified" License
37 stars 12 forks source link

Example or documentation to create a lbuild repo missing #44

Open rleh opened 5 years ago

rleh commented 5 years ago

What do I have to do to create a (minimal) lbuild repo?

What is recommended or is best-practise to structure the modules and sub-modules like?

How do use this new repo in a lbuild project or how can I add a dependency to another lbuild repo?

salkinium commented 5 years ago

What do I have to do to create a (minimal) lbuild repo?

You can create a repo.lb file which defines the three functions: init(repo), prepare(repo, options) and optionally build(env). For API features see: https://github.com/modm-io/lbuild#repositories Note that you need to explicitly add the module files, either manually via file path, or in batches via globbing.

What is recommended or is best-practise to structure the modules and sub-modules like?

Probably the easiest is to follow your existing folder structure, which may already somewhat grouped together, so there is a natual modularity in that. However, the lbuild module tree is completely independent from the file system, and you can use this to present a logical view of the repository, rather than the file system view, which was probably chosen for build system reasons (include paths) or even legal reasons (like keeping all third party code in ext/). https://github.com/modm-io/lbuild#modules

How do use this new repo in a lbuild project

You have to specify where the new repo.lb file is as the localpath from your project.xml:

<library>
  <repositories>
    <!-- Declare all your repository locations relative to this file here -->
    <repository><path>path/to/repo.lb</path></repository>
    <repository><path>path/to/repo2.lb</path></repository>
  </repositories>
</library>

If you want to use this repository from a lot of projects, you probably want to declare this repository path in a common lbuild.xml (like modm/examples/lbuild.xml). https://github.com/modm-io/lbuild#configuration

how can I add a dependency to another lbuild repo?

You can depend on a module of any repository via module.depends("repo:module"). Note that there is no way for a repository (ie. repo.lb) to depend on another repository. That's something I'm still trying to find a solution for (ie. lbuild doesn't do versioning right now, but inter-repository dependency would require that.)

salkinium commented 5 years ago

For a real-world example, the https://github.com/modm-io/Invensense-eMD/ repo does all these things and also uses the modm:build collectors to declare how to build it's own library using the modm build system.

salkinium commented 5 years ago

Note that you can also programmatically create submodules, so that you do not have to spam your repo with module.lb files.