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

Ivan Nedrehagen ivan at nedrehagen.com
Sun Mar 19 04:51:20 EDT 2017


This is a case that reproduce the problem I have.


It is not perfect, but it still illustrates the problem.


the header I generate doesn't include anything. It becomes one line: 
"class Test {};"

the test.cpp includes the file I generate of course. But in my 
understanding that only means that test.o depends on test.cpp and test.h

This is reflected in the tree.

For me it looks like that SCons decide that test.h depends on test.cpp, 
and that I therefore also must depend on test.h (since it is included)

This is also reflected in the tree (if I changed the #include "test.h" 
in test.cpp into #include "test2.h", test.h seems to be dependant on 
test2.h)


Please explain what I am doing wrong...


On 2017-03-19 05:17, Bill Deegan wrote:
> Your header file builder includes the header being generated.
> There is a dependency cycle..
> Is that really the code you have? (or just an example which doesn't 
> mimic your actual build?)
>
>
> -Bill
>
> On Sat, Mar 18, 2017 at 10:00 PM, Ivan Nedrehagen via Scons-users 
> <scons-users at scons.org <mailto:scons-users at scons.org>> wrote:
>
>     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?
>
>     _______________________________________________
>     Scons-users mailing list
>     Scons-users at scons.org <mailto:Scons-users at scons.org>
>     https://pairlist4.pair.net/mailman/listinfo/scons-users
>     <https://pairlist4.pair.net/mailman/listinfo/scons-users>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20170319/d63d67c6/attachment.html>


More information about the Scons-users mailing list