[Scons-users] SCons misses a dependency which results in incorrect output.

Tal Dayan tal at zapta.com
Wed Jul 16 12:38:28 EDT 2025


Hi all,

We encountered this problem with the nextpnr tool and created here a small
and independent example that demonstrates it.

In the example below, a shell script 'command.sh' reads the source file
'file1' and writes it to the target file 'file2'. However, if the
source file starts with 'bad' it exits with an error code, *after* creating
the target file.

The script `run.sh', runs scons three times with these values of the source
file file1 'good', 'bad', and 'good'.  The expectation is that after the
third scons run, file2 should contain the value 'good' but it contains the
value 'bad'.

Do we miss anything or is it simply a bug?

SConstruct:

----------------------------------------------
# SCons environment

env = Environment()


# Copy file1 → file2 using command.sh

# Inject an error if file1 starts with 'bad"

file2 = env.Command(

    target='file2',

    source='file1',

    action='./command.sh $SOURCE > $TARGET'

)


# Make 'file2' the default target

Default(file2)

----------------------------------------------


command.sh:

----------------------------------------------

#!/bin/bash

# Usage: ./command input > output


# Read from the first argument and copy to stdout

cat "$1"


# If the input file starts with 'bad', inject an error AFTER creating the
output file.


first_line=$(head -n 1 "$1")


if [[ "$first_line" == bad* ]]; then

  exit 1

fi


exit 0

----------------------------------------------



run.sh

----------------------------------------------

#!/bin/bash


# Clean up.

rm -f .sconsign.dblite

rm -f file[12]


echo

echo "---- Iteration 1: file1 = 'good'"

echo "good" > file1

scons

echo


echo "File1"

cat -n file1


echo "File2"

cat -n file2



echo

echo "---- Iteration 2: file1 = 'bad'"

echo "bad" > file1

cat -n file1

scons

echo


echo "File1"

cat -n file1


echo "File2"

cat -n file2


echo

echo "---- Iteration 3: file1 = 'good'"

echo "good" > file1

cat -n file1

scons

echo


echo "File1"

cat -n file1


echo "File2"

cat -n file2

----------------------------------------------



Run log:

----------------------------------------------

$ ./run.sh


---- Iteration 1: file1 = 'good'

scons: Reading SConscript files ...

scons: done reading SConscript files.

scons: Building targets ...

./command.sh file1 > file2

scons: done building targets.


File1

     1 good

File2

     1 good


---- Iteration 2: file1 = 'bad'

     1 bad

scons: Reading SConscript files ...

scons: done reading SConscript files.

scons: Building targets ...

./command.sh file1 > file2

scons: *** [file2] Error 1

scons: building terminated because of errors.


File1

     1 bad

File2

     1 bad


---- Iteration 1: file1 = 'good'

     1 good

scons: Reading SConscript files ...

scons: done reading SConscript files.

scons: Building targets ...

scons: `file2' is up to date.

scons: done building targets.


File1

     1 good

File2

     1 bad

----------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20250716/ac53518f/attachment-0001.htm>


More information about the Scons-users mailing list