Repository navigation
Description
This issue was originally created at: 2012-10-10 07:42:56.
This issue was reported by: marcnarc.
marcnarc said at 2012-10-10 07:42:56
SCons doesn't always pick up a dependency on $CC. Here's a simple SConstruct:
e = DefaultEnvironment()
mycc = e.Command(
target="mycc",
source="/usr/bin/gcc",
action="cp $SOURCE $TARGET",
)
e.Replace(CC=mycc[0].abspath)
e.Program(target="testapp", source="test.c")The above works fine:
$ scons --tree=prune
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cp /usr/bin/gcc mycc
/usr/home/marcnarc/Code/foo/sconsdep/mycc -o test.o -c test.c
/usr/home/marcnarc/Code/foo/sconsdep/mycc -o testapp test.o
+-.
+-SConstruct
+-mycc
| +-/usr/bin/gcc
| +-/bin/cp
+-test.c
+-test.o
| +-test.c
| +-[mycc]
+-testapp
+-[test.o]
+-[mycc]
scons: done building targets.However, it breaks with seemingly innocent changes:
- Put mycc inside a tools/ directory (
target="tools/mycc"). - Change the program's name from "testapp". Some names work but others don't. Here are some names that don't work: aragon frodo gimli legolas boromir. And here are some names that do work: waragon, phrodo, qgimli plegolas sauron.
- Run scons with the -q option.
What breaks is the dependency on mycc. In each failing case the tree shows no dependency from test.o on mycc:
...
+-.
+-SConstruct
+-test.c
+-test.o
| +-test.c
+-testapp
| +-[test.o]
+-tools
+-tools/mycc
+-/usr/bin/gcc
+-/bin/cp(I also see this problem with SCons 1.2.0.)
marcnarc said at 2012-10-10 12:28:32
Created an attachment (id=905) taskmaster trace from a successful run
marcnarc said at 2012-10-10 12:28:55
Created an attachment (id=906) taskmaster trace from a failed run
marcnarc said at 2012-10-10 12:37:50
Created an attachment (id=907) taskmaster trace when the program's name is "gimli"
marcnarc said at 2012-10-10 12:38:48
Attachment taskmaster.fail.trace is from a run where the mycc target is "tools/mycc".
Attachment taskmaster.fail-gimli.trace is from a run where the mycc target is just "mycc" but the program's target is "gimli".
marcnarc said at 2012-10-22 07:24:28
Johan Holmberg noted on scons-users that all the working target names are lexically > than "mycc".
I've verified that the lexicographic order of the target names is significant: Renaming the mycc target to "Amycc" fixes the broken program names ("aragon" et al.).
marcnarc said at 2012-10-22 07:28:17
A bit more info:
Specifying the target name (e.g. "testapp") on the scons command line always produces a failure, regardless of the name of the mycc target.
Votes for this issue: 1.
marcnarc attached taskmaster.good.trace at 2012-10-10 12:28:32.
taskmaster trace from a successful run
marcnarc attached taskmaster.fail.trace at 2012-10-10 12:28:55.
taskmaster trace from a failed run
marcnarc attached taskmaster.fail-gimli.trace at 2012-10-10 12:37:50.
taskmaster trace when the program's name is "gimli"
Activity
mwichmann commentedon Apr 3, 2022
This is just weird, why should there be a lexicograhical relationship to the pathname of a tool? Anyway, I try to reproduce it, it doesn't work like this, now if doesn't "make" the tool at all.
bdbaddog commentedon Apr 4, 2022
It seems you can't just cp gcc to another name in another location anymore..
bdbaddog commentedon Apr 4, 2022
ugh. I can repro.
You can see the files here: https://github.com/bdbaddog/scons-bugswork/tree/main/2877
This is via the copy to tools dir referred to above.
mwichmann commentedon Apr 4, 2022
Yeah, I was seeing the gcc problem as well, probably for demo purposes should pick a different tool. Also if the action uses
Copyit should figure out whether mkdir needed or not without having to wire it in? So maybe this isn't actually a problem? Using Copy it now looks like this - I see the tool in the deps where it's expected.bdbaddog commentedon Apr 4, 2022
@mwichmann try it with my sample code linked above. I still see the issue.
I think it's an issue with the implicit command dependencies...
mwichmann commentedon Apr 4, 2022
You're right, the lex-order-matters thing is still there, I didn't even notice in my test (pasted above) that I dodged it by using
bin/toolnameinstead oftools/toolname. Just like the original report, I can toggle success/fail by swapping the subdirectory names between bin and tools... weird.mwichmann commentedon Apr 4, 2022
SCons must be sorting something in order to get reproducibility, and thus somehow introducing this issue?
mwichmann commentedon Nov 18, 2026
This is convoluted enough that I asked an AI for help analyzing it. There's a lot going on here. Abbreviated, and possibly leaving out important details, the "compiler" in a builder is an implicit dependency, part of the DAG once discovered. But since in this case it's generated, and the check is filesystem-based (
WhereIs) - if it hasn't been generated yet, it's not discovered, and no node is created (basically "SCons discovers it too late"). As a result the sorted in-memory tree is walked instead of having a dep in place, and so the lex order matters. Underneath that is a layer where filesystem probes are sorted for consistency, and that sorted order is used in places where maybe it doesn't need to be sorted. Redesigning to get rid of that leakage (if you want to call it that) seems like a big/risky lift.For specific cases where people are using generated "compilers", using the much-maligned
Dependsmight be the best answer?mwichmann commentedon Nov 20, 2026
My current suggested band-aid is to add some doc helpers about this. Whether we close the issue after those additions or not, I don't have an opinion on yet. Open to comments
mwichmann commentedon Nov 20, 2026
I'm changing the issue summary in the hopes it will be easier to find if anyone runs into this.
Basically, you can make the original example work with tweak, but you have to do two things, neither of which is necessarily intuitive.
So here's the reworked example:
and here's the tree from that:
I'm going to propose a PR that documents some of this - the only place I can think where it might be seen is in $IMPLICIT_COMMAND_DEPENDENCIES
[-]Dependencies on $CC are flaky[/-][+]Implicit command dependency may fail if command is generated by the build[/+]Expand description of implicit command dependencies [skip appveyor]