[Scons-users] Copying and merging directories

Peter Steele pwsteele at gmail.com
Tue Sep 11 10:26:22 EDT 2012

I gave up on using the Install command and did it the old fashioned way. To
implement the copy phase of my script, I simply did this:

copy = env.Alias("copy", env.Command(
"copy", [], [
"cp -rf {0} {1}".format(C_FROM_DIR, C_TO_DIR),
"cp -rf {0} {1}".format(JAVA_FROM_DIR, JAVA_TO_DIR)

This does exactly what I need. However, if someone can explain how to
express this logic using the scons Copy or Install options I'd like to see

-----Original Message-----
From: Peter Steele [mailto:pwsteele at gmail.com]
Sent: Monday, September 10, 2012 6:33 AM
To: 'SCons users mailing list'
Subject: RE: [Scons-users] Copying and merging directories

Okay, I've got a basic test copy/install working, but after putting it all
together with my full SConstruct file, I'm getting behaving I don't quite
understand. Here's my full script, which I've modeled after my original ant

import os

TOT = os.environ["TOT"]
SM_BASE = "{0}/Peaxy/sm".format(TOT)
FROYO_BASE = SM_BASE + "/froyo"
C_FROM_DIR = FROYO_BASE + "/output/c"
C_TO_DIR = SM_BASE + "/libipc/src"
JAVA_FROM_DIR = FROYO_BASE + "/output/java/com/peaxy/ipc/fw"
JAVA_TO_DIR = SM_BASE + "/common/src/com/peaxy/ipc"


env.Clean("all", Glob("bin") + Glob("output") + Glob(C_TO_DIR + "/fw") +
Glob(JAVA_TO_DIR + "/fw"))

build = env.Alias("build", [env.Java("bin", "src"), env.Java("bin",

codegen = env.Alias("codegen", env.Command(
"codegen", [],
"java -cp {0} -Dsdir={1}/idl -Dodir={1}/output -Dtdir={1}/template
-Ddpath={1}/bin com.peaxy.ipc.codegen.IDLCompiler"

copy = env.Alias("copy", env.Install(C_TO_DIR, Glob(C_FROM_DIR +

Default(build, codegen, copy)

My application is basically a code generator and there are three distinct
phases: build, codegen, and copy. My ant script also has an "all" target so
that when I do an "ant all", it runs the targets build, codegen, and copy in
sequence. I'm using the scons Default function to mimic the ant "all"
target, at least that's my intent. When I run "scons -c clean", all of the
generated files are cleaned up as expected. When I run "scons" without any
arguments, the build and codegen phases work as intended. However, the
'copy' target reports "Nothing to be done for 'copy'." If I then immediately
turn around and run "scons copy", the files are copied successfully on this
attempt. So, I'm missing something key how this all operates. Why does the
copy alias not work when run through Default() but does run when specified
explicitly as a target?

In fact, my script above isn't quite complete. What I really want for the
copy step is something like this:

copy = env.Alias("copy", [env.Install(C_TO_DIR, Glob(C_FROM_DIR +

env.Install(JAVA_TO_DIR, Glob(JAVA_FROM_DIR + "/fw"))])

However, this doesn't work at all and I'm clearly not constructing the logic
correctly. Basically, I want to copy the generated source files to two
separate locations, one in a C source directory and another in a Java source
directory. These projects are then built in separate steps with their own
scons/ant scripts.

-----Original Message-----
From: scons-users-bounces at scons.org [mailto:scons-users-bounces at scons.org]
On Behalf Of Francis Bolduc
Sent: Monday, September 10, 2012 5:14 AM
To: SCons users mailing list
Subject: Re: [Scons-users] Copying and merging directories

> env.Alias('copy', env.Command('copy', [], env.Install(TO_DIR,

> env.Glob(FROM_DIR))))

I think there are two problems with this.

1- env.Command is redundant, simply remove it.

env.Alias('copy', env.Install(TO_DIR, env.Glob(FROM_DIR)))

2- Glob(pattern) returns files matching the pattern in the SConscript
directory. So if you print the result from Glob(), you'll see which files
will be copied. Also, beware, Glob(pattern) is not recursive.

for node in env.Glob('*.h'):
print node.abspath

Finally, be sure to keep the Alias because if TO_DIR is not in the
SConscript's directory or one of it's sub-directories, SCons will not copy
the install the files unless you specify the install directory as part of
the target. The phony 'copy' target you created prevents this.
Scons-users mailing list
Scons-users at scons.org

More information about the Scons-users mailing list