Wrong build cache with stale file if not cleaned before build

I have a custom task that compiles “hello.c” file into “hello.o” file and also creates “hello.d” file, both in “build/obj”. I defined the inputs and outputs of my task so it can be cached and up-to-date handled. As outputs I defined the whole dir “build/obj”.
Now, when I change certain compile parameters to not create the “hello.d” file anymore and I DO NOT CLEAN before executing my task, the build cache for the new inputs gets filled with both the “hello.o” and the “hello.d” file, allthough the .d file is outdated and should be ignored now. Thus, my build cache is broken now and I didnt even notice :frowning:

What is the recommended way to deal with such situations?

Note: I cannot list the files created by the compile tasks explicitly, because it depends on the parameters, which files are created in the end.

Your compile task needs to clean its output directory.
If you for example have a 1:1 mapping of input file to output file, you could make your task an incremental inputs task, so that it gets notified on deleted, added, and changed inputs, so that you can delete the output file for the deleted input file.
If the task cannot work incrementally but only produce all outputs on all inputs as one step, clear out the output directory before you invoke the actual compiler so that after running the output directory is in the correct state to be up-to-date and cached.

Ok, thanks for your answer!

1 Like