Skip to content

Scons fails to build dependent node #2647

Closed

Description

@bdbaddog

This issue was originally created at: 2010-06-09 16:00:50.
This issue was reported by: jason_at_intel.
jason_at_intel said at 2010-06-09 16:00:50

Scons is failing to build dependent nodes before trying to do action on a given
node is that node does not have a build actions.

A a simple test case one can do this on windows to show this off.

<< a.cpp >>
#include

__declspec(dllexport) void foo()
{
std::printf("Hello");
}
<<>>

<>
ret=SharedLibrary("sub1/a.cpp",no_import_lib=True)
Install("test","sub1/a.lib")
Depends("sub1/a.lib",ret)
<<>>

this would make a tree such as this:
+-test\a.lib
+-sub1\a.lib
+-sub1\a.dll
+-sub1\a.obj
| +-sub1\a.cpp
| +-C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\amd64\cl.EXE
+-C:\Program Files (x86)\Microsoft Visual Studio 8\VC\BIN\amd64\link.EXE

In Scons 1.2 and before this works fine (as it builds a.dll before the "copy"
of a.lib). I have not tested Scons 1.3 in this case. But in scons 2.0 release
candiate this fails. It seems that Scons stops processing this as soon as a
node is hit that does not have a builder. Where as before it seemed to consider
the node up to date if and only if the all the dependents are up to date. The
error message is:

scons: *** [test\a.lib] Source sub1\a.lib' not found, needed by target test\a.lib'.

Again this is an example that is easy to reproduce. In my case this same basic
pattern happens with a Command() to build a makefile. This breaks 6 product
builds we have.

stevenknight said at 2010-06-14 11:30:13

Okay, I've reproduced this. It appears to be a problem introduced in 1.3.0.

There's an omitted step here that at first made me think it worked correctly:
you need to try to build just the "test" subdirectory. If you let it default to
building the entire directory tree, then it can try to build the library first,
the .lib file gets built as a side effect, and everything appears to work.
Building just the "test" subdirectory explicitly on the command line isolates
the observed failure, which is (as stated) that the dependency is not followed
and the library is not built first.

I'm escalating this to P1. I've uploaded a preliminary copy of the test script
that isolates the test case. It contains some hackery to get the current test
infrastructure to work with 1.2.0, which should be removed before checking in.

stevenknight said at 2010-06-14 11:31:34

Created an attachment (id=758)
prototype test script containing use case

stevenknight said at 2010-06-14 11:46:34

Unfortunate news: the DAGs in 1.2.0 and 1.3.0 are identical. This suggests that
the correct behavior in 1.2.0 was relying on some quirky back-door behavior
specific to the then-implementation of Visual C++ support.

jason_at_intel said at 2010-06-14 12:07:07

I don't think so.. as I have a completly different MSVC tool in Parts. I can
reproduce it with that tool as well. This also shows up on linux. However the
case I have for this is requires setting up a make file Command() call to do
this.

The issue seems from what I can tell is that if the Node has a builder it will
work fine, if it does not have a builder the taskmaster ( or something) seems
to stop procossing correctly. In fact that the tree is the same is why this
seems to problem. People can make a tree of node with nodes in the middle that
do not have builders. ( which is what I am getting cases of here) then the code
fails to build.. confusion starts.

to help point this out say this with the sample I gave.

scons sub1\a.lib
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: *** Do not know how to make File target `sub1\a.lib'
(C:\Users\jlkenny\code\sconstest\sub1\a.lib). Stop.
scons: building terminated because of errors.

do this with SCons 1.2:

scons-1.2.0.bat sub1\a.lib
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosub1\a.obj /c sub1\a.cpp /nologo /TP /nologo
a.cpp
link /nologo /dll /out:sub1\a.dll sub1\a.obj
Creating library sub1\a.lib and object sub1\a.exp
scons: Nothing to be done for `sub1\a.lib'.
scons: done building targets.

This mean that there has to have been a change in some task master/execution
engine processing that use to allow empty nodes with out builder to be
processed correctly. in the 1.3\2.x case Scons says it does not know how to
build this node ( as it has no builder) where in 1.2 it doesn't care and tries
to build dependent node first then say there is not to do for this target ( as
there is no builder)

stevenknight said at 2010-06-14 13:51:51

Jason-- How difficult would it be for you to come up with a Linux test case, even
if it uses Make? I'm trying to narrow down the exact change that introduces the
problem, and it's proving problematic because of the significant changes to the VC
tool chain, and ripple effects in the test infrastructure. Being able to
demonstrate the problem on a different tool chain (esp. if it's just a Command()
call) would be a big help. --SK

jason_at_intel said at 2010-06-14 13:54:42

not to hard... give me a day or so to make up a small test case in my spare time

jason_at_intel said at 2010-06-14 14:22:18

got to love SCons some days... it can make stuff so easy to show.

take the previous sample I have and do this for the SConstruct

ret=Command(['sub1/foo.txt'],'sub1/a.cpp',"cd sub1 && echo foo>foo.txt && echo
hidden>hidden.txt")
Install("test","sub1/hidden.txt")
Depends("sub1/hidden.txt",ret)

run command of

scons sub1/hidden.txt

should repeat same basic messages as I reported before. Repeats on windows
linux and mac ( just tested it :-) )

stevenknight said at 2010-06-14 14:35:24

Uh... Thanks for the test case, but...

That test case fails, sure, but it doesn't just fail on 1.3.0 and 2.0.0. For
me, at least, itt also fails on 1.2.0, and 1.1.0, and 1.0.0... And it fails for
completely explainable reasons--namely, in this case there's a completely broken
dependency graph. There's no way I can see that SCons should ever know that it
needs to run the command to update foo.txt, because hidden.txt really is hidden.

