views:

164

answers:

6

Sometimes, when I look through my header files I'd like to add something little to the (doxygen) documentation. That might be a quick note about the use of some function parameter, or just fixing a little typo.

But then I think: Oh no, that'll trigger a recompile on the next make call! And for certain basic headers the whole project would recompile, which can take a long time. So, nevermind!

Is there a solution to this dilemma? Are there approaches where the functions/classes are documented not directly in the headers? Or are there (plans for) a smart make that would notice that only some comment has changed, but no recompilation is necessary?

+3  A: 

Why not just touch the file back to a time where make won't think it changed?

As onebyone suggests you could wrap it into a simple script.

Duck
Any instructions???? Any documentation on 'touch' ing?
Ganesh R.
I'd do this with "touch -r file.h timestamp" ... edit file.h ... rebuild docs (but not code) ... "touch -r timestamp file.h"
Steve Jessop
@Ganesh - Link added.
Duck
The 'touch' approach is okay, but potentially bug-prone: What if you actually had made a code change in that header, too, but you have forgotten about it?
That's why you save and restore the timestamp around the change to the docs. That way, if you've previously modified the file, that previous modification is still visible to make. It's only if you accidentally change the docs and the code *at the same time* that you'd have the problem you imply. That's the cost of ignoring a change, so don't do it.
Steve Jessop
+5  A: 

You could shorten the compile times using ccache, possibly with the CCACHE_UNIFY environment option set.

ccache hashes the pre-processor output, and serves the previously compiled object if no changes were detected.

Man page section about CCACHE_UNIFY

CCACHE_UNIFY

If you set the environment variable CCACHE_UNIFY then ccache will use the C/C++ unifier when hashing the pre-processor output if -g is not used in the compile. The unifier is slower than a normal hash, so setting this environment variable loses a little bit of speed, but it means that ccache can take advantage of not recompiling when the changes to the source code consist of reformatting only. Note that using CCACHE_UNIFY changes the hash, so cached compiles with CCACHE_UNIFY set cannot be used when CCACHE_UNIFY is not set and vice versa. The reason the unifier is off by default is that it can give incorrect line number information in compiler warning messages.

Hasturkun
I don't think this will work. At least with gcc preprocessor, when you add a new line of comment, the preprocessor removes all the contents, but leaves the extra new line. That is, the files will not be the same after preprocessing and ccache will recompile the file. I don't know whether this preprocessor behavior is standard.
David Rodríguez - dribeas
The `CCACHE_UNIFY` option works around that, at the expense of some speed. I'll add the details to my answer
Hasturkun
A: 

Just make the changes, and accept the recompile. It's not really possible to have a functional development environment when the devs are afraid of compliation; perhaps you need to look into a distributed grid compilation system that will reduce the compilation time?

McWafflestix
+2  A: 

make works strictly from the timestamps on the files, and there are definitly no plans to extend it past that. make is used for a lot of things besides just C, and doesn't know anything about the contents of the file. Your build would probably get a lot slower if make had to analyze the changes.

You can keep your documentation out of your header files and just in the .c files, which will limit the scope of what needs to be recompiled. I'll admit that personally I prefer to document "interface" functions in header files, but from doxygen's standpoint it doesn't really matter.

As suggested by another, you can bypass this system by using 'touch' to back-date a file.

doxygen will let you put comments in external files, but that's generally an undesireable solution; part of the whole point of doxygen was to keep the documentation close to the source.

Otherwise, I suggest you fix your compilations to be faster... you really shouldn't be afraid of them.

Chris Arguin
Qt actually does exactly that all the documentation is contained in the implementation files and not the header. I have almost come around to that too, most of the work happens in the implementation file not the header
Harald Scheirich
I generally stick to the rule that the interface is documented in the header files, and implementation-specific comments are in the implementation files.
@Harold - does that get awkward in cases where much of the code is inlined or templates?
Duck
@Duck - That's a good point. C++ throws this off because it does encourage you to put some implementation in header files. There I think you are stuck.
Chris Arguin
@Duck - wanted to look at some of the template classes but I don't have the sources here, could not find any of the inlined documentation there. That documentation might be in a separate file ...
Harald Scheirich
A: 

My solution is to simply not include headers as dependencies in the Makefile... so changes to a header file do not trigger any recompilation by "make".

Of course the downside to that is that if I make a change that affects memory layouts (e.g. adding a member variable to a class) I need to remember to manually touch the affected .cpp files (or if it's too difficult to figure out which cpp files are affected, do a "make clean; make"), which can be a bit error prone... but it generally works for me.

Jeremy Friesner
In addition to being error prone, this can't possibly scale for any decent size project where you don't know how many implementation files include the header. And if you do a 'make all' all the time you are defeating the purpose of using this scheme in the first place.
Newton Falls
-1: I agree with Newton Falls. The solution you propose does not scale and it has a very high bug-breeding potential. I see the fact that you clearly specified it in your answer, but this is definitely bad practice in my opinion, so it should be avoided.
Stefano Borini
Yeah, don't do that.
I agree that it wouldn't work for everyone. I prefer it for my work though, because (like the original poster) I find it really annoying to fix a typo in a comment and then find that everything must be recompiled.What would be ideal would be a C/C++-aware version of 'make' that actually keeps track of what parts of the header file changed, and used that knowledge to trigger rebuilds only when it was actually necessary. At a minimum, it could detect that changes were made only to comments in the file, and not trigger a rebuild in that case.
Jeremy Friesner
+3  A: 

How about checking out (you do version control, don't you?) another copy of the codebase in a different directory, just for these kinds of edits?

It can be a separate branch, or not. Then, when these kinds of small changes occur to you, you just make them here. You can commit them directly: now they are in a safe place, and won't disturb your actual development. Every once in a while, like once a week if your build times really are that long, you can merge these changes to what you are working on. Merge conflicts should rarely occur, as long as you document in one directory and write code in the other.

Pukku
Thanks, great idea!