Eric Anderson avatar Eric Anderson committed 45e8da5 Draft

Included hash of ext_signature.__code__ in ext_sig value, to detect
changes in external signature function. Also demonstrate non-trivial
extended signature function (hashImportantLines)
* * *
Fix typo I accidentally introduced in previous commit

Comments (0)

Files changed (4)

     
     # We always have to init the .ext_sig value...
     dep_ext_sig = dependency.get_ext_sig()
+
     if prev_ni is None:
-        print dependency.get_ninfo().__dict__, target, None
+        ## No previous record -> first time looking at this -> "changed"
         return True
-    else:
-        print dependency.get_ninfo().__dict__, target, prev_ni.__dict__
-
     try:
         prev_ext_sig = prev_ni.ext_sig
     except AttributeError:
-        print "shit"
+        ## No .ext_sig attribute -> first time looking at this (with ext_sig aware code) -> "changed"
         return True
+
+    #Finally, compare extended signatures
     return dep_ext_sig != prev_ext_sig
 
 env.Decider(myDecider)
 
+
+def hashImportantLines(contents):
+
+    """Takes a hash of lines that don't begin with #.  This is just an
+    example! I'm not certain that '\n'.join(X.split('\n')) == X for
+    all X.  Think about trailing newlines.  Also doesn't consider CRLF
+    line breaks, etc...    
+    """
+    reduced_contents = []
+    for line in contents.split('\n'):
+        if len(line)==0 or line[0] != '#':
+            reduced_contents.append(line)
+    return SCons.Util.MD5signature('\n'.join(reduced_contents))    
+
+
 def sigMaker(f):
-    ninfo = f.get_ninfo()
-    
-    print "bar"
-    ext_sig = "pants"
+    ninfo = f.get_ninfo()    
+    #print "Executing sigMaker"
+    ext_sig = hashImportantLines(f.get_contents())
     ninfo.ext_sig = ext_sig
     return ext_sig
 
 SCons.Defaults.DefaultEnvironment().ExtSignature(sigMaker)
 env.ExtSignature(sigMaker)
-print "Just set it for env %s" % repr(env)
-print "default env is %s" % repr(SCons.Defaults.DefaultEnvironment())
+#print "Just set it for env %s" % repr(env)
+#print "default env is %s" % repr(SCons.Defaults.DefaultEnvironment())
 
 b=Builder(action="bash myscript.sh $SOURCE $TARGET")
 env.Append(BUILDERS={'B' : b})

mydev/myinput.txt

 A line I care about
-#A line I don't care about -- 2012-07-27 16:46:27.551844784-04:00
+#A line I don't care about -- 2012-07-30 13:34:58.761217476-04:00
 Another line I do care about

mydev/myoutput.txt

-Last changed: 2012-07-27 16:46:27.551844784-04:00
+Last changed: 2012-07-30 13:34:58.761217476-04:00

src/engine/SCons/Node/FS.py

     def get_ext_sig(self):
         e = self.get_env()
         f = e.ext_signature
-        v = f(self)
-        print "in env %s %s(self)=%s" % (repr(e), repr(f),repr(v))
-        self.get_ninfo().ext_sig = v
-        return v
+        h = hash(f.__code__)
+        v = f(self)    
+        #print "in env %s %s(self) (hash %X)=%s" % (repr(e), repr(f), h, repr(v))
+        annotated_sig = (f.__name__, h, v)
+        self.get_ninfo().ext_sig = annotated_sig
+        return annotated_sig
 
 
     #
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.