[Scons-users] Running two commands after build

Adam Wysocki scons at chmurka.net
Wed Aug 12 04:48:49 EDT 2015


Hi Gary,

Thank you, AddPostAction solved it.

Cheers!

On Tue, 11 Aug 2015, Gary Oberbrunner wrote:

> For the first, use AddPostAction to add the executable-modifying command
> (see the man page or users guide).  It'll run that action any time that
> target is rebuilt, immediately after it's rebuilt and before building any
> further targets that depend on it.
> 
> For the second, this is normal SCons: your method should work, though it's
> usually better to use the nodes rather than filename strings:
>   # Create c2 from c1
>   c2 = env.Command('build/test.out.x',c1, 'echo test >> ${TARGET}')
> 
> 
> On Tue, Aug 11, 2015 at 8:33 AM, Adam Wysocki <scons at chmurka.net> wrote:
> 
> > Hello,
> >
> > Hi,
> >
> > I'm trying to use scons as my build environment and I have some problems.
> > I use scons 2.3.6 with Python 2.7 on Windows 7 64-bit, but the solution
> > should be portable to Linux.
> >
> > I need to compile and link C++ sources into an executable. That goes fine.
> > However, I need to execute two commands after a file has been linked. First
> > one (let's call it c1) modifies the generated executable file, second one
> > (let's call it c2) generates another file basing on (modified by c1)
> > executable file.
> >
> > Also I need to have separate source and build directories. So the sequence
> > is:
> >
> > - compile src/test/test.cpp to build/test/test.o
> > - link build/test/test.o to build/test.out (.out is my executable suffix)
> > - execute c1 on build/test.out (build/test.out will be modified)
> > - execute c2 on build/test.out (build/test.out will NOT be modified,
> >   build/test.out.x will be created)
> >
> > My simple test environment can be created with:
> >
> > mkdir build
> > mkdir src
> > mkdir src\test
> > echo int main; > src\test\test.cpp
> >
> > My sconstruct file for this environment:
> >
> > ---------------------------------------
> > # My executable file suffix is .out
> > env = Environment(PROGSUFFIX = '.out')
> >
> > # I have sources in src directory, but all output should be in build
> > directory
> > env.VariantDir('build', 'src', duplicate = 0)
> >
> > # Let's compile the program, it goes fine
> > p = env.Program('build/test.out', Glob('build/test/*.cpp'))
> >
> > # After a program is compiled, I need to modify it's executable
> > c1 = env.Command(None, 'build/test.out', 'echo test >> ${TARGET}.out')
> >
> > # After this executable has been modified, I need to generate new file
> > (test.out.x)
> > c2 = env.Command('build/test.out.x', 'build/test.out', 'echo test >>
> > ${TARGET}')
> >
> > # Let's add dependencies
> > env.Depends(c1, p)
> > env.Depends(c2, c1)
> > ---------------------------------------
> >
> > Now how it works and how I expect it will work.
> >
> > ---------------------------------------
> > T:\tmp\scons>scons -Q
> > echo test >> build\test.out
> > g++ -o build\test\test.o -c src\test\test.cpp
> > Assembler messages:
> > Fatal error: can't create build\test\test.o: No such file or directory
> > scons: *** [build\test\test.o] Error 1
> > ---------------------------------------
> >
> > Two things happened here.
> >
> > 1. Command "c1" was executed before command "p", but it should be executed
> >    after command "p"
> >
> > 2. scons did not create subdirectory for object files (it does it when c1,
> >    c2 and Depends are commented out)
> >
> > When I create this intermediate directory by hand, all goes fine.
> >
> > ---------------------------------------
> > T:\tmp\scons>mkdir build\test
> >
> > T:\tmp\scons>scons -Q
> > g++ -o build\test\test.o -c src\test\test.cpp
> > g++ -o build\test.out build\test\test.o
> > echo test >> build\test.out
> > echo test >> build\test.out.x
> > ---------------------------------------
> >
> > Which leads to my second problem. When I execute scons once again, command
> > c2
> > gets executed once again:
> >
> > ---------------------------------------
> > T:\tmp\scons>scons -Q
> > echo test >> build\test.out.x
> > ---------------------------------------
> >
> > When I execute scons one more time, it does not execute c2 (which is
> > correct):
> >
> > ---------------------------------------
> > T:\tmp\scons>scons -Q
> > scons: `.' is up to date.
> > ---------------------------------------
> >
> > Ok, now to my questions.
> >
> > 1. Is it possible to make scons behave as expected even when no
> > intermediate
> >    directory for object files is found? Is it a bug in scons, or in my
> >    sconstruct file?
> >
> > 2. Is it possible to make scons execute c2 only one time (so the second
> >    invocation will lead to "`.' is up to date")?
> >
> > Thanks for any feedback!
> >
> > --
> > AW
> > _______________________________________________
> > Scons-users mailing list
> > Scons-users at scons.org
> > https://pairlist4.pair.net/mailman/listinfo/scons-users
> >
> 
> 
> 
> 

-- 
"qui hic minxerit aut cacaverit, habeat deos superos et inferos iratos"
http://www.chmurka.net/


More information about the Scons-users mailing list