How do I tell SCons to ignore implicit dependencies from command actions?

二次信任 提交于 2019-12-14 01:27:04

问题


By default, SCons seems to look at the 'recipe' used to build a program and extracts implicit dependencies from it. For example suppose my SConstruct contains:

Command('foo', 'foocreator.py', '/usr/bin/python foocreator.py > foo')

And I've already built 'foo' ('foo' is up to date). Now I change SConstruct (or more realistically, pass different options) so that the command for 'foo' becomes:

Command('foo', 'foocreator.py', '/usr/bin/qrsh -V -cwd /usr/bin/python foocreator.py > foo')

(In other words, run the foocreator.py script through SGE) Now SCons tries to rebuild foo, --debug=explain tells me that this is because of a "new dependency on /usr/bin/qrsh" and a "dropped dependency on /usr/bin/python").

How can I prevent this inference of dependencies from the recipe, preferably globally? So far I haven't even been able to find a specification of this behaviour. I don't want to have to spell out the fact that 'foo' doesn't really depend on python or qrsh, because I would have to do that for every target and for every possible location of those programs. There must be a "right" way.

EDIT: I have also now tried explicitly adding Ignores for each target, as in:

Ignore('foo', '/usr/bin/python')
Ignore('foo', '/usr/bin/qrsh')

and even this doesn't work! SCons still wants to rebuild everything whenever I switch between running through qrsh and not.


回答1:


The thing is that scons does some minimal parsing of the action to determine what you are calling, so that

   python $SOURCE > $TARGET

automatically adds a dependency to python. It also includes the action TEXT in the md5 of the action. So that if you change it to

   anotherprog -cmd python $SOURCE > $TARGET

it will detect 3 changes:

  1. Removed dependency on python
  2. Added dependency on anotherprog
  3. Changed the command line

This is semi reasonable, in that if you change anotherprog you should arguably have a rebuild.

You can stop scons detecting command line changes by including the unimportant bits in '$(' and '$)', so changing

   anotherprog $( -date $TIME $) $SOURCE > $TARGET

to

   anotherprog $( -time $DATE $) $SOURCE > $TARGET

won't cause a rebuild.

So I'd guess if you had

  $( python $) $SOURCE > $TARGET

to

  $( anotherprog =cmd python $) $SOURCE > $TARGET

it'd do what you want.But I haven't tried that.




回答2:


I found the documented solution: there is a construction variable IMPLICIT_COMMAND_DEPENDENCIES which controls exactly this behaviour. It is documented on http://www.scons.org/doc/HTML/scons-man.html (but I discovered it by searching through the scons source code!)

So this gives the behaviour I want based on my original example.

env = Environment(IMPLICIT_COMMAND_DEPENDENCIES =0, ... )
Command('foo', 'foocreator.py', '/usr/bin/python foocreator.py > foo')

(or)

env = Environment(IMPLICIT_COMMAND_DEPENDENCIES =0, ... )
Command('foo', 'foocreator.py', '/usr/bin/python foocreator.py > foo')

I can switch between the two definitions for target 'foo' and scons will not think foo is out of date.




回答3:


Im not sure if this will help, but it would be better practice to change your action string as follows:

actionStr = '/usr/bin/qrsh -V -cwd /usr/bin/python $SOURCE > $TARGET'
Command(target = 'foo', source = 'foocreator.py', action = actionStr)

SCons may not be able to determine what is the source and target from the action string and may be getting confused.

It may not be possible to turn off the behavior like you suggest in your comment above, but instead of having to make your own builder, you should try fine-tuning it using the Ignore() and Depends() functions. And an absolute worst case would be to effectively make the action string non-changing by calling a shell script that executes qrsh and python internally.



来源:https://stackoverflow.com/questions/11564403/how-do-i-tell-scons-to-ignore-implicit-dependencies-from-command-actions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!