Insufficient dependencies for PCM files generation

Hi @laphecet

I’ve studied the problem spotted by @richterm (https://github.com/AliceO2Group/AliceO2/pull/3098#issuecomment-595891442) which can be summarized as follows:
assume we have build the O2 the base class in library A and derived class in library B.
Then we modify the layout of the base class (incrementing its class version in the ClassDef) and do an incremental rebuild.
Since in our current makefiles the generation of dictionaries for classes in the library B depends only on the headers of these classes, only the dictionary and the PCM file of the library A will be regenerated.

As a result, an attempt to write a TTree containing the derived class from lib. B will fail with errors like

Fatal in <TBranchElement::InitializeOffsets>: Could not find the real data member 'rof.bcData.user' when constructing the branch 'rof' [Likely an internal error, please report to the developers].
aborting

This is because the PCM file of library B stores inside the information about the layout of the base class from the lib.A, and it is not updated at the incremental rebuild.

As far as I can see, there are 2 solutions:

  1. (bad) The HEADERS section of the o2_target_root_dictionary should contain explicitly the headers of not only the classes of given module but also of their inclulded headers (recursively…). Or these headers should be extracted in the o2_target_root_dictionary itself

  2. (slightly better): The o2_target_root_dictionary should explicitly depend on the PCM files of libraries mentioned in the PUBLIC_LINK_LIBRARIES block of the o2_add_library (if this is a library accompanied with PCM file). Then, and incremental rebuild after the modification of the base class in the lib A (will trigger the regeneration of the
    libA.so, libA.rootmap and G__A_rdict.pcm) will also trigger the regeneration of the dictionary of the lib.B.
    From here I see that it is also recommended to add the pcm files of the base libraries to the rootcling call of the derived ones, e.g.
    rootcling -f G__B.cxx -m G__A_rdict.pcm -rmf ....
    This will allow to avoid redundancy in the newly generated G__B_rdict.pcm.

I’ve created a small demonstrator (with old style Makefile) in https://cernbox.cern.ch/index.php/s/0qr3JbmV9dvbeSX:
The ./test.sh will fail when trying to write a TTree after the incremental rebuild.

To “fix” it one should comment the $(DICT2): $(HDR2) InteractionRecordLinkDef.h block in the end and uncomment one of the alternative solutions below it.

Do you see easier solution?

Cheers,
Ruben

@shahoian I will have a look in O2-1232