Dobiasd / FunctionalPlus

Functional Programming Library for C++. Write concise and readable C++ code.
http://www.editgym.com/fplus-api-search/
Boost Software License 1.0
2.1k stars 167 forks source link

Consecutive build should only re-build changed files instead of all. (Circular build dependency in CMake setup?) #239

Closed Dobiasd closed 3 years ago

Dobiasd commented 3 years ago
git clone https://github.com/Dobiasd/FunctionalPlus
cmake -S FunctionalPlus/test -B FunctionalPlus/build
cmake --build FunctionalPlus/build -j 8
cmake --build FunctionalPlus/build -j 8
cmake --build FunctionalPlus/build -j 8

The first call to cmake --build FunctionalPlus/build is supposed to build all (Building CXX object CMakeFiles/foo_test.dir/foo_test.cpp.o), but the second and third ones should not do anything. Instead, they rebuild everything. The superfluous waiting time can be annoying when locally modifying only one of the unit tests.

The custom target auto_generate (added with pull/230) produces include/fplus/fwd_instances.autogenerated_defines and include/fplus/curry_instances.autogenerated_defines, which are inputs for the unit tests.

auto_generate depends on ALL. Does that mean, that it is also triggered (overwrites the autogenerated_defines files) when the tests were built? (Then, the next build needs to re-build the tests, and the cycle continues.)

If so, I guess it would make sense to run auto_generate before (and independent of) the tests to break the cycle. This would make additional sense because the tests actually do depend on the content of the autogenerated_defines files but not vice versa.

/cc @friendlyanon @pthom

pthom commented 3 years ago

You are right, I was annoyed when testing this yesterday.

The custom target auto_generate (added with pull/230) produces include/fplus/fwd_instances.autogenerated_defines and include/fplus/curry_instances.autogenerated_defines, which are inputs for the unit tests.

Nice catch, and sorry if I missed this in the original PR! I will propose a PR that solves this (auto_generate.py will touch nothing when no change is detected)

friendlyanon commented 3 years ago

I think the generated files should not be kept in the source tree, because CMake will always consider them changed when the timestamps don't match. Autogenerated sources and the single header should be kept only in the build directory.

What about providing a single header for people to just download then? The single header could be provided on the Releases page.

I guess you'll need to list all the files the python script uses to generate its output in the DEPENDS argument.