| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 the V8 project authors. All rights reserved. | 2 # Copyright 2014 the V8 project 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 delete the contents of the build | 8 the build should be clobbered, it will delete the contents of the build |
| 9 directory. | 9 directory. |
| 10 | 10 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 generator = 1 | 125 generator = 1 |
| 126 depfile = build.ninja.d | 126 depfile = build.ninja.d |
| 127 ''' % (os.path.split(build_dir)[1])) | 127 ''' % (os.path.split(build_dir)[1])) |
| 128 | 128 |
| 129 # Write a .d file for the build which references a nonexistant file. This | 129 # Write a .d file for the build which references a nonexistant file. This |
| 130 # will make Ninja always mark the build as dirty. | 130 # will make Ninja always mark the build as dirty. |
| 131 with open(build_ninja_d_file, 'w') as f: | 131 with open(build_ninja_d_file, 'w') as f: |
| 132 f.write('build.ninja: nonexistant_file.gn\n') | 132 f.write('build.ninja: nonexistant_file.gn\n') |
| 133 | 133 |
| 134 | 134 |
| 135 def clobber_if_necessary(new_landmines): | 135 def needs_clobber(landmines_path, new_landmines): |
| 136 """Does the work of setting, planting, and triggering landmines.""" | |
| 137 out_dir = get_build_dir(landmine_utils.builder()) | |
| 138 landmines_path = os.path.normpath(os.path.join(out_dir, '..', '.landmines')) | |
| 139 try: | |
| 140 os.makedirs(out_dir) | |
| 141 except OSError as e: | |
| 142 if e.errno == errno.EEXIST: | |
| 143 pass | |
| 144 | |
| 145 if os.path.exists(landmines_path): | 136 if os.path.exists(landmines_path): |
| 146 with open(landmines_path, 'r') as f: | 137 with open(landmines_path, 'r') as f: |
| 147 old_landmines = f.readlines() | 138 old_landmines = f.readlines() |
| 148 if old_landmines != new_landmines: | 139 if old_landmines != new_landmines: |
| 149 old_date = time.ctime(os.stat(landmines_path).st_ctime) | 140 old_date = time.ctime(os.stat(landmines_path).st_ctime) |
| 150 diff = difflib.unified_diff(old_landmines, new_landmines, | 141 diff = difflib.unified_diff(old_landmines, new_landmines, |
| 151 fromfile='old_landmines', tofile='new_landmines', | 142 fromfile='old_landmines', tofile='new_landmines', |
| 152 fromfiledate=old_date, tofiledate=time.ctime(), n=0) | 143 fromfiledate=old_date, tofiledate=time.ctime(), n=0) |
| 153 sys.stdout.write('Clobbering due to:\n') | 144 sys.stdout.write('Clobbering due to:\n') |
| 154 sys.stdout.writelines(diff) | 145 sys.stdout.writelines(diff) |
| 146 return True |
| 147 else: |
| 148 sys.stdout.write('Clobbering due to missing landmines file.\n') |
| 149 return True |
| 150 return False |
| 155 | 151 |
| 156 # Clobber contents of build directory but not directory itself: some | 152 |
| 157 # checkouts have the build directory mounted. | 153 def clobber_if_necessary(new_landmines): |
| 158 for f in os.listdir(out_dir): | 154 """Does the work of setting, planting, and triggering landmines.""" |
| 159 path = os.path.join(out_dir, f) | 155 out_dir = get_build_dir(landmine_utils.builder()) |
| 160 # Soft version of chromium's clobber. Only delete directories not files | 156 landmines_path = os.path.normpath(os.path.join(out_dir, '..', '.landmines')) |
| 161 # as e.g. on windows the output dir is the build dir that shares some | 157 try: |
| 162 # checked out files. | 158 os.makedirs(out_dir) |
| 163 if os.path.isdir(path) and re.search(r"(?:[Rr]elease)|(?:[Dd]ebug)", f): | 159 except OSError as e: |
| 164 delete_build_dir(path) | 160 if e.errno == errno.EEXIST: |
| 161 pass |
| 162 |
| 163 if needs_clobber(landmines_path, new_landmines): |
| 164 # Clobber contents of build directory but not directory itself: some |
| 165 # checkouts have the build directory mounted. |
| 166 for f in os.listdir(out_dir): |
| 167 path = os.path.join(out_dir, f) |
| 168 # Soft version of chromium's clobber. Only delete directories not files |
| 169 # as e.g. on windows the output dir is the build dir that shares some |
| 170 # checked out files. |
| 171 if os.path.isdir(path) and re.search(r"(?:[Rr]elease)|(?:[Dd]ebug)", f): |
| 172 delete_build_dir(path) |
| 165 | 173 |
| 166 # Save current set of landmines for next time. | 174 # Save current set of landmines for next time. |
| 167 with open(landmines_path, 'w') as f: | 175 with open(landmines_path, 'w') as f: |
| 168 f.writelines(new_landmines) | 176 f.writelines(new_landmines) |
| 169 | 177 |
| 170 | 178 |
| 171 def process_options(): | 179 def process_options(): |
| 172 """Returns a list of landmine emitting scripts.""" | 180 """Returns a list of landmine emitting scripts.""" |
| 173 parser = optparse.OptionParser() | 181 parser = optparse.OptionParser() |
| 174 parser.add_option( | 182 parser.add_option( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) | 219 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) |
| 212 output, _ = proc.communicate() | 220 output, _ = proc.communicate() |
| 213 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) | 221 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) |
| 214 clobber_if_necessary(landmines) | 222 clobber_if_necessary(landmines) |
| 215 | 223 |
| 216 return 0 | 224 return 0 |
| 217 | 225 |
| 218 | 226 |
| 219 if __name__ == '__main__': | 227 if __name__ == '__main__': |
| 220 sys.exit(main()) | 228 sys.exit(main()) |
| OLD | NEW |