I searched from internet on how to write our own decider function in scons, as to how/when a source file should be rebuilt, like this:
Program('hello.c')
def decide_if_changed(dependency,target,prev_ni):
if self.get_timestamp()!=prev_ni.timestamp:
dep=str(dependency)
tgt=str(target)
if specific_part_of_file_has_changed(dep,tgt):
return true;
return false;
Decider(decide_if_changed)
I've got a hello.c, no problem, but when running scons it prompts a python error:
$ scons -Q
scons: *** [o.o] NameError : global name 'self' is not defined
self is the python keyword to mention a class member function. Here in SContruct file, there's a class but just a decide_if_changed function. Question:
Do I have to add a class here? Why it prompts python error saying 'self' is not defined?
This example script a function call of specific_part_of_file_has_changed, is it a scons's own file that can be called by any pythong statement?
The name self
is not defined because there is a typo in the documentation. The second line of the decider should read:
if dependency.get_timestamp()!=prev_ni.timestamp:
Implementing the specific_part_of_file_has_changed()
method (or any similar series of steps to determine whether the file has changed) is completely up to you...the "customer". After all you do want a "custom decider", right? ;)