Please note:The SCons wiki is in read-only mode due to ongoing spam/DoS issues. Also, new account creation is currently disabled. We are looking into alternative wiki hosts.
Differences between revisions 14 and 15
Revision 14 as of 2008-03-12 02:47:00
Size: 2055
Editor: localhost
Comment: converted to 1.6 markup
Revision 15 as of 2012-11-03 04:10:05
Size: 2055
Editor: 114
Comment: Fix up env.Alias syntax. Its argument should be (alias_str, object_be_aliased)
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
  env.Alias(anothertgt, 'SomeAlias')   env.Alias('SomeAlias', anothertgt)
Line 14: Line 14:
  env.Alias(anothertgt, 'SomeAlias')   env.Alias('SomeAlias', anothertgt)
Line 29: Line 29:
  env.Alias(anothertgt, 'SomeAlias')   env.Alias('SomeAlias', anothertgt)

When you use Depends() like this:

  tgt = env.Command(...)
  env.Depends(tgt, 'SomeAlias')
 
  anothertgt = env.Command(...)
  env.Alias('SomeAlias', anothertgt)

it most likely won't work like you expect it to. The string 'SomeAlias' in this example is assumed to be the name of a sub-directory in the current directory, e.g. you will get an error saying that scons doesn't know how to build 'currdir\SomeAlias'.

On the other hand, if 'SomeAlias' is defined prior to the Depends() being executed, then all works as expected:

  anothertgt = env.Command(...)
  env.Alias('SomeAlias', anothertgt)
 
  tgt = env.Command(...)
  localenv.Depends(tgt, 'SomeAlias')

the target tgt will depend on the target 'anothertgt'.

The problem is that this fact (apparently) forces you to order your calls to Alias() and Depends() based on the dependency order. Not a good thing.

The solution is to not use a naked string in the Depends, if you expect it to be an Alias:

  tgt = env.Command(...)
  env.Depends(tgt, env.Alias('SomeAlias'))
 
  anothertgt = env.Command(...)
  env.Alias('SomeAlias', anothertgt)

As Anthony Roach (who proposed the solution) says:

"That tells SCons that SomeAlias is an alias, even if the alias definition hasn't been seen yet."

Perfect!

Now there's a twist to this if you happen to use env.Copy(). For example, if you have an sconscript that looks like this:

Import('env')
localenv = env.Copy()
tgt = localenv.Command(...)
localenv.Depends(tgt, localenv.Alias('SomeAlias'))

you might get a warning that 'SomeAlias' is defined in two environments. In this case, in the current local copy and in the environment where 'SomeAlias' is previously (or in future) defined. In my system, I got around this by putting all the aliases in one environment, like so:

Import('env')
localenv = env.Copy()
tgt = localenv.Command(...)
localenv.Depends(tgt, env.Alias('utx'))
localenv.Depends(tgt, env.Alias('SimpleXml'))

DependsAndAliases (last edited 2012-11-03 04:10:05 by 114)