If this is really a regression, we need something on Linux that demonstrates the
behavior that succeeds in 1.2.0, in a manner similar to what makes the Visual C
.lib file connection work in 1.2.0, but then fails in 1.3.0.

jason_at_intel said at 2010-06-14 14:46:41

Uhhh?? I don't know what you see but here is what I get on a ubuntu box. I run
all four possible test cases:

scons-1.2.0 test/hidden.txt --tree=all
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cd sub1 && echo foo>foo.txt && echo hidden>hidden.txt
Install file: "sub1/hidden.txt" as "test/hidden.txt"
+-test/hidden.txt
+-sub1/hidden.txt
+-sub1/foo.txt
+-sub1/a.cpp
scons: done building targets.

scons test/hidden.txt --tree=all
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: *** [test/hidden.txt] Source sub1/hidden.txt' not found, needed by target test/hidden.txt'.
+-test/hidden.txt
+-sub1/hidden.txt
+-sub1/foo.txt
+-sub1/a.cpp
scons: building terminated because of errors.

scons sub1/hidden.txt --tree=all
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: *** Do not know how to make File target `sub1/hidden.txt'
(/home/jlkenny/sconstest/sub1/hidden.txt). Stop.
+-sub1/hidden.txt
+-sub1/foo.txt
+-sub1/a.cpp
scons: building terminated because of errors.

scons-1.2.0 sub1/hidden.txt --tree=all
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cd sub1 && echo foo>foo.txt && echo hidden>hidden.txt
scons: Nothing to be done for `sub1/hidden.txt'.
+-sub1/hidden.txt
+-sub1/foo.txt
+-sub1/a.cpp
scons: done building targets.

Does that help?

jason_at_intel said at 2010-06-14 14:53:46

Created an attachment (id=759)
Test case.. 7z file

stevenknight said at 2010-06-14 14:57:15

Gah! You're right, I screwed up translating the test case into my script.
Working...

jason_at_intel said at 2010-06-14 14:58:28

No problem :-)

stevenknight said at 2010-06-14 15:50:27

I found the problem, and the fix. It's very specific to this case, where you
have a "hidden" file (i.e., a file without a Builder) and then establish an
explicit Dependency() on it. It could also, I suppose, happen if you caused a
source file to "depend" on some other built file, but that seems pretty
uncommon.

This has actually been in the code base for more than a year, and was first
released in the 1.2.0.d20090113 checkpoint. The fact that it's only coming to
light now reinforces that it's kind of an obscure corner.

The current consensus on the release team is to release 2.0.0 with this (since
it's technically not a regression from 1.3.0, which has the same problem), and
follow up with a 2.0.1 containing the fix (and a 1.3.x with it as well).

I'll attach a patch so you can test it out on your live configuration. I'm
quite sure it will work, but if you could test it out and verify it, I'd
appreciate it.

Many thanks for the test cases.

stevenknight said at 2010-06-14 15:51:01

Created an attachment (id=760)
fix for the problem

jason_at_intel said at 2010-06-14 15:58:24

I will test the patch with Scon 2.0 RC tomorrow.

As a FYI you could view this as a person trying to define a "virtual" node that
all source file "require" to be built before this file, or any targets that the
source might make has to be build first. I also found that this test case shows
that value of SideEffect() which I think will solve most of the issues here at
work ( all but one or two cases which fall in to this corner case).

jason_at_intel said at 2010-06-15 10:34:50

I am happy to say that the patch worked with Scons 2.0.0.candidate.

Thanks Steve!

stevenknight said at 2010-06-15 14:12:31

Fixed for next release in r5031:

http://scons.tigris.org/source/browse/scons?view=rev&revision=5031

Thanks,

gregnoel said at 2010-06-15 14:22:41

For the record, here's the SConstruct I used to demonstrate the problem on my
Mac, and which would presumably show it on Linux as well:

#ret=SharedLibrary("sub1/a.cpp",no_import_lib=True)
ret = Command('sub1/a.dll', 'sub1/a.cpp',
'cp sub1/a.cpp sub1/a.dll; cp sub1/a.cpp sub1/a.lib')
Install("test","sub1/a.lib")
Depends("sub1/a.lib",ret)
#SideEffect("sub1/a.lib",ret)
Default('test')

The trick was the last line, to force SCons to build 'test' before 'sub1'.

As a workaround, if you uncomment the SideEffect() line and comment out the
Depends(), it works fine, since it attaches 'sub1/a.lib' to the builder for
'sub1/a.dll'. Would that work for you?

jason_at_intel said at 2010-06-15 14:34:36

Hi Greg,

I think I noted above that SideEffect fixes the sample case. I have moved
everyone I can to use SideEffect as this does workaround the problem ( and
might be more correct) in effort to push the Scons 2.0 update at work. However,
I am not 100% sure this solves the problem for all cases ( more testing is
needed). At the very least it would be better to have SCons say soemthing
helpful here if the fix was not accepted to say "hey you have a node with
nothing in it,, use XXX API to get around this" at the very least. My main
concern is that people here use Depends where maybe SideEffect is better,
because they don't know better or it does not seem obvious to use in these cases

At any rate Steve has fixed it, so this prevents the "corner case" from
becoming an issue, and allow cases in which this happen by "misinformed users"
work as they expect.

stevenknight attached 2647.py at 2010-06-14 11:31:34.

prototype test script containing use case

jason_at_intel attached sconstest.7z at 2010-06-14 14:53:46.

Test case.. 7z file

stevenknight attached 2647.patch at 2010-06-14 15:51:01.

fix for the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions