Search code examples
makefilecmakebuildbazel

Rebuild based on file content modification, but not modification date


TL;DR How do we integrate code generation into a build system?

For source code with code generation, although one line of code generation is changed to create a new generated file, all code is re-generated. In this new generated code, although most of the code remains the same, the build system(make) only looks at the modification dates and decides to re-compile all of the generated code. Does make/cmake/bazel provide a facility to check dependencies based on file changes but not modification date?

Is there any other build system that considers whether the generated code is necessary to re-compile, not using modification date but file changes themselves?


Solution

  • Bazel use hashes to determine what has to be done. For example you can modify a C++ file by adding a new empty line. File will be recompiled, but next actions (like linking the library) will not be triggered, because the output of compilation will stay the same (probably, because it depends on an used compiler). That movie is a good introduction

    Make/Ninja for sure use timestamps. CMake does not care, because whole file comparing mechanism is delegated to the underlying build system