Home | History | Annotate | Download | only in subdir1
      1 #!/usr/bin/env python
      2 
      3 # Copyright (c) 2010 Google Inc. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 import sys
      8 import time
      9 
     10 output = sys.argv[1]
     11 persistoutput = "%s.persist" % sys.argv[1]
     12 
     13 count = 0
     14 try:
     15   count = open(persistoutput, 'r').read()
     16 except:
     17   pass
     18 count = int(count) + 1
     19 
     20 if len(sys.argv) > 2:
     21   max_count = int(sys.argv[2])
     22   if count > max_count:
     23     count = max_count
     24 
     25 oldcount = 0
     26 try:
     27   oldcount = open(output, 'r').read()
     28 except:
     29   pass
     30 
     31 # Save the count in a file that is undeclared, and thus hidden, to gyp. We need
     32 # to do this because, prior to running commands, some build systems deletes
     33 # any declared outputs, so we would lose our count if we just wrote to the
     34 # given output file.
     35 open(persistoutput, 'w').write('%d' % (count))
     36 
     37 # Only write the given output file if the count has changed.
     38 if int(oldcount) != count:
     39   open(output, 'w').write('%d' % (count))
     40   # Sleep so the next run changes the file time sufficiently to make the build
     41   # detect the file as changed.
     42   time.sleep(1)
     43 
     44 sys.exit(0)
     45