[Scons-users] Recursive directories, and the ignoring of filenames.

Matthew Marinets Matthew.Marinets at Kardium.com
Fri Aug 3 14:21:52 EDT 2018


I still can't reproduce the issue:

Renaming qwer.c to qwera.c behaves exactly as expected:
Rebuilt the first time, not rebuilt the next

I put in a print statement to check the order. Even when the order of sources did not change, SCons still behaves as expected. My complete output is below, at the ** symbol, but there's one more thing

At no point did you have a guard against a directory slipping into your sources argument in your initial post. The commands I saw attempted were as follows:
env.Command('listing.txt', 'files', 'ls -lR ${SOURCE} > ${TARGET}')

env.Command('listing.txt', ['files/', Glob('files/*')], 'ls -lR ${SOURCES[0]} > ${TARGET}')

env.Command('listing.txt', ['files/', Glob('files/*'), Glob('files/*/*'), Glob('files/*/*/*'), Glob('files/*/*/*/*')], 'ls -lR ${SOURCES[0]} > ${TARGET}')

env.Command('listing.txt', ['files',
Value(subprocess.check_output(['sh', '-c', 'find files/ -type f -exec sha256sum {} \; | sort | sha256sum']))], 'ls -lR ${SOURCES[0]} >
${TARGET}')

env.Command('out.txt', Glob('files/*'), 'ls -lR files/ > ${TARGET}')

Except for the last one, every call starts with 'files' as the first source. 'files' is a directory, as evidenced by your use of 'files/' in many places, and your introductory statement that "I have a directory called 'files'".

Under the hood, SCons converts all sources and targets to SCons nodes; usually Entry nodes. This means that:
	-If the file / directory does not exist, SCons waits waits until something creates it to check whether it's a file or dir.
	-If it already exists, SCons resolves it to either a File or Dir node. This might also explain why you said your script would work once then behave incorrectly.

I have read through your email multiple times. If I come off as not having read it clearly enough, I apologize. I am simply trying to help, and hopefully I'll get better at SCons myself as I do so.

-Matthew
-------------------------------------------------------
**My scons output. The only difference in the code is that I added a print statement so we can see the order of the sources being fed to the builder:

C:\Users\mmarinets\IdeaProjects\HelloWorld>dir src
 Volume in drive C has no label.
 Volume Serial Number is 76FB-4CD1

 Directory of C:\Users\mmarinets\IdeaProjects\HelloWorld\src

03-Aug-2018  11:08 AM    <DIR>          .
03-Aug-2018  11:08 AM    <DIR>          ..
03-Aug-2018  10:34 AM                71 a.c
03-Aug-2018  10:34 AM                71 b.c
27-Jun-2018  02:20 PM    <DIR>          com
18-Jul-2018  04:09 PM    <DIR>          org
03-Aug-2018  10:34 AM                71 qwer.c
               3 File(s)            213 bytes
               4 Dir(s)  154,776,956,928 bytes free

C:\Users\mmarinets\IdeaProjects\HelloWorld>dir build
 Volume in drive C has no label.
 Volume Serial Number is 76FB-4CD1

 Directory of C:\Users\mmarinets\IdeaProjects\HelloWorld\build

03-Aug-2018  11:08 AM    <DIR>          .
03-Aug-2018  11:08 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  154,776,956,928 bytes free

C:\Users\mmarinets\IdeaProjects\HelloWorld>scons
scons: Reading SConscript files ...
['src\\a.c', 'src\\b.c', 'src\\qwer.c']
scons: done reading SConscript files.
scons: Building targets ...
cp src\a.c src\b.c src\qwer.c build
scons: done building targets.

C:\Users\mmarinets\IdeaProjects\HelloWorld>scons
scons: Reading SConscript files ...
['src\\a.c', 'src\\b.c', 'src\\qwer.c']
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.

C:\Users\mmarinets\IdeaProjects\HelloWorld>cp src/qwer.c src/qwera.c

C:\Users\mmarinets\IdeaProjects\HelloWorld>del src\qwer.c

C:\Users\mmarinets\IdeaProjects\HelloWorld>scons --debug=explain
scons: Reading SConscript files ...
['src\\a.c', 'src\\b.c', 'src\\qwera.c']
scons: done reading SConscript files.
scons: Building targets ...
scons: rebuilding `build\a.c' because:
           `src\qwer.c' is no longer a dependency
           `src\qwera.c' is a new dependency
cp src\a.c src\b.c src\qwera.c build
scons: done building targets.

C:\Users\mmarinets\IdeaProjects\HelloWorld>scons --debug=explain
scons: Reading SConscript files ...
['src\\a.c', 'src\\b.c', 'src\\qwera.c']
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.

-----Original Message-----
From: Scons-users <scons-users-bounces at scons.org> On Behalf Of Alistair Buxton
Sent: August 3, 2018 11:03
To: SCons users mailing list <scons-users at scons.org>
Subject: Re: [Scons-users] Recursive directories, and the ignoring of filenames.

On 3 August 2018 at 18:51, Matthew Marinets <Matthew.Marinets at kardium.com> wrote:
> I can't reproduce your bug then.
>
> Using Python 3.6.5;
> scons -v:
>         script: v3.0.1.74b2c53bc42290e911b334a6b44f187da698a668, 2017/11/14 13:16:53, by bdbaddog on hpmicrodog
>         engine: v3.0.1.74b2c53bc42290e911b334a6b44f187da698a668, 2017/11/14 13:16:53, by bdbaddog on hpmicrodog
>         engine path: ['C:\\Program 
> Files\\Python36\\scons-3.0.1\\SCons']
>
>
> I made a Command() builder that Globs all .c files in the src/ directory, and copies them to the build/ directory:
>
>         sources = Glob(pattern = str(src) + '/*.c')
>         env.Command(target = [build.File(x.name) for x in sources], 
> source = sources, action = 'cp $SOURCES $TARGET.dir')
>
> First I ran it with src contents:
> src/a.c
> src/b.c
> src/asdf.c
>
> All files were copied, as expected. Running SCons again, the build was not executed as all targets were up to date.

The build was re-run because the new name you gave to the file changed the sorting order. I explained this in the initial report:

On 3 August 2018 at 00:45, Alistair Buxton <a.j.buxton at gmail.com> wrote:

> renames. It can also not if the renaming causes dependencies to be 
> listed in a different order (ie if you renamed a.txt instead of b.txt, 
> and the files had different contents).

If you renamed asdf.c to asdfa.c, then the build would still have re-run, because you put the name of every file into the action string, and scons will detect that that the action string has changed. I explained this in my initial follow up email:


> In this case you would instead say:
>
> env.Command('listing.txt', Glob('*.txt'), 'ls ${SOURCES} > ${TARGET}')
>
> and scons would identify that the build needs to be re-done because 
> the action string changed.

and the above was in reference to a reproduction of the issue which involves no directories at all:

> env.Command('listing.txt', Glob('*.txt'), 'ls *.txt > ${TARGET}')

Please actually read the whole report before jumping to conclusions.


--
Alistair Buxton
a.j.buxton at gmail.com
_______________________________________________
Scons-users mailing list
Scons-users at scons.org
https://pairlist4.pair.net/mailman/listinfo/scons-users


More information about the Scons-users mailing list