[Scons-users] Command vs. Action

Stefan Seefeld stefan at seefeld.name
Sun Jun 12 13:32:09 EDT 2016


On 12.06.2016 09:07, Dirk Bächle wrote:
> Hi Stefan,
>
> Am 10.06.2016 um 20:13 schrieb Stefan Seefeld:
>> Hello,
>>
>>
>> in my SConscript file I have
>>
>>
>>    def BoostRun(env, prog, target, command = "./$SOURCE > $TARGET"):
>>        run = env.Command(target, prog, command)
>>        return run
>>
>> which works reasonably well. I'd now like to fine-tune this to print a
>> custom message rather than the actual command being executed. Apparently
>> I need to use an 'Action' to do that, so I substitute the above by
>>
>>
>>    def BoostRun(env, prog, target, command = "./$SOURCE > $TARGET"):
>>        run = env.Command(target, prog, env.Action(command,
>> cmdstr="testing..."))
>>        return run
>>
>> This however yields an error, as the generated command is (almost)
>> empty, i.e. $SOURCE and $TARGET are not properly substituted. Can anyone
>> tell me what I'm missing ?
>
> I haven't actually tested this, but I think you need to use
>
>   SCons.Action.Action(...)
>
> or the simple
>
>   Action(...)
>
> instead of "env.Action(...)" here. The latter will start to substitute
> environment variables right away, in the parsing phase...but the
> proper SOURCE and TARGET variables in the environment aren't setup
> yet. You actually want to defer the evaluation/substitution of the
> command string's content until the final command string is compiled
> and executed in the build phase.

Thanks, that worked.

> Please also check out the UserGuide, Appendix D "Functions and
> Environment Methods", where the synopsis of "Action, env.Action" can
> be found.

I have to admit that I find that unnecessarily complicated. Would it
hurt to change env.Action to delay substitution ? It doesn't sound like
that should have unwanted effects on user code, but it would remove one
possible source of confusion.

Thanks,
        Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Scons-users mailing list