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 7import sys 8import time 9 10output = sys.argv[1] 11persistoutput = "%s.persist" % sys.argv[1] 12 13count = 0 14try: 15 count = open(persistoutput, 'r').read() 16except: 17 pass 18count = int(count) + 1 19 20if len(sys.argv) > 2: 21 max_count = int(sys.argv[2]) 22 if count > max_count: 23 count = max_count 24 25oldcount = 0 26try: 27 oldcount = open(output, 'r').read() 28except: 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. 35open(persistoutput, 'w').write('%d' % (count)) 36 37# Only write the given output file if the count has changed. 38if 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 44sys.exit(0) 45