[Scons-users] Copying and merging directories

Hill, Steve Steve.Hill at aeroflex.com
Wed Sep 12 11:31:19 EDT 2012


I've had to implement a different decider to get "Install" to work as we
need. If you can use a different environment for the installs, you could
do something like:

installEnv = baseEnv.Clone() # Create the environment for installing
installEnv.Decider(lambda t, d, p: True) # Always consider targets to
be out-of-date wrt their source
installEnv.Install(<.. Files ..>)

In practice, I've written the following decider that suppresses the copy
when the files are the same:

def _install_decider(dependency, target, prev_ni):
# Make sure that files are installed whenever the
destination is different
# from the source
if os.path.basename(str(dependency)) ==
os.path.basename(str(target)):
if os.path.isfile(str(target)):
import filecmp
different = not filecmp.cmp(str(dependency),
str(target))
return different
else:
return True
else:
return False

HTH,

Steve.


> -----Original Message-----

> From: scons-users-bounces at scons.org

> [mailto:scons-users-bounces at scons.org] On Behalf Of Peter Steele

> Sent: 12 September 2012 15:11

> To: 'SCons users mailing list'

> Subject: Re: [Scons-users] Copying and merging directories

>

> The thing that's a little different in our model is that we

> ultimately just want to blow away whatever files had been

> previously code generated and replace them with the new set.

> So the install operation should always happen, 100% of the

> time. The SConstruct script I have handles the build and

> codegen phases fine. The difficulty I'm having is trying to

> get the copy phase to run reliably, at least via Install.

> Using explicit cp operations via Command though seems to be

> working well.

>

> -----Original Message-----

> From: scons-users-bounces at scons.org

> [mailto:scons-users-bounces at scons.org]

> On Behalf Of William Deegan

> Sent: Tuesday, September 11, 2012 11:38 AM

> To: SCons users mailing list

> Subject: Re: [Scons-users] Copying and merging directories

>

> Peter,

>

> Try:

> scons --tree=prune

>

> This will show you the dependencies that SCons "knows" about.

> Specifically look at the install tree your construction.

>

> You could put the following in to debug what your glob is

> returning you.

>

> nodes=Glob(C_FROM_DIR+'/fw')

> for n in nodes:

> print "NODE:%s"%str(n)

> You might want to use env.Glob() instead of plain Glob.

>

> Is it safe to assume that TOT doesn't point to a subdirectory

> of the directory where you run SCons and/or SConstruct resides?

>

> -Bill

> On Sep 10, 2012, at 6:33 AM, "Peter Steele"

> <pwsteele at gmail.com> wrote:

>

> > 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

> > script:

> >

> > import os

> >

> > TOT = os.environ["TOT"]

> > CLASSPATH =

> >

> "bin:{0}/tools/jars/tools.jar:{0}/tools/jars/velocity-1.7-dep.jar".for

> > mat(TO

> > T)

> > 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 = Environment(JAVACLASSPATH=CLASSPATH, JAVAVERSION="1.7")

> >

> > 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",

> > "idl")])

> >

> > 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"

> > .format(CLASSPATH, FROYO_BASE)),

> > )

> >

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

> > "/fw")))

> >

> > 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 +

> > "/fw")),

> >

> > 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

> > http://four.pairlist.net/mailman/listinfo/scons-users

> >

> > _______________________________________________

> > Scons-users mailing list

> > Scons-users at scons.org

> > http://four.pairlist.net/mailman/listinfo/scons-users

>

> _______________________________________________

> Scons-users mailing list

> Scons-users at scons.org

> http://four.pairlist.net/mailman/listinfo/scons-users

>

> _______________________________________________

> Scons-users mailing list

> Scons-users at scons.org

> http://four.pairlist.net/mailman/listinfo/scons-users

>

Notice: This e-mail is intended solely for use of the individual or entity to which it is
addressed and may contain information that is proprietary, privileged, company confidential
and/or exempt from disclosure under applicable law. If the reader is not the intended
recipient or agent responsible for delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or copying of this communication is
strictly prohibited. If this communication has been transmitted from a U.S. location it may
also contain data subject to the International Traffic in Arms Regulations or U.S. Export
Administration Regulations and cannot be disseminated, distributed or copied to foreign
nationals, residing in the U.S. or abroad, without the prior approval of the U.S. Department
of State or appropriate export licensing authority. If you have received this communication
in error, please notify the sender by reply e-mail or collect telephone call and delete or
destroy all copies of this e-mail message, any physical copies made of this e-mail message
and/or any file attachment(s).



More information about the Scons-users mailing list