[Scons-users] Generating header from cpp file causes cycle

Ivan Nedrehagen ivan at nedrehagen.com
Sat Mar 18 22:00:12 EDT 2017


I have a unit test library that generates headers from the cpp files 
that contains tests.

Lately with my updated version of SCons (2.5.0) I get dependency cycles.

(It is very hard to debug these cycles, because --tree doesn't output 
anything)


A case that reproduce the problem:

--- SConstruct ---

def create_header(target, source, env):
     txt = " class Test {}; \n"
     file = open(str(target))
     file.write(txt)

env = Environment()

headerBuilder = env.Builder(action=create_header)

env.Append(BUILDERS={"Header": headerBuilder})

header = env.Header("test.h", "test.cpp")
exe = env.Program("test.cpp")

--- test.cpp ---

#include "test.h"

int main() {
   Test test;
   return 0;
}

--- Result ---

scons: *** Found dependency cycle(s):
   test.h -> test.h

--- End of Case ---

Why is this failing? I understand that the test.o should be dependent on 
test.h, but why is suddenly test.h depending on itself?

I tried to set target_scanner and source_scanner to None in the builder 
just to see if this made a difference, but no.

How can I express a builder that builds header files from cpp files 
without creating a builder that build dependency cycles?



More information about the Scons-users mailing list