OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ | 6 """ |
7 This script runs every build as the first hook (See DEPS). If it detects that | 7 This script runs every build as the first hook (See DEPS). If it detects that |
8 the build should be clobbered, it will remove the build directory. | 8 the build should be clobbered, it will delete the contents of the build |
| 9 directory. |
9 | 10 |
10 A landmine is tripped when a builder checks out a different revision, and the | 11 A landmine is tripped when a builder checks out a different revision, and the |
11 diff between the new landmines and the old ones is non-null. At this point, the | 12 diff between the new landmines and the old ones is non-null. At this point, the |
12 build is clobbered. | 13 build is clobbered. |
13 """ | 14 """ |
14 | 15 |
15 import difflib | 16 import difflib |
16 import errno | 17 import errno |
17 import gyp_environment | 18 import gyp_environment |
18 import logging | 19 import logging |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 with open(landmines_path, 'r') as f: | 64 with open(landmines_path, 'r') as f: |
64 old_landmines = f.readlines() | 65 old_landmines = f.readlines() |
65 if old_landmines != new_landmines: | 66 if old_landmines != new_landmines: |
66 old_date = time.ctime(os.stat(landmines_path).st_ctime) | 67 old_date = time.ctime(os.stat(landmines_path).st_ctime) |
67 diff = difflib.unified_diff(old_landmines, new_landmines, | 68 diff = difflib.unified_diff(old_landmines, new_landmines, |
68 fromfile='old_landmines', tofile='new_landmines', | 69 fromfile='old_landmines', tofile='new_landmines', |
69 fromfiledate=old_date, tofiledate=time.ctime(), n=0) | 70 fromfiledate=old_date, tofiledate=time.ctime(), n=0) |
70 sys.stdout.write('Clobbering due to:\n') | 71 sys.stdout.write('Clobbering due to:\n') |
71 sys.stdout.writelines(diff) | 72 sys.stdout.writelines(diff) |
72 | 73 |
73 # Clobber. | 74 # Clobber contents of build directory but not directory itself: some |
74 shutil.rmtree(out_dir) | 75 # checkouts have the build directory mounted. |
| 76 for f in os.listdir(out_dir): |
| 77 path = os.path.join(out_dir, f) |
| 78 if os.path.isfile(path): |
| 79 os.unlink(path) |
| 80 elif os.path.isdir(path): |
| 81 shutil.rmtree(path) |
75 | 82 |
76 # Save current set of landmines for next time. | 83 # Save current set of landmines for next time. |
77 with open(landmines_path, 'w') as f: | 84 with open(landmines_path, 'w') as f: |
78 f.writelines(new_landmines) | 85 f.writelines(new_landmines) |
79 | 86 |
80 | 87 |
81 def process_options(): | 88 def process_options(): |
82 """Returns a list of landmine emitting scripts.""" | 89 """Returns a list of landmine emitting scripts.""" |
83 parser = optparse.OptionParser() | 90 parser = optparse.OptionParser() |
84 parser.add_option( | 91 parser.add_option( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) | 128 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) |
122 output, _ = proc.communicate() | 129 output, _ = proc.communicate() |
123 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) | 130 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) |
124 clobber_if_necessary(landmines) | 131 clobber_if_necessary(landmines) |
125 | 132 |
126 return 0 | 133 return 0 |
127 | 134 |
128 | 135 |
129 if __name__ == '__main__': | 136 if __name__ == '__main__': |
130 sys.exit(main()) | 137 sys.exit(main()) |
OLD | NEW |