Skip to content
Advertisement

When changing the comment of a .c file, scons still re-compile it?

It’s said that scons uses MD5 signature as default decider to dertermine whether a source file needs re-compilation. E.g. I’ve got SConstruct as below:

Library('o.c')

And my o.c is:

$ cat o.c
    /*commented*/
    #include<stdio.h>
    int f(){
      printf("hellon");
      return 2;
    }

Run scons and remove the comment line, run scons again. I expect that scons should not compile it again, but actually it’s:

gcc -o o.o -c o.c
scons: done building targets.

If I change SConstruct file to add one line:

Decider('MD5').

Still same result.

My question is: how to make sure that for scons, when changing source file comments, they don’t get re-built?

Thanks!

Advertisement

Answer

As you correctly stated, SCons uses the MD5 hashsum of a source file to decide whether it has changed or not (content-based), and a rebuild of the target seems to be required (since one of its dependencies changed). By adding or changing a comment, the MD5 sum of the file changes…so the trigger fires.

If you don’t like this behaviour, you can write and use your own Decider function which will omit comment changes to your likings. Please check section 6.1.4 “Writing Your Own Custom Decider Function” in the UserGuide to see how this can be done.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement