[odb-users] Integrating ODB into an automake project

Boris Kolpackov boris at codesynthesis.com
Thu Jan 20 08:03:53 EST 2022

Per Edin <per.edin at sequence-point.se> writes:

> I'm using build2 for building my projects, but I think the same applies to
> whatever build system you're using.
> Don't "auto-generate" the files during build, instead, create a script that
> runs ODB on whatever files are required, then commit those files as part of
> the source tree. This allows others to build the project without requiring
> the ODB compiler unless they also have to modify the schema.
> In addition, ODB generates a changelog of the schema to enable migrations,
> this file needs to be committed as well, and could change as a result of
> simply building the project if ODB is run automatically.
> In conclusion, I would advise against auto-running ODB during builds. I did
> try and gave up on it.
> See https://git.build2.org/cgit/bdep/tree/bdep/odb.sh for an example (part
> of bdep, part of build2).

While the challenges you list are real, I don't believe a manually-run
script is a solution we should settle for(1). In fact, one of the main
reasons for build2's existence is proper support for auto-generated
source code and with the latest release we've come pretty far:




The only part that is still missing is the header dependency extraction
(which would be needed for the ODB compilation recipe to detect changes
in the included headers) and that is already implemented and coming in
the next release (we will also need to expose the -M* option family in
the ODB compiler).

We also have a solution to this problem:

> This allows others to build the project without requiring the ODB
> compiler unless they also have to modify the schema.

In `build2` we have a notion of the "development build":


So you can commit the pre-generated source code into the repository
and only enable its recompilation in the development build. You can
see an example of this technique in CLI:


Note that the one part that is still missing for this to work perfectly
is support for conditional dependencies in build2 (you would want the
dependency on the ODB compiler to be only enabled in the development
build). This is also coming in the next release.

Let me know if you decide to give this a try and run into any issues.

(1) We do in build2 due to the chicken-and-egg problem, but even then
    we plan to get rid of it soon.

More information about the odb-users mailing list