[Scons-users] Deleting empty source files

Petteri Hintsanen petterih at iki.fi
Tue Sep 5 15:42:50 EDT 2017


Hello all,

Today we ran into a somewhat confusing situation with empty source
files.  Consider the following SConstruct:

    sources = ["a.c", "b.c"]
    Program("a", sources)

Suppose a.c is simply

    int main() { return 0; }

and b.c is empty (zero bytes).  Running scons builds 'a', as expected:

    $ scons
    scons: Reading SConscript files ...
    scons: done reading SConscript files.
    scons: Building targets ...
    gcc -o a.o -c a.c
    gcc -o b.o -c b.c
    gcc -o a a.o b.o
    scons: done building targets.

Now delete b.c and run scons again:

    $ rm b.c
    $ scons
    scons: Reading SConscript files ...
    scons: done reading SConscript files.
    scons: Building targets ...
    scons: `.' is up to date.
    scons: done building targets.

So it looks like scons does not catch that b.c has been removed, albeit
the end result is correct.  But if you have a non-empty b.c, say
containing a single newline character like after

    $ echo > b.c

then scons will catch the deletion, even though the resulting object
file will be exactly the same.

I realize that this is a contrived case, and I'm not sure whether it is
a bug or not, but the behaviour seems somewhat inconsistent.  I would
expect scons to complain about missing b.c in any case.

This happens with SCons 2.5.1 and Python 2.7.13.

For curiosity's sake I tried the same example with GNU Make 4.1.  It
behaves differently depending on how you use implicit rules.  With
Makefile like this:

    objs = a.o b.o
    a: $(objs)

Make works like SCons, except that it does not care whether b.c has zero
or more bytes.  But with Makefile like this:

    objs = a.o b.o
    a: $(objs)
    a.o: a.c
    b.o: b.c

Make will complain after removing b.c, even if it has zero bytes.

Best regards,
Petteri


More information about the Scons-users mailing list