12.7. Executing an action immediately: the Execute Function

We've been showing you how to use Action factories in the Command function. You can also execute an Action returned by a factory (or actually, any Action) at the time the SConscript file is read by wrapping it up in the Execute function. For example, if we need to make sure that a directory exists before we build any targets,


Notice that this will create the directory while the SConscript file is being read:

      % scons
      scons: Reading SConscript files ...
      scons: done reading SConscript files.
      scons: Building targets ...
      scons: `.' is up to date.
      scons: done building targets.

If you're familiar with Python, you may wonder why you would want to use this instead of just calling the native Python os.mkdir() function. The advantage here is that the Mkdir action will behave appropriately if the user specifies the SCons -n or -q options--that is, it will print the action but not actually make the directory when -n is specified, or make the directory but not print the action when -q is specified.